From dd6a3fa98cde6fc49da61724b56adb22634427f4 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Mon, 11 Feb 2013 16:46:08 -0800 Subject: [PATCH] Directly populate filters on demand using the same logic as the old BladeFilterReceiver. Fixes bugs where there could be long delays in populating the list of lists --- .../todoroo/astrid/adapter/FilterAdapter.java | 89 +++++-------------- 1 file changed, 21 insertions(+), 68 deletions(-) diff --git a/astrid/src/com/todoroo/astrid/adapter/FilterAdapter.java b/astrid/src/com/todoroo/astrid/adapter/FilterAdapter.java index a22ec662e..7e01d1813 100644 --- a/astrid/src/com/todoroo/astrid/adapter/FilterAdapter.java +++ b/astrid/src/com/todoroo/astrid/adapter/FilterAdapter.java @@ -91,8 +91,6 @@ public class FilterAdapter extends ArrayAdapter { /** receiver for new filters */ protected final FilterReceiver filterReceiver = new FilterReceiver(); - private final BladeFilterReceiver bladeFilterReceiver = new BladeFilterReceiver(); - private boolean shouldUseBladeFilter = true; /** row layout to inflate */ private final int layout; @@ -370,18 +368,30 @@ public class FilterAdapter extends ArrayAdapter { * */ public class FilterReceiver extends BroadcastReceiver { + private final List filterExposerList; + + public FilterReceiver() { + // query astrids AndroidManifest.xml for all registered default-receivers to expose filters + PackageManager pm = ContextManager.getContext().getPackageManager(); + filterExposerList = pm.queryBroadcastReceivers( + new Intent(AstridApiConstants.BROADCAST_REQUEST_FILTERS), + PackageManager.MATCH_DEFAULT_ONLY); + } + @Override public void onReceive(Context context, Intent intent) { try { - Bundle extras = intent.getExtras(); - extras.setClassLoader(FilterListHeader.class.getClassLoader()); - final Parcelable[] filters = extras.getParcelableArray(AstridApiConstants.EXTRAS_RESPONSE); - populateFiltersToAdapter(filters); - shouldUseBladeFilter = getCount() == 0; + for (ResolveInfo filterExposerInfo : filterExposerList) { + String className = filterExposerInfo.activityInfo.name; + AstridFilterExposer filterExposer = null; + filterExposer = (AstridFilterExposer) Class.forName(className, true, FilterAdapter.class.getClassLoader()).newInstance(); + + if (filterExposer != null) { + populateFiltersToAdapter(filterExposer.getFilters()); + } + } } catch (Exception e) { - Log.e("receive-filter-" + //$NON-NLS-1$ - intent.getStringExtra(AstridApiConstants.EXTRAS_ADDON), - e.toString(), e); + e.printStackTrace(); } } @@ -411,50 +421,6 @@ public class FilterAdapter extends ArrayAdapter { } } - /** - * Receiver which gets called after the FilterReceiver - * and checks if the filters are populated. - * If they aren't (e.g. due to the bug in the ZTE Blade's Parcelable-system throwing a - * ClassNotFoundExeption), the filters are fetched manually. - * - * @author Arne Jans - * - */ - public class BladeFilterReceiver extends FilterReceiver { - private final List filterExposerList; - - public BladeFilterReceiver() { - // query astrids AndroidManifest.xml for all registered default-receivers to expose filters - PackageManager pm = ContextManager.getContext().getPackageManager(); - filterExposerList = pm.queryBroadcastReceivers( - new Intent(AstridApiConstants.BROADCAST_REQUEST_FILTERS), - PackageManager.MATCH_DEFAULT_ONLY); - } - - @SuppressWarnings("nls") - @Override - public void onReceive(Context context, Intent intent) { - if (shouldUseBladeFilter && getCount() == 0 && filterExposerList != null && filterExposerList.size()>0) { - try { - for (ResolveInfo filterExposerInfo : filterExposerList) { - Log.d("BladeFilterReceiver", filterExposerInfo.toString()); - String className = filterExposerInfo.activityInfo.name; - AstridFilterExposer filterExposer = null; - filterExposer = (AstridFilterExposer) Class.forName(className, true, FilterAdapter.class.getClassLoader()).newInstance(); - - if (filterExposer != null) { - populateFiltersToAdapter(filterExposer.getFilters()); - } - } - } catch (Exception e) { - Log.e("receive-bladefilter-" + //$NON-NLS-1$ - intent.getStringExtra(AstridApiConstants.EXTRAS_ADDON), - e.toString(), e); - } - } - } - } - @Override public void notifyDataSetChanged() { super.notifyDataSetChanged(); @@ -468,16 +434,7 @@ public class FilterAdapter extends ArrayAdapter { * can then add lists to this activity */ public void getLists() { - Intent broadcastIntent = new Intent(AstridApiConstants.BROADCAST_REQUEST_FILTERS); -// activity.sendOrderedBroadcast(broadcastIntent, AstridApiConstants.PERMISSION_READ); - // the bladeFilterReceiver will be called after the usual FilterReceiver has finished (to handle the empty list) - activity.sendOrderedBroadcast(broadcastIntent, - AstridApiConstants.PERMISSION_READ, - bladeFilterReceiver, - null, - Activity.RESULT_OK, - null, - null); + filterReceiver.onReceive(activity, null); } /** @@ -487,9 +444,6 @@ public class FilterAdapter extends ArrayAdapter { IntentFilter regularFilter = new IntentFilter(AstridApiConstants.BROADCAST_SEND_FILTERS); regularFilter.setPriority(2); activity.registerReceiver(filterReceiver, regularFilter); - IntentFilter bladeFilter = new IntentFilter(AstridApiConstants.BROADCAST_SEND_FILTERS); - bladeFilter.setPriority(1); - activity.registerReceiver(bladeFilterReceiver, bladeFilter); getLists(); } @@ -498,7 +452,6 @@ public class FilterAdapter extends ArrayAdapter { */ public void unregisterRecevier() { activity.unregisterReceiver(filterReceiver); - activity.unregisterReceiver(bladeFilterReceiver); } /**