admin
2021-05-15 2aead6275fdd1bbbd778abc0e85663a2578fab06
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package com.tejia.lijin.app.util.share;
 
import android.content.Context;
import android.content.SharedPreferences;
 
import com.google.gson.Gson;
import com.wpc.library.util.common.StringUtils;
 
import org.json.JSONArray;
 
import java.util.HashSet;
import java.util.Set;
 
import static android.content.Context.MODE_PRIVATE;
 
public class ShareCacheUtil {
 
    /**
     * 保存单品分享图片的习惯
     *
     * @param context
     */
    public static void saveSingleGoodsShareImage(Context context, boolean allImage) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("share-single", Context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean("allImage", allImage);
        editor.commit();
    }
 
    public static boolean isSingleGoodsShareAllImage(Context context) {
        SharedPreferences sharedPreferences = context.getSharedPreferences("share-single", Context.MODE_PRIVATE);
        return sharedPreferences.getBoolean("allImage", false);
    }
 
 
    /**
     * 保存快速分享评论选择项
     *
     * @param context
     * @param currentChoicedSet
     */
    public static void saveFastShareCommentChoices(Context context, Set<Integer> currentChoicedSet) {
        SharedPreferences sp = context.getSharedPreferences("fastShare", MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putString("commentChoices", new Gson().toJson(currentChoicedSet));
        editor.commit();
    }
 
    /**
     * 获取快速分享保存的选择项
     *
     * @param context
     * @return
     */
    public static Set<Integer> getFastCommentChoices(Context context) {
        SharedPreferences sp = context.getSharedPreferences("fastShare", MODE_PRIVATE);
        String commentChoices = sp.getString("commentChoices", "");
        if (StringUtils.isBlank(commentChoices)) {
            commentChoices = "[]";
        }
        Set<Integer> commentChoicesList = new HashSet<>();
        try {
            JSONArray array = new JSONArray(commentChoices);
            for (int i = 0; i < array.length(); i++)
                commentChoicesList.add(array.optInt(i));
        } catch (Exception e) {
        }
 
        return commentChoicesList;
    }
 
 
    /**
     * 快速分享的分享图上是是否显示邀请码
     *
     * @param context
     * @param show
     */
    public static void saveFastShareImageShowInviteCode(Context context, boolean show) {
        SharedPreferences sp = context.getSharedPreferences("fastShare", MODE_PRIVATE);
        SharedPreferences.Editor editor = sp.edit();
        editor.putBoolean("imgShowInviteCode", show);
        editor.commit();
    }
 
 
    public static boolean isFastShareImageShowInviteCode(Context context) {
        SharedPreferences sp = context.getSharedPreferences("fastShare", MODE_PRIVATE);
        return sp.getBoolean("imgShowInviteCode", true);
    }
}