admin
6 天以前 7f0825f8195a522ed7e8bcdb6347f3a719e06c74
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
package com.weikou.beibeivideo.util;
 
import android.content.Context;
import android.content.SharedPreferences;
 
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.lcjian.library.util.common.StringUtils;
import com.weikou.beibeivideo.entity.HomeAd;
import com.weikou.beibeivideo.entity.vo.BannerVO;
 
import org.json.JSONObject;
 
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
 
public class ConfigUtil {
 
    public static void saveVipLink(Context context, String link) {
        saveConfig("vipLink", link, context);
    }
 
    public static String getVipLink(Context context) {
        return getConfig("vipLink", context);
    }
 
 
    /**
     * 网页加速域名
     *
     * @param context
     * @param hosts
     */
    public static void saveWebSpeedUpHost(Context context, String hosts) {
        saveConfig("webSpeedUpHost", hosts, context);
    }
 
    public static Set<String> getWebSpeedUpHost(Context context) {
        Set<String> set = new HashSet<>();
        String value = getConfig("webSpeedUpHost", context);
        if (!StringUtils.isEmpty(value)) {
            set.addAll(Arrays.asList(value.split(",")));
        }
        return set;
    }
 
 
    /**
     * 我的页面banner
     *
     * @param context
     * @param content
     */
    public static void saveMinePageBanner(Context context, String content) {
        saveConfig("minePageBanner", content, context);
    }
 
    public static BannerVO getMinePageBanner(Context context) {
        try {
            String config = getConfig("minePageBanner", context);
            if (!StringUtils.isEmpty(config)) {
                JSONObject jsonObject = new JSONObject(config);
                JSONObject params = jsonObject.optJSONObject("params");
                jsonObject.remove("params");
                BannerVO bannerVO = new Gson().fromJson(jsonObject.toString(), BannerVO.class);
                if (params != null) {
                    bannerVO.setParams(params.toString());
                }
                if (bannerVO.isShow())
                    return bannerVO;
            }
        } catch (Exception e) {
            e.getMessage();
        }
        return null;
    }
 
 
    /**
     * 保存播放器外跳协议
     *
     * @param context
     * @param content
     */
    public static void savePlayerJumpOutProtocolPrefix(Context context, String content) {
        saveConfig("jumpAppProtocolPrefix", content, context);
    }
 
    public static Set<String> getPlayerJumpOutProtocolPrefix(Context context) {
        try {
            String config = getConfig("jumpAppProtocolPrefix", context);
            if (!StringUtils.isEmpty(config)) {
                Type type = new TypeToken<Set<String>>() {
                }.getType();
                return new Gson().fromJson(config, type);
            }
        } catch (Exception e) {
            e.getMessage();
        }
        return new HashSet<>();
    }
 
 
    /**
     * 保存购买记录
     *
     * @param context
     * @param content
     */
    public static void saveBuyRecordUrl(Context context, String content) {
        saveConfig("buyRecordUrl", content, context);
    }
 
 
    public static String getBuyRecordUrl(Context context) {
        return getConfig("buyRecordUrl", context);
    }
 
 
    public static void saveOnLining(Context context, boolean content) {
        saveConfig("onLining", content+"", context);
    }
 
 
    public static boolean isOnLining(Context context) {
        String onLine= getConfig("onLining", context);
        if(StringUtils.isEmpty(onLine)){
            return false;
        }
        return Boolean.parseBoolean(onLine);
    }
 
 
    public static void saveAiDaoMode(Context context, boolean content) {
        saveConfig("aiDaoMode", content+"", context);
    }
 
    public static boolean isAiDaoMode(Context context){
        String onLine= getConfig("aiDaoMode", context);
        if(StringUtils.isEmpty(onLine)){
            return false;
        }
        return Boolean.parseBoolean(onLine);
    }
 
 
    private static void saveConfig(String key, String value, Context context) {
        SharedPreferences.Editor editor = context.getSharedPreferences("config", Context.MODE_PRIVATE).edit();
        editor.putString(key, value);
        editor.commit();
    }
 
 
    private static String getConfig(String key, Context context) {
        if (context == null)
            return null;
        SharedPreferences share = context.getSharedPreferences("config", Context.MODE_PRIVATE);
        return share.getString(key, "");
    }
 
 
}