Fix launch ROM from ROM details screen not using latest config

This commit is contained in:
Rafael Caetano 2024-06-30 12:59:58 +01:00
parent ceb611e29c
commit 8b8e7d3fd6
2 changed files with 16 additions and 8 deletions

View File

@ -15,6 +15,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.ui.Modifier
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import dagger.hilt.android.AndroidEntryPoint
import me.magnum.melonds.domain.model.rom.Rom
import me.magnum.melonds.ui.emulator.EmulatorActivity
import me.magnum.melonds.ui.romdetails.ui.RomScreen
import me.magnum.melonds.ui.theme.MelonTheme
@ -26,12 +27,13 @@ class RomDetailsActivity : AppCompatActivity() {
const val KEY_ROM = "rom"
}
private val romDetailsViewModel by viewModels<RomDetailsViewModel>()
private val romRetroAchievementsViewModel by viewModels<RomDetailsRetroAchievementsViewModel>()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val systemUiController = rememberSystemUiController()
val romDetailsViewModel by viewModels<RomDetailsViewModel>()
val romRetroAchievementsViewModel by viewModels<RomDetailsRetroAchievementsViewModel>()
val rom by romDetailsViewModel.rom.collectAsState()
val romConfig by romDetailsViewModel.romConfigUiState.collectAsState()
@ -55,8 +57,7 @@ class RomDetailsActivity : AppCompatActivity() {
retroAchievementsUiState = retroAchievementsUiState,
onNavigateBack = { onNavigateUp() },
onLaunchRom = {
val intent = EmulatorActivity.getRomEmulatorActivityIntent(this, it)
startActivity(intent)
launchPlayRomIntent(it)
},
onRomConfigUpdate = {
romDetailsViewModel.onRomConfigUpdateEvent(it)
@ -76,6 +77,11 @@ class RomDetailsActivity : AppCompatActivity() {
}
}
private fun launchPlayRomIntent(rom: Rom) {
val intent = EmulatorActivity.getRomEmulatorActivityIntent(this, rom)
startActivity(intent)
}
private fun launchViewAchievementIntent(achievementUrl: String) {
val intent = Intent(Intent.ACTION_VIEW).apply {
data = Uri.parse(achievementUrl)

View File

@ -7,6 +7,7 @@ import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import me.magnum.melonds.common.Permission
import me.magnum.melonds.common.UriPermissionManager
@ -53,7 +54,7 @@ class RomDetailsViewModel @Inject constructor(
fun onRomConfigUpdateEvent(event: RomConfigUpdateEvent) {
val currentRomConfig = _romConfig.value
val newRomConfigUiModel = when(event) {
val newRomConfig = when(event) {
is RomConfigUpdateEvent.RuntimeConsoleUpdate -> currentRomConfig.copy(runtimeConsoleType = event.newRuntimeConsole)
is RomConfigUpdateEvent.RuntimeMicSourceUpdate -> currentRomConfig.copy(runtimeMicSource = event.newRuntimeMicSource)
is RomConfigUpdateEvent.LayoutUpdate -> currentRomConfig.copy(layoutId = event.newLayoutId)
@ -77,9 +78,10 @@ class RomDetailsViewModel @Inject constructor(
}
}
newRomConfigUiModel?.let {
_romConfig.value = it
saveRomConfig(it)
newRomConfig?.let { newConfig ->
_romConfig.value = newConfig
_rom.update { it.copy(config = newConfig) }
saveRomConfig(newConfig)
}
}