C - The type of callbackR - The type of network responseE - The type of error (if any)D - The type of data in this loaderpublic abstract class BaseLoader<C,R,E,D> extends Loader<BaseResponse<R,E,D>>
setCallback().| Modifier and Type | Class and Description |
|---|---|
static class |
BaseLoader.CoreLoadBuilder<R,E,D>
Builder class for
BaseResponseLoaderWrapper.CoreLoad objects. |
static class |
BaseLoader.CoreLoadExtendedBuilder<C,R,E,D,T>
Builder class for
BaseResponseLoaderWrapper.CoreLoad objects. |
static class |
BaseLoader.ProgressWrapper
The
ProgressWrapper class is intended to display a data loading progress to the user. |
Loader.ForceLoadContentObserver, Loader.OnLoadCanceledListener<D>, Loader.OnLoadCompleteListener<D>| Constructor and Description |
|---|
BaseLoader(Context context)
Initialises a newly created
BaseLoader object. |
BaseLoader(Context context,
int resId)
Initialises a newly created
BaseLoader object. |
BaseLoader(Context context,
int resId,
String logDescription)
Initialises a newly created
BaseLoader object. |
BaseLoader(Context context,
String description)
Initialises a newly created
BaseLoader object. |
BaseLoader(Context context,
String description,
String logDescription)
Initialises a newly created
BaseLoader object. |
| Modifier and Type | Method and Description |
|---|---|
void |
callbackHelper(boolean success,
BaseResponse<R,E,D> baseResponse)
Subject to call from the callback (see
setCallback()). |
protected void |
deliver(BaseResponse<R,E,D> baseResponse)
Delivers the results of loading.
|
void |
deliverResult(BaseResponse<R,E,D> data)
Please refer to the base method description.
|
static boolean |
destroyLoader(LoaderManager loaderManager,
int loaderId)
Destroys loader with the given ID.
|
static void |
destroyLoaders(LoaderManager loaderManager,
Collection<Integer> loaderIds)
Destroys loaders.
|
static BaseResponseLoaderWrapper.CoreLoad |
getCoreLoad(Activity activity)
Returns the
CoreLoad component for the given activity. |
static BaseResponseLoaderWrapper.CoreLoad |
getCoreLoad(Fragment fragment)
Returns the
CoreLoad component for the given fragment. |
protected void |
makeRequest()
Starts an asynchronous load.
|
protected abstract void |
makeRequest(C callback)
Starts an asynchronous load.
|
protected void |
onFailure(BaseResponse<R,E,D> baseResponse)
Callback which is called after NOT successful data loading.
|
protected void |
onForceLoad()
Please refer to the base method description.
|
protected void |
onReset()
Please refer to the base method description.
|
protected void |
onStartLoading()
Please refer to the base method description.
|
protected void |
onStopLoading()
Please refer to the base method description.
|
protected void |
onSuccess(BaseResponse<R,E,D> baseResponse)
Callback which is called after successful data loading.
|
BaseLoader<C,R,E,D> |
setCallback(C callback)
Sets callback component.
|
BaseLoader<C,R,E,D> |
setProgress(BaseLoader.ProgressWrapper progress)
Sets component to display progress.
|
BaseLoader<C,R,E,D> |
setTimeout(int timeout)
Sets timeout (in seconds).
|
String |
toString()
Please refer to the base method description.
|
abandon, cancelLoad, commitContentChanged, dataToString, deliverCancellation, dump, forceLoad, getContext, getId, isAbandoned, isReset, isStarted, onAbandon, onCancelLoad, onContentChanged, registerListener, registerOnLoadCanceledListener, reset, rollbackContentChanged, startLoading, stopLoading, takeContentChanged, unregisterListener, unregisterOnLoadCanceledListenerpublic BaseLoader(@NonNull Context context)
BaseLoader object.context - The contextpublic BaseLoader(@NonNull Context context, String description)
BaseLoader object.context - The contextdescription - The data description (for GUI)public BaseLoader(@NonNull Context context, String description, String logDescription)
BaseLoader object.context - The contextdescription - The data description (for GUI)logDescription - The data description (for logging)public BaseLoader(@NonNull Context context, @StringRes int resId)
BaseLoader object.context - The contextresId - The resource ID of the data description (for GUI)public BaseLoader(@NonNull Context context, @StringRes int resId, String logDescription)
BaseLoader object.context - The contextresId - The resource ID of the data description (for GUI)logDescription - The data description (for logging)public BaseLoader<C,R,E,D> setProgress(BaseLoader.ProgressWrapper progress)
progress - The progress componentBaseLoader objectpublic BaseLoader<C,R,E,D> setCallback(C callback)
setCallback(new Callback<D>() {
@Override
public void success(D result, Response response) {
loader.callbackHelper(true, new BaseResponse<...>(...));
}
@Override
public void failure(RetrofitError error) {
loader.callbackHelper(false, new BaseResponse<...>(...));
}
});
callback - The callback componentBaseLoader objectcallbackHelper,
BaseResponsepublic BaseLoader<C,R,E,D> setTimeout(int timeout)
timeout - The timeoutBaseLoader objectprotected void makeRequest()
public void callbackHelper(boolean success,
@NonNull
BaseResponse<R,E,D> baseResponse)
setCallback()).success - true if data loading completed successfully, false otherwisebaseResponse - The results of loading@MainThread protected void onSuccess(@NonNull BaseResponse<R,E,D> baseResponse)
baseResponse - The results of loading@MainThread protected void onFailure(@NonNull BaseResponse<R,E,D> baseResponse)
baseResponse - The results of loadingprotected void deliver(@NonNull BaseResponse<R,E,D> baseResponse)
baseResponse - The resultsprotected abstract void makeRequest(@NonNull C callback)
callback - The callbackpublic static void destroyLoaders(LoaderManager loaderManager, Collection<Integer> loaderIds)
loaderManager - The loader managerloaderIds - The list of loaders to destroypublic static boolean destroyLoader(LoaderManager loaderManager, int loaderId)
loaderManager - The loader managerloaderId - The loader IDtrue if loader was successfully destroyed, false otherwisepublic String toString()
@MainThread public void deliverResult(BaseResponse<R,E,D> data)
deliverResult in class Loader<BaseResponse<R,E,D>>protected void onStartLoading()
onStartLoading in class Loader<BaseResponse<R,E,D>>@MainThread protected void onStopLoading()
onStopLoading in class Loader<BaseResponse<R,E,D>>@MainThread protected void onForceLoad()
onForceLoad in class Loader<BaseResponse<R,E,D>>@MainThread protected void onReset()
public static BaseResponseLoaderWrapper.CoreLoad getCoreLoad(Fragment fragment)
CoreLoad component for the given fragment.fragment - The fragmentCoreLoadpublic static BaseResponseLoaderWrapper.CoreLoad getCoreLoad(Activity activity)
CoreLoad component for the given activity.activity - The activityCoreLoad
Copyright © 2015-2017 akha, a.k.a. Alexander Kharitonov
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.