From 1f729f1cb33e4d9df6471016417eac0fd1782735 Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Thu, 15 Apr 2021 20:55:39 +0700 Subject: [PATCH] Add navigation bar scrim (#4845) * Revert "Add navigation bar scrim (closes #4836)" This reverts commit 2a69d1b0 * Add navigation bar scrim --- .../ui/base/activity/BaseThemedActivity.kt | 2 +- .../kanade/tachiyomi/ui/main/MainActivity.kt | 33 ++++++++----------- .../util/system/InternalResourceHelper.kt | 25 ++++++++++++++ app/src/main/res/layout/main_activity.xml | 13 -------- app/src/main/res/values/themes.xml | 2 +- 5 files changed, 41 insertions(+), 34 deletions(-) create mode 100644 app/src/main/java/eu/kanade/tachiyomi/util/system/InternalResourceHelper.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseThemedActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseThemedActivity.kt index 5f9f48af9..afd4d1028 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseThemedActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseThemedActivity.kt @@ -13,7 +13,7 @@ abstract class BaseThemedActivity : AppCompatActivity() { val preferences: PreferencesHelper by injectLazy() - val isDarkMode: Boolean by lazy { + private val isDarkMode: Boolean by lazy { val themeMode = preferences.themeMode().get() (themeMode == Values.ThemeMode.dark) || ( diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index 3a66f4902..e577638ac 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -24,7 +24,6 @@ import com.bluelinelabs.conductor.Router import com.bluelinelabs.conductor.RouterTransaction import com.google.android.material.appbar.AppBarLayout import com.google.android.material.behavior.HideBottomViewOnScrollBehavior -import dev.chrisbanes.insetter.Insetter import dev.chrisbanes.insetter.applyInsetter import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.Migrations @@ -51,6 +50,8 @@ import eu.kanade.tachiyomi.ui.recent.history.HistoryController import eu.kanade.tachiyomi.ui.recent.updates.UpdatesController import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.lang.launchUI +import eu.kanade.tachiyomi.util.system.InternalResourceHelper +import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.toast import kotlinx.coroutines.delay import kotlinx.coroutines.flow.launchIn @@ -103,33 +104,27 @@ class MainActivity : BaseViewBindingActivity() { margin(top = true) } } - binding.rootFab.applyInsetter { - type(navigationBars = true) { - margin() - } - } binding.bottomNav.applyInsetter { type(navigationBars = true) { padding() } } - Insetter.builder() - .consume(Insetter.CONSUME_ALL) - .setOnApplyInsetsListener { view, insets, _ -> - val systemInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars()) - view.isVisible = systemInsets.bottom > 0 - view.updateLayoutParams { - height = systemInsets.bottom - } + binding.rootFab.applyInsetter { + type(navigationBars = true) { + margin() } - .applyToView(binding.navigationScrim) + } - // Make sure navigation bar is on bottom when making it transparent + // Make sure navigation bar is on bottom before we modify it ViewCompat.setOnApplyWindowInsetsListener(binding.root) { _, insets -> if (insets.getInsets(WindowInsetsCompat.Type.navigationBars()).bottom > 0) { - // Keep scrim on light theme if windowLightNavigationBar is not available - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 || isDarkMode) { - window.navigationBarColor = Color.TRANSPARENT + window.navigationBarColor = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && + !InternalResourceHelper.getBoolean(this, "config_navBarNeedsScrim", true) + ) { + Color.TRANSPARENT + } else { + // Set navbar scrim 70% of navigationBarColor + getResourceColor(android.R.attr.navigationBarColor, .7F) } } insets diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/InternalResourceHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/InternalResourceHelper.kt new file mode 100644 index 000000000..a46f73502 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/InternalResourceHelper.kt @@ -0,0 +1,25 @@ +package eu.kanade.tachiyomi.util.system + +import android.content.Context +import android.content.res.Resources + +object InternalResourceHelper { + /** + * Get resource id from system resources + * @param resName resource name to get + * @param type resource type of [resName] to get + * @return 0 if not available + */ + private fun getResourceId(resName: String, type: String): Int { + return Resources.getSystem().getIdentifier(resName, type, "android") + } + + fun getBoolean(context: Context, resName: String, defaultValue: Boolean): Boolean { + val id = getResourceId(resName, "bool") + return if (id != 0) { + context.createPackageContext("android", 0).resources.getBoolean(id) + } else { + defaultValue + } + } +} diff --git a/app/src/main/res/layout/main_activity.xml b/app/src/main/res/layout/main_activity.xml index d43b4c88c..cbd72ac50 100644 --- a/app/src/main/res/layout/main_activity.xml +++ b/app/src/main/res/layout/main_activity.xml @@ -91,17 +91,4 @@ app:layout_insetEdge="bottom" app:menu="@menu/bottom_nav" /> - - diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 617258706..756725679 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -201,7 +201,7 @@ @color/colorAmoledPrimary - @android:color/transparent + #000001 @color/selectorColorDark