package com.abbidot.tracker.ui.activity.set

import com.abbidot.baselibrary.constant.EventName
import com.abbidot.baselibrary.eventbus.XEventBus
import com.abbidot.baselibrary.util.AppUtils
import com.abbidot.baselibrary.util.LogUtil
import com.abbidot.tracker.R
import com.abbidot.tracker.adapter.PermissionsSetAdapter
import com.abbidot.tracker.base.BaseActivity
import com.abbidot.tracker.constant.ConstantInt
import com.abbidot.tracker.databinding.ActivityPermissionsSetBinding
import com.abbidot.tracker.ui.common.PermissionsActivityCommon
import com.abbidot.tracker.util.ViewUtil

class PermissionsSetActivity :
    BaseActivity<ActivityPermissionsSetBinding>(ActivityPermissionsSetBinding::inflate) {

    lateinit var mPermissionsCommon: PermissionsActivityCommon
    private lateinit var mPermissionsSetAdapter: PermissionsSetAdapter

    override fun getTopBar() = mViewBinding.ilPermissionsSetTopBar.titleTopBar

    override fun initData() {
        super.initData()
        setTopBarTitle(R.string.txt_permissions)
        setLeftBackImage(R.drawable.icon_white_back_svg)

        mPermissionsCommon = PermissionsActivityCommon(this).apply {
            registerGpsReceiver()
        }
        mPermissionsSetAdapter =
            PermissionsSetAdapter(mContext, mPermissionsCommon.addListData(mContext))

        mViewBinding.apply {
            ViewUtil.instance.setRecyclerViewVerticalLinearLayout(
                mContext, rvPermissionSetList, mPermissionsSetAdapter, top = AppUtils.dpToPx(12)
            )
        }
    }

    override fun liveDataObserve() {
        //蓝牙开关操作
        XEventBus.observe(this, EventName.ActionConDeviceState) { conState: Int ->
            mPermissionsCommon.updatePermissionsState(mPermissionsSetAdapter, ConstantInt.Type0)
        }
        //gps开关操作
        XEventBus.observe(this, EventName.GPSSwitchState) { switchState: Int ->
            mPermissionsCommon.updatePermissionsState(mPermissionsSetAdapter,ConstantInt.Type0)
        }
    }

    override fun onResume() {
        super.onResume()
        LogUtil.e("PermissionsSetActivity----------------->>>onResume")
        mPermissionsCommon.updatePermissionsState(mPermissionsSetAdapter,ConstantInt.Type0)
    }

    override fun onDestroy() {
        super.onDestroy()
        mPermissionsCommon.unregisterGpsReceiver()
    }
}