diff --git a/app/src/main/java/emu/skyline/MainActivity.kt b/app/src/main/java/emu/skyline/MainActivity.kt index 6014ef22..69cc2f6e 100644 --- a/app/src/main/java/emu/skyline/MainActivity.kt +++ b/app/src/main/java/emu/skyline/MainActivity.kt @@ -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() - private var formatFilter : RomFormat? = null - private var appEntries : Map>? = null + private var appEntries : List? = 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().apply { - 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) } - } + sortGameList(entries.toList()).forEach { entry -> + add(AppItem(entry).toViewItem()) } } - sortGameList(gameList.toList()).forEach { entry -> - add(AppItem(entry).toViewItem()) - } } private fun sortGameList(gameList : List) : List { - val sortedApps : MutableList = mutableListOf() + val sortedApps : MutableList = mutableListOf() gameList.forEach { entry -> sortedApps.add(entry) } when (appSettings.sortAppsBy) { SortingOrder.AlphabeticalAsc.ordinal -> sortedApps.sortBy { it.name } diff --git a/app/src/main/java/emu/skyline/MainViewModel.kt b/app/src/main/java/emu/skyline/MainViewModel.kt index 7d0f69f5..ebb3ad7a 100644 --- a/app/src/main/java/emu/skyline/MainViewModel.kt +++ b/app/src/main/java/emu/skyline/MainViewModel.kt @@ -20,7 +20,7 @@ import javax.inject.Inject sealed class MainState { object Loading : MainState() - class Loaded(val items : HashMap>) : MainState() + class Loaded(val items : ArrayList) : 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) diff --git a/app/src/main/java/emu/skyline/RomProvider.kt b/app/src/main/java/emu/skyline/RomProvider.kt index 590ebaf5..d4de3273 100644 --- a/app/src/main/java/emu/skyline/RomProvider.kt +++ b/app/src/main/java/emu/skyline/RomProvider.kt @@ -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, directory : DocumentFile, entries : HashMap>, systemLanguage : Int) { + private fun addEntries(fileFormats : Map, directory : DocumentFile, entries : ArrayList, 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>().apply { + arrayListOf().apply { addEntries(mapOf("nro" to NRO, "nso" to NSO, "nca" to NCA, "nsp" to NSP, "xci" to XCI), documentFile, this, systemLanguage) } }