Added a refresh receiver to the filterlist fragment to refresh lists after sync

pull/14/head
Sam Bosley 13 years ago
parent a99a484cbb
commit a6a1a9fcff

@ -6,8 +6,11 @@ package com.todoroo.astrid.activity;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.SearchManager; import android.app.SearchManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Rect; 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_SEARCH_ID = R.string.FLA_menu_search;
private static final int MENU_HELP_ID = R.string.FLA_menu_help; 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_FILTER_ID = R.string.FLA_new_filter;
private static final int MENU_NEW_LIST_ID = R.string.FLA_new_list; 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_SHORTCUT = R.string.FLA_context_shortcut;
private static final int CONTEXT_MENU_INTENT = Menu.FIRST + 4; private static final int CONTEXT_MENU_INTENT = Menu.FIRST + 4;
@ -93,6 +94,8 @@ public class FilterListActivity extends ListFragment {
protected FilterAdapter adapter = null; protected FilterAdapter adapter = null;
private boolean mDualFragments; private boolean mDualFragments;
private final RefreshReceiver refreshReceiver = new RefreshReceiver();
private OnFilterItemClickedListener mListener; private OnFilterItemClickedListener mListener;
/* ====================================================================== /* ======================================================================
@ -268,6 +271,9 @@ public class FilterListActivity extends ListFragment {
((TaskListWrapperActivity) activity).setupPopoverWithFilterList(this); ((TaskListWrapperActivity) activity).setupPopoverWithFilterList(this);
} }
activity.registerReceiver(refreshReceiver,
new IntentFilter(AstridApiConstants.BROADCAST_EVENT_REFRESH));
} }
@Override @Override
@ -276,6 +282,11 @@ public class FilterListActivity extends ListFragment {
super.onPause(); super.onPause();
if(adapter != null) if(adapter != null)
adapter.unregisterRecevier(); 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); super.onActivityResult(requestCode, resultCode, data);
} }
/**
* Receiver which receives refresh intents
*
* @author Tim Su <tim@todoroo.com>
*
*/
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();
}
});
}
}
} }

@ -5,7 +5,6 @@ package com.todoroo.astrid.adapter;
import greendroid.widget.AsyncImageView; import greendroid.widget.AsyncImageView;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
@ -70,9 +69,6 @@ public class FilterAdapter extends ArrayAdapter<Filter> {
/** owner listview */ /** owner listview */
protected final ListView listView; protected final ListView listView;
/** list of filters */
private final ArrayList<FilterListItem> items;
/** display metrics for scaling icons */ /** display metrics for scaling icons */
private final DisplayMetrics metrics = new DisplayMetrics(); private final DisplayMetrics metrics = new DisplayMetrics();
@ -114,7 +110,6 @@ public class FilterAdapter extends ArrayAdapter<Filter> {
DependencyInjectionService.getInstance().inject(this); DependencyInjectionService.getInstance().inject(this);
this.activity = activity; this.activity = activity;
this.items = new ArrayList<FilterListItem>();
this.listView = listView; this.listView = listView;
this.layout = rowLayout; this.layout = rowLayout;
this.skipIntentFilters = skipIntentFilters; this.skipIntentFilters = skipIntentFilters;
@ -155,23 +150,14 @@ public class FilterAdapter extends ArrayAdapter<Filter> {
return true; return true;
} }
public void add(FilterListItem item) { @Override
items.add(item); public void add(Filter item) {
super.add(item);
// load sizes // load sizes
if(item instanceof Filter) { offerFilter(item);
offerFilter((Filter)item);
} else if(item instanceof FilterCategory) {
for(Filter filter : ((FilterCategory)item).children)
offerFilter(filter);
}
} }
@Override
public void clear() {
items.clear();
notifyDataSetInvalidated();
}
/** /**
* Create or reuse a view * Create or reuse a view
@ -294,8 +280,6 @@ public class FilterAdapter extends ArrayAdapter<Filter> {
filter instanceof FilterListHeader || filter instanceof FilterListHeader ||
filter instanceof FilterCategory)) filter instanceof FilterCategory))
continue; continue;
add((FilterListItem)item);
onReceiveFilter((FilterListItem)item); onReceiveFilter((FilterListItem)item);
if (filter instanceof FilterCategory) { if (filter instanceof FilterCategory) {

Loading…
Cancel
Save