Fetcher
Manager
Wrapper
The FetcherManagerWrapper interface is useful for wrapping and facilitating operation with the FetcherManager, so the inheriting classes will invoke just the wrapper methods for a clean readability of the code, for example:
// the super class from which the other classes will be inherited
abstract class AbstractClass : FetcherManagerWrapper {
protected val refreshRoutine = CoroutineScope(Dispatchers.Default)
private val fetcherManager = FetcherManager(refreshRoutine)
override fun canRefresherStart(): Boolean {
return fetcherManager.canStart()
}
override fun suspendRefresher() {
fetcherManager.suspend()
}
override fun restartRefresher() {
fetcherManager.restart()
}
override fun continueToFetch(currentContext: Class<*>): Boolean {
return fetcherManager.continueToFetch(currentContext)
}
override fun execRefreshingRoutine(
currentContext: Class<*>,
routine: () -> Unit,
repeatRoutine: Boolean,
refreshDelay: Long
) {
fetcherManager.execute(
currentContext = currentContext,
routine = routine,
repeatRoutine = repeatRoutine,
refreshDelay = delay
)
}
}
// an inherit class example
class ExampleClass : AbstractClass {
fun example() {
execRefreshingRoutine(
currentContext = this::class.java,
routine = {
// your routine
}
)
}
fun example1() {
suspendRefresher()
}
}
Author
N7ghtm4r3 - Tecknobit
See also
Functions
Method to get whether the refreshRoutine can start, so if there aren't other jobs that routine is already executing
Method to check if the refreshRoutine can continue to refresh or need to be stopped, this for example when the UI displayed changes and the requests to refresh the UI data also changes
Method to execute the refresh routine designed
Method to restart the current refreshRoutine after other requests has been executed, the isRefreshing instance will be set as true to deny the restart of the routine after executing the other requests
Method to conditionally restart the current refreshRoutine after other requests has been executed, the isRefreshing instance will be set as true to deny the restart of the routine after executing the other requests
Method to set the current active context where the refreshRoutine is executing
Method to suspend the current refreshRoutine to execute other requests to the backend, the isRefreshing instance will be set as false to allow the restart of the routine after executing the other requests
Method to conditionally suspend the current refreshRoutine to execute other requests to the backend, the isRefreshing instance will be set as false to allow the restart of the routine after executing the other requests