package com.all.pdfreader.pdf.reader.ui.act

import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import androidx.activity.OnBackPressedCallback
import androidx.core.view.doOnPreDraw
import com.all.pdfreader.pdf.reader.R
import com.all.pdfreader.pdf.reader.databinding.ActivitySplashBinding
import com.all.pdfreader.pdf.reader.util.AnalyticsUtils
import com.gyf.immersionbar.BarHide
import com.gyf.immersionbar.ImmersionBar

@SuppressLint("CustomSplashScreen")
class SplashActivity : BaseActivity() {

    override val TAG: String = "SplashActivity"

    private lateinit var binding: ActivitySplashBinding

    companion object {
        private const val SPLASH_DELAY = 3000L // 启动页显示时长
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivitySplashBinding.inflate(layoutInflater)
        setupImmersionBar {
            fullScreen(true)
            statusBarDarkFont(true)
            hideBar(BarHide.FLAG_HIDE_NAVIGATION_BAR)
        }
        // 设置启动页布局
        setContentView(binding.root)
        AnalyticsUtils.logEvent(AnalyticsUtils.Event.SPLASH_VISIBLE)
        // 延迟跳转到权限检查
        Handler(Looper.getMainLooper()).postDelayed({
            navigateToNext()
        }, SPLASH_DELAY)
    }
    
    private fun navigateToNext() {
        val intent =  Intent(this, MainActivity::class.java)
        startActivity(intent)
        finish()
    }

    override fun shouldInterceptBackPress(): Boolean = true
    override fun onInterceptBackPressed() {

    }
}