package com.base.pdfreaderallpdfreader.ui.splash

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.core.splashscreen.SplashScreen
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.core.splashscreen.SplashScreenViewProvider
import java.util.concurrent.atomic.AtomicBoolean

/**
 * 适配官方启动页
 * https://cloud.tencent.com/developer/ask/sof/915280
 */
class SystemStartActivity : AppCompatActivity() {

    // 数据
    private var mKeepOnAtomicBool = AtomicBoolean(true)

    override fun onCreate(savedInstanceState: Bundle?) {
        // 初始化操作(必须放在setContentView()之前)
        val splashScreen = installSplashScreen()
        super.onCreate(savedInstanceState)
        // setContentView（可以省略）
//        setContentView(R.layout.activity_system_start)

        // 每次UI绘制前，会判断 Splash 是否有必要继续展示在屏幕上；直到不再满足条件时，隐藏Splash。
        splashScreen.setKeepOnScreenCondition {
            mKeepOnAtomicBool.get()
        }

        // Splash展示完毕的监听方法
        splashScreen.setOnExitAnimationListener(object : SplashScreen.OnExitAnimationListener {
            override fun onSplashScreenExit(splashScreenViewProvider: SplashScreenViewProvider) {
                startActivity(Intent(this@SystemStartActivity, MyStartActivity::class.java))
                this@SystemStartActivity.finish()
                overridePendingTransition(0, 0)
                mKeepOnAtomicBool.compareAndSet(true, false)
            }

        })
    }
}