mirror of https://github.com/tasks/tasks
Android Studio 4.2 Beta 5
parent
2b6e65cca4
commit
379bf3856f
@ -1,58 +0,0 @@
|
||||
package com.todoroo.astrid.api;
|
||||
|
||||
import android.os.Parcel;
|
||||
import com.google.common.primitives.Longs;
|
||||
import com.todoroo.andlib.sql.Join;
|
||||
import com.todoroo.andlib.sql.QueryTemplate;
|
||||
import com.todoroo.astrid.data.Task;
|
||||
import java.util.List;
|
||||
import org.tasks.data.Tag;
|
||||
|
||||
public class IdListFilter extends Filter {
|
||||
|
||||
public static final Creator<IdListFilter> CREATOR =
|
||||
new Creator<IdListFilter>() {
|
||||
|
||||
@Override
|
||||
public IdListFilter createFromParcel(Parcel source) {
|
||||
return new IdListFilter(source);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdListFilter[] newArray(int size) {
|
||||
return new IdListFilter[size];
|
||||
}
|
||||
};
|
||||
|
||||
private List<Long> ids;
|
||||
|
||||
public IdListFilter(List<Long> ids) {
|
||||
super("", getQueryTemplate(ids));
|
||||
this.ids = ids;
|
||||
}
|
||||
|
||||
private IdListFilter(Parcel source) {
|
||||
readFromParcel(source);
|
||||
}
|
||||
|
||||
private static QueryTemplate getQueryTemplate(List<Long> ids) {
|
||||
return new QueryTemplate()
|
||||
.join(Join.left(Tag.TABLE, Tag.TASK.eq(Task.ID)))
|
||||
.where(Task.ID.in(ids));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags) {
|
||||
super.writeToParcel(dest, flags);
|
||||
dest.writeLongArray(Longs.toArray(ids));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readFromParcel(Parcel source) {
|
||||
super.readFromParcel(source);
|
||||
long[] ids = new long[source.readInt()];
|
||||
source.setDataPosition(source.dataPosition() - 1);
|
||||
source.readLongArray(ids);
|
||||
this.ids = Longs.asList(ids);
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.todoroo.astrid.api
|
||||
|
||||
import android.os.Parcel
|
||||
import android.os.Parcelable
|
||||
import com.google.common.primitives.Longs
|
||||
import com.todoroo.andlib.sql.Join.Companion.left
|
||||
import com.todoroo.andlib.sql.QueryTemplate
|
||||
import com.todoroo.astrid.data.Task
|
||||
import org.tasks.data.Tag
|
||||
|
||||
class IdListFilter : Filter {
|
||||
private var ids: List<Long?>? = null
|
||||
|
||||
constructor(ids: List<Long?>) : super("", getQueryTemplate(ids)) {
|
||||
this.ids = ids
|
||||
}
|
||||
|
||||
private constructor(source: Parcel) {
|
||||
readFromParcel(source)
|
||||
}
|
||||
|
||||
override fun writeToParcel(dest: Parcel, flags: Int) {
|
||||
super.writeToParcel(dest, flags)
|
||||
dest.writeLongArray(Longs.toArray(ids!!))
|
||||
}
|
||||
|
||||
override fun readFromParcel(source: Parcel) {
|
||||
super.readFromParcel(source)
|
||||
val ids = LongArray(source.readInt())
|
||||
source.setDataPosition(source.dataPosition() - 1)
|
||||
source.readLongArray(ids)
|
||||
this.ids = Longs.asList(*ids)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmField val CREATOR: Parcelable.Creator<IdListFilter> = object : Parcelable.Creator<IdListFilter> {
|
||||
override fun createFromParcel(source: Parcel) = IdListFilter(source)
|
||||
|
||||
override fun newArray(size: Int): Array<IdListFilter?> = arrayOfNulls(size)
|
||||
}
|
||||
|
||||
private fun getQueryTemplate(ids: List<Long?>): QueryTemplate {
|
||||
return QueryTemplate()
|
||||
.join(left(Tag.TABLE, Tag.TASK.eq(Task.ID)))
|
||||
.where(Task.ID.`in`(ids))
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
Loading…
Reference in New Issue