diff options
| author | 2024-02-17 22:22:46 -0500 | |
|---|---|---|
| committer | 2024-02-17 22:22:46 -0500 | |
| commit | 316089c39fbca3e3bab3c00bec8e90c86101c64a (patch) | |
| tree | 24e0778729dc87d86fb73836417a13924aef0f56 /src/android | |
| parent | Merge pull request #13051 from german77/cheatmiss (diff) | |
| parent | android: Move CoreErrorDialogFragment to its own file (diff) | |
| download | yuzu-316089c39fbca3e3bab3c00bec8e90c86101c64a.tar.gz yuzu-316089c39fbca3e3bab3c00bec8e90c86101c64a.tar.xz yuzu-316089c39fbca3e3bab3c00bec8e90c86101c64a.zip | |
Merge pull request #13052 from t895/serializable-stuff
android: Move CoreErrorDialogFragment to its own file
Diffstat (limited to 'src/android')
| -rw-r--r-- | src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.kt | 48 | ||||
| -rw-r--r-- | src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/CoreErrorDialogFragment.kt | 47 |
2 files changed, 53 insertions, 42 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.kt index fd229c855..02a20dacf 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/NativeLibrary.kt | |||
| @@ -3,24 +3,21 @@ | |||
| 3 | 3 | ||
| 4 | package org.yuzu.yuzu_emu | 4 | package org.yuzu.yuzu_emu |
| 5 | 5 | ||
| 6 | import android.app.Dialog | ||
| 7 | import android.content.DialogInterface | 6 | import android.content.DialogInterface |
| 8 | import android.net.Uri | 7 | import android.net.Uri |
| 9 | import android.os.Bundle | ||
| 10 | import android.text.Html | 8 | import android.text.Html |
| 11 | import android.text.method.LinkMovementMethod | 9 | import android.text.method.LinkMovementMethod |
| 12 | import android.view.Surface | 10 | import android.view.Surface |
| 13 | import android.view.View | 11 | import android.view.View |
| 14 | import android.widget.TextView | 12 | import android.widget.TextView |
| 15 | import androidx.annotation.Keep | 13 | import androidx.annotation.Keep |
| 16 | import androidx.fragment.app.DialogFragment | ||
| 17 | import com.google.android.material.dialog.MaterialAlertDialogBuilder | 14 | import com.google.android.material.dialog.MaterialAlertDialogBuilder |
| 18 | import java.lang.ref.WeakReference | 15 | import java.lang.ref.WeakReference |
| 19 | import org.yuzu.yuzu_emu.activities.EmulationActivity | 16 | import org.yuzu.yuzu_emu.activities.EmulationActivity |
| 17 | import org.yuzu.yuzu_emu.fragments.CoreErrorDialogFragment | ||
| 20 | import org.yuzu.yuzu_emu.utils.DocumentsTree | 18 | import org.yuzu.yuzu_emu.utils.DocumentsTree |
| 21 | import org.yuzu.yuzu_emu.utils.FileUtil | 19 | import org.yuzu.yuzu_emu.utils.FileUtil |
| 22 | import org.yuzu.yuzu_emu.utils.Log | 20 | import org.yuzu.yuzu_emu.utils.Log |
| 23 | import org.yuzu.yuzu_emu.utils.SerializableHelper.serializable | ||
| 24 | import org.yuzu.yuzu_emu.model.InstallResult | 21 | import org.yuzu.yuzu_emu.model.InstallResult |
| 25 | import org.yuzu.yuzu_emu.model.Patch | 22 | import org.yuzu.yuzu_emu.model.Patch |
| 26 | import org.yuzu.yuzu_emu.model.GameVerificationResult | 23 | import org.yuzu.yuzu_emu.model.GameVerificationResult |
| @@ -184,46 +181,13 @@ object NativeLibrary { | |||
| 184 | ErrorUnknown | 181 | ErrorUnknown |
| 185 | } | 182 | } |
| 186 | 183 | ||
| 187 | private var coreErrorAlertResult = false | 184 | var coreErrorAlertResult = false |
| 188 | private val coreErrorAlertLock = Object() | 185 | val coreErrorAlertLock = Object() |
| 189 | |||
| 190 | class CoreErrorDialogFragment : DialogFragment() { | ||
| 191 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | ||
| 192 | val title = requireArguments().serializable<String>("title") | ||
| 193 | val message = requireArguments().serializable<String>("message") | ||
| 194 | |||
| 195 | return MaterialAlertDialogBuilder(requireActivity()) | ||
| 196 | .setTitle(title) | ||
| 197 | .setMessage(message) | ||
| 198 | .setPositiveButton(R.string.continue_button, null) | ||
| 199 | .setNegativeButton(R.string.abort_button) { _: DialogInterface?, _: Int -> | ||
| 200 | coreErrorAlertResult = false | ||
| 201 | synchronized(coreErrorAlertLock) { coreErrorAlertLock.notify() } | ||
| 202 | } | ||
| 203 | .create() | ||
| 204 | } | ||
| 205 | |||
| 206 | override fun onDismiss(dialog: DialogInterface) { | ||
| 207 | coreErrorAlertResult = true | ||
| 208 | synchronized(coreErrorAlertLock) { coreErrorAlertLock.notify() } | ||
| 209 | } | ||
| 210 | |||
| 211 | companion object { | ||
| 212 | fun newInstance(title: String?, message: String?): CoreErrorDialogFragment { | ||
| 213 | val frag = CoreErrorDialogFragment() | ||
| 214 | val args = Bundle() | ||
| 215 | args.putString("title", title) | ||
| 216 | args.putString("message", message) | ||
| 217 | frag.arguments = args | ||
| 218 | return frag | ||
| 219 | } | ||
| 220 | } | ||
| 221 | } | ||
| 222 | 186 | ||
| 223 | private fun onCoreErrorImpl(title: String, message: String) { | 187 | private fun onCoreErrorImpl(title: String, message: String) { |
| 224 | val emulationActivity = sEmulationActivity.get() | 188 | val emulationActivity = sEmulationActivity.get() |
| 225 | if (emulationActivity == null) { | 189 | if (emulationActivity == null) { |
| 226 | error("[NativeLibrary] EmulationActivity not present") | 190 | Log.error("[NativeLibrary] EmulationActivity not present") |
| 227 | return | 191 | return |
| 228 | } | 192 | } |
| 229 | 193 | ||
| @@ -239,7 +203,7 @@ object NativeLibrary { | |||
| 239 | fun onCoreError(error: CoreError?, details: String): Boolean { | 203 | fun onCoreError(error: CoreError?, details: String): Boolean { |
| 240 | val emulationActivity = sEmulationActivity.get() | 204 | val emulationActivity = sEmulationActivity.get() |
| 241 | if (emulationActivity == null) { | 205 | if (emulationActivity == null) { |
| 242 | error("[NativeLibrary] EmulationActivity not present") | 206 | Log.error("[NativeLibrary] EmulationActivity not present") |
| 243 | return false | 207 | return false |
| 244 | } | 208 | } |
| 245 | 209 | ||
| @@ -270,7 +234,7 @@ object NativeLibrary { | |||
| 270 | } | 234 | } |
| 271 | 235 | ||
| 272 | // Show the AlertDialog on the main thread. | 236 | // Show the AlertDialog on the main thread. |
| 273 | emulationActivity.runOnUiThread(Runnable { onCoreErrorImpl(title, message) }) | 237 | emulationActivity.runOnUiThread { onCoreErrorImpl(title, message) } |
| 274 | 238 | ||
| 275 | // Wait for the lock to notify that it is complete. | 239 | // Wait for the lock to notify that it is complete. |
| 276 | synchronized(coreErrorAlertLock) { coreErrorAlertLock.wait() } | 240 | synchronized(coreErrorAlertLock) { coreErrorAlertLock.wait() } |
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/CoreErrorDialogFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/CoreErrorDialogFragment.kt new file mode 100644 index 000000000..299f8da71 --- /dev/null +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/CoreErrorDialogFragment.kt | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | // SPDX-FileCopyrightText: 2024 yuzu Emulator Project | ||
| 2 | // SPDX-License-Identifier: GPL-2.0-or-later | ||
| 3 | |||
| 4 | package org.yuzu.yuzu_emu.fragments | ||
| 5 | |||
| 6 | import android.app.Dialog | ||
| 7 | import android.content.DialogInterface | ||
| 8 | import android.os.Bundle | ||
| 9 | import androidx.fragment.app.DialogFragment | ||
| 10 | import com.google.android.material.dialog.MaterialAlertDialogBuilder | ||
| 11 | import org.yuzu.yuzu_emu.NativeLibrary | ||
| 12 | import org.yuzu.yuzu_emu.R | ||
| 13 | |||
| 14 | class CoreErrorDialogFragment : DialogFragment() { | ||
| 15 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog = | ||
| 16 | MaterialAlertDialogBuilder(requireActivity()) | ||
| 17 | .setTitle(requireArguments().getString(TITLE)) | ||
| 18 | .setMessage(requireArguments().getString(MESSAGE)) | ||
| 19 | .setPositiveButton(R.string.continue_button, null) | ||
| 20 | .setNegativeButton(R.string.abort_button) { _: DialogInterface?, _: Int -> | ||
| 21 | NativeLibrary.coreErrorAlertResult = false | ||
| 22 | synchronized(NativeLibrary.coreErrorAlertLock) { | ||
| 23 | NativeLibrary.coreErrorAlertLock.notify() | ||
| 24 | } | ||
| 25 | } | ||
| 26 | .create() | ||
| 27 | |||
| 28 | override fun onDismiss(dialog: DialogInterface) { | ||
| 29 | super.onDismiss(dialog) | ||
| 30 | NativeLibrary.coreErrorAlertResult = true | ||
| 31 | synchronized(NativeLibrary.coreErrorAlertLock) { NativeLibrary.coreErrorAlertLock.notify() } | ||
| 32 | } | ||
| 33 | |||
| 34 | companion object { | ||
| 35 | const val TITLE = "Title" | ||
| 36 | const val MESSAGE = "Message" | ||
| 37 | |||
| 38 | fun newInstance(title: String, message: String): CoreErrorDialogFragment { | ||
| 39 | val frag = CoreErrorDialogFragment() | ||
| 40 | val args = Bundle() | ||
| 41 | args.putString(TITLE, title) | ||
| 42 | args.putString(MESSAGE, message) | ||
| 43 | frag.arguments = args | ||
| 44 | return frag | ||
| 45 | } | ||
| 46 | } | ||
| 47 | } | ||