From 5684aba36d78ff5ae9d07d78253f6cf2962c8731 Mon Sep 17 00:00:00 2001 From: Jonathan Klee Date: Fri, 20 Sep 2024 09:09:30 +0200 Subject: [PATCH] Implement NavigationBar theme --- .../io/heckel/ntfy/ui/MainSettingsActivity.kt | 45 ++++++++++++++++--- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/heckel/ntfy/ui/MainSettingsActivity.kt b/app/src/main/java/io/heckel/ntfy/ui/MainSettingsActivity.kt index dd7f6e7..07e9767 100644 --- a/app/src/main/java/io/heckel/ntfy/ui/MainSettingsActivity.kt +++ b/app/src/main/java/io/heckel/ntfy/ui/MainSettingsActivity.kt @@ -1,25 +1,60 @@ package io.heckel.ntfy.ui +import android.content.res.Configuration +import android.os.Build import android.os.Bundle +import android.view.WindowInsetsController +import androidx.annotation.RequiresApi import androidx.appcompat.app.AppCompatActivity import io.heckel.ntfy.R import io.heckel.ntfy.databinding.MainSettingsActivityBinding - -class MainSettingsActivity: AppCompatActivity() { +class MainSettingsActivity : AppCompatActivity() { private lateinit var mBinding: MainSettingsActivityBinding + @RequiresApi(Build.VERSION_CODES.R) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) mBinding = MainSettingsActivityBinding.inflate(layoutInflater) setContentView(mBinding.root) - mBinding.toolbar.setNavigationOnClickListener { - onBackPressed() - } + setupToolbar() + setSystemBarsAppearance() + showPreferencesFragment() + } + private fun setupToolbar() { + mBinding.toolbar.setNavigationOnClickListener { + onBackPressedDispatcher.onBackPressed() + } + } + + @RequiresApi(Build.VERSION_CODES.R) + private fun setSystemBarsAppearance() { + val insetsController = window.insetsController ?: return + + val isLightMode = isSystemInLightMode() + if (isLightMode) { + insetsController.setSystemBarsAppearance( + WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS, + WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS + ) + } else { + insetsController.setSystemBarsAppearance( + 0, + WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS + ) + } + } + + private fun isSystemInLightMode(): Boolean { + val nightModeFlags = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK + return nightModeFlags != Configuration.UI_MODE_NIGHT_YES + } + + private fun showPreferencesFragment() { supportFragmentManager .beginTransaction() .replace(R.id.fragment_container, PreferencesFragment())