summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar liamwhite2023-12-09 13:38:34 -0500
committerGravatar GitHub2023-12-09 13:38:34 -0500
commitf4479960806b3dda15b367830de53bf616a33b49 (patch)
tree57009813a2ee7d14b48839749199651aeb63c6fb
parentMerge pull request #12318 from t895/nce-default (diff)
parentandroid: Listen for directory selection in viewmodel (diff)
downloadyuzu-f4479960806b3dda15b367830de53bf616a33b49.tar.gz
yuzu-f4479960806b3dda15b367830de53bf616a33b49.tar.xz
yuzu-f4479960806b3dda15b367830de53bf616a33b49.zip
Merge pull request #12319 from t895/refresh-list-bug
android: Listen for directory selection in viewmodel
Diffstat (limited to '')
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/AddGameFolderDialogFragment.kt3
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/SetupFragment.kt28
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/model/GamesViewModel.kt2
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/model/HomeViewModel.kt8
4 files changed, 33 insertions, 8 deletions
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.kt
index dec2b7cf1..9fab88248 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.R
14import org.yuzu.yuzu_emu.databinding.DialogAddFolderBinding 14import org.yuzu.yuzu_emu.databinding.DialogAddFolderBinding
15import org.yuzu.yuzu_emu.model.GameDir 15import org.yuzu.yuzu_emu.model.GameDir
16import org.yuzu.yuzu_emu.model.GamesViewModel 16import org.yuzu.yuzu_emu.model.GamesViewModel
17import org.yuzu.yuzu_emu.model.HomeViewModel
17 18
18class AddGameFolderDialogFragment : DialogFragment() { 19class AddGameFolderDialogFragment : DialogFragment() {
20 private val homeViewModel: HomeViewModel by activityViewModels()
19 private val gamesViewModel: GamesViewModel by activityViewModels() 21 private val gamesViewModel: GamesViewModel by activityViewModels()
20 22
21 override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { 23 override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
@@ -30,6 +32,7 @@ class AddGameFolderDialogFragment : DialogFragment() {
30 .setTitle(R.string.add_game_folder) 32 .setTitle(R.string.add_game_folder)
31 .setPositiveButton(android.R.string.ok) { _: DialogInterface, _: Int -> 33 .setPositiveButton(android.R.string.ok) { _: DialogInterface, _: Int ->
32 val newGameDir = GameDir(folderUriString!!, binding.deepScanSwitch.isChecked) 34 val newGameDir = GameDir(folderUriString!!, binding.deepScanSwitch.isChecked)
35 homeViewModel.setGamesDirSelected(true)
33 gamesViewModel.addFolder(newGameDir) 36 gamesViewModel.addFolder(newGameDir)
34 } 37 }
35 .setNegativeButton(android.R.string.cancel, null) 38 .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.kt
index c4277735d..eb5edaa10 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 @@
4package org.yuzu.yuzu_emu.fragments 4package org.yuzu.yuzu_emu.fragments
5 5
6import android.Manifest 6import android.Manifest
7import android.annotation.SuppressLint
7import android.content.Intent 8import android.content.Intent
8import android.os.Build 9import android.os.Build
9import android.os.Bundle 10import android.os.Bundle
@@ -75,6 +76,8 @@ class SetupFragment : Fragment() {
75 return binding.root 76 return binding.root
76 } 77 }
77 78
79 // This is using the correct scope, lint is just acting up
80 @SuppressLint("UnsafeRepeatOnLifecycleDetector")
78 override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 81 override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
79 mainActivity = requireActivity() as MainActivity 82 mainActivity = requireActivity() as MainActivity
80 83
@@ -206,12 +209,24 @@ class SetupFragment : Fragment() {
206 ) 209 )
207 } 210 }
208 211
209 viewLifecycleOwner.lifecycleScope.launch { 212 viewLifecycleOwner.lifecycleScope.apply {
210 repeatOnLifecycle(Lifecycle.State.CREATED) { 213 launch {
211 homeViewModel.shouldPageForward.collect { 214 repeatOnLifecycle(Lifecycle.State.CREATED) {
212 if (it) { 215 homeViewModel.shouldPageForward.collect {
213 pageForward() 216 if (it) {
214 homeViewModel.setShouldPageForward(false) 217 pageForward()
218 homeViewModel.setShouldPageForward(false)
219 }
220 }
221 }
222 }
223 launch {
224 repeatOnLifecycle(Lifecycle.State.CREATED) {
225 homeViewModel.gamesDirSelected.collect {
226 if (it) {
227 gamesDirCallback.onStepCompleted()
228 homeViewModel.setGamesDirSelected(false)
229 }
215 } 230 }
216 } 231 }
217 } 232 }
@@ -339,7 +354,6 @@ class SetupFragment : Fragment() {
339 registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) { result -> 354 registerForActivityResult(ActivityResultContracts.OpenDocumentTree()) { result ->
340 if (result != null) { 355 if (result != null) {
341 mainActivity.processGamesDir(result) 356 mainActivity.processGamesDir(result)
342 gamesDirCallback.onStepCompleted()
343 } 357 }
344 } 358 }
345 359
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.kt
index 752d98c10..fd925235b 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() {
133 viewModelScope.launch { 133 viewModelScope.launch {
134 withContext(Dispatchers.IO) { 134 withContext(Dispatchers.IO) {
135 NativeConfig.addGameDir(gameDir) 135 NativeConfig.addGameDir(gameDir)
136 getGameDirs() 136 getGameDirs(true)
137 } 137 }
138 } 138 }
139 139
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.kt
index 251b5a667..07e65b028 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.model
6import androidx.lifecycle.ViewModel 6import androidx.lifecycle.ViewModel
7import kotlinx.coroutines.flow.MutableStateFlow 7import kotlinx.coroutines.flow.MutableStateFlow
8import kotlinx.coroutines.flow.StateFlow 8import kotlinx.coroutines.flow.StateFlow
9import kotlinx.coroutines.flow.asStateFlow
9 10
10class HomeViewModel : ViewModel() { 11class HomeViewModel : ViewModel() {
11 val navigationVisible: StateFlow<Pair<Boolean, Boolean>> get() = _navigationVisible 12 val navigationVisible: StateFlow<Pair<Boolean, Boolean>> get() = _navigationVisible
@@ -17,6 +18,9 @@ class HomeViewModel : ViewModel() {
17 val shouldPageForward: StateFlow<Boolean> get() = _shouldPageForward 18 val shouldPageForward: StateFlow<Boolean> get() = _shouldPageForward
18 private val _shouldPageForward = MutableStateFlow(false) 19 private val _shouldPageForward = MutableStateFlow(false)
19 20
21 private val _gamesDirSelected = MutableStateFlow(false)
22 val gamesDirSelected get() = _gamesDirSelected.asStateFlow()
23
20 var navigatedToSetup = false 24 var navigatedToSetup = false
21 25
22 fun setNavigationVisibility(visible: Boolean, animated: Boolean) { 26 fun setNavigationVisibility(visible: Boolean, animated: Boolean) {
@@ -36,4 +40,8 @@ class HomeViewModel : ViewModel() {
36 fun setShouldPageForward(pageForward: Boolean) { 40 fun setShouldPageForward(pageForward: Boolean) {
37 _shouldPageForward.value = pageForward 41 _shouldPageForward.value = pageForward
38 } 42 }
43
44 fun setGamesDirSelected(selected: Boolean) {
45 _gamesDirSelected.value = selected
46 }
39} 47}