diff --git a/app/src/main/java/com/philkes/notallyx/presentation/UiExtensions.kt b/app/src/main/java/com/philkes/notallyx/presentation/UiExtensions.kt index 0caadf9b..316cc6ff 100644 --- a/app/src/main/java/com/philkes/notallyx/presentation/UiExtensions.kt +++ b/app/src/main/java/com/philkes/notallyx/presentation/UiExtensions.kt @@ -112,6 +112,7 @@ import com.philkes.notallyx.presentation.viewmodel.BaseNoteModel import com.philkes.notallyx.presentation.viewmodel.preference.DateFormat import com.philkes.notallyx.presentation.viewmodel.preference.TimeFormat import com.philkes.notallyx.presentation.viewmodel.preference.displayBodySize +import com.philkes.notallyx.utils.backup.NotesAndAttachments import com.philkes.notallyx.utils.changehistory.ChangeHistory import com.philkes.notallyx.utils.changehistory.EditTextState import com.philkes.notallyx.utils.changehistory.EditTextWithHistoryChange @@ -505,7 +506,8 @@ private fun MutableLiveData.setupProgressDialog( } if (renderProgress == null) { Count.text = - context.getString(R.string.count, progress.current, progress.total) + context.getString(R.string.count, progress.current, progress.total) + + (progress.countSuffix?.let { " $it" } ?: "") } else renderProgress.invoke(context, this, progress) } } @@ -1186,3 +1188,6 @@ fun Chip.setupReminderChip( else paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv() } } + +fun Context.exportedText(notesAndAttachments: NotesAndAttachments) = + "${getString(R.string.exported)} ${notesAndAttachments.first} ${if(notesAndAttachments.first == 1) getString(R.string.note) else getString(R.string.notes)} (${notesAndAttachments.second} ${getQuantityString(R.plurals.attachments, notesAndAttachments.second)})" diff --git a/app/src/main/java/com/philkes/notallyx/presentation/view/misc/Progress.kt b/app/src/main/java/com/philkes/notallyx/presentation/view/misc/Progress.kt index 686ad19b..d7a5f937 100644 --- a/app/src/main/java/com/philkes/notallyx/presentation/view/misc/Progress.kt +++ b/app/src/main/java/com/philkes/notallyx/presentation/view/misc/Progress.kt @@ -6,4 +6,5 @@ abstract class Progress( val total: Int = 0, val inProgress: Boolean = true, val indeterminate: Boolean = false, + val countSuffix: String? = null, ) diff --git a/app/src/main/java/com/philkes/notallyx/presentation/viewmodel/BaseNoteModel.kt b/app/src/main/java/com/philkes/notallyx/presentation/viewmodel/BaseNoteModel.kt index 3f73c41c..1c23b019 100644 --- a/app/src/main/java/com/philkes/notallyx/presentation/viewmodel/BaseNoteModel.kt +++ b/app/src/main/java/com/philkes/notallyx/presentation/viewmodel/BaseNoteModel.kt @@ -45,6 +45,7 @@ import com.philkes.notallyx.data.model.SearchResult import com.philkes.notallyx.data.model.deepCopy import com.philkes.notallyx.presentation.activity.main.fragment.settings.SettingsFragment.Companion.EXTRA_SHOW_IMPORT_BACKUPS_FOLDER import com.philkes.notallyx.presentation.activity.note.refreshStatusBarPin +import com.philkes.notallyx.presentation.exportedText import com.philkes.notallyx.presentation.getQuantityString import com.philkes.notallyx.presentation.restartApplication import com.philkes.notallyx.presentation.setCancelButton @@ -410,7 +411,7 @@ class BaseNoteModel(private val app: Application) : AndroidViewModel(app) { fun exportBackup(uri: Uri, onComplete: (() -> Unit)? = null) { viewModelScope.launch { - val exportedNotes = + val exportedNotesAndAttachments = withContext(Dispatchers.IO) { app.log(TAG, msg = "Exporting backup to '$uri'...") return@withContext app.exportAsZip( @@ -420,8 +421,8 @@ class BaseNoteModel(private val app: Application) : AndroidViewModel(app) { ) .also { app.log(TAG, msg = "Finished exporting backup to '$uri'") } } - val message = app.getQuantityString(R.plurals.exported_notes, exportedNotes) - app.showToast(message) + + app.showToast(app.exportedText(exportedNotesAndAttachments)) onComplete?.invoke() } } diff --git a/app/src/main/java/com/philkes/notallyx/presentation/viewmodel/progress/BackupProgress.kt b/app/src/main/java/com/philkes/notallyx/presentation/viewmodel/progress/BackupProgress.kt index b20e93de..be008e9d 100644 --- a/app/src/main/java/com/philkes/notallyx/presentation/viewmodel/progress/BackupProgress.kt +++ b/app/src/main/java/com/philkes/notallyx/presentation/viewmodel/progress/BackupProgress.kt @@ -8,4 +8,5 @@ open class BackupProgress( total: Int = 0, inProgress: Boolean = true, indeterminate: Boolean = false, -) : Progress(R.string.export_backup, current, total, inProgress, indeterminate) + countSuffix: String? = null, +) : Progress(R.string.export_backup, current, total, inProgress, indeterminate, countSuffix) diff --git a/app/src/main/java/com/philkes/notallyx/utils/ErrorActivity.kt b/app/src/main/java/com/philkes/notallyx/utils/ErrorActivity.kt index eccc80df..acc8bee8 100644 --- a/app/src/main/java/com/philkes/notallyx/utils/ErrorActivity.kt +++ b/app/src/main/java/com/philkes/notallyx/utils/ErrorActivity.kt @@ -14,7 +14,7 @@ import com.philkes.notallyx.R.string.auto_backup_failed import com.philkes.notallyx.R.string.crash_export_backup_failed import com.philkes.notallyx.R.string.report_bug import com.philkes.notallyx.databinding.ActivityErrorBinding -import com.philkes.notallyx.presentation.getQuantityString +import com.philkes.notallyx.presentation.exportedText import com.philkes.notallyx.presentation.setCancelButton import com.philkes.notallyx.presentation.setupProgressDialog import com.philkes.notallyx.presentation.showToast @@ -102,7 +102,7 @@ class ErrorActivity : AppCompatActivity() { ) } lifecycleScope.launch(exceptionHandler) { - val exportedNotes = + val exportedNotesAndAttachments = withContext(Dispatchers.IO) { return@withContext application.exportAsZip( uri, @@ -110,11 +110,7 @@ class ErrorActivity : AppCompatActivity() { backupProgress = exportBackupProgress, ) } - val message = - application.getQuantityString( - R.plurals.exported_notes, - exportedNotes, - ) + val message = application.exportedText(exportedNotesAndAttachments) application.showToast(message) } } diff --git a/app/src/main/java/com/philkes/notallyx/utils/backup/ExportExtensions.kt b/app/src/main/java/com/philkes/notallyx/utils/backup/ExportExtensions.kt index d9d8d392..fa808f91 100644 --- a/app/src/main/java/com/philkes/notallyx/utils/backup/ExportExtensions.kt +++ b/app/src/main/java/com/philkes/notallyx/utils/backup/ExportExtensions.kt @@ -39,6 +39,7 @@ import com.philkes.notallyx.data.model.toTxt import com.philkes.notallyx.presentation.activity.LockedActivity import com.philkes.notallyx.presentation.activity.main.MainActivity import com.philkes.notallyx.presentation.activity.main.fragment.settings.SettingsFragment +import com.philkes.notallyx.presentation.getQuantityString import com.philkes.notallyx.presentation.view.misc.Progress import com.philkes.notallyx.presentation.viewmodel.BackupFile import com.philkes.notallyx.presentation.viewmodel.ExportMimeType @@ -314,13 +315,15 @@ fun ContextWrapper.modifiedNoteBackupExists(backupPath: String): Boolean { ?.exists() ?: false } +typealias NotesAndAttachments = Pair + fun ContextWrapper.exportAsZip( fileUri: Uri, compress: Boolean = false, password: String = PASSWORD_EMPTY, backupProgress: MutableLiveData? = null, retryOnFail: Boolean = true, -): Int { +): NotesAndAttachments { backupProgress?.postValue(BackupProgress(indeterminate = true)) val tempFile = createTempFile("export", "tmp", cacheDir) try { @@ -345,7 +348,13 @@ fun ContextWrapper.exportAsZip( val files = databaseOriginal.getBaseNoteDao().getAllFiles().toFileAttachments() val audios = databaseOriginal.getBaseNoteDao().getAllAudios() val totalAttachments = images.count() + files.count() + audios.size - backupProgress?.postValue(BackupProgress(0, totalAttachments)) + backupProgress?.postValue( + BackupProgress( + 0, + totalAttachments, + countSuffix = getQuantityString(R.plurals.attachments, totalAttachments), + ) + ) val counter = AtomicInteger(0) val missingAttachments = ArrayList() @@ -389,7 +398,11 @@ fun ContextWrapper.exportAsZip( log(TAG, throwable = exception) } finally { backupProgress?.postValue( - BackupProgress(counter.incrementAndGet(), totalAttachments) + BackupProgress( + counter.incrementAndGet(), + totalAttachments, + countSuffix = getQuantityString(R.plurals.attachments, totalAttachments), + ) ) } } @@ -442,7 +455,7 @@ fun ContextWrapper.exportAsZip( if (missingAttachments.isNotEmpty()) { postSkippedAttachmentsNotification(missingAttachments) } - return totalNotes + return Pair(totalNotes, totalAttachments) } finally { tempFile.delete() } @@ -566,7 +579,13 @@ private fun Sequence.export( } catch (exception: Exception) { context.log(TAG, throwable = exception) } finally { - backupProgress?.postValue(BackupProgress(counter.incrementAndGet(), total)) + backupProgress?.postValue( + BackupProgress( + counter.incrementAndGet(), + total, + countSuffix = context.getQuantityString(R.plurals.attachments, total), + ) + ) } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e4feed46..708b8dc9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -20,6 +20,10 @@ Ascending Attach file + + Attachment + Attachments + Audio Recordings Auto Backups An error occurred during auto backup:\n\'%1$s\'\nPlease check your settings or report a bug @@ -176,6 +180,7 @@ Failed to export settings, did you choose an invalid path\? All Settings will be exported to a JSON file, which can be used to re-import stored settings.\n\nBe aware, that this does not include encrypted settings like the auto-backup password or the biometric encryption key Successfully exported settings + Exported Exported %1$s Note Exported %1$s Notes @@ -269,6 +274,10 @@ Text too long, truncated to %1$d characters Note is too big to save, it was truncated to %1$s characters (was: %2$s) Notes + + Note + Notes + Notes sorted by %1$s Note is too big to save, it was truncated to %2$s characters diff --git a/app/translations.xlsx b/app/translations.xlsx index 67cf5914..fbd8fcef 100644 Binary files a/app/translations.xlsx and b/app/translations.xlsx differ