Move search query to filter

gtask_related_email
Alex Baker 5 years ago
parent 21b3cba8e3
commit a703fa30a0

@ -42,9 +42,6 @@ import butterknife.ButterKnife;
import butterknife.OnClick;
import com.google.android.material.snackbar.Snackbar;
import com.google.common.primitives.Longs;
import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Join;
import com.todoroo.andlib.sql.QueryTemplate;
import com.todoroo.astrid.adapter.TaskAdapter;
import com.todoroo.astrid.adapter.TaskAdapterProvider;
import com.todoroo.astrid.api.CaldavFilter;
@ -76,7 +73,6 @@ import org.tasks.activities.TagSettingsActivity;
import org.tasks.analytics.Tracker;
import org.tasks.analytics.Tracking;
import org.tasks.caldav.CaldavCalendarSettingsActivity;
import org.tasks.data.Tag;
import org.tasks.dialogs.DialogBuilder;
import org.tasks.dialogs.SortDialog;
import org.tasks.injection.ForActivity;
@ -343,18 +339,7 @@ public final class TaskListFragment extends InjectingFragment
}
private Filter createSearchFilter(String query) {
String title = getString(R.string.FLA_search_filter, query);
return new SearchFilter(
title,
new QueryTemplate()
.join(Join.left(Tag.TABLE, Tag.TASK_UID.eq(Task.UUID)))
.where(
Criterion.and(
Task.DELETION_DATE.eq(0),
Criterion.or(
Task.NOTES.like("%" + query + "%"),
Task.TITLE.like("%" + query + "%"),
Tag.NAME.like("%" + query + "%")))));
return new SearchFilter(getString(R.string.FLA_search_filter, query), query);
}
@Override

@ -2,7 +2,11 @@ package com.todoroo.astrid.api;
import android.os.Parcel;
import android.os.Parcelable;
import com.todoroo.andlib.sql.Criterion;
import com.todoroo.andlib.sql.Join;
import com.todoroo.andlib.sql.QueryTemplate;
import com.todoroo.astrid.data.Task;
import org.tasks.data.Tag;
public class SearchFilter extends Filter {
@ -27,7 +31,19 @@ public class SearchFilter extends Filter {
private SearchFilter() {}
public SearchFilter(String title, QueryTemplate where) {
super(title, where);
public SearchFilter(String title, String query) {
super(title, getQueryTemplate(query));
}
private static QueryTemplate getQueryTemplate(String query) {
return new QueryTemplate()
.join(Join.left(Tag.TABLE, Tag.TASK.eq(Task.ID)))
.where(
Criterion.and(
Task.DELETION_DATE.eq(0),
Criterion.or(
Task.NOTES.like("%" + query + "%"),
Task.TITLE.like("%" + query + "%"),
Tag.NAME.like("%" + query + "%"))));
}
}

@ -21,7 +21,6 @@ public class Tag {
public static final LongProperty TASK = new LongProperty(TABLE, "task");
public static final StringProperty TAG_UID = new StringProperty(TABLE, "tag_uid");
public static final StringProperty TASK_UID = new StringProperty(TABLE, "task_uid");
public static final StringProperty NAME = new StringProperty(TABLE, "name");
@PrimaryKey(autoGenerate = true)

Loading…
Cancel
Save