2018-07-05 16:08:19 +02:00
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/gestures.dart';
|
2019-01-26 15:10:18 +01:00
|
|
|
import 'package:git_flux/screens/screens.dart';
|
|
|
|
import 'package:git_flux/utils/utils.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 '),
|
|
|
|
_buildPullRequest(context),
|
|
|
|
TextSpan(text: ' at '),
|
|
|
|
_buildRepo(context),
|
|
|
|
]);
|
|
|
|
case 'PullRequestReviewCommentEvent':
|
|
|
|
return TextSpan(children: [
|
|
|
|
TextSpan(text: ' reviewed pull request '),
|
|
|
|
_buildPullRequest(context),
|
|
|
|
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':
|
|
|
|
return TextSpan(children: [
|
|
|
|
TextSpan(text: ' commented on issue '),
|
|
|
|
_buildIssue(context),
|
|
|
|
TextSpan(text: ' at '),
|
|
|
|
_buildRepo(context),
|
|
|
|
// TextSpan(text: event.payload['comment']['body'])
|
|
|
|
]);
|
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-01-26 15:10:18 +01:00
|
|
|
String _buildOriginalComment() {
|
|
|
|
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
|
|
|
String _buildComment() {
|
|
|
|
return _buildOriginalComment();
|
|
|
|
}
|
2018-07-05 16:08:19 +02:00
|
|
|
|
2019-01-26 15:10:18 +01:00
|
|
|
TextSpan _buildLink(BuildContext context, String text, Function handle) {
|
|
|
|
return TextSpan(
|
|
|
|
text: text,
|
|
|
|
style: TextStyle(color: Color(0xff0366d6)),
|
|
|
|
recognizer: TapGestureRecognizer()
|
|
|
|
..onTap = () {
|
|
|
|
Navigator.of(context).push(
|
|
|
|
CupertinoPageRoute(
|
|
|
|
builder: (context) {
|
|
|
|
return handle();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
2018-07-05 16:08:19 +02:00
|
|
|
|
2019-01-26 15:10:18 +01:00
|
|
|
TextSpan _buildRepo(BuildContext context) {
|
|
|
|
return _buildLink(context, event.repo.name, () => RepoScreen());
|
|
|
|
}
|
2018-07-05 16:08:19 +02:00
|
|
|
|
2019-01-26 15:10:18 +01:00
|
|
|
TextSpan _buildIssue(BuildContext context) {
|
|
|
|
return _buildLink(context,
|
|
|
|
'#' + event.payload['issue']['number'].toString(), () => UserScreen());
|
2018-07-05 16:08:19 +02:00
|
|
|
}
|
|
|
|
|
2019-01-26 15:10:18 +01:00
|
|
|
TextSpan _buildPullRequest(BuildContext context) {
|
|
|
|
return _buildLink(
|
|
|
|
context,
|
|
|
|
'#' + event.payload['pull_request']['number'].toString(),
|
|
|
|
() => UserScreen());
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
default:
|
|
|
|
return Octicons.octoface;
|
|
|
|
}
|
|
|
|
}
|
2018-07-05 16:08:19 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
build(context) {
|
2019-01-26 15:10:18 +01:00
|
|
|
return Container(
|
|
|
|
padding: EdgeInsets.all(10),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border(
|
|
|
|
bottom: BorderSide(color: CupertinoColors.lightBackgroundGray))),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
Row(
|
|
|
|
children: <Widget>[
|
|
|
|
CircleAvatar(
|
|
|
|
backgroundColor: Colors.transparent,
|
|
|
|
backgroundImage: NetworkImage(event.actor.avatarUrl),
|
|
|
|
radius: 16,
|
|
|
|
),
|
|
|
|
Padding(padding: EdgeInsets.only(left: 10)),
|
|
|
|
Expanded(
|
|
|
|
child: RichText(
|
|
|
|
text: TextSpan(
|
|
|
|
style: TextStyle(color: Color(0xff24292e), height: 1.2),
|
|
|
|
children: <TextSpan>[
|
|
|
|
_buildLink(
|
|
|
|
context, event.actor.login, () => UserScreen()),
|
|
|
|
_buildEvent(context),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(padding: EdgeInsets.only(left: 10)),
|
|
|
|
Icon(_buildIconData(context),
|
|
|
|
color: CupertinoColors.inactiveGray),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
padding: EdgeInsets.only(left: 42, top: 8),
|
|
|
|
child: Text(_buildComment(),
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
style: TextStyle(color: Color(0xffaaaaaa))))
|
2018-07-05 16:08:19 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|