From 921e6dddcc309665cfafdc002f0723cfa533c33d Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Tue, 11 Apr 2023 21:08:37 -0400 Subject: [PATCH] android: Switch from a colored status bar to a custom view Allows for smoother transitions with the search bar --- .../yuzu_emu/fragments/OptionsFragment.kt | 7 ------ .../org/yuzu/yuzu_emu/ui/GamesFragment.kt | 18 ++------------- .../org/yuzu/yuzu_emu/ui/main/MainActivity.kt | 22 +++++++++++++++++++ .../app/src/main/res/layout/activity_main.xml | 11 ++++++++++ 4 files changed, 35 insertions(+), 23 deletions(-) diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/OptionsFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/OptionsFragment.kt index dac9e67d57..954e52dc6a 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/OptionsFragment.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/OptionsFragment.kt @@ -87,13 +87,6 @@ class OptionsFragment : Fragment() { adapter = HomeOptionAdapter(requireActivity() as AppCompatActivity, optionsList) } - requireActivity().window.statusBarColor = ThemeHelper.getColorWithOpacity( - MaterialColors.getColor( - binding.root, - R.attr.colorSurface - ), ThemeHelper.SYSTEM_BAR_ALPHA - ) - setInsets() } diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/GamesFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/GamesFragment.kt index 0c609798b1..f542fe2de7 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/GamesFragment.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/GamesFragment.kt @@ -9,7 +9,6 @@ import android.view.View import android.view.ViewGroup import androidx.activity.OnBackPressedCallback import androidx.appcompat.app.AppCompatActivity -import androidx.core.content.ContextCompat import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat import androidx.core.view.updatePadding @@ -27,7 +26,6 @@ import org.yuzu.yuzu_emu.layout.AutofitGridLayoutManager import org.yuzu.yuzu_emu.model.Game import org.yuzu.yuzu_emu.model.GamesViewModel import org.yuzu.yuzu_emu.model.HomeViewModel -import org.yuzu.yuzu_emu.utils.ThemeHelper import java.util.Locale class GamesFragment : Fragment() { @@ -145,21 +143,9 @@ class GamesFragment : Fragment() { _binding = null } - private fun searchShown() { - homeViewModel.setNavigationVisible(false) - requireActivity().window.statusBarColor = - ContextCompat.getColor(requireContext(), android.R.color.transparent) - } + private fun searchShown() = homeViewModel.setNavigationVisible(false) - private fun searchHidden() { - homeViewModel.setNavigationVisible(true) - requireActivity().window.statusBarColor = ThemeHelper.getColorWithOpacity( - MaterialColors.getColor( - binding.root, - R.attr.colorSurface - ), ThemeHelper.SYSTEM_BAR_ALPHA - ) - } + private fun searchHidden() = homeViewModel.setNavigationVisible(true) private inner class ScoredGame(val score: Double, val item: Game) diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt index a16ca85290..c7d399846c 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/main/MainActivity.kt @@ -9,6 +9,7 @@ import android.view.ViewGroup.MarginLayoutParams import android.view.animation.PathInterpolator import androidx.activity.viewModels import androidx.appcompat.app.AppCompatActivity +import androidx.core.content.ContextCompat import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen import androidx.core.view.ViewCompat import androidx.core.view.WindowCompat @@ -41,6 +42,8 @@ class MainActivity : AppCompatActivity() { WindowCompat.setDecorFitsSystemWindows(window, false) + window.statusBarColor = + ContextCompat.getColor(applicationContext, android.R.color.transparent) ThemeHelper.setNavigationBarColor( this, ElevationOverlayProvider(binding.navigationBar.context).compositeOverlay( @@ -80,6 +83,25 @@ class MainActivity : AppCompatActivity() { } private fun showNavigation(visible: Boolean) { + // TODO: This should be decoupled from navigation in the future + binding.statusBarShade.animate().apply { + if (visible) { + binding.statusBarShade.visibility = View.VISIBLE + binding.statusBarShade.translationY = binding.statusBarShade.height.toFloat() * -2 + duration = 300 + translationY(0f) + interpolator = PathInterpolator(0.05f, 0.7f, 0.1f, 1f) + } else { + duration = 300 + translationY(binding.navigationBar.height.toFloat() * -2) + interpolator = PathInterpolator(0.3f, 0f, 0.8f, 0.15f) + } + }.withEndAction { + if (!visible) { + binding.statusBarShade.visibility = View.INVISIBLE + } + }.start() + binding.navigationBar.animate().apply { if (visible) { binding.navigationBar.visibility = View.VISIBLE diff --git a/src/android/app/src/main/res/layout/activity_main.xml b/src/android/app/src/main/res/layout/activity_main.xml index 9002b0642e..68a3eae460 100644 --- a/src/android/app/src/main/res/layout/activity_main.xml +++ b/src/android/app/src/main/res/layout/activity_main.xml @@ -29,4 +29,15 @@ app:layout_constraintRight_toRightOf="parent" app:menu="@menu/menu_navigation" /> + +