| | |
| | | import android.content.SharedPreferences; |
| | | import android.content.SharedPreferences.Editor; |
| | | |
| | | import com.moral.andbrickslib.utils.GsonUtil; |
| | | import com.moral.yunfushao.wxapi.data.AccessTokenBean; |
| | | import com.moral.yunfushao.MainApp; |
| | | import com.moral.yunfushao.model.User; |
| | | |
| | | public class SharedPreferencesUtil { |
| | | private Context mContext; |
| | | private static Context mContext = null; |
| | | public final static String SP_LOGIN_USER_KEY = "login_user"; |
| | | public final static String SP_BLE = "ble"; |
| | | public SharedPreferencesUtil(Context context) { |
| | | this.mContext = context; |
| | | |
| | | public static SharedPreferencesUtil getUtil(Context context) { |
| | | mContext = context; |
| | | return Instants.sharedPreferencesUtil; |
| | | } |
| | | |
| | | public static class Instants { |
| | | public static SharedPreferencesUtil sharedPreferencesUtil = new SharedPreferencesUtil(); |
| | | } |
| | | |
| | | /** |
| | | * 获取登陆模式,手机登陆和微信登陆 |
| | | * |
| | | * @return |
| | | */ |
| | | public static boolean getLoginModel() { |
| | | SharedPreferences preferences = mContext.getSharedPreferences(SP_LOGIN_USER_KEY, Context.MODE_PRIVATE); |
| | | return preferences.getBoolean("wx", false); |
| | | } |
| | | |
| | | /** |
| | | * 保存微信登陆Token |
| | | */ |
| | | public void saveWXToken(AccessTokenBean bean) { |
| | | SharedPreferences preferences = mContext.getSharedPreferences(SP_LOGIN_USER_KEY, Context.MODE_PRIVATE); |
| | | Editor edit = preferences.edit(); |
| | | edit.putString("token_wx", GsonUtil.toStr(bean)); |
| | | edit.commit(); |
| | | } |
| | | |
| | | /** |
| | | * 保存微信登陆Token |
| | | */ |
| | | public AccessTokenBean getWXToken() { |
| | | SharedPreferences preferences = mContext.getSharedPreferences(SP_LOGIN_USER_KEY, Context.MODE_PRIVATE); |
| | | String s = preferences.getString("token_wx", null); |
| | | if (s == null) { |
| | | return null; |
| | | } else |
| | | return GsonUtil.toObj(s, AccessTokenBean.class); |
| | | } |
| | | |
| | | /** |
| | | * 保存微信登陆Token |
| | | */ |
| | | public void removeWXToken() { |
| | | SharedPreferences preferences = mContext.getSharedPreferences(SP_LOGIN_USER_KEY, Context.MODE_PRIVATE); |
| | | Editor edit = preferences.edit(); |
| | | edit.putString("token_wx", null); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 保存蓝牙设备信息 |
| | | * |
| | | * @param mac |
| | | */ |
| | | public void saveBLE(String mac){ |
| | |
| | | return mac; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 账户登陆 |
| | | * 账户登陆清空微信登陆 |
| | | * |
| | | * @param loginUser |
| | | */ |
| | | public void saveLoginInfo(User loginUser){ |
| | | removeWXToken(); |
| | | SharedPreferences preferences = mContext.getSharedPreferences(SP_LOGIN_USER_KEY, Context.MODE_PRIVATE); |
| | | Editor editor = preferences.edit(); |
| | | editor.putString("id",loginUser.get_id()); |
| | |
| | | editor.putInt("video",video); |
| | | editor.commit(); |
| | | } |
| | | |
| | | public void setRefreh(int refresh){ |
| | | SharedPreferences preferences = mContext.getSharedPreferences(SP_LOGIN_USER_KEY, Context.MODE_PRIVATE); |
| | | Editor editor = preferences.edit(); |
| | |
| | | |
| | | /** |
| | | * 保存是否第一次登陆 |
| | | * |
| | | * @param flag |
| | | */ |
| | | public void saveFirstUse(int flag) { |
| | |
| | | |
| | | /** |
| | | * 铃声 |
| | | * |
| | | * @param video |
| | | */ |
| | | public void saveVideoList(String video) { |