From e3cba91b9c508322b01ac5b73978cc443fd1cb67 Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Mon, 9 Sep 2019 22:50:22 +0800 Subject: [PATCH] feat: style tweaks --- lib/screens/object.dart | 4 +- lib/screens/organization.dart | 5 +- lib/screens/repo.dart | 28 +++---- lib/screens/repos.dart | 2 +- lib/screens/user.dart | 5 +- lib/screens/users.dart | 56 +++----------- lib/widgets/repo_item.dart | 140 ++++++++++++++++++---------------- 7 files changed, 106 insertions(+), 134 deletions(-) diff --git a/lib/screens/object.dart b/lib/screens/object.dart index d6a56b1..4059f88 100644 --- a/lib/screens/object.dart +++ b/lib/screens/object.dart @@ -45,7 +45,7 @@ class ObjectScreen extends StatelessWidget { case 'blob': return [ SizedBox(width: 6), - SetiIcon(item['name'], size: 28), + SetiIcon(item['name'], size: 28, light: true), SizedBox(width: 6), ]; case 'tree': @@ -101,7 +101,7 @@ class ObjectScreen extends StatelessWidget { // TODO: All image types var ext = path.extension(item['name']); if (ext.isNotEmpty) ext = ext.substring(1); - if (['png', 'jpg', 'jpeg'].contains(ext)) { + if (['png', 'jpg', 'jpeg', 'gif', 'webp'].contains(ext)) { return ImageView(NetworkImage('$rawUrl/' + item['name'])); } return ObjectScreen( diff --git a/lib/screens/organization.dart b/lib/screens/organization.dart index 8e64f33..0cafb7c 100644 --- a/lib/screens/organization.dart +++ b/lib/screens/organization.dart @@ -73,10 +73,7 @@ class _OrganizationScreenState extends State { ), items: items, itemBuilder: (item, _) { - return RepoItem( - item, - showOwner: item['owner']['login'] != widget.login, - ); + return RepoItem(item); }, ); } diff --git a/lib/screens/repo.dart b/lib/screens/repo.dart index 1e0842e..fb93ec0 100644 --- a/lib/screens/repo.dart +++ b/lib/screens/repo.dart @@ -2,6 +2,7 @@ import 'dart:convert'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:git_touch/models/settings.dart'; +import 'package:git_touch/screens/users.dart'; import 'package:git_touch/utils/utils.dart'; import 'package:git_touch/widgets/table_view.dart'; import 'package:primer/primer.dart'; @@ -46,6 +47,9 @@ class RepoScreen extends StatelessWidget { isPrivate isFork description + watchers { + totalCount + } stargazers { totalCount } @@ -108,7 +112,7 @@ class RepoScreen extends StatelessWidget { @override Widget build(BuildContext context) { return RefreshScaffold( - title: Text(owner + '/' + name), + title: Text('Repository'), trailingBuilder: (data) { var payload = data[0]; @@ -179,27 +183,25 @@ class RepoScreen extends StatelessWidget { return Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ - RepoItem(payload, isLink: false), + RepoItem(payload, inRepoScreen: true), BorderView(), Row( children: [ EntryItem( - count: payload['issues']['totalCount'], - text: 'Issues', + count: payload['watchers']['totalCount'], + text: 'Watchers', screenBuilder: (context) => - IssuesScreen(owner: owner, name: name), + UsersScreen(login: 'pd4d10'), // FIXME: ), EntryItem( - count: payload['pullRequests']['totalCount'], - text: 'Pull Requests', - screenBuilder: (context) => IssuesScreen( - owner: owner, name: name, isPullRequest: true), + count: payload['stargazers']['totalCount'], + text: 'Stars', + screenBuilder: (context) => UsersScreen(login: 'pd4d10'), ), EntryItem( - count: payload['defaultBranchRef']['target']['history'] - ['totalCount'], - text: 'Commits', - screenBuilder: (context) => CommitsScreen(owner, name), + count: payload['forks']['totalCount'], + text: 'Forks', + screenBuilder: (context) => UsersScreen(login: 'pd4d10'), ), ], ), diff --git a/lib/screens/repos.dart b/lib/screens/repos.dart index 8eca3c9..7ce832f 100644 --- a/lib/screens/repos.dart +++ b/lib/screens/repos.dart @@ -64,7 +64,7 @@ class _ReposScreenState extends State { title: Text('$login\'s $title'), onRefresh: () => _queryRepos(), onLoadMore: (cursor) => _queryRepos(cursor), - itemBuilder: (payload) => RepoItem(payload, showOwner: widget.star), + itemBuilder: (payload) => RepoItem(payload), ); } } diff --git a/lib/screens/user.dart b/lib/screens/user.dart index 8788fd8..7b5ece4 100644 --- a/lib/screens/user.dart +++ b/lib/screens/user.dart @@ -91,10 +91,7 @@ class _UserScreenState extends State { ), items: items, itemBuilder: (item, _) { - return RepoItem( - item, - showOwner: item['owner']['login'] != widget.login, - ); + return RepoItem(item); }, ); } diff --git a/lib/screens/users.dart b/lib/screens/users.dart index ad9071f..1e394d9 100644 --- a/lib/screens/users.dart +++ b/lib/screens/users.dart @@ -51,9 +51,7 @@ class _UsersScreenState extends State { name login avatarUrl - bio - company - location + url } } } @@ -76,53 +74,23 @@ class _UsersScreenState extends State { child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Avatar(url: payload['avatarUrl']), + Avatar(url: payload['avatarUrl'], size: 20), SizedBox(width: 10), DefaultTextStyle( - style: TextStyle(color: PrimerColors.gray600, fontSize: 13), + style: TextStyle(color: PrimerColors.gray900, fontSize: 13), child: Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, - children: join(SizedBox(height: 8), [ - Row( - children: join(SizedBox(width: 10), [ - ifNotNull( - payload['name'] as String, - (String name) => Text( - name, - style: TextStyle( - fontSize: 16, color: PrimerColors.gray900), - ), - ), - Text(payload['login'], style: TextStyle(fontSize: 14)), - ]), - ), - (payload['bio'] == null || - (payload['bio'] as String).trim().isEmpty) - ? null - : Text(payload['bio']), - Row( - children: join(SizedBox(width: 10), [ - ifNotNull( - payload['company'] as String, - (String company) => Row(children: [ - Icon(Octicons.organization, - size: 14, color: PrimerColors.gray600), - SizedBox(width: 2), - Text(company) - ]), - ), - ifNotNull( - payload['location'] as String, - (String location) => Row(children: [ - Icon(Octicons.location, - size: 14, color: PrimerColors.gray600), - SizedBox(width: 2), - Text(location) - ]), - ), - ]), + children: join(SizedBox(height: 6), [ + Text( + payload['name'] ?? payload['login'], + style: TextStyle( + fontSize: 16, + color: PrimerColors.blue500, + fontWeight: FontWeight.w500, + ), ), + Text(payload['url'], style: TextStyle(fontSize: 14)) ]), ), ), diff --git a/lib/widgets/repo_item.dart b/lib/widgets/repo_item.dart index f9b3009..14749ba 100644 --- a/lib/widgets/repo_item.dart +++ b/lib/widgets/repo_item.dart @@ -8,10 +8,9 @@ import 'link.dart'; class RepoItem extends StatelessWidget { final Map payload; - final bool showOwner; - final bool isLink; + final bool inRepoScreen; - RepoItem(this.payload, {this.showOwner = true, this.isLink = true}); + RepoItem(this.payload, {this.inRepoScreen = false}); IconData _buildIconData() { if (payload['isPrivate']) { @@ -23,6 +22,57 @@ class RepoItem extends StatelessWidget { return Octicons.repo; } + Widget _buildStatus() { + return DefaultTextStyle( + style: TextStyle( + color: PrimerColors.gray800, + fontSize: 13, + fontWeight: FontWeight.w500, + ), + child: Row( + children: [ + Expanded( + child: Row(children: [ + Container( + width: 10, + height: 10, + decoration: BoxDecoration( + color: convertColor(payload['primaryLanguage'] == null + ? null + : payload['primaryLanguage']['color']), + shape: BoxShape.circle, + ), + ), + SizedBox(width: 4), + Text(payload['primaryLanguage'] == null + ? 'Unknown' + : payload['primaryLanguage']['name']), + ]), + ), + Expanded( + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Icon(Octicons.star, size: 14, color: PrimerColors.gray600), + Text(payload['stargazers']['totalCount'].toString()), + ], + ), + ), + Expanded( + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Icon(Octicons.repo_forked, + size: 14, color: PrimerColors.gray600), + Text(payload['forks']['totalCount'].toString()) + ], + ), + ), + ], + ), + ); + } + @override Widget build(BuildContext context) { var widget = Padding( @@ -36,14 +86,25 @@ class RepoItem extends StatelessWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: join(SizedBox(height: 8), [ - Text( - (showOwner ? (payload['owner']['login'] + ' / ') : '') + + Row( + children: [ + Text( + payload['owner']['login'] + ' / ', + style: TextStyle( + fontSize: 16, + color: PrimerColors.blue500, + fontWeight: FontWeight.w500, + ), + ), + Text( payload['name'], - style: TextStyle( - fontWeight: FontWeight.w500, - fontSize: 16, - color: PrimerColors.blue500, - ), + style: TextStyle( + fontSize: 16, + color: PrimerColors.blue500, + fontWeight: FontWeight.w600, + ), + ), + ], ), payload['description'] == null || (payload['description'] as String).isEmpty @@ -51,62 +112,9 @@ class RepoItem extends StatelessWidget { : Text( payload['description'], style: TextStyle( - color: PrimerColors.gray600, fontSize: 14), + color: PrimerColors.gray700, fontSize: 14), ), - DefaultTextStyle( - style: TextStyle( - color: PrimerColors.gray600, - fontSize: 13, - fontWeight: FontWeight.w500, - ), - child: Row( - children: [ - SizedBox( - width: 100, - child: Row(children: [ - Container( - width: 10, - height: 10, - decoration: BoxDecoration( - color: convertColor( - payload['primaryLanguage'] == null - ? null - : payload['primaryLanguage']['color']), - shape: BoxShape.circle, - ), - ), - SizedBox(width: 4), - Text(payload['primaryLanguage'] == null - ? 'Unknown' - : payload['primaryLanguage']['name']), - ]), - ), - SizedBox( - width: 100, - child: Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Icon(Octicons.star, - size: 14, color: PrimerColors.gray600), - Text( - payload['stargazers']['totalCount'].toString()), - ], - ), - ), - SizedBox( - width: 100, - child: Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Icon(Octicons.repo_forked, - size: 14, color: PrimerColors.gray600), - Text(payload['forks']['totalCount'].toString()) - ], - ), - ), - ], - ), - ) + ...(inRepoScreen ? [] : [_buildStatus()]) ]), ), ), @@ -115,7 +123,7 @@ class RepoItem extends StatelessWidget { ), ); - if (isLink) { + if (inRepoScreen) { // TODO: text style return Link( screenBuilder: (_) =>