From 46269525733cb6738bcad9715f3487e424c9e8ce Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Thu, 28 Mar 2013 15:57:02 -0700 Subject: [PATCH] Add waiting on me to the core filter exposer (needs icon) --- .../astrid/core/CoreFilterExposer.java | 56 +++++++++++++++++-- .../astrid/core/CustomFilterExposer.java | 27 --------- .../astrid/subtasks/SubtasksHelper.java | 5 +- astrid/res/values/keys.xml | 1 + astrid/res/values/strings-filters.xml | 3 + astrid/res/xml/preferences.xml | 4 ++ .../astrid/activity/TaskListFragment.java | 3 +- .../utility/AstridDefaultPreferenceSpec.java | 1 + .../utility/AstridLitePreferenceSpec.java | 1 + 9 files changed, 65 insertions(+), 36 deletions(-) diff --git a/astrid/plugin-src/com/todoroo/astrid/core/CoreFilterExposer.java b/astrid/plugin-src/com/todoroo/astrid/core/CoreFilterExposer.java index bc15f2349..f5b6336ed 100644 --- a/astrid/plugin-src/com/todoroo/astrid/core/CoreFilterExposer.java +++ b/astrid/plugin-src/com/todoroo/astrid/core/CoreFilterExposer.java @@ -5,7 +5,11 @@ */ package com.todoroo.astrid.core; +import java.util.ArrayList; +import java.util.List; + import android.content.BroadcastReceiver; +import android.content.ContentValues; import android.content.Context; import android.content.Intent; import android.content.res.Resources; @@ -16,15 +20,19 @@ import com.todoroo.andlib.service.ContextManager; import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.sql.QueryTemplate; +import com.todoroo.andlib.utility.AndroidUtilities; +import com.todoroo.andlib.utility.Preferences; import com.todoroo.astrid.activity.FilterListFragment; import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.AstridFilterExposer; import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.FilterListItem; +import com.todoroo.astrid.api.PermaSql; import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria; import com.todoroo.astrid.dao.TaskDao.TaskCriteria; import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Task; +import com.todoroo.astrid.data.WaitingOnMe; import com.todoroo.astrid.service.ThemeService; import com.todoroo.astrid.tags.TaskToTagMetadata; @@ -49,12 +57,17 @@ public final class CoreFilterExposer extends BroadcastReceiver implements Astrid private FilterListItem[] prepareFilters(Resources r) { // core filters - Filter inbox = buildInboxFilter(r); + List filters = new ArrayList(3); + + filters.add(buildInboxFilter(r)); + if (Preferences.getBoolean(R.string.p_show_today_filter, true)) + filters.add(getTodayFilter(r)); + + if (Preferences.getBoolean(R.string.p_show_waiting_on_me_filter, true)) + filters.add(getWaitingOnMeFilter(r)); // transmit filter list - FilterListItem[] list = new FilterListItem[1]; - list[0] = inbox; - return list; + return filters.toArray(new FilterListItem[filters.size()]); } /** @@ -75,6 +88,37 @@ public final class CoreFilterExposer extends BroadcastReceiver implements Astrid return inbox; } + public static Filter getTodayFilter(Resources r) { + int themeFlags = ThemeService.getFilterThemeFlags(); + String todayTitle = AndroidUtilities.capitalize(r.getString(R.string.today)); + ContentValues todayValues = new ContentValues(); + todayValues.put(Task.DUE_DATE.name, PermaSql.VALUE_NOON); + Filter todayFilter = new Filter(todayTitle, + todayTitle, + new QueryTemplate().where( + Criterion.and(TaskCriteria.activeVisibleMine(), + Task.DUE_DATE.gt(0), + Task.DUE_DATE.lte(PermaSql.VALUE_EOD))), + todayValues); + todayFilter.listingIcon = ((BitmapDrawable)r.getDrawable( + ThemeService.getDrawable(R.drawable.filter_calendar, themeFlags))).getBitmap(); + return todayFilter; + } + + public static Filter getWaitingOnMeFilter(Resources r) { + Filter waitingOnMe = new Filter(r.getString(R.string.BFE_waiting_on_me), r.getString(R.string.BFE_waiting_on_me), + new QueryTemplate().where( + Criterion.and(TaskCriteria.activeVisibleMine(), + Task.UUID.in(Query.select(WaitingOnMe.TASK_UUID) + .from(WaitingOnMe.TABLE).where(WaitingOnMe.DELETED_AT.eq(0))))), null); + + int themeFlags = ThemeService.getFilterThemeFlags(); + waitingOnMe.listingIcon = ((BitmapDrawable) r.getDrawable( + ThemeService.getDrawable(R.drawable.filter_inbox, themeFlags))).getBitmap(); + return waitingOnMe; + + } + /** * Is this the inbox? * @param filter @@ -84,6 +128,10 @@ public final class CoreFilterExposer extends BroadcastReceiver implements Astrid return (filter != null && filter.equals(buildInboxFilter(ContextManager.getContext().getResources()))); } + public static boolean isTodayFilter(Filter filter) { + return (filter != null && filter.equals(getTodayFilter(ContextManager.getContext().getResources()))); + } + @Override public FilterListItem[] getFilters() { if (ContextManager.getContext() == null || ContextManager.getContext().getResources() == null) diff --git a/astrid/plugin-src/com/todoroo/astrid/core/CustomFilterExposer.java b/astrid/plugin-src/com/todoroo/astrid/core/CustomFilterExposer.java index bd59b9c6e..f3ada3bef 100644 --- a/astrid/plugin-src/com/todoroo/astrid/core/CustomFilterExposer.java +++ b/astrid/plugin-src/com/todoroo/astrid/core/CustomFilterExposer.java @@ -9,7 +9,6 @@ import java.util.ArrayList; import android.app.Activity; import android.content.BroadcastReceiver; -import android.content.ContentValues; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -26,7 +25,6 @@ import com.todoroo.andlib.sql.Criterion; import com.todoroo.andlib.sql.Order; import com.todoroo.andlib.sql.Query; import com.todoroo.andlib.sql.QueryTemplate; -import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.DialogUtilities; import com.todoroo.andlib.utility.Preferences; import com.todoroo.astrid.actfm.sync.ActFmPreferenceService; @@ -35,7 +33,6 @@ import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.AstridFilterExposer; import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.FilterListItem; -import com.todoroo.astrid.api.PermaSql; import com.todoroo.astrid.dao.StoreObjectDao; import com.todoroo.astrid.dao.TaskDao.TaskCriteria; import com.todoroo.astrid.data.StoreObject; @@ -76,27 +73,6 @@ public final class CustomFilterExposer extends BroadcastReceiver implements Astr return savedFilters; } - public static Filter getTodayFilter(Resources r) { - int themeFlags = ThemeService.getFilterThemeFlags(); - String todayTitle = AndroidUtilities.capitalize(r.getString(R.string.today)); - ContentValues todayValues = new ContentValues(); - todayValues.put(Task.DUE_DATE.name, PermaSql.VALUE_NOON); - Filter todayFilter = new Filter(todayTitle, - todayTitle, - new QueryTemplate().where( - Criterion.and(TaskCriteria.activeVisibleMine(), - Task.DUE_DATE.gt(0), - Task.DUE_DATE.lte(PermaSql.VALUE_EOD))), - todayValues); - todayFilter.listingIcon = ((BitmapDrawable)r.getDrawable( - ThemeService.getDrawable(R.drawable.filter_calendar, themeFlags))).getBitmap(); - return todayFilter; - } - - public static boolean isTodayFilter(Filter filter) { - return (filter != null && filter.equals(getTodayFilter(ContextManager.getContext().getResources()))); - } - private Filter[] buildSavedFilters(Context context, Resources r) { int themeFlags = ThemeService.getFilterThemeFlags(); @@ -110,9 +86,6 @@ public final class CustomFilterExposer extends BroadcastReceiver implements Astr ArrayList list = new ArrayList(); // stock filters - if (Preferences.getBoolean(R.string.p_show_today_filter, true)) - list.add(getTodayFilter(r)); - if (Preferences.getBoolean(R.string.p_show_recently_modified_filter, true)) { Filter recent = new Filter(r.getString(R.string.BFE_Recent), r.getString(R.string.BFE_Recent), diff --git a/astrid/plugin-src/com/todoroo/astrid/subtasks/SubtasksHelper.java b/astrid/plugin-src/com/todoroo/astrid/subtasks/SubtasksHelper.java index 9e89f59bb..38e1779a1 100644 --- a/astrid/plugin-src/com/todoroo/astrid/subtasks/SubtasksHelper.java +++ b/astrid/plugin-src/com/todoroo/astrid/subtasks/SubtasksHelper.java @@ -16,7 +16,6 @@ import com.todoroo.astrid.actfm.TagViewFragment; import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.FilterWithCustomIntent; import com.todoroo.astrid.core.CoreFilterExposer; -import com.todoroo.astrid.core.CustomFilterExposer; import com.todoroo.astrid.core.PluginServices; import com.todoroo.astrid.core.SortHelper; import com.todoroo.astrid.dao.TaskDao.TaskCriteria; @@ -31,7 +30,7 @@ import com.todoroo.astrid.utility.AstridPreferences; public class SubtasksHelper { public static boolean shouldUseSubtasksFragmentForFilter(Filter filter) { - if(filter == null || CoreFilterExposer.isInbox(filter) || CustomFilterExposer.isTodayFilter(filter) || SubtasksHelper.isTagFilter(filter)) { + if(filter == null || CoreFilterExposer.isInbox(filter) || CoreFilterExposer.isTodayFilter(filter) || SubtasksHelper.isTagFilter(filter)) { SharedPreferences publicPrefs = AstridPreferences.getPublicPrefs(ContextManager.getContext()); int sortFlags = publicPrefs.getInt(SortHelper.PREF_SORT_FLAGS, 0); if(SortHelper.isManualSort(sortFlags)) @@ -67,7 +66,7 @@ public class SubtasksHelper { tlm = tlmd.fetchByTagId(tagData.getUuid(), TaskListMetadata.TASK_IDS); } else if (CoreFilterExposer.isInbox(filter)) { tlm = tlmd.fetchByTagId(TaskListMetadata.FILTER_ID_ALL, TaskListMetadata.TASK_IDS); - } else if (CustomFilterExposer.isTodayFilter(filter)) { + } else if (CoreFilterExposer.isTodayFilter(filter)) { tlm = tlmd.fetchByTagId(TaskListMetadata.FILTER_ID_TODAY, TaskListMetadata.TASK_IDS); } diff --git a/astrid/res/values/keys.xml b/astrid/res/values/keys.xml index e1d1fab35..421117ef9 100644 --- a/astrid/res/values/keys.xml +++ b/astrid/res/values/keys.xml @@ -73,6 +73,7 @@ p_filters_to_show p_show_my_tasks_f p_show_today_f + p_show_waiting_on_me_f p_show_recently_modified_f p_show_assigned_f p_show_no_list_f diff --git a/astrid/res/values/strings-filters.xml b/astrid/res/values/strings-filters.xml index 25e57115e..9bc5c37ac 100644 --- a/astrid/res/values/strings-filters.xml +++ b/astrid/res/values/strings-filters.xml @@ -12,6 +12,9 @@ My Tasks + + + Waiting On Me diff --git a/astrid/res/xml/preferences.xml b/astrid/res/xml/preferences.xml index ec8ad0785..b4ddd2be6 100644 --- a/astrid/res/xml/preferences.xml +++ b/astrid/res/xml/preferences.xml @@ -133,6 +133,10 @@ android:key="@string/p_show_today_filter" android:title="@string/today" android:defaultValue="true"/> +