summaryrefslogtreecommitdiff
path: root/src/android
diff options
context:
space:
mode:
authorGravatar t8952024-02-17 19:53:03 -0500
committerGravatar t8952024-02-17 21:58:25 -0500
commitc327d2a62c3699738b558f88ebe6645777cf5543 (patch)
tree425ad77849b807ef4442803aca5947ba3b062cc1 /src/android
parentMerge pull request #13017 from liamwhite/suspension (diff)
downloadyuzu-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.kt48
-rw-r--r--src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/CoreErrorDialogFragment.kt47
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
4package org.yuzu.yuzu_emu 4package org.yuzu.yuzu_emu
5 5
6import android.app.Dialog
7import android.content.DialogInterface 6import android.content.DialogInterface
8import android.net.Uri 7import android.net.Uri
9import android.os.Bundle
10import android.text.Html 8import android.text.Html
11import android.text.method.LinkMovementMethod 9import android.text.method.LinkMovementMethod
12import android.view.Surface 10import android.view.Surface
13import android.view.View 11import android.view.View
14import android.widget.TextView 12import android.widget.TextView
15import androidx.annotation.Keep 13import androidx.annotation.Keep
16import androidx.fragment.app.DialogFragment
17import com.google.android.material.dialog.MaterialAlertDialogBuilder 14import com.google.android.material.dialog.MaterialAlertDialogBuilder
18import java.lang.ref.WeakReference 15import java.lang.ref.WeakReference
19import org.yuzu.yuzu_emu.activities.EmulationActivity 16import org.yuzu.yuzu_emu.activities.EmulationActivity
17import org.yuzu.yuzu_emu.fragments.CoreErrorDialogFragment
20import org.yuzu.yuzu_emu.utils.DocumentsTree 18import org.yuzu.yuzu_emu.utils.DocumentsTree
21import org.yuzu.yuzu_emu.utils.FileUtil 19import org.yuzu.yuzu_emu.utils.FileUtil
22import org.yuzu.yuzu_emu.utils.Log 20import org.yuzu.yuzu_emu.utils.Log
23import org.yuzu.yuzu_emu.utils.SerializableHelper.serializable
24import org.yuzu.yuzu_emu.model.InstallResult 21import org.yuzu.yuzu_emu.model.InstallResult
25import org.yuzu.yuzu_emu.model.Patch 22import org.yuzu.yuzu_emu.model.Patch
26import org.yuzu.yuzu_emu.model.GameVerificationResult 23import 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
4package org.yuzu.yuzu_emu.fragments
5
6import android.app.Dialog
7import android.content.DialogInterface
8import android.os.Bundle
9import androidx.fragment.app.DialogFragment
10import com.google.android.material.dialog.MaterialAlertDialogBuilder
11import org.yuzu.yuzu_emu.NativeLibrary
12import org.yuzu.yuzu_emu.R
13
14class 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}