mirror of
https://git.suyu.dev/suyu/suyu
synced 2024-12-25 19:02:45 -06:00
android: Switch from a colored status bar to a custom view
Allows for smoother transitions with the search bar
This commit is contained in:
parent
3f2b832371
commit
921e6dddcc
4 changed files with 35 additions and 23 deletions
|
@ -87,13 +87,6 @@ class OptionsFragment : Fragment() {
|
||||||
adapter = HomeOptionAdapter(requireActivity() as AppCompatActivity, optionsList)
|
adapter = HomeOptionAdapter(requireActivity() as AppCompatActivity, optionsList)
|
||||||
}
|
}
|
||||||
|
|
||||||
requireActivity().window.statusBarColor = ThemeHelper.getColorWithOpacity(
|
|
||||||
MaterialColors.getColor(
|
|
||||||
binding.root,
|
|
||||||
R.attr.colorSurface
|
|
||||||
), ThemeHelper.SYSTEM_BAR_ALPHA
|
|
||||||
)
|
|
||||||
|
|
||||||
setInsets()
|
setInsets()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@ import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.activity.OnBackPressedCallback
|
import androidx.activity.OnBackPressedCallback
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.content.ContextCompat
|
|
||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.ViewCompat
|
||||||
import androidx.core.view.WindowInsetsCompat
|
import androidx.core.view.WindowInsetsCompat
|
||||||
import androidx.core.view.updatePadding
|
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.Game
|
||||||
import org.yuzu.yuzu_emu.model.GamesViewModel
|
import org.yuzu.yuzu_emu.model.GamesViewModel
|
||||||
import org.yuzu.yuzu_emu.model.HomeViewModel
|
import org.yuzu.yuzu_emu.model.HomeViewModel
|
||||||
import org.yuzu.yuzu_emu.utils.ThemeHelper
|
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
class GamesFragment : Fragment() {
|
class GamesFragment : Fragment() {
|
||||||
|
@ -145,21 +143,9 @@ class GamesFragment : Fragment() {
|
||||||
_binding = null
|
_binding = null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun searchShown() {
|
private fun searchShown() = homeViewModel.setNavigationVisible(false)
|
||||||
homeViewModel.setNavigationVisible(false)
|
|
||||||
requireActivity().window.statusBarColor =
|
|
||||||
ContextCompat.getColor(requireContext(), android.R.color.transparent)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun searchHidden() {
|
private fun searchHidden() = homeViewModel.setNavigationVisible(true)
|
||||||
homeViewModel.setNavigationVisible(true)
|
|
||||||
requireActivity().window.statusBarColor = ThemeHelper.getColorWithOpacity(
|
|
||||||
MaterialColors.getColor(
|
|
||||||
binding.root,
|
|
||||||
R.attr.colorSurface
|
|
||||||
), ThemeHelper.SYSTEM_BAR_ALPHA
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
private inner class ScoredGame(val score: Double, val item: Game)
|
private inner class ScoredGame(val score: Double, val item: Game)
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import android.view.ViewGroup.MarginLayoutParams
|
||||||
import android.view.animation.PathInterpolator
|
import android.view.animation.PathInterpolator
|
||||||
import androidx.activity.viewModels
|
import androidx.activity.viewModels
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
|
||||||
import androidx.core.view.ViewCompat
|
import androidx.core.view.ViewCompat
|
||||||
import androidx.core.view.WindowCompat
|
import androidx.core.view.WindowCompat
|
||||||
|
@ -41,6 +42,8 @@ class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
WindowCompat.setDecorFitsSystemWindows(window, false)
|
WindowCompat.setDecorFitsSystemWindows(window, false)
|
||||||
|
|
||||||
|
window.statusBarColor =
|
||||||
|
ContextCompat.getColor(applicationContext, android.R.color.transparent)
|
||||||
ThemeHelper.setNavigationBarColor(
|
ThemeHelper.setNavigationBarColor(
|
||||||
this,
|
this,
|
||||||
ElevationOverlayProvider(binding.navigationBar.context).compositeOverlay(
|
ElevationOverlayProvider(binding.navigationBar.context).compositeOverlay(
|
||||||
|
@ -80,6 +83,25 @@ class MainActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showNavigation(visible: Boolean) {
|
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 {
|
binding.navigationBar.animate().apply {
|
||||||
if (visible) {
|
if (visible) {
|
||||||
binding.navigationBar.visibility = View.VISIBLE
|
binding.navigationBar.visibility = View.VISIBLE
|
||||||
|
|
|
@ -29,4 +29,15 @@
|
||||||
app:layout_constraintRight_toRightOf="parent"
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
app:menu="@menu/menu_navigation" />
|
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>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
Loading…
Reference in a new issue