summaryrefslogtreecommitdiff
path: root/src/android
diff options
context:
space:
mode:
authorGravatar liamwhite2024-02-17 22:22:46 -0500
committerGravatar GitHub2024-02-17 22:22:46 -0500
commit316089c39fbca3e3bab3c00bec8e90c86101c64a (patch)
tree24e0778729dc87d86fb73836417a13924aef0f56 /src/android
parentMerge pull request #13051 from german77/cheatmiss (diff)
parentandroid: Move CoreErrorDialogFragment to its own file (diff)
downloadyuzu-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.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 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
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
@@ -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
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}