Skip to content

Commit

Permalink
Move due date when setting a start date that is later in time. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dmfs committed Dec 9, 2015
1 parent e62f547 commit 0ccc8eb
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/org/dmfs/tasks/model/TaskFieldAdapters.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.dmfs.tasks.model.contraints.ChecklistConstraint;
import org.dmfs.tasks.model.contraints.NotAfter;
import org.dmfs.tasks.model.contraints.NotBefore;
import org.dmfs.tasks.model.contraints.ShiftIfAfter;


/**
Expand Down Expand Up @@ -119,7 +120,7 @@ public final class TaskFieldAdapters
/**
* Adapter for the start date of a task.
*/
public final static TimeFieldAdapter DTSTART = (TimeFieldAdapter) _DTSTART.addContraint(new NotAfter(DUE));
public final static TimeFieldAdapter DTSTART = (TimeFieldAdapter) _DTSTART.addContraint(new ShiftIfAfter(DUE));

/**
* Adapter for the completed date of a task.
Expand Down
56 changes: 56 additions & 0 deletions src/org/dmfs/tasks/model/contraints/ShiftIfAfter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (C) 2013 Marten Gajda <marten@dmfs.org>
*
* 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.contraints;

import org.dmfs.tasks.model.ContentSet;
import org.dmfs.tasks.model.adapters.TimeFieldAdapter;

import android.text.format.Time;


/**
* Ensure a time is not after a specific reference time. If that would be the case, the reference time is updated.
*
* @author Marten Gajda <marten@dmfs.org>
*/
public class ShiftIfAfter extends AbstractConstraint<Time>
{
private final TimeFieldAdapter mTimeAdapter;


public ShiftIfAfter(TimeFieldAdapter adapter)
{
mTimeAdapter = adapter;
}


@Override
public Time apply(ContentSet currentValues, Time oldValue, Time newValue)
{
Time notAfterThisTime = mTimeAdapter.get(currentValues);
if (notAfterThisTime != null && newValue != null)
{
if (newValue.after(notAfterThisTime))
{
mTimeAdapter.set(currentValues, newValue);
}
}
return newValue;
}

}

0 comments on commit 0ccc8eb

Please sign in to comment.