Backup restore success dialog
This commit is contained in:
parent
2e88d021bb
commit
9265a2f0ff
@ -2,7 +2,6 @@ package com.cringe_studios.cringe_authenticator;
|
|||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -330,7 +329,7 @@ public class MainActivity extends BaseActivity {
|
|||||||
lockOnStop = true;
|
lockOnStop = true;
|
||||||
callback.accept(uri);
|
callback.accept(uri);
|
||||||
};
|
};
|
||||||
pickBackupFileLoad.launch(new String[]{"application/json"});
|
pickBackupFileLoad.launch(new String[]{"application/json", "*/*"});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -342,7 +341,6 @@ public class MainActivity extends BaseActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
Log.d("STOP", lockOnStop+"");
|
|
||||||
if(lockOnStop) OTPDatabase.unloadDatabase();
|
if(lockOnStop) OTPDatabase.unloadDatabase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,27 +267,32 @@ public class SettingsFragment extends NamedFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadBackup(Uri uri) {
|
private void loadBackup(Uri uri) {
|
||||||
OTPDatabase.promptLoadDatabase(requireActivity(), () -> {
|
DialogUtil.showYesNo(requireContext(), R.string.load_backup_title, R.string.backup_load_message, () -> {
|
||||||
if(SettingsUtil.isDatabaseEncrypted(requireContext())) {
|
OTPDatabase.promptLoadDatabase(requireActivity(), () -> {
|
||||||
try {
|
if(SettingsUtil.isDatabaseEncrypted(requireContext())) {
|
||||||
SecretKey key = OTPDatabase.getLoadedKey();
|
try {
|
||||||
CryptoParameters parameters = SettingsUtil.getCryptoParameters(requireContext());
|
SecretKey key = OTPDatabase.getLoadedKey();
|
||||||
loadBackup(uri, key, parameters);
|
CryptoParameters parameters = SettingsUtil.getCryptoParameters(requireContext());
|
||||||
} catch (CryptoException ignored) { // Load with password
|
loadBackup(uri, key, parameters);
|
||||||
} catch (BackupException | OTPDatabaseException e) {
|
return;
|
||||||
DialogUtil.showErrorDialog(requireContext(), "Failed to load backup", e);
|
} catch (CryptoException ignored) { // Load with password
|
||||||
return;
|
} catch (BackupException | OTPDatabaseException e) {
|
||||||
|
DialogUtil.showErrorDialog(requireContext(), "Failed to load backup", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
DialogUtil.showInputPasswordDialog(requireContext(), password -> {
|
DialogUtil.showInputPasswordDialog(requireContext(), password -> {
|
||||||
try {
|
try {
|
||||||
CryptoParameters parameters = BackupUtil.loadParametersFromBackup(requireContext(), uri);
|
CryptoParameters parameters = BackupUtil.loadParametersFromBackup(requireContext(), uri);
|
||||||
SecretKey key = Crypto.generateKey(parameters, password);
|
SecretKey key = Crypto.generateKey(parameters, password);
|
||||||
loadBackup(uri, key, parameters);
|
loadBackup(uri, key, parameters);
|
||||||
} catch (BackupException | OTPDatabaseException | CryptoException e2) {
|
} catch (CryptoException e) {
|
||||||
DialogUtil.showErrorDialog(requireContext(), "Failed to load backup", e2);
|
DialogUtil.showErrorDialog(requireContext(), "Failed to load backup. Make sure the password is valid", e);
|
||||||
}
|
} catch (BackupException | OTPDatabaseException e) {
|
||||||
|
DialogUtil.showErrorDialog(requireContext(), "Failed to load backup", e);
|
||||||
|
}
|
||||||
|
}, null);
|
||||||
}, null);
|
}, null);
|
||||||
}, null);
|
}, null);
|
||||||
}
|
}
|
||||||
@ -302,6 +307,8 @@ public class SettingsFragment extends NamedFragment {
|
|||||||
SettingsUtil.restoreGroups(requireContext(), data.getGroups());
|
SettingsUtil.restoreGroups(requireContext(), data.getGroups());
|
||||||
OTPDatabase.setLoadedDatabase(db);
|
OTPDatabase.setLoadedDatabase(db);
|
||||||
OTPDatabase.saveDatabase(requireContext(), SettingsUtil.getCryptoParameters(requireContext()));
|
OTPDatabase.saveDatabase(requireContext(), SettingsUtil.getCryptoParameters(requireContext()));
|
||||||
|
|
||||||
|
DialogUtil.showBackupLoadedDialog(requireContext(), data);
|
||||||
} catch (OTPDatabaseException | CryptoException e) {
|
} catch (OTPDatabaseException | CryptoException e) {
|
||||||
OTPDatabase.setLoadedDatabase(oldDatabase);
|
OTPDatabase.setLoadedDatabase(oldDatabase);
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
@ -12,6 +12,7 @@ import androidx.appcompat.app.AlertDialog;
|
|||||||
import androidx.core.util.Consumer;
|
import androidx.core.util.Consumer;
|
||||||
|
|
||||||
import com.cringe_studios.cringe_authenticator.R;
|
import com.cringe_studios.cringe_authenticator.R;
|
||||||
|
import com.cringe_studios.cringe_authenticator.backup.BackupData;
|
||||||
import com.cringe_studios.cringe_authenticator.databinding.DialogCreateGroupBinding;
|
import com.cringe_studios.cringe_authenticator.databinding.DialogCreateGroupBinding;
|
||||||
import com.cringe_studios.cringe_authenticator.databinding.DialogInputCodeHotpBinding;
|
import com.cringe_studios.cringe_authenticator.databinding.DialogInputCodeHotpBinding;
|
||||||
import com.cringe_studios.cringe_authenticator.databinding.DialogInputCodeTotpBinding;
|
import com.cringe_studios.cringe_authenticator.databinding.DialogInputCodeTotpBinding;
|
||||||
@ -277,7 +278,7 @@ public class DialogUtil {
|
|||||||
AlertDialog dialog = new StyledDialogBuilder(context)
|
AlertDialog dialog = new StyledDialogBuilder(context)
|
||||||
.setTitle(R.string.set_password)
|
.setTitle(R.string.set_password)
|
||||||
.setView(binding.getRoot())
|
.setView(binding.getRoot())
|
||||||
.setPositiveButton("Ok", (d, which) -> {})
|
.setPositiveButton(R.string.ok, (d, which) -> {})
|
||||||
.setNegativeButton(R.string.cancel, (d, which) -> { if(onCancel != null) onCancel.run(); })
|
.setNegativeButton(R.string.cancel, (d, which) -> { if(onCancel != null) onCancel.run(); })
|
||||||
.setOnCancelListener(d -> { if(onCancel != null) onCancel.run(); })
|
.setOnCancelListener(d -> { if(onCancel != null) onCancel.run(); })
|
||||||
.create();
|
.create();
|
||||||
@ -310,8 +311,8 @@ public class DialogUtil {
|
|||||||
|
|
||||||
AlertDialog dialog = new StyledDialogBuilder(context)
|
AlertDialog dialog = new StyledDialogBuilder(context)
|
||||||
.setTitle("Input Password")
|
.setTitle("Input Password")
|
||||||
.setView(binding.inputPassword)
|
.setView(binding.getRoot())
|
||||||
.setPositiveButton("Ok", (d, which) -> {})
|
.setPositiveButton(R.string.ok, (d, which) -> {})
|
||||||
.setNegativeButton(R.string.cancel, (d, which) -> { if(onCancel != null) onCancel.run(); })
|
.setNegativeButton(R.string.cancel, (d, which) -> { if(onCancel != null) onCancel.run(); })
|
||||||
.setOnCancelListener(d -> { if(onCancel != null) onCancel.run(); })
|
.setOnCancelListener(d -> { if(onCancel != null) onCancel.run(); })
|
||||||
.create();
|
.create();
|
||||||
@ -371,4 +372,14 @@ public class DialogUtil {
|
|||||||
showYesNoCancel(context, title, message, R.string.yes, R.string.no, R.string.cancel, yes, no, cancel);
|
showYesNoCancel(context, title, message, R.string.yes, R.string.no, R.string.cancel, yes, no, cancel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void showBackupLoadedDialog(Context context, BackupData data) {
|
||||||
|
AlertDialog dialog = new StyledDialogBuilder(context)
|
||||||
|
.setTitle("Backup loaded")
|
||||||
|
.setMessage(String.format("Successfully loaded %s group(s) from the backup", data.getGroups().length))
|
||||||
|
.setPositiveButton(R.string.ok, (d, which) -> {})
|
||||||
|
.create();
|
||||||
|
|
||||||
|
dialog.show();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -96,4 +96,6 @@
|
|||||||
<string name="enter_password">Passwort eingeben</string>
|
<string name="enter_password">Passwort eingeben</string>
|
||||||
<string name="disable_encryption_title">Verschlüsselung deaktivieren</string>
|
<string name="disable_encryption_title">Verschlüsselung deaktivieren</string>
|
||||||
<string name="disable_encryption_message">Willst du wirklich die Verschlüsselung deaktivieren?</string>
|
<string name="disable_encryption_message">Willst du wirklich die Verschlüsselung deaktivieren?</string>
|
||||||
|
<string name="load_backup_title">Backup laden</string>
|
||||||
|
<string name="backup_load_message">Willst du dieses Backup laden?\n\nDadurch werden ALLE Daten der App gelöscht und mit denen aus dem Backup ersetzt!</string>
|
||||||
</resources>
|
</resources>
|
@ -97,4 +97,6 @@
|
|||||||
<string name="enter_password">Enter Password</string>
|
<string name="enter_password">Enter Password</string>
|
||||||
<string name="disable_encryption_title">Disable encryption</string>
|
<string name="disable_encryption_title">Disable encryption</string>
|
||||||
<string name="disable_encryption_message">Do you really want to disable encryption?</string>
|
<string name="disable_encryption_message">Do you really want to disable encryption?</string>
|
||||||
|
<string name="load_backup_title">Load backup</string>
|
||||||
|
<string name="backup_load_message">Do you want to load this backup?\n\nThis will delete ALL of the current data in the app and replace it with the data from the backup!</string>
|
||||||
</resources>
|
</resources>
|
Loading…
Reference in New Issue
Block a user