mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-11-06 04:35:09 +01:00
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:
parent
fe46213beb
commit
c8e0f71bb7
@ -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(gameList.toList()).forEach { entry ->
|
||||
sortGameList(entries.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 }
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user