Android Open Source - generalsbuzz Check Local Data Task






From Project

Back to project page generalsbuzz.

License

The source code is released under:

MIT License

If you think the Android project generalsbuzz listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package me.kworden.wlcalendar2.async;
//w  w  w.  j  a v  a2s .c o m
import java.util.ArrayList;

import me.kworden.wlcalendar2.struct.MonthYearParcel;
import me.kworden.wlcalendar2.util.STATUS;
import android.content.Context;
import android.os.AsyncTask;

public class CheckLocalDataTask extends AsyncTask<MonthYearParcel, Void, STATUS>
{
  private Context m_context;
  private ArrayList<MonthYearParcel> m_files;
  
  public CheckLocalDataTask(Context p_activity)
  {
    m_context = p_activity;
    m_files = new ArrayList<MonthYearParcel>();
  }

  // Asynchronously checks to see if local data exists //
  @Override
  protected STATUS doInBackground(MonthYearParcel ... p_args)
  {
    System.out.println("Checking local data...");
    
    for(MonthYearParcel i_time : p_args)
    {
      // Adds the MonthYearParcels to a instance variable to queue which months should be loaded //
      m_files.add(i_time);

      if(!localFileExists(i_time.getAsFileName()))
      {
        System.out.println(i_time.getAsFileName() + " does not exist. Returning _NOT_FOUND data code for pull.");
        return STATUS.LOCAL_DATA_NOT_FOUND;
      }

      System.out.println("Found file for: " + i_time.getAsFileName());
    }
    
    return STATUS.LOCAL_DATA_FOUND;
  }
  
  @Override
  public void onPostExecute(STATUS p_status)
  {
    // Execute the desired task based on whether or not the local data file exists. m_files.toArray() is used because AsyncTasks can only take arrays //
    if(p_status.equals(STATUS.LOCAL_DATA_FOUND))
    {
      System.out.println("Local data found! Reading.");
      new ReadLocalDataTask(m_context).execute(m_files.toArray(new MonthYearParcel[m_files.size()]));
    }
    else
    {
      System.out.println("No local data found, executing remote request.");
      new RequestRemoteDataTask(m_context).execute(m_files.toArray(new MonthYearParcel[m_files.size()]));
    }
  }
  
  private boolean localFileExists(String p_file_name)
  {
    return m_context.getFileStreamPath(p_file_name).exists();
  }
}




Java Source Code List

me.kworden.wlcalendar2.BuildConfig.java
me.kworden.wlcalendar2.BuildConfig.java
me.kworden.wlcalendar2.MainActivity.java
me.kworden.wlcalendar2.SettingsActivity.java
me.kworden.wlcalendar2.adapter.EventAdapter.java
me.kworden.wlcalendar2.async.CheckLocalDataTask.java
me.kworden.wlcalendar2.async.ParseDataTask.java
me.kworden.wlcalendar2.async.ReadLocalDataTask.java
me.kworden.wlcalendar2.async.RequestRemoteDataTask.java
me.kworden.wlcalendar2.async.StoreDataTask.java
me.kworden.wlcalendar2.fragment.EventDisplayFragment.java
me.kworden.wlcalendar2.fragment.EventInfoFragment.java
me.kworden.wlcalendar2.fragment.SettingsFragment.java
me.kworden.wlcalendar2.receiver.CheckLocalDataReceiver.java
me.kworden.wlcalendar2.receiver.RequestRemoteDataReceiver.java
me.kworden.wlcalendar2.receiver.UpdateRowsReceiver.java
me.kworden.wlcalendar2.struct.MonthYearParcel.java
me.kworden.wlcalendar2.struct.WLEventClassifier.java
me.kworden.wlcalendar2.struct.WLEventLinebreak.java
me.kworden.wlcalendar2.struct.WLEvent.java
me.kworden.wlcalendar2.struct.WLHeader.java
me.kworden.wlcalendar2.util.APP.java
me.kworden.wlcalendar2.util.BROADCAST.java
me.kworden.wlcalendar2.util.MD5.java
me.kworden.wlcalendar2.util.PATTERNS.java
me.kworden.wlcalendar2.util.STATUS.java