put a date with the filename being exported (#3980)

This commit is contained in:
Tony Tam 2020-03-31 11:29:33 -07:00 committed by GitHub
parent b195e32c04
commit 91c15ac897
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 7 deletions

View File

@ -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()))