Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -505,7 +506,8 @@ private fun <T : Progress> MutableLiveData<T>.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)
}
}
Expand Down Expand Up @@ -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)})"
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ abstract class Progress(
val total: Int = 0,
val inProgress: Boolean = true,
val indeterminate: Boolean = false,
val countSuffix: String? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
10 changes: 3 additions & 7 deletions app/src/main/java/com/philkes/notallyx/utils/ErrorActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -102,19 +102,15 @@ class ErrorActivity : AppCompatActivity() {
)
}
lifecycleScope.launch(exceptionHandler) {
val exportedNotes =
val exportedNotesAndAttachments =
withContext(Dispatchers.IO) {
return@withContext application.exportAsZip(
uri,
password = preferences.backupPassword.value,
backupProgress = exportBackupProgress,
)
}
val message =
application.getQuantityString(
R.plurals.exported_notes,
exportedNotes,
)
val message = application.exportedText(exportedNotesAndAttachments)
application.showToast(message)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -314,13 +315,15 @@ fun ContextWrapper.modifiedNoteBackupExists(backupPath: String): Boolean {
?.exists() ?: false
}

typealias NotesAndAttachments = Pair<Int, Int>

fun ContextWrapper.exportAsZip(
fileUri: Uri,
compress: Boolean = false,
password: String = PASSWORD_EMPTY,
backupProgress: MutableLiveData<Progress>? = null,
retryOnFail: Boolean = true,
): Int {
): NotesAndAttachments {
backupProgress?.postValue(BackupProgress(indeterminate = true))
val tempFile = createTempFile("export", "tmp", cacheDir)
try {
Expand All @@ -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<String>()
Expand Down Expand Up @@ -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),
)
)
}
}
Expand Down Expand Up @@ -442,7 +455,7 @@ fun ContextWrapper.exportAsZip(
if (missingAttachments.isNotEmpty()) {
postSkippedAttachmentsNotification(missingAttachments)
}
return totalNotes
return Pair(totalNotes, totalAttachments)
} finally {
tempFile.delete()
}
Expand Down Expand Up @@ -566,7 +579,13 @@ private fun Sequence<FileAttachment>.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),
)
)
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
</plurals>
<string name="ascending">Ascending</string>
<string name="attach_file">Attach file</string>
<plurals name="attachments">
<item quantity="one">Attachment</item>
<item quantity="other">Attachments</item>
</plurals>
<string name="audio_recordings">Audio Recordings</string>
<string name="auto_backup">Auto Backups</string>
<string name="auto_backup_error_message">An error occurred during auto backup:\n\'%1$s\'\nPlease check your settings or report a bug</string>
Expand Down Expand Up @@ -176,6 +180,7 @@
<string name="export_settings_failure">Failed to export settings, did you choose an invalid path\?</string>
<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>
<string name="export_settings_success">Successfully exported settings</string>
<string name="exported">Exported</string>
<plurals name="exported_notes">
<item quantity="one">Exported %1$s Note</item>
<item quantity="other">Exported %1$s Notes</item>
Expand Down Expand Up @@ -269,6 +274,10 @@
<string name="note_text_too_long_truncated">Text too long, truncated to %1$d characters</string>
<string name="note_too_big_truncating">Note is too big to save, it was truncated to %1$s characters (was: %2$s)</string>
<string name="notes">Notes</string>
<plurals name="notes">
<item quantity="one">Note</item>
<item quantity="other">Notes</item>
</plurals>
<string name="notes_sorted_by">Notes sorted by</string>
<plurals name="notes_too_big_truncating">
<item quantity="one">%1$s Note is too big to save, it was truncated to %2$s characters</item>
Expand Down
Binary file modified app/translations.xlsx
Binary file not shown.