2018-07-05 16:08:19 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2019-02-02 17:28:51 +01:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2019-03-13 15:51:48 +01:00
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
2019-08-31 15:37:29 +02:00
|
|
|
import 'package:timeago/timeago.dart' as timeago;
|
2019-05-12 09:14:28 +02:00
|
|
|
import 'package:primer/primer.dart';
|
2019-02-07 07:35:19 +01:00
|
|
|
import '../screens/issue.dart';
|
|
|
|
import '../screens/user.dart';
|
|
|
|
import 'avatar.dart';
|
2019-03-13 15:51:48 +01:00
|
|
|
import '../widgets/link.dart';
|
2019-02-07 12:17:29 +01:00
|
|
|
import '../utils/utils.dart';
|
2018-07-05 16:08:19 +02:00
|
|
|
|
2019-02-10 05:54:48 +01:00
|
|
|
class EventPayload {
|
|
|
|
String actorLogin;
|
|
|
|
String actorAvatarUrl;
|
|
|
|
String type;
|
|
|
|
String repoFullName;
|
|
|
|
Map<String, dynamic> payload;
|
2019-08-31 15:37:29 +02:00
|
|
|
DateTime createdAt;
|
2019-02-10 05:54:48 +01:00
|
|
|
|
|
|
|
EventPayload.fromJson(input) {
|
|
|
|
actorLogin = input['actor']['login'];
|
|
|
|
actorAvatarUrl = input['actor']['avatar_url'];
|
|
|
|
type = input['type'];
|
|
|
|
payload = input['payload'];
|
|
|
|
repoFullName = input['repo']['name'];
|
2019-08-31 15:37:29 +02:00
|
|
|
createdAt = DateTime.parse(input['created_at']);
|
2019-02-10 05:54:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-05 16:08:19 +02:00
|
|
|
class EventItem extends StatelessWidget {
|
2019-02-10 05:54:48 +01:00
|
|
|
final EventPayload event;
|
2019-02-09 06:29:44 +01:00
|
|
|
|
2018-07-05 16:08:19 +02:00
|
|
|
EventItem(this.event);
|
|
|
|
|
2019-01-26 15:10:18 +01:00
|
|
|
TextSpan _buildRepo(BuildContext context) {
|
2019-02-10 05:54:48 +01:00
|
|
|
String name = event.repoFullName;
|
2019-01-27 17:37:44 +01:00
|
|
|
var arr = name.split('/');
|
2019-01-29 12:41:24 +01:00
|
|
|
return createRepoLinkSpan(context, arr[0], arr[1]);
|
2019-01-26 15:10:18 +01:00
|
|
|
}
|
2018-07-05 16:08:19 +02:00
|
|
|
|
2019-02-19 08:25:15 +01:00
|
|
|
TextSpan _buildIssue(BuildContext context,
|
|
|
|
{@required int number, bool isPullRequest = false}) {
|
|
|
|
// var resource = isPullRequest ? 'pull_request' : 'issue';
|
|
|
|
// int number = event.payload['issue']['number'];
|
2018-07-05 16:08:19 +02:00
|
|
|
|
2019-02-19 08:25:15 +01:00
|
|
|
return createLinkSpan(context, '#' + number.toString(), () {
|
|
|
|
return IssueScreen.fromFullName(
|
|
|
|
number: number,
|
|
|
|
fullName: event.repoFullName,
|
|
|
|
isPullRequest: isPullRequest,
|
|
|
|
);
|
|
|
|
});
|
2019-01-26 15:10:18 +01:00
|
|
|
}
|
|
|
|
|
2019-02-07 10:19:08 +01:00
|
|
|
Widget _buildItem({
|
|
|
|
@required BuildContext context,
|
|
|
|
@required List<TextSpan> spans,
|
|
|
|
String detail,
|
2019-03-13 15:51:48 +01:00
|
|
|
Widget detailWidget,
|
2019-02-07 10:19:08 +01:00
|
|
|
IconData iconData = Octicons.octoface,
|
2019-02-10 12:32:30 +01:00
|
|
|
WidgetBuilder screenBuilder,
|
2019-02-07 10:19:08 +01:00
|
|
|
}) {
|
2019-08-31 15:37:29 +02:00
|
|
|
if (detailWidget == null) {
|
|
|
|
if (detail == null) {
|
|
|
|
detailWidget = Container(); // TODO: placeholder
|
|
|
|
} else {
|
|
|
|
detailWidget = Text(
|
|
|
|
detail,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
maxLines: 5,
|
|
|
|
style: TextStyle(color: PrimerColors.gray600, fontSize: 14),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Link(
|
|
|
|
screenBuilder: screenBuilder,
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.all(10),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
Row(
|
|
|
|
children: <Widget>[
|
|
|
|
SizedBox(width: 18),
|
|
|
|
Icon(iconData, color: PrimerColors.gray400, size: 13),
|
|
|
|
SizedBox(width: 8),
|
|
|
|
Text(timeago.format(event.createdAt),
|
|
|
|
style: TextStyle(fontSize: 13, color: PrimerColors.gray400))
|
|
|
|
],
|
|
|
|
),
|
|
|
|
SizedBox(height: 6),
|
|
|
|
Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
Avatar(
|
|
|
|
url: event.actorAvatarUrl,
|
|
|
|
login: event.actorLogin,
|
|
|
|
size: 16),
|
|
|
|
SizedBox(width: 8),
|
|
|
|
Expanded(
|
|
|
|
child: RichText(
|
|
|
|
text: TextSpan(
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 15,
|
2019-07-28 15:59:18 +02:00
|
|
|
color: PrimerColors.gray900,
|
2019-05-12 08:01:12 +02:00
|
|
|
),
|
2019-08-31 15:37:29 +02:00
|
|
|
children: [
|
|
|
|
createLinkSpan(
|
|
|
|
context,
|
|
|
|
event.actorLogin,
|
|
|
|
() => UserScreen(event.actorLogin),
|
|
|
|
),
|
|
|
|
...spans,
|
|
|
|
// TextSpan(
|
|
|
|
// text: timeago.format(event.createdAt),
|
|
|
|
// style: TextStyle(
|
|
|
|
// fontSize: 13, color: PrimerColors.gray400))
|
|
|
|
],
|
|
|
|
),
|
2019-01-26 15:10:18 +01:00
|
|
|
),
|
2019-01-31 07:37:25 +01:00
|
|
|
),
|
2019-08-31 15:37:29 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
padding: EdgeInsets.only(left: 40, top: 6),
|
|
|
|
child: detailWidget,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2018-07-05 16:08:19 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
2019-02-07 10:19:08 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
build(BuildContext context) {
|
2019-02-07 10:39:27 +01:00
|
|
|
var defaultItem = _buildItem(
|
|
|
|
context: context,
|
2019-02-10 05:54:48 +01:00
|
|
|
spans: [
|
|
|
|
TextSpan(
|
|
|
|
text: ' ' + event.type,
|
|
|
|
style: TextStyle(color: Colors.blueAccent),
|
|
|
|
)
|
|
|
|
],
|
2019-02-07 10:39:27 +01:00
|
|
|
iconData: Octicons.octoface,
|
|
|
|
detail: 'Woops, ${event.type} not implemented yet',
|
|
|
|
);
|
|
|
|
|
|
|
|
// all events types here:
|
|
|
|
// https://developer.github.com/v3/activity/events/types/#event-types--payloads
|
2019-02-07 10:19:08 +01:00
|
|
|
switch (event.type) {
|
2019-02-07 10:39:27 +01:00
|
|
|
case 'CheckRunEvent':
|
|
|
|
case 'CheckSuiteEvent':
|
|
|
|
case 'CommitCommentEvent':
|
|
|
|
case 'ContentReferenceEvent':
|
|
|
|
case 'CreateEvent':
|
|
|
|
case 'DeleteEvent':
|
|
|
|
case 'DeploymentEvent':
|
|
|
|
case 'DeploymentStatusEvent':
|
|
|
|
case 'DownloadEvent':
|
|
|
|
case 'FollowEvent':
|
|
|
|
// TODO:
|
|
|
|
return defaultItem;
|
|
|
|
case 'ForkEvent':
|
2019-02-07 10:19:08 +01:00
|
|
|
return _buildItem(
|
|
|
|
context: context,
|
|
|
|
spans: [
|
2019-02-07 10:39:27 +01:00
|
|
|
TextSpan(text: ' forked '),
|
|
|
|
createRepoLinkSpan(
|
|
|
|
context,
|
|
|
|
event.payload['forkee']['owner']['login'],
|
|
|
|
event.payload['forkee']['name']),
|
|
|
|
TextSpan(text: ' from '),
|
|
|
|
_buildRepo(context),
|
|
|
|
],
|
|
|
|
iconData: Octicons.repo_forked,
|
|
|
|
);
|
|
|
|
case 'ForkApplyEvent':
|
|
|
|
case 'GitHubAppAuthorizationEvent':
|
|
|
|
case 'GistEvent':
|
|
|
|
case 'GollumEvent':
|
|
|
|
case 'InstallationEvent':
|
|
|
|
case 'InstallationRepositoriesEvent':
|
|
|
|
// TODO:
|
|
|
|
return defaultItem;
|
|
|
|
case 'IssueCommentEvent':
|
2019-02-19 08:25:15 +01:00
|
|
|
bool isPullRequest = event.payload['issue']['pull_request'] != null;
|
|
|
|
String resource = isPullRequest ? 'pull request' : 'issue';
|
|
|
|
int number = event.payload['issue']['number'];
|
2019-02-07 10:39:27 +01:00
|
|
|
|
|
|
|
return _buildItem(
|
|
|
|
context: context,
|
|
|
|
spans: [
|
|
|
|
TextSpan(text: ' commented on $resource '),
|
2019-02-19 08:25:15 +01:00
|
|
|
_buildIssue(
|
|
|
|
context,
|
|
|
|
number: number,
|
|
|
|
isPullRequest: isPullRequest,
|
|
|
|
),
|
2019-02-07 10:19:08 +01:00
|
|
|
TextSpan(text: ' at '),
|
|
|
|
_buildRepo(context),
|
2019-02-07 10:39:27 +01:00
|
|
|
// TextSpan(text: event.payload['comment']['body'])
|
2019-02-07 10:19:08 +01:00
|
|
|
],
|
2019-02-07 10:39:27 +01:00
|
|
|
detail: event.payload['comment']['body'],
|
|
|
|
iconData: Octicons.comment_discussion,
|
2019-02-10 12:32:30 +01:00
|
|
|
screenBuilder: (_) => IssueScreen.fromFullName(
|
2019-07-28 15:59:18 +02:00
|
|
|
number: number,
|
|
|
|
fullName: event.repoFullName,
|
|
|
|
isPullRequest: isPullRequest,
|
|
|
|
),
|
2019-02-07 10:19:08 +01:00
|
|
|
);
|
2019-02-07 10:39:27 +01:00
|
|
|
case 'IssuesEvent':
|
2019-02-19 08:25:15 +01:00
|
|
|
int number = event.payload['issue']['number'];
|
|
|
|
|
2019-02-07 10:19:08 +01:00
|
|
|
return _buildItem(
|
|
|
|
context: context,
|
|
|
|
spans: [
|
2019-02-07 10:39:27 +01:00
|
|
|
TextSpan(text: ' ${event.payload['action']} issue '),
|
2019-02-19 08:25:15 +01:00
|
|
|
_buildIssue(context, number: number),
|
2019-02-07 10:19:08 +01:00
|
|
|
TextSpan(text: ' at '),
|
|
|
|
_buildRepo(context),
|
|
|
|
],
|
2019-02-07 10:39:27 +01:00
|
|
|
iconData: Octicons.issue_opened,
|
|
|
|
detail: event.payload['issue']['title'],
|
2019-02-10 12:32:30 +01:00
|
|
|
screenBuilder: (_) => IssueScreen.fromFullName(
|
2019-07-28 15:59:18 +02:00
|
|
|
number: number,
|
|
|
|
fullName: event.repoFullName,
|
|
|
|
),
|
2019-02-07 10:19:08 +01:00
|
|
|
);
|
2019-02-07 10:39:27 +01:00
|
|
|
case 'LabelEvent':
|
|
|
|
case 'MarketplacePurchaseEvent':
|
|
|
|
case 'MemberEvent':
|
|
|
|
case 'MembershipEvent':
|
|
|
|
case 'MilestoneEvent':
|
|
|
|
case 'OrganizationEvent':
|
|
|
|
case 'OrgBlockEvent':
|
|
|
|
case 'PageBuildEvent':
|
|
|
|
case 'ProjectCardEvent':
|
|
|
|
case 'ProjectColumnEvent':
|
|
|
|
case 'ProjectEvent':
|
|
|
|
case 'PublicEvent':
|
|
|
|
// TODO:
|
|
|
|
return defaultItem;
|
2019-02-07 10:19:08 +01:00
|
|
|
case 'PullRequestEvent':
|
|
|
|
return _buildItem(
|
|
|
|
context: context,
|
|
|
|
spans: [
|
|
|
|
TextSpan(text: ' ${event.payload['action']} pull request '),
|
2019-02-19 08:25:15 +01:00
|
|
|
_buildIssue(context,
|
|
|
|
number: event.payload['number'], isPullRequest: true),
|
2019-02-07 10:19:08 +01:00
|
|
|
TextSpan(text: ' at '),
|
|
|
|
_buildRepo(context),
|
|
|
|
],
|
|
|
|
iconData: Octicons.git_pull_request,
|
|
|
|
detail: event.payload['pull_request']['title'],
|
2019-02-19 08:25:15 +01:00
|
|
|
screenBuilder: (_) => IssueScreen.fromFullName(
|
2019-07-28 15:59:18 +02:00
|
|
|
number: event.payload['pull_request']['number'],
|
|
|
|
fullName: event.repoFullName,
|
|
|
|
isPullRequest: true,
|
|
|
|
),
|
2019-02-07 10:19:08 +01:00
|
|
|
);
|
2019-02-07 10:39:27 +01:00
|
|
|
case 'PullRequestReviewEvent':
|
|
|
|
// TODO:
|
|
|
|
return defaultItem;
|
2019-02-07 10:19:08 +01:00
|
|
|
case 'PullRequestReviewCommentEvent':
|
|
|
|
return _buildItem(
|
|
|
|
context: context,
|
|
|
|
spans: [
|
|
|
|
TextSpan(text: ' reviewed pull request '),
|
2019-02-19 08:25:15 +01:00
|
|
|
_buildIssue(context,
|
|
|
|
number: event.payload['pull_request']['number'],
|
|
|
|
isPullRequest: true),
|
2019-02-07 10:19:08 +01:00
|
|
|
TextSpan(text: ' at '),
|
|
|
|
_buildRepo(context),
|
|
|
|
],
|
|
|
|
detail: event.payload['comment']['body'],
|
2019-02-19 08:25:15 +01:00
|
|
|
screenBuilder: (_) => IssueScreen.fromFullName(
|
2019-07-28 15:59:18 +02:00
|
|
|
number: event.payload['pull_request']['number'],
|
|
|
|
fullName: event.repoFullName,
|
|
|
|
isPullRequest: true,
|
|
|
|
),
|
2019-02-07 10:19:08 +01:00
|
|
|
);
|
2019-02-07 10:39:27 +01:00
|
|
|
case 'PushEvent':
|
2019-03-13 15:51:48 +01:00
|
|
|
String ref = event.payload['ref'];
|
|
|
|
List commits = event.payload['commits'];
|
|
|
|
|
2019-02-07 10:19:08 +01:00
|
|
|
return _buildItem(
|
|
|
|
context: context,
|
|
|
|
spans: [
|
2019-08-31 15:37:29 +02:00
|
|
|
TextSpan(text: ' pushed to '),
|
2019-05-12 09:14:28 +02:00
|
|
|
// TODO: Use primer widgets
|
2019-02-07 10:39:27 +01:00
|
|
|
TextSpan(
|
2019-03-13 15:51:48 +01:00
|
|
|
text: ref.replaceFirst('refs/heads/', ''),
|
|
|
|
style: TextStyle(
|
2019-05-12 09:14:28 +02:00
|
|
|
color: PrimerColors.blue500,
|
|
|
|
backgroundColor: Color(0xffeaf5ff),
|
2019-08-31 15:37:29 +02:00
|
|
|
fontFamily: 'Menlo',
|
2019-05-12 09:14:28 +02:00
|
|
|
),
|
2019-02-07 10:39:27 +01:00
|
|
|
),
|
2019-02-07 10:19:08 +01:00
|
|
|
TextSpan(text: ' at '),
|
2019-08-31 15:37:29 +02:00
|
|
|
_buildRepo(context)
|
2019-02-07 10:19:08 +01:00
|
|
|
],
|
2019-02-07 10:39:27 +01:00
|
|
|
iconData: Octicons.repo_push,
|
2019-08-31 15:37:29 +02:00
|
|
|
detailWidget: Link(
|
|
|
|
onTap: () {
|
|
|
|
launch('https://github.com/' +
|
|
|
|
event.repoFullName +
|
|
|
|
'/compare/' +
|
|
|
|
event.payload['before'] +
|
|
|
|
'...' +
|
|
|
|
event.payload['head']);
|
|
|
|
},
|
|
|
|
child: Column(
|
|
|
|
children: commits.map((commit) {
|
|
|
|
return Row(children: <Widget>[
|
|
|
|
Text(
|
|
|
|
(commit['sha'] as String).substring(0, 7),
|
|
|
|
style: TextStyle(
|
|
|
|
color: PrimerColors.blue500,
|
|
|
|
fontSize: 13,
|
|
|
|
fontFamily: 'Menlo',
|
|
|
|
fontFamilyFallback: ['Menlo', 'Roboto Mono'],
|
2019-03-13 15:51:48 +01:00
|
|
|
),
|
2019-08-31 15:37:29 +02:00
|
|
|
),
|
|
|
|
SizedBox(width: 6),
|
|
|
|
Expanded(
|
|
|
|
child: Text(
|
|
|
|
commit['message'],
|
|
|
|
style: TextStyle(color: Colors.black54, fontSize: 14),
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
maxLines: 1,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
]);
|
|
|
|
}).toList(),
|
2019-03-13 15:51:48 +01:00
|
|
|
),
|
|
|
|
),
|
2019-02-07 10:19:08 +01:00
|
|
|
);
|
2019-02-07 10:39:27 +01:00
|
|
|
case 'ReleaseEvent':
|
|
|
|
case 'RepositoryEvent':
|
|
|
|
case 'RepositoryImportEvent':
|
|
|
|
case 'RepositoryVulnerabilityAlertEvent':
|
|
|
|
case 'SecurityAdvisoryEvent':
|
|
|
|
case 'StatusEvent':
|
|
|
|
case 'TeamEvent':
|
|
|
|
case 'TeamAddEvent':
|
|
|
|
// TODO:
|
|
|
|
return defaultItem;
|
|
|
|
case 'WatchEvent':
|
2019-02-07 10:19:08 +01:00
|
|
|
return _buildItem(
|
|
|
|
context: context,
|
2019-03-13 15:14:30 +01:00
|
|
|
spans: [TextSpan(text: ' starred '), _buildRepo(context)],
|
2019-02-07 10:39:27 +01:00
|
|
|
iconData: Octicons.star,
|
2019-02-07 10:19:08 +01:00
|
|
|
);
|
|
|
|
default:
|
2019-02-07 10:39:27 +01:00
|
|
|
return defaultItem;
|
2019-02-07 10:19:08 +01:00
|
|
|
}
|
|
|
|
}
|
2018-07-05 16:08:19 +02:00
|
|
|
}
|