diff options
author | Charles Lombardo <clombardo169@gmail.com> | 2023-04-29 01:50:58 +0200 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2023-06-03 09:05:56 +0200 |
commit | 0d1680544501d9655341618ed007c3acfcd8de5a (patch) | |
tree | 88f25339f925380a7d68c517416f0a88b933568c /src/android | |
parent | android: Setup screen hotfix (diff) | |
download | yuzu-0d1680544501d9655341618ed007c3acfcd8de5a.tar yuzu-0d1680544501d9655341618ed007c3acfcd8de5a.tar.gz yuzu-0d1680544501d9655341618ed007c3acfcd8de5a.tar.bz2 yuzu-0d1680544501d9655341618ed007c3acfcd8de5a.tar.lz yuzu-0d1680544501d9655341618ed007c3acfcd8de5a.tar.xz yuzu-0d1680544501d9655341618ed007c3acfcd8de5a.tar.zst yuzu-0d1680544501d9655341618ed007c3acfcd8de5a.zip |
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() { private val _shouldSwapData = MutableLiveData(false) val shouldSwapData: LiveData<Boolean> get() = _shouldSwapData + private val _shouldScrollToTop = MutableLiveData(false) + val shouldScrollToTop: LiveData<Boolean> get() = _shouldScrollToTop + init { reloadGames(false) } @@ -38,6 +41,10 @@ class GamesViewModel : ViewModel() { _shouldSwapData.postValue(shouldSwap) } + fun setShouldScrollToTop(shouldScroll: Boolean) { + _shouldScrollToTop.postValue(shouldScroll) + } + fun reloadGames(directoryChanged: Boolean) { if (isReloading.value == true) 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() { searchHidden() } + // Check if the user reselected the games menu item and then scroll to top of the list + gamesViewModel.shouldScrollToTop.observe(viewLifecycleOwner) { shouldScroll -> + if (shouldScroll) { + scrollToTop() + gamesViewModel.setShouldScrollToTop(false) + } + } + setInsets() // 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() { } } + fun scrollToTop() { + if (_binding != null) { + binding.gridGames.smoothScrollToPosition(0) + } + } + private fun setInsets() = ViewCompat.setOnApplyWindowInsetsListener(binding.gridGames) { view: View, windowInsets: WindowInsetsCompat -> 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 import com.google.android.material.color.MaterialColors import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.elevation.ElevationOverlayProvider +import com.google.android.material.navigation.NavigationBarView import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -73,6 +74,11 @@ class MainActivity : AppCompatActivity(), ThemeProvider { val navHostFragment = supportFragmentManager.findFragmentById(R.id.fragment_container) as NavHostFragment setUpNavigation(navHostFragment.navController) + (binding.navigationBar as NavigationBarView).setOnItemReselectedListener { + if (it.itemId == R.id.gamesFragment) { + gamesViewModel.setShouldScrollToTop(true) + } + } binding.statusBarShade.setBackgroundColor( MaterialColors.getColor( @@ -243,7 +249,13 @@ class MainActivity : AppCompatActivity(), ThemeProvider { ) val dstPath = DirectoryInitialization.userDirectory + "/keys/" - if (FileUtil.copyUriToInternalStorage(applicationContext, result, dstPath, "prod.keys")) { + if (FileUtil.copyUriToInternalStorage( + applicationContext, + result, + dstPath, + "prod.keys" + ) + ) { if (NativeLibrary.reloadKeys()) { Toast.makeText( applicationContext, |