From 3ddd7f0de9ff0e154fb06acd0a3e4c79f20d8e5f Mon Sep 17 00:00:00 2001 From: Bennett Piater Date: Fri, 21 Jul 2017 16:38:40 +0200 Subject: [PATCH] SettingsExporter.java: add date to exported settings file name --- .../main/java/com/fsck/k9/activity/Accounts.java | 2 +- .../com/fsck/k9/preferences/SettingsExporter.java | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/k9mail/src/main/java/com/fsck/k9/activity/Accounts.java b/k9mail/src/main/java/com/fsck/k9/activity/Accounts.java index ed1943423..8acb19c3c 100644 --- a/k9mail/src/main/java/com/fsck/k9/activity/Accounts.java +++ b/k9mail/src/main/java/com/fsck/k9/activity/Accounts.java @@ -1924,7 +1924,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener { Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT); intent.setType("application/octet-stream"); - intent.putExtra(Intent.EXTRA_TITLE, SettingsExporter.EXPORT_FILENAME); + intent.putExtra(Intent.EXTRA_TITLE, SettingsExporter.generateDatedExportFileName()); intent.addCategory(Intent.CATEGORY_OPENABLE); startActivityForResult(intent, ACTIVITY_REQUEST_SAVE_SETTINGS_FILE); diff --git a/k9mail/src/main/java/com/fsck/k9/preferences/SettingsExporter.java b/k9mail/src/main/java/com/fsck/k9/preferences/SettingsExporter.java index 37130cfa7..8338d90cf 100644 --- a/k9mail/src/main/java/com/fsck/k9/preferences/SettingsExporter.java +++ b/k9mail/src/main/java/com/fsck/k9/preferences/SettingsExporter.java @@ -5,7 +5,9 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Calendar; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -33,7 +35,8 @@ import org.xmlpull.v1.XmlSerializer; public class SettingsExporter { - public static final String EXPORT_FILENAME = "settings.k9s"; + public static final String EXPORT_FILENAME_PREFIX = "k9_settings_export"; + public static final String EXPORT_FILENAME_SUFFIX = "k9s"; /** * File format version number. @@ -87,7 +90,7 @@ public class SettingsExporter { Timber.d("Unable to create directory: %s", dir.getAbsolutePath()); } - File file = FileHelper.createUniqueFile(dir, EXPORT_FILENAME); + File file = FileHelper.createUniqueFile(dir, generateDatedExportFileName()); String filename = file.getAbsolutePath(); os = new FileOutputStream(filename); @@ -533,4 +536,11 @@ public class SettingsExporter { } serializer.endTag(null, VALUE_ELEMENT); } + + public static String generateDatedExportFileName() { + Calendar now = Calendar.getInstance(); + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + + return String.format("%s_%s.%s", EXPORT_FILENAME_PREFIX, dateFormat.format(now.getTime()), EXPORT_FILENAME_SUFFIX); + } }