Skip to content

Commit

Permalink
Added checkbox for colpkg and apkg exports to match Anki desktop
Browse files Browse the repository at this point in the history
  • Loading branch information
Haz3-jolt committed Dec 18, 2024
1 parent ff607b3 commit fd7f50f
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
9 changes: 6 additions & 3 deletions AnkiDroid/src/main/java/com/ichi2/anki/BackendExporting.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ fun AnkiActivity.exportApkgPackage(
withDeckConfigs: Boolean,
withMedia: Boolean,
limit: ExportLimit,
legacy: Boolean,
) {
launchCatchingTask {
val onProgress: ProgressContext.() -> Unit = {
Expand All @@ -35,7 +36,7 @@ fun AnkiActivity.exportApkgPackage(
}
}
withProgress(extractProgress = onProgress) {
withCol { exportAnkiPackage(exportPath, withScheduling, withDeckConfigs, withMedia, limit) }
withCol { exportAnkiPackage(exportPath, withScheduling, withDeckConfigs, withMedia, limit, legacy) }
}
val factory =
(this@exportApkgPackage as ExportDialogsFactoryProvider).exportDialogsFactory()
Expand All @@ -47,23 +48,25 @@ fun AnkiActivity.exportApkgPackage(
suspend fun AnkiActivity.exportColpkg(
colpkgPath: String,
withMedia: Boolean,
legacy: Boolean,
) {
val onProgress: ProgressContext.() -> Unit = {
if (progress.hasExporting()) {
text = getString(R.string.export_preparation_in_progress)
}
}
withProgress(extractProgress = onProgress) {
withCol { exportCollectionPackage(colpkgPath, withMedia, true) }
withCol { exportCollectionPackage(colpkgPath, withMedia, legacy) }
}
}

fun AnkiActivity.exportCollectionPackage(
exportPath: String,
withMedia: Boolean,
legacy: Boolean,
) {
launchCatchingTask {
exportColpkg(exportPath, withMedia)
exportColpkg(exportPath, withMedia, legacy)
val factory =
(this@exportCollectionPackage as ExportDialogsFactoryProvider).exportDialogsFactory()
val dialog = factory.newExportReadyDialog().withArguments(exportPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class ExportDialogFragment : DialogFragment() {
private lateinit var notesIncludeNotetypeName: CheckBox
private lateinit var notesIncludeUniqueIdentifier: CheckBox
private lateinit var cardsIncludeHtml: CheckBox
private lateinit var apkgExportLegacyCheckbox: CheckBox
private lateinit var collectionExportLegacyCheckbox: CheckBox

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialogView =
Expand Down Expand Up @@ -209,6 +211,10 @@ class ExportDialogFragment : DialogFragment() {
findViewById<CheckBox>(R.id.export_extras_collection_media).apply {
text = exportingIncludeMedia()
}
collectionExportLegacyCheckbox =
findViewById<CheckBox>(R.id.export_legacy_checkbox_collection).apply {
text = exportingSupportOlderAnkiVersions()
}
}

/**
Expand All @@ -228,6 +234,10 @@ class ExportDialogFragment : DialogFragment() {
findViewById<CheckBox>(R.id.export_apkg_schedule).apply {
text = exportingIncludeSchedulingInformation()
}
apkgExportLegacyCheckbox =
findViewById<CheckBox>(R.id.export_legacy_checkbox_apkg).apply {
text = exportingSupportOlderAnkiVersions()
}
}

/**
Expand Down Expand Up @@ -274,6 +284,11 @@ class ExportDialogFragment : DialogFragment() {
targetConfig: ExportConfiguration,
) {
// if we export as collection there's no deck/selected items to choose from
if (targetConfig.layoutId == R.id.export_extras_collection || targetConfig.layoutId == R.id.export_extras_apkg) {
collectionExportLegacyCheckbox.visibility = View.VISIBLE
} else {
apkgExportLegacyCheckbox.visibility = View.GONE
}
if (targetConfig.layoutId == R.id.export_extras_collection) {
decksSelectorContainer.visibility = View.GONE
selectedLabel.visibility = View.GONE
Expand All @@ -295,18 +310,20 @@ class ExportDialogFragment : DialogFragment() {

private fun handleCollectionExport() {
val includeMedia = collectionIncludeMedia.isChecked
val legacy = collectionExportLegacyCheckbox.isChecked
val exportPath =
File(
getExportRootFile(),
"${CollectionManager.TR.exportingCollection()}-${getTimestamp(TimeManager.time)}.colpkg",
).path
(requireActivity() as AnkiActivity).exportCollectionPackage(exportPath, includeMedia)
(requireActivity() as AnkiActivity).exportCollectionPackage(exportPath, includeMedia, legacy)
}

private fun handleAnkiPackageExport() {
val includeSchedule = apkgIncludeSchedule.isChecked
val includeDeckConfigs = apkgIncludeDeckConfigs.isChecked
val includeMedia = apkgIncludeMedia.isChecked
val legacy = apkgExportLegacyCheckbox.isChecked
val limits = buildExportLimit()
var packagePrefix = getNonCollectionNamePrefix()
// files can't have `/` in their names
Expand All @@ -322,6 +339,7 @@ class ExportDialogFragment : DialogFragment() {
withDeckConfigs = includeDeckConfigs,
withMedia = includeMedia,
limit = limits,
legacy = legacy,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fun importCollectionPackage(
fun Collection.exportCollectionPackage(
outPath: String,
includeMedia: Boolean,
legacy: Boolean = true,
legacy: Boolean,
) {
close(forFullSync = true)
backend.exportCollectionPackage(
Expand Down Expand Up @@ -113,7 +113,7 @@ fun Collection.exportAnkiPackage(
withDeckConfigs: Boolean,
withMedia: Boolean,
limit: ExportLimit,
legacy: Boolean = true,
legacy: Boolean,
) {
val options =
exportAnkiPackageOptions {
Expand Down
15 changes: 14 additions & 1 deletion AnkiDroid/src/main/res/layout/dialog_export_options.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,21 @@
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/decks_selected_barrier">
app:layout_constraintTop_toBottomOf="@id/decks_selected_barrier"
android:orientation="vertical">

<CheckBox
android:id="@+id/export_extras_collection_media"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
tools:text="Include media" />

<CheckBox
android:id="@+id/export_legacy_checkbox_collection"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="false" />
</LinearLayout>


Expand Down Expand Up @@ -63,6 +70,12 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="true" />

<CheckBox
android:id="@+id/export_legacy_checkbox_apkg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="false" />
</LinearLayout>


Expand Down

0 comments on commit fd7f50f

Please sign in to comment.