1
1
Fork 0
forked from suyu/suyu

android: Switch from a colored status bar to a custom view

Allows for smoother transitions with the search bar
This commit is contained in:
Charles Lombardo 2023-04-11 21:08:37 -04:00 committed by bunnei
parent 3f2b832371
commit 921e6dddcc
4 changed files with 35 additions and 23 deletions

View file

@ -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()
}

View file

@ -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)

View file

@ -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

View file

@ -29,4 +29,15 @@
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/menu_navigation" />
<View
android:id="@+id/status_bar_shade"
android:layout_width="0dp"
android:layout_height="1px"
android:background="@android:color/transparent"
android:clickable="false"
android:focusable="false"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>