diff options
| author | 2023-05-22 16:20:51 -0400 | |
|---|---|---|
| committer | 2023-06-03 00:06:03 -0700 | |
| commit | 412c95e0b0515aa0211c7e7612ce237c23a7938e (patch) | |
| tree | 25819d8aebc30d76765f6a0d55db2c5a25ecb0b9 /src/android | |
| parent | android: Use collapsing toolbar layout in settings (diff) | |
| download | yuzu-412c95e0b0515aa0211c7e7612ce237c23a7938e.tar.gz yuzu-412c95e0b0515aa0211c7e7612ce237c23a7938e.tar.xz yuzu-412c95e0b0515aa0211c7e7612ce237c23a7938e.zip | |
android: Simplify setup in search and games fragments
Diffstat (limited to 'src/android')
| -rw-r--r-- | src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/SearchFragment.kt | 30 | ||||
| -rw-r--r-- | src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/GamesFragment.kt | 89 |
2 files changed, 62 insertions, 57 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/SearchFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/SearchFragment.kt index f6aa370f0..eb4f513d1 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/SearchFragment.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/SearchFragment.kt | |||
| @@ -61,13 +61,6 @@ class SearchFragment : Fragment() { | |||
| 61 | binding.searchText.setText(savedInstanceState.getString(SEARCH_TEXT)) | 61 | binding.searchText.setText(savedInstanceState.getString(SEARCH_TEXT)) |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | gamesViewModel.searchFocused.observe(viewLifecycleOwner) { searchFocused -> | ||
| 65 | if (searchFocused) { | ||
| 66 | focusSearch() | ||
| 67 | gamesViewModel.setSearchFocused(false) | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | binding.gridGamesSearch.apply { | 64 | binding.gridGamesSearch.apply { |
| 72 | layoutManager = AutofitGridLayoutManager( | 65 | layoutManager = AutofitGridLayoutManager( |
| 73 | requireContext(), | 66 | requireContext(), |
| @@ -87,13 +80,22 @@ class SearchFragment : Fragment() { | |||
| 87 | filterAndSearch() | 80 | filterAndSearch() |
| 88 | } | 81 | } |
| 89 | 82 | ||
| 90 | gamesViewModel.games.observe(viewLifecycleOwner) { filterAndSearch() } | 83 | gamesViewModel.apply { |
| 91 | gamesViewModel.searchedGames.observe(viewLifecycleOwner) { | 84 | searchFocused.observe(viewLifecycleOwner) { searchFocused -> |
| 92 | (binding.gridGamesSearch.adapter as GameAdapter).submitList(it) | 85 | if (searchFocused) { |
| 93 | if (it.isEmpty()) { | 86 | focusSearch() |
| 94 | binding.noResultsView.visibility = View.VISIBLE | 87 | gamesViewModel.setSearchFocused(false) |
| 95 | } else { | 88 | } |
| 96 | binding.noResultsView.visibility = View.GONE | 89 | } |
| 90 | |||
| 91 | games.observe(viewLifecycleOwner) { filterAndSearch() } | ||
| 92 | searchedGames.observe(viewLifecycleOwner) { | ||
| 93 | (binding.gridGamesSearch.adapter as GameAdapter).submitList(it) | ||
| 94 | if (it.isEmpty()) { | ||
| 95 | binding.noResultsView.visibility = View.VISIBLE | ||
| 96 | } else { | ||
| 97 | binding.noResultsView.visibility = View.GONE | ||
| 98 | } | ||
| 97 | } | 99 | } |
| 98 | } | 100 | } |
| 99 | 101 | ||
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 afabfb2b9..97eef40d2 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 | |||
| @@ -55,62 +55,65 @@ class GamesFragment : Fragment() { | |||
| 55 | adapter = GameAdapter(requireActivity() as AppCompatActivity) | 55 | adapter = GameAdapter(requireActivity() as AppCompatActivity) |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | // Add swipe down to refresh gesture | 58 | binding.swipeRefresh.apply { |
| 59 | binding.swipeRefresh.setOnRefreshListener { | 59 | // Add swipe down to refresh gesture |
| 60 | gamesViewModel.reloadGames(false) | 60 | setOnRefreshListener { |
| 61 | } | 61 | gamesViewModel.reloadGames(false) |
| 62 | } | ||
| 62 | 63 | ||
| 63 | // Set theme color to the refresh animation's background | 64 | // Set theme color to the refresh animation's background |
| 64 | binding.swipeRefresh.setProgressBackgroundColorSchemeColor( | 65 | setProgressBackgroundColorSchemeColor( |
| 65 | MaterialColors.getColor( | 66 | MaterialColors.getColor( |
| 66 | binding.swipeRefresh, | 67 | binding.swipeRefresh, |
| 67 | com.google.android.material.R.attr.colorPrimary | 68 | com.google.android.material.R.attr.colorPrimary |
| 69 | ) | ||
| 68 | ) | 70 | ) |
| 69 | ) | 71 | setColorSchemeColors( |
| 70 | binding.swipeRefresh.setColorSchemeColors( | 72 | MaterialColors.getColor( |
| 71 | MaterialColors.getColor( | 73 | binding.swipeRefresh, |
| 72 | binding.swipeRefresh, | 74 | com.google.android.material.R.attr.colorOnPrimary |
| 73 | com.google.android.material.R.attr.colorOnPrimary | 75 | ) |
| 74 | ) | 76 | ) |
| 75 | ) | ||
| 76 | 77 | ||
| 77 | // Watch for when we get updates to any of our games lists | 78 | // Make sure the loading indicator appears even if the layout is told to refresh before being fully drawn |
| 78 | gamesViewModel.isReloading.observe(viewLifecycleOwner) { isReloading -> | 79 | post { |
| 79 | binding.swipeRefresh.isRefreshing = isReloading | 80 | if (_binding == null) { |
| 80 | } | 81 | return@post |
| 81 | gamesViewModel.games.observe(viewLifecycleOwner) { | 82 | } |
| 82 | (binding.gridGames.adapter as GameAdapter).submitList(it) | 83 | binding.swipeRefresh.isRefreshing = gamesViewModel.isReloading.value!! |
| 83 | if (it.isEmpty()) { | ||
| 84 | binding.noticeText.visibility = View.VISIBLE | ||
| 85 | } else { | ||
| 86 | binding.noticeText.visibility = View.GONE | ||
| 87 | } | 84 | } |
| 88 | } | 85 | } |
| 89 | 86 | ||
| 90 | gamesViewModel.shouldSwapData.observe(viewLifecycleOwner) { shouldSwapData -> | 87 | gamesViewModel.apply { |
| 91 | if (shouldSwapData) { | 88 | // Watch for when we get updates to any of our games lists |
| 92 | (binding.gridGames.adapter as GameAdapter).submitList(gamesViewModel.games.value!!) | 89 | isReloading.observe(viewLifecycleOwner) { isReloading -> |
| 93 | gamesViewModel.setShouldSwapData(false) | 90 | binding.swipeRefresh.isRefreshing = isReloading |
| 91 | } | ||
| 92 | games.observe(viewLifecycleOwner) { | ||
| 93 | (binding.gridGames.adapter as GameAdapter).submitList(it) | ||
| 94 | if (it.isEmpty()) { | ||
| 95 | binding.noticeText.visibility = View.VISIBLE | ||
| 96 | } else { | ||
| 97 | binding.noticeText.visibility = View.GONE | ||
| 98 | } | ||
| 99 | } | ||
| 100 | shouldSwapData.observe(viewLifecycleOwner) { shouldSwapData -> | ||
| 101 | if (shouldSwapData) { | ||
| 102 | (binding.gridGames.adapter as GameAdapter).submitList(gamesViewModel.games.value!!) | ||
| 103 | gamesViewModel.setShouldSwapData(false) | ||
| 104 | } | ||
| 94 | } | 105 | } |
| 95 | } | ||
| 96 | 106 | ||
| 97 | // Check if the user reselected the games menu item and then scroll to top of the list | 107 | // Check if the user reselected the games menu item and then scroll to top of the list |
| 98 | gamesViewModel.shouldScrollToTop.observe(viewLifecycleOwner) { shouldScroll -> | 108 | shouldScrollToTop.observe(viewLifecycleOwner) { shouldScroll -> |
| 99 | if (shouldScroll) { | 109 | if (shouldScroll) { |
| 100 | scrollToTop() | 110 | scrollToTop() |
| 101 | gamesViewModel.setShouldScrollToTop(false) | 111 | gamesViewModel.setShouldScrollToTop(false) |
| 112 | } | ||
| 102 | } | 113 | } |
| 103 | } | 114 | } |
| 104 | 115 | ||
| 105 | setInsets() | 116 | setInsets() |
| 106 | |||
| 107 | // Make sure the loading indicator appears even if the layout is told to refresh before being fully drawn | ||
| 108 | binding.swipeRefresh.post { | ||
| 109 | if (_binding == null) { | ||
| 110 | return@post | ||
| 111 | } | ||
| 112 | binding.swipeRefresh.isRefreshing = gamesViewModel.isReloading.value!! | ||
| 113 | } | ||
| 114 | } | 117 | } |
| 115 | 118 | ||
| 116 | override fun onDestroyView() { | 119 | override fun onDestroyView() { |