override fun onCreate()

in SplashScreen/app/src/main/java/com/example/android/splashscreen/MainActivity.kt [28:67]


    override fun onCreate(savedInstanceState: Bundle?) {
        // Set up 'core-splashscreen' to handle the splash screen in a backward compatible manner.
        splashScreen = installSplashScreen()

        // The splash screen remains on the screen as long as this condition is true.
        splashScreen.setKeepOnScreenCondition { !viewModel.isReady }

        super.onCreate(savedInstanceState)

        val binding = MainActivityBinding.inflate(layoutInflater)
        setContentView(binding.root)
        setSupportActionBar(binding.toolbar)

        // Configure edge-to-edge display.
        WindowCompat.setDecorFitsSystemWindows(window, false)
        ViewCompat.setOnApplyWindowInsetsListener(binding.root) { _, insets ->
            binding.appBar.updatePadding(
                top = insets.getInsets(WindowInsetsCompat.Type.systemBars()).top
            )
            insets
        }

        // Show the in-app dark theme settings. This is available on API level 31 and above.
        if (Build.VERSION.SDK_INT >= 31) {
            var previousMode: Int? = null
            viewModel.nightMode.observe(this) { nightMode ->
                val radioButtonId = radioButtonId(nightMode)
                if (binding.theme.checkedRadioButtonId != radioButtonId) {
                    binding.theme.check(radioButtonId)
                }
                if (previousMode == null) previousMode = nightMode
                if (previousMode != nightMode) recreate()
            }
            binding.theme.setOnCheckedChangeListener { _, checkedId ->
                viewModel.updateNightMode(nightMode(checkedId))
            }
        } else {
            binding.content.visibility = View.INVISIBLE
        }
    }