public static interface BaseResponseLoaderWrapper.CoreLoad
CoreLoad
component is responsible for data loading. Usage example:
import akha.yakhont.loader.wrapper.BaseLoaderWrapper.SwipeRefreshWrapper; import akha.yakhont.loader.wrapper.BaseResponseLoaderWrapper.CoreLoad; import akha.yakhont.technology.retrofit.Retrofit2; import akha.yakhont.technology.retrofit.Retrofit2.Retrofit2Rx; import akha.yakhont.technology.retrofit.Retrofit2LoaderWrapper.Retrofit2CoreLoadBuilder; import akha.yakhont.technology.rx.Rx; import akha.yakhont.technology.rx.Rx2; import com.mypackage.model.MyData; import com.mypackage.retrofit.Retrofit2Api; import retrofit2.Callback; import android.support.annotation.NonNull; public class MyFragment extends Fragment { @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); ... // SwipeRefreshLayout handling (optional) SwipeRefreshWrapper.register(this, R.id.swipeContainer); // optional Rx component Retrofit2Rx<MyData[]> rx = new Retrofit2Rx<>(); CoreLoad coreLoad = new Retrofit2CoreLoadBuilder<MyData[], Retrofit2Api>( this, MyData[].class, getRetrofitApi()) { // optional: override makeRequest only if // the default one doesn't work well @Override public void makeRequest(@NonNull Callback<MyData[]> callback) { // something like this (e.g. for Retrofit2 Call): // getApi().data().enqueue(callback); // or like this (e.g. for Rx2 Flowable): // getRx2DisposableHandler().add(Rx2.handle( // getApi().data(), getRxWrapper(callback))); // or like this (e.g. for Rx Observable): // getRxSubscriptionHandler().add(Rx.handle( // getApi().data(), getRxWrapper(callback))); // or ... } } // optional .setDataBinding(new String[] {"name", "age" }, new int [] {R.id.name, R.id.age}) // all 3 "set" methods below are optional too .setListView(R.id.list_view) // list / grid / recycler view ID .setListItem(R.layout.list_item) // view item layout .setRx(rx) .create(); coreLoad.startLoading(); } private Retrofit2<Retrofit2Api> getRetrofitApi() { // something like below but not exactly - // Retrofit2 object should be cached somewhere // and don't forget to call Retrofit2.init() return new Retrofit2<>(); } }Here the item layout XML (R.layout.list_item) may looks as follows:
<LinearLayout ... > <TextView android:id="@+id/name" ... /> <TextView android:id="@+id/age" ... /> </LinearLayout>And the JSON:
[ { "name": "John", "age": 25 }, { "name": "Bob", "age": 32 }, ... ]
Modifier and Type | Method and Description |
---|---|
BaseLoaderWrapper |
addLoader(BaseCacheAdapter.CacheAdapter adapter,
BaseLoaderWrapper.LoaderBuilder builder)
Adds loader to the collection of
loaders associated with the given CoreLoad component. |
BaseLoaderWrapper |
addLoader(BaseCacheAdapter.CacheAdapter adapter,
BaseLoaderWrapper loader)
Adds loader to the collection of
loaders associated with the given CoreLoad component. |
BaseLoaderWrapper |
addLoader(BaseCacheAdapter.CacheAdapter adapter,
BaseRx.LoaderRx rx,
BaseLoaderWrapper.LoaderBuilder builder)
Adds loader to the collection of
loaders associated with the given CoreLoad component. |
BaseLoaderWrapper |
addLoader(BaseCacheAdapter.CacheAdapter adapter,
BaseRx.LoaderRx rx,
BaseLoaderWrapper loader)
Adds loader to the collection of
loaders associated with the given CoreLoad component. |
void |
cancelLoaders()
Cancels all
loaders associated with the given CoreLoad component. |
void |
clearLoaders()
Clears the collection of
loaders associated with the given CoreLoad component. |
void |
destroyLoaders()
Destroys all
loaders associated with the given CoreLoad component. |
Set<BaseLoaderWrapper> |
getLoaders()
Returns the collection of
loaders associated with the given CoreLoad component. |
void |
hideProgress(boolean force)
Hides data loading progress indicator.
|
BaseResponseLoaderWrapper.CoreLoad |
setGoBackOnLoadingCanceled(boolean isGoBackOnLoadingCanceled)
Indicates whether the back key press should be emulated if data loading was cancelled or not
|
void |
showProgress(String text)
Displays a data loading progress indicator.
|
void |
startLoading()
Starts all loaders associated with the given
CoreLoad component. |
void |
startLoading(boolean forceCache,
boolean noProgress,
boolean merge,
boolean sync)
Starts all loaders associated with the given
CoreLoad component. |
BaseLoaderWrapper |
startLoading(int loaderId,
boolean forceCache,
boolean noProgress,
boolean merge,
boolean sync)
Starts loader with the given ID.
|
Set<BaseLoaderWrapper> getLoaders()
loaders
associated with the given CoreLoad
component.void clearLoaders()
loaders
associated with the given CoreLoad
component.void destroyLoaders()
loaders
associated with the given CoreLoad
component.void cancelLoaders()
loaders
associated with the given CoreLoad
component.LoaderManager.destroyLoader(int)
BaseResponseLoaderWrapper.CoreLoad setGoBackOnLoadingCanceled(boolean isGoBackOnLoadingCanceled)
isGoBackOnLoadingCanceled
- The value to setCoreLoad
object to allow for chaining of calls to set methodsBaseLoaderWrapper addLoader(BaseCacheAdapter.CacheAdapter adapter, BaseLoaderWrapper.LoaderBuilder builder)
loaders
associated with the given CoreLoad
component.
If such loader already exists, it replaced by the new one (if not busy with loading data - otherwise, the new loader ignored
and the existing one updated by the new adapter).adapter
- The adapter which added loader should usebuilder
- The loader builder (to build the loader to add)BaseLoaderWrapper addLoader(BaseCacheAdapter.CacheAdapter adapter, BaseRx.LoaderRx rx, BaseLoaderWrapper.LoaderBuilder builder)
loaders
associated with the given CoreLoad
component.
If such loader already exists, it replaced by the new one (if not busy with loading data - otherwise, the new loader ignored
and the existing one updated by the new adapter and Rx component).adapter
- The adapter which added loader should userx
- The Rx component which added loader should usebuilder
- The loader builder (to build the loader to add)BaseLoaderWrapper addLoader(BaseCacheAdapter.CacheAdapter adapter, BaseLoaderWrapper loader)
loaders
associated with the given CoreLoad
component.
If such loader already exists, it replaced by the new one (if not busy with loading data - otherwise, the new loader ignored
and the existing one updated by the new adapter).adapter
- The adapter which added loader should useloader
- The loader to addBaseLoaderWrapper addLoader(BaseCacheAdapter.CacheAdapter adapter, BaseRx.LoaderRx rx, BaseLoaderWrapper loader)
loaders
associated with the given CoreLoad
component.
If such loader already exists, it replaced by the new one (if not busy with loading data - otherwise, the new loader ignored
and the existing one updated by the new adapter and Rx component).adapter
- The adapter which added loader should userx
- The Rx component which added loader should useloader
- The loader to addvoid startLoading()
CoreLoad
component.void startLoading(boolean forceCache, boolean noProgress, boolean merge, boolean sync)
CoreLoad
component.forceCache
- true
to force loading data from cache, false
otherwisenoProgress
- true
to not display loading progress, false
otherwisemerge
- true
to merge the newly loaded data with already existing, false
otherwisesync
- true
to load data synchronously, false
otherwiseBaseLoaderWrapper startLoading(int loaderId, boolean forceCache, boolean noProgress, boolean merge, boolean sync)
loaderId
- The loader's IDforceCache
- true
to force loading data from cache, false
otherwisenoProgress
- true
to not display loading progress, false
otherwisemerge
- true
to merge the newly loaded data with already existing, false
otherwisesync
- true
to load data synchronously, false
otherwisetrue
if loader was started successfully, false
otherwisevoid showProgress(String text)
text
- The text to displayvoid hideProgress(boolean force)
force
- Indicates whether the progress hiding should be forced (e.g as result of cancelLoaders()
) or not
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.