mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-12-23 05:16:58 +00:00
option to disable auto backup; close #1433
This commit is contained in:
parent
15e5d39f6b
commit
7345ecefd0
@ -17,7 +17,9 @@
|
||||
<application
|
||||
android:name=".InstaGrabberApplication"
|
||||
android:allowBackup="true"
|
||||
android:backupAgent=".backup.BarinstaBackupAgent"
|
||||
android:fullBackupContent="@xml/backup_descriptor"
|
||||
android:fullBackupOnly="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:supportsRtl="true"
|
||||
|
@ -0,0 +1,24 @@
|
||||
package awais.instagrabber.backup
|
||||
|
||||
import android.app.backup.BackupAgent
|
||||
import android.app.backup.BackupDataInput
|
||||
import android.app.backup.BackupDataOutput
|
||||
import android.app.backup.FullBackupDataOutput
|
||||
import android.os.ParcelFileDescriptor
|
||||
import awais.instagrabber.fragments.settings.PreferenceKeys
|
||||
import awais.instagrabber.utils.Utils.settingsHelper
|
||||
|
||||
class BarinstaBackupAgent : BackupAgent() {
|
||||
override fun onFullBackup(data: FullBackupDataOutput?) {
|
||||
if (data != null && settingsHelper.getBoolean(PreferenceKeys.PREF_AUTO_BACKUP_ENABLED)) {
|
||||
super.onFullBackup(data)
|
||||
}
|
||||
}
|
||||
|
||||
// no key-value backups
|
||||
override fun onBackup(oldState: ParcelFileDescriptor?,
|
||||
data: BackupDataOutput?, newState: ParcelFileDescriptor?) {}
|
||||
|
||||
override fun onRestore(data: BackupDataInput, appVersionCode: Int,
|
||||
newState: ParcelFileDescriptor) {}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package awais.instagrabber.fragments.settings;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
@ -9,7 +10,9 @@ import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
import androidx.preference.SwitchPreferenceCompat;
|
||||
|
||||
import com.google.android.material.snackbar.BaseTransientBottomBar;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
@ -26,30 +29,51 @@ public class BackupPreferencesFragment extends BasePreferencesFragment {
|
||||
if (context == null) {
|
||||
return;
|
||||
}
|
||||
screen.addPreference(getAboutPreference(context));
|
||||
screen.addPreference(getWarningPreference(context));
|
||||
screen.addPreference(getCreatePreference(context));
|
||||
screen.addPreference(getRestorePreference(context));
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
final PreferenceCategory autoCategory = new PreferenceCategory(context);
|
||||
screen.addPreference(autoCategory);
|
||||
autoCategory.setTitle(R.string.auto_backup);
|
||||
autoCategory.addPreference(getAboutPreference(context, true));
|
||||
autoCategory.addPreference(getWarningPreference(context, true));
|
||||
autoCategory.addPreference(getAutoBackupPreference(context));
|
||||
}
|
||||
final PreferenceCategory manualCategory = new PreferenceCategory(context);
|
||||
screen.addPreference(manualCategory);
|
||||
manualCategory.setTitle(R.string.manual_backup);
|
||||
manualCategory.addPreference(getAboutPreference(context, false));
|
||||
manualCategory.addPreference(getWarningPreference(context, false));
|
||||
manualCategory.addPreference(getCreatePreference(context));
|
||||
manualCategory.addPreference(getRestorePreference(context));
|
||||
}
|
||||
|
||||
private Preference getAboutPreference(@NonNull final Context context) {
|
||||
private Preference getAboutPreference(@NonNull final Context context,
|
||||
@NonNull final boolean auto) {
|
||||
final Preference preference = new Preference(context);
|
||||
preference.setSummary(R.string.backup_summary);
|
||||
preference.setSummary(auto ? R.string.auto_backup_summary : R.string.backup_summary);
|
||||
preference.setEnabled(false);
|
||||
preference.setIcon(R.drawable.ic_outline_info_24);
|
||||
preference.setIconSpaceReserved(true);
|
||||
return preference;
|
||||
}
|
||||
|
||||
private Preference getWarningPreference(@NonNull final Context context) {
|
||||
private Preference getWarningPreference(@NonNull final Context context,
|
||||
@NonNull final boolean auto) {
|
||||
final Preference preference = new Preference(context);
|
||||
preference.setSummary(R.string.backup_warning);
|
||||
preference.setSummary(auto ? R.string.auto_backup_warning : R.string.backup_warning);
|
||||
preference.setEnabled(false);
|
||||
preference.setIcon(R.drawable.ic_warning);
|
||||
preference.setIconSpaceReserved(true);
|
||||
return preference;
|
||||
}
|
||||
|
||||
private Preference getAutoBackupPreference(@NonNull final Context context) {
|
||||
final SwitchPreferenceCompat preference = new SwitchPreferenceCompat(context);
|
||||
preference.setKey(PreferenceKeys.PREF_AUTO_BACKUP_ENABLED);
|
||||
preference.setTitle(R.string.auto_backup_setting);
|
||||
preference.setIconSpaceReserved(false);
|
||||
return preference;
|
||||
}
|
||||
|
||||
private Preference getCreatePreference(@NonNull final Context context) {
|
||||
final Preference preference = new Preference(context);
|
||||
preference.setTitle(R.string.create_backup);
|
||||
|
@ -10,6 +10,7 @@ object PreferenceKeys {
|
||||
const val PREF_TAB_ORDER = "tab_order"
|
||||
const val PREF_SHOWN_COUNT_TOOLTIP = "shown_count_tooltip"
|
||||
const val PREF_SEARCH_FOCUS_KEYBOARD = "search_focus_keyboard"
|
||||
const val PREF_AUTO_BACKUP_ENABLED = "auto_backup_enabled"
|
||||
|
||||
// string prefs
|
||||
const val FOLDER_PATH = "custom_path"
|
||||
|
@ -38,19 +38,19 @@ class SettingsHelper(context: Context) {
|
||||
}
|
||||
|
||||
private fun getStringDefault(@StringSettings key: String): String {
|
||||
if (DATE_TIME_FORMAT == key) return "hh:mm:ss a 'on' dd-MM-yyyy"
|
||||
return if (DATE_TIME_SELECTION == key) "0;3;0" else ""
|
||||
if (PreferenceKeys.DATE_TIME_FORMAT == key) return "hh:mm:ss a 'on' dd-MM-yyyy"
|
||||
return if (PreferenceKeys.DATE_TIME_SELECTION == key) "0;3;0" else ""
|
||||
}
|
||||
|
||||
private fun getIntegerDefault(@IntegerSettings key: String): Int {
|
||||
if (APP_THEME == key) return getThemeCode(true)
|
||||
return if (PREV_INSTALL_VERSION == key || APP_UA_CODE == key || BROWSER_UA_CODE == key) -1 else 0
|
||||
if (PreferenceKeys.APP_THEME == key) return getThemeCode(true)
|
||||
return if (Constants.PREV_INSTALL_VERSION == key || Constants.APP_UA_CODE == key || Constants.BROWSER_UA_CODE == key) -1 else 0
|
||||
}
|
||||
|
||||
fun getThemeCode(fromHelper: Boolean): Int {
|
||||
var themeCode = AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
||||
if (!fromHelper && sharedPreferences != null) {
|
||||
themeCode = sharedPreferences.getString(APP_THEME, themeCode.toString())!!.toInt()
|
||||
themeCode = sharedPreferences.getString(PreferenceKeys.APP_THEME, themeCode.toString())!!.toInt()
|
||||
when (themeCode) {
|
||||
1 -> themeCode = AppCompatDelegate.MODE_NIGHT_AUTO_BATTERY
|
||||
3 -> themeCode = AppCompatDelegate.MODE_NIGHT_NO
|
||||
@ -136,7 +136,7 @@ class SettingsHelper(context: Context) {
|
||||
PreferenceKeys.PLAY_IN_BACKGROUND,
|
||||
PreferenceKeys.PREF_SHOWN_COUNT_TOOLTIP,
|
||||
PreferenceKeys.PREF_SEARCH_FOCUS_KEYBOARD,
|
||||
PreferenceKeys.PREF_AUTO_BACKUP_DISABLED
|
||||
PreferenceKeys.PREF_AUTO_BACKUP_ENABLED
|
||||
)
|
||||
annotation class BooleanSettings
|
||||
|
||||
|
@ -303,6 +303,11 @@
|
||||
<string name="unknown">Unknown</string>
|
||||
<string name="removed_from_favs">Removed from Favourites!</string>
|
||||
<string name="backup_and_restore">Backup & Restore</string>
|
||||
<string name="auto_backup">Auto Backup</string>
|
||||
<string name="auto_backup_summary">Starting from Android 6, Android\'s Auto Backup feature will upload all app settings, account login data, and favorites onto your Google Drive, which can be restored by reinstalling the app after uninstallation.</string>
|
||||
<string name="auto_backup_warning">This preference has no effect if Google Play Services is not present, or if Auto Backup is disabled from your device settings. Disabling here does not erase existing backups.</string>
|
||||
<string name="auto_backup_setting">Enable Auto Backup</string>
|
||||
<string name="manual_backup">Manual Backup</string>
|
||||
<string name="backup_summary">Backup Barinsta app settings, account login data, and/or favorites to a plain text or encrypted backup file for later restoration.</string>
|
||||
<string name="backup_warning">If you\'re backing up account login data, treat the file as confidential and keep it somewhere safe!</string>
|
||||
<string name="create_backup">Create new backup file</string>
|
||||
|
@ -1,3 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<full-backup-content>
|
||||
|
||||
</full-backup-content>
|
||||
|
Loading…
Reference in New Issue
Block a user