package com.zj365.mime.act

import com.alibaba.android.arouter.facade.annotation.Route
import com.suke.widget.SwitchButton
import com.xty.base.act.IBaseAct
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.ActMsgReceiveBinding


/**
 * 消息接收设置
 */
@Route(path = ARouterUrl.MSG_RECEIVE)
class MsgReceiveAct: IBaseAct(),SwitchButton.OnCheckedChangeListener {
    val binding by lazy{ActMsgReceiveBinding.inflate(layoutInflater)}
    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.device_10)

        binding.switchQQ.setOnCheckedChangeListener (this)
        binding.switchWx.setOnCheckedChangeListener (this)
        binding.switchMsg.setOnCheckedChangeListener (this)
        binding.switchPhone.setOnCheckedChangeListener (this)
        var wx = MMkvHelper.getBoolean(Const.WX_PUSH) //默认是打开的
        var qq = MMkvHelper.getBoolean(Const.QQ_PUSH) //默认是打开的
        var phone = MMkvHelper.getBoolean(Const.PHONE_PUSH) //默认是打开的
        var msg = MMkvHelper.getBoolean(Const.MSG_PUSH) //默认是打开的

        binding.switchWx.isChecked=wx
        binding.switchQQ.isChecked=qq
        binding.switchMsg.isChecked=msg
        binding.switchPhone.isChecked=phone



    }

    override fun onCheckedChanged(view: SwitchButton, isChecked: Boolean) {
        when(view.id){
            R.id.switchQQ->{
                MMkvHelper.put(Const.QQ_PUSH,isChecked)
            }
            R.id.switchWx->{
                MMkvHelper.put(Const.WX_PUSH,isChecked)
            }
            R.id.switchMsg->{
                MMkvHelper.put(Const.MSG_PUSH,isChecked)
            }
            R.id.switchPhone->{
                MMkvHelper.put(Const.PHONE_PUSH,isChecked)
            }
        }

    }
}