admin
2021-05-28 5965c01b38a2e83cecd7616daa11185fc2499303
app/src/main/java/com/tejia/lijin/app/util/user/UserUtil.java
@@ -33,16 +33,10 @@
     */
    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;
    }
@@ -130,14 +124,14 @@
        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", "");
    }
@@ -151,7 +145,7 @@
    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
@@ -169,6 +163,7 @@
        editor.putBoolean("isWxBind", false);
        editor.putString("uid", "0");
        editor.remove("userinfo");
        editor.remove("userinfo_new");
        editor.commit();
        //清除个人信息缓存
@@ -215,6 +210,25 @@
        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));