Add automatic refreshing games list

This commit is contained in:
kikimanjaro 2023-03-19 14:46:07 +01:00 committed by lynxnb
parent d00fcee79d
commit 0eed72664d
2 changed files with 18 additions and 1 deletions

View File

@ -351,5 +351,7 @@ class MainActivity : AppCompatActivity() {
setAppListDecoration() setAppListDecoration()
adapter.notifyItemRangeChanged(0, adapter.currentItems.size) adapter.notifyItemRangeChanged(0, adapter.currentItems.size)
} }
viewModel.checkRomHash(Uri.parse(appSettings.searchLocation), EmulationSettings.global.systemLanguage)
} }
} }

View File

@ -11,12 +11,12 @@ import emu.skyline.loader.AppEntry
import emu.skyline.loader.RomFormat import emu.skyline.loader.RomFormat
import emu.skyline.utils.fromFile import emu.skyline.utils.fromFile
import emu.skyline.utils.toFile import emu.skyline.utils.toFile
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import java.io.File import java.io.File
import java.util.* import java.util.*
import javax.inject.Inject import javax.inject.Inject
import kotlin.collections.HashMap
sealed class MainState { sealed class MainState {
object Loading : MainState() object Loading : MainState()
@ -73,4 +73,19 @@ 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(searchLocation : Uri, systemLanguage : Int) {
if(state !is MainState.Loaded) return
CoroutineScope(Dispatchers.IO).launch {
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)
}
}
}
} }