package mn.devfest.persistence;

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

import mn.devfest.api.model.Conference;

/**
 * Stores and provides information about the conference. The app is shipped with a local copy of
 * the latest conference information. As we get newer information from the API, this is updated.
 *
 * @author pfuentes
 */
public class ConferenceRepository {

    Context mContext;
    SharedPreferences mSharedPreferences;

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

    /**
     * Removes any existing persisted conference data and replaces it with the passed value
     *
     * @param conference most up-to-date conference information available
     */
    public void setConference(@Nullable Conference conference) {
        //TODO implement
    }

    /**
     * Provides the most recently persisted conference data
     *
     * @return persisted conference data
     */
    @NonNull
    public Conference getConference() {
        //TODO implement and remove dummy return
        return new Conference();
    }

}

@@ -229,24 +229,54 @@
 .Nullable;%0A%0A
+import com.google.gson.Gson;%0A%0A
 import mn.de
@@ -508,68 +508,224 @@
 .%0A *
-%0A * @author pfuentes%0A */%0Apublic class ConferenceRepository %7B
+ TODO evaluate if we want to use another persistence method, rather than SharedPreferences%0A *%0A * @author pfuentes%0A */%0Apublic class ConferenceRepository %7B%0A    private static final String CONFERENCE_KEY = %22CONFERENCE%22;
 %0A%0A  
@@ -785,16 +785,32 @@
 erences;
+%0A    Gson mGson;
 %0A%0A    pu
@@ -977,16 +977,44 @@
 ntext);%0A
+        mGson = new Gson();%0A
     %7D%0A%0A 
@@ -1122,432 +1122,1159 @@
    *
-%0A     * @param conference most up-to-date conference information available%0A     */%0A    public void setConference(@Nullable Conference conference) %7B%0A        //TODO implement%0A    %7D%0A%0A    /**%0A     * Provides the most recently persisted conference data%0A     *%0A     * @return persisted conference data%0A     */%0A    @NonNull%0A    public Conference getConference() %7B%0A        //TODO implement and remove dummy return%0A        return new
+ If you try to pass null as an argument, the data is not updated.%0A     * To delete all existing conference data, pass an empty %7B@link Conference%7D object%0A     *%0A     * @param conference most up-to-date conference information available%0A     */%0A    public void setConference(@Nullable Conference conference) %7B%0A        if (conference == null) %7B%0A            return;%0A        %7D%0A        SharedPreferences.Editor editor = mSharedPreferences.edit();%0A        String jsonString = mGson.toJson(conference);%0A        editor.putString(CONFERENCE_KEY, jsonString);%0A        editor.apply();%0A    %7D%0A%0A    /**%0A     * Provides the most recently persisted conference data%0A     * If no conference data is persisted, an empty %7B@link Conference%7D object is returned%0A     *%0A     * @return persisted conference data%0A     */%0A    @NonNull%0A    public Conference getConference() %7B%0A        String jsonString = mSharedPreferences.getString(CONFERENCE_KEY, null);%0A        if (jsonString == null) %7B%0A            //TODO update this to return the locally stored conference data & update the documentation%0A            return new Conference();%0A        %7D%0A        return mGson.fromJson(jsonString,
  Con
@@ -2276,25 +2276,30 @@
 , Conference
-(
+.class
 );%0A    %7D%0A%0A%7D%0A

Implement accessor and modifier for persisted conference data