summaryrefslogtreecommitdiff
path: root/Source/Android/app/src/main/java/org
diff options
context:
space:
mode:
authorCharles Lombardo <clombardo169@gmail.com>2023-01-24 00:24:05 -0500
committerCharles Lombardo <clombardo169@gmail.com>2023-03-07 15:45:40 -0500
commit6dfa5550998fdf6d33ad60f5f5d6b00f6840f728 (patch)
tree8dfd62401560a07c119fb3a98126cf81d0d60ba2 /Source/Android/app/src/main/java/org
parent16023ece6da3960fc1855db86325a209d4c0de4b (diff)
Android: Convert SystemUpdateProgressBarDialogFragment to Kotlin
Diffstat (limited to 'Source/Android/app/src/main/java/org')
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/SystemUpdateProgressBarDialogFragment.java133
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/SystemUpdateProgressBarDialogFragment.kt110
2 files changed, 110 insertions, 133 deletions
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
deleted file mode 100644
index 96dda28903..0000000000
--- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/SystemUpdateProgressBarDialogFragment.java
+++ /dev/null
@@ -1,133 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-
-package org.dolphinemu.dolphinemu.features.sysupdate.ui;
-
-import android.app.Dialog;
-import android.content.pm.ActivityInfo;
-import android.os.Bundle;
-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;
-
-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
-{
- @NonNull
- @Override
- public Dialog onCreateDialog(@Nullable Bundle savedInstanceState)
- {
- // Store the current orientation to be restored later
- final int orientation = getActivity().getRequestedOrientation();
- // Rotating the device while the update is running can result in a title failing to import.
- getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
-
- SystemUpdateViewModel viewModel =
- new ViewModelProvider(requireActivity()).get(SystemUpdateViewModel.class);
-
- DialogProgressBinding dialogProgressBinding;
- DialogProgressTvBinding dialogProgressTvBinding;
-
- // We need to set the message to something here, otherwise the text will not appear when we set it later.
- MaterialAlertDialogBuilder progressDialogBuilder =
- new MaterialAlertDialogBuilder(requireContext())
- .setTitle(getString(R.string.updating))
- .setMessage("")
- .setNegativeButton(getString(R.string.cancel), null)
- .setCancelable(false);
-
- // TODO: Remove dialog_progress_tv if we switch to an AppCompatActivity for leanback
- if (getActivity() instanceof AppCompatActivity)
- {
- dialogProgressBinding = DialogProgressBinding.inflate(getLayoutInflater());
- progressDialogBuilder.setView(dialogProgressBinding.getRoot());
-
- 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)));
-
- viewModel.getResultData().observe(this, (@Nullable Integer result) ->
- {
- if (result == -1)
- {
- // This is the default value, ignore
- return;
- }
-
- SystemUpdateResultFragment progressBarFragment = new SystemUpdateResultFragment();
- progressBarFragment.show(getParentFragmentManager(), "OnlineUpdateResultFragment");
-
- getActivity().setRequestedOrientation(orientation);
-
- dismiss();
- });
-
- if (savedInstanceState == null)
- {
- viewModel.startUpdate();
- }
- return progressDialog;
- }
-
- // 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
- public void onResume()
- {
- super.onResume();
- AlertDialog alertDialog = (AlertDialog) getDialog();
- SystemUpdateViewModel viewModel =
- new ViewModelProvider(requireActivity()).get(SystemUpdateViewModel.class);
- Button negativeButton = alertDialog.getButton(Dialog.BUTTON_NEGATIVE);
- negativeButton.setOnClickListener(v ->
- {
- alertDialog.setTitle(getString(R.string.cancelling));
- alertDialog.setMessage(getString(R.string.update_cancelling));
- viewModel.setCanceled();
- });
- }
-}
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/SystemUpdateProgressBarDialogFragment.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/SystemUpdateProgressBarDialogFragment.kt
new file mode 100644
index 0000000000..6ff5f4d4f2
--- /dev/null
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/sysupdate/ui/SystemUpdateProgressBarDialogFragment.kt
@@ -0,0 +1,110 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+package org.dolphinemu.dolphinemu.features.sysupdate.ui
+
+import android.app.Dialog
+import android.content.pm.ActivityInfo
+import android.os.Bundle
+import androidx.appcompat.app.AlertDialog
+import androidx.appcompat.app.AppCompatActivity
+import androidx.fragment.app.DialogFragment
+import androidx.lifecycle.ViewModelProvider
+import com.google.android.material.dialog.MaterialAlertDialogBuilder
+import org.dolphinemu.dolphinemu.R
+import org.dolphinemu.dolphinemu.databinding.DialogProgressBinding
+import org.dolphinemu.dolphinemu.databinding.DialogProgressTvBinding
+
+class SystemUpdateProgressBarDialogFragment : DialogFragment() {
+ override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
+ // Store the current orientation to be restored later
+ val orientation = requireActivity().requestedOrientation
+ // Rotating the device while the update is running can result in a title failing to import.
+ requireActivity().requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LOCKED
+
+ val viewModel = ViewModelProvider(requireActivity())[SystemUpdateViewModel::class.java]
+
+ val dialogProgressBinding: DialogProgressBinding
+ val dialogProgressTvBinding: DialogProgressTvBinding
+
+ // We need to set the message to something here, otherwise the text will not appear when we set it later.
+ val progressDialogBuilder = MaterialAlertDialogBuilder(requireContext())
+ .setTitle(getString(R.string.updating))
+ .setMessage("")
+ .setNegativeButton(getString(R.string.cancel), null)
+ .setCancelable(false)
+
+ // TODO: Remove dialog_progress_tv if we switch to an AppCompatActivity for leanback
+ if (activity is AppCompatActivity) {
+ dialogProgressBinding = DialogProgressBinding.inflate(layoutInflater)
+ progressDialogBuilder.setView(dialogProgressBinding.root)
+
+ viewModel.progressData.observe(
+ this
+ ) { progress: Int ->
+ dialogProgressBinding.updateProgress.progress = progress
+ }
+
+ viewModel.totalData.observe(this) { total: Int ->
+ if (total == 0) {
+ return@observe
+ }
+ dialogProgressBinding.updateProgress.max = total
+ }
+ } else {
+ dialogProgressTvBinding = DialogProgressTvBinding.inflate(layoutInflater)
+ progressDialogBuilder.setView(dialogProgressTvBinding.root)
+
+ viewModel.progressData.observe(
+ this
+ ) { progress: Int ->
+ dialogProgressTvBinding.updateProgress.progress = progress
+ }
+
+ viewModel.totalData.observe(this) { total: Int ->
+ if (total == 0) {
+ return@observe
+ }
+ dialogProgressTvBinding.updateProgress.max = total
+ }
+ }
+
+ val progressDialog = progressDialogBuilder.create()
+
+ viewModel.titleIdData.observe(this) { titleId: Long ->
+ progressDialog.setMessage(getString(R.string.updating_message, titleId))
+ }
+
+ viewModel.resultData.observe(this) { result: Int ->
+ if (result == -1) {
+ // This is the default value, ignore
+ return@observe
+ }
+
+ val progressBarFragment = SystemUpdateResultFragment()
+ progressBarFragment.show(parentFragmentManager, "OnlineUpdateResultFragment")
+
+ requireActivity().requestedOrientation = orientation
+
+ dismiss()
+ }
+
+ if (savedInstanceState == null) {
+ viewModel.startUpdate()
+ }
+ return progressDialog
+ }
+
+ // 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 viewModel = ViewModelProvider(requireActivity())[SystemUpdateViewModel::class.java]
+ val negativeButton = alertDialog!!.getButton(Dialog.BUTTON_NEGATIVE)
+ negativeButton.setOnClickListener {
+ alertDialog.setTitle(getString(R.string.cancelling))
+ alertDialog.setMessage(getString(R.string.update_cancelling))
+ viewModel.setCanceled()
+ }
+ }
+}