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 androidx.compose.ui.Modifier
|
||||||
import com.google.accompanist.systemuicontroller.rememberSystemUiController
|
import com.google.accompanist.systemuicontroller.rememberSystemUiController
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
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.emulator.EmulatorActivity
|
||||||
import me.magnum.melonds.ui.romdetails.ui.RomScreen
|
import me.magnum.melonds.ui.romdetails.ui.RomScreen
|
||||||
import me.magnum.melonds.ui.theme.MelonTheme
|
import me.magnum.melonds.ui.theme.MelonTheme
|
||||||
@ -26,12 +27,13 @@ class RomDetailsActivity : AppCompatActivity() {
|
|||||||
const val KEY_ROM = "rom"
|
const val KEY_ROM = "rom"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val romDetailsViewModel by viewModels<RomDetailsViewModel>()
|
||||||
|
private val romRetroAchievementsViewModel by viewModels<RomDetailsRetroAchievementsViewModel>()
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContent {
|
setContent {
|
||||||
val systemUiController = rememberSystemUiController()
|
val systemUiController = rememberSystemUiController()
|
||||||
val romDetailsViewModel by viewModels<RomDetailsViewModel>()
|
|
||||||
val romRetroAchievementsViewModel by viewModels<RomDetailsRetroAchievementsViewModel>()
|
|
||||||
|
|
||||||
val rom by romDetailsViewModel.rom.collectAsState()
|
val rom by romDetailsViewModel.rom.collectAsState()
|
||||||
val romConfig by romDetailsViewModel.romConfigUiState.collectAsState()
|
val romConfig by romDetailsViewModel.romConfigUiState.collectAsState()
|
||||||
@ -55,8 +57,7 @@ class RomDetailsActivity : AppCompatActivity() {
|
|||||||
retroAchievementsUiState = retroAchievementsUiState,
|
retroAchievementsUiState = retroAchievementsUiState,
|
||||||
onNavigateBack = { onNavigateUp() },
|
onNavigateBack = { onNavigateUp() },
|
||||||
onLaunchRom = {
|
onLaunchRom = {
|
||||||
val intent = EmulatorActivity.getRomEmulatorActivityIntent(this, it)
|
launchPlayRomIntent(it)
|
||||||
startActivity(intent)
|
|
||||||
},
|
},
|
||||||
onRomConfigUpdate = {
|
onRomConfigUpdate = {
|
||||||
romDetailsViewModel.onRomConfigUpdateEvent(it)
|
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) {
|
private fun launchViewAchievementIntent(achievementUrl: String) {
|
||||||
val intent = Intent(Intent.ACTION_VIEW).apply {
|
val intent = Intent(Intent.ACTION_VIEW).apply {
|
||||||
data = Uri.parse(achievementUrl)
|
data = Uri.parse(achievementUrl)
|
||||||
|
@ -7,6 +7,7 @@ import dagger.hilt.android.lifecycle.HiltViewModel
|
|||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
|
import kotlinx.coroutines.flow.update
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import me.magnum.melonds.common.Permission
|
import me.magnum.melonds.common.Permission
|
||||||
import me.magnum.melonds.common.UriPermissionManager
|
import me.magnum.melonds.common.UriPermissionManager
|
||||||
@ -53,7 +54,7 @@ class RomDetailsViewModel @Inject constructor(
|
|||||||
|
|
||||||
fun onRomConfigUpdateEvent(event: RomConfigUpdateEvent) {
|
fun onRomConfigUpdateEvent(event: RomConfigUpdateEvent) {
|
||||||
val currentRomConfig = _romConfig.value
|
val currentRomConfig = _romConfig.value
|
||||||
val newRomConfigUiModel = when(event) {
|
val newRomConfig = when(event) {
|
||||||
is RomConfigUpdateEvent.RuntimeConsoleUpdate -> currentRomConfig.copy(runtimeConsoleType = event.newRuntimeConsole)
|
is RomConfigUpdateEvent.RuntimeConsoleUpdate -> currentRomConfig.copy(runtimeConsoleType = event.newRuntimeConsole)
|
||||||
is RomConfigUpdateEvent.RuntimeMicSourceUpdate -> currentRomConfig.copy(runtimeMicSource = event.newRuntimeMicSource)
|
is RomConfigUpdateEvent.RuntimeMicSourceUpdate -> currentRomConfig.copy(runtimeMicSource = event.newRuntimeMicSource)
|
||||||
is RomConfigUpdateEvent.LayoutUpdate -> currentRomConfig.copy(layoutId = event.newLayoutId)
|
is RomConfigUpdateEvent.LayoutUpdate -> currentRomConfig.copy(layoutId = event.newLayoutId)
|
||||||
@ -77,9 +78,10 @@ class RomDetailsViewModel @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newRomConfigUiModel?.let {
|
newRomConfig?.let { newConfig ->
|
||||||
_romConfig.value = it
|
_romConfig.value = newConfig
|
||||||
saveRomConfig(it)
|
_rom.update { it.copy(config = newConfig) }
|
||||||
|
saveRomConfig(newConfig)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user