Skip to content
This repository has been archived by the owner on Sep 19, 2020. It is now read-only.
/ ez-loaders Public archive

A simple library to eliminate the boilerplate code that comes with the use of loaders in Android

License

Notifications You must be signed in to change notification settings

lkorth/ez-loaders

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EzLoaders

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

Support

EzLoaders is compatible with Android API 15 and up.

Usage

Adding the code

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>

Using the code

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()
}

License

The code in this project is licensed under the Apache Software License 2.0, for details see the included LICENSE file.

Issues

If you have encountered a bug, please post an issue.

About

A simple library to eliminate the boilerplate code that comes with the use of loaders in Android

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages