mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-04 20:30:36 +00:00
Decouple GroupManagerActivity from the global application state
This commit is contained in:
parent
ec5be68ff2
commit
b28691c274
4 changed files with 38 additions and 31 deletions
|
@ -162,6 +162,8 @@ public class DatabaseManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public TreeSet<String> getGroups() {
|
public TreeSet<String> getGroups() {
|
||||||
|
assertState(false, true);
|
||||||
|
|
||||||
TreeSet<String> groups = new TreeSet<>(Collator.getInstance());
|
TreeSet<String> groups = new TreeSet<>(Collator.getInstance());
|
||||||
for (DatabaseEntry entry : getEntries()) {
|
for (DatabaseEntry entry : getEntries()) {
|
||||||
String group = entry.getGroup();
|
String group = entry.getGroup();
|
||||||
|
@ -172,17 +174,6 @@ public class DatabaseManager {
|
||||||
return groups;
|
return groups;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeGroup(String groupName) {
|
|
||||||
TreeSet<String> groups = new TreeSet<>(Collator.getInstance());
|
|
||||||
for (DatabaseEntry entry : getEntries()) {
|
|
||||||
String group = entry.getGroup();
|
|
||||||
if (group != null && group.equals(groupName)) {
|
|
||||||
entry.setGroup(null);
|
|
||||||
_db.replaceEntry(entry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public DatabaseFileCredentials getCredentials() {
|
public DatabaseFileCredentials getCredentials() {
|
||||||
assertState(false, true);
|
assertState(false, true);
|
||||||
return _creds;
|
return _creds;
|
||||||
|
|
|
@ -104,7 +104,7 @@ public class EditEntryActivity extends AegisActivity {
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
_origEntry = (DatabaseEntry) intent.getSerializableExtra("entry");
|
_origEntry = (DatabaseEntry) intent.getSerializableExtra("entry");
|
||||||
_isNew = intent.getBooleanExtra("isNew", false);
|
_isNew = intent.getBooleanExtra("isNew", false);
|
||||||
_groups = new TreeSet<String>(Collator.getInstance());
|
_groups = new TreeSet<>(Collator.getInstance());
|
||||||
_groups.addAll(intent.getStringArrayListExtra("groups"));
|
_groups.addAll(intent.getStringArrayListExtra("groups"));
|
||||||
if (_isNew) {
|
if (_isNew) {
|
||||||
setTitle(R.string.add_new_profile);
|
setTitle(R.string.add_new_profile);
|
||||||
|
|
|
@ -1,38 +1,32 @@
|
||||||
package me.impy.aegis.ui;
|
package me.impy.aegis.ui;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
|
import java.text.Collator;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import androidx.appcompat.app.ActionBar;
|
import androidx.appcompat.app.ActionBar;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import me.impy.aegis.AegisApplication;
|
|
||||||
import me.impy.aegis.R;
|
import me.impy.aegis.R;
|
||||||
import me.impy.aegis.db.DatabaseFileCredentials;
|
|
||||||
import me.impy.aegis.db.DatabaseManager;
|
|
||||||
import me.impy.aegis.db.slots.Slot;
|
|
||||||
import me.impy.aegis.ui.views.GroupAdapter;
|
import me.impy.aegis.ui.views.GroupAdapter;
|
||||||
import me.impy.aegis.ui.views.SlotAdapter;
|
|
||||||
|
|
||||||
public class GroupManagerActivity extends AegisActivity implements GroupAdapter.Listener {
|
public class GroupManagerActivity extends AegisActivity implements GroupAdapter.Listener {
|
||||||
private AegisApplication _app;
|
|
||||||
private DatabaseManager _db;
|
|
||||||
private GroupAdapter _adapter;
|
private GroupAdapter _adapter;
|
||||||
|
private TreeSet<String> _groups;
|
||||||
TreeSet<String> groups;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_groups);
|
setContentView(R.layout.activity_groups);
|
||||||
|
|
||||||
_app = (AegisApplication) getApplication();
|
Intent intent = getIntent();
|
||||||
_db = _app.getDatabaseManager();
|
_groups = new TreeSet<>(Collator.getInstance());
|
||||||
|
_groups.addAll(intent.getStringArrayListExtra("groups"));
|
||||||
groups = _db.getGroups();
|
|
||||||
|
|
||||||
ActionBar bar = getSupportActionBar();
|
ActionBar bar = getSupportActionBar();
|
||||||
bar.setHomeAsUpIndicator(R.drawable.ic_close);
|
bar.setHomeAsUpIndicator(R.drawable.ic_close);
|
||||||
|
@ -46,8 +40,7 @@ public class GroupManagerActivity extends AegisActivity implements GroupAdapter.
|
||||||
slotsView.setAdapter(_adapter);
|
slotsView.setAdapter(_adapter);
|
||||||
slotsView.setNestedScrollingEnabled(false);
|
slotsView.setNestedScrollingEnabled(false);
|
||||||
|
|
||||||
// load the slots and masterKey
|
for (String group : _groups) {
|
||||||
for (String group : groups) {
|
|
||||||
_adapter.addGroup(group);
|
_adapter.addGroup(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,8 +51,7 @@ public class GroupManagerActivity extends AegisActivity implements GroupAdapter.
|
||||||
.setTitle(R.string.remove_group)
|
.setTitle(R.string.remove_group)
|
||||||
.setMessage(R.string.remove_group_description)
|
.setMessage(R.string.remove_group_description)
|
||||||
.setPositiveButton(android.R.string.yes, (dialog, whichButton) -> {
|
.setPositiveButton(android.R.string.yes, (dialog, whichButton) -> {
|
||||||
_db.removeGroup(group);
|
_groups.remove(group);
|
||||||
groups.remove(group);
|
|
||||||
_adapter.removeGroup(group);
|
_adapter.removeGroup(group);
|
||||||
})
|
})
|
||||||
.setNegativeButton(android.R.string.no, null)
|
.setNegativeButton(android.R.string.no, null)
|
||||||
|
@ -78,4 +70,12 @@ public class GroupManagerActivity extends AegisActivity implements GroupAdapter.
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBackPressed() {
|
||||||
|
Intent intent = new Intent();
|
||||||
|
intent.putExtra("groups", new ArrayList<>(_groups));
|
||||||
|
setResult(RESULT_OK, intent);
|
||||||
|
finish();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,8 @@ import com.takisoft.preferencex.PreferenceFragmentCompat;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -50,6 +52,7 @@ public class PreferencesFragment extends PreferenceFragmentCompat {
|
||||||
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;
|
private static final int CODE_SLOTS = 2;
|
||||||
|
private static final int CODE_GROUPS = 3;
|
||||||
|
|
||||||
// permission request codes
|
// permission request codes
|
||||||
private static final int CODE_PERM_IMPORT = 0;
|
private static final int CODE_PERM_IMPORT = 0;
|
||||||
|
@ -197,7 +200,6 @@ public class PreferencesFragment extends PreferenceFragmentCompat {
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
_slotsPreference = findPreference("pref_slots");
|
_slotsPreference = findPreference("pref_slots");
|
||||||
_slotsPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
_slotsPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -214,7 +216,8 @@ public class PreferencesFragment extends PreferenceFragmentCompat {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
Intent intent = new Intent(getActivity(), GroupManagerActivity.class);
|
Intent intent = new Intent(getActivity(), GroupManagerActivity.class);
|
||||||
startActivity(intent);
|
intent.putExtra("groups", new ArrayList<>(_db.getGroups()));
|
||||||
|
startActivityForResult(intent, CODE_GROUPS);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -254,6 +257,9 @@ public class PreferencesFragment extends PreferenceFragmentCompat {
|
||||||
case CODE_SLOTS:
|
case CODE_SLOTS:
|
||||||
onSlotManagerResult(resultCode, data);
|
onSlotManagerResult(resultCode, data);
|
||||||
break;
|
break;
|
||||||
|
case CODE_GROUPS:
|
||||||
|
onGroupManagerResult(resultCode, data);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,6 +423,16 @@ public class PreferencesFragment extends PreferenceFragmentCompat {
|
||||||
updateEncryptionPreferences();
|
updateEncryptionPreferences();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onGroupManagerResult(int resultCode, Intent data) {
|
||||||
|
HashSet<String> groups = new HashSet<>(data.getStringArrayListExtra("groups"));
|
||||||
|
|
||||||
|
for (DatabaseEntry entry : _db.getEntries()) {
|
||||||
|
if (!groups.contains(entry.getGroup())) {
|
||||||
|
entry.setGroup(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean saveDatabase() {
|
private boolean saveDatabase() {
|
||||||
try {
|
try {
|
||||||
_db.save();
|
_db.save();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue