Remove RomFormat as an AppEntry key

There may be a time and place where knowing the format is necessary, but it is not in the list of games being presented to the end-user
This commit is contained in:
Abandoned Cart 2023-04-19 07:47:52 -04:00 committed by Billy Laws
parent fe46213beb
commit c8e0f71bb7
3 changed files with 10 additions and 22 deletions

View File

@ -29,7 +29,6 @@ import dagger.hilt.android.AndroidEntryPoint
import emu.skyline.adapter.*
import emu.skyline.data.AppItem
import emu.skyline.data.AppItemTag
import emu.skyline.data.DataItem
import emu.skyline.databinding.MainActivityBinding
import emu.skyline.loader.AppEntry
import emu.skyline.loader.LoaderResult
@ -45,9 +44,6 @@ import kotlin.math.ceil
@AndroidEntryPoint
class MainActivity : AppCompatActivity() {
companion object {
private val formatOrder = listOf(RomFormat.NSP, RomFormat.XCI, RomFormat.NRO, RomFormat.NSO, RomFormat.NCA)
}
private val binding by lazy { MainActivityBinding.inflate(layoutInflater) }
@ -60,8 +56,7 @@ class MainActivity : AppCompatActivity() {
private val viewModel by viewModels<MainViewModel>()
private var formatFilter : RomFormat? = null
private var appEntries : Map<RomFormat, List<AppEntry>>? = null
private var appEntries : List<AppEntry>? = null
enum class SortingOrder {
AlphabeticalAsc,
@ -172,7 +167,7 @@ class MainActivity : AppCompatActivity() {
*/
private inner class CustomLayoutManager(gridSpan : Int) : GridLayoutManager(this, gridSpan) {
init {
spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
spanSizeLookup = object : SpanSizeLookup() {
override fun getSpanSize(position : Int) = if (layoutType == LayoutType.List || adapter.currentItems[position].fullSpan) gridSpan else 1
}
}
@ -216,22 +211,15 @@ class MainActivity : AppCompatActivity() {
}
private fun getDataItems() = mutableListOf<AppViewItem>().apply {
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) }
}
sortGameList(entries.toList()).forEach { entry ->
add(AppItem(entry).toViewItem())
}
}
sortGameList(gameList.toList()).forEach { entry ->
add(AppItem(entry).toViewItem())
}
}
private fun sortGameList(gameList : List<AppEntry>) : List<AppEntry> {
val sortedApps : MutableList<AppEntry> = mutableListOf<AppEntry>()
val sortedApps : MutableList<AppEntry> = mutableListOf()
gameList.forEach { entry -> sortedApps.add(entry) }
when (appSettings.sortAppsBy) {
SortingOrder.AlphabeticalAsc.ordinal -> sortedApps.sortBy { it.name }

View File

@ -20,7 +20,7 @@ import javax.inject.Inject
sealed class MainState {
object Loading : MainState()
class Loaded(val items : HashMap<RomFormat, ArrayList<AppEntry>>) : MainState()
class Loaded(val items : ArrayList<AppEntry>) : MainState()
class Error(val ex : Exception) : MainState()
}
@ -59,7 +59,7 @@ class MainViewModel @Inject constructor(@ApplicationContext context : Context, p
state = if (searchLocation.toString().isEmpty()) {
@Suppress("ReplaceWithEnumMap")
MainState.Loaded(HashMap())
MainState.Loaded(ArrayList())
} else {
try {
KeyReader.importFromLocation(context, searchLocation)

View File

@ -18,20 +18,20 @@ class RomProvider @Inject constructor(@ApplicationContext private val context :
* This adds all files in [directory] with [extension] as an entry using [RomFile] to load metadata
*/
@SuppressLint("DefaultLocale")
private fun addEntries(fileFormats : Map<String, RomFormat>, directory : DocumentFile, entries : HashMap<RomFormat, ArrayList<AppEntry>>, systemLanguage : Int) {
private fun addEntries(fileFormats : Map<String, RomFormat>, directory : DocumentFile, entries : ArrayList<AppEntry>, systemLanguage : Int) {
directory.listFiles().forEach { file ->
if (file.isDirectory) {
addEntries(fileFormats, file, entries, systemLanguage)
} else {
fileFormats[file.name?.substringAfterLast(".")?.lowercase()]?.let { romFormat->
entries.getOrPut(romFormat, { arrayListOf() }).add(RomFile(context, romFormat, file.uri, systemLanguage).appEntry)
entries.add(RomFile(context, romFormat, file.uri, systemLanguage).appEntry)
}
}
}
}
fun loadRoms(searchLocation : Uri, systemLanguage : Int) = DocumentFile.fromTreeUri(context, searchLocation)!!.let { documentFile ->
hashMapOf<RomFormat, ArrayList<AppEntry>>().apply {
arrayListOf<AppEntry>().apply {
addEntries(mapOf("nro" to NRO, "nso" to NSO, "nca" to NCA, "nsp" to NSP, "xci" to XCI), documentFile, this, systemLanguage)
}
}