SettingsExporter.java: add date to exported settings file name

This commit is contained in:
Bennett Piater 2017-07-21 16:38:40 +02:00
parent 72af527db0
commit 3ddd7f0de9
No known key found for this signature in database
GPG key ID: 26C7E577EF967808
2 changed files with 13 additions and 3 deletions

View file

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

View file

@ -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);
}
}