mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-11-06 09: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.adapter.*
|
||||||
import emu.skyline.data.AppItem
|
import emu.skyline.data.AppItem
|
||||||
import emu.skyline.data.AppItemTag
|
import emu.skyline.data.AppItemTag
|
||||||
import emu.skyline.data.DataItem
|
|
||||||
import emu.skyline.databinding.MainActivityBinding
|
import emu.skyline.databinding.MainActivityBinding
|
||||||
import emu.skyline.loader.AppEntry
|
import emu.skyline.loader.AppEntry
|
||||||
import emu.skyline.loader.LoaderResult
|
import emu.skyline.loader.LoaderResult
|
||||||
@ -45,9 +44,6 @@ import kotlin.math.ceil
|
|||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class MainActivity : AppCompatActivity() {
|
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) }
|
private val binding by lazy { MainActivityBinding.inflate(layoutInflater) }
|
||||||
|
|
||||||
@ -60,8 +56,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
private val viewModel by viewModels<MainViewModel>()
|
private val viewModel by viewModels<MainViewModel>()
|
||||||
|
|
||||||
private var formatFilter : RomFormat? = null
|
private var appEntries : List<AppEntry>? = null
|
||||||
private var appEntries : Map<RomFormat, List<AppEntry>>? = null
|
|
||||||
|
|
||||||
enum class SortingOrder {
|
enum class SortingOrder {
|
||||||
AlphabeticalAsc,
|
AlphabeticalAsc,
|
||||||
@ -172,7 +167,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
*/
|
*/
|
||||||
private inner class CustomLayoutManager(gridSpan : Int) : GridLayoutManager(this, gridSpan) {
|
private inner class CustomLayoutManager(gridSpan : Int) : GridLayoutManager(this, gridSpan) {
|
||||||
init {
|
init {
|
||||||
spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
|
spanSizeLookup = object : SpanSizeLookup() {
|
||||||
override fun getSpanSize(position : Int) = if (layoutType == LayoutType.List || adapter.currentItems[position].fullSpan) gridSpan else 1
|
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 {
|
private fun getDataItems() = mutableListOf<AppViewItem>().apply {
|
||||||
val gameList = mutableListOf<AppEntry>()
|
|
||||||
appEntries?.let { entries ->
|
appEntries?.let { entries ->
|
||||||
val formats = formatFilter?.let { listOf(it) } ?: formatOrder
|
sortGameList(entries.toList()).forEach { entry ->
|
||||||
for (format in formats) {
|
|
||||||
entries[format]?.let {
|
|
||||||
it.forEach { entry -> gameList.add(entry) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sortGameList(gameList.toList()).forEach { entry ->
|
|
||||||
add(AppItem(entry).toViewItem())
|
add(AppItem(entry).toViewItem())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun sortGameList(gameList : List<AppEntry>) : List<AppEntry> {
|
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) }
|
gameList.forEach { entry -> sortedApps.add(entry) }
|
||||||
when (appSettings.sortAppsBy) {
|
when (appSettings.sortAppsBy) {
|
||||||
SortingOrder.AlphabeticalAsc.ordinal -> sortedApps.sortBy { it.name }
|
SortingOrder.AlphabeticalAsc.ordinal -> sortedApps.sortBy { it.name }
|
||||||
|
@ -20,7 +20,7 @@ import javax.inject.Inject
|
|||||||
|
|
||||||
sealed class MainState {
|
sealed class MainState {
|
||||||
object Loading : 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()
|
class Error(val ex : Exception) : MainState()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ class MainViewModel @Inject constructor(@ApplicationContext context : Context, p
|
|||||||
|
|
||||||
state = if (searchLocation.toString().isEmpty()) {
|
state = if (searchLocation.toString().isEmpty()) {
|
||||||
@Suppress("ReplaceWithEnumMap")
|
@Suppress("ReplaceWithEnumMap")
|
||||||
MainState.Loaded(HashMap())
|
MainState.Loaded(ArrayList())
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
KeyReader.importFromLocation(context, searchLocation)
|
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
|
* This adds all files in [directory] with [extension] as an entry using [RomFile] to load metadata
|
||||||
*/
|
*/
|
||||||
@SuppressLint("DefaultLocale")
|
@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 ->
|
directory.listFiles().forEach { file ->
|
||||||
if (file.isDirectory) {
|
if (file.isDirectory) {
|
||||||
addEntries(fileFormats, file, entries, systemLanguage)
|
addEntries(fileFormats, file, entries, systemLanguage)
|
||||||
} else {
|
} else {
|
||||||
fileFormats[file.name?.substringAfterLast(".")?.lowercase()]?.let { romFormat->
|
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 ->
|
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)
|
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