mirror of
https://github.com/rafaelvcaetano/melonDS-android.git
synced 2024-11-23 05:39:41 +00:00
Fix launch ROM from ROM details screen not using latest config
This commit is contained in:
parent
ceb611e29c
commit
8b8e7d3fd6
@ -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)
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user