summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorknuthy <knuthy@gmail.com>2014-08-15 14:27:13 +0200
committerknuthy <knuthy@gmail.com>2014-08-15 14:27:13 +0200
commit390a7ec82598ba25f3dfa536ae819e771393f65b (patch)
treea111047c992019be2af65571475581d36cd89a4c /app/src/main/java
parente6ad605d1784886b8dd16af3db19f68f77a3ed0b (diff)
first shot for improved expandable lists
Diffstat (limited to 'app/src/main/java')
-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
2 files changed, 122 insertions, 13 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