git-touch-android-ios-app/lib/widgets/repository_item.dart

264 lines
9.0 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2019-02-04 14:38:29 +01:00
import 'package:flutter/cupertino.dart';
2022-09-06 18:00:51 +02:00
import 'package:git_touch/graphql/__generated__/github.data.gql.dart';
2020-02-02 10:30:48 +01:00
import 'package:git_touch/models/bitbucket.dart';
2020-01-31 15:36:58 +01:00
import 'package:git_touch/models/gitlab.dart';
2021-01-23 15:08:05 +01:00
import 'package:git_touch/models/gogs.dart';
2019-11-03 16:33:24 +01:00
import 'package:git_touch/models/theme.dart';
2020-02-26 14:16:45 +01:00
import 'package:git_touch/utils/utils.dart';
2019-09-08 15:20:12 +02:00
import 'package:git_touch/widgets/avatar.dart';
2020-02-26 14:16:45 +01:00
import 'package:git_touch/widgets/link.dart';
2019-11-03 16:33:24 +01:00
import 'package:provider/provider.dart';
2020-02-02 10:30:48 +01:00
import 'package:timeago/timeago.dart' as timeago;
2020-10-08 08:49:46 +02:00
import 'package:github/github.dart' as github;
2019-09-23 12:28:33 +02:00
class RepositoryItem extends StatelessWidget {
2021-05-16 09:16:35 +02: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 String? note;
2020-01-29 06:23:17 +01:00
final String url;
2021-05-16 09:16:35 +02:00
final String? avatarLink;
2022-09-06 18:28:12 +02:00
const RepositoryItem({
2021-05-16 09:16:35 +02:00
required this.owner,
required this.avatarUrl,
required this.name,
required this.description,
required this.starCount,
required this.forkCount,
2020-01-11 12:52:17 +01:00
this.primaryLanguageName,
this.primaryLanguageColor,
2020-01-29 06:06:55 +01:00
this.note,
2020-01-11 10:25:01 +01:00
this.iconData,
2021-05-16 09:16:35 +02:00
required this.url,
required this.avatarLink,
2020-01-11 12:52:17 +01:00
});
2021-01-23 15:08:05 +01:00
RepositoryItem.go({
2021-05-16 09:16:35 +02:00
required GogsRepository payload,
2021-01-23 15:08:05 +01:00
this.primaryLanguageName,
this.primaryLanguageColor,
this.note,
this.owner,
this.name,
}) : url = '/gogs/${payload.fullName}',
2021-05-16 09:16:35 +02:00
avatarUrl = payload.owner!.avatarUrl,
2021-01-23 15:08:05 +01:00
avatarLink = '/gogs/${payload.fullName}',
description = payload.description,
forkCount = payload.forksCount,
starCount = payload.starsCount,
2021-05-16 09:16:35 +02:00
iconData = payload.private! ? Octicons.lock : null;
2021-01-23 15:08:05 +01:00
2020-02-02 10:30:48 +01:00
RepositoryItem.bb({
2021-05-16 09:16:35 +02:00
required BbRepo payload,
2020-02-02 10:30:48 +01:00
this.primaryLanguageName,
this.primaryLanguageColor,
2020-02-02 12:06:48 +01:00
}) : owner = payload.ownerLogin,
2020-02-02 10:30:48 +01:00
name = payload.name,
url = '/bitbucket/${payload.fullName}',
avatarUrl = payload.avatarUrl,
2020-02-02 12:50:00 +01:00
avatarLink = null,
2021-05-16 09:16:35 +02:00
note = 'Updated ${timeago.format(payload.updatedOn!)}',
2020-02-02 10:30:48 +01:00
description = payload.description,
forkCount = 0,
starCount = 0,
2021-05-16 09:16:35 +02:00
iconData = payload.isPrivate! ? Octicons.lock : null;
2020-02-02 10:30:48 +01:00
2020-01-29 06:32:40 +01:00
RepositoryItem.gl({
2021-05-16 09:16:35 +02:00
required GitlabProject payload,
2020-01-29 06:32:40 +01:00
this.primaryLanguageName,
this.primaryLanguageColor,
this.note,
2021-05-16 09:16:35 +02:00
}) : owner = payload.namespace!.path,
2020-01-31 15:36:58 +01:00
avatarUrl = payload.owner?.avatarUrl,
name = payload.name,
description = payload.description,
starCount = payload.starCount,
forkCount = payload.forksCount,
url = '/gitlab/projects/${payload.id}',
2021-05-16 09:16:35 +02:00
avatarLink = payload.namespace!.kind == 'group'
? '/gitlab/group/${payload.namespace!.id}'
: '/gitlab/user/${payload.namespace!.id}',
2020-01-31 15:36:58 +01:00
iconData = _buildGlIconData(payload.visibility);
2020-01-29 06:32:40 +01:00
2020-01-29 06:06:55 +01:00
RepositoryItem.gh({
2021-05-16 09:16:35 +02:00
required this.owner,
required this.avatarUrl,
required this.name,
required this.description,
required this.starCount,
required this.forkCount,
2020-01-11 10:25:01 +01:00
this.primaryLanguageName,
this.primaryLanguageColor,
2020-01-29 06:06:55 +01:00
this.note,
2021-05-16 09:16:35 +02:00
required bool? isPrivate,
required bool? isFork,
2021-05-30 19:07:31 +02:00
}) : iconData = _buildIconData(isPrivate, isFork),
avatarLink = '/github/$owner',
url = '/github/$owner/$name';
2020-01-11 12:52:17 +01:00
2021-05-16 09:16:35 +02:00
factory RepositoryItem.gql(GRepoItem v, {required note}) {
2021-01-17 15:08:32 +01:00
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,
note: note,
isPrivate: v.isPrivate,
isFork: v.isFork,
);
}
2021-05-16 09:16:35 +02:00
static IconData? _buildIconData(bool? isPrivate, bool? isFork) {
2020-01-11 12:52:17 +01:00
if (isPrivate == true) return Octicons.lock;
if (isFork == true) return Octicons.repo_forked;
return null;
}
2019-02-04 11:32:39 +01:00
2021-05-16 09:16:35 +02:00
static IconData _buildGlIconData(String? visibility) {
2020-01-29 06:32:40 +01:00
switch (visibility) {
case 'internal':
2021-02-01 16:30:19 +01:00
return Ionicons.shield_outline;
2020-01-29 06:32:40 +01:00
case 'public':
2021-02-01 16:30:19 +01:00
return Ionicons.globe_outline;
2020-01-29 06:32:40 +01:00
case 'private':
2021-02-01 16:30:19 +01:00
return Ionicons.lock_closed_outline;
2020-01-29 06:32:40 +01:00
default:
return Octicons.repo;
}
}
@override
Widget build(BuildContext context) {
2019-11-05 14:22:41 +01:00
final theme = Provider.of<ThemeModel>(context);
2021-05-16 09:16:35 +02:00
return LinkWidget(
2020-01-29 06:23:17 +01:00
url: url,
2020-01-11 10:25:01 +01:00
child: Container(
padding: CommonStyle.padding,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
2020-01-11 10:57:22 +01:00
children: <Widget>[
2020-01-11 10:25:01 +01:00
Row(
children: <Widget>[
2020-01-11 10:57:22 +01:00
Avatar(
url: avatarUrl,
size: AvatarSize.small,
2020-01-30 05:35:11 +01:00
linkUrl: avatarLink,
2020-01-11 10:57:22 +01:00
),
2022-09-06 18:28:12 +02:00
const SizedBox(width: 8),
2020-01-26 16:36:58 +01:00
Expanded(
child: Text.rich(
TextSpan(children: [
TextSpan(
text: '$owner / ',
style: TextStyle(
fontSize: 18,
2020-01-27 08:11:51 +01:00
color: theme.palette.primary,
2020-01-26 16:36:58 +01:00
),
2019-12-21 15:01:08 +01:00
),
2020-01-26 16:36:58 +01:00
TextSpan(
text: name,
style: TextStyle(
fontSize: 18,
2020-01-27 08:11:51 +01:00
color: theme.palette.primary,
2020-01-26 16:36:58 +01:00
fontWeight: FontWeight.w600,
),
// overflow: TextOverflow.ellipsis,
2020-01-11 10:25:01 +01:00
),
2020-01-26 16:36:58 +01:00
]),
overflow: TextOverflow.ellipsis,
),
2020-01-11 10:25:01 +01:00
),
2020-01-11 12:52:17 +01:00
if (iconData != null) ...[
2022-09-06 18:28:12 +02:00
const SizedBox(width: 6),
2020-01-11 12:52:17 +01:00
DefaultTextStyle(
2022-09-06 18:28:12 +02:00
style: TextStyle(color: theme.palette.secondaryText),
2020-01-11 12:52:17 +01:00
child: Icon(iconData,
2020-01-27 08:11:51 +01:00
size: 18, color: theme.palette.secondaryText),
2020-01-11 12:52:17 +01:00
),
]
2020-01-11 10:25:01 +01:00
],
2019-12-21 09:16:17 +01:00
),
2022-09-06 18:28:12 +02:00
const SizedBox(height: 8),
2021-05-16 09:16:35 +02:00
if (description != null && description!.isNotEmpty) ...[
2020-01-11 10:25:01 +01:00
Text(
2021-05-16 09:16:35 +02:00
description!,
2020-01-11 10:25:01 +01:00
style: TextStyle(
2020-01-27 08:11:51 +01:00
color: theme.palette.secondaryText,
2020-01-11 10:57:22 +01:00
fontSize: 16,
2020-01-11 10:25:01 +01:00
),
),
2022-09-06 18:28:12 +02:00
const SizedBox(height: 10),
2020-01-11 10:57:22 +01:00
],
2020-01-11 12:25:33 +01:00
if (note != null) ...[
Text(
2021-05-16 09:16:35 +02:00
note!,
2020-01-11 12:25:33 +01:00
style: TextStyle(
fontSize: 14,
2020-01-27 08:11:51 +01:00
color: theme.palette.tertiaryText,
2020-01-11 12:25:33 +01:00
),
),
2022-09-06 18:28:12 +02:00
const SizedBox(height: 10),
2020-01-11 12:25:33 +01:00
],
2019-12-21 09:16:17 +01:00
DefaultTextStyle(
2020-01-27 08:11:51 +01:00
style: TextStyle(color: theme.palette.text, fontSize: 14),
2019-12-21 09:16:17 +01:00
child: Row(
children: <Widget>[
2020-01-11 10:57:22 +01:00
if (primaryLanguageName != null) ...[
Container(
width: 12,
height: 12,
decoration: BoxDecoration(
2020-02-26 14:16:45 +01:00
color: convertColor(primaryLanguageColor ??
2021-05-16 09:16:35 +02:00
github.languageColors[primaryLanguageName!]),
2020-01-11 10:57:22 +01:00
shape: BoxShape.circle,
2019-12-21 15:01:08 +01:00
),
2019-11-05 14:22:41 +01:00
),
2022-09-06 18:28:12 +02:00
const SizedBox(width: 4),
2020-01-11 10:57:22 +01:00
Text(
2021-05-16 09:16:35 +02:00
primaryLanguageName!,
2020-01-11 10:57:22 +01:00
overflow: TextOverflow.ellipsis,
2019-11-05 14:22:41 +01:00
),
2022-09-06 18:28:12 +02:00
const SizedBox(width: 24),
2020-01-11 10:57:22 +01:00
],
2021-05-16 09:16:35 +02:00
if (starCount! > 0) ...[
2020-01-11 10:57:22 +01:00
Icon(Octicons.star,
2020-01-27 08:11:51 +01:00
size: 16, color: theme.palette.text),
2022-09-06 18:28:12 +02:00
const SizedBox(width: 2),
2020-01-11 10:57:22 +01:00
Text(numberFormat.format(starCount)),
2022-09-06 18:28:12 +02:00
const SizedBox(width: 24),
2020-01-11 10:57:22 +01:00
],
2021-05-16 09:16:35 +02:00
if (forkCount! > 0) ...[
2020-01-11 10:57:22 +01:00
Icon(Octicons.repo_forked,
2020-01-27 08:11:51 +01:00
size: 16, color: theme.palette.text),
2022-09-06 18:28:12 +02:00
const SizedBox(width: 2),
2020-01-11 10:57:22 +01:00
Text(numberFormat.format(forkCount)),
],
2019-12-21 09:16:17 +01:00
],
2019-11-05 14:22:41 +01:00
),
2019-12-21 09:16:17 +01:00
),
2020-01-11 10:57:22 +01:00
],
2020-01-11 10:25:01 +01:00
),
2019-02-04 11:32:39 +01:00
),
2020-01-11 10:25:01 +01:00
],
),
),
);
}
}