From 79ddf784611bd7065d8e4f89c22ee29a58ba7095 Mon Sep 17 00:00:00 2001 From: Arthur Milchior Date: Sat, 7 Dec 2024 21:34:32 +0100 Subject: [PATCH] DatabaseErrorDialog require deck picker Currently, if the activity was not the deck picker, the buttons would have no effect. With this change, if for some reason the error appeared on another activity, we'd get a crash and could correct it. It's not 100% clear that this can't occur because the DatabaseErrorDialogi s created in AnkiActivity's `showDatabaseErrorDialog`. --- .../ichi2/anki/dialogs/DatabaseErrorDialog.kt | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/DatabaseErrorDialog.kt b/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/DatabaseErrorDialog.kt index 9e8ce271d22a..0bc34bd10a60 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/DatabaseErrorDialog.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/DatabaseErrorDialog.kt @@ -112,8 +112,7 @@ class DatabaseErrorDialog : AsyncDialogFragment() { message(text = message) setIcon(R.drawable.ic_warning) positiveButton(R.string.error_handling_options) { - (activity as DeckPicker?) - ?.showDatabaseErrorDialog(DIALOG_ERROR_HANDLING, exceptionData) + requireDeckPicker().showDatabaseErrorDialog(DIALOG_ERROR_HANDLING, exceptionData) } negativeButton(R.string.close) { closeCollectionAndFinish() @@ -129,8 +128,7 @@ class DatabaseErrorDialog : AsyncDialogFragment() { message(text = message) setIcon(R.drawable.ic_warning) positiveButton(R.string.error_handling_options) { - (activity as DeckPicker?) - ?.showDatabaseErrorDialog(DIALOG_ERROR_HANDLING, exceptionData) + requireDeckPicker().showDatabaseErrorDialog(DIALOG_ERROR_HANDLING, exceptionData) } negativeButton(R.string.answering_error_report) { requireDeckPicker().sendErrorReport() @@ -235,8 +233,7 @@ class DatabaseErrorDialog : AsyncDialogFragment() { alertDialog.title(R.string.backup_restore) .title(text = message) .positiveButton(R.string.dialog_ok) { - (activity as DeckPicker?) - ?.showDatabaseErrorDialog(DIALOG_ERROR_HANDLING, exceptionData) + requireDeckPicker().showDatabaseErrorDialog(DIALOG_ERROR_HANDLING, exceptionData) } } else { // Show backups sorted with latest on top @@ -254,10 +251,9 @@ class DatabaseErrorDialog : AsyncDialogFragment() { .setSingleChoiceItems(dates.toTypedArray(), -1) { _, index: Int -> if (backups[index].length() > 0) { // restore the backup if it's valid - (activity as DeckPicker?) - ?.restoreFromBackup( - backups[index].path - ) + requireDeckPicker().restoreFromBackup( + backups[index].path + ) activity?.dismissAllDialogFragments() } else { // otherwise show an error dialog @@ -318,8 +314,7 @@ class DatabaseErrorDialog : AsyncDialogFragment() { title(R.string.restore_backup_title) message(text = message) positiveButton(R.string.dialog_continue) { - (activity as DeckPicker?) - ?.showDatabaseErrorDialog(DIALOG_RESTORE_BACKUP, exceptionData) + requireDeckPicker().showDatabaseErrorDialog(DIALOG_RESTORE_BACKUP, exceptionData) } negativeButton(R.string.dialog_cancel) }