package com.zj365.mime.act

import com.alibaba.android.arouter.facade.annotation.Route
import com.xty.base.act.IBaseAct
import com.xty.common.bracelet.YCBManager
import com.xty.common.bracelet.YCBOrder
import com.xty.common.Const
import com.xty.common.MMkvHelper
import com.xty.common.arouter.ARouterUrl
import com.zj365.mime.R
import com.zj365.mime.databinding.ActDontDisturbBinding
import kotlinx.coroutines.launch

/**
 * 勿扰设置
 */
@Route(path = ARouterUrl.DONT_DISTURB)
class DontDisturbAct : IBaseAct() {
    val binding by lazy { ActDontDisturbBinding.inflate(layoutInflater) }
    override fun setLayout() = binding.root
    override fun initData() {
        super.initData()
        isDarkBar = true
    }

    override fun initView() {
        super.initView()
        statusBar(binding.title.mView)

        //勿扰设置，默认未开启
        binding.switchButton.isChecked = MMkvHelper.getBoolean(
            Const.WHATCH_DONT_REMIND_MODE_SETTING, false)

        binding.title.mIvBack.setOnClickListener {
            finish()
        }
        binding.switchButton.setOnCheckedChangeListener { view, isChecked ->
            var type = if (isChecked) YCBOrder.NOT_ON else YCBOrder.NOT_OFF
            YCBManager.settingNotDisturb(type, 22, 0, 7, 0) {
                if (it)  mainScope.launch {
                   MMkvHelper.put(Const.WHATCH_DONT_REMIND_MODE_SETTING, isChecked)
                }
                else  binding.switchButton.isChecked = !binding.switchButton.isChecked//重置状态
            }

        }
        binding.title.mTvTitle.text = getString(R.string.device_set)
    }
}