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());
|
}
|
|
|
}
|