From b67bfe3848d81daa8c5ac62ec9ada0789fd4d71b Mon Sep 17 00:00:00 2001 From: "hacobot.dev" Date: Tue, 10 Jan 2023 14:19:22 -0700 Subject: [PATCH] Added functionality to make optional to group games by format and sort --- app/src/main/java/emu/skyline/MainActivity.kt | 39 ++++++++++++++++--- .../emu/skyline/utils/PreferenceSettings.kt | 2 + app/src/main/res/values/array.xml | 4 ++ app/src/main/res/values/strings.xml | 4 ++ app/src/main/res/xml/preferences.xml | 14 +++++++ 5 files changed, 57 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/emu/skyline/MainActivity.kt b/app/src/main/java/emu/skyline/MainActivity.kt index c96a6dbf..09cfc033 100644 --- a/app/src/main/java/emu/skyline/MainActivity.kt +++ b/app/src/main/java/emu/skyline/MainActivity.kt @@ -217,17 +217,44 @@ class MainActivity : AppCompatActivity() { } private fun getDataItems() = mutableListOf().apply { - appEntries?.let { entries -> - val formats = formatFilter?.let { listOf(it) } ?: formatOrder - for (format in formats) { - entries[format]?.let { - add(HeaderItem(format.name)) - it.forEach { entry -> add(AppItem(entry)) } + if (preferenceSettings.groupByFormat) { + appEntries?.let { entries -> + val formats = formatFilter?.let { listOf(it) } ?: formatOrder + for (format in formats) { + entries[format]?.let { + add(HeaderItem(format.name)) + for (entry in sortGameList(it)) { + add(AppItem(entry)) + } + } } } + } else { + val gameList = mutableListOf() + appEntries?.let { entries -> + val formats = formatFilter?.let { listOf(it) } ?: formatOrder + for (format in formats) { + entries[format]?.let { + it.forEach { entry -> gameList.add(entry) } + } + } + } + for (entry in sortGameList(gameList.toList())) { + add(AppItem(entry)) + } } } + private fun sortGameList(gameList : List) : MutableList { + val sortedApps : MutableList = mutableListOf() + gameList.forEach { entry -> sortedApps.add(entry) } + when (preferenceSettings.sortAppsBy) { + 1 -> sortedApps.sortByDescending { it.name } + else -> sortedApps.sortBy { it.name } + } + return sortedApps + } + private fun handleState(state : MainState) = when (state) { MainState.Loading -> { binding.refreshIcon.apply { animate().rotation(rotation - 180f) } diff --git a/app/src/main/java/emu/skyline/utils/PreferenceSettings.kt b/app/src/main/java/emu/skyline/utils/PreferenceSettings.kt index 5e3f936a..d67a0b08 100644 --- a/app/src/main/java/emu/skyline/utils/PreferenceSettings.kt +++ b/app/src/main/java/emu/skyline/utils/PreferenceSettings.kt @@ -18,6 +18,8 @@ class PreferenceSettings @Inject constructor(@ApplicationContext private val con var searchLocation by sharedPreferences(context, "") var appTheme by sharedPreferences(context, 2) var layoutType by sharedPreferences(context, 1) + var groupByFormat by sharedPreferences(context, true) + var sortAppsBy by sharedPreferences(context, 0) var selectAction by sharedPreferences(context, false) var perfStats by sharedPreferences(context, false) var logLevel by sharedPreferences(context, 3) diff --git a/app/src/main/res/values/array.xml b/app/src/main/res/values/array.xml index 069adffb..e604bdec 100644 --- a/app/src/main/res/values/array.xml +++ b/app/src/main/res/values/array.xml @@ -12,6 +12,10 @@ Grid Grid Compact + + A-Z + Z-A + Light Dark diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bc45ee29..8b1521d5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -30,6 +30,10 @@ Cannot find an external file manager to open Skyline\'s internal directory Theme Game Display Layout + Group Games By Format + Games will be shown as a single list + Games will be shown grouped by format + Games Sorting Order Always Show Game Information Game information will be shown on clicking a game Game information will only be shown on long-clicking a game diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index c1db5116..7793cb06 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -22,6 +22,20 @@ app:key="layout_type" app:title="@string/layout_type" app:useSimpleSummaryProvider="true" /> + +