package com.zswc.creativity.utils

import com.hwangjr.rxbus.RxBus
import com.zswc.creativity.config.ConfigRx
import com.zswc.creativity.model.AppSetting
import com.ysnows.base.utils.MMKVManager

object SettingsUtil {

    @JvmStatic
    fun pinGoogleIcon(): Boolean {
        return MMKVManager.instance().decodeBool("setting_pin_google_icon", true)
    }

    fun pinGoogleIcon(enable: Boolean) {
        MMKVManager.instance().encode("setting_pin_google_icon", enable)

        RxBus.get().post(ConfigRx.ROUND_SEARCH_BAR_CHANGED, "changed")
       // App.getApp().sendBroadcast(Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE))

    }

    fun clipboardListener(): Boolean {
        return MMKVManager.instance().decodeBool("setting_clipboard_listener", false)
    }

    fun clipboardListener(enable: Boolean) {
        MMKVManager.instance().encode("setting_clipboard_listener", enable)
    }

    fun autoAd(): Boolean {
        return MMKVManager.instance().decodeBool("setting_auto_ad", false)
    }

    fun autoAd(enable: Boolean) {
        MMKVManager.instance().encode("setting_auto_ad", enable)
    }

    fun showMsg(): Boolean {
        return MMKVManager.instance().decodeBool("setting_msg", false)
    }

    fun showMsg(enable: Boolean) {
        MMKVManager.instance().encode("setting_msg", enable)
    }

    fun doubleClickPaste(): Boolean {
        return MMKVManager.instance().decodeBool("setting_double_click_paste", false)
    }

    fun doubleClickPaste(enable: Boolean) {
        MMKVManager.instance().encode("setting_double_click_paste", enable)
    }

    fun backUp() {

        val appSetting = AppSetting()
        appSetting.pinGoogleIcon = pinGoogleIcon()
        appSetting.clipboardListener = clipboardListener()
        appSetting.autoAd = autoAd()
        appSetting.showMsg = showMsg()
        appSetting.doubleClickPaste = doubleClickPaste()

    }
}
