-
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.
Make sure non-recurring tasks get an INSTANCE_ORIGINAL_TIME of 0. Imp…
…lements #577 This resulted in a minor SRP-ish refactoring to separate steps of instance value creation.
- Loading branch information
Showing
24 changed files
with
973 additions
and
346 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
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
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
51 changes: 51 additions & 0 deletions
51
...s-provider/src/main/java/org/dmfs/provider/tasks/processors/tasks/instancedata/Dated.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,51 @@ | ||
/* | ||
* 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.provider.tasks.processors.tasks.instancedata; | ||
|
||
import android.content.ContentValues; | ||
|
||
import org.dmfs.jems.single.Single; | ||
import org.dmfs.jems.single.decorators.DelegatingSingle; | ||
import org.dmfs.optional.Optional; | ||
import org.dmfs.provider.tasks.utils.Zipped; | ||
import org.dmfs.rfc5545.DateTime; | ||
|
||
import java.util.TimeZone; | ||
|
||
|
||
/** | ||
* A {@link Single} of date and time {@link ContentValues} of an instance. | ||
* | ||
* @author Marten Gajda | ||
*/ | ||
public final class Dated extends DelegatingSingle<ContentValues> | ||
{ | ||
|
||
public Dated(Optional<DateTime> dateTime, String timeStampColumn, String sortingColumn, Single<ContentValues> delegate) | ||
{ | ||
super(new Zipped<>( | ||
dateTime, | ||
delegate, | ||
(dateTime1, values) -> | ||
{ | ||
// add timestamp and sorting | ||
values.put(timeStampColumn, dateTime1.getTimestamp()); | ||
values.put(sortingColumn, dateTime1.isAllDay() ? dateTime1.getInstance() : dateTime1.shiftTimeZone(TimeZone.getDefault()).getInstance()); | ||
return values; | ||
})); | ||
} | ||
} |
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
57 changes: 57 additions & 0 deletions
57
...rovider/src/main/java/org/dmfs/provider/tasks/processors/tasks/instancedata/Enduring.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,57 @@ | ||
/* | ||
* 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.provider.tasks.processors.tasks.instancedata; | ||
|
||
import android.content.ContentValues; | ||
|
||
import org.dmfs.jems.single.Single; | ||
import org.dmfs.optional.NullSafe; | ||
import org.dmfs.optional.composite.Zipped; | ||
import org.dmfs.tasks.contract.TaskContract; | ||
|
||
|
||
/** | ||
* A decorator for {@link Single}s of Instance {@link ContentValues} which populates the {@link TaskContract.Instances#INSTANCE_DURATION} field based on the | ||
* already populated {@link TaskContract.Instances#INSTANCE_START} and {@link TaskContract.Instances#INSTANCE_DUE} fields. | ||
* | ||
* @author Marten Gajda | ||
*/ | ||
public final class Enduring implements Single<ContentValues> | ||
{ | ||
private final Single<ContentValues> mDelegate; | ||
|
||
|
||
public Enduring(Single<ContentValues> delegate) | ||
{ | ||
mDelegate = delegate; | ||
} | ||
|
||
|
||
@Override | ||
public ContentValues value() | ||
{ | ||
ContentValues values = mDelegate.value(); | ||
// just store the difference between due and start, if both are present, otherwise store null | ||
values.put(TaskContract.Instances.INSTANCE_DURATION, | ||
new Zipped<>( | ||
new NullSafe<>(values.getAsLong(TaskContract.Instances.INSTANCE_START)), | ||
new NullSafe<>(values.getAsLong(TaskContract.Instances.INSTANCE_DUE)), | ||
(start, due) -> due - start) | ||
.value(null)); | ||
return values; | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...vider/src/main/java/org/dmfs/provider/tasks/processors/tasks/instancedata/Overridden.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,62 @@ | ||
/* | ||
* 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.provider.tasks.processors.tasks.instancedata; | ||
|
||
import android.content.ContentValues; | ||
|
||
import org.dmfs.iterables.elementary.Seq; | ||
import org.dmfs.jems.optional.decorators.Mapped; | ||
import org.dmfs.jems.single.Single; | ||
import org.dmfs.optional.NullSafe; | ||
import org.dmfs.optional.Optional; | ||
import org.dmfs.optional.adapters.FirstPresent; | ||
import org.dmfs.rfc5545.DateTime; | ||
import org.dmfs.tasks.contract.TaskContract; | ||
|
||
|
||
/** | ||
* A decorator for {@link Single}s of Instance {@link ContentValues} which populates the {@link TaskContract.Instances#INSTANCE_ORIGINAL_TIME} field based on | ||
* the given {@link Optional} original start and the already populated {@link TaskContract.Instances#INSTANCE_START} and {@link | ||
* TaskContract.Instances#INSTANCE_DUE} fields. | ||
* | ||
* @author Marten Gajda | ||
*/ | ||
public final class Overridden implements Single<ContentValues> | ||
{ | ||
private final Optional<DateTime> mOriginalTime; | ||
private final Single<ContentValues> mDelegate; | ||
|
||
|
||
public Overridden(Optional<DateTime> originalTime, Single<ContentValues> delegate) | ||
{ | ||
mOriginalTime = originalTime; | ||
mDelegate = delegate; | ||
} | ||
|
||
|
||
@Override | ||
public ContentValues value() | ||
{ | ||
ContentValues values = mDelegate.value(); | ||
values.put(TaskContract.Instances.INSTANCE_ORIGINAL_TIME, new FirstPresent<>(new Seq<>( | ||
new Mapped<>(DateTime::getTimestamp, mOriginalTime), | ||
new NullSafe<>(values.getAsLong(TaskContract.Instances.INSTANCE_START)), | ||
new NullSafe<>(values.getAsLong(TaskContract.Instances.INSTANCE_DUE)))) | ||
.value(null)); | ||
return values; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...vider/src/main/java/org/dmfs/provider/tasks/processors/tasks/instancedata/StartDated.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,39 @@ | ||
/* | ||
* 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.provider.tasks.processors.tasks.instancedata; | ||
|
||
import android.content.ContentValues; | ||
|
||
import org.dmfs.jems.single.Single; | ||
import org.dmfs.jems.single.decorators.DelegatingSingle; | ||
import org.dmfs.optional.Optional; | ||
import org.dmfs.rfc5545.DateTime; | ||
import org.dmfs.tasks.contract.TaskContract; | ||
|
||
|
||
/** | ||
* A decorator to a {@link Single} of {@link ContentValues} adding start data. | ||
* | ||
* @author Marten Gajda | ||
*/ | ||
public final class StartDated extends DelegatingSingle<ContentValues> | ||
{ | ||
public StartDated(Optional<DateTime> start, Single<ContentValues> delegate) | ||
{ | ||
super(new Dated(start, TaskContract.Instances.INSTANCE_START, TaskContract.Instances.INSTANCE_START_SORTING, delegate)); | ||
} | ||
} |
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
Oops, something went wrong.