// Path: app/src/main/java/com/oklab/gitjourney/data/ContributionDataEntry.java
// public class ContributionDataEntry {
//     private final long entryId;
//     private final String entryURL;
//     private final String title;
//     private final String description;
//     private final ActionType actionType;
//     private final Calendar date;
// 
//     public ContributionDataEntry(long entryId, String entryURL, String title, String description, ActionType actionType, Calendar date) {
//         this.entryId = entryId;
//         this.entryURL = entryURL;
//         this.title = title;
//         this.description = description;
//         this.actionType = actionType;
//         this.date = date;
//     }
// 
//     public long getEntryId() {
//         return entryId;
//     }
// 
//     public String getEntryURL() {
//         return entryURL;
//     }
// 
//     public String getTitle() {
//         return title;
//     }
// 
//     public String getDescription() {
//         return description;
//     }
// 
//     public ActionType getActionType() {
//         return actionType;
//     }
// 
//     public Calendar getDate() {
//         return date;
//     }
// }
// 
// Path: app/src/main/java/com/oklab/gitjourney/data/UserSessionData.java
// public class UserSessionData {
// 
//     private final String id;
//     private final String credentials;
//     private final String token;
//     private final String login;
// 
// 
//     public UserSessionData(String id, String credentials, String token, String login) {
//         this.id = id;
//         this.credentials = credentials;
//         this.token = token;
//         this.login = login;
//     }
// 
//     public static UserSessionData createUserSessionDataFromString(String data) {
//         if (data == null || data.isEmpty()) {
//             return null;
//         }
//         String[] array = data.split(";");
//         return new UserSessionData(array[0], array[1], array[2], array[3]);
//     }
// 
//     public String getLogin() {
//         return login;
//     }
// 
//     public String getId() {
//         return id;
//     }
// 
//     public String getCredentials() {
//         return credentials;
//     }
// 
//     public String getToken() {
//         return token;
//     }
// 
//     @Override
//     public String toString() {
//         return id + ";" + credentials + ";" + token + ";" + login;
//     }
// }
// 
// Path: app/src/main/java/com/oklab/gitjourney/utils/Utils.java
// public final class Utils {
//     public static final String SHARED_PREF_NAME = "com.ok.lab.GitJourney";
//     public static final String DMY_DATE_FORMAT_PATTERN = "dd-MM-yyyy";
//     private static final int REQUEST_EXTERNAL_STORAGE = 1;
//     private static String[] PERMISSIONS_STORAGE = {
//             Manifest.permission.READ_EXTERNAL_STORAGE,
//             Manifest.permission.WRITE_EXTERNAL_STORAGE
//     };
// 
//     private Utils() {
// 
//     }
// 
//     public static void verifyStoragePermissions(Activity activity) {
//         // Check if we have write permission
//         int permission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE);
//         Log.e("TAG", "verifyStoragePermissions");
//         if (permission != PackageManager.PERMISSION_GRANTED) {
//             // We don't have permission so prompt the user
//             ActivityCompat.requestPermissions(
//                     activity,
//                     PERMISSIONS_STORAGE,
//                     REQUEST_EXTERNAL_STORAGE
//             );
//         }
//     }
// 
//     public static DateFormat createDateFormatterWithTimeZone(Context context, String pattern) {
//         SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
//         boolean timeZone = sharedPref.getBoolean("timezone_switch", true);
//         SimpleDateFormat formatter = new SimpleDateFormat(pattern, Locale.getDefault());
//         if (timeZone) {
//             formatter.setTimeZone(TimeZone.getDefault());
//         } else {
//             String customTimeZone = sharedPref.getString("timezone_list", TimeZone.getDefault().getID());
//             formatter.setTimeZone(TimeZone.getTimeZone(customTimeZone));
//         }
//         return formatter;
//     }
// 
//     public static String getStackTrace(Exception e) {
//         StringWriter writer = new StringWriter();
//         PrintWriter printer = new PrintWriter(writer);
//         e.printStackTrace(printer);
//         printer.close();
//         return writer.toString();
//     }
// }


import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.util.Log;
import com.oklab.gitjourney.R;
import com.oklab.gitjourney.data.ContributionDataEntry;
import com.oklab.gitjourney.data.UserSessionData;
import com.oklab.gitjourney.parsers.ContributionsParser;
import com.oklab.gitjourney.utils.Utils;
import org.apache.commons.io.IOUtils;
import org.json.JSONArray;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.List;
package com.oklab.gitjourney.asynctasks;





/**
 * Created by olgakuklina on 2017-02-28.
 */

public class ContributionsAsyncTask extends AsyncTask<Integer, Void, List<ContributionDataEntry>> {
    private static final String TAG = ContributionsAsyncTask.class.getSimpleName();
    private final Context context;
    private UserSessionData currentSessionData;
    private ContributionsAsyncTask.OnContributionsLoadedListener listener;

    public ContributionsAsyncTask(Context context, ContributionsAsyncTask.OnContributionsLoadedListener listener) {
        this.context = context;
        this.listener = listener;
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        SharedPreferences prefs = context.getSharedPreferences(Utils.SHARED_PREF_NAME, 0);
        String sessionDataStr = prefs.getString("userSessionData", null);
// Path: app/src/main/java/com/oklab/gitjourney/data/ContributionDataEntry.java
// public class ContributionDataEntry {
//     private final long entryId;
//     private final String entryURL;
//     private final String title;
//     private final String description;
//     private final ActionType actionType;
//     private final Calendar date;
// 
//     public ContributionDataEntry(long entryId, String entryURL, String title, String description, ActionType actionType, Calendar date) {
//         this.entryId = entryId;
//         this.entryURL = entryURL;
//         this.title = title;
//         this.description = description;
//         this.actionType = actionType;
//         this.date = date;
//     }
// 
//     public long getEntryId() {
//         return entryId;
//     }
// 
//     public String getEntryURL() {
//         return entryURL;
//     }
// 
//     public String getTitle() {
//         return title;
//     }
// 
//     public String getDescription() {
//         return description;
//     }
// 
//     public ActionType getActionType() {
//         return actionType;
//     }
// 
//     public Calendar getDate() {
//         return date;
//     }
// }
// 
// Path: app/src/main/java/com/oklab/gitjourney/data/UserSessionData.java
// public class UserSessionData {
// 
//     private final String id;
//     private final String credentials;
//     private final String token;
//     private final String login;
// 
// 
//     public UserSessionData(String id, String credentials, String token, String login) {
//         this.id = id;
//         this.credentials = credentials;
//         this.token = token;
//         this.login = login;
//     }
// 
//     public static UserSessionData createUserSessionDataFromString(String data) {
//         if (data == null || data.isEmpty()) {
//             return null;
//         }
//         String[] array = data.split(";");
//         return new UserSessionData(array[0], array[1], array[2], array[3]);
//     }
// 
//     public String getLogin() {
//         return login;
//     }
// 
//     public String getId() {
//         return id;
//     }
// 
//     public String getCredentials() {
//         return credentials;
//     }
// 
//     public String getToken() {
//         return token;
//     }
// 
//     @Override
//     public String toString() {
//         return id + ";" + credentials + ";" + token + ";" + login;
//     }
// }
// 
// Path: app/src/main/java/com/oklab/gitjourney/utils/Utils.java
// public final class Utils {
//     public static final String SHARED_PREF_NAME = "com.ok.lab.GitJourney";
//     public static final String DMY_DATE_FORMAT_PATTERN = "dd-MM-yyyy";
//     private static final int REQUEST_EXTERNAL_STORAGE = 1;
//     private static String[] PERMISSIONS_STORAGE = {
//             Manifest.permission.READ_EXTERNAL_STORAGE,
//             Manifest.permission.WRITE_EXTERNAL_STORAGE
//     };
// 
//     private Utils() {
// 
//     }
// 
//     public static void verifyStoragePermissions(Activity activity) {
//         // Check if we have write permission
//         int permission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE);
//         Log.e("TAG", "verifyStoragePermissions");
//         if (permission != PackageManager.PERMISSION_GRANTED) {
//             // We don't have permission so prompt the user
//             ActivityCompat.requestPermissions(
//                     activity,
//                     PERMISSIONS_STORAGE,
//                     REQUEST_EXTERNAL_STORAGE
//             );
//         }
//     }
// 
//     public static DateFormat createDateFormatterWithTimeZone(Context context, String pattern) {
//         SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
//         boolean timeZone = sharedPref.getBoolean("timezone_switch", true);
//         SimpleDateFormat formatter = new SimpleDateFormat(pattern, Locale.getDefault());
//         if (timeZone) {
//             formatter.setTimeZone(TimeZone.getDefault());
//         } else {
//             String customTimeZone = sharedPref.getString("timezone_list", TimeZone.getDefault().getID());
//             formatter.setTimeZone(TimeZone.getTimeZone(customTimeZone));
//         }
//         return formatter;
//     }
// 
//     public static String getStackTrace(Exception e) {
//         StringWriter writer = new StringWriter();
//         PrintWriter printer = new PrintWriter(writer);
//         e.printStackTrace(printer);
//         printer.close();
//         return writer.toString();
//     }
// }


// Path: app/src/main/java/com/oklab/gitjourney/asynctasks/ContributionsAsyncTask.java
import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.util.Log;
import com.oklab.gitjourney.R;
import com.oklab.gitjourney.data.ContributionDataEntry;
import com.oklab.gitjourney.data.UserSessionData;
import com.oklab.gitjourney.parsers.ContributionsParser;
import com.oklab.gitjourney.utils.Utils;
import org.apache.commons.io.IOUtils;
import org.json.JSONArray;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.List;

package com.oklab.gitjourney.asynctasks;





/**
 * Created by olgakuklina on 2017-02-28.
 */

public class ContributionsAsyncTask extends AsyncTask<Integer, Void, List<ContributionDataEntry>> {
    private static final String TAG = ContributionsAsyncTask.class.getSimpleName();
    private final Context context;
    private UserSessionData currentSessionData;
    private ContributionsAsyncTask.OnContributionsLoadedListener listener;

    public ContributionsAsyncTask(Context context, ContributionsAsyncTask.OnContributionsLoadedListener listener) {
        this.context = context;
        this.listener = listener;
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        SharedPreferences prefs = context.getSharedPreferences(Utils.SHARED_PREF_NAME, 0);
        String sessionDataStr = prefs.getString("userSessionData", null);
        currentSessionData = UserSessionData.createUserSessionDataFromString(sessionDataStr);