Loader
@UnstableApi
class Loader : LoaderErrorThrower
Manages the background loading of Loadables.
Summary
Nested types |
|---|
interface Loader.Callback<T : Loader.Loadable?>A callback to be notified of |
class Loader.LoadErrorActionAction that can be taken in response to |
interface Loader.LoadableAn object that can be loaded using a |
interface Loader.ReleaseCallbackA callback to be notified when a |
|
Thrown when an unexpected exception or error is encountered during loading. |
Constants |
|
|---|---|
const Loader.LoadErrorAction! |
Discards the failed |
const Loader.LoadErrorAction! |
Discards the failed |
const Loader.LoadErrorAction! |
Retries the load using the default delay. |
const Loader.LoadErrorAction! |
Retries the load using the default delay and resets the error count. |
Public constructors |
|---|
Loader(downloadExecutor: ReleasableExecutor!)Constructs an instance. |
|
Constructs an instance. |
Public functions |
|
|---|---|
Unit |
Cancels the current load. |
Unit |
Clears any stored fatal error. |
java-static Loader.LoadErrorAction! |
createRetryAction(resetErrorCount: Boolean, retryDelayMillis: Long)Creates a |
Boolean |
Whether the last call to |
Boolean |
Returns whether the loader is currently loading. |
Unit |
Throws a fatal error, or a non-fatal error if loading is currently backed off and the current |
Unit |
maybeThrowError(minRetryCount: Int)Throws a fatal error, or a non-fatal error if loading is currently backed off and the current |
Unit |
release()Releases the loader. |
Unit |
release(callback: Loader.ReleaseCallback?)Releases the loader. |
Long |
<T : Loader.Loadable?> startLoading(Starts loading a |
Constants
DONT_RETRY
const val DONT_RETRY: Loader.LoadErrorAction!
Discards the failed Loadable and ignores any errors that have occurred.
DONT_RETRY_FATAL
const val DONT_RETRY_FATAL: Loader.LoadErrorAction!
Discards the failed Loadable. The next call to maybeThrowError will throw the last load error.
RETRY_RESET_ERROR_COUNT
const val RETRY_RESET_ERROR_COUNT: Loader.LoadErrorAction!
Retries the load using the default delay and resets the error count.
Public constructors
Loader
Loader(downloadExecutor: ReleasableExecutor!)
Constructs an instance.
| Parameters | |
|---|---|
downloadExecutor: ReleasableExecutor! |
A |
Public functions
cancelLoading
fun cancelLoading(): Unit
Cancels the current load.
| Throws | |
|---|---|
java.lang.IllegalStateException |
If the loader is not currently loading. |
createRetryAction
java-static fun createRetryAction(resetErrorCount: Boolean, retryDelayMillis: Long): Loader.LoadErrorAction!
Creates a LoadErrorAction for retrying with the given parameters.
| Parameters | |
|---|---|
resetErrorCount: Boolean |
Whether the previous error count should be set to zero. |
retryDelayMillis: Long |
The number of milliseconds to wait before retrying. |
| Returns | |
|---|---|
Loader.LoadErrorAction! |
A |
hasFatalError
fun hasFatalError(): Boolean
Whether the last call to startLoading resulted in a fatal error. Calling maybeThrowError will throw the fatal error.
maybeThrowError
fun maybeThrowError(): Unit
Throws a fatal error, or a non-fatal error if loading is currently backed off and the current Loadable has incurred a number of errors greater than the Loaders default minimum number of retries. Else does nothing.
| Throws | |
|---|---|
java.io.IOException |
The error. |
maybeThrowError
fun maybeThrowError(minRetryCount: Int): Unit
Throws a fatal error, or a non-fatal error if loading is currently backed off and the current Loadable has incurred a number of errors greater than the specified minimum number of retries. Else does nothing.
| Parameters | |
|---|---|
minRetryCount: Int |
A minimum retry count that must be exceeded for a non-fatal error to be thrown. Should be non-negative. |
| Throws | |
|---|---|
java.io.IOException |
The error. |
release
fun release(): Unit
Releases the loader. This method should be called when the loader is no longer required.
release
fun release(callback: Loader.ReleaseCallback?): Unit
Releases the loader. This method should be called when the loader is no longer required.
| Parameters | |
|---|---|
callback: Loader.ReleaseCallback? |
An optional callback to be called on the loading thread once the loader has been released. |
startLoading
fun <T : Loader.Loadable?> startLoading(
loadable: T!,
callback: Loader.Callback<T!>!,
defaultMinRetryCount: Int
): Long
Starts loading a Loadable.
The calling thread must be a Looper thread, which is the thread on which the Callback will be called.
| Parameters | |
|---|---|
<T : Loader.Loadable?> |
The type of the loadable. |
loadable: T! |
The |
callback: Loader.Callback<T!>! |
A callback to be called when the load ends. |
defaultMinRetryCount: Int |
The minimum number of times the load must be retried before |
| Returns | |
|---|---|
Long |
|
| Throws | |
|---|---|
java.lang.IllegalStateException |
If the calling thread does not have an associated |