Search results match on additional fields

Match places, comments, caldav/google task list names
pull/996/head
Alex Baker 5 years ago
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)))
)))
}
}
}

@ -6,6 +6,8 @@ import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.Ignore
import androidx.room.PrimaryKey
import com.todoroo.andlib.data.Property
import com.todoroo.andlib.data.Table
import com.todoroo.astrid.data.Task
import org.tasks.themes.CustomIcons.CLOUD
@ -110,6 +112,9 @@ class CaldavCalendar : Parcelable {
}
companion object {
@JvmField val TABLE = Table("caldav_lists")
@JvmField val UUID = Property.StringProperty(TABLE, "cdl_uuid")
@JvmField val NAME = Property.StringProperty(TABLE, "cdl_name")
@JvmField val CREATOR: Parcelable.Creator<CaldavCalendar> = object : Parcelable.Creator<CaldavCalendar> {
override fun createFromParcel(source: Parcel): CaldavCalendar? {
return CaldavCalendar(source)

@ -6,6 +6,8 @@ import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.Ignore
import androidx.room.PrimaryKey
import com.todoroo.andlib.data.Property
import com.todoroo.andlib.data.Table
import org.tasks.themes.CustomIcons.CLOUD
@Entity(tableName = "google_task_lists")
@ -112,6 +114,9 @@ class GoogleTaskList : Parcelable {
}
companion object {
@JvmField val TABLE = Table("google_task_lists")
@JvmField val REMOTE_ID = Property.StringProperty(TABLE, "gtl_remote_id")
@JvmField val NAME = Property.StringProperty(TABLE, "gtl_title")
@JvmField val CREATOR: Parcelable.Creator<GoogleTaskList> = object : Parcelable.Creator<GoogleTaskList> {
override fun createFromParcel(parcel: Parcel): GoogleTaskList? {
return GoogleTaskList(parcel)

@ -183,6 +183,8 @@ class Place : Serializable, Parcelable {
const val TABLE_NAME = "places"
@JvmField val TABLE = Table(TABLE_NAME)
@JvmField val UID = StringProperty(TABLE, "uid")
@JvmField val NAME = StringProperty(TABLE, "name")
@JvmField val ADDRESS = StringProperty(TABLE, "address")
@JvmField val CREATOR: Parcelable.Creator<Place> = object : Parcelable.Creator<Place> {
override fun createFromParcel(source: Parcel): Place? {
return Place(source)

@ -7,6 +7,8 @@ import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.Ignore
import androidx.room.PrimaryKey
import com.todoroo.andlib.data.Property
import com.todoroo.andlib.data.Table
import com.todoroo.astrid.data.Task
import org.json.JSONException
import org.json.JSONObject
@ -85,6 +87,9 @@ class UserActivity : Parcelable {
}
companion object {
@JvmField val TABLE = Table("userActivity")
@JvmField val TASK = Property.StringProperty(TABLE, "target_id")
@JvmField val MESSAGE = Property.StringProperty(TABLE, "message")
@JvmField val CREATOR: Parcelable.Creator<UserActivity> = object : Parcelable.Creator<UserActivity> {
override fun createFromParcel(source: Parcel): UserActivity? {
return UserActivity(source)

Loading…
Cancel
Save