package com.ym.modulecommon.utils;

import android.content.SharedPreferences;
import android.text.TextUtils;
import com.ayl.ces.jni.CesCore;
import com.ym.modulecommon.AppliContext;
import com.ym.modulecommon.AdConstant;
import com.ym.modulecommon.net.NetConfig;
import org.jetbrains.annotations.Nullable;
import java.util.UUID;


/**
 * Created by gaoleichao on 2018/5/5.
 */
public class AdPreference {
    private static final String USER_SETTING = "ad_user_setting";
    private static final String INIT_SETTING = "ad_init_setting";

    private static final String USER_TOKEN_KEY = "user_token_keys";
    private static final String USER_ID = "user_id";
    private static final String APP_SECRET = "app_secret";

    /*公共参数二级缓存*/
    private static final String USER_AGENT = "userAgent";
    private static final String MODEL = "model";
    private static final String ANDROID_ID = "android_id";
    private static final String CARRIER = "carrier";
    private static final String W = "w";
    private static final String H = "h";
    private static final String SOURCE = "sourch";
    private static final String IP = "ip";
    private static final String SVN = "svn";

    private static final String DEVICE = "device";

    private static final String IMEI = "imei";
    private static final String SSID = "ssid";
    private static final String IMSI = "imsi";
    private static final String MAC = "mac";
    private static final String UA = "ua";
    private static final String VC = "vc";
    private static final String VN = "vn";
    private static final String NTT = "ntt";

    private static final String SEC_MD5 = "sec_md5";
    private static final String SEC_DESC = "sec_desc";

    private static final String SIGN_SESSIONID = "sign_sessionid";
    private static final String IS_FIRST_LOGIN_DIALOG = "is_first_login_dialog";
    private static final String LAT = "lat";
    private static final String LON = "lon";
    private static final String CITY = "city";
    private static final String LOCATION_TYPE = "location_type";
    private static final String SPLASH_INVREVAL = "splash_intreval";

    private static final String TRACK_ID = "track_id";
    private static final String TERMINAL_ID = "terminalId";
    private static final String USER_INFRO_NAME = "user_infro_name";
    private static final String OAID = "oaid";
    private static final String FIRST_REPORT = "first_report";//首次上报

    public static String getUserAgent() {
        String userAgent = AdConstant.param.userAgent;
        if (TextUtils.isEmpty(userAgent)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            return settings.getString(USER_AGENT, "");
        }
        return userAgent;
    }

    public static void setUserAgent(String userAgent) {
        AdConstant.param.userAgent = TextUtils.isEmpty(userAgent) ? "" : userAgent;
        if (!TextUtils.isEmpty(AdConstant.param.userAgent)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putString(USER_AGENT, AdConstant.param.userAgent);
            editor.commit();
        }
    }

    public static String getModel() {
        String model = AdConstant.param.model;
        if (TextUtils.isEmpty(model)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            return settings.getString(MODEL, PhoneUtils.INSTANCE.getModel());
        }
        return model;
    }

    public static void setModel(String model) {
        AdConstant.param.model = TextUtils.isEmpty(model) ? "" : model;
        if (!TextUtils.isEmpty(AdConstant.param.model)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putString(MODEL, AdConstant.param.model);
            editor.commit();
        }
    }

    public static String getAndroidId() {
        String androidId = AdConstant.param.androidId;
        if (TextUtils.isEmpty(androidId)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            return settings.getString(ANDROID_ID, PhoneUtils.INSTANCE.getAndroidID(AppliContext.get()));
        }
        return androidId;
    }

    public static void setAndroidId(String androidId) {
        AdConstant.param.androidId = TextUtils.isEmpty(androidId) ? "" : androidId;
        if (!TextUtils.isEmpty(AdConstant.param.androidId)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putString(ANDROID_ID, AdConstant.param.androidId);
            editor.commit();
        }
    }

    public static String getCarrier() {
        String carrier = AdConstant.param.carrier;
        if (TextUtils.isEmpty(carrier)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            return settings.getString(CARRIER, PhoneUtils.INSTANCE.getOperator(AppliContext.get()));
        }
        return carrier;
    }

    public static void setCarrier(String carrier) {
        AdConstant.param.carrier = TextUtils.isEmpty(carrier) ? "" : carrier;
        if (!TextUtils.isEmpty(AdConstant.param.carrier)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putString(CARRIER, AdConstant.param.carrier);
            editor.commit();
        }
    }

    public static String getW() {
        String w = AdConstant.param.w;
        if (TextUtils.isEmpty(w)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            return settings.getString(W, PhoneUtils.INSTANCE.getScreenWidth(AppliContext.get()) + "");
        }
        return w;
    }

    public static void setW(String w) {
        AdConstant.param.w = TextUtils.isEmpty(w) ? "" : w;
        if (!TextUtils.isEmpty(AdConstant.param.w)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putString(W, AdConstant.param.w);
            editor.commit();
        }
    }

    public static String getH() {
        String h = AdConstant.param.h;
        if (TextUtils.isEmpty(h)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            return settings.getString(H, PhoneUtils.INSTANCE.getScreenHeight(AppliContext.get()) + "");
        }
        return h;
    }

    public static void setH(String h) {
        AdConstant.param.h = TextUtils.isEmpty(h) ? "" : h;
        if (!TextUtils.isEmpty(AdConstant.param.h)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putString(H, AdConstant.param.h);
            editor.commit();
        }
    }

    public static String getDevice() {
        String device = AdConstant.param.device;
        try {
            if (TextUtils.isEmpty(device)) {
                SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
                return settings.getString(DEVICE, PhoneUtils.INSTANCE.getDeviceId(AppliContext.get()));
            }
        } catch (Exception e) {
            return "";
        }
        return device;
    }

    public static void setDevice(String device) {
        AdConstant.param.device = TextUtils.isEmpty(device) ? "" : device;
        if (!TextUtils.isEmpty(AdConstant.param.device)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putString(DEVICE, AdConstant.param.device);
            editor.commit();
        }
    }

    public static String getImei() {
        String imei = AdConstant.param.imei;
        if (TextUtils.isEmpty(imei)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            return settings.getString(IMEI, PhoneUtils.INSTANCE.getImei(AppliContext.get()));
        }
        return imei;
    }

    public static void setImei(String imei) {
        AdConstant.param.imei = TextUtils.isEmpty(imei) ? "" : imei;
        if (!TextUtils.isEmpty(AdConstant.param.imei)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putString(IMEI, AdConstant.param.imei);
            editor.commit();
        }
    }

    public static String getSsid() {
        String ssid = AdConstant.param.ssid;
        if (TextUtils.isEmpty(ssid)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            return settings.getString(SSID, PhoneUtils.INSTANCE.getBSSID(AppliContext.get()));
        }
        return ssid;
    }

    public static void setSsid(String ssid) {
        AdConstant.param.ssid = TextUtils.isEmpty(ssid) ? "" : ssid;
        if (!TextUtils.isEmpty(AdConstant.param.ssid)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            SharedPreferences.Editor editor = settings.edit();
            AdConstant.param.ssid.replace(":", "");
            editor.putString(SSID, AdConstant.param.ssid);
            editor.commit();
        }
    }


    public static String getImsi() {
        String imsi = AdConstant.param.imsi;
        if (TextUtils.isEmpty(imsi)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            return settings.getString(IMSI, PhoneUtils.INSTANCE.getIMSI(AppliContext.get()));
        }
        return imsi;
    }

    public static void setImsi(String imsi) {
        AdConstant.param.imsi = TextUtils.isEmpty(imsi) ? "" : imsi;
        if (!TextUtils.isEmpty(AdConstant.param.imsi)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putString(IMSI, AdConstant.param.imsi);
            editor.commit();
        }
    }

    public static String getMac() {
        String mac = AdConstant.param.mac;
        if (TextUtils.isEmpty(mac)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            return settings.getString(MAC, PhoneUtils.INSTANCE.getMac(AppliContext.get()));
        }
        return mac;
    }

    public static void setMac(String mac) {
        AdConstant.param.mac = TextUtils.isEmpty(mac) ? "" : mac;
        if (!TextUtils.isEmpty(AdConstant.param.mac)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putString(MAC, AdConstant.param.mac);
            editor.commit();
        }
    }

    public static String getIp() {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(IP, "");
    }

    public static void setIp(String ip) {
        SharedPreferences sharedPre = AppliContext.get().getSharedPreferences(
                USER_SETTING, AppliContext.get().MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPre.edit();
        editor.putString(IP, ip);
        editor.commit();
    }

    public static String getUA() {
        String ua = AdConstant.param.ua;
        if (TextUtils.isEmpty(ua)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            return settings.getString(UA, System.getProperty("http.agent"));
        }
        return ua;
    }

    public static void setUA(String ua) {
        AdConstant.param.ua = TextUtils.isEmpty(ua) ? "" : ua;
        if (!TextUtils.isEmpty(AdConstant.param.ua)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putString(UA, AdConstant.param.ua);
            editor.commit();
        }
    }

    public static String getVC() {
        String vc = AdConstant.param.vc;
        if (TextUtils.isEmpty(vc)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            return settings.getString(VC, PhoneUtils.INSTANCE.getAppVersionCode(AppliContext.get()) + "");
        }
        return vc;
    }

    public static void setVC(String vc) {
        AdConstant.param.vc = TextUtils.isEmpty(vc) ? "" : vc;
        if (!TextUtils.isEmpty(AdConstant.param.vc)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putString(VC, AdConstant.param.vc);
            editor.commit();
        }
    }

    public static String getVN() {
        String vn = AdConstant.param.vn;
        if (TextUtils.isEmpty(vn)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            return settings.getString(VN, PhoneUtils.INSTANCE.getAppVersionName(AppliContext.get()));
        }
        return vn;
    }

    public static void setVN(String vn) {
        AdConstant.param.vn = TextUtils.isEmpty(vn) ? "" : vn;
        if (!TextUtils.isEmpty(AdConstant.param.vn)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putString(VN, AdConstant.param.vn);
            editor.commit();
        }
    }

    public static String getSource() {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);

        String source = settings.getString(SOURCE, "");
        if (TextUtils.isEmpty(source)) {
            source = Utils.getChannel(AppliContext.get());
            if (!TextUtils.isEmpty(source)) {
                setSource(source);
            }
        }

        return source;
    }

    public static void setSource(String source) {
        SharedPreferences sharedPre = AppliContext.get().getSharedPreferences(
                USER_SETTING, AppliContext.get().MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPre.edit();
        editor.putString(SOURCE, source);
        editor.commit();
    }

    public static String getSVN() {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(SVN, "");
    }

    public static void setSVN(String svn) {
        SharedPreferences sharedPre = AppliContext.get().getSharedPreferences(
                USER_SETTING, AppliContext.get().MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPre.edit();
        editor.putString(SVN, svn);
        editor.commit();
    }

    public static String getNTT() {
        String ntt = AdConstant.param.ntt;
        if (TextUtils.isEmpty(ntt)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            return settings.getString(NTT, PhoneUtils.INSTANCE.getNetworkType(AppliContext.get()).toString());
        }
        return ntt;
    }

    public static void setNTT(String ntt) {
        AdConstant.param.ntt = TextUtils.isEmpty(ntt) ? "" : ntt;
        if (!TextUtils.isEmpty(AdConstant.param.ntt)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putString(NTT, AdConstant.param.ntt);
            editor.commit();
        }
    }

    public static String getUid() {
        String uid = AdConstant.param.uid;
        if (TextUtils.isEmpty(uid)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            return settings.getString(USER_ID, "");
        }
        return uid;
    }

    public static void setUid(String uid) {
        AdConstant.param.uid = TextUtils.isEmpty(uid) ? "" : uid;
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString(USER_ID, AdConstant.param.uid);
        editor.commit();
    }


    public static String getMd5() {
        String md5 = AdConstant.param.md5;
        if (TextUtils.isEmpty(md5)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            return settings.getString(SEC_MD5, "");
        }
        return md5;
    }

    public static void saveMd5(String md5) {
        AdConstant.param.md5 = TextUtils.isEmpty(md5) ? "" : md5;
        if (!TextUtils.isEmpty(AdConstant.param.md5)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putString(SEC_MD5, AdConstant.param.md5);
            editor.commit();
        }
    }

    public static String getSecDesc() {
        String sec_desc = AdConstant.param.sec_desc;
        if (TextUtils.isEmpty(sec_desc)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            return settings.getString(SEC_DESC, "");
        }
        return sec_desc;
    }

    public static void saveSecDesc(String sec_desc) {
        AdConstant.param.sec_desc = TextUtils.isEmpty(sec_desc) ? "" : sec_desc;
        if (!TextUtils.isEmpty(AdConstant.param.sec_desc)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putString(SEC_DESC, AdConstant.param.sec_desc);
            editor.commit();
        }
    }

    public static void saveToken(String token) {
        AdConstant.param.token = TextUtils.isEmpty(token) ? "" : token;
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString(USER_TOKEN_KEY, AdConstant.param.token);
        editor.commit();
    }

    public static String getToken() {
        String token = AdConstant.param.token;
        if (TextUtils.isEmpty(token)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            return settings.getString(AdConstant.Device.token, "");
        }
        return token;
    }

    public static void setToken(String token) {
        AdConstant.param.token = token;
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString(AdConstant.Device.token, AdConstant.param.token);
        editor.commit();
    }

    // 保存广点通配置信息
    public static void saveSlotGDT(String gdtStr) {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(INIT_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("gdtStr", gdtStr).commit();
    }

    public static String getSlotGDT() {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(INIT_SETTING, 0);
        String gdtStr = settings.getString("gdtStr", "");
        return gdtStr;
    }


    // 保存穿山甲配置信息
    public static void saveSlotJrtt(String jrttStr) {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(INIT_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("jrttStr", jrttStr).commit();
    }

    public static String getSlotJrtt() {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(INIT_SETTING, 0);
        String gdtStr = settings.getString("jrttStr", "");
        return gdtStr;
    }


    public static void setAgeDate(String text) {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("Age_s", text);
        editor.commit();
    }

    public static String getAgeDate() {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        String json = settings.getString("Age_s", "");
        return json;
    }

    public static void setGenderDate(String text) {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("gender_s", text);
        editor.commit();
    }

    public static String getGenderDate() {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        String json = settings.getString("gender_s", "");
        return json;
    }

    public static void setWeightDate(String text) {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("Weight_s", text);
        editor.commit();
    }

    public static String getWeightDate() {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        String json = settings.getString("Weight_s", "");
        return json;
    }

    public static void setHeightDate(String text) {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("Height_s", text);
        editor.commit();
    }

    public static String getHeightDate() {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        String json = settings.getString("Height_s", "");
        return json;
    }

    public static void setRandom(String text) {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("Random", text);
        editor.commit();
    }

    public static String getRandom() {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        String json = settings.getString("Random", "");
        return json;
    }

    public static void setSignSesstionId(String str) {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString(SIGN_SESSIONID, str);
        editor.commit();
    }

    public static String getSignSessionId() {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        String str = settings.getString(SIGN_SESSIONID, "");
        return str;
    }

    public static void setFirstLoginDIalog(boolean str) {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean(IS_FIRST_LOGIN_DIALOG, str);
        editor.commit();
    }

    public static boolean getIsFirstLoginDialog() {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        boolean str = settings.getBoolean(IS_FIRST_LOGIN_DIALOG, false);
        return str;
    }

    public static String getUUid() {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        String str = settings.getString("UUID", UUID.randomUUID().toString());
        setUUid(str);
        return str;
    }

    public static void setUUid(String str) {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("UUID", str);
        editor.commit();
    }


    public static String getLat() {
        String lat = AdConstant.param.lat;
        if (TextUtils.isEmpty(lat)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            return settings.getString(LAT, "");
        }
        return lat;
    }

    public static void setLat(String lat) {
        AdConstant.param.lat = TextUtils.isEmpty(lat) ? "" : lat;
        if (!TextUtils.isEmpty(AdConstant.param.lat)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putString(LAT, AdConstant.param.lat);
            editor.commit();
        }
    }

    public static String getLon() {
        String lon = AdConstant.param.lon;
        if (TextUtils.isEmpty(lon)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            return settings.getString(LON, "");
        }
        return lon;
    }

    public static void setLon(String lon) {
        AdConstant.param.lon = TextUtils.isEmpty(lon) ? "" : lon;
        if (!TextUtils.isEmpty(AdConstant.param.lon)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putString(LON, AdConstant.param.lon);
            editor.commit();
        }
    }

    public static String getCity() {
        String city = AdConstant.param.city;
        if (TextUtils.isEmpty(city)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            return settings.getString(CITY, "");
        }
        return city;
    }

    public static void setCity(String city) {
        AdConstant.param.city = TextUtils.isEmpty(city) ? "" : city;
        if (!TextUtils.isEmpty(AdConstant.param.city)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            SharedPreferences.Editor editor = settings.edit();
            editor.putString(CITY, AdConstant.param.city);
            editor.commit();
        }
    }

    public static String getLocationType() {
        String locationType = AdConstant.param.locationType;
        if (TextUtils.isEmpty(locationType)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            return settings.getString(LOCATION_TYPE, "");
        }
        return locationType;
    }



    public static void setSplashInvreval(long value) {
        if (value == 0) {
            value = 10;
        }
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putLong(SPLASH_INVREVAL, value);
        editor.commit();
    }



    public static void setTrackId(Long id) {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putLong(TRACK_ID, id);
        editor.commit();
    }


    public static void setTerminalId(Long id) {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putLong(TERMINAL_ID, id);
        editor.commit();
    }


    // 保存登陆用户昵称
    public static void saveUserInfoName(String name) {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString(USER_INFRO_NAME, null == name ? "" : name).commit();

    }

    private static final String SIGN_IN_ISTODAY = "sign_in_istoDay";

    // 获取任务页签到日期
    public static String getSignInIsDate() {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(SIGN_IN_ISTODAY, "");
    }

    // 保存当前环境
    public static void saveEvnvironment(String evnvironment) {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString(ENVIRONMENT, null == evnvironment ? "" : evnvironment).commit();
    }

    // 获取当前环境
    public static NetConfig.Environment getEvnvironment() {
        SharedPreferences settings =  AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        String name = settings.getString(ENVIRONMENT, null);
        if (name != null) {
            for (NetConfig.Environment environment : NetConfig.Environment.values()) {
                if (environment.name().equals(name)) {
                    return environment;
                }
            }
        }
        // 如果都没匹配到或没修改过，则返回当前环境值
        return NetConfig.sEnvironment;
    }
    private static final String ENVIRONMENT = "environment";//环境


    public static String getAppSecret() {
        String secret = AdConstant.param.b;
        if (TextUtils.isEmpty(secret)) {
            SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
            return settings.getString(APP_SECRET, "");
        }
        return secret;
    }

    public static void setAppSecret(String secret) {
        AdConstant.param.b = TextUtils.isEmpty(secret) ? "" : secret;
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString(APP_SECRET, AdConstant.param.b);
        editor.commit();
    }

    public static String getOaid() {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(OAID, "");
    }

    public static void setOaid(String oaid) {
        SharedPreferences sharedPre = AppliContext.get().getSharedPreferences(
                USER_SETTING, AppliContext.get().MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPre.edit();
        editor.putString(OAID, oaid);
        editor.commit();
    }

    public static void saveLua(@Nullable String md5, @Nullable String lua) {
        if (lua != null && !TextUtils.isEmpty(lua)) {
            if (!TextUtils.isEmpty(md5)) {
                AdPreference.saveMd5(md5);
            }
            AdPreference.saveSecDesc(lua);

            CesCore.Companion.getInstance().setData(lua);
            AdConstant.param.env = CesCore.Companion.getInstance().Ckwork(AdPreference.getAndroidId());
            AdConstant.param.md5 = AdPreference.getMd5();
        } else {
            String luas = AdPreference.getSecDesc();
            if (!TextUtils.isEmpty(luas)) {
                CesCore.Companion.getInstance().setData(luas);
                AdConstant.param.env = CesCore.Companion.getInstance().Ckwork(AdPreference.getAndroidId());
            }
        }
    }

    public static boolean getFirstReport() {
        return AppliContext.get().getSharedPreferences(USER_SETTING, 0).getBoolean(FIRST_REPORT, true);
    }

    public static void setFirstReport(boolean isReport) {
        SharedPreferences.Editor editor = AppliContext.get().getSharedPreferences(USER_SETTING, AppliContext.get().MODE_PRIVATE).edit();
        editor.putBoolean(FIRST_REPORT, isReport);
        editor.commit();
    }

    public static void setH5Data(String key, String value) {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("h5_" + key, value);
        editor.commit();
    }

    public static String getH5Data(String key) {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        String ad = settings.getString("h5_" + key, "");
        return ad;
    }

    public static void setBlackBox(@Nullable String s) {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("water_BlackBox", s);
        editor.commit();
    }
    public static String getBlackBox() {
        SharedPreferences settings = AppliContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString("water_BlackBox", "");
    }
}
