Added functionality to make optional to group games by format and sort

This commit is contained in:
hacobot.dev 2023-01-10 14:19:22 -07:00 committed by Billy Laws
parent 6b9be2edd4
commit b67bfe3848
5 changed files with 57 additions and 6 deletions

View File

@ -217,17 +217,44 @@ class MainActivity : AppCompatActivity() {
}
private fun getDataItems() = mutableListOf<DataItem>().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<AppEntry>()
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<AppEntry>) : MutableList<AppEntry> {
val sortedApps : MutableList<AppEntry> = mutableListOf<AppEntry>()
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) }

View File

@ -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)

View File

@ -12,6 +12,10 @@
<item>Grid</item>
<item>Grid Compact</item>
</string-array>
<string-array name="sort_apps_by">
<item>A-Z</item>
<item>Z-A</item>
</string-array>
<string-array name="app_theme">
<item>Light</item>
<item>Dark</item>

View File

@ -30,6 +30,10 @@
<string name="failed_open_directory">Cannot find an external file manager to open Skyline\'s internal directory</string>
<string name="theme">Theme</string>
<string name="layout_type">Game Display Layout</string>
<string name="group_by_format">Group Games By Format</string>
<string name="group_by_format_desc_off">Games will be shown as a single list</string>
<string name="group_by_format_desc_on">Games will be shown grouped by format</string>
<string name="sort_apps_by">Games Sorting Order</string>
<string name="select_action">Always Show Game Information</string>
<string name="select_action_desc_on">Game information will be shown on clicking a game</string>
<string name="select_action_desc_off">Game information will only be shown on long-clicking a game</string>

View File

@ -22,6 +22,20 @@
app:key="layout_type"
app:title="@string/layout_type"
app:useSimpleSummaryProvider="true" />
<CheckBoxPreference
android:defaultValue="true"
android:summaryOff="@string/group_by_format_desc_off"
android:summaryOn="@string/group_by_format_desc_on"
app:key="group_by_format"
app:refreshRequired="true"
app:title="@string/group_by_format" />
<emu.skyline.preference.IntegerListPreference
android:defaultValue="0"
android:entries="@array/sort_apps_by"
app:key="sort_apps_by"
app:refreshRequired="true"
app:title="@string/sort_apps_by"
app:useSimpleSummaryProvider="true" />
<CheckBoxPreference
android:defaultValue="false"
android:summaryOff="@string/select_action_desc_off"