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';
|
2018-07-05 16:08:19 +02:00
|
|
|
import 'package:flutter/gestures.dart';
|
2019-02-02 17:28:51 +01:00
|
|
|
import 'package:flutter/services.dart';
|
2019-01-31 07:20:48 +01:00
|
|
|
import '../screens/screens.dart';
|
|
|
|
import '../utils/utils.dart';
|
|
|
|
import '../widgets/widgets.dart';
|
2019-01-31 07:37:25 +01:00
|
|
|
import '../widgets/link.dart';
|
2018-07-05 16:08:19 +02:00
|
|
|
|
2019-01-26 15:10:18 +01:00
|
|
|
/// Events types:
|
|
|
|
///
|
|
|
|
/// https://developer.github.com/v3/activity/events/types/#event-types--payloads
|
2018-07-05 16:08:19 +02:00
|
|
|
class EventItem extends StatelessWidget {
|
|
|
|
final Event event;
|
|
|
|
EventItem(this.event);
|
|
|
|
|
2019-01-26 15:10:18 +01:00
|
|
|
TextSpan _buildEvent(BuildContext context) {
|
2018-07-05 16:08:19 +02:00
|
|
|
switch (event.type) {
|
|
|
|
case 'IssuesEvent':
|
2019-01-26 15:10:18 +01:00
|
|
|
return TextSpan(children: [
|
|
|
|
TextSpan(text: ' ${event.payload['action']} issue '),
|
|
|
|
_buildIssue(context),
|
|
|
|
TextSpan(text: ' at '),
|
|
|
|
_buildRepo(context),
|
|
|
|
]);
|
2018-07-05 16:08:19 +02:00
|
|
|
case 'PushEvent':
|
2019-01-26 15:10:18 +01:00
|
|
|
return TextSpan(children: [
|
|
|
|
TextSpan(text: ' pushed to '),
|
|
|
|
TextSpan(
|
|
|
|
text: event.payload['ref'],
|
|
|
|
style: TextStyle(color: CupertinoColors.activeBlue),
|
2019-01-22 12:41:12 +01:00
|
|
|
),
|
2019-01-26 15:10:18 +01:00
|
|
|
TextSpan(text: ' at '),
|
|
|
|
_buildRepo(context),
|
|
|
|
TextSpan(text: '')
|
|
|
|
]);
|
2018-07-05 16:08:19 +02:00
|
|
|
case 'PullRequestEvent':
|
2019-01-26 15:10:18 +01:00
|
|
|
return TextSpan(children: [
|
|
|
|
TextSpan(text: ' ${event.payload['action']} pull request '),
|
2019-01-27 17:37:44 +01:00
|
|
|
_buildPullRequest(context, event.payload['pull_request']['number']),
|
2019-01-26 15:10:18 +01:00
|
|
|
TextSpan(text: ' at '),
|
|
|
|
_buildRepo(context),
|
|
|
|
]);
|
|
|
|
case 'PullRequestReviewCommentEvent':
|
|
|
|
return TextSpan(children: [
|
|
|
|
TextSpan(text: ' reviewed pull request '),
|
2019-01-27 17:37:44 +01:00
|
|
|
_buildPullRequest(context, event.payload['pull_request']['number']),
|
2019-01-26 15:10:18 +01:00
|
|
|
TextSpan(text: ' at '),
|
|
|
|
_buildRepo(context),
|
|
|
|
]);
|
2018-07-05 16:08:19 +02:00
|
|
|
case 'WatchEvent':
|
2019-01-26 15:10:18 +01:00
|
|
|
return TextSpan(children: [
|
|
|
|
TextSpan(text: ' ${event.payload['action']} '),
|
|
|
|
_buildRepo(context)
|
|
|
|
]);
|
|
|
|
case 'IssueCommentEvent':
|
2019-01-27 17:37:44 +01:00
|
|
|
bool isIssue = event.payload['issue']['pull_request'] == null;
|
|
|
|
String resource = isIssue ? 'issue' : 'pull request';
|
|
|
|
TextSpan link = isIssue
|
|
|
|
? _buildIssue(context)
|
|
|
|
: _buildPullRequest(context, event.payload['issue']['number']);
|
|
|
|
|
2019-01-26 15:10:18 +01:00
|
|
|
return TextSpan(children: [
|
2019-01-27 17:37:44 +01:00
|
|
|
TextSpan(text: ' commented on $resource '),
|
|
|
|
link,
|
2019-01-26 15:10:18 +01:00
|
|
|
TextSpan(text: ' at '),
|
|
|
|
_buildRepo(context),
|
|
|
|
// TextSpan(text: event.payload['comment']['body'])
|
|
|
|
]);
|
2019-01-28 14:32:01 +01:00
|
|
|
case 'ForkEvent':
|
|
|
|
return TextSpan(children: [
|
|
|
|
TextSpan(text: ' forked '),
|
2019-01-29 12:41:24 +01:00
|
|
|
createRepoLinkSpan(context, event.payload['forkee']['owner']['login'],
|
|
|
|
event.payload['forkee']['name']),
|
|
|
|
TextSpan(text: ' from '),
|
|
|
|
_buildRepo(context),
|
2019-01-28 14:32:01 +01:00
|
|
|
]);
|
2018-07-05 16:08:19 +02:00
|
|
|
default:
|
2019-01-26 15:10:18 +01:00
|
|
|
return TextSpan(
|
|
|
|
text: 'Type ${event.type} Not implement yet',
|
2019-01-22 12:41:12 +01:00
|
|
|
style: TextStyle(color: CupertinoColors.destructiveRed),
|
|
|
|
);
|
2018-07-05 16:08:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-02 17:28:51 +01:00
|
|
|
String _buildDetail() {
|
2019-01-26 15:10:18 +01:00
|
|
|
switch (event.type) {
|
|
|
|
case 'IssueCommentEvent':
|
|
|
|
return event.payload['comment']['body'];
|
|
|
|
case 'IssuesEvent':
|
|
|
|
return event.payload['issue']['title'];
|
|
|
|
case 'PullRequestEvent':
|
|
|
|
return event.payload['pull_request']['title'];
|
|
|
|
case 'PullRequestReviewCommentEvent':
|
|
|
|
return event.payload['comment']['body'];
|
|
|
|
default:
|
|
|
|
return '';
|
|
|
|
}
|
2018-07-05 16:08:19 +02:00
|
|
|
}
|
|
|
|
|
2019-01-26 15:10:18 +01:00
|
|
|
TextSpan _buildRepo(BuildContext context) {
|
2019-01-27 17:37:44 +01:00
|
|
|
String name = event.repo.name;
|
|
|
|
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-01-26 15:10:18 +01:00
|
|
|
TextSpan _buildIssue(BuildContext context) {
|
2019-01-27 17:37:44 +01:00
|
|
|
int id = event.payload['issue']['number'];
|
2019-01-28 14:32:01 +01:00
|
|
|
String name = event.repo.name;
|
|
|
|
var arr = name.split('/');
|
2019-02-02 17:28:51 +01:00
|
|
|
return createLinkSpan(
|
2019-01-28 14:32:01 +01:00
|
|
|
context, '#' + id.toString(), () => IssueScreen(id, arr[0], arr[1]));
|
2018-07-05 16:08:19 +02:00
|
|
|
}
|
|
|
|
|
2019-01-27 17:37:44 +01:00
|
|
|
TextSpan _buildPullRequest(BuildContext context, int id) {
|
|
|
|
String name = event.repo.name;
|
|
|
|
var arr = name.split('/');
|
2019-02-02 17:28:51 +01:00
|
|
|
return createLinkSpan(context, '#' + id.toString(),
|
2019-01-27 17:37:44 +01:00
|
|
|
() => PullRequestScreen(id, arr[0], arr[1]));
|
2019-01-26 15:10:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
IconData _buildIconData(BuildContext context) {
|
|
|
|
switch (event.type) {
|
|
|
|
case 'IssueCommentEvent':
|
|
|
|
return Octicons.comment_discussion;
|
|
|
|
case 'IssuesEvent':
|
|
|
|
return Octicons.issue_opened;
|
|
|
|
case 'PullRequestEvent':
|
|
|
|
return Octicons.git_pull_request;
|
|
|
|
case 'PushEvent':
|
|
|
|
return Octicons.repo_push;
|
|
|
|
case 'WatchEvent':
|
|
|
|
return Octicons.star;
|
2019-01-28 14:32:01 +01:00
|
|
|
case 'ForkEvent':
|
|
|
|
return Octicons.repo_forked;
|
2019-01-26 15:10:18 +01:00
|
|
|
default:
|
|
|
|
return Octicons.octoface;
|
|
|
|
}
|
|
|
|
}
|
2018-07-05 16:08:19 +02:00
|
|
|
|
|
|
|
@override
|
2019-02-02 17:28:51 +01:00
|
|
|
build(BuildContext context) {
|
|
|
|
return Container(
|
|
|
|
padding: EdgeInsets.all(8),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border(bottom: BorderSide(color: Colors.black12))),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
Row(
|
|
|
|
children: <Widget>[
|
2019-02-03 08:50:17 +01:00
|
|
|
Avatar(login: event.actor.login, url: event.actor.avatarUrl),
|
2019-02-02 17:28:51 +01:00
|
|
|
Padding(padding: EdgeInsets.only(left: 10)),
|
|
|
|
Expanded(
|
|
|
|
child: RichText(
|
|
|
|
text: TextSpan(
|
|
|
|
style: TextStyle(
|
|
|
|
color: Colors.black,
|
|
|
|
height: 1.3,
|
|
|
|
fontSize: 15,
|
2019-01-31 07:20:48 +01:00
|
|
|
),
|
2019-02-02 17:28:51 +01:00
|
|
|
children: <TextSpan>[
|
|
|
|
createLinkSpan(context, event.actor.login,
|
|
|
|
() => UserScreen(event.actor.login)),
|
|
|
|
_buildEvent(context),
|
|
|
|
],
|
2019-01-26 15:10:18 +01:00
|
|
|
),
|
2019-01-31 07:37:25 +01:00
|
|
|
),
|
2019-02-02 17:28:51 +01:00
|
|
|
),
|
|
|
|
Padding(padding: EdgeInsets.only(left: 8)),
|
|
|
|
Icon(
|
|
|
|
_buildIconData(context),
|
|
|
|
color: CupertinoColors.inactiveGray,
|
|
|
|
size: 22,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
padding: EdgeInsets.only(left: 46, top: 6),
|
|
|
|
child: Text(
|
|
|
|
_buildDetail(),
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
maxLines: 3,
|
|
|
|
style: TextStyle(
|
|
|
|
color: Colors.black87,
|
2019-02-03 08:50:17 +01:00
|
|
|
fontSize: 14,
|
2019-02-02 17:28:51 +01:00
|
|
|
height: 1.2,
|
|
|
|
fontWeight: FontWeight.w300,
|
|
|
|
),
|
2019-01-31 07:37:25 +01:00
|
|
|
),
|
2019-02-02 17:28:51 +01:00
|
|
|
)
|
|
|
|
],
|
2018-07-05 16:08:19 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|