Add rating organizations information about rom : refacto + fix refreshing game

This commit is contained in:
kikimanjaro 2023-04-02 16:34:41 +02:00
parent d59d5d560a
commit e0b26cf6f5
3 changed files with 7 additions and 9 deletions

View File

@ -16,9 +16,7 @@ import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.ContextCompat
import androidx.core.content.res.use
import androidx.core.graphics.drawable.toBitmap
import androidx.core.view.WindowCompat
import androidx.core.view.isInvisible
import androidx.core.view.isVisible
@ -352,6 +350,6 @@ class MainActivity : AppCompatActivity() {
adapter.notifyItemRangeChanged(0, adapter.currentItems.size)
}
viewModel.checkRomHash(Uri.parse(appSettings.searchLocation), EmulationSettings.global.systemLanguage)
viewModel.checkRomHash(Uri.parse(appSettings.searchLocation), EmulationSettings.global.systemLanguage, appSettings.ratingOrganization)
}
}

View File

@ -77,11 +77,11 @@ 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) {
fun checkRomHash(searchLocation : Uri, systemLanguage : Int, ratingOrganization : 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 romElements = romProvider.loadRoms(searchLocation, systemLanguage, ratingOrganization)
val newHash = romElements.hashCode()
if (newHash != currentHash) {
state = MainState.Loaded(romElements)

View File

@ -33,16 +33,16 @@ class RatingPreference @JvmOverloads constructor(context : Context, attrs : Attr
entries = RATING_ORGANIZATIONS
entryValues = RATING_ORGANIZATIONS.map { RATING_ORGANIZATIONS.indexOf(it).toString() }.toTypedArray()
value = context?.getSettings()?.ratingOrganization.toString()
value = context.getSettings().ratingOrganization.toString()
onPreferenceChangeListener = OnPreferenceChangeListener { _, newValue ->
context?.getSettings()?.ratingOrganization = (newValue as String).toInt()
context?.getSettings()?.refreshRequired = true
context.getSettings().ratingOrganization = (newValue as String).toInt()
context.getSettings().refreshRequired = true
true
}
summaryProvider = SummaryProvider<ListPreference> {
RATING_ORGANIZATIONS[context?.getSettings()?.ratingOrganization!!]
RATING_ORGANIZATIONS[context.getSettings().ratingOrganization]
}
}
}