package com.zxhl.cms.net;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;

import androidx.annotation.NonNull;

import com.zxhl.cms.AppContext;
import com.zxhl.cms.ad.upload.model.NewsEntity;
import com.zxhl.cms.common.Constant;
import com.zxhl.cms.common.NetConfig;
import com.zxhl.cms.net.model.box.AppInEntity;
import com.zxhl.cms.net.model.news.HotSearchEntity;
import com.zxhl.cms.net.model.uc.UserInfo;
import com.zxhl.cms.utils.LogUtils;
import com.zxhl.cms.utils.MainLooper;
import com.zxhl.cms.utils.PhoneUtils;
import com.zxhl.cms.utils.Utils;
import com.zxhl.cms.utils.cache.UserCacheUtils;

import java.util.UUID;

/**
 * Created by gaoleichao on 2018/5/5.
 */

public class SettingPreference {
    private static final String USER_SETTING = "user_setting";

    private static String USER_READ_PROGRESS = "user_read_progress";
    private static String OUTSIDE_MSG_LIMIT = "outside_msg_limit";
    private static String INSIDE_MSG_LIMIT = "inside_msg_limit";
    private static String CODE_AWARD_STATUS = "invite_code_status";
    private static String SPLASH_AD = "splash_ads";
    private static String SEARCH_DATA = "search_data";
    private static String NEWS_READ_TIME = "news_read_time";
    private static String NEWS_READ_TASK = "news_read_task";
    private static String CANCEL_UPDATE_DATE = "cancel_update_date";
    private static String NEWS_SHARE_TIPS = "news_share_tips";
    private static String SOGOU_PID = "sogou_pid";
    private static String SOGOU_MID = "sogou_mid";
    private static String IS_NEW_USER = "is_new_user";
    private static String CHANNEL_KEY = "channel";
    private static String ISREAD = "isread";
    private static String MAIN_BOTTOM_COINS_TIPS = "main_bottom_coins_tips";
    private static final String USER_INFO_KEY = "user_info_keys";
    private static final String APP_INFO_KEY = "app_info_keys";
    private static final String USER_TOKEN_KEY = "user_token_keys";
    private static final String IS_REFRESH_NEWS = "is_refresh_news";
    private static final String NEWS_GUIDE = "news_guide";
    private static final String VIDEO_GUIDE = "video_guide";
    private static final String TASK_GUIDE = "task_guide";
    private static final String CHANGE_GUIDE = "change_guide";
    // 是否强制调试模式
    private static final String IS_FORCE_DEBUG = "is_force_debug";
    // 是否开发设备
    private static final String IS_DEV_DEVICE = "is_dev_device";
    // 是否开启LOG打印
    private static final String IS_OPEN_LOG_PRINT = "is_open_log";
    // 是否开启LOG日志保存
    private static final String IS_OPEN_LOG_SAVE = "is_open_log_save";

    private static final String IS_UPLOAD_CONTACTS = "is_upload_contacts";
    // 当前环境
    private static final String CURRENT_ENV = "current_env";

    private static final String INFO_SHARE_DESC = "info_share_desc";
    private static final String INVITE_SHARE_WX_GROUP_DESC = "invite_share_wx_group_desc";
    private static final String INVITE_SHARE_QZONE_DESC = "invite_share_qq_group_desc";
    private static final String INVITE_SHARE_WX_DESC = "invite_share_wx_user_desc";
    private static final String INVITE_SHARE_QQ_DESC = "invite_share_qq_user_desc";
    private static final String AWAKE_SHARE_WX_GROUP_DESC = "awake_share_wx_group_desc";
    private static final String AWAKE_SHARE_QZONE_DESC = "awake_share_qq_group_desc";
    private static final String AWAKE_SHARE_WX_DESC = "awake_share_wx_user_desc";
    private static final String AWAKE_SHARE_QQ_DESC = "awake_share_qq_user_desc";
    private static final String SHARE_IMAGE = "share_image";
    private static final String SHARE_URL = "share_url";
    private static final String AWAKE_URL = "landing_url";
    private static final String SHARE_TITLE = "share_title";
    private static final String SHARE_NEWS_DIALOG_TITLE = "dialog_news_share_title";
    private static final String NAVIGATION_BAR = "navigation_bar";
    private static final String KKZ_DESC = "kkz_desc";
    private static final String DDZ_DESC = "ddz_desc";
    private static final String JSZ_DESC = "jsz_desc";
    private static final String HOBBY_LIST = "hobby_list";
    private static final String FLOAT_ICON_LIST = "float_icon_list";

    private static final String ACTIVITY_DIALOG = "activity_dialog";

    private static final String LOCAL_SERVICE_TABID = "local_service_tabid";

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

    /*公共参数二级缓存*/
    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 MI_TOKEN = "miToken";
    private static final String IMSI = "imsi";
    private static final String MAC = "mac";
    private static final String ENV = "env";
    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 USER_ID = "user_id";
    private static final String OAID = "oaid";
    private static final String FLOW_TAG = "flowtag";

    // 保存登陆用户信息。
    public static void saveUserInfo(UserInfo userInfoData) {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString(USER_INFO_KEY, null == userInfoData ? "" : Utils.obj2Str(userInfoData)).commit();
        if (userInfoData == null) {
            setUid("");
            saveToken("");
        } else {
            setUid(userInfoData.uid);
            //saveToken(userInfoData.token);
        }
    }

    // 获取登陆用户信息。
    public static UserInfo getUserInfoData() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        String user = settings.getString(USER_INFO_KEY, "");
        if (TextUtils.isEmpty(user)) {
            return null;
        }
        return (UserInfo) Utils.str2Obj(user, UserInfo.class);
    }

    // 保存app配置
    public static void saveConfig(AppInEntity appInfo) {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString(APP_INFO_KEY, null == appInfo ? "" : Utils.obj2Str(appInfo)).commit();
    }

    // 获取app配置
    public static AppInEntity getConfig() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        String user = settings.getString(APP_INFO_KEY, "");
        if (TextUtils.isEmpty(user)) {
            return null;
        }
        return (AppInEntity) Utils.str2Obj(user, AppInEntity.class);
    }

    /**
     * 更新用户数据以及token（保存access token及用户数据）
     *
     * @param userInfo    用户信息接口请求结果
     * @param accessToken 请求授权码
     * @return 用户数据
     */
    public static UserInfo resolveAndSetData(@NonNull UserInfo userInfo, String accessToken) {
        // 保存token和用户信息
        if (userInfo != null) {
            saveUserInfo(userInfo);
        }
        if (accessToken != null) {
            saveToken(accessToken);
        }
        return userInfo;
    }

    // 保存登录用户信息。
    public static void saveToken(String token) {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString(USER_TOKEN_KEY, token);
        editor.commit();
    }

    // 获取登录用户信息。
    public static String getUserToken() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(USER_TOKEN_KEY, "");
    }

    // 资讯新手引导。
    public static void saveNewsGuide(boolean isShow) {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean(NEWS_GUIDE, isShow);
        editor.commit();
    }

    // 资讯新手引导。
    public static Boolean getNewsGuide() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getBoolean(NEWS_GUIDE, false);
    }

    // 视频引导。
    public static void saveVideoGuide(boolean isShow) {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean(VIDEO_GUIDE, isShow);
        editor.commit();
    }

    // 视频引导。
    public static Boolean getVideoGuide() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getBoolean(VIDEO_GUIDE, false);
    }

    // 任务引导。
    public static void saveTaskGuide(boolean isShow) {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean(TASK_GUIDE, isShow);
        editor.commit();
    }

    // 任务引导。
    public static Boolean getTaskGuide() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getBoolean(TASK_GUIDE, false);
    }

    // 兑换引导。
    public static void saveChangeGuide(boolean isShow) {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean(CHANGE_GUIDE, isShow);
        editor.commit();
    }

    // 兑换引导。
    public static Boolean getChangeGuide() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getBoolean(CHANGE_GUIDE, false);
    }

    public static void saveReadNews(String id) {
        UserCacheUtils.saveNewsRecord(AppContext.get(), id);
    }


    // 保存用户阅读进度
    public static void saveUserReadProgress(int value) {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putInt(USER_READ_PROGRESS, value);
        editor.commit();
    }
    // 获取用户阅读进度

    public static int getUserReadProgress() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getInt(USER_READ_PROGRESS, 0);
    }

    public static void setTotalOutsideMsgLimit(int time) {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putInt(OUTSIDE_MSG_LIMIT, time);
        editor.commit();
    }

    public static int getTotalOutsideMsgLimit(int defalue) {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getInt(OUTSIDE_MSG_LIMIT, defalue);
    }

    public static void setTotalInsideMsgLimit(int time) {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putInt(INSIDE_MSG_LIMIT, time);
        editor.commit();
    }

    public static int getTotalInsideMsgLimit(int defaule) {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getInt(INSIDE_MSG_LIMIT, defaule);
    }

    /**
     * 获取邀请码奖励是否领取
     *
     * @param
     */
    public static String getCodeAwardStatus() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(CODE_AWARD_STATUS, "");
    }

    /**
     * 保存邀请码奖励是否领取
     *
     * @param
     * @param status
     */
    public static void saveCodeAwardStatus(String status) {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString(CODE_AWARD_STATUS, status);
        editor.commit();
    }

    public static boolean isReaded(String currentId) {
        return UserCacheUtils.isReaded(currentId);
    }

    public static void saveSplashAd(NewsEntity ad) {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString(SPLASH_AD, null == ad ? "" : Utils.obj2Str(ad));
        editor.commit();
    }

    public static NewsEntity getSplashAd() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        String ad = settings.getString(SPLASH_AD, "");
        if (TextUtils.isEmpty(ad)) {
            return null;
        }
        return (NewsEntity) Utils.str2Obj(ad, NewsEntity.class);
    }

    public static void saveSearchData(HotSearchEntity ad) {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString(SEARCH_DATA, null == ad ? "" : Utils.obj2Str(ad));
        editor.commit();
    }

    public static HotSearchEntity getSearchData() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        String ad = settings.getString(SEARCH_DATA, "");
        if (TextUtils.isEmpty(ad)) {
            return null;
        }
        return (HotSearchEntity) Utils.str2Obj(ad, HotSearchEntity.class);
    }

    /**
     * 是否完成阅读任务
     *
     * @param
     */
    public static boolean isComplateReadTask() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getBoolean(NEWS_READ_TASK, false);
    }

    /**
     * 是否完成阅读任务
     *
     * @param
     * @param
     */
    public static void onComplateReadTask() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean(NEWS_READ_TASK, true);
        editor.commit();
    }

    /**
     * 是否完成阅读任务
     *
     * @param
     */
    public static boolean isComplateNewUserReadTask() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getBoolean(NEWS_READ_TASK, false);
    }

    /**
     * 是否完成阅读任务
     *
     * @param
     * @param
     */
    public static void onComplateNewUserReadTask() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean(NEWS_READ_TASK, true);
        editor.commit();
    }


    /**
     * 保存新闻阅读时间
     */

    public static void setNewReadTime() {
        long nowTime = System.currentTimeMillis();
        long lastTime = getNewReadTime();
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        if (Utils.isYesterday(lastTime)) {
            editor.putLong(NEWS_READ_TIME, nowTime);
            editor.commit();
        }
    }

    /**
     * 获取阅读时间
     */
    public static Long getNewReadTime() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getLong(NEWS_READ_TIME, 0);
    }

    public static void setUpdateApkTime(final Context context) {
        SharedPreferences sharedPre = context.getSharedPreferences(
                USER_SETTING, context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPre.edit();
        editor.putLong("time", System.currentTimeMillis());
        editor.commit();
    }

    /**
     * 获取签到日期
     */
    public static String getCancelUpdateDate() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(CANCEL_UPDATE_DATE, "");
    }

    public static void setCancelUpdateDate(Context context, String date) {
        SharedPreferences sharedPre = context.getSharedPreferences(
                USER_SETTING, context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPre.edit();
        editor.putString(CANCEL_UPDATE_DATE, date);
        editor.commit();
    }

    /**
     * 搜狗pid
     */
    public static String getSogouPid() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(SOGOU_PID, "");
    }

    public static void setSogouPid(Context context, String date) {
        SharedPreferences sharedPre = context.getSharedPreferences(
                USER_SETTING, context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPre.edit();
        editor.putString(SOGOU_PID, date);
        editor.commit();
    }

    /**
     * 搜狗mid
     */
    public static String getSogouMid() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(SOGOU_MID, "");
    }

    public static void setSogouMid(Context context, String date) {
        SharedPreferences sharedPre = context.getSharedPreferences(
                USER_SETTING, context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPre.edit();
        editor.putString(SOGOU_MID, date);
        editor.commit();
    }

    /**
     * 是否获取过阅读奖励
     */
    public static Boolean isReadCoins() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getBoolean(ISREAD, false);
    }

    public static void setReadCoins(Context context, boolean isCom) {
        SharedPreferences sharedPre = context.getSharedPreferences(
                USER_SETTING, context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPre.edit();
        editor.putBoolean(ISREAD, isCom);
        editor.commit();
    }

    /**
     * 是否获取过1000金币
     */
    public static Boolean isComplateCoins() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getBoolean(MAIN_BOTTOM_COINS_TIPS, false);
    }

    public static void setComplateCoins(Context context, boolean isCom) {
        SharedPreferences sharedPre = context.getSharedPreferences(
                USER_SETTING, context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPre.edit();
        editor.putBoolean(MAIN_BOTTOM_COINS_TIPS, isCom);
        editor.commit();
    }

    /**
     * 是否刷新首页资讯
     */
    public static Boolean getRefreshNews() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getBoolean(IS_REFRESH_NEWS, false);
    }

    public static void setRefreshNews(Context context, boolean isCom) {
        SharedPreferences sharedPre = context.getSharedPreferences(
                USER_SETTING, context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPre.edit();
        editor.putBoolean(IS_REFRESH_NEWS, isCom);
        editor.commit();
    }

    /**
     * 获取新闻分享展示时间
     */
    public static String getNewsShareTipsDate() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(NEWS_SHARE_TIPS, "");
    }

    public static void setNewsShareTipsDate(Context context, String date) {
        SharedPreferences sharedPre = context.getSharedPreferences(
                USER_SETTING, context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPre.edit();
        editor.putString(NEWS_SHARE_TIPS, date);
        editor.commit();
    }

//    /**
//     * 是否新手用户
//     */
//    public static boolean getIsNewUser() {
//        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
//        return settings.getBoolean(IS_NEW_USER, false);
//    }
//
//    public static void setIsNewUser(Context context, boolean date) {
//        SharedPreferences sharedPre = context.getSharedPreferences(
//                USER_SETTING, context.MODE_PRIVATE);
//        SharedPreferences.Editor editor = sharedPre.edit();
//        editor.putBoolean(IS_NEW_USER, date);
//        editor.commit();
//    }

    /**
     * 渠道号
     */
    public static String getChannel() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(CHANNEL_KEY, "");
    }

    public static void setChannel(Context context, String date) {
        SharedPreferences sharedPre = context.getSharedPreferences(
                USER_SETTING, context.MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPre.edit();
        editor.putString(CHANNEL_KEY, date);
        editor.commit();
    }


    /**
     * 设置强制调试模式
     *
     * @param context
     * @param isForceDebug
     */
    public static void setIsForceDebug(Context context, boolean isForceDebug) {
        SharedPreferences settings = context.getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean(IS_FORCE_DEBUG, isForceDebug);
        editor.commit();
    }

    /**
     * 是否强制调试模式
     *
     * @param context
     * @return
     */
    public static boolean isForceDebug(Context context) {
        SharedPreferences settings = context.getSharedPreferences(USER_SETTING, 0);
        return settings.getBoolean(IS_FORCE_DEBUG, false);
    }

    /**
     * 设置开发设备
     *
     * @param context
     * @param isDevDevice
     */
    public static void setIsDevDevice(Context context, boolean isDevDevice) {
        SharedPreferences settings = context.getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean(IS_DEV_DEVICE, isDevDevice);
        editor.commit();
    }

    /**
     * 是否开发设备
     *
     * @param context
     * @return
     */
    public static boolean isDevDevice(Context context) {
        SharedPreferences settings = context.getSharedPreferences(USER_SETTING, 0);
        return settings.getBoolean(IS_DEV_DEVICE, false);
    }


    /**
     * 设置是否上传过通讯录
     *
     * @param context
     * @param isUpload
     */
    public static void setIsUploadContacts(Context context, boolean isUpload) {
        SharedPreferences settings = context.getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean(IS_UPLOAD_CONTACTS, isUpload);
        editor.commit();
    }

    /**
     * 是否上传过通讯录
     *
     * @param context
     * @return
     */
    public static boolean isUploadContacts(Context context) {
        SharedPreferences settings = context.getSharedPreferences(USER_SETTING, 0);
        return settings.getBoolean(IS_UPLOAD_CONTACTS, false);
    }

    /**
     * 设置当前环境
     *
     * @param context
     * @param environment
     */
    public static void setCurrentEnv(Context context, NetConfig.Environment environment) {
        SharedPreferences settings = context.getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString(CURRENT_ENV, environment.name());
        editor.commit();
    }

    /**
     * 获取当前环境
     *
     * @param context
     * @return
     */
    public static NetConfig.Environment getCurrentEnv(Context context) {
        SharedPreferences settings = context.getSharedPreferences(USER_SETTING, 0);
        String name = settings.getString(CURRENT_ENV, null);
        if (name != null) {
            for (NetConfig.Environment environment : NetConfig.Environment.values()) {
                if (environment.name().equals(name)) {
                    return environment;
                }
            }
        }
        // 如果都没匹配到或没修改过，则返回当前环境值
        return NetConfig.sEnvironment;
    }

    /**
     * 设置是否开启log打印
     *
     * @param context
     * @param isLogPrint
     */
    public static void setOpenLogPrint(Context context, boolean isLogPrint) {
        SharedPreferences settings = context.getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        LogUtils.getConfig().setLogSwitch(isLogPrint);
        editor.putBoolean(IS_OPEN_LOG_PRINT, isLogPrint);
        editor.commit();
    }

    /**
     * 获取是否开启log打印
     *
     * @param context
     * @return
     */
    public static boolean getOpenLogPrint(Context context) {
        SharedPreferences settings = context.getSharedPreferences(USER_SETTING, 0);
        return settings.getBoolean(IS_OPEN_LOG_PRINT, true);
    }

    public static String getShareImage() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(SHARE_IMAGE, "");
    }

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

    public static String getShareInfoDesc() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(INFO_SHARE_DESC, "");
    }

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

    public static String getInviteWxGroupDesc() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(INVITE_SHARE_WX_GROUP_DESC, "");
    }

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

    public static String getInviteQzoneDesc() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(INVITE_SHARE_QZONE_DESC, "");
    }

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

    public static String getInviteWxDesc() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(INVITE_SHARE_WX_DESC, "");
    }

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

    public static String getInviteQqDesc() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(INVITE_SHARE_QQ_DESC, "");
    }

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

    public static String getAwakeWxGroupDesc() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(AWAKE_SHARE_WX_GROUP_DESC, "");
    }

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

    public static String getAwakeQzoneDesc() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(AWAKE_SHARE_QZONE_DESC, "");
    }

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

    public static String getAwakeWxDesc() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(AWAKE_SHARE_WX_DESC, "");
    }

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

    public static String getAwakeQqDesc() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(AWAKE_SHARE_QQ_DESC, "");
    }

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

    public static String getShareUrl() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(SHARE_URL, "");
    }

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

    public static String getAwakeUrl() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(AWAKE_URL, "");
    }

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

    public static String getMd5() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(SEC_MD5, "");
    }

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

    public static String getShareTitle() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(SHARE_TITLE, "");
    }

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

    public static String getSecDesc() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(SEC_DESC, "");
    }

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

    public static String getNewsShareDialogTitle() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(SHARE_NEWS_DIALOG_TITLE, "");
    }

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

    public static String getNavigationBarStr() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(NAVIGATION_BAR, "");
    }

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

    public static String getKkzDesc() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(KKZ_DESC, "");
    }

    public static void saveKkzDesc(String str) {
        if (TextUtils.isEmpty(str)) {
            str = "";
        }
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString(KKZ_DESC, str);
        editor.commit();
    }

    public static String getDdzDesc() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(DDZ_DESC, "");
    }

    public static void saveDdzDesc(String str) {
        if (TextUtils.isEmpty(str)) {
            str = "";
        }
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString(DDZ_DESC, str);
        editor.commit();
    }

    public static String getJszDesc() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(JSZ_DESC, "");
    }

    public static void saveJszDesc(String str) {
        if (TextUtils.isEmpty(str)) {
            str = "";
        }
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString(JSZ_DESC, str);
        editor.commit();
    }

    public static String getHobbyList() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(HOBBY_LIST, "");
    }

    public static void saveHobbyList(String str) {
        if (TextUtils.isEmpty(str)) {
            str = "";
        }
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString(HOBBY_LIST, str);
        editor.commit();
    }

    public static String getFloatIconList() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(FLOAT_ICON_LIST, "");
    }

    public static void saveFloatIconList(String str) {
        if (TextUtils.isEmpty(str)) {
            str = "";
        }
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString(FLOAT_ICON_LIST, str);
        editor.commit();
    }

    public static String getActivityData() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(ACTIVITY_DIALOG, "");
    }

    public static void saveActivityData(String str) {
        if (TextUtils.isEmpty(str)) {
            str = "";
        }
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString(ACTIVITY_DIALOG, str);
        editor.commit();
    }

    public static String getLocalServiceTabid() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString(LOCAL_SERVICE_TABID, "");
    }

    public static void saveLocalServiceTabid(String str) {
        if (TextUtils.isEmpty(str)) {
            str = "";
        }
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString(LOCAL_SERVICE_TABID, str);
        editor.commit();
    }

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

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

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

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

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

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

    public static String getCarrier() {
        String carrier = Constant.Param.carrier;
        if (TextUtils.isEmpty(carrier)) {
            SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);

            carrier = settings.getString(CARRIER, "");
            if (TextUtils.isEmpty(carrier)) {
                MainLooper.Companion.get().post(new Runnable() {
                    @Override
                    public void run() {
                        setCarrier(PhoneUtils.INSTANCE.getOperator(AppContext.get()));
                    }
                });
                return "";
            } else {
                return carrier;
            }
        }
        return carrier;
    }

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

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

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

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

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

    public static String getDevice() {
        String device = Constant.Param.device;
        if (TextUtils.isEmpty(device)) {
            SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
            return settings.getString(DEVICE, PhoneUtils.INSTANCE.getDeviceId(AppContext.get()));
        }
        return device;
    }

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

    public static String getImei() {
        String imei = Constant.Param.imei;
        if (TextUtils.isEmpty(imei)) {
            SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
            imei = settings.getString(IMEI, "");
            if (TextUtils.isEmpty(imei)) {
                MainLooper.Companion.get().post(new Runnable() {
                    @Override
                    public void run() {
                        setImei(PhoneUtils.INSTANCE.getImei(AppContext.get()));
                    }
                });
                return "";
            } else {
                return imei;
            }

        }
        return imei;
    }

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

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

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


    public static String getImsi() {
        String imsi = Constant.Param.imsi;
        if (TextUtils.isEmpty(imsi)) {
            SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
            imsi = settings.getString(IMSI, "");
            if (TextUtils.isEmpty(imsi)) {

                MainLooper.Companion.get().post(new Runnable() {
                    @Override
                    public void run() {
                        setImsi(PhoneUtils.INSTANCE.getIMSI(AppContext.get()));
                    }
                });

                return "";
            } else {
                return imsi;
            }

        }
        return imsi;
    }

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

    public static String getMac() {
        String mac = Constant.Param.mac;
        if (TextUtils.isEmpty(mac)) {
            SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
            mac = settings.getString(MAC, "");
            if (TextUtils.isEmpty(mac)) {

                MainLooper.Companion.get().post(new Runnable() {
                    @Override
                    public void run() {
//                        setMac(PhoneUtils.INSTANCE.getMac(AppContext.get()));
                    }
                });

                return "";
            } else {
                return mac;
            }
        }
        return mac;
    }

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

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

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

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

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

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

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

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

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

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

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

        return source;
    }

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

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

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

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

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

    public static String getFlowTag() {
        String flowTag = Constant.Param.flowTag;
        if (TextUtils.isEmpty(flowTag)) {
            SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
            return settings.getString(FLOW_TAG, "");
        }
        return flowTag;
    }

    public static void setFlowTag(String flowTag) {
        Constant.Param.flowTag = TextUtils.isEmpty(flowTag) ? "" : flowTag;
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString(FLOW_TAG, Constant.Param.flowTag);
        editor.commit();
    }

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

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


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

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

    public static String getUUid() {
        SharedPreferences settings = AppContext.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 = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("UUID", str);
        editor.commit();
    }

    public static boolean getFirstApp() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        Boolean str = settings.getBoolean("first_app", true);
        return str;
    }

    public static void setFirstApp() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean("first_app", false);
        editor.commit();
    }

    public static boolean getFirstLoginApp() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        Boolean str = settings.getBoolean("first_login_app", true);
        return str;
    }

    public static void setFirstLoginApp() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean("first_login_app", false);
        editor.commit();
    }

    public static int getFirstOpenDiscountBox() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        int str = settings.getInt("first_free_box_num", 0);
        return str;
    }

    public static void setFirstOpenDiscountBox(int num) {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putInt("first_free_box_num", num);
        editor.commit();
    }

    public static int getFirstOpenDiscountBox2() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        int str = settings.getInt("first_free_box_num2", 0);
        return str;
    }

    public static void setFirstOpenDiscountBox2(int num) {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putInt("first_free_box_num2", num);
        editor.commit();
    }

    public static Boolean getIsOpenLuckLottery() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        Boolean str = settings.getBoolean("luck_lottery_box_open", true);
        return str;
    }

    public static void setIsOpenLuckLottery() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean("luck_lottery_box_open", false);
        editor.commit();
    }


    public static boolean getFirstShowShopTips() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        Boolean str = settings.getBoolean("first_show_shop_tips", true);
        return str;
    }

    public static void setFirstShowShopTips() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean("first_show_shop_tips", false);
        editor.commit();
    }

    public static boolean getshowDialog() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        Boolean str = settings.getBoolean("show_dialog", true);
        return str;
    }

    public static void setShowDialog() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean("show_dialog", false);
        editor.commit();
    }

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

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

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

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


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

    public static String getUserCoinNum() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString("USER_COIN_NUM", "");
    }

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

    public static String getHomeBoxId() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString("HOME_BOX_ID", "");
    }

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

    public static String getHomeBoxPrice() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString("HOME_BOX_PRICE", "");
    }

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

    public static String getHomeBoxFivePrice() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString("HOME_BOX_FIVE_PRICE", "");
    }

    public static boolean getshowGuide() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        Boolean str = settings.getBoolean("showguide", true);
        return str;
    }

    public static void setShowGuide() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean("showguide", false);
        editor.commit();
    }

    public static void setIsNewUser(boolean isNewUser) {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putBoolean(IS_NEW_USER, isNewUser);
        editor.commit();
    }


    public static boolean isNewUser() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getBoolean(IS_NEW_USER, false);
    }

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

    public static String getOutTradeNo() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString("OUT_TRADENO", "");
    }

    public static String getRecoveType() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString("RECOVE_TYPE", "");
    }

    public static void setRecoveType(String recoveType) {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("RECOVE_TYPE", recoveType);
        editor.commit();
    }

    public static String getShowEnterDialog() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString("SHOW_ENTER_DIALOG", "0");
    }

    public static void setShowEnterDialog(String ispop) {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("SHOW_ENTER_DIALOG", ispop);
        editor.commit();
    }

    public static String getShowEndDialog() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString("SHOW_END_DIALOG", "0");
    }

    public static void setShowEndDialog(String ispop) {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("SHOW_END_DIALOG", ispop);
        editor.commit();
    }

    public static String getBuyMode() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString("BUY_MODE", "0");
    }

    public static void setShowBuyMode(String buyMode) {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("BUY_MODE", buyMode);
        editor.commit();
    }

    public static String getGoodPrice() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString("GOODS_PRICE", "0");
    }

    public static void setGoodsPrice(String price) {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("GOODS_PRICE", price);
        editor.commit();
    }

    //支付提示次数
    public static int getPayTipsShowNum() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getInt("PAY_TIPS_DIALOG", 0);
    }

    //设置支付
    public static void setPayTipsShowNum(int num) {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putInt("PAY_TIPS_DIALOG", num);
        editor.commit();
    }

    public static String getShowUseDiscount() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString("SHOW_USE_DISCOUNT_DIALOG", "0");
    }

    public static void setShowUseDiscount(String isshow) {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("SHOW_USE_DISCOUNT_DIALOG", isshow);
        editor.commit();
    }

    public static String getifShowCoups() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString("SHOW_COUPS_DIALOG", "0");
    }

    public static void setShowCoups(String isshow) {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("SHOW_COUPS_DIALOG", isshow);
        editor.commit();
    }

    public static String getAdSwitch() {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        return settings.getString("AD_SWITCH", "1");
    }

    public static void setAdSwitch(String ifopen) {
        SharedPreferences settings = AppContext.get().getSharedPreferences(USER_SETTING, 0);
        SharedPreferences.Editor editor = settings.edit();
        editor.putString("AD_SWITCH", ifopen);
        editor.commit();
    }
}
