package com.shing.aputimetable.model;

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

import com.shing.aputimetable.entity.ApuClass;
import com.shing.aputimetable.utils.QueryUtils;

import java.util.List;

/**
 * Created by Shing on 31-Jul-17.
 */

public class ApuClassLoader extends AsyncTaskLoader<List<ApuClass>> {

    private String mIntakeCode;

    public ApuClassLoader(Context context, String intakeCode) {
        super(context);
        mIntakeCode = intakeCode;
    }

    @Override
    protected void onStartLoading() {
        forceLoad();
    }


    @Override
    public List<ApuClass> loadInBackground() {

        if (TextUtils.isEmpty(mIntakeCode)) {
            return null;
        }

        // Perform the network request, parse the response, and extract a list of apu class details.
        return QueryUtils.getAllClass(mIntakeCode);
    }
}

@@ -64,16 +64,48 @@
 ontext;%0A
+import android.database.Cursor;%0A
 import a
@@ -147,16 +147,16 @@
 Loader;%0A
-
 import a
@@ -226,16 +226,84 @@
 uClass;%0A
+import com.shing.aputimetable.model.ApuClassContract.ApuClassEntry;%0A
 import c
@@ -339,24 +339,52 @@
 ueryUtils;%0A%0A
+import java.util.ArrayList;%0A
 import java.
@@ -540,16 +540,46 @@
 akeCode;
+%0A    private Context mContext;
 %0A%0A    pu
@@ -690,24 +690,52 @@
 intakeCode;%0A
+        mContext = context;%0A
     %7D%0A%0A    @
@@ -950,24 +950,1821 @@
 %0A        %7D%0A%0A
+        String%5B%5D projection = %7B%0A                ApuClassEntry._ID,%0A                ApuClassEntry.COLUMN_CLASS_DAY,%0A                ApuClassEntry.COLUMN_CLASS_DATE,%0A                ApuClassEntry.COLUMN_CLASS_TIME,%0A                ApuClassEntry.COLUMN_CLASS_ROOM,%0A                ApuClassEntry.COLUMN_CLASS_LOCATION,%0A                ApuClassEntry.COLUMN_CLASS_SUBJECT,%0A                ApuClassEntry.COLUMN_CLASS_LECTURER%0A        %7D;%0A%0A        Cursor cursor = mContext.getContentResolver().query(ApuClassEntry.CONTENT_URI, projection, null, null, null);%0A%0A        if (cursor != null && cursor.moveToFirst()) %7B%0A            List%3CApuClass%3E classes = new ArrayList%3C%3E();%0A            try %7B%0A                while (!cursor.isAfterLast()) %7B%0A                    ApuClass c = new ApuClass();%0A                    c.setDate(cursor.getString(cursor.getColumnIndex(ApuClassEntry.COLUMN_CLASS_DATE)));%0A                    c.setDay(cursor.getString(cursor.getColumnIndex(ApuClassEntry.COLUMN_CLASS_DAY)));%0A                    c.setTime(cursor.getString(cursor.getColumnIndex(ApuClassEntry.COLUMN_CLASS_TIME)));%0A                    c.setRoom(cursor.getString(cursor.getColumnIndex(ApuClassEntry.COLUMN_CLASS_ROOM)));%0A                    c.setLocation(cursor.getString(cursor.getColumnIndex(ApuClassEntry.COLUMN_CLASS_LOCATION)));%0A                    c.setSubject(cursor.getString(cursor.getColumnIndex(ApuClassEntry.COLUMN_CLASS_SUBJECT)));%0A                    c.setLecturer(cursor.getString(cursor.getColumnIndex(ApuClassEntry.COLUMN_CLASS_LECTURER)));%0A                    classes.add(c);%0A                    cursor.moveToNext();%0A                %7D%0A                return classes;%0A            %7D finally %7B%0A                cursor.close();%0A            %7D%0A        %7D%0A%0A        if (QueryUtils.isNetworkConnected(mContext)) %7B%0A    
         // P
@@ -2856,24 +2856,28 @@
 ls.%0A        
+    
 return Query
@@ -2905,18 +2905,62 @@
 takeCode
-);
+, mContext);%0A        %7D%0A%0A%0A        return null;%0A
 %0A    %7D%0A%7D

Load class details from SQLite database if have save before