All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.stanfy.enroscar.async.internal.LoaderDescription Maven / Gradle / Ivy

Go to download

Helper classes and extended abstractions for Android loaders, content resolvers, and DB access.

There is a newer version: 2.1
Show newest version
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);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy