From 285723e7b91af58edc6f77d04b94912a16d00b48 Mon Sep 17 00:00:00 2001 From: Levin Li Date: Thu, 11 Jul 2024 22:44:54 -0700 Subject: [PATCH] Minor tweaks --- app/src/main/AndroidManifest.xml | 2 +- .../mobilecelestia/celestia/CelestiaInteraction.kt | 4 ++++ .../java/space/celestia/mobilecelestia/utils/Dialog.kt | 9 +++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 48aa96e8..dcbaa62f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -13,7 +13,7 @@ diff --git a/app/src/main/java/space/celestia/mobilecelestia/celestia/CelestiaInteraction.kt b/app/src/main/java/space/celestia/mobilecelestia/celestia/CelestiaInteraction.kt index e9269333..44850ce3 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/celestia/CelestiaInteraction.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/celestia/CelestiaInteraction.kt @@ -536,6 +536,10 @@ class CelestiaInteraction(context: Context, private val appCore: AppCore, privat return false } + // Ignore Back button action + if (event.keyCode == KeyEvent.KEYCODE_BACK) + return false + if (event.action == KeyEvent.ACTION_UP) return onKeyUp(keyCode, event) else if (event.action == KeyEvent.ACTION_DOWN) diff --git a/app/src/main/java/space/celestia/mobilecelestia/utils/Dialog.kt b/app/src/main/java/space/celestia/mobilecelestia/utils/Dialog.kt index 7ef7f9ef..cd46bd06 100644 --- a/app/src/main/java/space/celestia/mobilecelestia/utils/Dialog.kt +++ b/app/src/main/java/space/celestia/mobilecelestia/utils/Dialog.kt @@ -114,7 +114,7 @@ fun Activity.showLoading(title: String, cancelHandler: (() -> Unit)? = null): Al return builder.show() } -fun Activity.showAlert(title: String, message: String? = null, handler: (() -> Unit)? = null) { +fun Activity.showAlert(title: String, message: String? = null, handler: (() -> Unit)? = null, cancelHandler: (() -> Unit)? = null) { if (isFinishing || isDestroyed) return @@ -126,11 +126,16 @@ fun Activity.showAlert(title: String, message: String? = null, handler: (() -> U if (handler != null) handler() } - if (handler != null) { + if (handler != null || cancelHandler != null) { builder.setNegativeButton(CelestiaString("Cancel", "")) { dialog, _ -> dialog.cancel() } } + if (cancelHandler != null) { + builder.setOnCancelListener { + cancelHandler() + } + } builder.show() }