-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add RowData to create recurring tasks. Implements #460
This certainly needs to be revisited, but it should be ok for now when it's mostly required to write unit tests.
- Loading branch information
Showing
7 changed files
with
432 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
opentaskspal/src/main/java/org/dmfs/opentaskspal/tasks/ExDatesTaskData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* 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.content.ContentProviderOperation; | ||
import android.support.annotation.NonNull; | ||
import android.text.TextUtils; | ||
|
||
import org.dmfs.android.contentpal.RowData; | ||
import org.dmfs.android.contentpal.TransactionContext; | ||
import org.dmfs.jems.iterable.decorators.Mapped; | ||
import org.dmfs.rfc5545.DateTime; | ||
import org.dmfs.tasks.contract.TaskContract; | ||
|
||
|
||
/** | ||
* {@link RowData} for tasks with EXDATEs | ||
* <p> | ||
* TODO: how to make sure this is only ever used with tasks having a start and/or due date? | ||
* | ||
* @author Marten Gajda | ||
*/ | ||
public final class ExDatesTaskData implements RowData<TaskContract.Tasks> | ||
{ | ||
private final Iterable<DateTime> mExDates; | ||
|
||
|
||
public ExDatesTaskData(@NonNull Iterable<DateTime> exdates) | ||
{ | ||
mExDates = exdates; | ||
} | ||
|
||
|
||
@NonNull | ||
@Override | ||
public ContentProviderOperation.Builder updatedBuilder(@NonNull TransactionContext transactionContext, @NonNull ContentProviderOperation.Builder builder) | ||
{ | ||
String value = TextUtils.join(",", | ||
new Mapped<>(DateTime::toString, new Mapped<>(dt -> dt.isFloating() ? dt : dt.shiftTimeZone(DateTime.UTC), mExDates))); | ||
return builder.withValue(TaskContract.Tasks.EXDATE, value.isEmpty() ? null : value); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
opentaskspal/src/main/java/org/dmfs/opentaskspal/tasks/RDatesTaskData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* 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.content.ContentProviderOperation; | ||
import android.support.annotation.NonNull; | ||
import android.text.TextUtils; | ||
|
||
import org.dmfs.android.contentpal.RowData; | ||
import org.dmfs.android.contentpal.TransactionContext; | ||
import org.dmfs.jems.iterable.decorators.Mapped; | ||
import org.dmfs.rfc5545.DateTime; | ||
import org.dmfs.tasks.contract.TaskContract; | ||
|
||
|
||
/** | ||
* {@link RowData} for tasks with RDATEs. | ||
* <p> | ||
* TODO: how to make sure this is only ever used with tasks having a start and/or due date? | ||
* | ||
* @author Marten Gajda | ||
*/ | ||
public final class RDatesTaskData implements RowData<TaskContract.Tasks> | ||
{ | ||
private final Iterable<DateTime> mRDates; | ||
|
||
|
||
public RDatesTaskData(@NonNull Iterable<DateTime> rdates) | ||
{ | ||
mRDates = rdates; | ||
} | ||
|
||
|
||
@NonNull | ||
@Override | ||
public ContentProviderOperation.Builder updatedBuilder(@NonNull TransactionContext transactionContext, @NonNull ContentProviderOperation.Builder builder) | ||
{ | ||
String value = TextUtils.join(",", | ||
new Mapped<>(DateTime::toString, new Mapped<>(dt -> dt.isFloating() ? dt : dt.shiftTimeZone(DateTime.UTC), mRDates))); | ||
return builder.withValue(TaskContract.Tasks.RDATE, value.isEmpty() ? null : value); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
opentaskspal/src/main/java/org/dmfs/opentaskspal/tasks/RRuleTaskData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* 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.content.ContentProviderOperation; | ||
import android.support.annotation.NonNull; | ||
|
||
import org.dmfs.android.contentpal.RowData; | ||
import org.dmfs.android.contentpal.TransactionContext; | ||
import org.dmfs.rfc5545.recur.RecurrenceRule; | ||
import org.dmfs.tasks.contract.TaskContract; | ||
|
||
|
||
/** | ||
* {@link RowData} for tasks with a recurrence rule. | ||
* <p> | ||
* TODO: how to make sure this is only ever used with tasks having a start and/or due date? | ||
* | ||
* @author Marten Gajda | ||
*/ | ||
public final class RRuleTaskData implements RowData<TaskContract.Tasks> | ||
{ | ||
private final RecurrenceRule mRule; | ||
|
||
|
||
public RRuleTaskData(@NonNull RecurrenceRule rule) | ||
{ | ||
mRule = rule; | ||
} | ||
|
||
|
||
@NonNull | ||
@Override | ||
public ContentProviderOperation.Builder updatedBuilder(@NonNull TransactionContext transactionContext, @NonNull ContentProviderOperation.Builder builder) | ||
{ | ||
return builder.withValue(TaskContract.Tasks.RRULE, mRule.toString()); | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
opentaskspal/src/test/java/org/dmfs/opentaskspal/tasks/ExDatesTaskDataTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* 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.iterables.SingletonIterable; | ||
import org.dmfs.iterables.elementary.Seq; | ||
import org.dmfs.rfc5545.DateTime; | ||
import org.dmfs.tasks.contract.TaskContract; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.robolectric.RobolectricTestRunner; | ||
import org.robolectric.annotation.Config; | ||
|
||
import static org.dmfs.android.contentpal.testing.contentoperationbuilder.WithValues.withValuesOnly; | ||
import static org.dmfs.android.contentpal.testing.contentvalues.Containing.containing; | ||
import static org.dmfs.android.contentpal.testing.contentvalues.NullValue.withNullValue; | ||
import static org.dmfs.android.contentpal.testing.rowdata.RowDataMatcher.builds; | ||
import static org.dmfs.iterables.EmptyIterable.instance; | ||
import static org.junit.Assert.assertThat; | ||
|
||
|
||
/** | ||
* @author Marten Gajda | ||
*/ | ||
@RunWith(RobolectricTestRunner.class) | ||
@Config(manifest = Config.NONE) | ||
public class ExDatesTaskDataTest | ||
{ | ||
@Test | ||
public void testEmpty() throws Exception | ||
{ | ||
assertThat(new ExDatesTaskData(instance()), | ||
builds( | ||
withValuesOnly( | ||
withNullValue(TaskContract.Tasks.EXDATE)))); | ||
} | ||
|
||
|
||
@Test | ||
public void testSingle() throws Exception | ||
{ | ||
assertThat(new ExDatesTaskData(new SingletonIterable<>(DateTime.parse("Europe/Berlin", "20171212T123456"))), | ||
builds( | ||
withValuesOnly( | ||
containing(TaskContract.Tasks.EXDATE, "20171212T113456Z")))); | ||
} | ||
|
||
|
||
@Test | ||
public void testSingleFloating() throws Exception | ||
{ | ||
assertThat(new ExDatesTaskData(new SingletonIterable<>(DateTime.parse("20171212T123456"))), | ||
builds( | ||
withValuesOnly( | ||
containing(TaskContract.Tasks.EXDATE, "20171212T123456")))); | ||
} | ||
|
||
|
||
@Test | ||
public void testSingleAllDay() throws Exception | ||
{ | ||
assertThat(new ExDatesTaskData(new SingletonIterable<>(DateTime.parse("20171212"))), | ||
builds( | ||
withValuesOnly( | ||
containing(TaskContract.Tasks.EXDATE, "20171212")))); | ||
} | ||
|
||
|
||
@Test | ||
public void testMulti1() throws Exception | ||
{ | ||
assertThat(new ExDatesTaskData( | ||
new Seq<>( | ||
DateTime.parse("Europe/Berlin", "20171212T123456"), | ||
DateTime.parse("UTC", "20171213T123456"))), | ||
builds( | ||
withValuesOnly( | ||
containing(TaskContract.Tasks.EXDATE, "20171212T113456Z,20171213T123456Z")))); | ||
} | ||
|
||
|
||
@Test | ||
public void testMulti2() throws Exception | ||
{ | ||
assertThat(new ExDatesTaskData( | ||
new Seq<>( | ||
DateTime.parse("Europe/Berlin", "20171212T123456"), | ||
DateTime.parse("UTC", "20171213T123456"), | ||
DateTime.parse("America/New_York", "20171214T123456"))), | ||
builds( | ||
withValuesOnly( | ||
containing(TaskContract.Tasks.EXDATE, "20171212T113456Z,20171213T123456Z,20171214T173456Z")))); | ||
} | ||
|
||
} |
109 changes: 109 additions & 0 deletions
109
opentaskspal/src/test/java/org/dmfs/opentaskspal/tasks/RDatesTaskDataTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* 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.iterables.SingletonIterable; | ||
import org.dmfs.iterables.elementary.Seq; | ||
import org.dmfs.rfc5545.DateTime; | ||
import org.dmfs.tasks.contract.TaskContract; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.robolectric.RobolectricTestRunner; | ||
import org.robolectric.annotation.Config; | ||
|
||
import static org.dmfs.android.contentpal.testing.contentoperationbuilder.WithValues.withValuesOnly; | ||
import static org.dmfs.android.contentpal.testing.contentvalues.Containing.containing; | ||
import static org.dmfs.android.contentpal.testing.contentvalues.NullValue.withNullValue; | ||
import static org.dmfs.android.contentpal.testing.rowdata.RowDataMatcher.builds; | ||
import static org.dmfs.iterables.EmptyIterable.instance; | ||
import static org.junit.Assert.assertThat; | ||
|
||
|
||
/** | ||
* @author Marten Gajda | ||
*/ | ||
@RunWith(RobolectricTestRunner.class) | ||
@Config(manifest = Config.NONE) | ||
public class RDatesTaskDataTest | ||
{ | ||
@Test | ||
public void testEmpty() throws Exception | ||
{ | ||
assertThat(new RDatesTaskData(instance()), | ||
builds( | ||
withValuesOnly( | ||
withNullValue(TaskContract.Tasks.RDATE)))); | ||
} | ||
|
||
|
||
@Test | ||
public void testSingle() throws Exception | ||
{ | ||
assertThat(new RDatesTaskData(new SingletonIterable<>(DateTime.parse("Europe/Berlin", "20171212T123456"))), | ||
builds( | ||
withValuesOnly( | ||
containing(TaskContract.Tasks.RDATE, "20171212T113456Z")))); | ||
} | ||
|
||
|
||
@Test | ||
public void testSingleFloating() throws Exception | ||
{ | ||
assertThat(new RDatesTaskData(new SingletonIterable<>(DateTime.parse("20171212T123456"))), | ||
builds( | ||
withValuesOnly( | ||
containing(TaskContract.Tasks.RDATE, "20171212T123456")))); | ||
} | ||
|
||
|
||
@Test | ||
public void testSingleAllDay() throws Exception | ||
{ | ||
assertThat(new RDatesTaskData(new SingletonIterable<>(DateTime.parse("20171212"))), | ||
builds( | ||
withValuesOnly( | ||
containing(TaskContract.Tasks.RDATE, "20171212")))); | ||
} | ||
|
||
|
||
@Test | ||
public void testMulti1() throws Exception | ||
{ | ||
assertThat(new RDatesTaskData( | ||
new Seq<>( | ||
DateTime.parse("Europe/Berlin", "20171212T123456"), | ||
DateTime.parse("UTC", "20171213T123456"))), | ||
builds( | ||
withValuesOnly( | ||
containing(TaskContract.Tasks.RDATE, "20171212T113456Z,20171213T123456Z")))); | ||
} | ||
|
||
|
||
@Test | ||
public void testMulti2() throws Exception | ||
{ | ||
assertThat(new RDatesTaskData( | ||
new Seq<>( | ||
DateTime.parse("Europe/Berlin", "20171212T123456"), | ||
DateTime.parse("UTC", "20171213T123456"), | ||
DateTime.parse("America/New_York", "20171214T123456"))), | ||
builds( | ||
withValuesOnly( | ||
containing(TaskContract.Tasks.RDATE, "20171212T113456Z,20171213T123456Z,20171214T173456Z")))); | ||
} | ||
|
||
} |
Oops, something went wrong.