From dde4f4e74a509f5f9c2b167b28bdd98d45984126 Mon Sep 17 00:00:00 2001 From: David Allison <62114487+david-allison@users.noreply.github.com> Date: Sun, 25 Feb 2024 22:47:26 +0000 Subject: [PATCH] refactor: move exit() to AnkiActivity (#15666) * refactor: move exit() to AnkiActivity * refactor: rename exit to closeCollectionAndFinish --------- Co-authored-by: Mike Hardy (cherry picked from commit 81748980632ce2fd12316a9cba83cfd57ef069b9) --- .../src/main/java/com/ichi2/anki/AnkiActivity.kt | 6 ++++++ .../src/main/java/com/ichi2/anki/DeckPicker.kt | 8 +------- .../ichi2/anki/dialogs/DatabaseErrorDialog.kt | 16 ++++++++-------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/AnkiActivity.kt b/AnkiDroid/src/main/java/com/ichi2/anki/AnkiActivity.kt index 34cd6993e231..233ba7eaa125 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/AnkiActivity.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/AnkiActivity.kt @@ -546,6 +546,12 @@ open class AnkiActivity : AppCompatActivity, SimpleMessageDialogListener { window.navigationBarColor = ThemeUtils.getThemeAttrColor(this, attr) } + fun closeCollectionAndFinish() { + Timber.i("closeCollectionAndFinish()") + CollectionHelper.instance.closeCollection("AnkiActivity:closeCollectionAndFinish()") + finish() + } + companion object { const val DIALOG_FRAGMENT_TAG = "dialog" diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt b/AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt index ee21425ba539..be6fc00121bc 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt @@ -732,7 +732,7 @@ open class DeckPicker : ) ) positiveButton(R.string.close) { - exit() + closeCollectionAndFinish() } cancelable(false) } @@ -1656,12 +1656,6 @@ open class DeckPicker : } } - fun exit() { - Timber.i("exit()") - CollectionHelper.instance.closeCollection("DeckPicker:exit()") - finish() - } - open fun handleDbError() { Timber.i("Displaying Database Error") showDatabaseErrorDialog(DatabaseErrorDialogType.DIALOG_LOAD_FAILED) 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 da9b4ef08d95..7c875c308532 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/DatabaseErrorDialog.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/dialogs/DatabaseErrorDialog.kt @@ -83,7 +83,7 @@ class DatabaseErrorDialog : AsyncDialogFragment() { ?.showDatabaseErrorDialog(DIALOG_ERROR_HANDLING) } negativeButton(R.string.close) { - exit() + closeCollectionAndFinish() } } } @@ -103,7 +103,7 @@ class DatabaseErrorDialog : AsyncDialogFragment() { dismissAllDialogFragments() } neutralButton(R.string.close) { - exit() + closeCollectionAndFinish() } setActionButtonEnabled(WhichButton.NEGATIVE, (activity as DeckPicker).hasErrorFiles()) } @@ -304,7 +304,7 @@ class DatabaseErrorDialog : AsyncDialogFragment() { dialog.show { contentNullable(message) positiveButton(R.string.close) { - exit() + closeCollectionAndFinish() } cancelable(false) } @@ -323,7 +323,7 @@ class DatabaseErrorDialog : AsyncDialogFragment() { contentNullable(message) icon(R.drawable.ic_warning) positiveButton(R.string.close) { - exit() + closeCollectionAndFinish() } listItems(items = options, waitForPositiveButton = false) { _: MaterialDialog, index: Int, _: CharSequence -> when (values[index]) { @@ -341,7 +341,7 @@ class DatabaseErrorDialog : AsyncDialogFragment() { dialog.show { contentNullable(message) positiveButton(R.string.close) { - exit() + closeCollectionAndFinish() } } } @@ -439,7 +439,7 @@ class DatabaseErrorDialog : AsyncDialogFragment() { val ch = CollectionHelper.instance ch.closeCollection("DatabaseErrorDialog: Before Create New Collection") CollectionHelper.resetAnkiDroidDirectory(context) - context.exit() + context.closeCollectionAndFinish() } negativeButton(R.string.dialog_cancel) cancelable(false) @@ -455,8 +455,8 @@ class DatabaseErrorDialog : AsyncDialogFragment() { } } - private fun exit() { - (activity as DeckPicker).exit() + private fun closeCollectionAndFinish() { + (activity as AnkiActivity).closeCollectionAndFinish() } // Generic message shown when a libanki task failed // The sqlite database has been corrupted (DatabaseErrorHandler.onCorrupt() was called)