2019-01-27 17:37:44 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2019-01-25 18:43:09 +01:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2019-02-10 11:50:40 +01:00
|
|
|
import 'package:share/share.dart';
|
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
2019-01-31 07:37:25 +01:00
|
|
|
import '../utils/utils.dart';
|
2019-02-08 07:06:48 +01:00
|
|
|
import '../scaffolds/long_list.dart';
|
2019-02-03 07:42:50 +01:00
|
|
|
import '../widgets/timeline_item.dart';
|
2019-02-06 06:06:11 +01:00
|
|
|
import '../widgets/comment_item.dart';
|
2019-02-07 07:35:19 +01:00
|
|
|
import '../providers/settings.dart';
|
2019-02-10 11:50:40 +01:00
|
|
|
import '../widgets/link.dart';
|
2019-01-28 14:32:01 +01:00
|
|
|
|
2019-02-19 08:25:15 +01:00
|
|
|
/// Screen for issue and pull request
|
2019-02-03 07:42:50 +01:00
|
|
|
class IssueScreen extends StatefulWidget {
|
2019-02-08 07:01:25 +01:00
|
|
|
final int number;
|
2019-01-28 14:32:01 +01:00
|
|
|
final String owner;
|
|
|
|
final String name;
|
2019-02-19 08:25:15 +01:00
|
|
|
final bool isPullRequest;
|
2019-01-27 17:37:44 +01:00
|
|
|
|
2019-02-08 07:01:25 +01:00
|
|
|
IssueScreen({
|
|
|
|
@required this.number,
|
|
|
|
@required this.owner,
|
|
|
|
@required this.name,
|
2019-02-19 08:25:15 +01:00
|
|
|
this.isPullRequest = false,
|
2019-02-08 07:01:25 +01:00
|
|
|
});
|
|
|
|
|
2019-02-19 08:25:15 +01:00
|
|
|
IssueScreen.fromFullName({
|
|
|
|
@required this.number,
|
|
|
|
@required String fullName,
|
|
|
|
this.isPullRequest = false,
|
|
|
|
}) : owner = fullName.split('/')[0],
|
|
|
|
name = fullName.split('/')[1];
|
2019-01-27 17:37:44 +01:00
|
|
|
|
2019-02-03 07:42:50 +01:00
|
|
|
@override
|
|
|
|
_IssueScreenState createState() => _IssueScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _IssueScreenState extends State<IssueScreen> {
|
2019-02-19 08:25:15 +01:00
|
|
|
String get owner => widget.owner;
|
|
|
|
String get name => widget.name;
|
|
|
|
int get number => widget.number;
|
|
|
|
bool get isPullRequest => widget.isPullRequest;
|
2019-02-03 07:42:50 +01:00
|
|
|
|
2019-02-19 08:25:15 +01:00
|
|
|
String get resource => isPullRequest ? 'pullRequest' : 'issue';
|
|
|
|
|
|
|
|
String get issueChunk {
|
|
|
|
var base = '''
|
|
|
|
title
|
|
|
|
createdAt
|
|
|
|
body
|
|
|
|
author {
|
|
|
|
login
|
|
|
|
avatarUrl
|
|
|
|
}
|
|
|
|
closed
|
|
|
|
url
|
|
|
|
''';
|
|
|
|
|
|
|
|
if (isPullRequest) {
|
|
|
|
base += '''
|
|
|
|
merged
|
|
|
|
additions
|
|
|
|
deletions
|
|
|
|
commits {
|
|
|
|
totalCount
|
|
|
|
}
|
|
|
|
''';
|
|
|
|
}
|
|
|
|
return base;
|
|
|
|
}
|
|
|
|
|
|
|
|
String get timelineChunk {
|
|
|
|
var base = '''
|
|
|
|
__typename
|
|
|
|
... on IssueComment {
|
|
|
|
createdAt
|
|
|
|
body
|
|
|
|
author {
|
|
|
|
login
|
|
|
|
avatarUrl
|
|
|
|
}
|
|
|
|
}
|
|
|
|
... on Commit {
|
|
|
|
committedDate
|
|
|
|
oid
|
|
|
|
author {
|
|
|
|
user {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
... on ReferencedEvent {
|
|
|
|
createdAt
|
|
|
|
isCrossRepository
|
|
|
|
actor {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
commit {
|
|
|
|
oid
|
|
|
|
url
|
|
|
|
}
|
|
|
|
commitRepository {
|
|
|
|
owner {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
... on RenamedTitleEvent {
|
|
|
|
createdAt
|
|
|
|
previousTitle
|
|
|
|
currentTitle
|
|
|
|
actor {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
}
|
|
|
|
... on ClosedEvent {
|
|
|
|
createdAt
|
|
|
|
actor {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
}
|
|
|
|
... on ReopenedEvent {
|
|
|
|
createdAt
|
|
|
|
actor {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
}
|
|
|
|
... on CrossReferencedEvent {
|
|
|
|
createdAt
|
|
|
|
actor {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
source {
|
|
|
|
__typename
|
|
|
|
... on Issue {
|
|
|
|
number
|
|
|
|
repository {
|
|
|
|
owner {
|
|
|
|
login
|
2019-02-07 07:35:19 +01:00
|
|
|
}
|
2019-02-19 08:25:15 +01:00
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
... on PullRequest {
|
|
|
|
number
|
|
|
|
repository {
|
|
|
|
owner {
|
|
|
|
login
|
2019-02-07 07:35:19 +01:00
|
|
|
}
|
2019-02-19 08:25:15 +01:00
|
|
|
name
|
2019-02-07 07:35:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-19 08:25:15 +01:00
|
|
|
... on LabeledEvent {
|
|
|
|
createdAt
|
|
|
|
actor {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
label {
|
|
|
|
name
|
|
|
|
color
|
|
|
|
}
|
|
|
|
}
|
|
|
|
... on UnlabeledEvent {
|
|
|
|
createdAt
|
|
|
|
actor {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
label {
|
|
|
|
name
|
|
|
|
color
|
|
|
|
}
|
|
|
|
}
|
|
|
|
... on MilestonedEvent {
|
|
|
|
createdAt
|
|
|
|
actor {
|
|
|
|
login
|
2019-02-07 07:35:19 +01:00
|
|
|
}
|
2019-02-19 08:25:15 +01:00
|
|
|
milestoneTitle
|
|
|
|
}
|
|
|
|
... on LockedEvent {
|
|
|
|
createdAt
|
|
|
|
actor {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
lockReason
|
|
|
|
}
|
|
|
|
... on UnlockedEvent {
|
|
|
|
createdAt
|
|
|
|
actor {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
}
|
|
|
|
... on AssignedEvent {
|
|
|
|
createdAt
|
|
|
|
actor {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
user {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
}
|
|
|
|
''';
|
2019-02-07 07:35:19 +01:00
|
|
|
|
2019-02-19 08:25:15 +01:00
|
|
|
if (isPullRequest) {
|
|
|
|
base += '''
|
|
|
|
... on ReviewRequestedEvent {
|
|
|
|
createdAt
|
|
|
|
actor {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
requestedReviewer {
|
|
|
|
... on User {
|
|
|
|
login
|
2019-02-08 07:01:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-19 08:25:15 +01:00
|
|
|
... on PullRequestReview {
|
|
|
|
createdAt
|
|
|
|
state
|
|
|
|
author {
|
|
|
|
login
|
2019-02-08 07:01:25 +01:00
|
|
|
}
|
2019-02-19 08:25:15 +01:00
|
|
|
}
|
|
|
|
... on MergedEvent {
|
|
|
|
createdAt
|
|
|
|
mergeRefName
|
|
|
|
actor {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
commit {
|
|
|
|
oid
|
|
|
|
url
|
|
|
|
}
|
|
|
|
}
|
|
|
|
... on HeadRefDeletedEvent {
|
|
|
|
createdAt
|
|
|
|
actor {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
headRefName
|
|
|
|
}
|
|
|
|
''';
|
|
|
|
}
|
|
|
|
|
|
|
|
return base;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future _queryIssue({String cursor, bool trailing = false}) async {
|
|
|
|
String timelineParams;
|
|
|
|
if (trailing) {
|
|
|
|
timelineParams = 'last: $pageSize';
|
|
|
|
} else {
|
|
|
|
timelineParams = 'first: $pageSize';
|
|
|
|
if (cursor != null) {
|
|
|
|
timelineParams += ', after: $cursor';
|
|
|
|
}
|
|
|
|
}
|
2019-02-08 07:01:25 +01:00
|
|
|
|
|
|
|
var data = await SettingsProvider.of(context).query('''
|
|
|
|
{
|
|
|
|
repository(owner: "$owner", name: "$name") {
|
2019-02-19 08:25:15 +01:00
|
|
|
$resource(number: $number) {
|
|
|
|
$issueChunk
|
|
|
|
timeline($timelineParams) {
|
|
|
|
totalCount
|
|
|
|
pageInfo {
|
|
|
|
hasNextPage
|
|
|
|
endCursor
|
|
|
|
}
|
2019-02-08 07:01:25 +01:00
|
|
|
nodes {
|
2019-02-19 08:25:15 +01:00
|
|
|
$timelineChunk
|
2019-02-08 07:01:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
''');
|
2019-02-19 08:25:15 +01:00
|
|
|
return data['repository'][resource];
|
2019-02-08 07:01:25 +01:00
|
|
|
}
|
|
|
|
|
2019-02-09 08:33:06 +01:00
|
|
|
Widget _buildBadge(payload) {
|
|
|
|
Color bgColor;
|
|
|
|
IconData iconData;
|
|
|
|
String text;
|
|
|
|
|
2019-02-19 08:25:15 +01:00
|
|
|
if (isPullRequest) {
|
|
|
|
if (payload['merged']) {
|
|
|
|
bgColor = Palette.purple;
|
|
|
|
iconData = Octicons.git_merge;
|
|
|
|
text = 'Merged';
|
|
|
|
} else if (payload['closed']) {
|
|
|
|
bgColor = Palette.red;
|
|
|
|
iconData = Octicons.git_pull_request;
|
|
|
|
text = 'Closed';
|
|
|
|
} else {
|
|
|
|
bgColor = Palette.green;
|
|
|
|
iconData = Octicons.git_pull_request;
|
|
|
|
text = 'Open';
|
|
|
|
}
|
2019-02-09 08:33:06 +01:00
|
|
|
} else {
|
2019-02-19 08:25:15 +01:00
|
|
|
if (payload['closed']) {
|
|
|
|
bgColor = Palette.red;
|
|
|
|
iconData = Octicons.issue_closed;
|
|
|
|
text = 'Closed';
|
|
|
|
} else {
|
|
|
|
bgColor = Palette.green;
|
|
|
|
iconData = Octicons.issue_opened;
|
|
|
|
text = 'Open';
|
|
|
|
}
|
2019-02-09 08:33:06 +01:00
|
|
|
}
|
|
|
|
return Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: bgColor,
|
|
|
|
borderRadius: BorderRadius.all(Radius.circular(4)),
|
|
|
|
),
|
|
|
|
padding: EdgeInsets.all(6),
|
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
|
|
|
Icon(iconData, color: Colors.white, size: 15),
|
|
|
|
Padding(padding: EdgeInsets.only(left: 2)),
|
|
|
|
Text(
|
|
|
|
text,
|
|
|
|
style: TextStyle(
|
|
|
|
color: Colors.white,
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
fontSize: 14,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-02-10 11:50:40 +01:00
|
|
|
Future<void> _openActions(payload) async {
|
|
|
|
if (payload == null) return;
|
|
|
|
|
2019-02-19 14:20:00 +01:00
|
|
|
showActions(
|
|
|
|
context,
|
|
|
|
title: (isPullRequest ? 'Pull Request' : 'Issue') + ' Actions',
|
|
|
|
actions: [
|
|
|
|
Action(
|
|
|
|
text: 'Share',
|
|
|
|
onPress: () {
|
|
|
|
Share.share(payload['url']);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
Action(
|
|
|
|
text: 'Open in Browser',
|
|
|
|
onPress: () {
|
|
|
|
launch(payload['url']);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
2019-02-10 11:50:40 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-01-25 18:43:09 +01:00
|
|
|
@override
|
2019-01-27 17:37:44 +01:00
|
|
|
Widget build(BuildContext context) {
|
2019-02-08 07:01:25 +01:00
|
|
|
return LongListScaffold(
|
2019-02-19 08:25:15 +01:00
|
|
|
title: Text('$owner/$name #$number'),
|
2019-02-10 11:50:40 +01:00
|
|
|
trailingBuilder: (payload) {
|
|
|
|
return Link(
|
|
|
|
child: Icon(Icons.more_vert, size: 24),
|
|
|
|
material: false,
|
|
|
|
beforeRedirect: () => _openActions(payload),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
actionsBuilder: (payload) {
|
|
|
|
return [
|
|
|
|
Link(
|
|
|
|
iconButton: Icon(Icons.more_vert),
|
|
|
|
beforeRedirect: () => _openActions(payload),
|
|
|
|
),
|
|
|
|
];
|
|
|
|
},
|
2019-02-08 07:01:25 +01:00
|
|
|
headerBuilder: (payload) {
|
|
|
|
return Column(children: <Widget>[
|
|
|
|
Container(
|
2019-02-09 08:33:06 +01:00
|
|
|
padding: EdgeInsets.all(10),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border(bottom: BorderSide(color: Colors.black12)),
|
|
|
|
),
|
2019-02-08 07:01:25 +01:00
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
2019-02-09 08:33:06 +01:00
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
children: <Widget>[
|
|
|
|
Expanded(
|
|
|
|
child: Text(
|
|
|
|
payload['title'],
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 20,
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(padding: EdgeInsets.only(right: 8)),
|
|
|
|
_buildBadge(payload),
|
|
|
|
],
|
2019-02-08 07:01:25 +01:00
|
|
|
),
|
2019-02-09 08:33:06 +01:00
|
|
|
Padding(padding: EdgeInsets.only(bottom: 16)),
|
2019-02-08 07:01:25 +01:00
|
|
|
CommentItem(payload),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
itemBuilder: (itemPayload) => TimelineItem(itemPayload),
|
2019-02-03 07:42:50 +01:00
|
|
|
onRefresh: () async {
|
2019-02-19 08:25:15 +01:00
|
|
|
var res = await _queryIssue();
|
2019-02-08 07:01:25 +01:00
|
|
|
int totalCount = res['timeline']['totalCount'];
|
|
|
|
String cursor = res['timeline']['pageInfo']['endCursor'];
|
|
|
|
List leadingItems = res['timeline']['nodes'];
|
|
|
|
|
|
|
|
var payload = LongListPayload(
|
|
|
|
header: res,
|
|
|
|
totalCount: totalCount,
|
|
|
|
cursor: cursor,
|
|
|
|
leadingItems: leadingItems,
|
|
|
|
trailingItems: [],
|
|
|
|
);
|
|
|
|
|
|
|
|
if (totalCount > 2 * pageSize) {
|
2019-02-19 08:25:15 +01:00
|
|
|
var res = await _queryIssue(trailing: true);
|
|
|
|
payload.trailingItems = res['timeline']['nodes'];
|
2019-02-06 14:35:52 +01:00
|
|
|
}
|
2019-02-08 07:01:25 +01:00
|
|
|
|
|
|
|
return payload;
|
|
|
|
},
|
|
|
|
onLoadMore: (String _cursor) async {
|
2019-02-19 08:25:15 +01:00
|
|
|
var res = await _queryIssue(cursor: _cursor);
|
2019-02-08 07:01:25 +01:00
|
|
|
int totalCount = res['timeline']['totalCount'];
|
|
|
|
String cursor = res['timeline']['pageInfo']['endCursor'];
|
|
|
|
List leadingItems = res['timeline']['nodes'];
|
|
|
|
|
|
|
|
var payload = LongListPayload(
|
|
|
|
totalCount: totalCount,
|
|
|
|
cursor: cursor,
|
|
|
|
leadingItems: leadingItems,
|
|
|
|
);
|
|
|
|
|
|
|
|
return payload;
|
2019-02-03 07:42:50 +01:00
|
|
|
},
|
2019-01-25 18:43:09 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|