package com.cygnusa.hyperm.util;

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

public class StorePreference {
    private static SharedPreferences mSharedPreferences;
    private static SharedPreferences.Editor mPreferenceEditor;
    private static String SHARE_USER_INFO = "userinfo";
    private static String SHARE_KEY_UID = "uid";
    private static StorePreference instance = null;
    private Context mContext;

    public StorePreference(Context aContext) {
        mContext = aContext;
        mSharedPreferences = mContext.getSharedPreferences(GlobalData.PREFERENCES_NAME, Context.MODE_PRIVATE);
        mPreferenceEditor = mSharedPreferences.edit();
        mPreferenceEditor.apply();
    }

    public static StorePreference getInstance(Context context) {
        if (instance == null) {
            instance = new StorePreference(context);
            mSharedPreferences = context.getSharedPreferences(SHARE_USER_INFO, Context.MODE_PRIVATE);
            mPreferenceEditor = mSharedPreferences.edit();
            mPreferenceEditor.apply();
        }
        return instance;
    }


    public String getUID() {
        return mSharedPreferences.getString(SHARE_KEY_UID, "");
    }

    public void setString(String key, String value) {
        mPreferenceEditor.putString(key, value);
        mPreferenceEditor.apply();
    }

    public void setInt(String key, int value) {
        mPreferenceEditor.putInt(key, value);
        mPreferenceEditor.apply();
    }

    public String getStringValue(String key) {
        String aName = "";
        aName = mSharedPreferences.getString(key, null);
        return aName == null ? "" : aName;
    }

    public int getIntValue(String key) {
        return mSharedPreferences.getInt(key, -1);
    }

    public void setBoolean(String key, boolean value) {
        mPreferenceEditor.putBoolean(key, value);
        mPreferenceEditor.apply();
    }

    public boolean getBooleanValue(String key) {
        return mSharedPreferences.getBoolean(key, false);
    }


}