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

Link copied to clipboard
abstract fun canRefresherStart(): Boolean

Function to get whether the refreshRoutine can start, so if there aren't other jobs that routine is already executing

Link copied to clipboard
abstract fun continueToFetch(currentContext: Class<*>): Boolean

Function 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

Link copied to clipboard
abstract fun execRefreshingRoutine(currentContext: Class<*>, routine: () -> Unit, repeatRoutine: Boolean = true, refreshDelay: Long = 1000)

Function to execute the refresh routine designed

Link copied to clipboard
abstract fun restartRefresher()

Function 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

Link copied to clipboard
open fun restartRefresherIf(condition: Boolean)

Function 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

Link copied to clipboard
open fun setActiveContext(currentContext: Class<*>)

Function to set the current active context where the refreshRoutine is executing

Link copied to clipboard
abstract fun suspendRefresher()

Function 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

Link copied to clipboard
open fun suspendRefresherIf(condition: Boolean)

Function 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