From 91c15ac89776750a2ea4a5f1f5d3aa19425efdb7 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Tue, 31 Mar 2020 11:29:33 -0700 Subject: [PATCH] put a date with the filename being exported (#3980) --- .../ImportExportPreferencesFragment.java | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/ImportExportPreferencesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/ImportExportPreferencesFragment.java index 4f0feef47..c8abe0dc5 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/ImportExportPreferencesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/ImportExportPreferencesFragment.java @@ -35,6 +35,8 @@ import io.reactivex.schedulers.Schedulers; import java.io.File; import java.io.FileOutputStream; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.List; public class ImportExportPreferencesFragment extends PreferenceFragmentCompat { @@ -44,16 +46,16 @@ public class ImportExportPreferencesFragment extends PreferenceFragmentCompat { private static final String PREF_HTML_EXPORT = "prefHtmlExport"; private static final String PREF_DATABASE_IMPORT = "prefDatabaseImport"; private static final String PREF_DATABASE_EXPORT = "prefDatabaseExport"; - private static final String DEFAULT_OPML_OUTPUT_NAME = "antennapod-feeds.opml"; + private static final String DEFAULT_OPML_OUTPUT_NAME = "antennapod-feeds-%s.opml"; private static final String CONTENT_TYPE_OPML = "text/x-opml"; - private static final String DEFAULT_HTML_OUTPUT_NAME = "antennapod-feeds.html"; + private static final String DEFAULT_HTML_OUTPUT_NAME = "antennapod-feeds-%s.html"; private static final String CONTENT_TYPE_HTML = "text/html"; private static final int REQUEST_CODE_CHOOSE_OPML_EXPORT_PATH = 1; private static final int REQUEST_CODE_CHOOSE_OPML_IMPORT_PATH = 2; private static final int REQUEST_CODE_CHOOSE_HTML_EXPORT_PATH = 3; private static final int REQUEST_CODE_RESTORE_DATABASE = 4; private static final int REQUEST_CODE_BACKUP_DATABASE = 5; - private static final String DATABASE_EXPORT_FILENAME = "AntennaPodBackup.db"; + private static final String DATABASE_EXPORT_FILENAME = "AntennaPodBackup-%s.db"; private Disposable disposable; private ProgressDialog progressDialog; @@ -80,17 +82,23 @@ public class ImportExportPreferencesFragment extends PreferenceFragmentCompat { } } + private String dateStampFilename(String fname) { + return String.format(fname, + new SimpleDateFormat("yyyy-MM-dd") + .format(new Date())); + } + private void setupStorageScreen() { findPreference(PREF_OPML_EXPORT).setOnPreferenceClickListener( preference -> { - openExportPathPicker(CONTENT_TYPE_OPML, DEFAULT_OPML_OUTPUT_NAME, + openExportPathPicker(CONTENT_TYPE_OPML, dateStampFilename(DEFAULT_OPML_OUTPUT_NAME), REQUEST_CODE_CHOOSE_OPML_EXPORT_PATH, new OpmlWriter()); return true; } ); findPreference(PREF_HTML_EXPORT).setOnPreferenceClickListener( preference -> { - openExportPathPicker(CONTENT_TYPE_HTML, DEFAULT_HTML_OUTPUT_NAME, + openExportPathPicker(CONTENT_TYPE_HTML, dateStampFilename(DEFAULT_HTML_OUTPUT_NAME), REQUEST_CODE_CHOOSE_HTML_EXPORT_PATH, new HtmlWriter()); return true; }); @@ -146,12 +154,12 @@ public class ImportExportPreferencesFragment extends PreferenceFragmentCompat { Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT) .addCategory(Intent.CATEGORY_OPENABLE) .setType("application/x-sqlite3") - .putExtra(Intent.EXTRA_TITLE, DATABASE_EXPORT_FILENAME); + .putExtra(Intent.EXTRA_TITLE, dateStampFilename(DATABASE_EXPORT_FILENAME)); startActivityForResult(intent, REQUEST_CODE_BACKUP_DATABASE); } else { File sd = Environment.getExternalStorageDirectory(); - File backupDB = new File(sd, DATABASE_EXPORT_FILENAME); + File backupDB = new File(sd, dateStampFilename(DATABASE_EXPORT_FILENAME)); progressDialog.show(); disposable = Completable.fromAction(() -> DatabaseExporter.exportToStream(new FileOutputStream(backupDB), getContext()))