Skip to content

Commit

Permalink
Merge branch 'rc-1.6.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
jenspfahl committed Mar 14, 2024
2 parents 78a0297 + 7ab549f commit 020ad43
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 19 deletions.
27 changes: 18 additions & 9 deletions lib/model/ScheduledTask.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,9 @@ class ScheduledTask extends TitleAndDescription implements Comparable {

bool isDue() => !isOneTimeCompleted && (isDueNow() || isNextScheduleOverdue(false));

bool isNextScheduleReached() {
var duration = getMissingDuration();
if (duration != null) {
return _getRoundedDurationValue(duration) == 0;
}
return false;
bool isNextScheduleAlmostReached() {
return (getNextRepetitionIndicatorValue()??0.0) > 0.9;

}

bool isDueNow() => getNextSchedule() != null && truncToMinutes(getNextSchedule()!) == truncToMinutes(DateTime.now());
Expand All @@ -125,10 +122,13 @@ class ScheduledTask extends TitleAndDescription implements Comparable {
}

/*
* Returns the duration in the next bigger unit then the repitition steps are defined.
* Returns the duration in the next bigger unit then the repetition steps are defined.
*/
int _getRoundedDurationValue(Duration duration) {
if (schedule.repetitionStep == RepetitionStep.DAILY
if (schedule.repetitionMode == RepetitionMode.ONE_TIME) {
return duration.inHours;
}
if (schedule.repetitionStep == RepetitionStep.DAILY
|| schedule.repetitionStep == RepetitionStep.EVERY_OTHER_DAY
|| (schedule.repetitionStep == RepetitionStep.CUSTOM
&& schedule.customRepetition?.repetitionUnit == RepetitionUnit.DAYS)
Expand Down Expand Up @@ -163,7 +163,16 @@ class ScheduledTask extends TitleAndDescription implements Comparable {
var scheduledDuration = getScheduledDuration();
var missingDuration = getMissingDuration();
if (scheduledDuration != null && missingDuration != null) {
return 1 - (missingDuration.inMinutes / (scheduledDuration.inMinutes != 0 ? scheduledDuration.inMinutes : 1));
final value = 1 - (missingDuration.inMinutes / (scheduledDuration.inMinutes != 0 ? scheduledDuration.inMinutes : 1));
if (value.isNegative && schedule.repetitionMode == RepetitionMode.ONE_TIME) {
// It can be negative if the schedule was reused after stopped or done and due date was set to a past date (which is an unusual use case).
// With having this, we cannot really compare by progress since the start value is random by the users reactivation date
final missingDays = missingDuration.inHours / 24;
return 1 + (missingDays.abs() * 0.5);
}
else {
return value;
}
}
return null;
}
Expand Down
23 changes: 18 additions & 5 deletions lib/ui/components/ScheduledTaskWidget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,20 @@ class ScheduledTaskWidget extends StatefulWidget {
.currentState
?.addTaskEvent(insertedTaskEvent, justSetState: true);

scheduledTask.executeSchedule(insertedTaskEvent);
if (scheduledTask.schedule.repetitionMode == RepetitionMode.FIXED) {

// move schedule forward if check-marked directly
var newNextDueDate = scheduledTask.simulateExecuteSchedule(null);
if (!scheduledTask.isDue()) {
// get schedule after next due date to move forward
newNextDueDate = scheduledTask.getNextScheduleAfter(newNextDueDate);
}
// because the schedule snaps to the next due date we have to subtract one day
scheduledTask.lastScheduledEventOn = newNextDueDate?.subtract(Duration(days: 1));
}
else {
scheduledTask.executeSchedule(insertedTaskEvent);
}
ScheduledTaskRepository.update(scheduledTask).then((changedScheduledTask) {
cancelSnoozedNotification(scheduledTask);
pagesHolder
Expand Down Expand Up @@ -185,9 +198,9 @@ class ScheduledTaskWidgetState extends State<ScheduledTaskWidget> {
value: scheduledTask.isNextScheduleOverdue(true) ? null : scheduledTask.getNextRepetitionIndicatorValue(),
color: scheduledTask.isNextScheduleOverdue(false)
? Colors.red[500]
: (scheduledTask.isNextScheduleReached()
? scheduledTask.getDueColor(context, lighter: false)
: null),
: (scheduledTask.isNextScheduleAlmostReached()
? scheduledTask.getDueColor(context, lighter: false)
: null),
backgroundColor: scheduledTask.getDueBackgroundColor(context),
),
),
Expand Down Expand Up @@ -562,7 +575,7 @@ class ScheduledTaskWidgetState extends State<ScheduledTaskWidget> {
icon: Icon(resetIcon),
okPressed: () {
if (scheduledTask.schedule.repetitionMode == RepetitionMode.FIXED) {
// because the schedule snaps to the next due date we have to substract one day
// because the schedule snaps to the next due date we have to subtract one day
scheduledTask.lastScheduledEventOn = newNextDueDate?.subtract(Duration(days: 1));
}
else {
Expand Down
5 changes: 1 addition & 4 deletions lib/ui/forms/ScheduledTaskForm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -712,15 +712,12 @@ class _ScheduledTaskFormState extends State<ScheduledTaskForm> {
var scheduleFrom = schedule.getPreviousRepetitionFrom(nextDueOn);

var oneTimeDueOn = _scheduledTask?.schedule.oneTimeDueOn;
DateTime? oneTimeCompletedOn = null;
if (_repetitionMode == RepetitionMode.ONE_TIME) {
oneTimeCompletedOn = _scheduledTask?.oneTimeCompletedOn;
final now = DateTime.now();
if (_scheduledTask == null || _scheduledTask!.isOneTimeCompleted) {
// reuse this schedule once completed
scheduleFrom = now;
oneTimeDueOn = nextDueOn;
oneTimeCompletedOn = null;
}
else {
// just update this schedule
Expand All @@ -739,7 +736,7 @@ class _ScheduledTaskFormState extends State<ScheduledTaskForm> {
createdAt: _scheduledTask?.createdAt ?? DateTime.now(),
schedule: schedule,
lastScheduledEventOn: scheduleFrom,
oneTimeCompletedOn: oneTimeCompletedOn,
oneTimeCompletedOn: null,
active: _isActive,
important: _isImportant,
reminderNotificationEnabled: _isRemindersEnabled,
Expand Down
3 changes: 3 additions & 0 deletions metadata/en-US/changelogs/10601.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Completing fixed schedules will also move non-due schedules further
* Fix sort order of reused One-Time schedules
* Fix progress bar color when close to due
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.6.0+10600
version: 1.6.1+10601

environment:
sdk: ">=3.0.0"
Expand Down

0 comments on commit 020ad43

Please sign in to comment.