diff --git a/lib/components/AddDialog.dart b/lib/components/AddDialog.dart index 15b1aec..1f844a7 100644 --- a/lib/components/AddDialog.dart +++ b/lib/components/AddDialog.dart @@ -1,24 +1,49 @@ import 'package:flutter/material.dart'; -class AddDialog extends StatelessWidget { - final ValueChanged onAdd; - final InputDecoration decoration; +import '../models/task.dart'; - const AddDialog({Key key, this.onAdd, this.decoration}) : super(key: key); +enum NewTaskDue {day,week, month} +Map newTaskDueToDuration = { + NewTaskDue.day: Duration(days: 1), + NewTaskDue.week: Duration(days: 7), + NewTaskDue.month: Duration(days: 30), +}; + +class AddDialog extends StatefulWidget { + final ValueChanged onAdd; + final ValueChanged onAddTask; + final InputDecoration decoration; + const AddDialog({Key key, this.onAdd, this.decoration, this.onAddTask}) : super(key: key); + + @override + State createState() => AddDialogState(); + +} + +class AddDialogState extends State { + NewTaskDue newTaskDue = NewTaskDue.day; @override Widget build(BuildContext context) { var textController = TextEditingController(); return new AlertDialog( contentPadding: const EdgeInsets.all(16.0), - content: new Row(children: [ - Expanded( - child: new TextField( - autofocus: true, - decoration: this.decoration, - controller: textController, + content: new Column( + mainAxisSize: MainAxisSize.min, + children: [ + Row(children: [ + Expanded( + child: new TextField( + autofocus: true, + decoration: widget.decoration, + controller: textController, + ), ), - ) + ]), + widget.onAddTask != null ? taskDueList("1 Day", NewTaskDue.day) : new Container(), + widget.onAddTask != null ? taskDueList("1 Week", NewTaskDue.week) : new Container(), + widget.onAddTask != null ? taskDueList("1 Month", NewTaskDue.month) : new Container(), + //],) ]), actions: [ new TextButton( @@ -28,12 +53,33 @@ class AddDialog extends StatelessWidget { new TextButton( child: const Text('ADD'), onPressed: () { - if (this.onAdd != null && textController.text.isNotEmpty) - this.onAdd(textController.text); + if (widget.onAdd != null && textController.text.isNotEmpty) + widget.onAdd(textController.text); + if(widget.onAddTask != null && textController.text.isNotEmpty) + widget.onAddTask(Task(id: null, title: textController.text, done: false, owner: null, due: DateTime.now().add(newTaskDueToDuration[newTaskDue]))); Navigator.pop(context); }, ) ], ); } + + Widget taskDueList(String name, NewTaskDue thisNewTaskDue) { + // TODO: I know you can do better + return Row(children: [ + Checkbox(value: newTaskDue == thisNewTaskDue, onChanged: (value) { setState(() => newTaskDue = value ? thisNewTaskDue: newTaskDue);}, shape: CircleBorder(),), + Text(name), + ]); + /*Row(children: [ + Checkbox(value: newTaskDue == NewTaskDue.week, onChanged: (value) { setState(() => newTaskDue = value ? NewTaskDue.week: newTaskDue);}, shape: CircleBorder(),), + Text("1 Week"), + ]), + Row(children: [ + Checkbox(value: newTaskDue == NewTaskDue.month, onChanged: (value) { setState(() => newTaskDue = value ? NewTaskDue.month: newTaskDue);}, shape: CircleBorder(),), + Text("1 Month"), + ]) + ]; + + */ + } } diff --git a/lib/components/TaskTile.dart b/lib/components/TaskTile.dart index 22d5beb..497e5ab 100644 --- a/lib/components/TaskTile.dart +++ b/lib/components/TaskTile.dart @@ -5,6 +5,7 @@ import 'package:flutter/material.dart'; import 'package:vikunja_app/global.dart'; import 'package:vikunja_app/models/task.dart'; import 'package:vikunja_app/pages/task/edit_task.dart'; +import 'package:vikunja_app/utils/misc.dart'; class TaskTile extends StatefulWidget { final Task task; @@ -34,6 +35,7 @@ class TaskTileState extends State { @override Widget build(BuildContext context) { + Duration durationUntilDue = _currentTask.due.difference(DateTime.now()); if (_currentTask.loading) { return ListTile( leading: Padding( @@ -69,7 +71,7 @@ class TaskTileState extends State { controlAffinity: ListTileControlAffinity.leading, value: _currentTask.done ?? false, subtitle: widget.showInfo && _currentTask.due.year > 2 ? - Text("Due in " + _currentTask.due.difference(DateTime.now()).inDays.toString() + " days.") + Text("Due in " + durationToHumanReadable(durationUntilDue),style: TextStyle(color: durationUntilDue.isNegative ? Colors.red : null),) : _currentTask.description == null || _currentTask.description.isEmpty ? null : Text(_currentTask.description), diff --git a/lib/models/task.dart b/lib/models/task.dart index 7fc1c1a..4622166 100644 --- a/lib/models/task.dart +++ b/lib/models/task.dart @@ -47,7 +47,7 @@ class Task { 'created': created?.toIso8601String(), 'reminder_dates': reminders?.map((date) => date.toIso8601String())?.toList(), - 'due_date': due?.toIso8601String(), + 'due_date': due.toUtc()?.toIso8601String(), 'description': description, 'title': title, 'done': done ?? false, diff --git a/lib/models/user.dart b/lib/models/user.dart index 56e21fa..66e32a2 100644 --- a/lib/models/user.dart +++ b/lib/models/user.dart @@ -15,9 +15,9 @@ class User { String avatarUrl(BuildContext context) { return VikunjaGlobal.of(context).client.base + - "/" + - this.username + - "/avatar"; + "/avatar/ " + + this.username+ + "?size=50"; } } diff --git a/lib/pages/landing_page.dart b/lib/pages/landing_page.dart index bb77434..6abaac7 100644 --- a/lib/pages/landing_page.dart +++ b/lib/pages/landing_page.dart @@ -72,16 +72,14 @@ class LandingPageState extends State { showDialog( context: context, builder: (_) => AddDialog( - onAdd: (name) => _addItem(name, context), + onAddTask: (task) => _addTask(task, context), decoration: new InputDecoration( labelText: 'Task Name', hintText: 'eg. Milk'))); } - _addItem(String name, BuildContext context) { + _addTask(Task task, BuildContext context) { var globalState = VikunjaGlobal.of(context); - var newTask = Task( - id: null, title: name, owner: globalState.currentUser, done: false, loading: true); - globalState.taskService.add(defaultList, newTask).then((_) { + globalState.taskService.add(defaultList, task).then((_) { ScaffoldMessenger.of(context).showSnackBar(SnackBar( content: Text('The task was added successfully!'), )); diff --git a/lib/service/services.dart b/lib/service/services.dart index 9cc0623..014bfc1 100644 --- a/lib/service/services.dart +++ b/lib/service/services.dart @@ -62,7 +62,6 @@ class TaskServiceOptions { if(result.startsWith('&')) result.substring(1); - log(result); return result; } } diff --git a/lib/utils/misc.dart b/lib/utils/misc.dart new file mode 100644 index 0000000..ae3630f --- /dev/null +++ b/lib/utils/misc.dart @@ -0,0 +1,11 @@ +String durationToHumanReadable(Duration dur) { + if(dur.inDays.abs() > 1) + return dur.inDays.toString() + " days"; + if(dur.inDays.abs() == 1) + return dur.inDays.toString() + " day"; + if(dur.inHours.abs() > 1) + return dur.inHours.toString() + " hours"; + if(dur.inHours.abs() == 1) + return dur.inHours.toString() + "1 hour"; + return "under 1 hour"; +} \ No newline at end of file