summaryrefslogtreecommitdiffstats
path: root/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/ProgressDialogFragment.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/ProgressDialogFragment.kt')
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/ProgressDialogFragment.kt99
1 files changed, 38 insertions, 61 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/ProgressDialogFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/ProgressDialogFragment.kt
index ae29e9cd1..ee3bb0386 100644
--- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/ProgressDialogFragment.kt
+++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/ProgressDialogFragment.kt
@@ -13,16 +13,13 @@ import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentActivity
import androidx.fragment.app.activityViewModels
-import androidx.lifecycle.Lifecycle
import androidx.lifecycle.ViewModelProvider
-import androidx.lifecycle.lifecycleScope
-import androidx.lifecycle.repeatOnLifecycle
import com.google.android.material.dialog.MaterialAlertDialogBuilder
-import kotlinx.coroutines.launch
import org.yuzu.yuzu_emu.R
import org.yuzu.yuzu_emu.databinding.DialogProgressBarBinding
import org.yuzu.yuzu_emu.model.TaskViewModel
import org.yuzu.yuzu_emu.utils.ViewUtils.setVisible
+import org.yuzu.yuzu_emu.utils.collect
class ProgressDialogFragment : DialogFragment() {
private val taskViewModel: TaskViewModel by activityViewModels()
@@ -65,70 +62,50 @@ class ProgressDialogFragment : DialogFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
binding.message.isSelected = true
- viewLifecycleOwner.lifecycleScope.apply {
- launch {
- repeatOnLifecycle(Lifecycle.State.CREATED) {
- taskViewModel.isComplete.collect {
- if (it) {
- dismiss()
- when (val result = taskViewModel.result.value) {
- is String -> Toast.makeText(
- requireContext(),
- result,
- Toast.LENGTH_LONG
- ).show()
-
- is MessageDialogFragment -> result.show(
- requireActivity().supportFragmentManager,
- MessageDialogFragment.TAG
- )
-
- else -> {
- // Do nothing
- }
- }
- taskViewModel.clear()
- }
+ taskViewModel.isComplete.collect(viewLifecycleOwner) {
+ if (it) {
+ dismiss()
+ when (val result = taskViewModel.result.value) {
+ is String -> Toast.makeText(
+ requireContext(),
+ result,
+ Toast.LENGTH_LONG
+ ).show()
+
+ is MessageDialogFragment -> result.show(
+ requireActivity().supportFragmentManager,
+ MessageDialogFragment.TAG
+ )
+
+ else -> {
+ // Do nothing
}
}
+ taskViewModel.clear()
}
- launch {
- repeatOnLifecycle(Lifecycle.State.CREATED) {
- taskViewModel.cancelled.collect {
- if (it) {
- dialog?.setTitle(R.string.cancelling)
- }
- }
- }
- }
- launch {
- repeatOnLifecycle(Lifecycle.State.CREATED) {
- taskViewModel.progress.collect {
- if (it != 0.0) {
- binding.progressBar.apply {
- isIndeterminate = false
- progress = (
- (it / taskViewModel.maxProgress.value) *
- PROGRESS_BAR_RESOLUTION
- ).toInt()
- min = 0
- max = PROGRESS_BAR_RESOLUTION
- }
- }
- }
- }
+ }
+ taskViewModel.cancelled.collect(viewLifecycleOwner) {
+ if (it) {
+ dialog?.setTitle(R.string.cancelling)
}
- launch {
- repeatOnLifecycle(Lifecycle.State.CREATED) {
- taskViewModel.message.collect {
- binding.message.setVisible(it.isNotEmpty())
- if (it.isNotEmpty()) {
- binding.message.text = it
- }
- }
+ }
+ taskViewModel.progress.collect(viewLifecycleOwner) {
+ if (it != 0.0) {
+ binding.progressBar.apply {
+ isIndeterminate = false
+ progress = (
+ (it / taskViewModel.maxProgress.value) *
+ PROGRESS_BAR_RESOLUTION
+ ).toInt()
+ min = 0
+ max = PROGRESS_BAR_RESOLUTION
}
}
}
+ taskViewModel.message.collect(viewLifecycleOwner) {
+ binding.message.setVisible(it.isNotEmpty())
+ binding.message.text = it
+ }
}
// By default, the ProgressDialog will immediately dismiss itself upon a button being pressed.