admin
2022-05-07 4c7cde7ae5ed57335405459e47de4bbd2726c4ba
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
package com.yeshi.makemoney.video.app.utils;
 
import android.content.Context;
import android.content.SharedPreferences;
 
import com.bytedance.sdk.dp.DPSdk;
import com.bytedance.sdk.dp.DPUpdate;
import com.demo.library_ad.AdUtil;
 
import cn.jpush.android.api.JPushInterface;
 
public class SettingUtil {
 
    public enum SettingKey {
        //是否显示资讯页面的提醒
        showNewsNotify(true),
        //推送免打扰
        pushUnDisturb(false),
        //广告推荐
        adRecommend(true),
        //内容推荐
        contentRecommend(true);
 
        private boolean defaultValue;
 
        private SettingKey(boolean defaultValue) {
            this.defaultValue = defaultValue;
        }
 
        public boolean isDefaultValue() {
            return defaultValue;
        }
    }
 
 
    public static void saveSetting(SettingKey key, boolean value, Context context) {
        SharedPreferences.Editor editor = context.getSharedPreferences("settings", Context.MODE_PRIVATE).edit();
        editor.putBoolean(key.name(), value);
        editor.commit();
        initSetting(key, value, context);
    }
 
    //初始化设置,在应用初始化完成后调用
    public static void initSettings(Context context) {
        for (SettingKey key : SettingKey.values()) {
            boolean value = getSetting(key, context);
            initSetting(key, value, context);
        }
    }
 
    private static void initSetting(SettingKey key, boolean value, Context context) {
        if (key == SettingKey.adRecommend) {
            AdUtil.setPersonalRecommend(value);
        } else if (key == SettingKey.contentRecommend) {
            //穿山甲内容个性化
            DPUpdate.setPersonalRec(value);
        } else if (key == SettingKey.pushUnDisturb) {
            if (value) {
                JPushInterface.setPushTime(context, null, 9, 21);
            } else {
                JPushInterface.setPushTime(context, null, 0, 23);
            }
        }
 
    }
 
 
    public static boolean getSetting(SettingKey key, Context context) {
        SharedPreferences share = context.getSharedPreferences("settings", Context.MODE_PRIVATE);
        return share.getBoolean(key.name(), key.isDefaultValue());
    }
 
 
}