Skip to content

Commit

Permalink
OpenTaskPal subtask operations and queries support. #450 (#465)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabor Keszthelyi authored and dmfs committed Oct 18, 2017
1 parent 07289ae commit 79e9658
Show file tree
Hide file tree
Showing 12 changed files with 411 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .idea/dictionaries/dictionary.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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<TaskContract.Properties>
{

private final Operation<TaskContract.Properties> mDelegate;


public SubtaskRelation(String authority, RowSnapshot<TaskContract.Tasks> subtask, RowSnapshot<TaskContract.Tasks> parentTask)
{
mDelegate = new Insert<>(new PropertiesTable(authority), new ParentTaskRelationData(parentTask, subtask));
}


@NonNull
@Override
public Optional<SoftRowReference<TaskContract.Properties>> reference()
{
return mDelegate.reference();
}


@NonNull
@Override
public ContentProviderOperation.Builder contentOperationBuilder(@NonNull TransactionContext transactionContext) throws UnsupportedOperationException
{
return mDelegate.contentOperationBuilder(transactionContext);
}
}
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -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<TaskContract.Tasks>
{

public Subtasks(String authority, ContentProviderClient client, @NonNull RowSnapshot<TaskContract.Tasks> parentTask)
{
super(new QueryRowSet<>(new TasksView(authority, client), new ReferringTo<>(TaskContract.Tasks.PARENT_ID, parentTask)));
}

}
Original file line number Diff line number Diff line change
@@ -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<TaskContract.Properties>
{
public PropertiesTable(String authority)
{
super(new BaseTable<TaskContract.Properties>(TaskContract.Properties.getContentUri(authority)));
}
}
Original file line number Diff line number Diff line change
@@ -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<TaskContract.Properties>
{
public ChildTaskRelationData(RowSnapshot<TaskContract.Tasks> childTask, RowSnapshot<TaskContract.Tasks> parentTask)
{
super(new RelationData(parentTask, RelType.CHILD, childTask));
}


public ChildTaskRelationData(CharSequence childTaskUid, RowSnapshot<TaskContract.Tasks> parentTask)
{
super(new RelationData(parentTask, RelType.CHILD, childTaskUid));
}

}
Original file line number Diff line number Diff line change
@@ -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<TaskContract.Properties>
{
public ParentTaskRelationData(RowSnapshot<TaskContract.Tasks> parentTask, RowSnapshot<TaskContract.Tasks> childTask)
{
super(new RelationData(childTask, RelType.PARENT, parentTask));
}

public ParentTaskRelationData(CharSequence parentTaskUid, RowSnapshot<TaskContract.Tasks> childTask)
{
super(new RelationData(childTask, RelType.PARENT, parentTaskUid));
}

}
Original file line number Diff line number Diff line change
@@ -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<TaskContract.Properties>
{
public RelationData(@NonNull RowSnapshot<TaskContract.Tasks> relatingTask,
@NonNull RelType relType,
@NonNull RowSnapshot<TaskContract.Tasks> relatedTask)
{
super(new Composite<>(
new Referring<TaskContract.Properties>(TaskContract.Property.Relation.TASK_ID, relatingTask),
new RawRowData<TaskContract.Properties>(TaskContract.Property.Relation.RELATED_TYPE, relType.ordinal()),
new Referring<TaskContract.Properties>(TaskContract.Property.Relation.RELATED_ID, relatedTask)));
}


public RelationData(@NonNull RowSnapshot<TaskContract.Tasks> relatingTask,
@NonNull RelType relType,
@NonNull CharSequence relatedTaskUid)
{
super(new Composite<>(
new Referring<TaskContract.Properties>(TaskContract.Property.Relation.TASK_ID, relatingTask),
new RawRowData<TaskContract.Properties>(TaskContract.Property.Relation.RELATED_TYPE, relType.ordinal()),
new CharSequenceRowData<TaskContract.Properties>(TaskContract.Property.Relation.RELATED_UID, relatedTaskUid)));
}
}
Loading

0 comments on commit 79e9658

Please sign in to comment.