diff options
| author | 2024-02-17 19:53:03 -0500 | |
|---|---|---|
| committer | 2024-02-17 21:58:25 -0500 | |
| commit | c327d2a62c3699738b558f88ebe6645777cf5543 (patch) | |
| tree | 425ad77849b807ef4442803aca5947ba3b062cc1 /src/android | |
| parent | Merge pull request #13017 from liamwhite/suspension (diff) | |
| download | yuzu-c327d2a62c3699738b558f88ebe6645777cf5543.tar.gz yuzu-c327d2a62c3699738b558f88ebe6645777cf5543.tar.xz yuzu-c327d2a62c3699738b558f88ebe6645777cf5543.zip | |
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 6ebb46af7..f2f82080e 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 |
| @@ -318,46 +315,13 @@ object NativeLibrary { | |||
| 318 | ErrorUnknown | 315 | ErrorUnknown |
| 319 | } | 316 | } |
| 320 | 317 | ||
| 321 | private var coreErrorAlertResult = false | 318 | var coreErrorAlertResult = false |
| 322 | private val coreErrorAlertLock = Object() | 319 | val coreErrorAlertLock = Object() |
| 323 | |||
| 324 | class CoreErrorDialogFragment : DialogFragment() { | ||
| 325 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { | ||
| 326 | val title = requireArguments().serializable<String>("title") | ||
| 327 | val message = requireArguments().serializable<String>("message") | ||
| 328 | |||
| 329 | return MaterialAlertDialogBuilder(requireActivity()) | ||
| 330 | .setTitle(title) | ||
| 331 | .setMessage(message) | ||
| 332 | .setPositiveButton(R.string.continue_button, null) | ||
| 333 | .setNegativeButton(R.string.abort_button) { _: DialogInterface?, _: Int -> | ||
| 334 | coreErrorAlertResult = false | ||
| 335 | synchronized(coreErrorAlertLock) { coreErrorAlertLock.notify() } | ||
| 336 | } | ||
| 337 | .create() | ||
| 338 | } | ||
| 339 | |||
| 340 | override fun onDismiss(dialog: DialogInterface) { | ||
| 341 | coreErrorAlertResult = true | ||
| 342 | synchronized(coreErrorAlertLock) { coreErrorAlertLock.notify() } | ||
| 343 | } | ||
| 344 | |||
| 345 | companion object { | ||
| 346 | fun newInstance(title: String?, message: String?): CoreErrorDialogFragment { | ||
| 347 | val frag = CoreErrorDialogFragment() | ||
| 348 | val args = Bundle() | ||
| 349 | args.putString("title", title) | ||
| 350 | args.putString("message", message) | ||
| 351 | frag.arguments = args | ||
| 352 | return frag | ||
| 353 | } | ||
| 354 | } | ||
| 355 | } | ||
| 356 | 320 | ||
| 357 | private fun onCoreErrorImpl(title: String, message: String) { | 321 | private fun onCoreErrorImpl(title: String, message: String) { |
| 358 | val emulationActivity = sEmulationActivity.get() | 322 | val emulationActivity = sEmulationActivity.get() |
| 359 | if (emulationActivity == null) { | 323 | if (emulationActivity == null) { |
| 360 | error("[NativeLibrary] EmulationActivity not present") | 324 | Log.error("[NativeLibrary] EmulationActivity not present") |
| 361 | return | 325 | return |
| 362 | } | 326 | } |
| 363 | 327 | ||
| @@ -373,7 +337,7 @@ object NativeLibrary { | |||
| 373 | fun onCoreError(error: CoreError?, details: String): Boolean { | 337 | fun onCoreError(error: CoreError?, details: String): Boolean { |
| 374 | val emulationActivity = sEmulationActivity.get() | 338 | val emulationActivity = sEmulationActivity.get() |
| 375 | if (emulationActivity == null) { | 339 | if (emulationActivity == null) { |
| 376 | error("[NativeLibrary] EmulationActivity not present") | 340 | Log.error("[NativeLibrary] EmulationActivity not present") |
| 377 | return false | 341 | return false |
| 378 | } | 342 | } |
| 379 | 343 | ||
| @@ -404,7 +368,7 @@ object NativeLibrary { | |||
| 404 | } | 368 | } |
| 405 | 369 | ||
| 406 | // Show the AlertDialog on the main thread. | 370 | // Show the AlertDialog on the main thread. |
| 407 | emulationActivity.runOnUiThread(Runnable { onCoreErrorImpl(title, message) }) | 371 | emulationActivity.runOnUiThread { onCoreErrorImpl(title, message) } |
| 408 | 372 | ||
| 409 | // Wait for the lock to notify that it is complete. | 373 | // Wait for the lock to notify that it is complete. |
| 410 | synchronized(coreErrorAlertLock) { coreErrorAlertLock.wait() } | 374 | 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 | } | ||