com.stanfy.enroscar.async.internal.LoaderDescription Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of enroscar-content Show documentation
Show all versions of enroscar-content Show documentation
Helper classes and extended abstractions for Android loaders, content resolvers, and DB access.
package com.stanfy.enroscar.async.internal;
import android.support.v4.app.LoaderManager;
import android.util.SparseArray;
import com.stanfy.enroscar.async.AsyncObserver;
import static com.stanfy.enroscar.async.internal.OperatorBase.OperatorContext;
/**
* Describes what actions should be taken when some operation completes.
* @author Roman Mazur - Stanfy (http://stanfy.com)
*/
public abstract class LoaderDescription {
/** Observers mapping. */
private final SparseArray> observers = new SparseArray<>();
/** Operator context. */
private final OperatorContext> operatorContext;
protected LoaderDescription(final OperatorContext> operatorContext) {
this.operatorContext = operatorContext;
}
void addObserver(final int loaderId, final AsyncObserver> observer) {
observers.put(loaderId, observer);
}
LoaderManager.LoaderCallbacks> makeCallbacks(final int loaderId,
final AsyncProvider provider,
final boolean destroyOnFinish) {
@SuppressWarnings("unchecked")
AsyncObserver observer = (AsyncObserver) observers.get(loaderId);
return new ObserverCallbacks<>(provider, operatorContext, observer, destroyOnFinish);
}
}