SettingsExporter.java: add date to exported settings file name
This commit is contained in:
parent
72af527db0
commit
3ddd7f0de9
2 changed files with 13 additions and 3 deletions
|
@ -1924,7 +1924,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener {
|
||||||
|
|
||||||
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
|
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
|
||||||
intent.setType("application/octet-stream");
|
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);
|
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||||
|
|
||||||
startActivityForResult(intent, ACTIVITY_REQUEST_SAVE_SETTINGS_FILE);
|
startActivityForResult(intent, ACTIVITY_REQUEST_SAVE_SETTINGS_FILE);
|
||||||
|
|
|
@ -5,7 +5,9 @@ import java.io.File;
|
||||||
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.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -33,7 +35,8 @@ import org.xmlpull.v1.XmlSerializer;
|
||||||
|
|
||||||
|
|
||||||
public class SettingsExporter {
|
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.
|
* File format version number.
|
||||||
|
@ -87,7 +90,7 @@ public class SettingsExporter {
|
||||||
Timber.d("Unable to create directory: %s", dir.getAbsolutePath());
|
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();
|
String filename = file.getAbsolutePath();
|
||||||
os = new FileOutputStream(filename);
|
os = new FileOutputStream(filename);
|
||||||
|
|
||||||
|
@ -533,4 +536,11 @@ public class SettingsExporter {
|
||||||
}
|
}
|
||||||
serializer.endTag(null, VALUE_ELEMENT);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue