package com.hanju.video.app.util.common;
|
|
import android.content.Context;
|
import android.content.SharedPreferences;
|
|
import com.google.gson.Gson;
|
import com.google.gson.reflect.TypeToken;
|
import com.hanju.lib.library.util.common.StringUtils;
|
|
import java.lang.reflect.Type;
|
import java.util.HashSet;
|
import java.util.Set;
|
|
public class AppConfigUtil {
|
|
|
/**
|
* 保存广告APPID
|
*
|
* @param context
|
* @param gdtAppId
|
* @param csjAppId
|
*/
|
public static void saveADAPPId(Context context, String gdtAppId, String csjAppId) {
|
saveConfig("gdtAppId", gdtAppId, context);
|
saveConfig("csjAppId", csjAppId, context);
|
}
|
|
public static String getGDTAppId(Context context) {
|
return getConfig("gdtAppId", context);
|
}
|
|
public static String getCSJAppId(Context context) {
|
return getConfig("csjAppId", context);
|
}
|
|
|
/**
|
* 保存播放器外跳协议
|
*
|
* @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 link
|
*/
|
public static void saveConcatUsLink(Context context, String link) {
|
saveConfig("contactUs", link, context);
|
}
|
|
public static String getConcatUsLink(Context context) {
|
return getConfig("contactUs", context);
|
}
|
|
/**
|
* 保存注销链接
|
*
|
* @param context
|
* @param link
|
*/
|
public static void saveUnRegisterLink(Context context, String link) {
|
saveConfig("unRegister", link, context);
|
}
|
|
public static String getUnRegisterLink(Context context) {
|
return getConfig("unRegister", context);
|
}
|
|
|
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, "");
|
}
|
|
|
}
|