diff --git a/lib/home.dart b/lib/home.dart index fd7e897..befc08a 100644 --- a/lib/home.dart +++ b/lib/home.dart @@ -3,6 +3,7 @@ import 'package:flutter/cupertino.dart'; import 'package:git_touch/models/auth.dart'; import 'package:git_touch/models/notification.dart'; import 'package:git_touch/models/theme.dart'; +import 'package:git_touch/screens/gitlab_explore.dart'; import 'package:git_touch/screens/gitlab_project.dart'; import 'package:git_touch/screens/gitlab_todos.dart'; import 'package:git_touch/screens/gitlab_user.dart'; @@ -49,7 +50,7 @@ class _HomeState extends State { case PlatformType.gitlab: switch (index) { case 0: - return GitlabTodosScreen(); + return GitlabExplore(); case 1: return GitlabUserScreen(null); } @@ -108,12 +109,11 @@ class _HomeState extends State { case PlatformType.gitlab: return [ BottomNavigationBarItem( - icon: Icon(Icons.timeline), - title: Text('Todos'), + icon: Icon(Icons.explore), + title: Text('Explore'), ), BottomNavigationBarItem( - icon: Icon(Icons.person_outline), - activeIcon: Icon(Icons.person), + icon: Icon(Icons.person), title: Text('Me'), ), ]; diff --git a/lib/models/gitlab.dart b/lib/models/gitlab.dart index d830190..89c1008 100644 --- a/lib/models/gitlab.dart +++ b/lib/models/gitlab.dart @@ -98,6 +98,7 @@ class GitlabProject { int openIssuesCount; bool mergeRequestsEnabled; GitlabProjectStatistics statistics; + DateTime lastActivityAt; GitlabProject(); factory GitlabProject.fromJson(Map json) => _$GitlabProjectFromJson(json); @@ -124,6 +125,7 @@ class GitlabProjectStatistics { class GitlabProjectNamespace { int id; String name; + String path; GitlabProjectNamespace(); factory GitlabProjectNamespace.fromJson(Map json) => diff --git a/lib/models/gitlab.g.dart b/lib/models/gitlab.g.dart index 53956d9..e442b3e 100644 --- a/lib/models/gitlab.g.dart +++ b/lib/models/gitlab.g.dart @@ -147,7 +147,10 @@ GitlabProject _$GitlabProjectFromJson(Map json) { ..statistics = json['statistics'] == null ? null : GitlabProjectStatistics.fromJson( - json['statistics'] as Map); + json['statistics'] as Map) + ..lastActivityAt = json['last_activity_at'] == null + ? null + : DateTime.parse(json['last_activity_at'] as String); } Map _$GitlabProjectToJson(GitlabProject instance) => @@ -166,6 +169,7 @@ Map _$GitlabProjectToJson(GitlabProject instance) => 'open_issues_count': instance.openIssuesCount, 'merge_requests_enabled': instance.mergeRequestsEnabled, 'statistics': instance.statistics, + 'last_activity_at': instance.lastActivityAt?.toIso8601String(), }; GitlabProjectBadge _$GitlabProjectBadgeFromJson(Map json) { @@ -196,7 +200,8 @@ GitlabProjectNamespace _$GitlabProjectNamespaceFromJson( Map json) { return GitlabProjectNamespace() ..id = json['id'] as int - ..name = json['name'] as String; + ..name = json['name'] as String + ..path = json['path'] as String; } Map _$GitlabProjectNamespaceToJson( @@ -204,6 +209,7 @@ Map _$GitlabProjectNamespaceToJson( { 'id': instance.id, 'name': instance.name, + 'path': instance.path, }; GitlabTreeItem _$GitlabTreeItemFromJson(Map json) { diff --git a/lib/scaffolds/list_stateful.dart b/lib/scaffolds/list_stateful.dart index 152b072..d532a6f 100644 --- a/lib/scaffolds/list_stateful.dart +++ b/lib/scaffolds/list_stateful.dart @@ -14,7 +14,11 @@ class ListPayload { List items; bool hasMore; - ListPayload({this.items, this.cursor, this.hasMore}); + ListPayload({ + @required this.items, + @required this.cursor, + @required this.hasMore, + }); } // This is a scaffold for infinite scroll screens diff --git a/lib/screens/gitlab_explore.dart b/lib/screens/gitlab_explore.dart new file mode 100644 index 0000000..6f3fa21 --- /dev/null +++ b/lib/screens/gitlab_explore.dart @@ -0,0 +1,46 @@ +import 'package:flutter/material.dart'; +import 'package:git_touch/models/auth.dart'; +import 'package:git_touch/models/gitlab.dart'; +import 'package:git_touch/scaffolds/list_stateful.dart'; +import 'package:git_touch/widgets/app_bar_title.dart'; +import 'package:git_touch/widgets/repository_item.dart'; +import 'package:provider/provider.dart'; +import 'package:timeago/timeago.dart' as timeago; + +class GitlabExplore extends StatelessWidget { + Future> _query(BuildContext context, + [int page = 1]) async { + final auth = Provider.of(context); + final res = await auth + .fetchGitlabWithPage('/projects?order_by=last_activity_at&page=$page'); + return ListPayload( + cursor: res.cursor, + hasMore: res.hasMore, + items: [ + for (var v in res.data) GitlabProject.fromJson(v), + ], + ); + } + + @override + Widget build(BuildContext context) { + return ListStatefulScaffold( + title: AppBarTitle('Explore'), + onRefresh: () => _query(context), + onLoadMore: (page) => _query(context, page), + itemBuilder: (v) { + return RepositoryItem.gl( + id: v.id, + owner: v.namespace.path, + avatarUrl: v.avatarUrl, + name: v.name, + description: v.description, + starCount: v.starCount, + forkCount: v.forksCount, + note: 'Updated ${timeago.format(v.lastActivityAt)}', + visibility: v.visibility, + ); + }, + ); + } +}