| | |
| | | */ |
| | | public static UserInfo getUserInfo(Context context) { |
| | | SharedPreferences sp = context.getSharedPreferences("user", MODE_PRIVATE); |
| | | String userInfo = sp.getString("userinfo", ""); |
| | | String userInfo = sp.getString("userinfo_new", ""); |
| | | if (StringUtils.isNullOrEmpty(userInfo)) |
| | | return null; |
| | | JSONObject jsonObject = null; |
| | | try { |
| | | jsonObject = new JSONObject(userInfo); |
| | | } catch (JSONException e) { |
| | | return null; |
| | | } |
| | | UserInfo info = gson.fromJson(jsonObject.optJSONObject("data").optJSONObject("user").toString(), new TypeToken<UserInfo>() { |
| | | UserInfo info = gson.fromJson(userInfo, new TypeToken<UserInfo>() { |
| | | }.getType()); |
| | | return info; |
| | | } |
| | |
| | | return sp.getBoolean("isLogin", false); |
| | | } |
| | | |
| | | public static void setInviteCode(Context context, String uid, String inviteCode) { |
| | | public static void setInviteCode(Context context, String inviteCode) { |
| | | SharedPreferences sp = context.getSharedPreferences("user-info", Context.MODE_PRIVATE); |
| | | SharedPreferences.Editor editor = sp.edit(); |
| | | editor.putString("inviteCode", inviteCode); |
| | | editor.commit(); |
| | | } |
| | | |
| | | public static String getInviteCode(Context context, String uid) { |
| | | public static String getInviteCode(Context context) { |
| | | SharedPreferences sp = context.getSharedPreferences("user-info", Context.MODE_PRIVATE); |
| | | return sp.getString("inviteCode", ""); |
| | | } |
| | |
| | | public static UserLoginStatus getLoginState(Context context) { |
| | | boolean isLogin = isLogin(context); |
| | | if (isLogin) { |
| | | String inviteCode = getInviteCode(context, getUid(context) + ""); |
| | | String inviteCode = getInviteCode(context); |
| | | if (StringUtils.isNullOrEmpty(inviteCode)) |
| | | return UserLoginStatus.LOINGED_NO_ACTIVE; |
| | | else |
| | |
| | | editor.putBoolean("isWxBind", false); |
| | | editor.putString("uid", "0"); |
| | | editor.remove("userinfo"); |
| | | editor.remove("userinfo_new"); |
| | | editor.commit(); |
| | | |
| | | //清除个人信息缓存 |
| | |
| | | return resourceId; |
| | | } |
| | | |
| | | /** |
| | | * 登录成功 |
| | | * |
| | | * @param context |
| | | * @param info |
| | | */ |
| | | public static void loginSuccess(Context context, UserInfo info) { |
| | | SharedPreferences sp = context.getSharedPreferences("user", MODE_PRIVATE); |
| | | SharedPreferences.Editor editor = sp.edit(); |
| | | editor.putBoolean("isLogin", true); |
| | | editor.putBoolean("isFirstInput", false); |
| | | editor.putString("uid", info.getId()); |
| | | editor.putString("openid", info.getOpenid()); |
| | | editor.putString("portrait", info.getPortrait()); |
| | | editor.putString("userinfo_new", new Gson().toJson(info)); |
| | | editor.commit(); |
| | | MiPushClient.setAlias(context, info.getId(), null); |
| | | } |
| | | |
| | | |
| | | public static void jumpLogin(Context context) { |
| | | context.startActivity(new Intent(context, LoginSelectActivity.class)); |