diff --git a/lib/global.dart b/lib/global.dart index 0f8081a..061ae99 100644 --- a/lib/global.dart +++ b/lib/global.dart @@ -120,9 +120,9 @@ class VikunjaGlobalState extends State { }); return; } - loadedCurrentUser = User(int.tryParse(currentUser), "", "", ""); + loadedCurrentUser = User(int.tryParse(currentUser), "", ""); } catch (otherExceptions) { - loadedCurrentUser = User(int.tryParse(currentUser), "", "", ""); + loadedCurrentUser = User(int.tryParse(currentUser), "", ""); } setState(() { _client = client; diff --git a/lib/models/list.dart b/lib/models/list.dart index cf9a5ad..4578c4d 100644 --- a/lib/models/list.dart +++ b/lib/models/list.dart @@ -23,8 +23,8 @@ class TaskList { owner = User.fromJson(json['owner']), description = json['description'], title = json['title'], - updated = DateTime.fromMillisecondsSinceEpoch(json['updated']), - created = DateTime.fromMillisecondsSinceEpoch(json['created']), + updated = DateTime.parse(json['updated']), + created = DateTime.parse(json['created']), tasks = (json['tasks'] == null ? [] : json['tasks'] as List) ?.map((taskJson) => Task.fromJson(taskJson)) ?.toList(); @@ -35,8 +35,8 @@ class TaskList { "title": this.title, "description": this.description, "owner": this.owner?.toJSON(), - "created": this.created?.millisecondsSinceEpoch, - "updated": this.updated?.millisecondsSinceEpoch, + "created": this.created?.toIso8601String(), + "updated": this.updated?.toIso8601String(), }; } } diff --git a/lib/models/namespace.dart b/lib/models/namespace.dart index 700d2d7..f271914 100644 --- a/lib/models/namespace.dart +++ b/lib/models/namespace.dart @@ -19,13 +19,13 @@ class Namespace { : name = json['name'], description = json['description'], id = json['id'], - created = DateTime.fromMillisecondsSinceEpoch(json['created']), - updated = DateTime.fromMillisecondsSinceEpoch(json['updated']), + created = DateTime.parse(json['created']), + updated = DateTime.parse(json['updated']), owner = User.fromJson(json['owner']); toJSON() => { - "created": created?.millisecondsSinceEpoch, - "updated": updated?.millisecondsSinceEpoch, + "created": created?.toIso8601String(), + "updated": updated?.toIso8601String(), "name": name, "owner": owner?.toJSON(), "description": description diff --git a/lib/models/task.dart b/lib/models/task.dart index 897f63e..0a83f7a 100644 --- a/lib/models/task.dart +++ b/lib/models/task.dart @@ -22,12 +22,12 @@ class Task { Task.fromJson(Map json) : id = json['id'], - updated = DateTime.fromMillisecondsSinceEpoch(json['updated']), - created = DateTime.fromMillisecondsSinceEpoch(json['created']), + updated = DateTime.parse(json['updated']), + created = DateTime.parse(json['created']), reminders = (json['reminderDates'] as List) - ?.map((milli) => DateTime.fromMillisecondsSinceEpoch(milli)) + ?.map((r) => DateTime.parse(r)) ?.toList(), - due = DateTime.fromMillisecondsSinceEpoch(json['dueDate']), + due = DateTime.parse(json['dueDate']), description = json['description'], text = json['text'], done = json['done'], @@ -35,11 +35,11 @@ class Task { toJSON() => { 'id': id, - 'updated': updated?.millisecondsSinceEpoch, - 'created': created?.millisecondsSinceEpoch, + 'updated': updated?.toIso8601String(), + 'created': created?.toIso8601String(), 'reminderDates': - reminders?.map((date) => date.millisecondsSinceEpoch)?.toList(), - 'dueDate': due?.millisecondsSinceEpoch, + reminders?.map((date) => date.toIso8601String())?.toList(), + 'dueDate': due?.toIso8601String(), 'description': description, 'text': text, 'done': done ?? false, diff --git a/lib/models/user.dart b/lib/models/user.dart index 17f7639..08b0280 100644 --- a/lib/models/user.dart +++ b/lib/models/user.dart @@ -1,18 +1,20 @@ +import 'package:flutter/cupertino.dart'; +import 'package:vikunja_app/global.dart'; + class User { final int id; - final String email, username, avatarHash; + final String email, username; - User(this.id, this.email, this.username, this.avatarHash); + User(this.id, this.email, this.username); User.fromJson(Map json) : id = json['id'], email = json.containsKey('email') ? json['email'] : '', - username = json['username'], - avatarHash = json['avatarUrl']; + username = json['username']; toJSON() => {"id": this.id, "email": this.email, "username": this.username}; - String avatarUrl() { - return "https://secure.gravatar.com/avatar/" + this.avatarHash; + String avatarUrl(BuildContext context) { + return VikunjaGlobal.of(context).client.base + "/" + this.username + "/avatar"; } } diff --git a/lib/pages/home.dart b/lib/pages/home.dart index e37c07e..089cf07 100644 --- a/lib/pages/home.dart +++ b/lib/pages/home.dart @@ -101,7 +101,7 @@ class HomePageState extends State with AfterLayoutMixin { currentAccountPicture: currentUser == null ? null : CircleAvatar( - backgroundImage: NetworkImage(currentUser.avatarUrl()), + backgroundImage: NetworkImage(currentUser.avatarUrl(context)), ), decoration: BoxDecoration( image: DecorationImage( diff --git a/lib/service/mocked_services.dart b/lib/service/mocked_services.dart index 98913e1..35d5fbb 100644 --- a/lib/service/mocked_services.dart +++ b/lib/service/mocked_services.dart @@ -7,7 +7,7 @@ import 'package:vikunja_app/models/user.dart'; import 'package:vikunja_app/service/services.dart'; // Data for mocked services -var _users = {1: User(1, 'test@testuser.org', 'test1', '')}; +var _users = {1: User(1, 'test@testuser.org', 'test1')}; var _namespaces = { 1: Namespace(