mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-14 14:02:49 +00:00
Don't leave the PreferencesActivity when managing slots
This commit is contained in:
parent
7630bbfe25
commit
da529608fa
2 changed files with 36 additions and 41 deletions
|
@ -4,10 +4,8 @@ import android.Manifest;
|
||||||
import android.content.ClipData;
|
import android.content.ClipData;
|
||||||
import android.content.ClipboardManager;
|
import android.content.ClipboardManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.media.MediaScannerConnection;
|
|
||||||
import android.support.design.widget.BottomSheetDialog;
|
import android.support.design.widget.BottomSheetDialog;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
@ -26,7 +24,6 @@ import me.impy.aegis.AegisApplication;
|
||||||
import me.impy.aegis.R;
|
import me.impy.aegis.R;
|
||||||
import me.impy.aegis.crypto.MasterKey;
|
import me.impy.aegis.crypto.MasterKey;
|
||||||
import me.impy.aegis.db.DatabaseManagerException;
|
import me.impy.aegis.db.DatabaseManagerException;
|
||||||
import me.impy.aegis.db.slots.SlotCollection;
|
|
||||||
import me.impy.aegis.db.DatabaseEntry;
|
import me.impy.aegis.db.DatabaseEntry;
|
||||||
import me.impy.aegis.db.DatabaseManager;
|
import me.impy.aegis.db.DatabaseManager;
|
||||||
import me.impy.aegis.helpers.PermissionHelper;
|
import me.impy.aegis.helpers.PermissionHelper;
|
||||||
|
@ -42,7 +39,6 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
|
||||||
private static final int CODE_DO_INTRO = 4;
|
private static final int CODE_DO_INTRO = 4;
|
||||||
private static final int CODE_DECRYPT = 5;
|
private static final int CODE_DECRYPT = 5;
|
||||||
private static final int CODE_PREFERENCES = 6;
|
private static final int CODE_PREFERENCES = 6;
|
||||||
private static final int CODE_SLOTS = 7;
|
|
||||||
|
|
||||||
// permission request codes
|
// permission request codes
|
||||||
private static final int CODE_PERM_CAMERA = 0;
|
private static final int CODE_PERM_CAMERA = 0;
|
||||||
|
@ -179,9 +175,6 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
|
||||||
case CODE_PREFERENCES:
|
case CODE_PREFERENCES:
|
||||||
onPreferencesResult(resultCode, data);
|
onPreferencesResult(resultCode, data);
|
||||||
break;
|
break;
|
||||||
case CODE_SLOTS:
|
|
||||||
onSlotManagerResult(resultCode, data);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,16 +192,6 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onSlotManagerResult(int resultCode, Intent data) {
|
|
||||||
if (resultCode != RESULT_OK) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SlotCollection slots = (SlotCollection) data.getSerializableExtra("slots");
|
|
||||||
_db.getFile().setSlots(slots);
|
|
||||||
saveDatabase();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onPreferencesResult(int resultCode, Intent data) {
|
private void onPreferencesResult(int resultCode, Intent data) {
|
||||||
// refresh the entire key profile list if needed
|
// refresh the entire key profile list if needed
|
||||||
if (data.getBooleanExtra("needsReload", false)) {
|
if (data.getBooleanExtra("needsReload", false)) {
|
||||||
|
@ -221,18 +204,6 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
|
||||||
boolean showIssuer = _app.getPreferences().getBoolean("pref_issuer", false);
|
boolean showIssuer = _app.getPreferences().getBoolean("pref_issuer", false);
|
||||||
_keyProfileView.setShowIssuer(showIssuer);
|
_keyProfileView.setShowIssuer(showIssuer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// perform any pending actions
|
|
||||||
int action = data.getIntExtra("action", -1);
|
|
||||||
switch (action) {
|
|
||||||
case PreferencesFragment.ACTION_SLOTS:
|
|
||||||
MasterKey masterKey = _db.getMasterKey();
|
|
||||||
Intent intent = new Intent(this, SlotManagerActivity.class);
|
|
||||||
intent.putExtra("masterKey", masterKey);
|
|
||||||
intent.putExtra("slots", _db.getFile().getSlots());
|
|
||||||
startActivityForResult(intent, CODE_SLOTS);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void startEditProfileActivity(int requestCode, KeyProfile profile, boolean isNew) {
|
private void startEditProfileActivity(int requestCode, KeyProfile profile, boolean isNew) {
|
||||||
|
@ -445,7 +416,6 @@ public class MainActivity extends AegisActivity implements KeyProfileView.Listen
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.action_settings:
|
case R.id.action_settings:
|
||||||
Intent intent = new Intent(this, PreferencesActivity.class);
|
Intent intent = new Intent(this, PreferencesActivity.class);
|
||||||
intent.putExtra("encrypted", _db.getFile().isEncrypted());
|
|
||||||
startActivityForResult(intent, CODE_PREFERENCES);
|
startActivityForResult(intent, CODE_PREFERENCES);
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_lock:
|
case R.id.action_lock:
|
||||||
|
|
|
@ -25,6 +25,7 @@ import me.impy.aegis.crypto.MasterKey;
|
||||||
import me.impy.aegis.db.DatabaseEntry;
|
import me.impy.aegis.db.DatabaseEntry;
|
||||||
import me.impy.aegis.db.DatabaseManager;
|
import me.impy.aegis.db.DatabaseManager;
|
||||||
import me.impy.aegis.db.DatabaseManagerException;
|
import me.impy.aegis.db.DatabaseManagerException;
|
||||||
|
import me.impy.aegis.db.slots.SlotCollection;
|
||||||
import me.impy.aegis.helpers.PermissionHelper;
|
import me.impy.aegis.helpers.PermissionHelper;
|
||||||
import me.impy.aegis.importers.AegisImporter;
|
import me.impy.aegis.importers.AegisImporter;
|
||||||
import me.impy.aegis.importers.DatabaseImporter;
|
import me.impy.aegis.importers.DatabaseImporter;
|
||||||
|
@ -35,14 +36,12 @@ public class PreferencesFragment extends PreferenceFragment {
|
||||||
// activity request codes
|
// activity request codes
|
||||||
private static final int CODE_IMPORT = 0;
|
private static final int CODE_IMPORT = 0;
|
||||||
private static final int CODE_IMPORT_DECRYPT = 1;
|
private static final int CODE_IMPORT_DECRYPT = 1;
|
||||||
|
private static final int CODE_SLOTS = 2;
|
||||||
|
|
||||||
// permission request codes
|
// permission request codes
|
||||||
private static final int CODE_PERM_IMPORT = 0;
|
private static final int CODE_PERM_IMPORT = 0;
|
||||||
private static final int CODE_PERM_EXPORT = 1;
|
private static final int CODE_PERM_EXPORT = 1;
|
||||||
|
|
||||||
// action codes
|
|
||||||
public static final int ACTION_SLOTS = 0;
|
|
||||||
|
|
||||||
private Intent _result = new Intent();
|
private Intent _result = new Intent();
|
||||||
private DatabaseManager _db;
|
private DatabaseManager _db;
|
||||||
|
|
||||||
|
@ -98,12 +97,15 @@ public class PreferencesFragment extends PreferenceFragment {
|
||||||
});
|
});
|
||||||
|
|
||||||
Preference slotsPreference = findPreference("pref_slots");
|
Preference slotsPreference = findPreference("pref_slots");
|
||||||
slotsPreference.setEnabled(getArguments().getBoolean("encrypted"));
|
slotsPreference.setEnabled(_db.getFile().isEncrypted());
|
||||||
slotsPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
slotsPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
_result.putExtra("action", ACTION_SLOTS);
|
MasterKey masterKey = _db.getMasterKey();
|
||||||
finish();
|
Intent intent = new Intent(getActivity(), SlotManagerActivity.class);
|
||||||
|
intent.putExtra("masterKey", masterKey);
|
||||||
|
intent.putExtra("slots", _db.getFile().getSlots());
|
||||||
|
startActivityForResult(intent, CODE_SLOTS);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -158,6 +160,9 @@ public class PreferencesFragment extends PreferenceFragment {
|
||||||
case CODE_IMPORT_DECRYPT:
|
case CODE_IMPORT_DECRYPT:
|
||||||
onImportDecryptResult(resultCode, data);
|
onImportDecryptResult(resultCode, data);
|
||||||
break;
|
break;
|
||||||
|
case CODE_SLOTS:
|
||||||
|
onSlotManagerResult(resultCode, data);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -184,6 +189,8 @@ public class PreferencesFragment extends PreferenceFragment {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Toast.makeText(getActivity(), "An error occurred while trying to parse the file", Toast.LENGTH_SHORT).show();
|
Toast.makeText(getActivity(), "An error occurred while trying to parse the file", Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_converter = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onImportResult(int resultCode, Intent data) {
|
private void onImportResult(int resultCode, Intent data) {
|
||||||
|
@ -249,11 +256,7 @@ public class PreferencesFragment extends PreferenceFragment {
|
||||||
_db.addKey(entry);
|
_db.addKey(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
if (!saveDatabase()) {
|
||||||
_db.save();
|
|
||||||
} catch (DatabaseManagerException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
Toast.makeText(getActivity(), "An error occurred while trying to save the database", Toast.LENGTH_LONG).show();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,4 +303,26 @@ public class PreferencesFragment extends PreferenceFragment {
|
||||||
}
|
}
|
||||||
builder.show();
|
builder.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onSlotManagerResult(int resultCode, Intent data) {
|
||||||
|
if (resultCode != Activity.RESULT_OK) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SlotCollection slots = (SlotCollection) data.getSerializableExtra("slots");
|
||||||
|
_db.getFile().setSlots(slots);
|
||||||
|
saveDatabase();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean saveDatabase() {
|
||||||
|
try {
|
||||||
|
_db.save();
|
||||||
|
} catch (DatabaseManagerException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Toast.makeText(getActivity(), "An error occurred while trying to save the database", Toast.LENGTH_LONG).show();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue