From a6a1a9fcff7216a03ff293f458d29a64eea7bd75 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Thu, 19 Jan 2012 15:43:06 -0800 Subject: [PATCH] Added a refresh receiver to the filterlist fragment to refresh lists after sync --- .../astrid/activity/FilterListActivity.java | 37 ++++++++++++++++++- .../todoroo/astrid/adapter/FilterAdapter.java | 24 ++---------- 2 files changed, 39 insertions(+), 22 deletions(-) diff --git a/astrid/src/com/todoroo/astrid/activity/FilterListActivity.java b/astrid/src/com/todoroo/astrid/activity/FilterListActivity.java index 03368baf3..dd3c982c7 100644 --- a/astrid/src/com/todoroo/astrid/activity/FilterListActivity.java +++ b/astrid/src/com/todoroo/astrid/activity/FilterListActivity.java @@ -6,8 +6,11 @@ package com.todoroo.astrid.activity; import android.app.Activity; import android.app.AlertDialog; import android.app.SearchManager; +import android.content.BroadcastReceiver; +import android.content.Context; import android.content.DialogInterface; import android.content.Intent; +import android.content.IntentFilter; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Rect; @@ -73,11 +76,9 @@ public class FilterListActivity extends ListFragment { private static final int MENU_SEARCH_ID = R.string.FLA_menu_search; private static final int MENU_HELP_ID = R.string.FLA_menu_help; - private static final int MENU_REFRESH_ID = R.string.actfm_FLA_menu_refresh; private static final int MENU_NEW_FILTER_ID = R.string.FLA_new_filter; private static final int MENU_NEW_LIST_ID = R.string.FLA_new_list; - private static final String LAST_TAG_REFRESH_KEY = "last_tag_refresh"; //$NON-NLS-1$ private static final int CONTEXT_MENU_SHORTCUT = R.string.FLA_context_shortcut; private static final int CONTEXT_MENU_INTENT = Menu.FIRST + 4; @@ -93,6 +94,8 @@ public class FilterListActivity extends ListFragment { protected FilterAdapter adapter = null; private boolean mDualFragments; + private final RefreshReceiver refreshReceiver = new RefreshReceiver(); + private OnFilterItemClickedListener mListener; /* ====================================================================== @@ -268,6 +271,9 @@ public class FilterListActivity extends ListFragment { ((TaskListWrapperActivity) activity).setupPopoverWithFilterList(this); } + activity.registerReceiver(refreshReceiver, + new IntentFilter(AstridApiConstants.BROADCAST_EVENT_REFRESH)); + } @Override @@ -276,6 +282,11 @@ public class FilterListActivity extends ListFragment { super.onPause(); if(adapter != null) adapter.unregisterRecevier(); + try { + getActivity().unregisterReceiver(refreshReceiver); + } catch (IllegalArgumentException e) { + // Might not have fully initialized + } } /* ====================================================================== @@ -477,4 +488,26 @@ public class FilterListActivity extends ListFragment { super.onActivityResult(requestCode, resultCode, data); } + + /** + * Receiver which receives refresh intents + * + * @author Tim Su + * + */ + protected class RefreshReceiver extends BroadcastReceiver { + @Override + public void onReceive(Context context, Intent intent) { + if(intent == null || !AstridApiConstants.BROADCAST_EVENT_REFRESH.equals(intent.getAction())) + return; + + getActivity().runOnUiThread(new Runnable() { + @Override + public void run() { + adapter.clear(); + adapter.getLists(); + } + }); + } + } } diff --git a/astrid/src/com/todoroo/astrid/adapter/FilterAdapter.java b/astrid/src/com/todoroo/astrid/adapter/FilterAdapter.java index 2a68e7805..b1f8af8cf 100644 --- a/astrid/src/com/todoroo/astrid/adapter/FilterAdapter.java +++ b/astrid/src/com/todoroo/astrid/adapter/FilterAdapter.java @@ -5,7 +5,6 @@ package com.todoroo.astrid.adapter; import greendroid.widget.AsyncImageView; -import java.util.ArrayList; import java.util.List; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; @@ -70,9 +69,6 @@ public class FilterAdapter extends ArrayAdapter { /** owner listview */ protected final ListView listView; - /** list of filters */ - private final ArrayList items; - /** display metrics for scaling icons */ private final DisplayMetrics metrics = new DisplayMetrics(); @@ -114,7 +110,6 @@ public class FilterAdapter extends ArrayAdapter { DependencyInjectionService.getInstance().inject(this); this.activity = activity; - this.items = new ArrayList(); this.listView = listView; this.layout = rowLayout; this.skipIntentFilters = skipIntentFilters; @@ -155,23 +150,14 @@ public class FilterAdapter extends ArrayAdapter { return true; } - public void add(FilterListItem item) { - items.add(item); + @Override + public void add(Filter item) { + super.add(item); // load sizes - if(item instanceof Filter) { - offerFilter((Filter)item); - } else if(item instanceof FilterCategory) { - for(Filter filter : ((FilterCategory)item).children) - offerFilter(filter); - } + offerFilter(item); } - @Override - public void clear() { - items.clear(); - notifyDataSetInvalidated(); - } /** * Create or reuse a view @@ -294,8 +280,6 @@ public class FilterAdapter extends ArrayAdapter { filter instanceof FilterListHeader || filter instanceof FilterCategory)) continue; - - add((FilterListItem)item); onReceiveFilter((FilterListItem)item); if (filter instanceof FilterCategory) {