package mn.devfest.schedule;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

/**
 * Stores and provides the sessions that the user has added to their schedule.
 * This class must be notified any time a session is added or removed from a user's schedule.
 * TODO when this class syncs with the API, we should move it to the api package
 *
 * @author pfuentes
 */
public class UserScheduleRepository {
    private static final String SCHEDULE_ID_STRING_SET_TAG = "SCHEDULE_IDS";

    Context mContext;
    SharedPreferences mSharedPreferences;

    public UserScheduleRepository (@NonNull Context context){
        mContext = context;
        mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
    }

    /**
     * Adds the session with the given ID to the user's schedule
     * @param sessionId ID of the session to be added
     */
    public void addSession(String sessionId) {
        //TODO implement
    }

    /**
     * Removes the session with the given ID from the user's schedule
     * @param sessionId ID of the session to be removed
     */
    public void removeSession(String sessionId) {
        //TODO implement
    }

    /**
     * Shares the list of IDs for all of the sessions in the user's schedule
     * @return List of IDs of the sessions in the user's schedule
     */
    public ArrayList<String> getScheduleIds() {
        //TODO implement
        return new ArrayList<>(); //TODO update return statement
    }

    /**
     * Checks if a given session is in the user's schedule
     * @param sessionId ID of the session to check for inclusion in the list
     * @return true if the session is in the user's schedule; otherwise false
     */
    public boolean isInSchedule(String sessionId) {
        //TODO implement
        return true; //TODO update return statement
    }

    private void setScheduleIdStringSet(@NonNull Set<String> stringSet) {
        SharedPreferences.Editor editor = mSharedPreferences.edit();
        editor.putStringSet(SCHEDULE_ID_STRING_SET_TAG, stringSet);
        editor.commit();
    }

    @NonNull
    private Set<String> getScheduleIdStringSet() {
        return mSharedPreferences.getStringSet(SCHEDULE_ID_STRING_SET_TAG, new HashSet<>());
    }
}

@@ -1102,32 +1102,154 @@
         
-//TODO implement
+ArrayList%3CString%3E scheduleIds = getScheduleIdStringSet();%0A        scheduleIds.add(sessionId);%0A        setScheduleIdStringSet(scheduleIds);
 %0A    %7D%0A%0A
@@ -2195,32 +2195,100 @@
 ull 
-Set%3CString%3E stringSet) %7B
+ArrayList%3CString%3E scheduleIds) %7B%0A        Set%3CString%3E stringSet = new HashSet%3C%3E(scheduleIds);
 %0A   
@@ -2478,18 +2478,24 @@
 private 
-Se
+ArrayLis
 t%3CString
@@ -2531,22 +2531,43 @@
         
-return
+Set%3CString%3E scheduleIdSet =
  mShared
@@ -2637,16 +2637,69 @@
 t%3C%3E());%0A
+        return new ArrayList%3CString%3E(scheduleIdSet);%0A
     %7D%0A%7D%0A

Isolate string sets to helper methods for ease of using Array Lists elsewhere Implement addSession()