Fetcher Manager

class FetcherManager(val refreshRoutine: CoroutineScope)

The FetcherManager class is useful to manage the requests to the backend executing these requests with a CoroutineScope so to execute in background and not working in the main UI thread

Author

N7ghtm4r3 - Tecknobit

Parameters

refreshRoutine

: the coroutine used to execute the refresh routines

Constructors

Link copied to clipboard
constructor(refreshRoutine: CoroutineScope)

Types

Link copied to clipboard
object Companion
Link copied to clipboard

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:

Link copied to clipboard
private data class FetcherRoutine(val currentContext: Class<*>, val routine: () -> Unit, val repeatRoutine: Boolean = true, val refreshDelay: Long = 1000)

The FetcherRoutine data class is useful to memorize the last routine executed by the execute method

Link copied to clipboard

The GenericFetcher interface is useful to manage the requests to refresh a list of items and a single item

Link copied to clipboard
interface ItemFetcher

The ItemFetcher interface is useful to manage the requests to refresh a single item

Link copied to clipboard
interface ListFetcher

The ListFetcher interface is useful to manage the requests to refresh a list of items

Properties

Link copied to clipboard
private var isRefreshing: Boolean

isRefreshing -> whether the refreshRoutine is already refreshing

Link copied to clipboard

lastRoutineExecuted -> the last routine executed by the execute method must re-launched after the suspend method has been invoked

Link copied to clipboard
private val refreshRoutine: CoroutineScope

Functions

Link copied to clipboard

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

Link copied to clipboard
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
fun execute(currentContext: Class<*>, routine: () -> Unit, repeatRoutine: Boolean = true, refreshDelay: Long = 1000)

Function to execute the refresh routine designed

Link copied to clipboard
fun restart()

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
fun suspend()

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