// Path: app/src/main/java/com/commonslab/commonslab/Utils/Today.java
// public class Today {
//     public String date() {
//         Calendar c = Calendar.getInstance();
//         SimpleDateFormat month = new SimpleDateFormat("MMMM");
//         SimpleDateFormat day = new SimpleDateFormat("d");
//         String formattedMonth = month.format(c.getTime());
//         String formattedDay = day.format(c.getTime());
//         return formattedMonth + " " + formattedDay;
//     }
// }


import android.content.Context;
import android.content.SharedPreferences;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.commonslab.commonslab.R;
import com.commonslab.commonslab.Utils.Today;
import java.lang.reflect.Type;
import java.util.ArrayList;
import apiwrapper.commons.wikimedia.org.Models.FeedItem;
import apiwrapper.commons.wikimedia.org.Enums.MediaType;
import apiwrapper.commons.wikimedia.org.Models.Contribution;
    public boolean usersContributionsAvailable() {
        preferences = context.getSharedPreferences(context.getString(R.string.User_Contributions), Context.MODE_PRIVATE);
        return preferences.getBoolean("ContributionsAvailable", false);
    }

    public ArrayList<Contribution> retrieveUserContributions() {
        preferences = context.getSharedPreferences(context.getString(R.string.User_Contributions), Context.MODE_PRIVATE);
        String contributions;
        //Check if contributions are previously stored
        if ((contributions = preferences.getString("Contributions", null)) == null) return null;
        if (contributions.equals("")) return null;//no uploads from this user

        Gson gson = new Gson();
        Type type = new TypeToken<ArrayList<Contribution>>() {
        }.getType();
        return gson.fromJson(contributions, type);
    }


    //Store RSS feed, Picture and Media of the day
    public void storeRSS_Feed(ArrayList<FeedItem> list, MediaType mediaType) {
        if (mediaType == MediaType.PICTURE) {
            preferences = context.getSharedPreferences(context.getString(R.string.Picture_of_the_day), Context.MODE_PRIVATE);
        } else {
            preferences = context.getSharedPreferences(context.getString(R.string.Media_of_the_day), Context.MODE_PRIVATE);
        }
        SharedPreferences.Editor prefsEditor = preferences.edit();
        Gson gson = new Gson();
        String json = gson.toJson(list);
        //Store date of this RSS feed
// Path: app/src/main/java/com/commonslab/commonslab/Utils/Today.java
// public class Today {
//     public String date() {
//         Calendar c = Calendar.getInstance();
//         SimpleDateFormat month = new SimpleDateFormat("MMMM");
//         SimpleDateFormat day = new SimpleDateFormat("d");
//         String formattedMonth = month.format(c.getTime());
//         String formattedDay = day.format(c.getTime());
//         return formattedMonth + " " + formattedDay;
//     }
// }


// Path: app/src/main/java/com/commonslab/commonslab/Utils/SharedPreferencesUtils/StorageUtil.java
import android.content.Context;
import android.content.SharedPreferences;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.commonslab.commonslab.R;
import com.commonslab.commonslab.Utils.Today;
import java.lang.reflect.Type;
import java.util.ArrayList;
import apiwrapper.commons.wikimedia.org.Models.FeedItem;
import apiwrapper.commons.wikimedia.org.Enums.MediaType;
import apiwrapper.commons.wikimedia.org.Models.Contribution;

    public boolean usersContributionsAvailable() {
        preferences = context.getSharedPreferences(context.getString(R.string.User_Contributions), Context.MODE_PRIVATE);
        return preferences.getBoolean("ContributionsAvailable", false);
    }

    public ArrayList<Contribution> retrieveUserContributions() {
        preferences = context.getSharedPreferences(context.getString(R.string.User_Contributions), Context.MODE_PRIVATE);
        String contributions;
        //Check if contributions are previously stored
        if ((contributions = preferences.getString("Contributions", null)) == null) return null;
        if (contributions.equals("")) return null;//no uploads from this user

        Gson gson = new Gson();
        Type type = new TypeToken<ArrayList<Contribution>>() {
        }.getType();
        return gson.fromJson(contributions, type);
    }


    //Store RSS feed, Picture and Media of the day
    public void storeRSS_Feed(ArrayList<FeedItem> list, MediaType mediaType) {
        if (mediaType == MediaType.PICTURE) {
            preferences = context.getSharedPreferences(context.getString(R.string.Picture_of_the_day), Context.MODE_PRIVATE);
        } else {
            preferences = context.getSharedPreferences(context.getString(R.string.Media_of_the_day), Context.MODE_PRIVATE);
        }
        SharedPreferences.Editor prefsEditor = preferences.edit();
        Gson gson = new Gson();
        String json = gson.toJson(list);
        //Store date of this RSS feed
        prefsEditor.putString("Date", new Today().date());