RetrieverWrapper

The RetrieverWrapper interface is useful for wrapping and facilitating operation with the Retriever, 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 : RetrieverWrapper {

    protected val retrieverScope = CoroutineScope(Dispatchers.Default)

    private val retrieverScope = Retriever(retrieverScope)

    override fun canRetrieverStart(): Boolean {
        return retrieverScope.canStart()
    }

    override fun suspendRetriever() {
        retrieverScope.suspend()
    }

    override fun restartRetriever() {
        retrieverScope.restart()
    }

    override fun continueToRetrieve(
        currentContext: KClass<*>
    ): Boolean {
        return retrieverScope.continueToRetrieve(currentContext)
    }

    override fun retrieve(
        currentContext: KClass<*>,
        routine: () -> Unit,
        repeatRoutine: Boolean,
        refreshDelay: Long
    ) {
        retrieverScope.execute(
            currentContext = currentContext,
            routine = routine,
            repeatRoutine = repeatRoutine,
            refreshDelay = delay
        )
    }

}

// an inherit class example
class ExampleClass : AbstractClass {

    fun example() {
        retrieve(
            currentContext = this::class.java,
            routine = {
                // your routine
            }
        )
    }

    fun example1() {
        suspendRetriever()
    }

}

Author

N7ghtm4r3 - Tecknobit

See also

Inheritors

Functions

Link copied to clipboard
abstract fun canRetrieverStart(): Boolean

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

Link copied to clipboard
abstract fun continueToRetrieve(currentContext: KClass<*>): Boolean

Method used to check if the retrieverScope 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 restartRetriever()

Method used to restart the current retrieverScope 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 restartRetrieverIf(condition: Boolean)

Method used to conditionally restart the current retrieverScope 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
abstract fun retrieve(currentContext: KClass<*>, routine: suspend () -> Unit, repeatRoutine: Boolean = true, refreshDelay: Long = 1000)

Method used to execute the refresh routine designed

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

Method used to set the current active context where the retrieverScope is executing

Link copied to clipboard
abstract fun suspendRetriever()

Method used to suspend the current retrieverScope 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 suspendRetrieverIf(condition: Boolean)

Method used to conditionally suspend the current retrieverScope 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