Skip to content

Commit

Permalink
DatabaseErrorDialog require deck picker
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
Arthur-Milchior authored and mikehardy committed Dec 8, 2024
1 parent da82fb1 commit 79ddf78
Showing 1 changed file with 7 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 79ddf78

Please sign in to comment.