// Path: app/src/main/java/com/crazyhitty/chdev/ks/munch/models/SourceItem.java
// public class SourceItem {
//     private String sourceName, sourceUrl, sourceCategoryName, sourceDateAdded;
//     private int sourceCategoryImgId;
// 
//     public int getSourceCategoryImgId() {
//         return sourceCategoryImgId;
//     }
// 
//     public void setSourceCategoryImgId(int sourceCategoryImgId) {
//         this.sourceCategoryImgId = sourceCategoryImgId;
//     }
// 
//     public String getSourceName() {
//         return sourceName;
//     }
// 
//     public void setSourceName(String sourceName) {
//         this.sourceName = sourceName;
//     }
// 
//     public String getSourceUrl() {
//         return sourceUrl;
//     }
// 
//     public void setSourceUrl(String sourceUrl) {
//         this.sourceUrl = sourceUrl;
//     }
// 
//     public String getSourceDateAdded() {
//         return sourceDateAdded;
//     }
// 
//     public void setSourceDateAdded(String sourceDateAdded) {
//         this.sourceDateAdded = sourceDateAdded;
//     }
// 
//     public String getSourceCategoryName() {
//         return sourceCategoryName;
//     }
// 
//     public void setSourceCategoryName(String sourceCategoryName) {
//         this.sourceCategoryName = sourceCategoryName;
//     }
// }
// 
// Path: app/src/main/java/com/crazyhitty/chdev/ks/munch/utils/DateUtil.java
// public class DateUtil {
//     String formatRfc2822 = "EEE, dd MMM yyyy HH:mm:ss Z";
//     String formatLocal = "EEE, d MMM yyyy";
//     private String date;
// 
//     public String getCurrDate() {
//         date = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").format(new Date());
//         return date;
//     }
// 
//     //converts rss publish date into a readable format
//     public String getDate(String pubDate) throws ParseException {
//         Date date = getDateObj(pubDate);
//         return new SimpleDateFormat(formatLocal).format(date);
//     }
// 
//     //get Date object from pub date
//     public Date getDateObj(String pubDate) throws ParseException {
//         SimpleDateFormat pubDateFormat = new SimpleDateFormat(formatRfc2822, Locale.ENGLISH); //rss spec
//         Date date = null;
//         try {
//             date = pubDateFormat.parse(pubDate);
//         } catch (ParseException e) {
//             pubDateFormat = new SimpleDateFormat(formatLocal); //fallback
//             date = pubDateFormat.parse(pubDate);
//         }
//         return date;
//     }
// }


import android.content.Context;
import android.os.Handler;
import com.crazyhitty.chdev.ks.munch.models.SourceItem;
import com.crazyhitty.chdev.ks.munch.utils.DateUtil;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
            final String responseMsg = response.message();
            //run on the ui thread
            new Handler(mContext.getMainLooper()).post(new Runnable() {
                @Override
                public void run() {
                    mOnCuratedFeedsRetrievedListener.onFailure(responseMsg);
                }
            });
        }
    }

    private void parseCuratedFeedsJson(String curatedFeedsResponseStr) {
        try {
            JSONObject mainJsonObject = new JSONObject(curatedFeedsResponseStr);
            double version = ((Number) mainJsonObject.get(VERSION)).doubleValue();
            String releaseDate = mainJsonObject.getString(RELEASE_DATE);
            String lastModified = mainJsonObject.getString(LAST_MODIFIED);

            List<SourceItem> sourceItems = new ArrayList<>();

            JSONArray curatedFeedsJsonObject = mainJsonObject.getJSONArray(CURATED_FEEDS);
            for (int i = 0; i < curatedFeedsJsonObject.length(); i++) {
                String sourceName = curatedFeedsJsonObject.getJSONObject(i).getString(SOURCE_NAME);
                String sourceUrl = curatedFeedsJsonObject.getJSONObject(i).getString(SOURCE_URL);
                String sourceCategory = curatedFeedsJsonObject.getJSONObject(i).getString(SOURCE_CATEGORY);

                SourceItem sourceItem = new SourceItem();
                sourceItem.setSourceName(sourceName);
                sourceItem.setSourceUrl(sourceUrl);
                sourceItem.setSourceCategoryName(sourceCategory);
// Path: app/src/main/java/com/crazyhitty/chdev/ks/munch/models/SourceItem.java
// public class SourceItem {
//     private String sourceName, sourceUrl, sourceCategoryName, sourceDateAdded;
//     private int sourceCategoryImgId;
// 
//     public int getSourceCategoryImgId() {
//         return sourceCategoryImgId;
//     }
// 
//     public void setSourceCategoryImgId(int sourceCategoryImgId) {
//         this.sourceCategoryImgId = sourceCategoryImgId;
//     }
// 
//     public String getSourceName() {
//         return sourceName;
//     }
// 
//     public void setSourceName(String sourceName) {
//         this.sourceName = sourceName;
//     }
// 
//     public String getSourceUrl() {
//         return sourceUrl;
//     }
// 
//     public void setSourceUrl(String sourceUrl) {
//         this.sourceUrl = sourceUrl;
//     }
// 
//     public String getSourceDateAdded() {
//         return sourceDateAdded;
//     }
// 
//     public void setSourceDateAdded(String sourceDateAdded) {
//         this.sourceDateAdded = sourceDateAdded;
//     }
// 
//     public String getSourceCategoryName() {
//         return sourceCategoryName;
//     }
// 
//     public void setSourceCategoryName(String sourceCategoryName) {
//         this.sourceCategoryName = sourceCategoryName;
//     }
// }
// 
// Path: app/src/main/java/com/crazyhitty/chdev/ks/munch/utils/DateUtil.java
// public class DateUtil {
//     String formatRfc2822 = "EEE, dd MMM yyyy HH:mm:ss Z";
//     String formatLocal = "EEE, d MMM yyyy";
//     private String date;
// 
//     public String getCurrDate() {
//         date = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss").format(new Date());
//         return date;
//     }
// 
//     //converts rss publish date into a readable format
//     public String getDate(String pubDate) throws ParseException {
//         Date date = getDateObj(pubDate);
//         return new SimpleDateFormat(formatLocal).format(date);
//     }
// 
//     //get Date object from pub date
//     public Date getDateObj(String pubDate) throws ParseException {
//         SimpleDateFormat pubDateFormat = new SimpleDateFormat(formatRfc2822, Locale.ENGLISH); //rss spec
//         Date date = null;
//         try {
//             date = pubDateFormat.parse(pubDate);
//         } catch (ParseException e) {
//             pubDateFormat = new SimpleDateFormat(formatLocal); //fallback
//             date = pubDateFormat.parse(pubDate);
//         }
//         return date;
//     }
// }


// Path: app/src/main/java/com/crazyhitty/chdev/ks/munch/curatedfeeds/CuratedFeedsInteractor.java
import android.content.Context;
import android.os.Handler;
import com.crazyhitty.chdev.ks.munch.models.SourceItem;
import com.crazyhitty.chdev.ks.munch.utils.DateUtil;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

            final String responseMsg = response.message();
            //run on the ui thread
            new Handler(mContext.getMainLooper()).post(new Runnable() {
                @Override
                public void run() {
                    mOnCuratedFeedsRetrievedListener.onFailure(responseMsg);
                }
            });
        }
    }

    private void parseCuratedFeedsJson(String curatedFeedsResponseStr) {
        try {
            JSONObject mainJsonObject = new JSONObject(curatedFeedsResponseStr);
            double version = ((Number) mainJsonObject.get(VERSION)).doubleValue();
            String releaseDate = mainJsonObject.getString(RELEASE_DATE);
            String lastModified = mainJsonObject.getString(LAST_MODIFIED);

            List<SourceItem> sourceItems = new ArrayList<>();

            JSONArray curatedFeedsJsonObject = mainJsonObject.getJSONArray(CURATED_FEEDS);
            for (int i = 0; i < curatedFeedsJsonObject.length(); i++) {
                String sourceName = curatedFeedsJsonObject.getJSONObject(i).getString(SOURCE_NAME);
                String sourceUrl = curatedFeedsJsonObject.getJSONObject(i).getString(SOURCE_URL);
                String sourceCategory = curatedFeedsJsonObject.getJSONObject(i).getString(SOURCE_CATEGORY);

                SourceItem sourceItem = new SourceItem();
                sourceItem.setSourceName(sourceName);
                sourceItem.setSourceUrl(sourceUrl);
                sourceItem.setSourceCategoryName(sourceCategory);
                sourceItem.setSourceDateAdded(new DateUtil().getCurrDate());