2019-01-28 00:37:44 +08:00
|
|
|
import 'package:flutter/material.dart';
|
2019-01-25 20:35:20 +08:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2021-01-17 22:08:32 +08:00
|
|
|
import 'package:git_touch/graphql/github.data.gql.dart';
|
|
|
|
import 'package:git_touch/graphql/github.req.gql.dart';
|
2019-09-29 00:25:14 +08:00
|
|
|
import 'package:git_touch/models/theme.dart';
|
2019-09-25 17:06:36 +08:00
|
|
|
import 'package:git_touch/scaffolds/refresh_stateful.dart';
|
2019-10-06 21:27:00 +08:00
|
|
|
import 'package:git_touch/utils/utils.dart';
|
2020-01-27 14:43:10 +08:00
|
|
|
import 'package:git_touch/widgets/action_entry.dart';
|
2019-09-11 19:59:47 +08:00
|
|
|
import 'package:git_touch/widgets/app_bar_title.dart';
|
2020-10-05 16:07:07 +08:00
|
|
|
import 'package:git_touch/widgets/contribution.dart';
|
2020-01-12 14:49:46 +08:00
|
|
|
import 'package:git_touch/widgets/mutation_button.dart';
|
2019-10-06 21:27:00 +08:00
|
|
|
import 'package:git_touch/widgets/entry_item.dart';
|
2019-12-06 21:51:33 +08:00
|
|
|
import 'package:git_touch/widgets/repository_item.dart';
|
2019-09-04 22:59:33 +08:00
|
|
|
import 'package:git_touch/widgets/table_view.dart';
|
2020-10-04 22:20:21 +08:00
|
|
|
import 'package:git_touch/widgets/text_with_at.dart';
|
2019-09-27 20:52:38 +08:00
|
|
|
import 'package:git_touch/models/auth.dart';
|
2020-01-29 13:45:22 +08:00
|
|
|
import 'package:git_touch/widgets/user_header.dart';
|
2019-09-08 20:07:35 +08:00
|
|
|
import 'package:provider/provider.dart';
|
2019-09-30 16:31:07 +08:00
|
|
|
import 'package:git_touch/widgets/action_button.dart';
|
2021-02-03 09:34:41 +05:30
|
|
|
import 'package:flutter_gen/gen_l10n/S.dart';
|
2019-01-28 00:37:44 +08:00
|
|
|
|
2021-01-17 22:08:32 +08:00
|
|
|
class _Repos extends StatelessWidget {
|
|
|
|
final String title;
|
|
|
|
final Iterable<GRepoItem> repos;
|
2019-12-06 21:51:33 +08:00
|
|
|
|
2021-01-17 22:08:32 +08:00
|
|
|
_Repos(final Iterable<GRepoItem> pinned, final Iterable<GRepoItem> repos)
|
|
|
|
: title =
|
|
|
|
pinned.isNotEmpty ? 'pinned repositories' : 'popular repositories',
|
|
|
|
repos = pinned.isNotEmpty ? pinned : repos;
|
2019-12-06 21:51:33 +08:00
|
|
|
|
2021-01-17 22:08:32 +08:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: [
|
|
|
|
TableViewHeader(title),
|
|
|
|
...join(
|
|
|
|
CommonStyle.border,
|
|
|
|
repos.map((v) {
|
|
|
|
return RepositoryItem.gh(
|
|
|
|
owner: v.owner.login,
|
|
|
|
avatarUrl: v.owner.avatarUrl,
|
|
|
|
name: v.name,
|
|
|
|
description: v.description,
|
|
|
|
starCount: v.stargazers.totalCount,
|
|
|
|
forkCount: v.forks.totalCount,
|
|
|
|
primaryLanguageName: v.primaryLanguage?.name,
|
|
|
|
primaryLanguageColor: v.primaryLanguage?.color,
|
|
|
|
isPrivate: v.isPrivate,
|
|
|
|
isFork: v.isFork,
|
|
|
|
);
|
|
|
|
}).toList(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
2019-12-06 21:51:33 +08:00
|
|
|
}
|
2021-01-17 22:08:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
class _User extends StatelessWidget {
|
|
|
|
final GUserParts p;
|
|
|
|
final bool isViewer;
|
2021-01-31 15:49:28 +08:00
|
|
|
final List<Widget> rightWidgets;
|
|
|
|
const _User(this.p, {this.isViewer = false, this.rightWidgets = const []});
|
2019-12-06 21:51:33 +08:00
|
|
|
|
2021-01-17 22:08:32 +08:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2019-12-06 21:51:33 +08:00
|
|
|
final theme = Provider.of<ThemeModel>(context);
|
2020-01-12 14:49:46 +08:00
|
|
|
final login = p.login;
|
2021-01-17 22:08:32 +08:00
|
|
|
|
2019-12-06 21:51:33 +08:00
|
|
|
return Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: <Widget>[
|
2020-01-29 13:45:22 +08:00
|
|
|
UserHeader(
|
|
|
|
avatarUrl: p.avatarUrl,
|
|
|
|
name: p.name,
|
|
|
|
login: p.login,
|
|
|
|
createdAt: p.createdAt,
|
|
|
|
bio: p.bio,
|
2020-10-08 11:09:50 +02:00
|
|
|
isViewer: isViewer,
|
2021-01-31 15:49:28 +08:00
|
|
|
rightWidgets: rightWidgets,
|
2020-01-11 21:22:52 +08:00
|
|
|
),
|
2019-12-06 21:51:33 +08:00
|
|
|
CommonStyle.border,
|
|
|
|
Row(children: [
|
|
|
|
EntryItem(
|
2020-01-12 14:49:46 +08:00
|
|
|
count: p.repositories.totalCount,
|
2021-02-03 09:34:41 +05:30
|
|
|
text: AppLocalizations.of(context).repositories,
|
2020-05-12 21:01:30 +05:30
|
|
|
url: '/github/$login?tab=repositories',
|
2019-12-06 21:51:33 +08:00
|
|
|
),
|
|
|
|
EntryItem(
|
2020-01-12 14:49:46 +08:00
|
|
|
count: p.starredRepositories.totalCount,
|
2021-02-03 09:34:41 +05:30
|
|
|
text: AppLocalizations.of(context).stars,
|
2020-05-12 21:01:30 +05:30
|
|
|
url: '/github/$login?tab=stars',
|
2019-12-06 21:51:33 +08:00
|
|
|
),
|
|
|
|
EntryItem(
|
2020-01-12 14:49:46 +08:00
|
|
|
count: p.followers.totalCount,
|
2021-02-03 09:34:41 +05:30
|
|
|
text: AppLocalizations.of(context).followers,
|
2020-05-12 21:01:30 +05:30
|
|
|
url: '/github/$login?tab=followers',
|
2019-12-06 21:51:33 +08:00
|
|
|
),
|
|
|
|
EntryItem(
|
2020-01-12 14:49:46 +08:00
|
|
|
count: p.following.totalCount,
|
2021-02-03 09:34:41 +05:30
|
|
|
text: AppLocalizations.of(context).following,
|
2020-05-12 21:01:30 +05:30
|
|
|
url: '/github/$login?tab=following',
|
2019-12-06 21:51:33 +08:00
|
|
|
),
|
|
|
|
]),
|
2020-01-02 13:56:50 +08:00
|
|
|
CommonStyle.border,
|
2020-10-05 16:07:07 +08:00
|
|
|
ContributionWidget(
|
2020-10-05 16:47:26 +08:00
|
|
|
weeks: [
|
|
|
|
for (final week
|
|
|
|
in p.contributionsCollection.contributionCalendar.weeks)
|
|
|
|
[
|
2020-11-02 00:26:49 +08:00
|
|
|
// https://github.com/git-touch/git-touch/issues/122
|
2020-10-05 16:47:26 +08:00
|
|
|
for (final day in week.contributionDays)
|
2020-12-13 01:01:42 +08:00
|
|
|
ContributionDay(hexColor: day.color)
|
2020-10-05 16:47:26 +08:00
|
|
|
]
|
|
|
|
],
|
2020-01-01 13:26:20 +08:00
|
|
|
),
|
2020-01-02 13:56:50 +08:00
|
|
|
CommonStyle.border,
|
2019-12-06 21:51:33 +08:00
|
|
|
TableView(
|
|
|
|
hasIcon: true,
|
|
|
|
items: [
|
2020-05-14 10:58:12 +05:30
|
|
|
TableViewItem(
|
2021-02-14 22:17:22 +08:00
|
|
|
leftIconData: Octicons.rss,
|
2021-02-03 09:34:41 +05:30
|
|
|
text: Text(AppLocalizations.of(context).events),
|
2020-10-04 21:04:23 +08:00
|
|
|
url: '/github/$login?tab=events',
|
|
|
|
),
|
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.book,
|
2021-02-03 09:34:41 +05:30
|
|
|
text: Text(AppLocalizations.of(context).gists),
|
2020-10-04 21:04:23 +08:00
|
|
|
url: '/github/$login?tab=gists',
|
|
|
|
),
|
2020-04-28 22:29:01 +05:30
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.home,
|
2021-02-03 09:34:41 +05:30
|
|
|
text: Text(AppLocalizations.of(context).organizations),
|
2020-05-12 21:01:30 +05:30
|
|
|
url: '/github/$login?tab=organizations',
|
2020-04-28 22:29:01 +05:30
|
|
|
),
|
2020-01-12 14:49:46 +08:00
|
|
|
if (isNotNullOrEmpty(p.company))
|
2019-12-06 21:51:33 +08:00
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.organization,
|
2020-10-04 22:20:21 +08:00
|
|
|
text: TextWithAt(
|
|
|
|
text: p.company,
|
|
|
|
linkFactory: (text) => '/github/' + text.substring(1),
|
2020-01-27 15:11:51 +08:00
|
|
|
style: TextStyle(fontSize: 17, color: theme.palette.text),
|
2020-01-01 12:55:27 +08:00
|
|
|
oneLine: true,
|
2019-12-06 21:51:33 +08:00
|
|
|
),
|
|
|
|
),
|
2020-01-12 14:49:46 +08:00
|
|
|
if (isNotNullOrEmpty(p.location))
|
2019-12-06 21:51:33 +08:00
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.location,
|
2020-01-12 14:49:46 +08:00
|
|
|
text: Text(p.location),
|
2019-12-06 21:51:33 +08:00
|
|
|
onTap: () {
|
|
|
|
launchUrl('https://www.google.com/maps/place/' +
|
2020-01-12 14:49:46 +08:00
|
|
|
p.location.replaceAll(RegExp(r'\s+'), ''));
|
2019-12-06 21:51:33 +08:00
|
|
|
},
|
|
|
|
),
|
2020-01-12 14:49:46 +08:00
|
|
|
if (isNotNullOrEmpty(p.email))
|
2019-12-06 21:51:33 +08:00
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.mail,
|
2020-01-12 14:49:46 +08:00
|
|
|
text: Text(p.email),
|
2019-12-06 21:51:33 +08:00
|
|
|
onTap: () {
|
2020-01-12 14:49:46 +08:00
|
|
|
launchUrl('mailto:' + p.email);
|
2019-12-06 21:51:33 +08:00
|
|
|
},
|
|
|
|
),
|
2020-01-12 14:49:46 +08:00
|
|
|
if (isNotNullOrEmpty(p.websiteUrl))
|
2019-12-06 21:51:33 +08:00
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.link,
|
2020-01-12 14:49:46 +08:00
|
|
|
text: Text(p.websiteUrl),
|
2019-12-06 21:51:33 +08:00
|
|
|
onTap: () {
|
2020-01-12 14:49:46 +08:00
|
|
|
var url = p.websiteUrl;
|
2019-12-06 21:51:33 +08:00
|
|
|
if (!url.startsWith('http')) {
|
|
|
|
url = 'http://$url';
|
|
|
|
}
|
|
|
|
launchUrl(url);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2020-01-01 16:35:50 +08:00
|
|
|
CommonStyle.verticalGap,
|
2021-01-17 22:08:32 +08:00
|
|
|
_Repos(
|
|
|
|
p.pinnedItems.nodes.whereType<GRepoItem>(),
|
|
|
|
p.repositories.nodes,
|
|
|
|
),
|
2019-12-06 21:51:33 +08:00
|
|
|
CommonStyle.verticalGap,
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
2021-01-17 22:08:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
class _Org extends StatelessWidget {
|
|
|
|
final GUserData_repositoryOwner__asOrganization p;
|
|
|
|
_Org(this.p);
|
2019-12-06 21:51:33 +08:00
|
|
|
|
2021-01-17 22:08:32 +08:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2019-12-06 21:51:33 +08:00
|
|
|
return Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: <Widget>[
|
2020-01-29 13:45:22 +08:00
|
|
|
UserHeader(
|
|
|
|
avatarUrl: p.avatarUrl,
|
|
|
|
name: p.name,
|
|
|
|
login: p.login,
|
|
|
|
createdAt: p.createdAt,
|
|
|
|
bio: p.description,
|
|
|
|
),
|
2019-12-06 21:51:33 +08:00
|
|
|
CommonStyle.border,
|
|
|
|
Row(children: [
|
|
|
|
EntryItem(
|
2020-01-12 14:49:46 +08:00
|
|
|
count: p.pinnableItems.totalCount,
|
2021-02-03 09:34:41 +05:30
|
|
|
text: AppLocalizations.of(context).repositories,
|
2020-05-12 21:01:30 +05:30
|
|
|
url: '/github/${p.login}?tab=orgrepo',
|
2019-12-06 21:51:33 +08:00
|
|
|
),
|
|
|
|
EntryItem(
|
2020-01-12 14:49:46 +08:00
|
|
|
count: p.membersWithRole.totalCount,
|
2021-02-03 09:34:41 +05:30
|
|
|
text: AppLocalizations.of(context).members,
|
2020-05-12 21:01:30 +05:30
|
|
|
url: '/github/${p.login}?tab=people',
|
2019-12-06 21:51:33 +08:00
|
|
|
),
|
|
|
|
]),
|
|
|
|
TableView(
|
|
|
|
hasIcon: true,
|
|
|
|
items: [
|
2020-10-04 21:04:23 +08:00
|
|
|
TableViewItem(
|
2021-02-14 22:17:22 +08:00
|
|
|
leftIconData: Octicons.rss,
|
2021-02-03 09:34:41 +05:30
|
|
|
text: Text(AppLocalizations.of(context).events),
|
2021-01-17 22:08:32 +08:00
|
|
|
url: '/github/${p.login}?tab=events',
|
2020-10-04 21:04:23 +08:00
|
|
|
),
|
2020-01-12 14:49:46 +08:00
|
|
|
if (isNotNullOrEmpty(p.location))
|
2019-12-06 21:51:33 +08:00
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.location,
|
2020-01-12 14:49:46 +08:00
|
|
|
text: Text(p.location),
|
2019-12-06 21:51:33 +08:00
|
|
|
onTap: () {
|
|
|
|
launchUrl('https://www.google.com/maps/place/' +
|
2020-01-12 14:49:46 +08:00
|
|
|
p.location.replaceAll(RegExp(r'\s+'), ''));
|
2019-12-06 21:51:33 +08:00
|
|
|
},
|
|
|
|
),
|
2020-01-12 14:49:46 +08:00
|
|
|
if (isNotNullOrEmpty(p.email))
|
2019-12-06 21:51:33 +08:00
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.mail,
|
2020-01-12 14:49:46 +08:00
|
|
|
text: Text(p.email),
|
2019-12-06 21:51:33 +08:00
|
|
|
onTap: () {
|
2020-01-12 14:49:46 +08:00
|
|
|
launchUrl('mailto:' + p.email);
|
2019-12-06 21:51:33 +08:00
|
|
|
},
|
|
|
|
),
|
2020-01-12 14:49:46 +08:00
|
|
|
if (isNotNullOrEmpty(p.websiteUrl))
|
2019-12-06 21:51:33 +08:00
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.link,
|
2020-01-12 14:49:46 +08:00
|
|
|
text: Text(p.websiteUrl),
|
2019-12-06 21:51:33 +08:00
|
|
|
onTap: () {
|
2020-01-12 14:49:46 +08:00
|
|
|
var url = p.websiteUrl;
|
2019-12-06 21:51:33 +08:00
|
|
|
if (!url.startsWith('http')) {
|
|
|
|
url = 'http://$url';
|
|
|
|
}
|
|
|
|
launchUrl(url);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2020-01-01 16:35:50 +08:00
|
|
|
CommonStyle.verticalGap,
|
2021-01-17 22:08:32 +08:00
|
|
|
_Repos(
|
|
|
|
p.pinnedItems.nodes.whereType<GRepoItem>(),
|
|
|
|
p.pinnableItems.nodes.whereType<GRepoItem>(),
|
2019-12-06 21:51:33 +08:00
|
|
|
),
|
|
|
|
CommonStyle.verticalGap,
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
2021-01-17 22:08:32 +08:00
|
|
|
}
|
2019-12-06 21:51:33 +08:00
|
|
|
|
2021-01-17 22:08:32 +08:00
|
|
|
class GhViewer extends StatelessWidget {
|
2019-01-25 20:35:20 +08:00
|
|
|
@override
|
2019-01-28 00:37:44 +08:00
|
|
|
Widget build(BuildContext context) {
|
2020-01-07 15:32:48 +08:00
|
|
|
final auth = Provider.of<AuthModel>(context);
|
2021-01-17 22:08:32 +08:00
|
|
|
return RefreshStatefulScaffold<GUserParts>(
|
2020-10-06 20:52:40 +08:00
|
|
|
fetch: () async {
|
2021-01-17 22:08:32 +08:00
|
|
|
final req = GViewerReq();
|
|
|
|
final res = await auth.gqlClient.request(req).first;
|
|
|
|
return res.data.viewer;
|
2019-03-07 21:10:52 +08:00
|
|
|
},
|
2021-02-03 09:34:41 +05:30
|
|
|
title: AppBarTitle(AppLocalizations.of(context).me),
|
2021-01-17 22:08:32 +08:00
|
|
|
action: ActionEntry(
|
2021-02-14 22:17:22 +08:00
|
|
|
iconData: Ionicons.cog,
|
2021-01-17 22:08:32 +08:00
|
|
|
url: '/settings',
|
|
|
|
),
|
2021-01-31 15:49:28 +08:00
|
|
|
bodyBuilder: (p, _) {
|
2021-01-17 22:08:32 +08:00
|
|
|
return _User(p, isViewer: true);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class GhUser extends StatelessWidget {
|
|
|
|
final String login;
|
|
|
|
GhUser(this.login);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final auth = Provider.of<AuthModel>(context);
|
|
|
|
return RefreshStatefulScaffold<GUserData>(
|
|
|
|
fetch: () async {
|
|
|
|
final req = GUserReq((b) => b..vars.login = login);
|
|
|
|
final res = await auth.gqlClient.request(req).first;
|
|
|
|
return res.data;
|
|
|
|
},
|
|
|
|
title: AppBarTitle(login),
|
2021-01-31 15:49:28 +08:00
|
|
|
actionBuilder: (payload, _) {
|
2021-01-17 22:08:32 +08:00
|
|
|
return ActionButton(
|
|
|
|
title: 'User Actions',
|
|
|
|
items: ActionItem.getUrlActions(payload.repositoryOwner.url),
|
|
|
|
);
|
|
|
|
},
|
2021-01-31 15:49:28 +08:00
|
|
|
bodyBuilder: (data, setData) {
|
|
|
|
if (data.repositoryOwner.G__typename == 'User') {
|
|
|
|
final p = data.repositoryOwner as GUserData_repositoryOwner__asUser;
|
|
|
|
return _User(
|
|
|
|
p,
|
|
|
|
rightWidgets: [
|
|
|
|
if (p.viewerCanFollow)
|
|
|
|
MutationButton(
|
|
|
|
active: p.viewerIsFollowing,
|
|
|
|
text: p.viewerIsFollowing
|
2021-02-03 09:34:41 +05:30
|
|
|
? AppLocalizations.of(context).unfollow
|
|
|
|
: AppLocalizations.of(context).follow,
|
2021-01-31 15:49:28 +08:00
|
|
|
onTap: () async {
|
|
|
|
if (p.viewerIsFollowing) {
|
|
|
|
await auth.ghClient.users.unfollowUser(p.login);
|
|
|
|
} else {
|
|
|
|
await auth.ghClient.users.followUser(p.login);
|
|
|
|
}
|
|
|
|
setData(data.rebuild((b) {
|
|
|
|
final u = b.repositoryOwner
|
|
|
|
as GUserData_repositoryOwner__asUser;
|
|
|
|
b.repositoryOwner = u.rebuild((b1) {
|
|
|
|
b1.viewerIsFollowing = !b1.viewerIsFollowing;
|
|
|
|
});
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
2021-01-17 22:08:32 +08:00
|
|
|
} else {
|
2021-01-31 15:49:28 +08:00
|
|
|
return _Org(data.repositoryOwner
|
|
|
|
as GUserData_repositoryOwner__asOrganization);
|
2019-12-06 21:51:33 +08:00
|
|
|
}
|
2019-02-03 23:10:10 +08:00
|
|
|
},
|
2019-02-03 15:50:17 +08:00
|
|
|
);
|
2019-01-25 20:35:20 +08:00
|
|
|
}
|
|
|
|
}
|