package com.tutorial.passingdata.storage;
import android.content.Context;
import android.content.SharedPreferences;
/**
* Created by Shiburagi on 09-Jul-15.
*/
public class PreferencesMode {
private static final String FIRST_NAME_KEY = "frtnm";
private static final String LAST_NAME_KEY = "lstnm";
private final SharedPreferences sharedPreferences;
private final String MY_PREF_KEY="passingdata_tutorial";
public PreferencesMode(Context context){
sharedPreferences = context.getSharedPreferences(MY_PREF_KEY,Context.MODE_PRIVATE);
}
/**
* Retrieve first name value
* @return first name
*/
public String getFirstName(){
return sharedPreferences.getString(FIRST_NAME_KEY,"undefined");
}
/**
* retrieve last name value
* @return last name
*/
public String getLastName(){
return sharedPreferences.getString(LAST_NAME_KEY,"undefined");
}
/**
* store first name value
* @param firstName
*/
public void setFirstName(String firstName){
SharedPreferences.Editor editor=sharedPreferences.edit();
editor.putString(FIRST_NAME_KEY,firstName);
editor.commit();
}
/**
* store last name value
* @param lastname
*/
public void setLastName(String lastname){
SharedPreferences.Editor editor=sharedPreferences.edit();
editor.putString(LAST_NAME_KEY,lastname);
editor.commit();
}
}