Skip to content

Commit

Permalink
refactor: move exit() to AnkiActivity (#15666)
Browse files Browse the repository at this point in the history
* refactor: move exit() to AnkiActivity
* refactor: rename exit to closeCollectionAndFinish

---------

Co-authored-by: Mike Hardy <[email protected]>
(cherry picked from commit 8174898)
  • Loading branch information
david-allison authored and mikehardy committed Feb 25, 2024
1 parent 1519938 commit dde4f4e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
6 changes: 6 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/anki/AnkiActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
8 changes: 1 addition & 7 deletions AnkiDroid/src/main/java/com/ichi2/anki/DeckPicker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ open class DeckPicker :
)
)
positiveButton(R.string.close) {
exit()
closeCollectionAndFinish()
}
cancelable(false)
}
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class DatabaseErrorDialog : AsyncDialogFragment() {
?.showDatabaseErrorDialog(DIALOG_ERROR_HANDLING)
}
negativeButton(R.string.close) {
exit()
closeCollectionAndFinish()
}
}
}
Expand All @@ -103,7 +103,7 @@ class DatabaseErrorDialog : AsyncDialogFragment() {
dismissAllDialogFragments()
}
neutralButton(R.string.close) {
exit()
closeCollectionAndFinish()
}
setActionButtonEnabled(WhichButton.NEGATIVE, (activity as DeckPicker).hasErrorFiles())
}
Expand Down Expand Up @@ -304,7 +304,7 @@ class DatabaseErrorDialog : AsyncDialogFragment() {
dialog.show {
contentNullable(message)
positiveButton(R.string.close) {
exit()
closeCollectionAndFinish()
}
cancelable(false)
}
Expand All @@ -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]) {
Expand All @@ -341,7 +341,7 @@ class DatabaseErrorDialog : AsyncDialogFragment() {
dialog.show {
contentNullable(message)
positiveButton(R.string.close) {
exit()
closeCollectionAndFinish()
}
}
}
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit dde4f4e

Please sign in to comment.