Skip to content

Instantly share code, notes, and snippets.

@snadjafi
Created August 21, 2013 18:16
Show Gist options
  • Save snadjafi/6298002 to your computer and use it in GitHub Desktop.
Save snadjafi/6298002 to your computer and use it in GitHub Desktop.
persistent model
package com.kuapay.library.helperClass;
import android.content.Context;
import android.content.SharedPreferences;
public class DefaultTipHelper
{
//region Constant Variables
private static final String TIP_SETTING = "tip_setting";
private static final String DEFAULT_TIP = "0";
private final String email;
//endregion
//region Variables
private final SharedPreferences tipSettingsSharedPreferences;
private final SharedPreferences.Editor editor;
//endregion
//region Constructors
public DefaultTipHelper(Context context, String email)
{
tipSettingsSharedPreferences = context.getSharedPreferences(TIP_SETTING, 0);
editor = tipSettingsSharedPreferences.edit();
this.email = email;
}
//endregion
//region Getters
public String getTip()
{
String tip = tipSettingsSharedPreferences.getString(email,null);
if (tip == null)
{
editor.putString(email, DEFAULT_TIP).commit();
return DEFAULT_TIP;
}
return tip;
}
//endregion
//region Setters
public void setTip(String tip)
{
editor.putString(email, tip).commit();
}
//endregion
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment