Skip to content

Commit

Permalink
Fix launch ROM from ROM details screen not using latest config
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelvcaetano committed Jun 30, 2024
1 parent ceb611e commit 8b8e7d3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
}

Expand Down

0 comments on commit 8b8e7d3

Please sign in to comment.