2019-02-04 14:38:29 +01:00
|
|
|
import 'dart:convert';
|
2019-01-27 17:37:44 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2019-02-04 14:38:29 +01:00
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter_markdown/flutter_markdown.dart';
|
2019-09-02 15:52:32 +02:00
|
|
|
import 'package:git_touch/models/theme.dart';
|
2019-08-30 10:26:56 +02:00
|
|
|
import 'package:git_touch/screens/commits.dart';
|
2019-08-30 08:08:09 +02:00
|
|
|
import 'package:git_touch/screens/object.dart';
|
2019-09-02 15:52:32 +02:00
|
|
|
import 'package:provider/provider.dart';
|
2019-02-10 11:50:40 +01:00
|
|
|
import 'package:share/share.dart';
|
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
2019-02-07 07:35:19 +01:00
|
|
|
import '../providers/settings.dart';
|
2019-02-08 07:06:48 +01:00
|
|
|
import '../scaffolds/refresh.dart';
|
2019-02-04 14:38:29 +01:00
|
|
|
import '../widgets/repo_item.dart';
|
|
|
|
import '../widgets/entry_item.dart';
|
|
|
|
import '../screens/issues.dart';
|
2019-03-10 14:53:35 +01:00
|
|
|
import '../screens/user.dart';
|
2019-03-10 16:34:34 +01:00
|
|
|
import '../screens/organization.dart';
|
2019-02-20 09:31:22 +01:00
|
|
|
import '../widgets/action.dart';
|
2019-03-10 16:34:34 +01:00
|
|
|
import '../utils/utils.dart';
|
2019-02-04 14:38:29 +01:00
|
|
|
|
2019-02-07 07:35:19 +01:00
|
|
|
class RepoScreen extends StatefulWidget {
|
|
|
|
final String owner;
|
|
|
|
final String name;
|
|
|
|
|
|
|
|
RepoScreen(this.owner, this.name);
|
|
|
|
|
|
|
|
@override
|
|
|
|
_RepoScreenState createState() => _RepoScreenState();
|
2019-02-04 14:38:29 +01:00
|
|
|
}
|
|
|
|
|
2019-02-07 07:35:19 +01:00
|
|
|
class _RepoScreenState extends State<RepoScreen> {
|
2019-03-10 14:53:35 +01:00
|
|
|
String get owner => widget.owner;
|
|
|
|
String get name => widget.name;
|
2019-02-10 11:50:40 +01:00
|
|
|
|
2019-02-07 07:35:19 +01:00
|
|
|
Future queryRepo(BuildContext context) async {
|
|
|
|
var data = await SettingsProvider.of(context).query('''
|
2019-02-04 14:38:29 +01:00
|
|
|
{
|
|
|
|
repository(owner: "$owner", name: "$name") {
|
2019-02-10 11:50:40 +01:00
|
|
|
id
|
2019-02-04 14:38:29 +01:00
|
|
|
owner {
|
2019-03-10 14:53:35 +01:00
|
|
|
__typename
|
2019-02-04 14:38:29 +01:00
|
|
|
login
|
2019-03-10 16:34:34 +01:00
|
|
|
url
|
2019-02-04 14:38:29 +01:00
|
|
|
}
|
|
|
|
name
|
|
|
|
isPrivate
|
|
|
|
isFork
|
|
|
|
description
|
|
|
|
stargazers {
|
|
|
|
totalCount
|
|
|
|
}
|
|
|
|
forks {
|
|
|
|
totalCount
|
|
|
|
}
|
|
|
|
primaryLanguage {
|
|
|
|
color
|
|
|
|
name
|
|
|
|
}
|
|
|
|
issues(states: OPEN) {
|
|
|
|
totalCount
|
|
|
|
}
|
|
|
|
pullRequests(states: OPEN) {
|
|
|
|
totalCount
|
|
|
|
}
|
2019-02-10 07:26:51 +01:00
|
|
|
url
|
|
|
|
defaultBranchRef {
|
|
|
|
name
|
2019-08-30 10:26:56 +02:00
|
|
|
target {
|
|
|
|
... on Commit {
|
|
|
|
history {
|
|
|
|
totalCount
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-10 07:26:51 +01:00
|
|
|
}
|
2019-02-10 11:50:40 +01:00
|
|
|
viewerHasStarred
|
|
|
|
viewerSubscription
|
2019-02-04 14:38:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
''');
|
2019-02-07 07:35:19 +01:00
|
|
|
return data['repository'];
|
|
|
|
}
|
2019-02-06 15:28:04 +01:00
|
|
|
|
2019-02-07 07:35:19 +01:00
|
|
|
Future fetchReadme(BuildContext context) async {
|
|
|
|
var owner = widget.owner;
|
|
|
|
var name = widget.name;
|
|
|
|
var data = await SettingsProvider.of(context)
|
|
|
|
.getWithCredentials('/repos/$owner/$name/readme');
|
2019-02-14 05:42:25 +01:00
|
|
|
|
|
|
|
if (data['content'] == null) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2019-02-07 07:35:19 +01:00
|
|
|
var bits = base64.decode(data['content'].replaceAll('\n', ''));
|
|
|
|
var str = utf8.decode(bits);
|
|
|
|
return str;
|
2019-02-06 15:28:04 +01:00
|
|
|
}
|
|
|
|
|
2019-01-25 13:35:20 +01:00
|
|
|
@override
|
2019-01-27 17:37:44 +01:00
|
|
|
Widget build(BuildContext context) {
|
2019-02-04 14:38:29 +01:00
|
|
|
return RefreshScaffold(
|
|
|
|
title: Text(widget.owner + '/' + widget.name),
|
2019-02-20 09:31:22 +01:00
|
|
|
trailingBuilder: (data) {
|
|
|
|
var payload = data[0];
|
|
|
|
|
|
|
|
return ActionButton(title: 'Repository Actions', actions: [
|
2019-06-20 16:59:13 +02:00
|
|
|
MyAction(
|
2019-03-10 16:34:34 +01:00
|
|
|
text: '@$owner',
|
2019-03-10 14:53:35 +01:00
|
|
|
onPress: () {
|
|
|
|
WidgetBuilder builder;
|
|
|
|
|
|
|
|
switch (payload['owner']['__typename']) {
|
|
|
|
case 'Organization':
|
2019-03-10 16:34:34 +01:00
|
|
|
// builder = (_) => OrganizationScreen(owner);
|
|
|
|
// break;
|
|
|
|
|
|
|
|
// Seems organization permission is a little complicated
|
|
|
|
// So we just launch browser currently
|
|
|
|
launch(payload['owner']['url']);
|
|
|
|
return;
|
2019-03-10 14:53:35 +01:00
|
|
|
case 'User':
|
|
|
|
builder = (_) => UserScreen(owner);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-09-02 15:52:32 +02:00
|
|
|
Provider.of<ThemeModel>(context)
|
2019-03-10 14:53:35 +01:00
|
|
|
.pushRoute(context: context, builder: builder);
|
|
|
|
},
|
|
|
|
),
|
2019-06-20 16:59:13 +02:00
|
|
|
MyAction(
|
2019-02-20 09:31:22 +01:00
|
|
|
text: payload['viewerHasStarred'] ? 'Unstar' : 'Star',
|
|
|
|
onPress: () async {
|
|
|
|
if (payload['viewerHasStarred']) {
|
|
|
|
await SettingsProvider.of(context)
|
|
|
|
.deleteWithCredentials('/user/starred/$owner/$name');
|
|
|
|
payload['viewerHasStarred'] = false;
|
|
|
|
} else {
|
|
|
|
SettingsProvider.of(context)
|
|
|
|
.putWithCredentials('/user/starred/$owner/$name');
|
|
|
|
payload['viewerHasStarred'] = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
// TODO: watch
|
2019-06-20 16:59:13 +02:00
|
|
|
MyAction(
|
2019-02-20 09:31:22 +01:00
|
|
|
text: 'Share',
|
|
|
|
onPress: () {
|
|
|
|
Share.share(payload['url']);
|
|
|
|
},
|
|
|
|
),
|
2019-06-20 16:59:13 +02:00
|
|
|
MyAction(
|
2019-02-20 09:31:22 +01:00
|
|
|
text: 'Open in Browser',
|
|
|
|
onPress: () {
|
|
|
|
launch(payload['url']);
|
|
|
|
},
|
2019-02-10 11:50:40 +01:00
|
|
|
),
|
2019-02-20 09:31:22 +01:00
|
|
|
]);
|
2019-02-10 11:50:40 +01:00
|
|
|
},
|
2019-02-08 13:52:10 +01:00
|
|
|
onRefresh: () => Future.wait([
|
2019-06-20 16:59:13 +02:00
|
|
|
queryRepo(context),
|
|
|
|
fetchReadme(context),
|
|
|
|
]),
|
2019-02-08 13:52:10 +01:00
|
|
|
bodyBuilder: (data) {
|
|
|
|
var payload = data[0];
|
|
|
|
var readme = data[1];
|
|
|
|
|
2019-02-04 14:38:29 +01:00
|
|
|
return Column(
|
|
|
|
children: <Widget>[
|
2019-03-10 10:24:03 +01:00
|
|
|
RepoItem(payload, isLink: false),
|
2019-02-04 14:38:29 +01:00
|
|
|
Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border(
|
|
|
|
bottom: BorderSide(color: Colors.black12),
|
|
|
|
top: BorderSide(color: Colors.black12),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
|
|
|
EntryItem(
|
|
|
|
count: payload['issues']['totalCount'],
|
|
|
|
text: 'Issues',
|
2019-02-10 05:42:21 +01:00
|
|
|
screenBuilder: (context) => IssuesScreen(
|
2019-06-20 16:59:13 +02:00
|
|
|
owner: widget.owner,
|
|
|
|
name: widget.name,
|
|
|
|
),
|
2019-02-04 14:38:29 +01:00
|
|
|
),
|
|
|
|
EntryItem(
|
|
|
|
count: payload['pullRequests']['totalCount'],
|
|
|
|
text: 'Pull Requests',
|
2019-02-10 05:42:21 +01:00
|
|
|
screenBuilder: (context) => IssuesScreen(
|
2019-06-20 16:59:13 +02:00
|
|
|
owner: widget.owner,
|
|
|
|
name: widget.name,
|
|
|
|
isPullRequest: true,
|
|
|
|
),
|
2019-02-04 14:38:29 +01:00
|
|
|
),
|
2019-02-10 07:26:51 +01:00
|
|
|
EntryItem(
|
|
|
|
text: 'Files',
|
2019-08-30 08:08:09 +02:00
|
|
|
screenBuilder: (context) => ObjectScreen(
|
|
|
|
owner: widget.owner,
|
|
|
|
name: widget.name,
|
|
|
|
),
|
2019-02-10 07:26:51 +01:00
|
|
|
),
|
|
|
|
EntryItem(
|
2019-08-30 10:26:56 +02:00
|
|
|
count: payload['defaultBranchRef']['target']['history']
|
|
|
|
['totalCount'],
|
2019-02-10 07:26:51 +01:00
|
|
|
text: 'Commits',
|
2019-08-30 10:26:56 +02:00
|
|
|
screenBuilder: (context) =>
|
|
|
|
CommitsScreen(widget.owner, widget.name),
|
2019-02-10 07:26:51 +01:00
|
|
|
),
|
2019-02-04 14:38:29 +01:00
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
padding: EdgeInsets.all(16),
|
|
|
|
child: MarkdownBody(data: readme),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
2019-01-25 13:35:20 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|