This commit is contained in:
gdlbo
2022-04-28 20:57:57 +03:00
parent d9896257c5
commit 319d657ab4
5 changed files with 45 additions and 11 deletions
@@ -2,6 +2,7 @@ package ru.vtosters.lite.ui.fragments;
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 android.content.ClipData;
import android.content.ClipboardManager;
@@ -143,6 +144,17 @@ public class OtherFragment extends MaterialPreferenceToolbarFragment {
}
}
public class restoreprefs implements Preference.c {
@Override // android.support.v7.preference.Preference.c
public boolean a(Preference preference) {
restoreBackup();
return true;
}
restoreprefs() {
}
}
private void prefs() {
a("firebasefix").a((Preference.c) new a());
a("applicationstop").a((Preference.c) new b());
@@ -150,8 +162,9 @@ public class OtherFragment extends MaterialPreferenceToolbarFragment {
a("applicationrestart").a((Preference.c) new d());
a("clearcache").a((Preference.c) new e());
a("stickfix").a((Preference.c) new f());
a("saveprefs").a((Preference.c) new saveprefs());
a("deleteprefs").a((Preference.c) new deleteprefs());
// a("saveprefs").a((Preference.c) new saveprefs());
// a("restoreprefs").a((Preference.c) new restoreprefs());
}
}
@@ -1,7 +1,17 @@
package ru.vtosters.lite.utils;
import static android.app.Activity.RESULT_OK;
import static android.os.Environment.*;
import static android.widget.Toast.*;
import static androidx.core.app.ActivityCompat.startActivityForResult;
import static ru.vtosters.lite.utils.Helper.*;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Environment;
import android.util.Base64;
import android.widget.Toast;
@@ -15,18 +25,18 @@ import java.util.Locale;
import java.util.Map;
public class SettBackup {
static SharedPreferences prefs = Helper.GetContext().getSharedPreferences("com.vtosters.lite_preferences", Context.MODE_PRIVATE);
static SharedPreferences prefs = GetContext().getSharedPreferences("com.vtosters.lite_preferences", Context.MODE_PRIVATE);
public static void deletePrefs() {
prefs.edit().clear().commit();
File file = new File(new File(Helper.GetContext().getFilesDir().getParent(), "shared_prefs"), "com.vtosters.lite_preferences");
File file = new File(new File(GetContext().getFilesDir().getParent(), "shared_prefs"), "com.vtosters.lite_preferences");
if (file.exists()) file.delete();
}
public static void backupSettings() {
SimpleDateFormat date = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault());
String currentDateandTime = date.format(new Date());
var directory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/VTLBackup_" + currentDateandTime + ".txt";
var directory = getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS) + "/VTLBackup_" + currentDateandTime + ".txt";
var file = new File(directory);
try {
var exists = file.createNewFile();
@@ -39,15 +49,15 @@ public class SettBackup {
FileWriter out = new FileWriter(file);
out.write(getAllPrefs());
out.close();
Toast.makeText(Helper.GetContext(), "Сохранено в файл " + directory, Toast.LENGTH_LONG).show();
makeText(GetContext(), "Сохранено в файл " + directory, LENGTH_LONG).show();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(Helper.GetContext(), "Не удалось сохранить файл", Toast.LENGTH_SHORT).show();
makeText(GetContext(), "Не удалось сохранить файл", LENGTH_SHORT).show();
}
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(Helper.GetContext(), "Не удалось сохранить файл", Toast.LENGTH_SHORT).show();
makeText(GetContext(), "Не удалось сохранить файл", LENGTH_SHORT).show();
}
}
@@ -57,5 +67,9 @@ public class SettBackup {
}
public static void restoreBackup() {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.setType("text/plain");
GetContext().startActivity(intent);
}
}
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:orientation="horizontal"
android:id="@id/picker_attach_gallery_camera_layout"
android:background="#ffffffff"
android:background="?tabbar_background"
android:layout_width="fill_parent"
android:layout_height="56.0dip"
xmlns:android="http://schemas.android.com/apk/res/android"
+1
View File
@@ -4,6 +4,7 @@
<com.vtosters.lite.ui.MaterialSwitchPreference
android:defaultValue="true"
android:key="calls"
android:summary="Иконка звонков в сообщениях"
android:title="@string/vtlcalls" />
<com.vtosters.lite.ui.MaterialSwitchPreference
android:defaultValue="true"
+8 -2
View File
@@ -16,6 +16,9 @@
android:key="stickfix"
android:title="Очистить кэш стикеров"
android:summary="Исправление загрузки стикеров при их полном отсутствии" />
<Preference
android:key="deleteprefs"
android:title="Сбросить настройки" />
<Preference
android:key="applicationrestart"
android:title="@string/applicationrestart" />
@@ -24,15 +27,18 @@
android:title="@string/killappbtn" />
<com.vtosters.lite.ui.MaterialSectionDividerPreference />
</PreferenceCategory>
<PreferenceCategory android:title="Backup system">
<!-- <PreferenceCategory android:title="Backup system">
<Preference
android:key="deleteprefs"
android:title="Reset prefs" />
<Preference
android:key="saveprefs"
android:title="Save prefs to file" />
<Preference
android:key="restoreprefs"
android:title="Restore prefs" />
<com.vtosters.lite.ui.MaterialSectionDividerPreference />
</PreferenceCategory>
</PreferenceCategory> -->
<PreferenceCategory android:title="@string/vtverify">
<Preference
android:enabled="false"