Skip to content

Commit d0ecce9

Browse files
authored
Show amount attachments and notes on export (#973)
1 parent 3f49d4b commit d0ecce9

8 files changed

Lines changed: 49 additions & 17 deletions

File tree

app/src/main/java/com/philkes/notallyx/presentation/UiExtensions.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ import com.philkes.notallyx.presentation.viewmodel.BaseNoteModel
112112
import com.philkes.notallyx.presentation.viewmodel.preference.DateFormat
113113
import com.philkes.notallyx.presentation.viewmodel.preference.TimeFormat
114114
import com.philkes.notallyx.presentation.viewmodel.preference.displayBodySize
115+
import com.philkes.notallyx.utils.backup.NotesAndAttachments
115116
import com.philkes.notallyx.utils.changehistory.ChangeHistory
116117
import com.philkes.notallyx.utils.changehistory.EditTextState
117118
import com.philkes.notallyx.utils.changehistory.EditTextWithHistoryChange
@@ -505,7 +506,8 @@ private fun <T : Progress> MutableLiveData<T>.setupProgressDialog(
505506
}
506507
if (renderProgress == null) {
507508
Count.text =
508-
context.getString(R.string.count, progress.current, progress.total)
509+
context.getString(R.string.count, progress.current, progress.total) +
510+
(progress.countSuffix?.let { " $it" } ?: "")
509511
} else renderProgress.invoke(context, this, progress)
510512
}
511513
}
@@ -1186,3 +1188,6 @@ fun Chip.setupReminderChip(
11861188
else paintFlags and Paint.STRIKE_THRU_TEXT_FLAG.inv()
11871189
}
11881190
}
1191+
1192+
fun Context.exportedText(notesAndAttachments: NotesAndAttachments) =
1193+
"${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)})"

app/src/main/java/com/philkes/notallyx/presentation/view/misc/Progress.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ abstract class Progress(
66
val total: Int = 0,
77
val inProgress: Boolean = true,
88
val indeterminate: Boolean = false,
9+
val countSuffix: String? = null,
910
)

app/src/main/java/com/philkes/notallyx/presentation/viewmodel/BaseNoteModel.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import com.philkes.notallyx.data.model.SearchResult
4545
import com.philkes.notallyx.data.model.deepCopy
4646
import com.philkes.notallyx.presentation.activity.main.fragment.settings.SettingsFragment.Companion.EXTRA_SHOW_IMPORT_BACKUPS_FOLDER
4747
import com.philkes.notallyx.presentation.activity.note.refreshStatusBarPin
48+
import com.philkes.notallyx.presentation.exportedText
4849
import com.philkes.notallyx.presentation.getQuantityString
4950
import com.philkes.notallyx.presentation.restartApplication
5051
import com.philkes.notallyx.presentation.setCancelButton
@@ -410,7 +411,7 @@ class BaseNoteModel(private val app: Application) : AndroidViewModel(app) {
410411

411412
fun exportBackup(uri: Uri, onComplete: (() -> Unit)? = null) {
412413
viewModelScope.launch {
413-
val exportedNotes =
414+
val exportedNotesAndAttachments =
414415
withContext(Dispatchers.IO) {
415416
app.log(TAG, msg = "Exporting backup to '$uri'...")
416417
return@withContext app.exportAsZip(
@@ -420,8 +421,8 @@ class BaseNoteModel(private val app: Application) : AndroidViewModel(app) {
420421
)
421422
.also { app.log(TAG, msg = "Finished exporting backup to '$uri'") }
422423
}
423-
val message = app.getQuantityString(R.plurals.exported_notes, exportedNotes)
424-
app.showToast(message)
424+
425+
app.showToast(app.exportedText(exportedNotesAndAttachments))
425426
onComplete?.invoke()
426427
}
427428
}

app/src/main/java/com/philkes/notallyx/presentation/viewmodel/progress/BackupProgress.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ open class BackupProgress(
88
total: Int = 0,
99
inProgress: Boolean = true,
1010
indeterminate: Boolean = false,
11-
) : Progress(R.string.export_backup, current, total, inProgress, indeterminate)
11+
countSuffix: String? = null,
12+
) : Progress(R.string.export_backup, current, total, inProgress, indeterminate, countSuffix)

app/src/main/java/com/philkes/notallyx/utils/ErrorActivity.kt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import com.philkes.notallyx.R.string.auto_backup_failed
1414
import com.philkes.notallyx.R.string.crash_export_backup_failed
1515
import com.philkes.notallyx.R.string.report_bug
1616
import com.philkes.notallyx.databinding.ActivityErrorBinding
17-
import com.philkes.notallyx.presentation.getQuantityString
17+
import com.philkes.notallyx.presentation.exportedText
1818
import com.philkes.notallyx.presentation.setCancelButton
1919
import com.philkes.notallyx.presentation.setupProgressDialog
2020
import com.philkes.notallyx.presentation.showToast
@@ -102,19 +102,15 @@ class ErrorActivity : AppCompatActivity() {
102102
)
103103
}
104104
lifecycleScope.launch(exceptionHandler) {
105-
val exportedNotes =
105+
val exportedNotesAndAttachments =
106106
withContext(Dispatchers.IO) {
107107
return@withContext application.exportAsZip(
108108
uri,
109109
password = preferences.backupPassword.value,
110110
backupProgress = exportBackupProgress,
111111
)
112112
}
113-
val message =
114-
application.getQuantityString(
115-
R.plurals.exported_notes,
116-
exportedNotes,
117-
)
113+
val message = application.exportedText(exportedNotesAndAttachments)
118114
application.showToast(message)
119115
}
120116
}

app/src/main/java/com/philkes/notallyx/utils/backup/ExportExtensions.kt

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import com.philkes.notallyx.data.model.toTxt
3939
import com.philkes.notallyx.presentation.activity.LockedActivity
4040
import com.philkes.notallyx.presentation.activity.main.MainActivity
4141
import com.philkes.notallyx.presentation.activity.main.fragment.settings.SettingsFragment
42+
import com.philkes.notallyx.presentation.getQuantityString
4243
import com.philkes.notallyx.presentation.view.misc.Progress
4344
import com.philkes.notallyx.presentation.viewmodel.BackupFile
4445
import com.philkes.notallyx.presentation.viewmodel.ExportMimeType
@@ -314,13 +315,15 @@ fun ContextWrapper.modifiedNoteBackupExists(backupPath: String): Boolean {
314315
?.exists() ?: false
315316
}
316317

318+
typealias NotesAndAttachments = Pair<Int, Int>
319+
317320
fun ContextWrapper.exportAsZip(
318321
fileUri: Uri,
319322
compress: Boolean = false,
320323
password: String = PASSWORD_EMPTY,
321324
backupProgress: MutableLiveData<Progress>? = null,
322325
retryOnFail: Boolean = true,
323-
): Int {
326+
): NotesAndAttachments {
324327
backupProgress?.postValue(BackupProgress(indeterminate = true))
325328
val tempFile = createTempFile("export", "tmp", cacheDir)
326329
try {
@@ -345,7 +348,13 @@ fun ContextWrapper.exportAsZip(
345348
val files = databaseOriginal.getBaseNoteDao().getAllFiles().toFileAttachments()
346349
val audios = databaseOriginal.getBaseNoteDao().getAllAudios()
347350
val totalAttachments = images.count() + files.count() + audios.size
348-
backupProgress?.postValue(BackupProgress(0, totalAttachments))
351+
backupProgress?.postValue(
352+
BackupProgress(
353+
0,
354+
totalAttachments,
355+
countSuffix = getQuantityString(R.plurals.attachments, totalAttachments),
356+
)
357+
)
349358

350359
val counter = AtomicInteger(0)
351360
val missingAttachments = ArrayList<String>()
@@ -389,7 +398,11 @@ fun ContextWrapper.exportAsZip(
389398
log(TAG, throwable = exception)
390399
} finally {
391400
backupProgress?.postValue(
392-
BackupProgress(counter.incrementAndGet(), totalAttachments)
401+
BackupProgress(
402+
counter.incrementAndGet(),
403+
totalAttachments,
404+
countSuffix = getQuantityString(R.plurals.attachments, totalAttachments),
405+
)
393406
)
394407
}
395408
}
@@ -442,7 +455,7 @@ fun ContextWrapper.exportAsZip(
442455
if (missingAttachments.isNotEmpty()) {
443456
postSkippedAttachmentsNotification(missingAttachments)
444457
}
445-
return totalNotes
458+
return Pair(totalNotes, totalAttachments)
446459
} finally {
447460
tempFile.delete()
448461
}
@@ -566,7 +579,13 @@ private fun Sequence<FileAttachment>.export(
566579
} catch (exception: Exception) {
567580
context.log(TAG, throwable = exception)
568581
} finally {
569-
backupProgress?.postValue(BackupProgress(counter.incrementAndGet(), total))
582+
backupProgress?.postValue(
583+
BackupProgress(
584+
counter.incrementAndGet(),
585+
total,
586+
countSuffix = context.getQuantityString(R.plurals.attachments, total),
587+
)
588+
)
570589
}
571590
}
572591
}

app/src/main/res/values/strings.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
</plurals>
2121
<string name="ascending">Ascending</string>
2222
<string name="attach_file">Attach file</string>
23+
<plurals name="attachments">
24+
<item quantity="one">Attachment</item>
25+
<item quantity="other">Attachments</item>
26+
</plurals>
2327
<string name="audio_recordings">Audio Recordings</string>
2428
<string name="auto_backup">Auto Backups</string>
2529
<string name="auto_backup_error_message">An error occurred during auto backup:\n\'%1$s\'\nPlease check your settings or report a bug</string>
@@ -176,6 +180,7 @@
176180
<string name="export_settings_failure">Failed to export settings, did you choose an invalid path\?</string>
177181
<string name="export_settings_message">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</string>
178182
<string name="export_settings_success">Successfully exported settings</string>
183+
<string name="exported">Exported</string>
179184
<plurals name="exported_notes">
180185
<item quantity="one">Exported %1$s Note</item>
181186
<item quantity="other">Exported %1$s Notes</item>
@@ -269,6 +274,10 @@
269274
<string name="note_text_too_long_truncated">Text too long, truncated to %1$d characters</string>
270275
<string name="note_too_big_truncating">Note is too big to save, it was truncated to %1$s characters (was: %2$s)</string>
271276
<string name="notes">Notes</string>
277+
<plurals name="notes">
278+
<item quantity="one">Note</item>
279+
<item quantity="other">Notes</item>
280+
</plurals>
272281
<string name="notes_sorted_by">Notes sorted by</string>
273282
<plurals name="notes_too_big_truncating">
274283
<item quantity="one">%1$s Note is too big to save, it was truncated to %2$s characters</item>

app/translations.xlsx

4.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)