android: Fix game content installer

Before this would run on the main thread and freeze the device. Additionally this fixes the result dialog not appearing if a config change happens during the installation by getting the activity's fragment manager when needed.
This commit is contained in:
Charles Lombardo 2023-08-30 19:05:33 -04:00
parent d833fc383d
commit 50d4e0f4f7
2 changed files with 80 additions and 85 deletions

View File

@ -34,7 +34,7 @@ class IndeterminateProgressDialogFragment : DialogFragment() {
when (val result = taskViewModel.result.value) { when (val result = taskViewModel.result.value) {
is String -> Toast.makeText(requireContext(), result, Toast.LENGTH_LONG).show() is String -> Toast.makeText(requireContext(), result, Toast.LENGTH_LONG).show()
is MessageDialogFragment -> result.show( is MessageDialogFragment -> result.show(
parentFragmentManager, requireActivity().supportFragmentManager,
MessageDialogFragment.TAG MessageDialogFragment.TAG
) )
} }

View File

@ -501,8 +501,6 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
var errorBaseGame = 0 var errorBaseGame = 0
var errorExtension = 0 var errorExtension = 0
var errorOther = 0 var errorOther = 0
var errorTotal = 0
lifecycleScope.launch {
documents.forEach { documents.forEach {
when (NativeLibrary.installFileToNand(it.toString())) { when (NativeLibrary.installFileToNand(it.toString())) {
NativeLibrary.InstallFileToNandResult.Success -> { NativeLibrary.InstallFileToNandResult.Success -> {
@ -526,7 +524,7 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
} }
} }
} }
withContext(Dispatchers.Main) {
val separator = System.getProperty("line.separator") ?: "\n" val separator = System.getProperty("line.separator") ?: "\n"
val installResult = StringBuilder() val installResult = StringBuilder()
if (installSuccess > 0) { if (installSuccess > 0) {
@ -547,7 +545,7 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
) )
installResult.append(separator) installResult.append(separator)
} }
errorTotal = errorBaseGame + errorExtension + errorOther val errorTotal: Int = errorBaseGame + errorExtension + errorOther
if (errorTotal > 0) { if (errorTotal > 0) {
installResult.append(separator) installResult.append(separator)
installResult.append( installResult.append(
@ -577,20 +575,17 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
) )
installResult.append(separator) installResult.append(separator)
} }
MessageDialogFragment.newInstance( return@newInstance MessageDialogFragment.newInstance(
titleId = R.string.install_game_content_failure, titleId = R.string.install_game_content_failure,
descriptionString = installResult.toString().trim(), descriptionString = installResult.toString().trim(),
helpLinkId = R.string.install_game_content_help_link helpLinkId = R.string.install_game_content_help_link
).show(supportFragmentManager, MessageDialogFragment.TAG) )
} else { } else {
MessageDialogFragment.newInstance( return@newInstance MessageDialogFragment.newInstance(
titleId = R.string.install_game_content_success, titleId = R.string.install_game_content_success,
descriptionString = installResult.toString().trim() descriptionString = installResult.toString().trim()
).show(supportFragmentManager, MessageDialogFragment.TAG) )
} }
}
}
return@newInstance installSuccess + installOverwrite + errorTotal
}.show(supportFragmentManager, IndeterminateProgressDialogFragment.TAG) }.show(supportFragmentManager, IndeterminateProgressDialogFragment.TAG)
} }
} }