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

com.stanfy.enroscar.content.loader.BaseAsyncTaskLoader 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.content.loader;

import android.content.Context;
import android.support.v4.content.AsyncTaskLoader;


/**
 * @author Olexandr Tereshchuk - Stanfy
 *
 * @param  data type
 */
public abstract class BaseAsyncTaskLoader extends AsyncTaskLoader {

  /** Logging tag. */
  private static final String TAG = "BaseAsyncTaskLoader";

  /** Result data. */
  private T result;

  public BaseAsyncTaskLoader(final Context ctx) {
    super(ctx);
  }

  @Override
  public void deliverResult(final T data) {
    if (isReset()) { return; }

    result = data;

    if (isStarted()) {
      super.deliverResult(data);
    }
  }

  @Override
  protected void onStartLoading() {
    final boolean contentChanges = takeContentChanged();
    if (!contentChanges && result != null) {
      deliverResult(result);
    }

    if (contentChanges || result == null) {
      forceLoad();
    }
  }

  @Override
  protected void onStopLoading() {
    cancelLoad();
  }

  @Override
  protected void onReset() {
    onStopLoading();
    result = null;
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy