diff --git a/app/src/main/java/com/beemdevelopment/aegis/BackupsVersioningStrategy.java b/app/src/main/java/com/beemdevelopment/aegis/BackupsVersioningStrategy.java new file mode 100644 index 000000000..0e06954f5 --- /dev/null +++ b/app/src/main/java/com/beemdevelopment/aegis/BackupsVersioningStrategy.java @@ -0,0 +1,7 @@ +package com.beemdevelopment.aegis; + +public enum BackupsVersioningStrategy { + UNDEFINED, + MULTIPLE_BACKUPS, + SINGLE_BACKUP +} \ No newline at end of file diff --git a/app/src/main/java/com/beemdevelopment/aegis/Preferences.java b/app/src/main/java/com/beemdevelopment/aegis/Preferences.java index 5b4041ab5..d9e160fdb 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/Preferences.java +++ b/app/src/main/java/com/beemdevelopment/aegis/Preferences.java @@ -6,6 +6,7 @@ import android.net.Uri; import android.os.Build; +import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.preference.PreferenceManager; @@ -597,6 +598,33 @@ public Set getGroupFilter() { } } + @NonNull + public BackupsVersioningStrategy getBackupVersioningStrategy() { + Uri uri = getBackupsLocation(); + if (uri == null) { + return BackupsVersioningStrategy.UNDEFINED; + } + String path = uri.getPath(); + if (path == null) { + return BackupsVersioningStrategy.UNDEFINED; + } + String[] pathArray = path.split("/"); + if (pathArray.length < 2) { + return BackupsVersioningStrategy.UNDEFINED; + } + String type = pathArray[1]; + if (type.equals("tree")) { + return BackupsVersioningStrategy.MULTIPLE_BACKUPS; + } else if (type.equals("document")) { + return BackupsVersioningStrategy.SINGLE_BACKUP; + } + return BackupsVersioningStrategy.UNDEFINED; + } + + public boolean isSingleBackupEnabled() { + return getBackupVersioningStrategy() == BackupsVersioningStrategy.SINGLE_BACKUP; + } + public static class BackupResult { private final Date _time; private boolean _isBuiltIn; diff --git a/app/src/main/java/com/beemdevelopment/aegis/ui/dialogs/Dialogs.java b/app/src/main/java/com/beemdevelopment/aegis/ui/dialogs/Dialogs.java index 2a76f0832..692ba3a54 100644 --- a/app/src/main/java/com/beemdevelopment/aegis/ui/dialogs/Dialogs.java +++ b/app/src/main/java/com/beemdevelopment/aegis/ui/dialogs/Dialogs.java @@ -19,6 +19,8 @@ import android.widget.ListView; import android.widget.NumberPicker; import android.widget.ProgressBar; +import android.widget.RadioButton; +import android.widget.RadioGroup; import android.widget.TextView; import android.widget.Toast; @@ -27,6 +29,7 @@ import androidx.annotation.StringRes; import androidx.appcompat.app.AlertDialog; +import com.beemdevelopment.aegis.BackupsVersioningStrategy; import com.beemdevelopment.aegis.Preferences; import com.beemdevelopment.aegis.R; import com.beemdevelopment.aegis.helpers.EditTextHelper; @@ -577,6 +580,54 @@ public static void showPartialGoogleAuthImportWarningDialog(Context context, Lis showSecureDialog(dialog); } + public static void showBackupsVersioningStrategy(Context context, BackupsVersioningStrategy currentStrategy, BackupsVersioningStrategyListener listener) { + View view = LayoutInflater.from(context).inflate(R.layout.dialog_backups_versioning_strategy, null); + RadioGroup radioGroup = view.findViewById(R.id.radio_group); + RadioButton keepXVersionsButton = view.findViewById(R.id.keep_x_versions_button); + RadioButton singleBackupButton = view.findViewById(R.id.single_backup_button); + TextView warningText = view.findViewById(R.id.warning_text); + CheckBox riskAccept = view.findViewById(R.id.risk_accept); + final AtomicReference