mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 14:19:46 -06:00
Android: Switch to indeterminate progress bar on system update cancel
This commit is contained in:
@ -3,7 +3,6 @@
|
|||||||
package org.dolphinemu.dolphinemu.features.sysupdate.ui
|
package org.dolphinemu.dolphinemu.features.sysupdate.ui
|
||||||
|
|
||||||
import android.app.Dialog
|
import android.app.Dialog
|
||||||
import android.content.pm.ActivityInfo
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
@ -15,11 +14,13 @@ import org.dolphinemu.dolphinemu.databinding.DialogProgressBinding
|
|||||||
import org.dolphinemu.dolphinemu.databinding.DialogProgressTvBinding
|
import org.dolphinemu.dolphinemu.databinding.DialogProgressTvBinding
|
||||||
|
|
||||||
class SystemUpdateProgressBarDialogFragment : DialogFragment() {
|
class SystemUpdateProgressBarDialogFragment : DialogFragment() {
|
||||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
private lateinit var viewModel: SystemUpdateViewModel
|
||||||
val viewModel = ViewModelProvider(requireActivity())[SystemUpdateViewModel::class.java]
|
|
||||||
|
|
||||||
val dialogProgressBinding: DialogProgressBinding
|
private lateinit var binding: DialogProgressBinding
|
||||||
val dialogProgressTvBinding: DialogProgressTvBinding
|
private lateinit var bindingTv: DialogProgressTvBinding
|
||||||
|
|
||||||
|
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||||
|
viewModel = ViewModelProvider(requireActivity())[SystemUpdateViewModel::class.java]
|
||||||
|
|
||||||
// We need to set the message to something here, otherwise the text will not appear when we set it later.
|
// We need to set the message to something here, otherwise the text will not appear when we set it later.
|
||||||
val progressDialogBuilder = MaterialAlertDialogBuilder(requireContext())
|
val progressDialogBuilder = MaterialAlertDialogBuilder(requireContext())
|
||||||
@ -30,36 +31,36 @@ class SystemUpdateProgressBarDialogFragment : DialogFragment() {
|
|||||||
|
|
||||||
// TODO: Remove dialog_progress_tv if we switch to an AppCompatActivity for leanback
|
// TODO: Remove dialog_progress_tv if we switch to an AppCompatActivity for leanback
|
||||||
if (activity is AppCompatActivity) {
|
if (activity is AppCompatActivity) {
|
||||||
dialogProgressBinding = DialogProgressBinding.inflate(layoutInflater)
|
binding = DialogProgressBinding.inflate(layoutInflater)
|
||||||
progressDialogBuilder.setView(dialogProgressBinding.root)
|
progressDialogBuilder.setView(binding.root)
|
||||||
|
|
||||||
viewModel.progressData.observe(
|
viewModel.progressData.observe(
|
||||||
this
|
this
|
||||||
) { progress: Int ->
|
) { progress: Int ->
|
||||||
dialogProgressBinding.updateProgress.progress = progress
|
binding.updateProgress.progress = progress
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel.totalData.observe(this) { total: Int ->
|
viewModel.totalData.observe(this) { total: Int ->
|
||||||
if (total == 0) {
|
if (total == 0) {
|
||||||
return@observe
|
return@observe
|
||||||
}
|
}
|
||||||
dialogProgressBinding.updateProgress.max = total
|
binding.updateProgress.max = total
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
dialogProgressTvBinding = DialogProgressTvBinding.inflate(layoutInflater)
|
bindingTv = DialogProgressTvBinding.inflate(layoutInflater)
|
||||||
progressDialogBuilder.setView(dialogProgressTvBinding.root)
|
progressDialogBuilder.setView(bindingTv.root)
|
||||||
|
|
||||||
viewModel.progressData.observe(
|
viewModel.progressData.observe(
|
||||||
this
|
this
|
||||||
) { progress: Int ->
|
) { progress: Int ->
|
||||||
dialogProgressTvBinding.updateProgress.progress = progress
|
bindingTv.updateProgress.progress = progress
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel.totalData.observe(this) { total: Int ->
|
viewModel.totalData.observe(this) { total: Int ->
|
||||||
if (total == 0) {
|
if (total == 0) {
|
||||||
return@observe
|
return@observe
|
||||||
}
|
}
|
||||||
dialogProgressTvBinding.updateProgress.max = total
|
bindingTv.updateProgress.max = total
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,13 +92,17 @@ class SystemUpdateProgressBarDialogFragment : DialogFragment() {
|
|||||||
// Setting the OnClickListener again after the dialog is shown overrides this behavior.
|
// Setting the OnClickListener again after the dialog is shown overrides this behavior.
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
val alertDialog = dialog as AlertDialog?
|
val alertDialog = dialog as AlertDialog
|
||||||
val viewModel = ViewModelProvider(requireActivity())[SystemUpdateViewModel::class.java]
|
val negativeButton = alertDialog.getButton(Dialog.BUTTON_NEGATIVE)
|
||||||
val negativeButton = alertDialog!!.getButton(Dialog.BUTTON_NEGATIVE)
|
|
||||||
negativeButton.setOnClickListener {
|
negativeButton.setOnClickListener {
|
||||||
alertDialog.setTitle(getString(R.string.cancelling))
|
alertDialog.setTitle(getString(R.string.cancelling))
|
||||||
alertDialog.setMessage(getString(R.string.update_cancelling))
|
alertDialog.setMessage(getString(R.string.update_cancelling))
|
||||||
viewModel.setCanceled()
|
viewModel.setCanceled()
|
||||||
|
|
||||||
|
if (activity is AppCompatActivity)
|
||||||
|
binding.updateProgress.isIndeterminate = true
|
||||||
|
else
|
||||||
|
bindingTv.updateProgress.isIndeterminate = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user