From 2e978ad4282c5fa0ada59a93b71cfc5b18fe637e Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Sat, 12 Nov 2022 15:45:59 -0500 Subject: [PATCH] Android: Use progress bar that does not inherit from AppCompat on leanback --- ...SystemUpdateProgressBarDialogFragment.java | 70 +++++++++++++------ .../main/res/layout/dialog_progress_tv.xml | 19 +++++ 2 files changed, 68 insertions(+), 21 deletions(-) create mode 100644 Source/Android/app/src/main/res/layout/dialog_progress_tv.xml diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/SystemUpdateProgressBarDialogFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/SystemUpdateProgressBarDialogFragment.java index 7f865106b8..96dda28903 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/SystemUpdateProgressBarDialogFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/SystemUpdateProgressBarDialogFragment.java @@ -10,6 +10,7 @@ import android.widget.Button; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.app.AppCompatActivity; import androidx.fragment.app.DialogFragment; import androidx.lifecycle.ViewModelProvider; @@ -17,6 +18,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder; import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.databinding.DialogProgressBinding; +import org.dolphinemu.dolphinemu.databinding.DialogProgressTvBinding; public class SystemUpdateProgressBarDialogFragment extends DialogFragment { @@ -32,32 +34,58 @@ public class SystemUpdateProgressBarDialogFragment extends DialogFragment SystemUpdateViewModel viewModel = new ViewModelProvider(requireActivity()).get(SystemUpdateViewModel.class); - DialogProgressBinding dialogProgressBinding = - DialogProgressBinding.inflate(getLayoutInflater()); + DialogProgressBinding dialogProgressBinding; + DialogProgressTvBinding dialogProgressTvBinding; // We need to set the message to something here, otherwise the text will not appear when we set it later. - AlertDialog progressDialog = new MaterialAlertDialogBuilder(requireContext()) - .setTitle(getString(R.string.updating)) - .setMessage("") - .setNegativeButton(getString(R.string.cancel), null) - .setView(dialogProgressBinding.getRoot()) - .setCancelable(false) - .create(); + MaterialAlertDialogBuilder progressDialogBuilder = + new MaterialAlertDialogBuilder(requireContext()) + .setTitle(getString(R.string.updating)) + .setMessage("") + .setNegativeButton(getString(R.string.cancel), null) + .setCancelable(false); - viewModel.getProgressData() - .observe(this, (@Nullable - Integer progress) -> dialogProgressBinding.updateProgress.setProgress( - progress)); - - viewModel.getTotalData().observe(this, (@Nullable Integer total) -> + // TODO: Remove dialog_progress_tv if we switch to an AppCompatActivity for leanback + if (getActivity() instanceof AppCompatActivity) { - if (total == 0) - { - return; - } + dialogProgressBinding = DialogProgressBinding.inflate(getLayoutInflater()); + progressDialogBuilder.setView(dialogProgressBinding.getRoot()); - dialogProgressBinding.updateProgress.setMax(total); - }); + viewModel.getProgressData().observe(this, + (@Nullable Integer progress) -> dialogProgressBinding.updateProgress.setProgress( + progress)); + + viewModel.getTotalData().observe(this, (@Nullable Integer total) -> + { + if (total == 0) + { + return; + } + + dialogProgressBinding.updateProgress.setMax(total); + }); + } + else + { + dialogProgressTvBinding = DialogProgressTvBinding.inflate(getLayoutInflater()); + progressDialogBuilder.setView(dialogProgressTvBinding.getRoot()); + + viewModel.getProgressData().observe(this, + (@Nullable Integer progress) -> dialogProgressTvBinding.updateProgress.setProgress( + progress)); + + viewModel.getTotalData().observe(this, (@Nullable Integer total) -> + { + if (total == 0) + { + return; + } + + dialogProgressTvBinding.updateProgress.setMax(total); + }); + } + + AlertDialog progressDialog = progressDialogBuilder.create(); viewModel.getTitleIdData().observe(this, (@Nullable Long titleId) -> progressDialog.setMessage( getString(R.string.updating_message, titleId))); diff --git a/Source/Android/app/src/main/res/layout/dialog_progress_tv.xml b/Source/Android/app/src/main/res/layout/dialog_progress_tv.xml new file mode 100644 index 0000000000..1967c7e3f6 --- /dev/null +++ b/Source/Android/app/src/main/res/layout/dialog_progress_tv.xml @@ -0,0 +1,19 @@ + + + + + +