VERY experimental Nintendo Switch 2 emulator
C++
android: Listen for directory selection in viewmodel
t895a939ceb7cb5b
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/AddGameFolderDialogFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/AddGameFolderDialogFragment.ktindex dec2b7cf16..9fab88248d 100644--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/AddGameFolderDialogFragment.kt+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/AddGameFolderDialogFragment.kt@@ -14,8 +14,10 @@ import org.yuzu.yuzu_emu.Rimport org.yuzu.yuzu_emu.databinding.DialogAddFolderBindingimport org.yuzu.yuzu_emu.model.GameDirimport org.yuzu.yuzu_emu.model.GamesViewModel+import org.yuzu.yuzu_emu.model.HomeViewModelclass AddGameFolderDialogFragment : DialogFragment() {+ private val homeViewModel: HomeViewModel by activityViewModels()private val gamesViewModel: GamesViewModel by activityViewModels()override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {@@ -30,6 +32,7 @@ class AddGameFolderDialogFragment : DialogFragment() {.setTitle(R.string.add_game_folder).setPositiveButton(android.R.string.ok) { _: DialogInterface, _: Int ->val newGameDir = GameDir(folderUriString!!, binding.deepScanSwitch.isChecked)+ homeViewModel.setGamesDirSelected(true)gamesViewModel.addFolder(newGameDir)}.setNegativeButton(android.R.string.cancel, null)diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/SetupFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/SetupFragment.ktindex c4277735da..eb5edaa104 100644--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/SetupFragment.kt+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/SetupFragment.kt@@ -4,6 +4,7 @@package org.yuzu.yuzu_emu.fragmentsimport android.Manifest+import android.annotation.SuppressLintimport android.content.Intentimport android.os.Buildimport android.os.Bundle@@ -75,6 +76,8 @@ class SetupFragment : Fragment() {return binding.root}+ // This is using the correct scope, lint is just acting up+ @SuppressLint("UnsafeRepeatOnLifecycleDetector")override fun onViewCreated(view: View, savedInstanceState: Bundle?) {mainActivity = requireActivity() as MainActivity@@ -206,12 +209,24 @@ class SetupFragment : Fragment() {)}- viewLifecycleOwner.lifecycleScope.launch {- repeatOnLifecycle(Lifecycle.State.CREATED) {- homeViewModel.shouldPageForward.collect {- if (it) {- pageForward()- homeViewModel.setShouldPageForward(false)+ viewLifecycleOwner.lifecycleScope.apply {+ launch {+ repeatOnLifecycle(Lifecycle.State.CREATED) {+ homeViewModel.shouldPageForward.collect {+ if (it) {+ pageForward()+ homeViewModel.setShouldPageForward(false)+ }+ }+ }+ }+ launch {+ repeatOnLifecycle(Lifecycle.State.CREATED) {+ homeViewModel.gamesDirSelected.collect {+ if (it) {+ gamesDirCallback.onStepCompleted()+ homeViewModel.setGamesDirSelected(false)+ }}}}@@ -339,7 +354,6 @@ class SetupFragment : Fragment() {registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) { result ->if (result != null) {mainActivity.processGamesDir(result)- gamesDirCallback.onStepCompleted()}}diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.ktindex 752d98c102..fd925235b9 100644--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt@@ -133,7 +133,7 @@ class GamesViewModel : ViewModel() {viewModelScope.launch {withContext(Dispatchers.IO) {NativeConfig.addGameDir(gameDir)- getGameDirs()+ getGameDirs(true)}}diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/HomeViewModel.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/HomeViewModel.ktindex 251b5a6676..07e65b028d 100644--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/HomeViewModel.kt+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/model/HomeViewModel.kt@@ -6,6 +6,7 @@ package org.yuzu.yuzu_emu.modelimport androidx.lifecycle.ViewModelimport kotlinx.coroutines.flow.MutableStateFlowimport kotlinx.coroutines.flow.StateFlow+import kotlinx.coroutines.flow.asStateFlowclass HomeViewModel : ViewModel() {val navigationVisible: StateFlow<Pair<Boolean, Boolean>> get() = _navigationVisible@@ -17,6 +18,9 @@ class HomeViewModel : ViewModel() {val shouldPageForward: StateFlow<Boolean> get() = _shouldPageForwardprivate val _shouldPageForward = MutableStateFlow(false)+ private val _gamesDirSelected = MutableStateFlow(false)+ val gamesDirSelected get() = _gamesDirSelected.asStateFlow()+var navigatedToSetup = falsefun setNavigationVisibility(visible: Boolean, animated: Boolean) {@@ -36,4 +40,8 @@ class HomeViewModel : ViewModel() {fun setShouldPageForward(pageForward: Boolean) {_shouldPageForward.value = pageForward}++ fun setGamesDirSelected(selected: Boolean) {+ _gamesDirSelected.value = selected+ }}