package com.quansu.heifengwuliu.activity

import android.content.Intent
import android.view.View
import com.hwangjr.rxbus.annotation.Subscribe
import com.hwangjr.rxbus.annotation.Tag
import com.qmuiteam.qmui.kotlin.onClick
import com.quansu.heifengwuliu.R
import com.quansu.heifengwuliu.base.MBActivity
import com.quansu.heifengwuliu.config.ConfigRx
import com.quansu.heifengwuliu.databinding.ActivitySettingsBinding
import com.quansu.heifengwuliu.repository.UserInfoRepository
import com.quansu.heifengwuliu.vmodel.SettingsVModel
import com.ysnows.base.base.BRepository
import com.ysnows.base.ccretrofit.CCRetrofit
import com.ysnows.base.ext.message
import com.ysnows.base.route.IUpdate
import com.ysnows.base.utils.MMKVManager
import com.ysnows.base.utils.UiSwitch


class SettingsActivity : MBActivity<SettingsVModel, ActivitySettingsBinding>() {

    override fun listeners() {
        super.listeners()

        binding.layAboutUs.onClick {
            single(AboutActivity::class.java)
        }
        binding.layCheckupdate.setOnClickListener { v: View? ->

            //检查更新
            CCRetrofit.instance()
                    .create(IUpdate::class.java)
                    .checkUpgrade(true)
                    .subscribe()

        }



        binding.btnLogout.onClick {
            message(R.string.enture_logout, negativeEnable = true, positiveAction = { dialog, _ ->
                MMKVManager.instance().clearAll()
                dialog.dismiss()
                UiSwitch.single_new_task_with_clear_task(context(), OneLoginActivity::class.java)
            })
        }
    }

    override fun binding(): ActivitySettingsBinding {
        return ActivitySettingsBinding.inflate(layoutInflater)
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == 100) {
//            if (PermissionUtils.checkFloatPermission(this)) {
//                ClipBoardListenService.start(getContext());
//                SettingsUtil.clipboard_listener(1);
//            }
        }
    }

//    override fun onResume() {
//        super.onResume()
//        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
//            if (PermissionUtils.checkFloatPermission(this)) {
//                ClipBoardListenService.start(context())
//            }
//        }
//    }

    override fun title(): String? {
        return "设置"
    }

    override val isRxbus: Boolean
        get() = true

    override fun vmClass(): Class<SettingsVModel> {
        return SettingsVModel::class.java
    }

    override fun createRepository(): BRepository {
        return UserInfoRepository()
    }

    @Subscribe(tags = [Tag(ConfigRx.LOGIN)])
    fun userInfo(from: String) {
        vm.firstReq()
    }


}
