mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-06-01 08:38:46 +02:00
Add automatic refreshing games list - Refacto
This commit is contained in:
parent
6076050bb3
commit
d94d63ecea
|
@ -352,6 +352,6 @@ class MainActivity : AppCompatActivity() {
|
|||
adapter.notifyItemRangeChanged(0, adapter.currentItems.size)
|
||||
}
|
||||
|
||||
viewModel.checkRomHash(this, Uri.parse(appSettings.searchLocation), EmulationSettings.global.systemLanguage)
|
||||
viewModel.checkRomHash(Uri.parse(appSettings.searchLocation), EmulationSettings.global.systemLanguage)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -77,15 +77,14 @@ class MainViewModel @Inject constructor(@ApplicationContext context : Context, p
|
|||
/**
|
||||
* This checks if the roms have changed since the last time they were loaded and if so it reloads them
|
||||
*/
|
||||
fun checkRomHash(context : Context, searchLocation : Uri, systemLanguage : Int) {
|
||||
fun checkRomHash(searchLocation : Uri, systemLanguage : Int) {
|
||||
if(state !is MainState.Loaded) return
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
val oldHashFile = File(getApplication<SkylineApplication>().filesDir.canonicalPath + "/roms.txt")
|
||||
val oldHash = if (oldHashFile.exists()) oldHashFile.readText().toIntOrNull() else null
|
||||
val romElements = romProvider.loadRoms(searchLocation, systemLanguage).values.flatten().toList()
|
||||
val newHash = romElements.map { it.name }.toSet().hashCode()
|
||||
if (newHash != oldHash) {
|
||||
loadRoms(context, false, searchLocation, systemLanguage)
|
||||
oldHashFile.writeText(newHash.toString())
|
||||
val currentHash = (state as MainState.Loaded).items.hashCode()
|
||||
val romElements = romProvider.loadRoms(searchLocation, systemLanguage)
|
||||
val newHash = romElements.hashCode()
|
||||
if (newHash != currentHash) {
|
||||
state = MainState.Loaded(romElements)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user