0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-19 19:42:17 +02:00

Move exported file saving to a background thread

This avoids the UI being "blocked" while saving the exported collection or
apkg, issue which becomes "visible" to the user when dealing with bigger
collections.
This commit is contained in:
lukstbit 2024-07-15 11:12:33 +03:00
parent a73f17330e
commit c7cbea0b53
2 changed files with 17 additions and 6 deletions

View File

@ -30,13 +30,17 @@ import com.google.android.material.snackbar.Snackbar
import com.ichi2.anki.AnkiActivity
import com.ichi2.anki.R
import com.ichi2.anki.dialogs.ExportReadyDialog.ExportReadyDialogListener
import com.ichi2.anki.launchCatchingTask
import com.ichi2.anki.preferences.sharedPrefs
import com.ichi2.anki.showThemedToast
import com.ichi2.anki.snackbar.showSnackbar
import com.ichi2.anki.withProgress
import com.ichi2.annotations.NeedsTest
import com.ichi2.compat.CompatHelper
import com.ichi2.libanki.Collection
import com.ichi2.libanki.utils.TimeManager
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import timber.log.Timber
import java.io.File
import java.io.FileOutputStream
@ -143,13 +147,19 @@ class ActivityExportingDelegate(private val activity: AnkiActivity, private val
}
private fun saveFileCallback(result: ActivityResult) {
val isSuccessful = exportToProvider(result.data!!)
activity.launchCatchingTask {
activity.withProgress(activity.getString(R.string.export_saving_exported_collection)) {
val isSuccessful = withContext(Dispatchers.IO) {
exportToProvider(result.data!!)
}
if (isSuccessful) {
activity.showSnackbar(R.string.export_save_apkg_successful, Snackbar.LENGTH_SHORT)
saveSuccessfulCollectionExportIfRelevant()
} else {
activity.showSnackbar(R.string.export_save_apkg_unsuccessful)
if (isSuccessful) {
activity.showSnackbar(R.string.export_save_apkg_successful, Snackbar.LENGTH_SHORT)
saveSuccessfulCollectionExportIfRelevant()
} else {
activity.showSnackbar(R.string.export_save_apkg_unsuccessful)
}
}
}
}

View File

@ -148,6 +148,7 @@
</string>
<string name="export_choice_share">Share</string>
<string name="export_choice_save_to">Save to</string>
<string name="export_saving_exported_collection">Saving exported file&#8230;</string>
<string name="study_options" comment="Name for a preference category in Filtered deck (aka Cram deck, aka Custom study) options">Options</string>
<string name="menu__deck_options">Deck options</string>
<string name="menu__study_options" comment="Menu item that opens options for a Filtered deck (aka Cram deck, aka Custom study)">Study options</string>