mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-04 20:30:36 +00:00
Start working on ability to remove groups
This commit is contained in:
parent
ae0b4b5a37
commit
feeada3e2d
10 changed files with 289 additions and 0 deletions
|
@ -54,5 +54,10 @@
|
||||||
android:label="Manage key slots"
|
android:label="Manage key slots"
|
||||||
android:theme="@style/AppTheme.TransparentActionBar">
|
android:theme="@style/AppTheme.TransparentActionBar">
|
||||||
</activity>
|
</activity>
|
||||||
|
<activity
|
||||||
|
android:name=".ui.GroupManagerActivity"
|
||||||
|
android:label="Manage groups"
|
||||||
|
android:theme="@style/AppTheme.TransparentActionBar">
|
||||||
|
</activity>
|
||||||
</application>
|
</application>
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|
|
@ -172,6 +172,17 @@ 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;
|
||||||
|
|
58
app/src/main/java/me/impy/aegis/ui/GroupManagerActivity.java
Normal file
58
app/src/main/java/me/impy/aegis/ui/GroupManagerActivity.java
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
package me.impy.aegis.ui;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.ActionBar;
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import me.impy.aegis.AegisApplication;
|
||||||
|
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.SlotAdapter;
|
||||||
|
|
||||||
|
public class GroupManagerActivity extends AegisActivity implements GroupAdapter.Listener {
|
||||||
|
private AegisApplication _app;
|
||||||
|
private DatabaseManager _db;
|
||||||
|
private GroupAdapter _adapter;
|
||||||
|
|
||||||
|
TreeSet<String> groups;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_groups);
|
||||||
|
|
||||||
|
_app = (AegisApplication) getApplication();
|
||||||
|
_db = _app.getDatabaseManager();
|
||||||
|
|
||||||
|
groups = _db.getGroups();
|
||||||
|
|
||||||
|
ActionBar bar = getSupportActionBar();
|
||||||
|
bar.setHomeAsUpIndicator(R.drawable.ic_close);
|
||||||
|
bar.setDisplayHomeAsUpEnabled(true);
|
||||||
|
|
||||||
|
// set up the recycler view
|
||||||
|
_adapter = new GroupAdapter(this);
|
||||||
|
RecyclerView slotsView = findViewById(R.id.list_slots);
|
||||||
|
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
|
||||||
|
slotsView.setLayoutManager(layoutManager);
|
||||||
|
slotsView.setAdapter(_adapter);
|
||||||
|
slotsView.setNestedScrollingEnabled(false);
|
||||||
|
|
||||||
|
// load the slots and masterKey
|
||||||
|
for (String group : groups) {
|
||||||
|
_adapter.addGroup(group);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRemoveGroup(String group) {
|
||||||
|
_db.removeGroup(group);
|
||||||
|
groups.remove(group);
|
||||||
|
}
|
||||||
|
}
|
|
@ -67,6 +67,7 @@ public class PreferencesFragment extends PreferenceFragmentCompat {
|
||||||
private SwitchPreference _fingerprintPreference;
|
private SwitchPreference _fingerprintPreference;
|
||||||
private Preference _setPasswordPreference;
|
private Preference _setPasswordPreference;
|
||||||
private Preference _slotsPreference;
|
private Preference _slotsPreference;
|
||||||
|
private Preference _groupsPreference;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreatePreferencesFix(Bundle savedInstanceState, String rootKey) {
|
public void onCreatePreferencesFix(Bundle savedInstanceState, String rootKey) {
|
||||||
|
@ -208,6 +209,15 @@ public class PreferencesFragment extends PreferenceFragmentCompat {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
_groupsPreference = findPreference("pref_groups");
|
||||||
|
_groupsPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onPreferenceClick(Preference preference) {
|
||||||
|
Intent intent = new Intent(getActivity(), GroupManagerActivity.class);
|
||||||
|
startActivity(intent);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
updateEncryptionPreferences();
|
updateEncryptionPreferences();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
62
app/src/main/java/me/impy/aegis/ui/views/GroupAdapter.java
Normal file
62
app/src/main/java/me/impy/aegis/ui/views/GroupAdapter.java
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
package me.impy.aegis.ui.views;
|
||||||
|
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import me.impy.aegis.R;
|
||||||
|
import me.impy.aegis.db.slots.Slot;
|
||||||
|
|
||||||
|
public class GroupAdapter extends RecyclerView.Adapter<GroupHolder> {
|
||||||
|
private GroupAdapter.Listener _listener;
|
||||||
|
private ArrayList<String> _groups;
|
||||||
|
|
||||||
|
public GroupAdapter(GroupAdapter.Listener listener) {
|
||||||
|
_listener = listener;
|
||||||
|
_groups = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addGroup(String group) {
|
||||||
|
_groups.add(group);
|
||||||
|
|
||||||
|
int position = getItemCount() - 1;
|
||||||
|
if (position == 0) {
|
||||||
|
notifyDataSetChanged();
|
||||||
|
} else {
|
||||||
|
notifyItemInserted(position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeGroup(String group) {
|
||||||
|
int position = _groups.indexOf(group);
|
||||||
|
_groups.remove(position);
|
||||||
|
notifyItemRemoved(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GroupHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
|
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.card_slot, parent, false);
|
||||||
|
return new GroupHolder(view);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(GroupHolder holder, int position) {
|
||||||
|
holder.setData(_groups.get(position));
|
||||||
|
holder.setOnDeleteClickListener(v -> {
|
||||||
|
int position12 = holder.getAdapterPosition();
|
||||||
|
_listener.onRemoveGroup(_groups.get(position12));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return _groups.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface Listener {
|
||||||
|
void onRemoveGroup(String group);
|
||||||
|
}
|
||||||
|
}
|
35
app/src/main/java/me/impy/aegis/ui/views/GroupHolder.java
Normal file
35
app/src/main/java/me/impy/aegis/ui/views/GroupHolder.java
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
package me.impy.aegis.ui.views;
|
||||||
|
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import me.impy.aegis.R;
|
||||||
|
import me.impy.aegis.crypto.KeyStoreHandle;
|
||||||
|
import me.impy.aegis.crypto.KeyStoreHandleException;
|
||||||
|
import me.impy.aegis.db.slots.FingerprintSlot;
|
||||||
|
import me.impy.aegis.db.slots.PasswordSlot;
|
||||||
|
import me.impy.aegis.db.slots.RawSlot;
|
||||||
|
import me.impy.aegis.db.slots.Slot;
|
||||||
|
import me.impy.aegis.helpers.FingerprintHelper;
|
||||||
|
|
||||||
|
public class GroupHolder extends RecyclerView.ViewHolder {
|
||||||
|
private TextView _slotName;
|
||||||
|
private ImageView _buttonDelete;
|
||||||
|
|
||||||
|
public GroupHolder(final View view) {
|
||||||
|
super(view);
|
||||||
|
_slotName = view.findViewById(R.id.text_slot_name);
|
||||||
|
_buttonDelete = view.findViewById(R.id.button_delete);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setData(String groupName) {
|
||||||
|
_slotName.setText(groupName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnDeleteClickListener(View.OnClickListener listener) {
|
||||||
|
_buttonDelete.setOnClickListener(listener);
|
||||||
|
}
|
||||||
|
}
|
30
app/src/main/res/layout/activity_groups.xml
Normal file
30
app/src/main/res/layout/activity_groups.xml
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:fitsSystemWindows="true"
|
||||||
|
tools:context="me.impy.aegis.ui.GroupManagerActivity">
|
||||||
|
|
||||||
|
<androidx.core.widget.NestedScrollView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/list_slots"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:scrollbars="vertical"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</androidx.core.widget.NestedScrollView>
|
||||||
|
|
||||||
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
70
app/src/main/res/layout/card_group.xml
Normal file
70
app/src/main/res/layout/card_group.xml
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/button_edit"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:paddingStart="10dp"
|
||||||
|
android:paddingEnd="10dp"
|
||||||
|
android:paddingTop="12.5dp"
|
||||||
|
android:paddingBottom="12.5dp"
|
||||||
|
android:foreground="?android:attr/selectableItemBackground">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/text_group_name"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="Group name"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
|
android:textColor="?android:attr/textColorPrimary" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/text_slot_used"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="5dp"
|
||||||
|
android:text="... entries"
|
||||||
|
android:visibility="visible" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="1dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@android:color/darker_gray"
|
||||||
|
android:paddingStart="15dp"
|
||||||
|
android:paddingEnd="15dp"
|
||||||
|
android:layout_marginTop="12.5dp"
|
||||||
|
android:layout_marginBottom="12.5dp"/>
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/button_delete"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:clickable="true"
|
||||||
|
android:focusable="true"
|
||||||
|
android:foreground="?android:attr/selectableItemBackground"
|
||||||
|
android:paddingStart="15dp"
|
||||||
|
android:paddingTop="12.5dp"
|
||||||
|
android:paddingEnd="15dp"
|
||||||
|
android:paddingBottom="12.5dp"
|
||||||
|
android:src="@drawable/ic_delete_black_24dp"
|
||||||
|
android:tint="?attr/iconColorPrimary" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
|
@ -142,4 +142,6 @@
|
||||||
<string name="new_group">New group...</string>
|
<string name="new_group">New group...</string>
|
||||||
<string name="enter_group_name">Enter a group name</string>
|
<string name="enter_group_name">Enter a group name</string>
|
||||||
<string name="group_name_hint">Group name</string>
|
<string name="group_name_hint">Group name</string>
|
||||||
|
<string name="preference_manage_groups">Edit groups</string>
|
||||||
|
<string name="preference_manage_groups_summary">Manage and delete your groups here</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -20,6 +20,12 @@
|
||||||
android:title="@string/pref_account_name_title"
|
android:title="@string/pref_account_name_title"
|
||||||
android:summary="@string/pref_account_name_summary"
|
android:summary="@string/pref_account_name_summary"
|
||||||
app:iconSpaceReserved="false"/>
|
app:iconSpaceReserved="false"/>
|
||||||
|
|
||||||
|
<Preference
|
||||||
|
android:key="pref_groups"
|
||||||
|
android:title="@string/preference_manage_groups"
|
||||||
|
android:summary="@string/preference_manage_groups_summary"
|
||||||
|
app:iconSpaceReserved="false"/>
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue