package com.quyunshuo.module.home.fragment.fragment

import android.os.Handler
import android.util.Log
import android.view.View
import android.widget.AdapterView
import android.widget.ArrayAdapter
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
import com.alibaba.android.arouter.launcher.ARouter
import com.quyunshuo.androidbaseframemvvm.base.ktx.observeLiveData
import com.quyunshuo.androidbaseframemvvm.base.utils.SpUtils
import com.quyunshuo.androidbaseframemvvm.common.constant.MMKVName
import com.quyunshuo.androidbaseframemvvm.common.constant.RouteUrl
import com.quyunshuo.androidbaseframemvvm.common.ui.BaseFragment
import com.quyunshuo.androidbaseframemvvm.common.util.LongClickUtils
import com.quyunshuo.androidbaseframemvvm.common.util.ToastUtil
import com.quyunshuo.androidbaseframemvvm.common.util.UiUtil
import com.quyunshuo.module.home.R
import com.quyunshuo.module.home.databinding.HomeFragmentSleepBlockBinding
import com.quyunshuo.module.home.databinding.HomeFragmentUserloginBinding
import com.quyunshuo.module.home.fragment.vm.SleepFragmentVM
import com.quyunshuo.module.home.fragment.vm.UserLoginFragmentVM
import com.quyunshuo.module.home.model.livedata.LiveDataBean
import dagger.hilt.android.AndroidEntryPoint


/**
 * 首页Fragment
 *
 * @author Qu Yunshuo
 * @since 2021/8/1 11:46 下午
 */
@AndroidEntryPoint
class SleepFragment : BaseFragment<HomeFragmentSleepBlockBinding, SleepFragmentVM>() {
    private val TAG = "SleepFragment"

    override val mViewModel: SleepFragmentVM by viewModels()
    override fun createVB() = HomeFragmentSleepBlockBinding.inflate(layoutInflater)

    override fun HomeFragmentSleepBlockBinding.initView() {
        //1. 设置屏幕显示的文本
        val sleepText = SpUtils.getString(MMKVName.SLEEP_TEXT, "")
        if (sleepText != "") {
            tvTitle.text = sleepText
        }
        //2. 设置为休眠模式
        SpUtils.putBoolean(MMKVName.SLEEP, true)
        //3. 上传状态到后台

        LongClickUtils.setLongClick(
            Handler(),
            mBinding.tvExitSleep,
            5000,
            object : View.OnLongClickListener {
                override fun onLongClick(v: View?): Boolean {
                    SpUtils.putBoolean(MMKVName.SLEEP, false)
                    val findNavController = findNavController()
                    findNavController.navigate(R.id.home_action_home_sleepfragment_to_home_buyfragment)
                    return true
                }
            })
    }

    override fun initObserve() {
    }

    override fun initRequestData() {
    }


    override fun onDestroy() {
        super.onDestroy()
        Log.d(TAG, "onDestroy: ")
    }


}