package com.zj365.mime.act

import com.alibaba.android.arouter.facade.annotation.Route
import com.xty.base.act.IBaseAct
import com.xty.common.Const
import com.xty.common.JPushHelper
import com.xty.common.MMkvHelper
import com.xty.common.arouter.ARouterUrl
import com.zj365.mime.R
import com.zj365.mime.databinding.ActNoticeSettingBinding
import com.zj365.mime.weight.NoticeSettingDialog

/**
 * 通知设置
 */
@Route(path = ARouterUrl.NOTICE_SETTING)
class NoticeSettingAct : IBaseAct(){
    val binding by lazy { ActNoticeSettingBinding.inflate(layoutInflater) }
    val cancelNoticeDiaLog by lazy {
        NoticeSettingDialog(this, getString(R.string.dialog_cancel_notice),{
            binding.noticeSwitchButton.isChecked = MMkvHelper.getBoolean(Const.NOTICE_FLAG)
        }){
            JPushHelper(this).stopJPush()
            MMkvHelper.put(Const.NOTICE_FLAG, false)
        }
    }

    override fun setLayout() = binding.root

    override fun initData() {
        super.initData()
        isDarkBar = true
    }

    override fun initView() {
        super.initView()

        statusBar(binding.title.mView)
        binding.title.mIvBack.setOnClickListener {
            finish()
        }
        binding.title.mTvTitle.text = getString(R.string.notice_title)
        binding.noticeSwitchButton.isChecked = MMkvHelper.getBoolean(Const.NOTICE_FLAG)
        binding.noticeSwitchButton.setOnCheckedChangeListener { view, isChecked ->
            //默认为开启通知
            if(!isChecked){
                cancelNoticeDiaLog.show()
            }else{
                JPushHelper(this).resumeJPush();
                MMkvHelper.put(Const.NOTICE_FLAG, true)
            }
        }
    }
}