|
|
|
|
@ -31,58 +31,58 @@ import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
|
import javax.inject.Singleton;
|
|
|
|
|
|
|
|
|
|
@Singleton
|
|
|
|
|
public final class BuiltInFilters {
|
|
|
|
|
/**
|
|
|
|
|
* Exposes Astrid's built in filters to the NavigationDrawerFragment
|
|
|
|
|
*
|
|
|
|
|
* @author Tim Su <tim@todoroo.com>
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
public final class BuiltInFilterExposer {
|
|
|
|
|
|
|
|
|
|
private final Filter myTasks;
|
|
|
|
|
private final Filter today;
|
|
|
|
|
private final Filter recentlyModified;
|
|
|
|
|
private final Filter uncategorized;
|
|
|
|
|
private final Preferences preferences;
|
|
|
|
|
private final Context context;
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
|
public BuiltInFilters(@ForApplication Context context) {
|
|
|
|
|
Resources resources = context.getResources();
|
|
|
|
|
|
|
|
|
|
myTasks = getMyTasksFilter(resources);
|
|
|
|
|
myTasks.icon = R.drawable.ic_inbox_24dp;
|
|
|
|
|
|
|
|
|
|
today = getTodayFilter(resources);
|
|
|
|
|
today.icon = R.drawable.ic_today_24dp;
|
|
|
|
|
|
|
|
|
|
recentlyModified = getRecentlyModifiedFilter(resources);
|
|
|
|
|
recentlyModified.icon = R.drawable.ic_history_24dp;
|
|
|
|
|
|
|
|
|
|
uncategorized = getUncategorizedFilter(resources);
|
|
|
|
|
uncategorized.icon = R.drawable.ic_label_outline_24dp;
|
|
|
|
|
public BuiltInFilterExposer(@ForApplication Context context, Preferences preferences) {
|
|
|
|
|
this.context = context;
|
|
|
|
|
this.preferences = preferences;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Filter getMyTasks() {
|
|
|
|
|
return myTasks;
|
|
|
|
|
public Filter getMyTasksFilter() {
|
|
|
|
|
Filter myTasksFilter = getMyTasksFilter(context.getResources());
|
|
|
|
|
myTasksFilter.icon = R.drawable.ic_inbox_24dp;
|
|
|
|
|
return myTasksFilter;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Filter getToday() {
|
|
|
|
|
return today;
|
|
|
|
|
}
|
|
|
|
|
public List<Filter> getFilters() {
|
|
|
|
|
Resources r = context.getResources();
|
|
|
|
|
// core filters
|
|
|
|
|
List<Filter> filters = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
public Filter getRecentlyModified() {
|
|
|
|
|
return recentlyModified;
|
|
|
|
|
if (preferences.getBoolean(R.string.p_show_today_filter, true)) {
|
|
|
|
|
Filter todayFilter = getTodayFilter(r);
|
|
|
|
|
todayFilter.icon = R.drawable.ic_today_24dp;
|
|
|
|
|
filters.add(todayFilter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Filter getUncategorized() {
|
|
|
|
|
return uncategorized;
|
|
|
|
|
if (preferences.getBoolean(R.string.p_show_recently_modified_filter, true)) {
|
|
|
|
|
Filter recentlyModifiedFilter = getRecentlyModifiedFilter(r);
|
|
|
|
|
recentlyModifiedFilter.icon = R.drawable.ic_history_24dp;
|
|
|
|
|
filters.add(recentlyModifiedFilter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isMyTasksFilter(Filter filter) {
|
|
|
|
|
return myTasks.equals(filter);
|
|
|
|
|
if (preferences.getBoolean(R.string.p_show_not_in_list_filter, true)) {
|
|
|
|
|
Filter uncategorizedFilter = getUncategorizedFilter(r);
|
|
|
|
|
uncategorizedFilter.icon = R.drawable.ic_label_outline_24dp;
|
|
|
|
|
filters.add(uncategorizedFilter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isTodayFilter(Filter filter) {
|
|
|
|
|
return today.equals(filter);
|
|
|
|
|
// transmit filter list
|
|
|
|
|
return filters;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Filter getMyTasksFilter(Resources r) {
|
|
|
|
|
/**
|
|
|
|
|
* Build inbox filter
|
|
|
|
|
*/
|
|
|
|
|
public static Filter getMyTasksFilter(Resources r) {
|
|
|
|
|
return new Filter(r.getString(R.string.BFE_Active),
|
|
|
|
|
new QueryTemplate().where(
|
|
|
|
|
Criterion.and(TaskCriteria.activeAndVisible(),
|
|
|
|
|
@ -121,4 +121,15 @@ public final class BuiltInFilters {
|
|
|
|
|
TaskCriteria.isVisible())),
|
|
|
|
|
null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Is this the inbox?
|
|
|
|
|
*/
|
|
|
|
|
public static boolean isInbox(Context context, Filter filter) {
|
|
|
|
|
return (filter != null && filter.equals(getMyTasksFilter(context.getResources())));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean isTodayFilter(Context context, Filter filter) {
|
|
|
|
|
return (filter != null && filter.equals(getTodayFilter(context.getResources())));
|
|
|
|
|
}
|
|
|
|
|
}
|