Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ class DatabaseErrorDialog : AsyncDialogFragment() {
DIALOG_ERROR_HANDLING -> {
// The user has asked to see repair options; allow them to choose one of the repair options or go back
// to the previous dialog
val options = ArrayList<String>(7)
val values = ArrayList<ErrorHandlingEntries>(7)
val options = ArrayList<String>(8)
val values = ArrayList<ErrorHandlingEntries>(8)
if (!requireAnkiActivity().colIsOpenUnsafe()) {
// retry
options.add(res.getString(R.string.backup_retry_opening))
Expand All @@ -171,6 +171,23 @@ class DatabaseErrorDialog : AsyncDialogFragment() {
options.add(res.getString(R.string.backup_one_way_sync_from_server))
values.add(ErrorHandlingEntries.ONE_WAY)
}

val activity = requireActivity()
val shouldOfferResetToDefaultDirectory =
try {
val currentDir = CollectionHelper.getCurrentAnkiDroidDirectory(activity)
val defaultDir = CollectionHelper.getDefaultAnkiDroidDirectory(activity)
currentDir.absolutePath != defaultDir.absolutePath
} catch (e: SystemStorageException) {
Timber.w(e, "Failed to determine whether to offer reset-to-default directory option")
false
}

if (shouldOfferResetToDefaultDirectory) {
options.add(res.getString(R.string.backup_use_default_folder))
values.add(ErrorHandlingEntries.RESET_TO_DEFAULT_DIRECTORY)
}

// delete old collection and build new one
options.add(res.getString(R.string.backup_del_collection))
values.add(ErrorHandlingEntries.NEW)
Expand Down Expand Up @@ -200,6 +217,18 @@ class DatabaseErrorDialog : AsyncDialogFragment() {
showDatabaseErrorDialog(DIALOG_ONE_WAY_SYNC_FROM_SERVER)
return@listItems
}
ErrorHandlingEntries.RESET_TO_DEFAULT_DIRECTORY -> {
try {
val defaultDir = CollectionHelper.getDefaultAnkiDroidDirectory(activity)
CollectionManager.closeCollectionBlocking()
CollectionHelper.resetAnkiDroidDirectory(activity, defaultDir)
closeCollectionAndFinish()
} catch (e: SystemStorageException) {
Timber.w(e, "Failed to reset AnkiDroid directory to default")
showDatabaseErrorDialog(DIALOG_LOAD_FAILED)
}
return@listItems
}
ErrorHandlingEntries.NEW -> {
showDatabaseErrorDialog(DIALOG_NEW_COLLECTION)
return@listItems
Expand Down Expand Up @@ -747,6 +776,7 @@ private enum class ErrorHandlingEntries {
REPAIR,
RESTORE,
ONE_WAY,
RESET_TO_DEFAULT_DIRECTORY,
NEW,
DEBUG_INFO,
}
Expand Down
1 change: 1 addition & 0 deletions AnkiDroid/src/main/res/values/09-backup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<string name="backup_del_collection">Delete collection and create new one</string>
<string name="backup_del_collection_question">Delete the collection and create a new one? This will drop all your learning progress and delete all cards.</string>
<string name="backup_one_way_sync_from_server">One-way sync from server</string>
<string name="backup_use_default_folder">Use default collection folder</string>
<string name="backup_full_sync_from_server_question">Overwrite your collection with the one from AnkiWeb? This will drop all your learning progress and added information since your last sync.</string>
<string name="error_handling_title">Error handling</string>
<string name="error_handling_options" comment="In a warning message, the label of the suggested action that the user should take">Options</string>
Expand Down
Loading