mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-22 14:52:45 +01:00
android: Fix cancel behavior on indeterminate progress dialog fragment
The dialog would previously dismiss immediately when it should stay alive until the task is cancelled completely.
This commit is contained in:
parent
c8673a16bb
commit
95a31b8887
1 changed files with 14 additions and 4 deletions
|
@ -4,12 +4,12 @@
|
||||||
package org.yuzu.yuzu_emu.fragments
|
package org.yuzu.yuzu_emu.fragments
|
||||||
|
|
||||||
import android.app.Dialog
|
import android.app.Dialog
|
||||||
import android.content.DialogInterface
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.fragment.app.DialogFragment
|
import androidx.fragment.app.DialogFragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
|
@ -39,9 +39,7 @@ class IndeterminateProgressDialogFragment : DialogFragment() {
|
||||||
.setView(binding.root)
|
.setView(binding.root)
|
||||||
|
|
||||||
if (cancellable) {
|
if (cancellable) {
|
||||||
dialog.setNegativeButton(android.R.string.cancel) { _: DialogInterface, _: Int ->
|
dialog.setNegativeButton(android.R.string.cancel, null)
|
||||||
taskViewModel.setCancelled(true)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val alertDialog = dialog.create()
|
val alertDialog = dialog.create()
|
||||||
|
@ -98,6 +96,18 @@ class IndeterminateProgressDialogFragment : DialogFragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// By default, the ProgressDialog will immediately dismiss itself upon a button being pressed.
|
||||||
|
// Setting the OnClickListener again after the dialog is shown overrides this behavior.
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
val alertDialog = dialog as AlertDialog
|
||||||
|
val negativeButton = alertDialog.getButton(Dialog.BUTTON_NEGATIVE)
|
||||||
|
negativeButton.setOnClickListener {
|
||||||
|
alertDialog.setTitle(getString(R.string.cancelling))
|
||||||
|
taskViewModel.setCancelled(true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val TAG = "IndeterminateProgressDialogFragment"
|
const val TAG = "IndeterminateProgressDialogFragment"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue