Skip to content

Commit

Permalink
fix: understand new TaskReminder class
Browse files Browse the repository at this point in the history
  • Loading branch information
Benimautner committed Jun 6, 2024
1 parent 8423c8c commit bed2a8f
Show file tree
Hide file tree
Showing 4 changed files with 232 additions and 188 deletions.
4 changes: 2 additions & 2 deletions lib/managers/notifications.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ class NotificationClass {
"Reminder",
"This is your reminder for '" + task.title + "'",
notificationsPlugin,
reminder,
reminder.reminder,
await FlutterTimezone.getLocalTimezone(),
platformChannelSpecificsReminders,
id: (reminder.millisecondsSinceEpoch / 1000).floor(),
id: (reminder.reminder.millisecondsSinceEpoch / 1000).floor(),
);
}
if (task.hasDueDate) {
Expand Down
33 changes: 26 additions & 7 deletions lib/models/task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@ import 'package:vikunja_app/models/user.dart';
import 'package:vikunja_app/models/taskAttachment.dart';
import 'package:vikunja_app/utils/checkboxes_in_text.dart';

class TaskReminder {
final int relative_period;
final String relative_to;
DateTime reminder;

TaskReminder(this.reminder) : relative_period = 0, relative_to = "";

TaskReminder.fromJson(Map<String, dynamic> json)
: reminder = DateTime.parse(json['reminder']),
relative_period = json['relative_period'],
relative_to = json['relative_to'];

toJSON() => {
'relative_period': relative_period,
'relative_to': relative_to,
'reminder': reminder.toUtc().toIso8601String(),
};
}

@JsonSerializable()
class Task {
final int id;
Expand All @@ -14,7 +33,7 @@ class Task {
final int? projectId;
final DateTime created, updated;
DateTime? dueDate, startDate, endDate;
final List<DateTime> reminderDates;
final List<TaskReminder> reminderDates;
final String identifier;
final String title, description;
final bool done;
Expand Down Expand Up @@ -76,9 +95,9 @@ class Task {
description = json['description'],
identifier = json['identifier'],
done = json['done'],
reminderDates = json['reminder_dates'] != null
? (json['reminder_dates'] as List<dynamic>)
.map((ts) => DateTime.parse(ts))
reminderDates = json['reminders'] != null
? (json['reminders'] as List<dynamic>)
.map((ts) => TaskReminder.fromJson(ts))
.toList()
: [],
dueDate = DateTime.parse(json['due_date']),
Expand Down Expand Up @@ -124,8 +143,8 @@ class Task {
'description': description,
'identifier': identifier.isNotEmpty ? identifier : null,
'done': done,
'reminder_dates': reminderDates
.map((date) => date.toUtc().toIso8601String())
'reminders': reminderDates
.map((date) => date.toJSON())
.toList(),
'due_date': dueDate?.toUtc().toIso8601String(),
'start_date': startDate?.toUtc().toIso8601String(),
Expand Down Expand Up @@ -158,7 +177,7 @@ class Task {
DateTime? dueDate,
DateTime? startDate,
DateTime? endDate,
List<DateTime>? reminderDates,
List<TaskReminder>? reminderDates,
String? title,
String? description,
String? identifier,
Expand Down
Loading

0 comments on commit bed2a8f

Please sign in to comment.