package ai.pai.lensman.db;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by chengzhenyu on 2015/8/24.
 */
public class Preferences {

    private Context context;
    private SharedPreferences mPrefs;
    private static Preferences instance;
    private static final String NullStr = "";

    private Preferences(Context context) {
        this.context = context.getApplicationContext();
        mPrefs = this.context.getSharedPreferences("prefs", Context.MODE_PRIVATE);
    }

    public static synchronized Preferences getInstance(Context context) {

        if (instance == null) {
            instance = new Preferences(context);
        }
        return instance;
    }


    public void setLastRunDate(String date) {
        mPrefs.edit().putString("lastRunDate", date).commit();
    }

    public String getLastRunDate() {
        return mPrefs.getString("lastRunDate", "1970-01-01");
    }

    public void setUserName(String userName){
        mPrefs.edit().putString("userName",userName).commit();
    }

    public String getUserName(){
        return mPrefs.getString("userName",NullStr);
    }

    public void setNickName(String nickName){
        mPrefs.edit().putString("nickName",nickName).commit();
    }

    public String getNickName(){
        return mPrefs.getString("nickName",NullStr);
    }

    public void setUserId(String userId){
        mPrefs.edit().putString("userId",userId).commit();
    }

    public String getUserId(){
        return mPrefs.getString("userId",NullStr);
    }

    public void clearPrefs(){
        mPrefs.edit().clear().commit();
    }
}
