diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/BackendImporting.kt b/AnkiDroid/src/main/java/com/ichi2/anki/BackendImporting.kt index 4e723d2424c0..0f422ea067f8 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/BackendImporting.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/BackendImporting.kt @@ -21,6 +21,7 @@ package com.ichi2.anki import anki.import_export.ImportResponse import com.ichi2.anki.CollectionManager.withColNew import com.ichi2.libanki.exportAnkiPackage +import com.ichi2.libanki.exportCollectionPackage import com.ichi2.libanki.importAnkiPackage import com.ichi2.libanki.undoableOp import net.ankiweb.rsdroid.Translations @@ -63,23 +64,38 @@ private fun summarizeReport(tr: Translations, output: ImportResponse): String { return msgs.joinToString("\n") } -fun DeckPicker.exportApkg( +suspend fun AnkiActivity.exportApkg( apkgPath: String, withScheduling: Boolean, withMedia: Boolean, deckId: Long? ) { - launchCatchingTask { - withProgress( - extractProgress = { - if (progress.hasExporting()) { - text = progress.exporting - } - }, - ) { - withColNew { - exportAnkiPackage(apkgPath, withScheduling, withMedia, deckId) + withProgress( + extractProgress = { + if (progress.hasExporting()) { + text = progress.exporting + } + }, + ) { + withColNew { + exportAnkiPackage(apkgPath, withScheduling, withMedia, deckId) + } + } +} + +suspend fun AnkiActivity.exportColpkg( + colpkgPath: String, + withMedia: Boolean, +) { + withProgress( + extractProgress = { + if (progress.hasExporting()) { + text = progress.exporting } + }, + ) { + withColNew { + exportCollectionPackage(colpkgPath, withMedia, true) } } } diff --git a/AnkiDroid/src/main/java/com/ichi2/anki/export/ActivityExportingDelegate.kt b/AnkiDroid/src/main/java/com/ichi2/anki/export/ActivityExportingDelegate.kt index 98a1489266b4..4f4290b06233 100644 --- a/AnkiDroid/src/main/java/com/ichi2/anki/export/ActivityExportingDelegate.kt +++ b/AnkiDroid/src/main/java/com/ichi2/anki/export/ActivityExportingDelegate.kt @@ -25,14 +25,11 @@ import androidx.activity.result.contract.ActivityResultContracts import androidx.annotation.StringRes import androidx.core.app.ShareCompat.IntentBuilder import androidx.core.content.FileProvider -import com.ichi2.anki.AnkiActivity -import com.ichi2.anki.DeckPicker -import com.ichi2.anki.R +import com.ichi2.anki.* import com.ichi2.anki.UIUtils.showSimpleSnackbar import com.ichi2.anki.UIUtils.showThemedToast import com.ichi2.anki.dialogs.ExportCompleteDialog.ExportCompleteDialogListener import com.ichi2.anki.dialogs.ExportDialog.ExportDialogListener -import com.ichi2.anki.exportApkg import com.ichi2.async.CollectionTask.ExportApkg import com.ichi2.async.TaskManager import com.ichi2.compat.CompatHelper @@ -102,11 +99,15 @@ class ActivityExportingDelegate(private val activity: AnkiActivity, private val exportListener ) } else { - // TODO: this code needs reworking so that the post-export dialogs can be - // shown correctly - (activity as DeckPicker).exportApkg(exportPath.path, includeSched, includeMedia, did) - // exportListener.actualOnPreExecute(activity) - // exportListener.actualOnPostExecute(activity, android.util.Pair(false, exportPath.path)) + activity.launchCatchingTask { + if (did == null && includeSched) { + activity.exportColpkg(exportPath.path, includeMedia) + } else { + activity.exportApkg(exportPath.path, includeSched, includeMedia, did) + } + val dialog = mDialogsFactory.newExportCompleteDialog().withArguments(exportPath.path) + activity.showAsyncDialogFragment(dialog) + } } } diff --git a/AnkiDroid/src/main/java/com/ichi2/libanki/BackendImportExport.kt b/AnkiDroid/src/main/java/com/ichi2/libanki/BackendImportExport.kt index abd520c81660..22ad620a2089 100644 --- a/AnkiDroid/src/main/java/com/ichi2/libanki/BackendImportExport.kt +++ b/AnkiDroid/src/main/java/com/ichi2/libanki/BackendImportExport.kt @@ -74,9 +74,8 @@ fun importCollectionPackage( } /** - * Export the collection into a .colpkg file. This closes the collection (since it may need to - * downgrade the schema for a legacy export), and col.reopen() must be called afterwards. - * * If legacy=false, a file targeting Anki 2.1.50+ is created. It compresses better and is faster to + * Export the collection into a .colpkg file. + * If legacy=false, a file targeting Anki 2.1.50+ is created. It compresses better and is faster to * create, but older clients can not read it. */ fun CollectionV16.exportCollectionPackage( @@ -84,11 +83,13 @@ fun CollectionV16.exportCollectionPackage( includeMedia: Boolean, legacy: Boolean = true ) { + close(save = true, downgrade = false, forFullSync = true) backend.exportCollectionPackage( outPath = outPath, includeMedia = includeMedia, legacy = legacy ) + reopen(afterFullSync = false) } /**