some backup fixes

This commit is contained in:
gdlbo
2022-07-13 01:03:04 +03:00
parent 71d4cd09fc
commit 36c244be15
3 changed files with 21 additions and 16 deletions
@@ -11,6 +11,7 @@ import static ru.vtosters.lite.utils.SettBackup.backupOnlines;
import static ru.vtosters.lite.utils.SettBackup.backupSettings;
import static ru.vtosters.lite.utils.SettBackup.deletePrefs;
import static ru.vtosters.lite.utils.SettBackup.restoreBackup;
import static ru.vtosters.lite.utils.Themes.getAlertStyle;
import android.content.ClipData;
import android.content.ClipboardManager;
@@ -75,7 +76,11 @@ public class OtherFragment extends MaterialPreferenceToolbarFragment{
public static class onlines implements Preference.OnPreferenceClickListener{
@Override // android.support.v7.preference.Preference.c
public boolean onPreferenceClick(Preference preference){
backupOnlines();
try {
backupOnlines();
} catch (IOException e) {
e.printStackTrace();
}
return true;
}
}
@@ -171,7 +176,7 @@ public class OtherFragment extends MaterialPreferenceToolbarFragment{
public boolean onPreferenceClick(Preference preference){
var arr = SettBackup.getBackupsNames();
var adapter = new ArrayAdapter(getContext(), android.R.layout.simple_list_item_1, arr);
new AlertDialog.Builder(getContext())
new AlertDialog.Builder(getContext(), getAlertStyle())
.setTitle("Выберите бэкап")
.setAdapter(adapter, (dialog, which) -> {
try {
@@ -39,7 +39,12 @@ public class SettBackup{
file.delete();
}
public static void backupOnlines(){
public static void backupOnlines() throws IOException{
if (getPrefContent("onlines.xml") == null) {
Toast.makeText(getContext(), "Нет данных для резервного копирования", LENGTH_SHORT).show();
return;
}
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault());
var dir = new File(getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS), "/VTLBackups/");
var file = new File(dir, "Onlines_" + dateFormat.format(new Date()) + ".xml");
@@ -58,9 +63,7 @@ public class SettBackup{
public static void backupSettings(){
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd:HH-mm-ss", Locale.getDefault());
var file = new File(sBackupDir,
"Backup_"
+ dateFormat.format(new Date())
+ ".xml");
"Backup_" + dateFormat.format(new Date()) + ".xml");
try {
file.delete();
sBackupDir.mkdirs();