Add way to pass selected group to edit entry activity

This commit is contained in:
Michael Schättgen 2019-08-31 13:46:18 +02:00
parent c12c6ab107
commit 1b5ab33c25
2 changed files with 19 additions and 9 deletions

View file

@ -107,6 +107,8 @@ public class EditEntryActivity extends AegisActivity {
setTitle(R.string.add_new_profile);
}
String selectedGroup = intent.getStringExtra("selectedGroup");
// set up fields
_iconView = findViewById(R.id.profile_drawable);
_kropView = findViewById(R.id.krop_view);
@ -173,10 +175,7 @@ public class EditEntryActivity extends AegisActivity {
_spinnerAlgo.setSelection(getStringResourceIndex(R.array.otp_algo_array, algo), false);
String group = _origEntry.getGroup();
if (group != null) {
int pos = _groups.contains(group) ? _groups.headSet(group).size() : -1;
_spinnerGroup.setSelection(pos + 1, false);
}
setGroup(group);
}
// update the icon if the text changed
@ -253,9 +252,19 @@ public class EditEntryActivity extends AegisActivity {
// automatically open advanced settings since 'Secret' is required.
if (_isNew) {
openAdvancedSettings();
setGroup(selectedGroup);
}
}
private void setGroup(String groupName) {
if (groupName == null) {
return;
}
int pos = _groups.contains(groupName) ? _groups.headSet(groupName).size() : -1;
_spinnerGroup.setSelection(pos + 1, false);
}
private void openAdvancedSettings() {
Animation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setInterpolator(new AccelerateInterpolator());

View file

@ -74,7 +74,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
private AegisApplication _app;
private DatabaseManager _db;
private boolean _loaded;
private String _checkedGroup;
private String _selectedGroup;
private boolean _searchSubmitted;
private DatabaseEntry _selectedEntry;
@ -235,6 +235,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
intent.putExtra("entry", entry);
}
intent.putExtra("isNew", isNew);
intent.putExtra("selectedGroup", _selectedGroup);
intent.putExtra("groups", new ArrayList<>(_db.getGroups()));
startActivityForResult(intent, requestCode);
}
@ -321,14 +322,14 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
// if the group no longer exists, switch back to 'All'
TreeSet<String> groups = _db.getGroups();
if (_checkedGroup != null && !groups.contains(_checkedGroup)) {
if (_selectedGroup != null && !groups.contains(_selectedGroup)) {
menu.findItem(R.id.menu_filter_all).setChecked(true);
setGroupFilter(null);
}
for (String group : groups) {
MenuItem item = menu.add(R.id.action_filter_group, Menu.NONE, Menu.NONE, group);
if (group.equals(_checkedGroup)) {
if (group.equals(_selectedGroup)) {
item.setChecked(true);
}
}
@ -343,7 +344,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
private void setGroupFilter(String group) {
getSupportActionBar().setSubtitle(group);
_checkedGroup = group;
_selectedGroup = group;
_entryListView.setGroupFilter(group, true);
}
@ -482,7 +483,7 @@ public class MainActivity extends AegisActivity implements EntryListView.Listene
collapseSearchView();
setTitle("Aegis");
setGroupFilter(_checkedGroup);
setGroupFilter(_selectedGroup);
return;
}