2019-02-03 16:10:10 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2019-02-04 14:38:29 +01:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2019-12-07 09:12:18 +01:00
|
|
|
import 'package:git_touch/graphql/github_repository.dart';
|
2019-12-07 08:28:43 +01:00
|
|
|
import 'package:git_touch/graphql/github_user.dart';
|
2019-12-04 15:02:22 +01:00
|
|
|
import 'package:git_touch/models/gitea.dart';
|
2019-12-04 15:00:39 +01:00
|
|
|
import 'package:git_touch/models/gitlab.dart';
|
2019-11-03 16:33:24 +01:00
|
|
|
import 'package:git_touch/models/theme.dart';
|
2019-12-11 16:09:39 +01:00
|
|
|
import 'package:git_touch/screens/gitlab_project.dart';
|
2019-09-23 12:28:33 +02:00
|
|
|
import 'package:git_touch/screens/repository.dart';
|
2019-11-03 16:33:24 +01:00
|
|
|
import 'package:git_touch/widgets/action_button.dart';
|
2019-09-08 15:20:12 +02:00
|
|
|
import 'package:git_touch/widgets/avatar.dart';
|
2019-08-31 16:17:35 +02:00
|
|
|
import 'package:primer/primer.dart';
|
2019-11-03 16:33:24 +01:00
|
|
|
import 'package:provider/provider.dart';
|
2019-02-03 16:10:10 +01:00
|
|
|
import '../utils/utils.dart';
|
|
|
|
import 'link.dart';
|
|
|
|
|
2019-09-21 19:23:38 +02:00
|
|
|
const repoChunk = '''
|
|
|
|
owner {
|
2019-10-03 04:12:22 +02:00
|
|
|
__typename
|
2019-09-21 19:23:38 +02:00
|
|
|
login
|
|
|
|
avatarUrl
|
|
|
|
}
|
|
|
|
name
|
|
|
|
description
|
|
|
|
isPrivate
|
|
|
|
isFork
|
|
|
|
stargazers {
|
|
|
|
totalCount
|
|
|
|
}
|
|
|
|
forks {
|
|
|
|
totalCount
|
|
|
|
}
|
|
|
|
primaryLanguage {
|
|
|
|
color
|
|
|
|
name
|
|
|
|
}
|
|
|
|
''';
|
|
|
|
|
2019-09-23 12:28:33 +02:00
|
|
|
class RepositoryItem extends StatelessWidget {
|
2019-11-02 10:50:04 +01:00
|
|
|
final String owner;
|
|
|
|
final String avatarUrl;
|
|
|
|
final String name;
|
|
|
|
final String description;
|
|
|
|
final IconData iconData;
|
|
|
|
final int starCount;
|
|
|
|
final int forkCount;
|
|
|
|
final String primaryLanguageName;
|
|
|
|
final String primaryLanguageColor;
|
|
|
|
final Widget Function(BuildContext context) screenBuilder;
|
2019-09-09 16:50:22 +02:00
|
|
|
final bool inRepoScreen;
|
2019-12-07 09:12:18 +01:00
|
|
|
final Iterable<GithubRepositoryRepositoryTopic> topics;
|
2019-02-03 16:10:10 +01:00
|
|
|
|
2019-12-07 07:42:33 +01:00
|
|
|
RepositoryItem.raw(
|
|
|
|
this.owner,
|
|
|
|
this.avatarUrl,
|
|
|
|
this.name,
|
|
|
|
this.description,
|
|
|
|
this.iconData,
|
|
|
|
this.starCount,
|
|
|
|
this.forkCount,
|
|
|
|
this.primaryLanguageName,
|
|
|
|
this.primaryLanguageColor,
|
|
|
|
this.screenBuilder,
|
|
|
|
this.topics,
|
|
|
|
{this.inRepoScreen = false});
|
|
|
|
|
2019-11-02 10:50:04 +01:00
|
|
|
RepositoryItem(payload, {this.inRepoScreen = false})
|
|
|
|
: this.owner = payload['owner']['login'],
|
|
|
|
this.avatarUrl = payload['owner']['avatarUrl'],
|
|
|
|
this.name = payload['name'],
|
|
|
|
this.description = payload['description'],
|
|
|
|
this.iconData = _buildIconData(payload),
|
|
|
|
this.starCount = payload['stargazers']['totalCount'],
|
|
|
|
this.forkCount = payload['forks']['totalCount'],
|
|
|
|
this.primaryLanguageName = payload['primaryLanguage'] == null
|
|
|
|
? null
|
|
|
|
: payload['primaryLanguage']['name'],
|
|
|
|
this.primaryLanguageColor = payload['primaryLanguage'] == null
|
|
|
|
? null
|
|
|
|
: payload['primaryLanguage']['color'],
|
|
|
|
this.screenBuilder = ((_) =>
|
|
|
|
RepositoryScreen(payload['owner']['login'], payload['name'])),
|
2019-12-07 09:12:18 +01:00
|
|
|
this.topics = [];
|
2019-02-03 16:10:10 +01:00
|
|
|
|
2019-12-07 08:28:43 +01:00
|
|
|
RepositoryItem.github(GithubUserRepository payload,
|
|
|
|
{this.inRepoScreen = false})
|
2019-12-07 14:12:48 +01:00
|
|
|
: this.owner = payload.owner.login,
|
|
|
|
this.avatarUrl = payload.owner.avatarUrl,
|
2019-12-06 14:51:33 +01:00
|
|
|
this.name = payload.name,
|
|
|
|
this.description = payload.description,
|
|
|
|
this.iconData = Octicons.repo, // TODO:
|
|
|
|
this.starCount = payload.stargazers.totalCount,
|
|
|
|
this.forkCount = payload.forks.totalCount,
|
|
|
|
this.primaryLanguageName = payload.primaryLanguage?.name,
|
|
|
|
this.primaryLanguageColor = payload.primaryLanguage?.color,
|
2019-12-07 14:12:48 +01:00
|
|
|
this.screenBuilder =
|
|
|
|
((_) => RepositoryScreen(payload.owner.login, payload.name)),
|
2019-12-06 14:51:33 +01:00
|
|
|
this.topics = []; // TODO:
|
|
|
|
// this.topics = payload['repositoryTopics'] == null
|
|
|
|
// ? []
|
|
|
|
// : payload['repositoryTopics']['nodes'];
|
|
|
|
|
2019-12-08 13:08:50 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-11 16:09:39 +01:00
|
|
|
RepositoryItem.gitlab(GitlabUserProject payload, {this.inRepoScreen = false})
|
2019-12-04 15:00:39 +01:00
|
|
|
: this.owner = payload.owner.name,
|
|
|
|
this.avatarUrl = payload.owner.avatarUrl,
|
|
|
|
this.name = payload.name,
|
|
|
|
this.description = payload.description,
|
2019-12-08 13:08:50 +01:00
|
|
|
this.iconData = _getGitlabIcon(payload.visibility),
|
2019-12-04 15:00:39 +01:00
|
|
|
this.starCount = payload.starCount,
|
|
|
|
this.forkCount = payload.forksCount,
|
2019-11-02 10:50:04 +01:00
|
|
|
this.primaryLanguageName = null,
|
|
|
|
this.primaryLanguageColor = null,
|
2019-12-11 16:09:39 +01:00
|
|
|
this.screenBuilder = ((_) => GitlabProjectScreen(payload.id)),
|
2019-11-02 10:50:04 +01:00
|
|
|
this.topics = [];
|
|
|
|
|
2019-12-04 15:02:22 +01:00
|
|
|
RepositoryItem.gitea(GiteaRepository payload, {this.inRepoScreen = false})
|
|
|
|
: this.owner = payload.owner.login,
|
|
|
|
this.avatarUrl = payload.owner.avatarUrl,
|
|
|
|
this.name = payload.name,
|
|
|
|
this.description = payload.description,
|
|
|
|
this.iconData = Octicons.repo,
|
|
|
|
this.starCount = payload.starsCount,
|
|
|
|
this.forkCount = payload.forksCount,
|
|
|
|
this.primaryLanguageName = null,
|
|
|
|
this.primaryLanguageColor = null,
|
|
|
|
this.screenBuilder = ((_) => RepositoryScreen('', '')), // TODO:
|
|
|
|
this.topics = [];
|
|
|
|
|
2019-11-02 10:50:04 +01:00
|
|
|
static IconData _buildIconData(payload) {
|
2019-03-02 11:17:46 +01:00
|
|
|
if (payload['isPrivate']) {
|
2019-02-04 11:32:39 +01:00
|
|
|
return Octicons.lock;
|
|
|
|
}
|
2019-03-02 11:17:46 +01:00
|
|
|
if (payload['isFork']) {
|
2019-02-04 11:32:39 +01:00
|
|
|
return Octicons.repo_forked;
|
|
|
|
}
|
|
|
|
return Octicons.repo;
|
|
|
|
}
|
|
|
|
|
2019-02-03 16:10:10 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2019-11-05 14:22:41 +01:00
|
|
|
final theme = Provider.of<ThemeModel>(context);
|
|
|
|
|
2019-10-02 08:58:11 +02:00
|
|
|
// TODO: text style
|
|
|
|
return Link(
|
2019-11-02 10:50:04 +01:00
|
|
|
screenBuilder: inRepoScreen ? null : screenBuilder,
|
2019-11-03 16:33:24 +01:00
|
|
|
onLongPress: () async {
|
|
|
|
await Provider.of<ThemeModel>(context).showActions(context, [
|
|
|
|
ActionItem.user(owner),
|
|
|
|
ActionItem.repository(owner, name),
|
|
|
|
]);
|
|
|
|
},
|
2019-10-02 08:58:11 +02:00
|
|
|
child: Container(
|
2019-10-02 10:09:54 +02:00
|
|
|
padding: CommonStyle.padding,
|
2019-10-02 08:58:11 +02:00
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
2019-11-02 10:50:04 +01:00
|
|
|
Avatar.small(url: avatarUrl),
|
2019-10-02 08:58:11 +02:00
|
|
|
SizedBox(width: 8),
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: join(SizedBox(height: 8), <Widget>[
|
|
|
|
Row(
|
2019-10-02 09:55:25 +02:00
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
2019-10-02 08:58:11 +02:00
|
|
|
children: <Widget>[
|
|
|
|
Text(
|
2019-11-02 10:50:04 +01:00
|
|
|
owner + ' / ',
|
2019-10-02 08:58:11 +02:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: inRepoScreen ? 18 : 16,
|
2019-11-05 14:22:41 +01:00
|
|
|
color: theme.palette.primary,
|
2019-10-02 08:58:11 +02:00
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
),
|
2019-09-09 16:50:22 +02:00
|
|
|
),
|
2019-10-02 08:58:11 +02:00
|
|
|
Text(
|
2019-11-02 10:50:04 +01:00
|
|
|
name,
|
2019-10-02 08:58:11 +02:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: inRepoScreen ? 18 : 16,
|
2019-11-05 14:22:41 +01:00
|
|
|
color: theme.palette.primary,
|
2019-10-02 08:58:11 +02:00
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
),
|
|
|
|
),
|
2019-10-02 09:55:25 +02:00
|
|
|
Expanded(child: Container()),
|
2019-11-05 14:22:41 +01:00
|
|
|
Icon(iconData,
|
|
|
|
size: 18, color: theme.palette.tertiaryText),
|
2019-10-02 08:58:11 +02:00
|
|
|
],
|
|
|
|
),
|
2019-11-02 10:50:04 +01:00
|
|
|
if (description != null && description.isNotEmpty)
|
2019-09-09 16:50:22 +02:00
|
|
|
Text(
|
2019-11-02 10:50:04 +01:00
|
|
|
description,
|
2019-09-09 16:50:22 +02:00
|
|
|
style: TextStyle(
|
2019-11-05 14:22:41 +01:00
|
|
|
color: theme.palette.secondaryText,
|
2019-10-02 08:58:11 +02:00
|
|
|
fontSize: inRepoScreen ? 15 : 14),
|
2019-09-09 16:50:22 +02:00
|
|
|
),
|
2019-11-05 14:22:41 +01:00
|
|
|
if (inRepoScreen)
|
|
|
|
// TODO: link
|
|
|
|
Wrap(
|
|
|
|
spacing: 4,
|
|
|
|
runSpacing: 4,
|
|
|
|
children: topics.map((node) {
|
|
|
|
return Container(
|
|
|
|
padding:
|
|
|
|
EdgeInsets.symmetric(vertical: 4, horizontal: 8),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: PrimerColors.blue000,
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(4)),
|
|
|
|
),
|
|
|
|
child: Text(
|
2019-12-07 09:12:18 +01:00
|
|
|
node.topic.name,
|
2019-11-05 14:22:41 +01:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 12,
|
|
|
|
color: theme.palette.primary,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}).toList(),
|
|
|
|
)
|
|
|
|
else
|
|
|
|
DefaultTextStyle(
|
|
|
|
style: TextStyle(
|
|
|
|
color: theme.palette.text,
|
|
|
|
fontSize: 13,
|
|
|
|
fontWeight: FontWeight.w500,
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
|
|
|
Expanded(
|
|
|
|
child: Row(children: <Widget>[
|
|
|
|
Container(
|
|
|
|
width: 10,
|
|
|
|
height: 10,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: convertColor(primaryLanguageColor),
|
|
|
|
shape: BoxShape.circle,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(width: 4),
|
|
|
|
Text(primaryLanguageName ?? 'Unknown'),
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
Icon(Octicons.star,
|
|
|
|
size: 14, color: theme.palette.text),
|
|
|
|
Text(numberFormat.format(starCount)),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
Icon(Octicons.repo_forked,
|
|
|
|
size: 14, color: theme.palette.text),
|
|
|
|
Text(numberFormat.format(forkCount)),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
2019-10-02 08:58:11 +02:00
|
|
|
]),
|
|
|
|
),
|
2019-02-04 11:32:39 +01:00
|
|
|
),
|
2019-10-02 08:58:11 +02:00
|
|
|
],
|
|
|
|
),
|
2019-02-03 16:10:10 +01:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|