diff --git a/.idea/dictionaries/dictionary.xml b/.idea/dictionaries/dictionary.xml
index f2d484282..7db7138b1 100644
--- a/.idea/dictionaries/dictionary.xml
+++ b/.idea/dictionaries/dictionary.xml
@@ -2,6 +2,8 @@
opentasks
+ subtask
+ subtasks
\ No newline at end of file
diff --git a/gradle.properties b/gradle.properties
index c1dfcd9fe..4c4856618 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -4,5 +4,5 @@ MIN_SDK_VERSION=9
TARGET_SDK_VERSION=25
# dependency versions
SUPPORT_LIBRARY_VERSION=25.0.1
-CONTENTPAL_VERSION=879bb47
+CONTENTPAL_VERSION=2d16bb5
ROBOLECTRIC_VERSION=3.1.4
\ No newline at end of file
diff --git a/opentaskspal/src/main/java/org/dmfs/opentaskspal/operations/SubtaskRelation.java b/opentaskspal/src/main/java/org/dmfs/opentaskspal/operations/SubtaskRelation.java
new file mode 100644
index 000000000..ec7375575
--- /dev/null
+++ b/opentaskspal/src/main/java/org/dmfs/opentaskspal/operations/SubtaskRelation.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2017 dmfs GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.dmfs.opentaskspal.operations;
+
+import android.content.ContentProviderOperation;
+import android.support.annotation.NonNull;
+
+import org.dmfs.android.contentpal.InsertOperation;
+import org.dmfs.android.contentpal.Operation;
+import org.dmfs.android.contentpal.RowSnapshot;
+import org.dmfs.android.contentpal.SoftRowReference;
+import org.dmfs.android.contentpal.TransactionContext;
+import org.dmfs.android.contentpal.operations.Insert;
+import org.dmfs.opentaskspal.tables.PropertiesTable;
+import org.dmfs.opentaskspal.tasks.ParentTaskRelationData;
+import org.dmfs.optional.Optional;
+import org.dmfs.tasks.contract.TaskContract;
+
+
+/**
+ * {@link InsertOperation} for adding a 'subtask relation' property to {@link TaskContract.Properties} table.
+ *
+ * @author Gabor Keszthelyi
+ */
+public final class SubtaskRelation implements InsertOperation
+{
+
+ private final Operation mDelegate;
+
+
+ public SubtaskRelation(String authority, RowSnapshot subtask, RowSnapshot parentTask)
+ {
+ mDelegate = new Insert<>(new PropertiesTable(authority), new ParentTaskRelationData(parentTask, subtask));
+ }
+
+
+ @NonNull
+ @Override
+ public Optional> reference()
+ {
+ return mDelegate.reference();
+ }
+
+
+ @NonNull
+ @Override
+ public ContentProviderOperation.Builder contentOperationBuilder(@NonNull TransactionContext transactionContext) throws UnsupportedOperationException
+ {
+ return mDelegate.contentOperationBuilder(transactionContext);
+ }
+}
diff --git a/opentaskspal/src/main/java/org/dmfs/opentaskspal/predicates/IsProperty.java b/opentaskspal/src/main/java/org/dmfs/opentaskspal/predicates/IsProperty.java
new file mode 100644
index 000000000..9f93d3847
--- /dev/null
+++ b/opentaskspal/src/main/java/org/dmfs/opentaskspal/predicates/IsProperty.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2017 dmfs GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.dmfs.opentaskspal.predicates;
+
+import org.dmfs.android.contentpal.Predicate;
+import org.dmfs.android.contentpal.predicates.DelegatingPredicate;
+import org.dmfs.android.contentpal.predicates.EqArg;
+import org.dmfs.tasks.contract.TaskContract;
+
+
+/**
+ * {@link Predicate} for selecting rows from {@link TaskContract.Properties} table representing a certain property identified by its mimeType.
+ *
+ * @author Gabor Keszthelyi
+ */
+public final class IsProperty extends DelegatingPredicate
+{
+ public IsProperty(String mimeType)
+ {
+ super(new EqArg(TaskContract.PropertyColumns.MIMETYPE, mimeType));
+ }
+}
diff --git a/opentaskspal/src/main/java/org/dmfs/opentaskspal/predicates/IsRelation.java b/opentaskspal/src/main/java/org/dmfs/opentaskspal/predicates/IsRelation.java
new file mode 100644
index 000000000..d130130c0
--- /dev/null
+++ b/opentaskspal/src/main/java/org/dmfs/opentaskspal/predicates/IsRelation.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2017 dmfs GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.dmfs.opentaskspal.predicates;
+
+import org.dmfs.android.contentpal.Predicate;
+import org.dmfs.android.contentpal.predicates.DelegatingPredicate;
+import org.dmfs.tasks.contract.TaskContract;
+
+
+/**
+ * {@link Predicate} for selecting {@link TaskContract.Property.Relation} properties from {@link TaskContract.Properties} table.
+ *
+ * @author Gabor Keszthelyi
+ */
+public final class IsRelation extends DelegatingPredicate
+{
+ public IsRelation()
+ {
+ super(new IsProperty(TaskContract.Property.Relation.CONTENT_ITEM_TYPE));
+ }
+}
diff --git a/opentaskspal/src/main/java/org/dmfs/opentaskspal/rowsets/Subtasks.java b/opentaskspal/src/main/java/org/dmfs/opentaskspal/rowsets/Subtasks.java
new file mode 100644
index 000000000..1d57f321f
--- /dev/null
+++ b/opentaskspal/src/main/java/org/dmfs/opentaskspal/rowsets/Subtasks.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2017 dmfs GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.dmfs.opentaskspal.rowsets;
+
+import android.content.ContentProviderClient;
+import android.support.annotation.NonNull;
+
+import org.dmfs.android.contentpal.RowSet;
+import org.dmfs.android.contentpal.RowSnapshot;
+import org.dmfs.android.contentpal.predicates.ReferringTo;
+import org.dmfs.android.contentpal.rowsets.DelegatingRowSet;
+import org.dmfs.android.contentpal.rowsets.QueryRowSet;
+import org.dmfs.opentaskspal.views.TasksView;
+import org.dmfs.tasks.contract.TaskContract;
+
+
+/**
+ * {@link RowSet} for the subtasks of a given task.
+ *
+ * @author Gabor Keszthelyi
+ */
+public final class Subtasks extends DelegatingRowSet
+{
+
+ public Subtasks(String authority, ContentProviderClient client, @NonNull RowSnapshot parentTask)
+ {
+ super(new QueryRowSet<>(new TasksView(authority, client), new ReferringTo<>(TaskContract.Tasks.PARENT_ID, parentTask)));
+ }
+
+}
diff --git a/opentaskspal/src/main/java/org/dmfs/opentaskspal/tables/PropertiesTable.java b/opentaskspal/src/main/java/org/dmfs/opentaskspal/tables/PropertiesTable.java
new file mode 100644
index 000000000..cb74ed020
--- /dev/null
+++ b/opentaskspal/src/main/java/org/dmfs/opentaskspal/tables/PropertiesTable.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2017 dmfs GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.dmfs.opentaskspal.tables;
+
+import org.dmfs.android.contentpal.Table;
+import org.dmfs.android.contentpal.tables.BaseTable;
+import org.dmfs.android.contentpal.tables.DelegatingTable;
+import org.dmfs.tasks.contract.TaskContract;
+
+
+/**
+ * {@link Table} for {@link TaskContract.Properties}.
+ *
+ * @author Gabor Keszthelyi
+ */
+public final class PropertiesTable extends DelegatingTable
+{
+ public PropertiesTable(String authority)
+ {
+ super(new BaseTable(TaskContract.Properties.getContentUri(authority)));
+ }
+}
diff --git a/opentaskspal/src/main/java/org/dmfs/opentaskspal/tasks/ChildTaskRelationData.java b/opentaskspal/src/main/java/org/dmfs/opentaskspal/tasks/ChildTaskRelationData.java
new file mode 100644
index 000000000..3f82111bc
--- /dev/null
+++ b/opentaskspal/src/main/java/org/dmfs/opentaskspal/tasks/ChildTaskRelationData.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2017 dmfs GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.dmfs.opentaskspal.tasks;
+
+import org.dmfs.android.contentpal.RowData;
+import org.dmfs.android.contentpal.RowSnapshot;
+import org.dmfs.android.contentpal.rowdata.DelegatingRowData;
+import org.dmfs.tasks.contract.TaskContract;
+import org.dmfs.tasks.contract.TaskContract.Property.Relation.RelType;
+
+
+/**
+ * {@link RowData} to add the {@link RelType#CHILD} relation between the 2 given tasks, to the {@link TaskContract.Properties} table.
+ *
+ * @author Gabor Keszthelyi
+ */
+public final class ChildTaskRelationData extends DelegatingRowData
+{
+ public ChildTaskRelationData(RowSnapshot childTask, RowSnapshot parentTask)
+ {
+ super(new RelationData(parentTask, RelType.CHILD, childTask));
+ }
+
+
+ public ChildTaskRelationData(CharSequence childTaskUid, RowSnapshot parentTask)
+ {
+ super(new RelationData(parentTask, RelType.CHILD, childTaskUid));
+ }
+
+}
diff --git a/opentaskspal/src/main/java/org/dmfs/opentaskspal/tasks/ParentTaskRelationData.java b/opentaskspal/src/main/java/org/dmfs/opentaskspal/tasks/ParentTaskRelationData.java
new file mode 100644
index 000000000..b4e395058
--- /dev/null
+++ b/opentaskspal/src/main/java/org/dmfs/opentaskspal/tasks/ParentTaskRelationData.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2017 dmfs GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.dmfs.opentaskspal.tasks;
+
+import org.dmfs.android.contentpal.RowData;
+import org.dmfs.android.contentpal.RowSnapshot;
+import org.dmfs.android.contentpal.rowdata.DelegatingRowData;
+import org.dmfs.tasks.contract.TaskContract;
+import org.dmfs.tasks.contract.TaskContract.Property.Relation.RelType;
+
+
+/**
+ * {@link RowData} to add the {@link RelType#PARENT} relation between the 2 given tasks, to the {@link TaskContract.Properties} table.
+ *
+ * @author Gabor Keszthelyi
+ */
+public final class ParentTaskRelationData extends DelegatingRowData
+{
+ public ParentTaskRelationData(RowSnapshot parentTask, RowSnapshot childTask)
+ {
+ super(new RelationData(childTask, RelType.PARENT, parentTask));
+ }
+
+ public ParentTaskRelationData(CharSequence parentTaskUid, RowSnapshot childTask)
+ {
+ super(new RelationData(childTask, RelType.PARENT, parentTaskUid));
+ }
+
+}
diff --git a/opentaskspal/src/main/java/org/dmfs/opentaskspal/tasks/RelationData.java b/opentaskspal/src/main/java/org/dmfs/opentaskspal/tasks/RelationData.java
new file mode 100644
index 000000000..e595ff375
--- /dev/null
+++ b/opentaskspal/src/main/java/org/dmfs/opentaskspal/tasks/RelationData.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2017 dmfs GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.dmfs.opentaskspal.tasks;
+
+import android.support.annotation.NonNull;
+
+import org.dmfs.android.contentpal.RowData;
+import org.dmfs.android.contentpal.RowSnapshot;
+import org.dmfs.android.contentpal.rowdata.CharSequenceRowData;
+import org.dmfs.android.contentpal.rowdata.Composite;
+import org.dmfs.android.contentpal.rowdata.DelegatingRowData;
+import org.dmfs.android.contentpal.rowdata.RawRowData;
+import org.dmfs.android.contentpal.rowdata.Referring;
+import org.dmfs.tasks.contract.TaskContract;
+import org.dmfs.tasks.contract.TaskContract.Property.Relation.RelType;
+
+
+/**
+ * {@link RowData} for adding a {@link TaskContract.Property.Relation} property.
+ *
+ * @author Gabor Keszthelyi
+ */
+public final class RelationData extends DelegatingRowData
+{
+ public RelationData(@NonNull RowSnapshot relatingTask,
+ @NonNull RelType relType,
+ @NonNull RowSnapshot relatedTask)
+ {
+ super(new Composite<>(
+ new Referring(TaskContract.Property.Relation.TASK_ID, relatingTask),
+ new RawRowData(TaskContract.Property.Relation.RELATED_TYPE, relType.ordinal()),
+ new Referring(TaskContract.Property.Relation.RELATED_ID, relatedTask)));
+ }
+
+
+ public RelationData(@NonNull RowSnapshot relatingTask,
+ @NonNull RelType relType,
+ @NonNull CharSequence relatedTaskUid)
+ {
+ super(new Composite<>(
+ new Referring(TaskContract.Property.Relation.TASK_ID, relatingTask),
+ new RawRowData(TaskContract.Property.Relation.RELATED_TYPE, relType.ordinal()),
+ new CharSequenceRowData(TaskContract.Property.Relation.RELATED_UID, relatedTaskUid)));
+ }
+}
diff --git a/opentaskspal/src/main/java/org/dmfs/opentaskspal/views/TaskListScoped.java b/opentaskspal/src/main/java/org/dmfs/opentaskspal/views/TaskListScoped.java
index 8fd7aa464..2bbf7594b 100644
--- a/opentaskspal/src/main/java/org/dmfs/opentaskspal/views/TaskListScoped.java
+++ b/opentaskspal/src/main/java/org/dmfs/opentaskspal/views/TaskListScoped.java
@@ -64,4 +64,12 @@ public Table table()
{
return new org.dmfs.opentaskspal.tables.TaskListScoped(mTaskListRow, mDelegate.table());
}
+
+
+ @NonNull
+ @Override
+ public View withProjection(@NonNull String... strings)
+ {
+ return mDelegate.withProjection(strings);
+ }
}
diff --git a/opentaskspal/src/main/java/org/dmfs/opentaskspal/views/TasksView.java b/opentaskspal/src/main/java/org/dmfs/opentaskspal/views/TasksView.java
new file mode 100644
index 000000000..986cac3e9
--- /dev/null
+++ b/opentaskspal/src/main/java/org/dmfs/opentaskspal/views/TasksView.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2017 dmfs GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.dmfs.opentaskspal.views;
+
+import android.content.ContentProviderClient;
+
+import org.dmfs.android.contentpal.View;
+import org.dmfs.android.contentpal.views.BaseView;
+import org.dmfs.android.contentpal.views.DelegatingView;
+import org.dmfs.tasks.contract.TaskContract;
+
+
+/**
+ * {@link View} for the {@link TaskContract.Tasks} table.
+ *
+ * @author Gabor Keszthelyi
+ */
+public final class TasksView extends DelegatingView
+{
+ public TasksView(String authority, ContentProviderClient client)
+ {
+ super(new BaseView(client, TaskContract.Tasks.getContentUri(authority)));
+ }
+}