diff --git a/lib/models/gitlab.dart b/lib/models/gitlab.dart index c8cefda..c8ed29c 100644 --- a/lib/models/gitlab.dart +++ b/lib/models/gitlab.dart @@ -11,6 +11,7 @@ class GitlabUserProject { int starCount; int forksCount; String visibility; + DateTime createdAt; GitlabUserProject(); diff --git a/lib/models/gitlab.g.dart b/lib/models/gitlab.g.dart index 0447d0b..0dec17b 100644 --- a/lib/models/gitlab.g.dart +++ b/lib/models/gitlab.g.dart @@ -16,7 +16,10 @@ GitlabUserProject _$GitlabUserProjectFromJson(Map json) { ..description = json['description'] as String ..starCount = json['star_count'] as int ..forksCount = json['forks_count'] as int - ..visibility = json['visibility'] as String; + ..visibility = json['visibility'] as String + ..createdAt = json['created_at'] == null + ? null + : DateTime.parse(json['created_at'] as String); } Map _$GitlabUserProjectToJson(GitlabUserProject instance) => @@ -28,6 +31,7 @@ Map _$GitlabUserProjectToJson(GitlabUserProject instance) => 'star_count': instance.starCount, 'forks_count': instance.forksCount, 'visibility': instance.visibility, + 'created_at': instance.createdAt?.toIso8601String(), }; GitlabUser _$GitlabUserFromJson(Map json) { diff --git a/lib/screens/gitlab_user.dart b/lib/screens/gitlab_user.dart index cd605f4..3e0e5a5 100644 --- a/lib/screens/gitlab_user.dart +++ b/lib/screens/gitlab_user.dart @@ -10,6 +10,7 @@ import 'package:git_touch/widgets/user_item.dart'; import 'package:provider/provider.dart'; import 'package:tuple/tuple.dart'; import 'package:git_touch/utils/utils.dart'; +import 'package:timeago/timeago.dart' as timeago; final gitlabUserRouter = RouterScreen( '/gitlab/user/:id', @@ -21,19 +22,6 @@ class GitlabUserScreen extends StatelessWidget { GitlabUserScreen(this.id); bool get isViewer => id == null; - static _getGitlabIcon(String visibility) { - switch (visibility) { - case 'internal': - return FontAwesome.shield; - case 'public': - return FontAwesome.globe; - case 'private': - return FontAwesome.lock; - default: - return Octicons.repo; - } - } - @override Widget build(BuildContext context) { return RefreshStatefulScaffold< @@ -74,14 +62,16 @@ class GitlabUserScreen extends StatelessWidget { Column( children: [ for (var v in projects) - RepositoryItem( + RepositoryItem.gl( + id: v.id, owner: v.owner.username, avatarUrl: v.owner.avatarUrl, name: v.name, description: v.description, starCount: v.starCount, forkCount: v.forksCount, - url: '/gitlab/projects/${v.id}', + note: 'Created ${timeago.format(v.createdAt)}', + visibility: v.visibility, ) ], ) diff --git a/lib/screens/repositories.dart b/lib/screens/repositories.dart index 2f8daa8..d777b77 100644 --- a/lib/screens/repositories.dart +++ b/lib/screens/repositories.dart @@ -1,7 +1,6 @@ import 'package:flutter/material.dart'; import 'package:git_touch/graphql/gh.dart'; import 'package:git_touch/scaffolds/list_stateful.dart'; -import 'package:git_touch/utils/utils.dart'; import 'package:git_touch/widgets/app_bar_title.dart'; import 'package:git_touch/models/auth.dart'; import 'package:provider/provider.dart'; diff --git a/lib/widgets/repository_item.dart b/lib/widgets/repository_item.dart index bedd806..dc87af1 100644 --- a/lib/widgets/repository_item.dart +++ b/lib/widgets/repository_item.dart @@ -33,6 +33,21 @@ class RepositoryItem extends StatelessWidget { @required this.url, }); + RepositoryItem.gl({ + @required id, + @required this.owner, + @required this.avatarUrl, + @required this.name, + @required this.description, + @required this.starCount, + @required this.forkCount, + @required visibility, + this.primaryLanguageName, + this.primaryLanguageColor, + this.note, + }) : url = '/gitlab/projects/$id', + iconData = _buildGlIconData(visibility); + RepositoryItem.gh({ @required this.owner, @required this.avatarUrl, @@ -45,8 +60,8 @@ class RepositoryItem extends StatelessWidget { this.note, @required bool isPrivate, @required bool isFork, - }) : this.iconData = _buildIconData(isPrivate, isFork), - this.url = '$owner/$name'; + }) : iconData = _buildIconData(isPrivate, isFork), + url = '$owner/$name'; static IconData _buildIconData(bool isPrivate, bool isFork) { if (isPrivate == true) return Octicons.lock; @@ -54,6 +69,19 @@ class RepositoryItem extends StatelessWidget { return null; } + static IconData _buildGlIconData(String visibility) { + switch (visibility) { + case 'internal': + return FontAwesome.shield; + case 'public': + return FontAwesome.globe; + case 'private': + return FontAwesome.lock; + default: + return Octicons.repo; + } + } + @override Widget build(BuildContext context) { final theme = Provider.of(context);