yuzu-emu
/
yuzu-android
Archived
1
0
Fork 0

Merge pull request #11521 from t895/content-install-fix

android: Collect task state once view is created
This commit is contained in:
Charles Lombardo 2023-09-16 19:51:29 -04:00 committed by GitHub
commit 7282976de3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 9 deletions

View File

@ -5,6 +5,9 @@ package org.yuzu.yuzu_emu.fragments
import android.app.Dialog import android.app.Dialog
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
@ -21,22 +24,40 @@ import org.yuzu.yuzu_emu.model.TaskViewModel
class IndeterminateProgressDialogFragment : DialogFragment() { class IndeterminateProgressDialogFragment : DialogFragment() {
private val taskViewModel: TaskViewModel by activityViewModels() private val taskViewModel: TaskViewModel by activityViewModels()
private lateinit var binding: DialogProgressBarBinding
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val titleId = requireArguments().getInt(TITLE) val titleId = requireArguments().getInt(TITLE)
val progressBinding = DialogProgressBarBinding.inflate(layoutInflater) binding = DialogProgressBarBinding.inflate(layoutInflater)
progressBinding.progressBar.isIndeterminate = true binding.progressBar.isIndeterminate = true
val dialog = MaterialAlertDialogBuilder(requireContext()) val dialog = MaterialAlertDialogBuilder(requireContext())
.setTitle(titleId) .setTitle(titleId)
.setView(progressBinding.root) .setView(binding.root)
.create() .create()
dialog.setCanceledOnTouchOutside(false) dialog.setCanceledOnTouchOutside(false)
if (!taskViewModel.isRunning.value) {
taskViewModel.runTask()
}
return dialog
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
viewLifecycleOwner.lifecycleScope.launch { viewLifecycleOwner.lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.CREATED) { repeatOnLifecycle(Lifecycle.State.CREATED) {
taskViewModel.isComplete.collect { taskViewModel.isComplete.collect {
if (it) { if (it) {
dialog.dismiss() dismiss()
when (val result = taskViewModel.result.value) { when (val result = taskViewModel.result.value) {
is String -> Toast.makeText(requireContext(), result, Toast.LENGTH_LONG) is String -> Toast.makeText(requireContext(), result, Toast.LENGTH_LONG)
.show() .show()
@ -51,11 +72,6 @@ class IndeterminateProgressDialogFragment : DialogFragment() {
} }
} }
} }
if (!taskViewModel.isRunning.value) {
taskViewModel.runTask()
}
return dialog
} }
companion object { companion object {