admin
2021-03-27 214f9edd2fe20c20e32630e9b5380cc6271c1eb7
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
package com.weikou.beibeivideo.util;
 
import android.content.Context;
import android.content.SharedPreferences;
 
import com.lcjian.library.util.common.StringUtils;
 
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);
    }
 
 
    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;
    }
 
 
    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, "");
    }
 
 
}