mirror of https://github.com/tasks/tasks
Search results match on additional fields
Match places, comments, caldav/google task list namespull/996/head
parent
16829dec6c
commit
b955a0435d
@ -1,56 +0,0 @@
|
||||
package com.todoroo.astrid.api;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import com.todoroo.andlib.sql.Criterion;
|
||||
import com.todoroo.andlib.sql.Query;
|
||||
import com.todoroo.andlib.sql.QueryTemplate;
|
||||
import com.todoroo.astrid.data.Task;
|
||||
import org.tasks.data.Tag;
|
||||
|
||||
public class SearchFilter extends Filter {
|
||||
|
||||
/** Parcelable Creator Object */
|
||||
public static final Parcelable.Creator<SearchFilter> CREATOR =
|
||||
new Parcelable.Creator<SearchFilter>() {
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public SearchFilter createFromParcel(Parcel source) {
|
||||
SearchFilter item = new SearchFilter();
|
||||
item.readFromParcel(source);
|
||||
return item;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
public SearchFilter[] newArray(int size) {
|
||||
return new SearchFilter[size];
|
||||
}
|
||||
};
|
||||
|
||||
private SearchFilter() {}
|
||||
|
||||
public SearchFilter(String title, String query) {
|
||||
super(title, getQueryTemplate(query));
|
||||
}
|
||||
|
||||
private static QueryTemplate getQueryTemplate(String query) {
|
||||
return new QueryTemplate()
|
||||
.where(
|
||||
Criterion.and(
|
||||
Task.DELETION_DATE.eq(0),
|
||||
Criterion.or(
|
||||
Task.NOTES.like("%" + query + "%"),
|
||||
Task.TITLE.like("%" + query + "%"),
|
||||
Task.ID.in(
|
||||
Query.select(Tag.TASK)
|
||||
.from(Tag.TABLE)
|
||||
.where(Tag.NAME.like("%" + query + "%"))))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supportsHiddenTasks() {
|
||||
return false;
|
||||
}
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
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.Query
|
||||
import com.todoroo.andlib.sql.QueryTemplate
|
||||
import com.todoroo.astrid.data.Task
|
||||
import org.tasks.data.*
|
||||
|
||||
class SearchFilter : Filter {
|
||||
private constructor()
|
||||
|
||||
constructor(title: String?, query: String) : super(title, getQueryTemplate(query))
|
||||
|
||||
override fun supportsHiddenTasks() = false
|
||||
|
||||
companion object {
|
||||
/** Parcelable Creator Object */
|
||||
@JvmField
|
||||
val CREATOR: Parcelable.Creator<SearchFilter> = object : Parcelable.Creator<SearchFilter> {
|
||||
/** {@inheritDoc} */
|
||||
override fun createFromParcel(source: Parcel): SearchFilter? {
|
||||
val item = SearchFilter()
|
||||
item.readFromParcel(source)
|
||||
return item
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
override fun newArray(size: Int): Array<SearchFilter?> {
|
||||
return arrayOfNulls(size)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getQueryTemplate(query: String): QueryTemplate {
|
||||
val matcher = "%$query%"
|
||||
return QueryTemplate()
|
||||
.where(
|
||||
Criterion.and(
|
||||
Task.DELETION_DATE.eq(0),
|
||||
Criterion.or(
|
||||
Task.NOTES.like(matcher),
|
||||
Task.TITLE.like(matcher),
|
||||
Task.ID.`in`(
|
||||
Query.select(Tag.TASK)
|
||||
.from(Tag.TABLE)
|
||||
.where(Tag.NAME.like(matcher))),
|
||||
Task.UUID.`in`(
|
||||
Query.select(UserActivity.TASK)
|
||||
.from(UserActivity.TABLE)
|
||||
.where(UserActivity.MESSAGE.like(matcher))),
|
||||
Task.ID.`in`(
|
||||
Query.select(Geofence.TASK)
|
||||
.from(Geofence.TABLE)
|
||||
.join(Join.inner(Place.TABLE, Place.UID.eq(Geofence.PLACE)))
|
||||
.where(Criterion.or(Place.NAME.like(matcher),
|
||||
Place.ADDRESS.like(matcher)))),
|
||||
Task.ID.`in`(
|
||||
Query.select(CaldavTask.TASK)
|
||||
.from(CaldavTask.TABLE)
|
||||
.join(Join.inner(CaldavCalendar.TABLE, CaldavCalendar.UUID.eq(CaldavTask.CALENDAR)))
|
||||
.where(CaldavCalendar.NAME.like(matcher))),
|
||||
Task.ID.`in`(
|
||||
Query.select(GoogleTask.TASK)
|
||||
.from(GoogleTask.TABLE)
|
||||
.join(Join.inner(GoogleTaskList.TABLE, GoogleTaskList.REMOTE_ID.eq(GoogleTask.LIST)))
|
||||
.where(GoogleTaskList.NAME.like(matcher)))
|
||||
)))
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue