Add datestamp to backup filename (#1364)

resolve #1188
This commit is contained in:
ottosch 2025-02-26 16:00:25 -03:00 committed by GitHub
parent aaa7fb2ad1
commit f65864a935
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 2 deletions

View file

@ -57,6 +57,9 @@ import java.io.FileInputStream
import java.io.FileOutputStream import java.io.FileOutputStream
import java.io.IOException import java.io.IOException
import java.io.OutputStream import java.io.OutputStream
import java.text.SimpleDateFormat
import java.util.Calendar
import java.util.Locale
import java.util.concurrent.CountDownLatch import java.util.concurrent.CountDownLatch
import java.util.zip.ZipEntry import java.util.zip.ZipEntry
import java.util.zip.ZipInputStream import java.util.zip.ZipInputStream
@ -273,12 +276,13 @@ class AdvancedSettingsFragment : SubScreenFragment() {
.setTitle(R.string.backup_restore_title) .setTitle(R.string.backup_restore_title)
.setMessage(R.string.backup_restore_message) .setMessage(R.string.backup_restore_message)
.setNegativeButton(R.string.button_backup) { _, _ -> .setNegativeButton(R.string.button_backup) { _, _ ->
val currentDate = SimpleDateFormat("yyyyMMdd", Locale.getDefault()).format(Calendar.getInstance().time)
val intent = Intent(Intent.ACTION_CREATE_DOCUMENT) val intent = Intent(Intent.ACTION_CREATE_DOCUMENT)
.addCategory(Intent.CATEGORY_OPENABLE) .addCategory(Intent.CATEGORY_OPENABLE)
.putExtra( .putExtra(
Intent.EXTRA_TITLE, Intent.EXTRA_TITLE,
requireContext().getString(R.string.english_ime_name) requireContext().getString(R.string.english_ime_name)
.replace(" ", "_") + "_backup.zip" .replace(" ", "_") + "_backup_$currentDate.zip"
) )
.setType("application/zip") .setType("application/zip")
backupFilePicker.launch(intent) backupFilePicker.launch(intent)

View file

@ -44,6 +44,9 @@ import kotlinx.serialization.json.Json
import java.io.File import java.io.File
import java.io.FileInputStream import java.io.FileInputStream
import java.io.OutputStream import java.io.OutputStream
import java.text.SimpleDateFormat
import java.util.Calendar
import java.util.Locale
import java.util.concurrent.CountDownLatch import java.util.concurrent.CountDownLatch
import java.util.zip.ZipEntry import java.util.zip.ZipEntry
import java.util.zip.ZipInputStream import java.util.zip.ZipInputStream
@ -192,12 +195,13 @@ fun BackupRestorePreference(setting: Setting) {
restoreLauncher.launch(intent) restoreLauncher.launch(intent)
}, },
onConfirmed = { onConfirmed = {
val currentDate = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(Calendar.getInstance().time)
val intent = Intent(Intent.ACTION_CREATE_DOCUMENT) val intent = Intent(Intent.ACTION_CREATE_DOCUMENT)
.addCategory(Intent.CATEGORY_OPENABLE) .addCategory(Intent.CATEGORY_OPENABLE)
.putExtra( .putExtra(
Intent.EXTRA_TITLE, Intent.EXTRA_TITLE,
ctx.getString(R.string.english_ime_name) ctx.getString(R.string.english_ime_name)
.replace(" ", "_") + "_backup.zip" .replace(" ", "_") + "_backup_$currentDate.zip"
) )
.setType("application/zip") .setType("application/zip")
backupLauncher.launch(intent) backupLauncher.launch(intent)