summaryrefslogtreecommitdiff
path: root/Source/Android/app/src/main/java
diff options
context:
space:
mode:
authorSimonx22 <simon@oatmealdome.me>2025-11-07 13:13:09 -0500
committerSimonx22 <simon@oatmealdome.me>2025-11-08 12:21:12 -0500
commit8ee767f29298f9d9bff501708f8b2b3f6512bde7 (patch)
tree38032138ce29bd7177560388a10a3fb1ae3316b2 /Source/Android/app/src/main/java
parent5650be68425960131225bcd3ea5a8dfc85074148 (diff)
Android: Convert AlertMessage dialog to Kotlin
Diffstat (limited to 'Source/Android/app/src/main/java')
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java4
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/AlertMessage.java100
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/AlertMessage.kt82
3 files changed, 84 insertions, 102 deletions
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java
index 69b9a94595..eca80d530c 100644
--- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java
@@ -497,7 +497,7 @@ public final class NativeLibrary
}
else
{
- AlertMessage.newInstance(caption, text, yesNo, isWarning)
+ AlertMessage.Companion.newInstance(caption, text, yesNo, isWarning)
.show(fragmentManager, "AlertMessage");
}
});
@@ -513,7 +513,7 @@ public final class NativeLibrary
if (yesNo)
{
- result = AlertMessage.getAlertResult();
+ result = AlertMessage.Companion.getAlertResult();
}
}
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/AlertMessage.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/AlertMessage.java
deleted file mode 100644
index aef3016134..0000000000
--- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/AlertMessage.java
+++ /dev/null
@@ -1,100 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-
-package org.dolphinemu.dolphinemu.dialogs;
-
-import android.app.Dialog;
-import android.os.Bundle;
-
-import androidx.annotation.NonNull;
-import androidx.fragment.app.DialogFragment;
-
-import com.google.android.material.dialog.MaterialAlertDialogBuilder;
-
-import org.dolphinemu.dolphinemu.NativeLibrary;
-import org.dolphinemu.dolphinemu.R;
-import org.dolphinemu.dolphinemu.activities.EmulationActivity;
-import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting;
-import org.dolphinemu.dolphinemu.features.settings.model.NativeConfig;
-
-public final class AlertMessage extends DialogFragment
-{
- private static boolean sAlertResult = false;
- private static final String ARG_TITLE = "title";
- private static final String ARG_MESSAGE = "message";
- private static final String ARG_YES_NO = "yesNo";
- private static final String ARG_IS_WARNING = "isWarning";
-
- public static AlertMessage newInstance(String title, String message, boolean yesNo,
- boolean isWarning)
- {
- AlertMessage fragment = new AlertMessage();
-
- Bundle args = new Bundle();
- args.putString(ARG_TITLE, title);
- args.putString(ARG_MESSAGE, message);
- args.putBoolean(ARG_YES_NO, yesNo);
- args.putBoolean(ARG_IS_WARNING, isWarning);
- fragment.setArguments(args);
-
- return fragment;
- }
-
- @NonNull
- @Override
- public Dialog onCreateDialog(Bundle savedInstanceState)
- {
- final EmulationActivity emulationActivity = NativeLibrary.getEmulationActivity();
- String title = requireArguments().getString(ARG_TITLE);
- String message = requireArguments().getString(ARG_MESSAGE);
- boolean yesNo = requireArguments().getBoolean(ARG_YES_NO);
- boolean isWarning = requireArguments().getBoolean(ARG_IS_WARNING);
- setCancelable(false);
-
- MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(emulationActivity)
- .setTitle(title)
- .setMessage(message);
-
- // If not yes/no dialog just have one button that dismisses modal,
- // otherwise have a yes and no button that sets sAlertResult accordingly.
- if (!yesNo)
- {
- builder.setPositiveButton(android.R.string.ok, (dialog, which) ->
- {
- dialog.dismiss();
- NativeLibrary.NotifyAlertMessageLock();
- });
- }
- else
- {
- builder.setPositiveButton(android.R.string.yes, (dialog, which) ->
- {
- sAlertResult = true;
- dialog.dismiss();
- NativeLibrary.NotifyAlertMessageLock();
- })
- .setNegativeButton(android.R.string.no, (dialog, which) ->
- {
- sAlertResult = false;
- dialog.dismiss();
- NativeLibrary.NotifyAlertMessageLock();
- });
- }
-
- if (isWarning)
- {
- builder.setNeutralButton(R.string.ignore_warning_alert_messages, (dialog, which) ->
- {
- BooleanSetting.MAIN_USE_PANIC_HANDLERS.setBoolean(NativeConfig.LAYER_CURRENT, false);
- dialog.dismiss();
- NativeLibrary.NotifyAlertMessageLock();
- });
- }
-
- return builder.create();
- }
-
- public static boolean getAlertResult()
- {
- return sAlertResult;
- }
-}
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/AlertMessage.kt b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/AlertMessage.kt
new file mode 100644
index 0000000000..3c87b324f6
--- /dev/null
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/dialogs/AlertMessage.kt
@@ -0,0 +1,82 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+package org.dolphinemu.dolphinemu.dialogs
+
+import android.app.Dialog
+import android.content.DialogInterface
+import android.os.Bundle
+import androidx.fragment.app.DialogFragment
+import com.google.android.material.dialog.MaterialAlertDialogBuilder
+import org.dolphinemu.dolphinemu.NativeLibrary
+import org.dolphinemu.dolphinemu.R
+import org.dolphinemu.dolphinemu.activities.EmulationActivity
+import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting
+import org.dolphinemu.dolphinemu.features.settings.model.NativeConfig
+
+class AlertMessage : DialogFragment() {
+ override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
+ val emulationActivity: EmulationActivity = NativeLibrary.getEmulationActivity()
+ val args = requireArguments()
+ val title = args.getString(ARG_TITLE).orEmpty()
+ val message = args.getString(ARG_MESSAGE).orEmpty()
+ val yesNo = args.getBoolean(ARG_YES_NO)
+ val isWarning = args.getBoolean(ARG_IS_WARNING)
+ isCancelable = false
+
+ return MaterialAlertDialogBuilder(emulationActivity).setTitle(title).setMessage(message)
+ .apply { configureButtons(yesNo, isWarning) }.create()
+ }
+
+ private fun MaterialAlertDialogBuilder.configureButtons(yesNo: Boolean, isWarning: Boolean) {
+ if (yesNo) {
+ setPositiveButton(android.R.string.yes) { dialog, _ ->
+ dialog.releaseLock(result = true)
+ }
+ setNegativeButton(android.R.string.no) { dialog, _ ->
+ dialog.releaseLock(result = false)
+ }
+ } else {
+ setPositiveButton(android.R.string.ok) { dialog, _ ->
+ dialog.releaseLock()
+ }
+ }
+
+ if (isWarning) {
+ setNeutralButton(R.string.ignore_warning_alert_messages) { dialog, _ ->
+ BooleanSetting.MAIN_USE_PANIC_HANDLERS.setBoolean(
+ NativeConfig.LAYER_CURRENT, false
+ )
+ dialog.releaseLock()
+ }
+ }
+ }
+
+ private fun DialogInterface.releaseLock(result: Boolean? = null) {
+ result?.let { alertResult = it }
+ dismiss()
+ NativeLibrary.NotifyAlertMessageLock()
+ }
+
+ companion object {
+ private var alertResult = false
+ private const val ARG_TITLE = "title"
+ private const val ARG_MESSAGE = "message"
+ private const val ARG_YES_NO = "yesNo"
+ private const val ARG_IS_WARNING = "isWarning"
+
+ fun newInstance(
+ title: String, message: String, yesNo: Boolean, isWarning: Boolean
+ ): AlertMessage {
+ return AlertMessage().apply {
+ arguments = Bundle().apply {
+ putString(ARG_TITLE, title)
+ putString(ARG_MESSAGE, message)
+ putBoolean(ARG_YES_NO, yesNo)
+ putBoolean(ARG_IS_WARNING, isWarning)
+ }
+ }
+ }
+
+ fun getAlertResult(): Boolean = alertResult
+ }
+}