Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- forbid DUE=START; - use defaults satisfying DUE>START; - shift DUE if START violates constraint; - refactor: correct spelling of "constraint".
- Loading branch information
Showing
18 changed files
with
343 additions
and
34 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
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
53 changes: 53 additions & 0 deletions
53
opentasks/src/main/java/org/dmfs/tasks/model/constraints/After.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,53 @@ | ||
/* | ||
* 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.tasks.model.constraints; | ||
|
||
import android.text.format.Time; | ||
|
||
import org.dmfs.tasks.model.ContentSet; | ||
import org.dmfs.tasks.model.adapters.TimeFieldAdapter; | ||
import org.dmfs.tasks.model.defaults.AbstractDefault; | ||
import org.dmfs.tasks.model.defaults.DefaultAfter; | ||
|
||
|
||
/** | ||
* Ensure a time is after a specific reference time. The new value will be set using {@link DefaultAfter} otherwise. | ||
*/ | ||
public class After extends AbstractConstraint<Time> | ||
{ | ||
private final TimeFieldAdapter mReferenceAdapter; | ||
private final AbstractDefault<Time> mDefault; | ||
|
||
|
||
public After(TimeFieldAdapter referenceAdapter) | ||
{ | ||
mReferenceAdapter = referenceAdapter; | ||
mDefault = new DefaultAfter(referenceAdapter); | ||
} | ||
|
||
|
||
@Override | ||
public Time apply(ContentSet currentValues, Time oldValue, Time newValue) | ||
{ | ||
Time reference = mReferenceAdapter.get(currentValues); | ||
if (reference != null && newValue != null && !newValue.after(reference)) | ||
{ | ||
newValue.set(mDefault.getCustomDefault(currentValues, reference)); | ||
} | ||
return newValue; | ||
} | ||
|
||
} |
79 changes: 79 additions & 0 deletions
79
opentasks/src/main/java/org/dmfs/tasks/model/constraints/BeforeOrShiftTime.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,79 @@ | ||
/* | ||
* 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.tasks.model.constraints; | ||
|
||
import android.text.format.Time; | ||
|
||
import org.dmfs.tasks.model.ContentSet; | ||
import org.dmfs.tasks.model.adapters.TimeFieldAdapter; | ||
import org.dmfs.tasks.model.defaults.AbstractDefault; | ||
import org.dmfs.tasks.model.defaults.DefaultAfter; | ||
|
||
|
||
/** | ||
* Ensure a time is before a specific reference time. | ||
* Otherwise, shift the reference time by the same amount that value has been shifted. | ||
* If this still violated the constraint, then set the reference value to its default value. | ||
* | ||
* TODO: use Duration class to get the duration in days and shift without summer/winter time switches | ||
*/ | ||
public class BeforeOrShiftTime extends AbstractConstraint<Time> | ||
{ | ||
private final TimeFieldAdapter mReferenceAdapter; | ||
private final AbstractDefault<Time> mDefault; | ||
|
||
|
||
public BeforeOrShiftTime(TimeFieldAdapter referenceAdapter) | ||
{ | ||
mReferenceAdapter = referenceAdapter; | ||
mDefault = new DefaultAfter(null); | ||
} | ||
|
||
|
||
@Override | ||
public Time apply(ContentSet currentValues, Time oldValue, Time newValue) | ||
{ | ||
Time reference = mReferenceAdapter.get(currentValues); | ||
if (reference != null && newValue != null) | ||
{ | ||
if (oldValue != null && !newValue.before(reference)) | ||
{ | ||
// try to shift the reference value | ||
long diff = newValue.toMillis(false) - oldValue.toMillis(false); | ||
if (diff > 0) | ||
{ | ||
boolean isAllDay = reference.allDay; | ||
reference.set(reference.toMillis(false) + diff); | ||
|
||
// ensure the event is still allday if is was allday before. | ||
if (isAllDay) | ||
{ | ||
reference.set(reference.monthDay, reference.month, reference.year); | ||
} | ||
mReferenceAdapter.set(currentValues, reference); | ||
} | ||
} | ||
if (!newValue.before(reference)) | ||
{ | ||
// constraint is still violated, so set reference to its default value | ||
reference.set(mDefault.getCustomDefault(currentValues, newValue)); | ||
mReferenceAdapter.set(currentValues, reference); | ||
} | ||
} | ||
return newValue; | ||
} | ||
|
||
} |
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
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
Oops, something went wrong.