diff options
| author | 2023-04-28 19:50:58 -0400 | |
|---|---|---|
| committer | 2023-06-03 00:05:56 -0700 | |
| commit | 0d1680544501d9655341618ed007c3acfcd8de5a (patch) | |
| tree | 88f25339f925380a7d68c517416f0a88b933568c /src/android | |
| parent | android: Setup screen hotfix (diff) | |
| download | yuzu-0d1680544501d9655341618ed007c3acfcd8de5a.tar.gz yuzu-0d1680544501d9655341618ed007c3acfcd8de5a.tar.xz yuzu-0d1680544501d9655341618ed007c3acfcd8de5a.zip | |
android: Scroll shortcut for games list
If you reselect the "Games" menu item in the bottom navigation menu, the list smoothly scrolls to the top.
Diffstat (limited to 'src/android')
3 files changed, 34 insertions, 1 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt index 709a5b976..95bad38c6 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt | |||
| @@ -26,6 +26,9 @@ class GamesViewModel : ViewModel() { | |||
| 26 | private val _shouldSwapData = MutableLiveData(false) | 26 | private val _shouldSwapData = MutableLiveData(false) |
| 27 | val shouldSwapData: LiveData<Boolean> get() = _shouldSwapData | 27 | val shouldSwapData: LiveData<Boolean> get() = _shouldSwapData |
| 28 | 28 | ||
| 29 | private val _shouldScrollToTop = MutableLiveData(false) | ||
| 30 | val shouldScrollToTop: LiveData<Boolean> get() = _shouldScrollToTop | ||
| 31 | |||
| 29 | init { | 32 | init { |
| 30 | reloadGames(false) | 33 | reloadGames(false) |
| 31 | } | 34 | } |
| @@ -38,6 +41,10 @@ class GamesViewModel : ViewModel() { | |||
| 38 | _shouldSwapData.postValue(shouldSwap) | 41 | _shouldSwapData.postValue(shouldSwap) |
| 39 | } | 42 | } |
| 40 | 43 | ||
| 44 | fun setShouldScrollToTop(shouldScroll: Boolean) { | ||
| 45 | _shouldScrollToTop.postValue(shouldScroll) | ||
| 46 | } | ||
| 47 | |||
| 41 | fun reloadGames(directoryChanged: Boolean) { | 48 | fun reloadGames(directoryChanged: Boolean) { |
| 42 | if (isReloading.value == true) | 49 | if (isReloading.value == true) |
| 43 | return | 50 | return |
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 3ca529b20..227ca1afc 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 | |||
| @@ -138,6 +138,14 @@ class GamesFragment : Fragment() { | |||
| 138 | searchHidden() | 138 | searchHidden() |
| 139 | } | 139 | } |
| 140 | 140 | ||
| 141 | // Check if the user reselected the games menu item and then scroll to top of the list | ||
| 142 | gamesViewModel.shouldScrollToTop.observe(viewLifecycleOwner) { shouldScroll -> | ||
| 143 | if (shouldScroll) { | ||
| 144 | scrollToTop() | ||
| 145 | gamesViewModel.setShouldScrollToTop(false) | ||
| 146 | } | ||
| 147 | } | ||
| 148 | |||
| 141 | setInsets() | 149 | setInsets() |
| 142 | 150 | ||
| 143 | // Make sure the loading indicator appears even if the layout is told to refresh before being fully drawn | 151 | // Make sure the loading indicator appears even if the layout is told to refresh before being fully drawn |
| @@ -191,6 +199,12 @@ class GamesFragment : Fragment() { | |||
| 191 | } | 199 | } |
| 192 | } | 200 | } |
| 193 | 201 | ||
| 202 | fun scrollToTop() { | ||
| 203 | if (_binding != null) { | ||
| 204 | binding.gridGames.smoothScrollToPosition(0) | ||
| 205 | } | ||
| 206 | } | ||
| 207 | |||
| 194 | private fun setInsets() = | 208 | private fun setInsets() = |
| 195 | ViewCompat.setOnApplyWindowInsetsListener(binding.gridGames) { view: View, windowInsets: WindowInsetsCompat -> | 209 | ViewCompat.setOnApplyWindowInsetsListener(binding.gridGames) { view: View, windowInsets: WindowInsetsCompat -> |
| 196 | val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()) | 210 | val insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()) |
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 e8284471a..473d38a29 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 | |||
| @@ -25,6 +25,7 @@ import androidx.preference.PreferenceManager | |||
| 25 | import com.google.android.material.color.MaterialColors | 25 | import com.google.android.material.color.MaterialColors |
| 26 | import com.google.android.material.dialog.MaterialAlertDialogBuilder | 26 | import com.google.android.material.dialog.MaterialAlertDialogBuilder |
| 27 | import com.google.android.material.elevation.ElevationOverlayProvider | 27 | import com.google.android.material.elevation.ElevationOverlayProvider |
| 28 | import com.google.android.material.navigation.NavigationBarView | ||
| 28 | import kotlinx.coroutines.Dispatchers | 29 | import kotlinx.coroutines.Dispatchers |
| 29 | import kotlinx.coroutines.launch | 30 | import kotlinx.coroutines.launch |
| 30 | import kotlinx.coroutines.withContext | 31 | import kotlinx.coroutines.withContext |
| @@ -73,6 +74,11 @@ class MainActivity : AppCompatActivity(), ThemeProvider { | |||
| 73 | val navHostFragment = | 74 | val navHostFragment = |
| 74 | supportFragmentManager.findFragmentById(R.id.fragment_container) as NavHostFragment | 75 | supportFragmentManager.findFragmentById(R.id.fragment_container) as NavHostFragment |
| 75 | setUpNavigation(navHostFragment.navController) | 76 | setUpNavigation(navHostFragment.navController) |
| 77 | (binding.navigationBar as NavigationBarView).setOnItemReselectedListener { | ||
| 78 | if (it.itemId == R.id.gamesFragment) { | ||
| 79 | gamesViewModel.setShouldScrollToTop(true) | ||
| 80 | } | ||
| 81 | } | ||
| 76 | 82 | ||
| 77 | binding.statusBarShade.setBackgroundColor( | 83 | binding.statusBarShade.setBackgroundColor( |
| 78 | MaterialColors.getColor( | 84 | MaterialColors.getColor( |
| @@ -243,7 +249,13 @@ class MainActivity : AppCompatActivity(), ThemeProvider { | |||
| 243 | ) | 249 | ) |
| 244 | 250 | ||
| 245 | val dstPath = DirectoryInitialization.userDirectory + "/keys/" | 251 | val dstPath = DirectoryInitialization.userDirectory + "/keys/" |
| 246 | if (FileUtil.copyUriToInternalStorage(applicationContext, result, dstPath, "prod.keys")) { | 252 | if (FileUtil.copyUriToInternalStorage( |
| 253 | applicationContext, | ||
| 254 | result, | ||
| 255 | dstPath, | ||
| 256 | "prod.keys" | ||
| 257 | ) | ||
| 258 | ) { | ||
| 247 | if (NativeLibrary.reloadKeys()) { | 259 | if (NativeLibrary.reloadKeys()) { |
| 248 | Toast.makeText( | 260 | Toast.makeText( |
| 249 | applicationContext, | 261 | applicationContext, |