package com.dahe.gldriver.ui

import android.os.Bundle
import android.view.WindowManager
import com.dahe.gldriver.databinding.ActivityLauncherBinding
import com.dahe.mylibrary.base.BaseActivity
import com.dahe.mylibrary.utils.ActivityUtils
import com.dahe.gldriver.ui.account.LoginActivity
import com.dahe.gldriver.utils.SPUtils
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.disposables.Disposable
import io.reactivex.rxjava3.schedulers.Schedulers
import java.util.concurrent.TimeUnit

class LauncherActivity : BaseActivity<ActivityLauncherBinding>() {


    override fun initView(savedInstanceState: Bundle?) {
//        setStatusBarColorToLight2()
        val extras = intent.extras
        binding.llCount.setOnClickListener {
            mDisposable?.dispose()
            //已登录，直接跳转首页
//            val userInfo = SPUtils.getUserInfo(mContext)
//
//            if (userInfo != null && StringUtils.isNotEmpty(userInfo.token)) {
//                ActivityUtils.startActivity(mContext, HomeActivity::class.java,intent.extras)
//            } else {
//                ActivityUtils.startActivity(this@LauncherActivity, LoginActivity::class.java)
//            }
//            window.setFlags(
//                WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
//                WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
            ActivityUtils.startActivity(this@LauncherActivity, LoginActivity::class.java)
            finish()
        }
        val count = 3
        mDisposable = Observable.interval(0, 1, TimeUnit.SECONDS)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe { aLong: Long ->
                binding.tvCount.setText((count - aLong).toString())
                if (count - aLong == 0L) {
                    mDisposable?.dispose()
                    //已登录，直接跳转首页
                    //已登录，直接跳转首页
//                    val userInfo: UserBean? = SPUtils.getUserInfo(mContext)
//
//                    if (userInfo != null && !TextUtils.isEmpty(userInfo.getToken())) {
//                        ActivityUtils.startActivity(mContext, HomeActivity::class.java,intent.extras)
//                    } else {
//                        ActivityUtils.startActivity(
//                            this@LauncherActivity,
//                            LoginActivity::class.java
//                        )
//
//                    }

//                    ActivityUtils.startActivity(
//                        this@LauncherActivity,
//                        LoginActivity::class.java
//                    )


//                    window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
//                    window.setFlags(
//                        WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
//                        WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

//                    finish()
                }

            }
    }

    private var mDisposable: Disposable? = null

    override fun initDate() {
    }

    override fun onDestroy() {
        super.onDestroy()
        mDisposable?.dispose()
    }
}