admin
2021-08-27 d3a2058934c91d91ebb3a549701f267c66a83e52
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.hanju.video.app.util;
 
import android.content.Context;
import android.content.SharedPreferences;
 
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.hanju.video.app.util.downutils.StringUtils;
 
import static android.content.Context.MODE_PRIVATE;
 
public class UserUtil {
 
    private static Gson gson = new GsonBuilder().serializeNulls().create();
 
 
    /**
     * 是否同意了用户协议
     *
     * @param context
     * @return
     */
    public static boolean isAgreeUserProtocol(Context context) {
        SharedPreferences sp = context.getSharedPreferences("user", MODE_PRIVATE);
        String protocol = sp.getString("protocol-agree", "");
        return !StringUtils.isNullOrEmpty(protocol);
    }
 
 
    /**
     * 同意用户协议
     *
     * @param context
     */
    public static void agreeUserProtocol(Context context) {
        SharedPreferences sp = context.getSharedPreferences("user", MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putString("protocol-agree", "1");
        editor.commit();
    }
 
    public static String getUid(Context context) {
        SharedPreferences preferences = context.getSharedPreferences("user", MODE_PRIVATE);
        String uid = preferences.getString("uid", "");
        return uid;
    }
 
    public static String getLoginUid(Context context) {
        SharedPreferences preferences = context.getSharedPreferences("user", MODE_PRIVATE);
        return preferences.getString("loginUid", null);
    }
 
    public static void logout(Context context) {
        SharedPreferences preferences = context.getSharedPreferences("user", MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.remove("loginUid");
        editor.commit();
    }
 
    /**
     * 登录成功
     *
     * @param context
     * @param loginUid
     */
    public static void loginSuccess(Context context, String loginUid) {
        SharedPreferences preferences = context.getSharedPreferences("user", MODE_PRIVATE);
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString("loginUid", loginUid);
        editor.commit();
    }
}