summaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java31
-rw-r--r--app/src/main/java/com/zeapo/pwdstore/utils/PasswordAdapter.java104
-rw-r--r--app/src/main/res/layout/child_row_layout.xml30
-rw-r--r--app/src/main/res/layout/fragment_password_list.xml5
4 files changed, 155 insertions, 15 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java
index ab7c8a77..a8dc67bb 100644
--- a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java
+++ b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java
@@ -10,6 +10,7 @@ import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
+import android.widget.ExpandableListView;
import android.widget.ListAdapter;
import android.widget.ListView;
@@ -27,14 +28,14 @@ import java.util.List;
* with a GridView.
* <p />
*/
-public class PasswordFragment extends Fragment implements AbsListView.OnItemClickListener {
+public class PasswordFragment extends Fragment implements ExpandableListView.OnGroupClickListener {
private OnFragmentInteractionListener mListener;
/**
* The fragment's ListView/GridView.
*/
- private ListView mListView;
+ private ExpandableListView mListView;
/**
* The Adapter which will be used to populate the ListView/GridView with
@@ -62,11 +63,11 @@ public class PasswordFragment extends Fragment implements AbsListView.OnItemClic
View view = inflater.inflate(R.layout.fragment_password, container, false);
// Set the adapter
- mListView = (ListView) view.findViewById(R.id.pass_list);
- ((AdapterView<ListAdapter>) mListView).setAdapter(mAdapter);
+ mListView = (ExpandableListView) view.findViewById(R.id.pass_list);
+ mListView.setAdapter((android.widget.ExpandableListAdapter) mAdapter);
// Set OnItemClickListener so we can be notified on item clicks
- mListView.setOnItemClickListener(this);
+ mListView.setOnGroupClickListener(this);
mListView.setSelectionFromTop(getArguments().getInt("Position"), 0);
return view;
@@ -97,12 +98,22 @@ public class PasswordFragment extends Fragment implements AbsListView.OnItemClic
}
@Override
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- if (null != mListener) {
- // Notify the active callbacks interface (the activity, if the
- // fragment is attached to one) that an item has been selected.
- mListener.onFragmentInteraction(mAdapter.getItem(position));
+ public boolean onGroupClick(ExpandableListView expandableListView, View view, int i, long l) {
+ if( ((PasswordItem) mAdapter.getGroup(i)).getType() == PasswordItem.TYPE_CATEGORY ){
+ if (null != mListener) {
+ // Notify the active callbacks interface (the activity, if the
+ // fragment is attached to one) that an item has been selected.
+ mListener.onFragmentInteraction(mAdapter.getItem(i));
+ }
+ } else {
+ if (expandableListView.isGroupExpanded(i)) {
+ expandableListView.collapseGroup(i);
+ } else {
+ expandableListView.expandGroup(i);
+ }
}
+
+ return true;
}
public interface OnFragmentInteractionListener {
diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordAdapter.java b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordAdapter.java
index b0cdb5a5..c18b1ab8 100644
--- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordAdapter.java
+++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordAdapter.java
@@ -1,18 +1,21 @@
package com.zeapo.pwdstore.utils;
import android.content.Context;
+import android.database.DataSetObserver;
import android.graphics.Typeface;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
+import android.widget.ExpandableListAdapter;
import android.widget.TextView;
import com.zeapo.pwdstore.R;
import java.util.ArrayList;
-public class PasswordAdapter extends ArrayAdapter<PasswordItem> {
+public class PasswordAdapter extends ArrayAdapter<PasswordItem> implements ExpandableListAdapter{
private final Context context;
private final ArrayList<PasswordItem> values;
@@ -28,9 +31,57 @@ public class PasswordAdapter extends ArrayAdapter<PasswordItem> {
}
@Override
- public View getView(int position, View convertView, ViewGroup parent) {
+ public void registerDataSetObserver(DataSetObserver dataSetObserver) {
+
+ }
+
+ @Override
+ public void unregisterDataSetObserver(DataSetObserver dataSetObserver) {
+
+ }
+
+ @Override
+ public int getGroupCount() {
+ return values.size();
+ }
+
+ @Override
+ public int getChildrenCount(int i) {
+ if (values.get(i).getType() == PasswordItem.TYPE_CATEGORY)
+ return 0;
+ else
+ return 1;
+ }
+
+ @Override
+ public Object getGroup(int i) {
+ return values.get(i);
+ }
+
+ @Override
+ public Object getChild(int i, int i2) {
+ return null;
+ }
+
+ @Override
+ public long getGroupId(int i) {
+ return 0;
+ }
+
+ @Override
+ public long getChildId(int i, int i2) {
+ return 0;
+ }
+
+ @Override
+ public boolean hasStableIds() {
+ return false;
+ }
+
+ @Override
+ public View getGroupView(int i, boolean b, View convertView, ViewGroup viewGroup) {
View rowView = convertView;
- PasswordItem pass = values.get(position);
+ PasswordItem pass = values.get(i);
// reuse for performance, holder pattern!
if (rowView == null) {
@@ -60,4 +111,51 @@ public class PasswordAdapter extends ArrayAdapter<PasswordItem> {
return rowView;
}
+
+ @Override
+ public View getChildView(int i, int i2, boolean b, View view, ViewGroup viewGroup) {
+ PasswordItem pass = values.get(i);
+
+ LayoutInflater inflater = (LayoutInflater) context
+ .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ view = inflater.inflate(R.layout.child_row_layout, null);
+ Log.i("ADAPTER", "Child clicked");
+
+ return view;
+ }
+
+ @Override
+ public boolean isChildSelectable(int i, int i2) {
+ return false;
+ }
+
+ @Override
+ public boolean areAllItemsEnabled() {
+ return false;
+ }
+
+ @Override
+ public boolean isEmpty() {
+ return false;
+ }
+
+ @Override
+ public void onGroupExpanded(int i) {
+
+ }
+
+ @Override
+ public void onGroupCollapsed(int i) {
+
+ }
+
+ @Override
+ public long getCombinedChildId(long l, long l2) {
+ return 0;
+ }
+
+ @Override
+ public long getCombinedGroupId(long l) {
+ return 0;
+ }
} \ No newline at end of file
diff --git a/app/src/main/res/layout/child_row_layout.xml b/app/src/main/res/layout/child_row_layout.xml
new file mode 100644
index 00000000..a60ead53
--- /dev/null
+++ b/app/src/main/res/layout/child_row_layout.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical" android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <ImageButton
+ android:id="@+id/crypto_delete_button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:src="@drawable/ico_del"
+ android:background="@drawable/red_rectangle"
+ android:layout_gravity="center_vertical"
+ android:onClick="handleClick"
+ android:layout_column="1"
+ android:layout_row="0"/>
+
+ <ImageButton
+ android:id="@+id/crypto_show_button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:src="@drawable/ico_key"
+ android:background="@drawable/blue_rectangle"
+ android:layout_gravity="center_vertical"
+ android:layout_marginLeft="8dp"
+ android:onClick="handleClick"
+ android:layout_column="2"
+ android:layout_row="0"/>
+
+</GridLayout> \ No newline at end of file
diff --git a/app/src/main/res/layout/fragment_password_list.xml b/app/src/main/res/layout/fragment_password_list.xml
index 64dd3d94..6ae0c0d8 100644
--- a/app/src/main/res/layout/fragment_password_list.xml
+++ b/app/src/main/res/layout/fragment_password_list.xml
@@ -5,11 +5,12 @@
android:layout_height="match_parent"
tools:context="com.zeapo.pwdstore.PasswordFragment">
- <ListView
+ <ExpandableListView
android:id="@+id/pass_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:dividerHeight="@dimen/activity_vertical_margin"
- android:divider="@android:color/transparent"/>
+ android:divider="@android:color/transparent"
+ android:groupIndicator="@android:drawable/screen_background_light_transparent"/>
</FrameLayout>