Просмотр исходного кода

android: Sort games alphabetically by default

Charles Lombardo 3 лет назад
Родитель
Сommit
03541703fa
1 измененных файлов с 9 добавлено и 2 удалено
  1. 9 2
      src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/GamesFragment.kt

+ 9 - 2
src/android/app/src/main/java/org/yuzu/yuzu_emu/ui/GamesFragment.kt

@@ -20,8 +20,10 @@ import org.yuzu.yuzu_emu.R
 import org.yuzu.yuzu_emu.adapters.GameAdapter
 import org.yuzu.yuzu_emu.adapters.GameAdapter
 import org.yuzu.yuzu_emu.databinding.FragmentGamesBinding
 import org.yuzu.yuzu_emu.databinding.FragmentGamesBinding
 import org.yuzu.yuzu_emu.layout.AutofitGridLayoutManager
 import org.yuzu.yuzu_emu.layout.AutofitGridLayoutManager
+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 java.util.Locale
 
 
 class GamesFragment : Fragment() {
 class GamesFragment : Fragment() {
     private var _binding: FragmentGamesBinding? = null
     private var _binding: FragmentGamesBinding? = null
@@ -73,7 +75,7 @@ class GamesFragment : Fragment() {
             binding.swipeRefresh.isRefreshing = isReloading
             binding.swipeRefresh.isRefreshing = isReloading
         }
         }
         gamesViewModel.games.observe(viewLifecycleOwner) {
         gamesViewModel.games.observe(viewLifecycleOwner) {
-            (binding.gridGames.adapter as GameAdapter).submitList(it)
+            submitGamesList(it)
             if (it.isEmpty()) {
             if (it.isEmpty()) {
                 binding.noticeText.visibility = View.VISIBLE
                 binding.noticeText.visibility = View.VISIBLE
             } else {
             } else {
@@ -83,7 +85,7 @@ class GamesFragment : Fragment() {
 
 
         gamesViewModel.shouldSwapData.observe(viewLifecycleOwner) { shouldSwapData ->
         gamesViewModel.shouldSwapData.observe(viewLifecycleOwner) { shouldSwapData ->
             if (shouldSwapData) {
             if (shouldSwapData) {
-                (binding.gridGames.adapter as GameAdapter).submitList(gamesViewModel.games.value)
+                submitGamesList(gamesViewModel.games.value!!)
                 gamesViewModel.setShouldSwapData(false)
                 gamesViewModel.setShouldSwapData(false)
             }
             }
         }
         }
@@ -107,6 +109,11 @@ class GamesFragment : Fragment() {
         }
         }
     }
     }
 
 
+    private fun submitGamesList(gameList: List<Game>) {
+        val sortedList = gameList.sortedBy { it.title.lowercase(Locale.getDefault()) }
+        (binding.gridGames.adapter as GameAdapter).submitList(sortedList)
+    }
+
     override fun onDestroyView() {
     override fun onDestroyView() {
         super.onDestroyView()
         super.onDestroyView()
         _binding = null
         _binding = null