Start working on ability to remove groups

This commit is contained in:
Michael Schättgen 2018-12-16 22:57:04 +01:00
parent ae0b4b5a37
commit feeada3e2d
10 changed files with 289 additions and 0 deletions

View file

@ -54,5 +54,10 @@
android:label="Manage key slots"
android:theme="@style/AppTheme.TransparentActionBar">
</activity>
<activity
android:name=".ui.GroupManagerActivity"
android:label="Manage groups"
android:theme="@style/AppTheme.TransparentActionBar">
</activity>
</application>
</manifest>

View file

@ -172,6 +172,17 @@ public class DatabaseManager {
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() {
assertState(false, true);
return _creds;

View 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);
}
}

View file

@ -67,6 +67,7 @@ public class PreferencesFragment extends PreferenceFragmentCompat {
private SwitchPreference _fingerprintPreference;
private Preference _setPasswordPreference;
private Preference _slotsPreference;
private Preference _groupsPreference;
@Override
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();
}

View 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);
}
}

View 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);
}
}

View 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>

View 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>

View file

@ -142,4 +142,6 @@
<string name="new_group">New group...</string>
<string name="enter_group_name">Enter a 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>

View file

@ -20,6 +20,12 @@
android:title="@string/pref_account_name_title"
android:summary="@string/pref_account_name_summary"
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