content: package com.alexstyl.specialdates.ui.loader;
  
  import android.content.Context;
  import android.support.v4.content.AsyncTaskLoader;
  
  @SuppressWarnings("all")
  public abstract class SimpleAsyncTaskLoader<T> extends AsyncTaskLoader<T> {
  
      public SimpleAsyncTaskLoader(Context context) {
          super(context);
      }
  
      private T mData;
  
      @Override
      public void deliverResult(T data) {
          if (isReset()) {
              // The Loader has been reset; ignore the result and invalidate the data.
              releaseResources(data);
              return;
          }
  
          // Hold a reference to the old data so it doesn't get garbage collected.
          // We must protect it until the new data has been delivered.
          T oldData = mData;
          mData = data;
  
          if (isStarted()) {
              // If the Loader is in a started state, deliver the results to the
              // client. The superclass method does this for us.
              super.deliverResult(data);
          }
  
          // Invalidate the old data as we don't need it any more.
          if (oldData != null && oldData != data) {
              releaseResources(oldData);
          }
      }
  
      private void releaseResources(T oldData) {
  
      }
  
      @Override
      protected void onStartLoading() {
          if (mData != null) {
              // Deliver any previously loaded data immediately.
              deliverResult(mData);
          }
  
          if (takeContentChanged() || mData == null) {
              // When the observer detects a change, it should call onContentChanged()
              // on the Loader, which will cause the next call to takeContentChanged()
              // to return true. If this is ever the case (or if the current data is
              // null), we force a new load.
              forceLoad();
          }
      }
  
      @Override
      protected void onStopLoading() {
          // The Loader is in a stopped state, so we should attempt to cancel the
          // current load (if there is one).
          cancelLoad();
  
          // Note that we leave the observer as is. Loaders in a stopped state
          // should still monitor the data source for changes so that the Loader
          // will know to force a new load if it is ever started again.
      }
  
      @Override
      protected void onReset() {
          // Ensure the loader has been stopped.
          onStopLoading();
  
          // At this point we can release the resources associated with 'mData'.
          if (mData != null) {
              releaseResources(mData);
              mData = null;
          }
  
          // The Loader is being reset, so we should stop monitoring for changes.
          onUnregisterObserver();
      }
  
      final public T getCachedData() {
          return mData;
      }
  
      /**
       * Called whenever it's time to stop monitoring changes on the loaders data source
       */
      protected void onUnregisterObserver() {
  
      }
  
      @Override
      public void onCanceled(T data) {
          // Attempt to cancel the current asynchronous load.
          super.onCanceled(data);
  
          // The load has been canceled, so we should release the resources
          // associated with 'data'.
          releaseResources(data);
      }
  
  }
  