Refactor filter adapter to not be expandable

pull/14/head
Sam Bosley 13 years ago
parent 9d237bf81f
commit 50eebc46b8

@ -2,7 +2,7 @@ package com.todoroo.astrid.locale;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.ExpandableListActivity; import android.app.ListActivity;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.os.Bundle; import android.os.Bundle;
@ -10,8 +10,8 @@ import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.ExpandableListView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Spinner; import android.widget.Spinner;
import com.timsu.astrid.R; import com.timsu.astrid.R;
@ -33,7 +33,7 @@ import com.twofortyfouram.SharedResources;
* @author Tim Su <tim@todoroo.com> * @author Tim Su <tim@todoroo.com>
* *
*/ */
public final class LocaleEditAlerts extends ExpandableListActivity { public final class LocaleEditAlerts extends ListActivity {
// --- locale constants // --- locale constants
@ -156,7 +156,7 @@ public final class LocaleEditAlerts extends ExpandableListActivity {
// if we match a selection, make it selected // if we match a selection, make it selected
final String finalSelection = selectionToMatch; final String finalSelection = selectionToMatch;
adapter = new FilterAdapter(this, getExpandableListView(), R.layout.filter_adapter_row, true) { adapter = new FilterAdapter(this, getListView(), R.layout.filter_adapter_row, true) {
@Override @Override
public void onReceiveFilter(FilterListItem item) { public void onReceiveFilter(FilterListItem item) {
if(adapter.getSelection() != null || finalSelection == null) if(adapter.getSelection() != null || finalSelection == null)
@ -197,32 +197,9 @@ public final class LocaleEditAlerts extends ExpandableListActivity {
} }
@Override @Override
public boolean onChildClick(ExpandableListView parent, View v, public void onListItemClick(ListView parent, View v, int position, long id) {
int groupPosition, int childPosition, long id) { Filter item = adapter.getItem(position);
FilterListItem item = (FilterListItem) adapter.getChild(groupPosition,
childPosition);
if(item instanceof Filter) {
adapter.setSelection(item);
}
return true;
}
@Override
public void onGroupExpand(int groupPosition) {
FilterListItem item = (FilterListItem) adapter.getGroup(groupPosition);
if(item instanceof Filter)
adapter.setSelection(item);
else if(item instanceof FilterCategory)
adapter.saveExpansionSetting((FilterCategory) item, true);
}
@Override
public void onGroupCollapse(int groupPosition) {
FilterListItem item = (FilterListItem) adapter.getGroup(groupPosition);
if(item instanceof Filter)
adapter.setSelection(item); adapter.setSelection(item);
else if(item instanceof FilterCategory)
adapter.saveExpansionSetting((FilterCategory) item, false);
} }
/** /**

@ -30,7 +30,7 @@
<!-- List --> <!-- List -->
<ExpandableListView android:id="@android:id/list" <ListView android:id="@android:id/list"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:layout_weight="100" android:layout_weight="100"

@ -30,7 +30,7 @@
<!-- List --> <!-- List -->
<ExpandableListView android:id="@android:id/list" <ListView android:id="@android:id/list"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:layout_weight="100" android:layout_weight="100"

@ -28,7 +28,7 @@
android:layout_margin="10px" android:layout_margin="10px"
android:background="@drawable/locale_border"> android:background="@drawable/locale_border">
<ExpandableListView android:id="@android:id/list" <ListView android:id="@android:id/list"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:scrollbars="vertical" android:scrollbars="vertical"

@ -8,7 +8,7 @@
android:background="@drawable/background_gradient"> android:background="@drawable/background_gradient">
<!-- List --> <!-- List -->
<ExpandableListView android:id="@android:id/list" <ListView android:id="@android:id/list"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_height="fill_parent"
android:layout_weight="100" android:layout_weight="100"

@ -270,7 +270,7 @@
<style name="TextAppearance.FLA_Filter"> <style name="TextAppearance.FLA_Filter">
<item name="android:textSize">18sp</item> <item name="android:textSize">18sp</item>
<item name="android:textStyle">bold</item> <item name="android:textStyle">bold</item>
<item name="android:textColor">?attr/asTextColor</item> <item name="android:textColor">@android:color/white</item>
</style> </style>
<style name="TextAppearance.FLA_Header" parent="TextAppearance.FLA_Filter"> <style name="TextAppearance.FLA_Header" parent="TextAppearance.FLA_Filter">

@ -15,6 +15,7 @@ import android.graphics.drawable.BitmapDrawable;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.ListFragment;
import android.support.v4.app.SupportActivity; import android.support.v4.app.SupportActivity;
import android.support.v4.view.Menu; import android.support.v4.view.Menu;
import android.support.v4.view.MenuItem; import android.support.v4.view.MenuItem;
@ -28,11 +29,11 @@ import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.ExpandableListContextMenuInfo;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ListAdapter;
import android.widget.ListView; import android.widget.ListView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener; import android.widget.TextView.OnEditorActionListener;
@ -48,7 +49,6 @@ import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.astrid.adapter.FilterAdapter; import com.todoroo.astrid.adapter.FilterAdapter;
import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.FilterCategory;
import com.todoroo.astrid.api.FilterListItem; import com.todoroo.astrid.api.FilterListItem;
import com.todoroo.astrid.core.CustomFilterActivity; import com.todoroo.astrid.core.CustomFilterActivity;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
@ -63,7 +63,7 @@ import com.todoroo.astrid.tags.TagsPlugin;
* @author Tim Su <tim@todoroo.com> * @author Tim Su <tim@todoroo.com>
* *
*/ */
public class FilterListActivity extends ExpandableListFragment { public class FilterListActivity extends ListFragment {
public static final String TAG_FILTERLIST_FRAGMENT = "filterlist_fragment"; public static final String TAG_FILTERLIST_FRAGMENT = "filterlist_fragment";
@ -172,8 +172,6 @@ public class FilterListActivity extends ExpandableListFragment {
} }
}); });
onContentChanged();
onNewIntent(getActivity().getIntent()); onNewIntent(getActivity().getIntent());
Fragment tasklistFrame = getFragmentManager().findFragmentByTag(TaskListActivity.TAG_TASKLIST_FRAGMENT); Fragment tasklistFrame = getFragmentManager().findFragmentByTag(TaskListActivity.TAG_TASKLIST_FRAGMENT);
@ -181,8 +179,8 @@ public class FilterListActivity extends ExpandableListFragment {
if (mDualFragments) { if (mDualFragments) {
// In dual-pane mode, the list view highlights the selected item. // In dual-pane mode, the list view highlights the selected item.
getExpandableListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE); getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
getExpandableListView().setItemsCanFocus(false); getListView().setItemsCanFocus(false);
} }
} }
@ -279,63 +277,45 @@ public class FilterListActivity extends ExpandableListFragment {
/** Sets up the coach list adapter */ /** Sets up the coach list adapter */
protected void setUpList() { protected void setUpList() {
adapter = new FilterAdapter(getActivity(), getExpandableListView(), adapter = new FilterAdapter(getActivity(), getListView(),
R.layout.filter_adapter_row, false); R.layout.filter_adapter_row, false);
setListAdapter(adapter); setListAdapter(adapter);
registerForContextMenu(getExpandableListView()); registerForContextMenu(getListView());
}
@Override
public void setListAdapter(ListAdapter adapter) {
super.setListAdapter(adapter);
Activity activity = getActivity();
if (activity instanceof TaskListWrapperActivity && adapter instanceof FilterAdapter) {
((TaskListWrapperActivity) activity).setPopoverAdapter((FilterAdapter) adapter);
}
} }
/* ====================================================================== /* ======================================================================
* ============================================================== actions * ============================================================== actions
* ====================================================================== */ * ====================================================================== */
@Override @Override
public boolean onChildClick(ExpandableListView parent, View v, public void onListItemClick(ListView parent, View v, int position, long id) {
int groupPosition, int childPosition, long id) {
// if (mDualFragments) // if (mDualFragments)
// { // {
// setSelectedChild(groupPosition, childPosition, false); // setSelectedChild(groupPosition, childPosition, false);
// setItemChecked((int) getSelectedPosition(), true); // setItemChecked((int) getSelectedPosition(), true);
// } // }
FilterListItem item = (FilterListItem) adapter.getChild(groupPosition, Filter item = adapter.getItem(position);
childPosition);
return mListener.onFilterItemClicked(item);
}
@Override
public void onGroupExpand(int groupPosition) {
FilterListItem item = (FilterListItem) adapter.getGroup(groupPosition);
mListener.onFilterItemClicked(item);
if(item instanceof FilterCategory)
adapter.saveExpansionSetting((FilterCategory) item, true);
}
@Override
public void onGroupCollapse(int groupPosition) {
FilterListItem item = (FilterListItem) adapter.getGroup(groupPosition);
mListener.onFilterItemClicked(item); mListener.onFilterItemClicked(item);
if(item instanceof FilterCategory)
adapter.saveExpansionSetting((FilterCategory) item, false);
} }
@Override @Override
public void onCreateContextMenu(ContextMenu menu, View v, public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) { ContextMenuInfo menuInfo) {
ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuInfo; AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
int type = ExpandableListView.getPackedPositionType(info.packedPosition); Filter item = adapter.getItem(info.position);
FilterListItem item;
if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition);
int childPos = ExpandableListView.getPackedPositionChild(info.packedPosition);
item = (FilterListItem) adapter.getChild(groupPos, childPos);
} else if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition);
item = (FilterListItem) adapter.getGroup(groupPos);
} else {
return;
}
android.view.MenuItem menuItem; android.view.MenuItem menuItem;
@ -420,7 +400,7 @@ public class FilterListActivity extends ExpandableListFragment {
return true; return true;
} }
case CONTEXT_MENU_SHORTCUT: { case CONTEXT_MENU_SHORTCUT: {
ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo)item.getMenuInfo(); AdapterContextMenuInfo info = (AdapterContextMenuInfo)item.getMenuInfo();
final Intent shortcutIntent = item.getIntent(); final Intent shortcutIntent = item.getIntent();
FilterListItem filter = ((FilterAdapter.ViewHolder)info.targetView.getTag()).item; FilterListItem filter = ((FilterAdapter.ViewHolder)info.targetView.getTag()).item;
if(filter instanceof Filter) if(filter instanceof Filter)

@ -6,12 +6,12 @@ import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.PopupWindow.OnDismissListener; import android.widget.PopupWindow.OnDismissListener;
import android.widget.TextView; import android.widget.TextView;
import com.timsu.astrid.R; import com.timsu.astrid.R;
import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.astrid.adapter.FilterAdapter;
import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.service.ThemeService; import com.todoroo.astrid.service.ThemeService;
import com.todoroo.astrid.ui.ListDropdownPopover; import com.todoroo.astrid.ui.ListDropdownPopover;
@ -22,7 +22,7 @@ public class TaskListWrapperActivity extends AstridWrapperActivity {
private View listsNav; private View listsNav;
private TextView lists; private TextView lists;
private ArrayAdapter<Filter> listDropdownAdapter; private FilterAdapter listDropdownAdapter;
private ListDropdownPopover popover; private ListDropdownPopover popover;
private final OnItemClickListener listClickListener = new OnItemClickListener() { private final OnItemClickListener listClickListener = new OnItemClickListener() {
@ -102,7 +102,7 @@ public class TaskListWrapperActivity extends AstridWrapperActivity {
super.onResume(); super.onResume();
} }
public void updateDropdownNav(ArrayAdapter<Filter> arrayAdapter) { public void setPopoverAdapter(FilterAdapter arrayAdapter) {
listDropdownAdapter = arrayAdapter; listDropdownAdapter = arrayAdapter;
popover.setAdapter(listDropdownAdapter, listClickListener); popover.setAdapter(listDropdownAdapter, listClickListener);
} }

@ -20,9 +20,7 @@ import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.content.res.TypedArray;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle; import android.os.Bundle;
import android.os.Parcelable; import android.os.Parcelable;
import android.text.TextUtils; import android.text.TextUtils;
@ -33,10 +31,9 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams; import android.view.ViewGroup.LayoutParams;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.ExpandableListView;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
@ -44,9 +41,7 @@ import com.timsu.astrid.R;
import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.service.ContextManager;
import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.activity.FilterListActivity; import com.todoroo.astrid.activity.FilterListActivity;
import com.todoroo.astrid.activity.TaskListWrapperActivity;
import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.AstridFilterExposer; import com.todoroo.astrid.api.AstridFilterExposer;
import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.Filter;
@ -57,7 +52,7 @@ import com.todoroo.astrid.api.FilterListItem;
import com.todoroo.astrid.api.FilterWithUpdate; import com.todoroo.astrid.api.FilterWithUpdate;
import com.todoroo.astrid.service.TaskService; import com.todoroo.astrid.service.TaskService;
public class FilterAdapter extends BaseExpandableListAdapter { public class FilterAdapter extends ArrayAdapter<Filter> {
// --- style constants // --- style constants
@ -73,11 +68,10 @@ public class FilterAdapter extends BaseExpandableListAdapter {
protected final Activity activity; protected final Activity activity;
/** owner listview */ /** owner listview */
protected final ExpandableListView listView; protected final ListView listView;
/** list of filters */ /** list of filters */
private final ArrayList<FilterListItem> items; private final ArrayList<FilterListItem> items;
private final FilterArrayAdapter arrayAdapter;
/** display metrics for scaling icons */ /** display metrics for scaling icons */
private final DisplayMetrics metrics = new DisplayMetrics(); private final DisplayMetrics metrics = new DisplayMetrics();
@ -107,16 +101,15 @@ public class FilterAdapter extends BaseExpandableListAdapter {
// if new filters are queued (obviously it cannot be garbage collected if it is possible for new filters to // if new filters are queued (obviously it cannot be garbage collected if it is possible for new filters to
// be added). // be added).
private final ThreadPoolExecutor filterExecutor = new ThreadPoolExecutor(0, 1, 1, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>()); private final ThreadPoolExecutor filterExecutor = new ThreadPoolExecutor(0, 1, 1, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>());
private final Drawable headerBackground;
public FilterAdapter(Activity activity, ExpandableListView listView, public FilterAdapter(Activity activity, ListView listView,
int rowLayout, boolean skipIntentFilters) { int rowLayout, boolean skipIntentFilters) {
this(activity, listView, rowLayout, skipIntentFilters, false); this(activity, listView, rowLayout, skipIntentFilters, false);
} }
public FilterAdapter(Activity activity, ExpandableListView listView, public FilterAdapter(Activity activity, ListView listView,
int rowLayout, boolean skipIntentFilters, boolean selectable) { int rowLayout, boolean skipIntentFilters, boolean selectable) {
super(); super(activity, 0);
DependencyInjectionService.getInstance().inject(this); DependencyInjectionService.getInstance().inject(this);
@ -127,17 +120,10 @@ public class FilterAdapter extends BaseExpandableListAdapter {
this.skipIntentFilters = skipIntentFilters; this.skipIntentFilters = skipIntentFilters;
this.selectable = selectable; this.selectable = selectable;
arrayAdapter = new FilterArrayAdapter(activity);
inflater = (LayoutInflater) activity.getSystemService( inflater = (LayoutInflater) activity.getSystemService(
Context.LAYOUT_INFLATER_SERVICE); Context.LAYOUT_INFLATER_SERVICE);
activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); activity.getWindowManager().getDefaultDisplay().getMetrics(metrics);
listView.setGroupIndicator(
activity.getResources().getDrawable(R.drawable.expander_group));
TypedArray a = activity.obtainStyledAttributes(new int[] { R.attr.asFilterHeaderBackground });
headerBackground = a.getDrawable(0);
} }
private void offerFilter(final Filter filter) { private void offerFilter(final Filter filter) {
@ -164,6 +150,7 @@ public class FilterAdapter extends BaseExpandableListAdapter {
}); });
} }
@Override
public boolean hasStableIds() { public boolean hasStableIds() {
return true; return true;
} }
@ -180,9 +167,9 @@ public class FilterAdapter extends BaseExpandableListAdapter {
} }
} }
@Override
public void clear() { public void clear() {
items.clear(); items.clear();
arrayAdapter.clear();
notifyDataSetInvalidated(); notifyDataSetInvalidated();
} }
@ -223,71 +210,22 @@ public class FilterAdapter extends BaseExpandableListAdapter {
public View decoration; public View decoration;
} }
/* ======================================================================
* ========================================================== child nodes
* ====================================================================== */
public Object getChild(int groupPosition, int childPosition) {
FilterListItem item = items.get(groupPosition);
if(!(item instanceof FilterCategory) || ((FilterCategory)item).children == null)
return null;
return ((FilterCategory)item).children[childPosition]; @Override
} public View getView(int position, View convertView, ViewGroup parent) {
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
public int getChildrenCount(int groupPosition) {
FilterListItem item = items.get(groupPosition);
if(!(item instanceof FilterCategory))
return 0;
return ((FilterCategory)item).children.length;
}
public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
View convertView, ViewGroup parent) {
convertView = newView(convertView, parent); convertView = newView(convertView, parent);
ViewHolder viewHolder = (ViewHolder) convertView.getTag(); ViewHolder viewHolder = (ViewHolder) convertView.getTag();
viewHolder.item = (FilterListItem) getChild(groupPosition, childPosition); viewHolder.item = (FilterListItem) getItem(position);
populateView(viewHolder, false); populateView(viewHolder, false);
return convertView; return convertView;
} }
/* ====================================================================== @Override
* ========================================================= parent nodes public View getDropDownView(int position, View convertView, ViewGroup parent) {
* ====================================================================== */ return getView(position, convertView, parent);
public Object getGroup(int groupPosition) {
if(groupPosition >= items.size())
return null;
return items.get(groupPosition);
}
public int getGroupCount() {
return items.size();
}
public long getGroupId(int groupPosition) {
return groupPosition;
}
public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
ViewGroup parent) {
convertView = newView(convertView, parent);
ViewHolder viewHolder = (ViewHolder) convertView.getTag();
viewHolder.item = (FilterListItem) getGroup(groupPosition);
populateView(viewHolder, isExpanded);
return convertView;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
} }
/* ====================================================================== /* ======================================================================
* ============================================================ selection * ============================================================ selection
* ====================================================================== */ * ====================================================================== */
@ -363,23 +301,13 @@ public class FilterAdapter extends BaseExpandableListAdapter {
if (filter instanceof FilterCategory) { if (filter instanceof FilterCategory) {
Filter[] children = ((FilterCategory) filter).children; Filter[] children = ((FilterCategory) filter).children;
for (Filter f : children) { for (Filter f : children) {
arrayAdapter.add(f); add(f);
} }
} else if (filter instanceof Filter){ } else if (filter instanceof Filter){
arrayAdapter.add((Filter) filter); add((Filter) filter);
} }
} }
notifyDataSetChanged(); notifyDataSetChanged();
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
expandList(filters);
if (activity instanceof TaskListWrapperActivity) {
((TaskListWrapperActivity) activity).updateDropdownNav(arrayAdapter);
}
}
});
} }
} }
@ -405,7 +333,7 @@ public class FilterAdapter extends BaseExpandableListAdapter {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if (shouldUseBladeFilter && getGroupCount() == 0 && filterExposerList != null && filterExposerList.size()>0) { if (shouldUseBladeFilter && getCount() == 0 && filterExposerList != null && filterExposerList.size()>0) {
try { try {
for (ResolveInfo filterExposerInfo : filterExposerList) { for (ResolveInfo filterExposerInfo : filterExposerList) {
Log.d("BladeFilterReceiver", filterExposerInfo.toString()); Log.d("BladeFilterReceiver", filterExposerInfo.toString());
@ -426,37 +354,6 @@ public class FilterAdapter extends BaseExpandableListAdapter {
} }
} }
/**
* Expand the category filters in this group according to preference
* @param filters
*/
protected void expandList(Parcelable[] filters) {
for(Parcelable filter : filters) {
if(filter instanceof FilterCategory) {
String preference = createExpansionPreference((FilterCategory) filter);
if(!Preferences.getBoolean(preference, true))
continue;
int count = getGroupCount();
for(int i = 0; i < count; i++)
if(getGroup(i) == filter) {
listView.expandGroup(i);
break;
}
}
}
}
/**
* Call to save user preference for whether a node is expanded
* @param category
* @param expanded
*/
public void saveExpansionSetting(FilterCategory category, boolean expanded) {
String preference = createExpansionPreference(category);
Preferences.setBoolean(preference, expanded);
}
/** /**
* Broadcast a request for lists. The request is sent to every * Broadcast a request for lists. The request is sent to every
* application registered to listen for this broadcast. Each application * application registered to listen for this broadcast. Each application
@ -485,7 +382,7 @@ public class FilterAdapter extends BaseExpandableListAdapter {
IntentFilter bladeFilter = new IntentFilter(AstridApiConstants.BROADCAST_SEND_FILTERS); IntentFilter bladeFilter = new IntentFilter(AstridApiConstants.BROADCAST_SEND_FILTERS);
bladeFilter.setPriority(1); bladeFilter.setPriority(1);
activity.registerReceiver(bladeFilterReceiver, bladeFilter); activity.registerReceiver(bladeFilterReceiver, bladeFilter);
if(getGroupCount() == 0) if(getCount() == 0)
getLists(); getLists();
} }
@ -524,7 +421,6 @@ public class FilterAdapter extends BaseExpandableListAdapter {
if(viewHolder.item instanceof FilterListHeader || viewHolder.item instanceof FilterCategory) { if(viewHolder.item instanceof FilterListHeader || viewHolder.item instanceof FilterCategory) {
viewHolder.name.setTextAppearance(activity, headerStyle); viewHolder.name.setTextAppearance(activity, headerStyle);
viewHolder.name.setShadowLayer(1, 1, 1, Color.BLACK); viewHolder.name.setShadowLayer(1, 1, 1, Color.BLACK);
viewHolder.view.setBackgroundDrawable(headerBackground);
viewHolder.view.setPadding((int) (7 * metrics.density), 5, 0, 5); viewHolder.view.setPadding((int) (7 * metrics.density), 5, 0, 5);
viewHolder.view.getLayoutParams().height = (int) (40 * metrics.density); viewHolder.view.getLayoutParams().height = (int) (40 * metrics.density);
} else { } else {
@ -616,7 +512,6 @@ public class FilterAdapter extends BaseExpandableListAdapter {
activity.runOnUiThread(new Runnable() { activity.runOnUiThread(new Runnable() {
public void run() { public void run() {
clear(); clear();
arrayAdapter.clear();
} }
}); });
} }
@ -627,28 +522,4 @@ public class FilterAdapter extends BaseExpandableListAdapter {
} }
}); });
} }
private class FilterArrayAdapter extends ArrayAdapter<Filter> {
public FilterArrayAdapter(Context context) {
super(context, 0);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView = newView(convertView, parent);
ViewHolder viewHolder = (ViewHolder) convertView.getTag();
viewHolder.item = (FilterListItem) getItem(position);
populateView(viewHolder, false);
viewHolder.name.setTextColor(Color.WHITE);
return convertView;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
return getView(position, convertView, parent);
}
}
} }

@ -1,6 +1,6 @@
package com.todoroo.astrid.widget; package com.todoroo.astrid.widget;
import android.app.ExpandableListActivity; import android.app.ListActivity;
import android.appwidget.AppWidgetManager; import android.appwidget.AppWidgetManager;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Intent; import android.content.Intent;
@ -8,21 +8,20 @@ import android.os.Bundle;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.view.View; import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.ExpandableListView; import android.widget.ListView;
import com.timsu.astrid.R; import com.timsu.astrid.R;
import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.Preferences; import com.todoroo.andlib.utility.Preferences;
import com.todoroo.astrid.adapter.FilterAdapter; import com.todoroo.astrid.adapter.FilterAdapter;
import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.FilterCategory;
import com.todoroo.astrid.api.FilterListItem; import com.todoroo.astrid.api.FilterListItem;
import com.todoroo.astrid.api.FilterWithCustomIntent; import com.todoroo.astrid.api.FilterWithCustomIntent;
import com.todoroo.astrid.service.StatisticsConstants; import com.todoroo.astrid.service.StatisticsConstants;
import com.todoroo.astrid.service.StatisticsService; import com.todoroo.astrid.service.StatisticsService;
@SuppressWarnings("nls") @SuppressWarnings("nls")
abstract public class WidgetConfigActivity extends ExpandableListActivity { abstract public class WidgetConfigActivity extends ListActivity {
static final String PREF_TITLE = "widget-title-"; static final String PREF_TITLE = "widget-title-";
static final String PREF_SQL = "widget-sql-"; static final String PREF_SQL = "widget-sql-";
@ -67,7 +66,7 @@ abstract public class WidgetConfigActivity extends ExpandableListActivity {
} }
// set up ui // set up ui
adapter = new FilterAdapter(this, getExpandableListView(), adapter = new FilterAdapter(this, getListView(),
R.layout.filter_adapter_row, true, true); R.layout.filter_adapter_row, true, true);
setListAdapter(adapter); setListAdapter(adapter);
@ -92,33 +91,13 @@ abstract public class WidgetConfigActivity extends ExpandableListActivity {
} }
}; };
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
FilterListItem item = (FilterListItem) adapter.getChild(groupPosition,
childPosition);
if(item instanceof Filter) {
adapter.setSelection(item);
}
return true;
}
@Override
public void onGroupExpand(int groupPosition) {
FilterListItem item = (FilterListItem) adapter.getGroup(groupPosition);
if(item instanceof Filter)
adapter.setSelection(item);
else if(item instanceof FilterCategory)
adapter.saveExpansionSetting((FilterCategory) item, true);
}
@Override @Override
public void onGroupCollapse(int groupPosition) { protected void onListItemClick(ListView l, View v, int position, long id) {
FilterListItem item = (FilterListItem) adapter.getGroup(groupPosition); super.onListItemClick(l, v, position, id);
if(item instanceof Filter) Filter item = adapter.getItem(position);
adapter.setSelection(item); adapter.setSelection(item);
else if(item instanceof FilterCategory)
adapter.saveExpansionSetting((FilterCategory) item, false);
} }
@Override @Override

Loading…
Cancel
Save