Making loaders quick and easy.
EzLoaders borrows heavily from these posts written by Alex Lockwood If you are not familiar with Loaders please read the four posts Alex has written on them
Additional information about Loaders can be found in the Android documentation
EzLoaders is compatible with Android API 15 and up.
EzLoaders is available on maven central.
For those using gradle, simply add the following to your build.gradle
dependencies {
compile 'com.lukekorth:ez-loaders:1.4.0'
}
Users of maven can add the following to their pom
<dependency>
<groupId>com.lukekorth</groupId>
<artifactId>ez-loaders</artifactId>
<version>1.4.0</version>
</dependency>
When you want to make use of a Loader, your Activity or Fragment should implement EzLoaderInterface.
To start the loader, in onCreate
your Activity should call initLoader
.
Your LOADER_ID
can be any value, it is returned to you in onCreateLoader
and loadInBackground
as id
and onLoadFinished
and onLoaderReset
as
loader.getId()
. LOADER_ID
is mainly used to branch on when multiple loaders
are used in one Activity, you will not need to worry about it if you are only
using a single loader.
You can pass a Bundle
of args to initLoader
which can be used in onCreateLoader
.
getLoaderManager().initLoader(LOADER_ID, null, this)
@Override
public Loader<T> onCreateLoader(int id, Bundle args) {
// com.lukekorth.REFRESH is the broadcast action that will cause
// the loader to refresh it's data
return new EzLoader<T>(this, "com.lukekorth.REFRESH", this);
}
@Override
public void onLoadFinished(Loader<T> loader, T data) {
mAdapter.setData(data);
}
@Override
public void onLoaderReset(Loader<T> loader) {
mAdapter.setData(null);
}
@Override
public T loadInBackground(int id) {
//fetch and return your data here, this will be passed to your adapter
}
@Override
public void onReleaseResources(List<Thread> t) {
//release any resources you may have used to query data in loadInBackground()
}
The code in this project is licensed under the Apache Software License 2.0, for details see the included LICENSE file.
If you have encountered a bug, please post an issue.