admin
2021-04-02 545ce4665c1d506393908b55aafd681a45c774e6
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
package com.weikou.beibeivideo.util;
 
import android.content.Context;
import android.content.SharedPreferences;
 
import com.google.gson.Gson;
import com.lcjian.library.util.common.StringUtils;
import com.weikou.beibeivideo.entity.HomeAd;
import com.weikou.beibeivideo.entity.vo.BannerVO;
 
import java.util.Arrays;
import java.util.HashSet;
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)) {
                BannerVO bannerVO = new Gson().fromJson(config, BannerVO.class);
                return bannerVO;
            }
        } catch (Exception e) {
 
        }
        return null;
    }
 
 
    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, "");
    }
 
 
}