mirror of
https://git.suyu.dev/suyu/suyu
synced 2024-12-25 10:52:48 -06:00
android: Decouple status bar shade from navigation bar visibility
This commit is contained in:
parent
d57ae50f17
commit
9c9d9131b5
3 changed files with 42 additions and 22 deletions
|
@ -8,10 +8,20 @@ class HomeViewModel : ViewModel() {
|
|||
private val _navigationVisible = MutableLiveData(true)
|
||||
val navigationVisible: LiveData<Boolean> get() = _navigationVisible
|
||||
|
||||
fun setNavigationVisible(visible: Boolean) {
|
||||
private val _statusBarShadeVisible = MutableLiveData(true)
|
||||
val statusBarShadeVisible: LiveData<Boolean> get() = _statusBarShadeVisible
|
||||
|
||||
fun setNavigationVisibility(visible: Boolean) {
|
||||
if (_navigationVisible.value == visible) {
|
||||
return
|
||||
}
|
||||
_navigationVisible.value = visible
|
||||
}
|
||||
|
||||
fun setStatusBarShadeVisibility(visible: Boolean) {
|
||||
if (_statusBarShadeVisible.value == visible) {
|
||||
return
|
||||
}
|
||||
_statusBarShadeVisible.value = visible
|
||||
}
|
||||
}
|
||||
|
|
|
@ -143,9 +143,15 @@ class GamesFragment : Fragment() {
|
|||
_binding = null
|
||||
}
|
||||
|
||||
private fun searchShown() = homeViewModel.setNavigationVisible(false)
|
||||
private fun searchShown() {
|
||||
homeViewModel.setNavigationVisibility(false)
|
||||
homeViewModel.setStatusBarShadeVisibility(false)
|
||||
}
|
||||
|
||||
private fun searchHidden() = homeViewModel.setNavigationVisible(true)
|
||||
private fun searchHidden() {
|
||||
homeViewModel.setNavigationVisibility(true)
|
||||
homeViewModel.setStatusBarShadeVisibility(true)
|
||||
}
|
||||
|
||||
private inner class ScoredGame(val score: Double, val item: Game)
|
||||
|
||||
|
|
|
@ -75,6 +75,9 @@ class MainActivity : AppCompatActivity() {
|
|||
homeViewModel.navigationVisible.observe(this) { visible ->
|
||||
showNavigation(visible)
|
||||
}
|
||||
homeViewModel.statusBarShadeVisible.observe(this) { visible ->
|
||||
showStatusBarShade(visible)
|
||||
}
|
||||
|
||||
// Dismiss previous notifications (should not happen unless a crash occurred)
|
||||
EmulationActivity.tryDismissRunningNotification(this)
|
||||
|
@ -83,25 +86,6 @@ 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
|
||||
|
@ -121,6 +105,26 @@ class MainActivity : AppCompatActivity() {
|
|||
}.start()
|
||||
}
|
||||
|
||||
private fun showStatusBarShade(visible: Boolean) {
|
||||
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()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
EmulationActivity.tryDismissRunningNotification(this)
|
||||
super.onDestroy()
|
||||
|
|
Loading…
Reference in a new issue