2020-11-01 16:43:51 +01:00
|
|
|
import 'dart:convert';
|
2020-10-17 13:06:11 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:git_touch/models/auth.dart';
|
|
|
|
import 'package:git_touch/models/gitee.dart';
|
2021-01-09 17:52:45 +01:00
|
|
|
import 'package:git_touch/models/theme.dart';
|
2020-10-17 13:06:11 +02:00
|
|
|
import 'package:git_touch/scaffolds/refresh_stateful.dart';
|
|
|
|
import 'package:git_touch/utils/utils.dart';
|
|
|
|
import 'package:git_touch/widgets/app_bar_title.dart';
|
|
|
|
import 'package:git_touch/widgets/entry_item.dart';
|
2020-11-04 09:41:04 +01:00
|
|
|
import 'package:git_touch/widgets/markdown_view.dart';
|
2020-10-17 13:06:11 +02:00
|
|
|
import 'package:git_touch/widgets/repo_header.dart';
|
|
|
|
import 'package:git_touch/widgets/table_view.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:tuple/tuple.dart';
|
2020-11-01 16:43:51 +01:00
|
|
|
import 'package:http/http.dart' as http;
|
2021-01-05 10:25:19 +01:00
|
|
|
import '../generated/l10n.dart';
|
2020-10-17 13:06:11 +02:00
|
|
|
|
|
|
|
class GeRepoScreen extends StatelessWidget {
|
|
|
|
final String owner;
|
|
|
|
final String name;
|
2021-01-09 17:52:45 +01:00
|
|
|
final String branch;
|
|
|
|
GeRepoScreen(this.owner, this.name, {this.branch});
|
2020-10-17 13:06:11 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-01-09 17:52:45 +01:00
|
|
|
return RefreshStatefulScaffold<
|
|
|
|
Tuple3<GiteeRepo, MarkdownViewData, List<GiteeBranch>>>(
|
2021-01-05 10:25:19 +01:00
|
|
|
title: AppBarTitle(S.of(context).repository),
|
2020-10-17 13:06:11 +02:00
|
|
|
fetch: () async {
|
|
|
|
final auth = context.read<AuthModel>();
|
2020-11-08 08:00:13 +01:00
|
|
|
final repo = await auth.fetchGitee('/repos/$owner/$name').then((v) {
|
|
|
|
return GiteeRepo.fromJson(v);
|
|
|
|
});
|
2020-11-01 16:43:51 +01:00
|
|
|
|
2020-11-08 08:00:13 +01:00
|
|
|
final md =
|
|
|
|
() => auth.fetchGitee('/repos/$owner/$name/readme').then((v) {
|
|
|
|
return (v['content'] as String)?.base64ToUtf8;
|
|
|
|
});
|
|
|
|
final html = () => md().then((v) async {
|
|
|
|
final res = await http.post(
|
|
|
|
'${auth.activeAccount.domain}/api/v5/markdown',
|
|
|
|
headers: {'Authorization': 'token ${auth.token}'},
|
|
|
|
body: {'text': v},
|
|
|
|
);
|
|
|
|
return utf8.decode(res.bodyBytes).normalizedHtml;
|
|
|
|
});
|
|
|
|
final readmeData = MarkdownViewData(context, md: md, html: html);
|
2021-01-09 17:52:45 +01:00
|
|
|
final branches =
|
|
|
|
await auth.fetchGitee('/repos/$owner/$name/branches').then((v) {
|
|
|
|
return [for (var branch in v) GiteeBranch.fromJson(branch)];
|
|
|
|
});
|
|
|
|
return Tuple3(repo, readmeData, branches);
|
2020-10-17 13:06:11 +02:00
|
|
|
},
|
|
|
|
bodyBuilder: (t, setState) {
|
|
|
|
final p = t.item1;
|
2021-01-09 17:52:45 +01:00
|
|
|
final branches = t.item3;
|
|
|
|
final theme = context.read<ThemeModel>();
|
2020-10-17 13:06:11 +02:00
|
|
|
return Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: <Widget>[
|
|
|
|
RepoHeader(
|
|
|
|
avatarUrl: p.owner.avatarUrl,
|
|
|
|
avatarLink: '/gitee/${p.namespace.path}',
|
|
|
|
owner: p.namespace.path,
|
|
|
|
name: p.path,
|
|
|
|
description: p.description,
|
|
|
|
homepageUrl: p.homepage,
|
|
|
|
),
|
|
|
|
CommonStyle.border,
|
|
|
|
Row(
|
|
|
|
children: <Widget>[
|
|
|
|
EntryItem(
|
|
|
|
text: 'Watchers',
|
|
|
|
url: '/gitee/$owner/$name/watchers',
|
|
|
|
),
|
|
|
|
EntryItem(
|
|
|
|
count: p.stargazersCount,
|
|
|
|
text: 'Stars',
|
|
|
|
url: '/gitee/$owner/$name/stargazers',
|
|
|
|
),
|
|
|
|
EntryItem(
|
|
|
|
count: p.forksCount,
|
|
|
|
text: 'Forks',
|
|
|
|
url: '/gitee/$owner/$name/forks',
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
CommonStyle.border,
|
|
|
|
TableView(
|
|
|
|
hasIcon: true,
|
|
|
|
items: [
|
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.code,
|
|
|
|
text: Text('Code'),
|
|
|
|
rightWidget: Text(p.license ?? ''),
|
2021-01-09 17:52:45 +01:00
|
|
|
url:
|
|
|
|
'/gitee/$owner/$name/tree/${branch == null ? p.defaultBranch : branch}',
|
2020-10-17 13:06:11 +02:00
|
|
|
),
|
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.issue_opened,
|
|
|
|
text: Text('Issues'),
|
|
|
|
rightWidget: Text(numberFormat.format(p.openIssuesCount)),
|
2021-01-06 05:52:58 +01:00
|
|
|
url: '/gitee/$owner/$name/issues',
|
2020-10-17 13:06:11 +02:00
|
|
|
),
|
|
|
|
if (p.pullRequestsEnabled)
|
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.git_pull_request,
|
|
|
|
text: Text('Pull requests'),
|
2021-01-06 05:52:58 +01:00
|
|
|
url: '/gitee/$owner/$name/pulls',
|
2020-10-17 13:06:11 +02:00
|
|
|
),
|
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.history,
|
|
|
|
text: Text('Commits'),
|
2021-01-09 17:52:45 +01:00
|
|
|
url:
|
|
|
|
'/gitee/$owner/$name/commits?branch=${branch == null ? p.defaultBranch : branch}',
|
2020-10-17 13:06:11 +02:00
|
|
|
),
|
2021-01-09 17:52:45 +01:00
|
|
|
if (branches != null)
|
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.git_branch,
|
|
|
|
text: Text(S.of(context).branches),
|
|
|
|
rightWidget: Text(
|
|
|
|
(branch == null ? p.defaultBranch : branch) +
|
|
|
|
' • ' +
|
|
|
|
branches.length.toString()),
|
|
|
|
onTap: () async {
|
|
|
|
if (branches.length < 2) return;
|
|
|
|
|
|
|
|
await theme.showPicker(
|
|
|
|
context,
|
|
|
|
PickerGroupItem(
|
|
|
|
value: branch,
|
|
|
|
items: branches
|
|
|
|
.map((b) => PickerItem(b.name, text: b.name))
|
|
|
|
.toList(),
|
|
|
|
onClose: (ref) {
|
|
|
|
if (ref != branch) {
|
|
|
|
theme.push(
|
|
|
|
context, '/gitee/$owner/$name?branch=$ref',
|
|
|
|
replace: true);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.organization,
|
|
|
|
text: Text('Contributors'),
|
|
|
|
url: '/gitee/$owner/$name/contributors'),
|
2020-10-17 13:06:11 +02:00
|
|
|
],
|
|
|
|
),
|
|
|
|
CommonStyle.verticalGap,
|
2020-11-08 08:00:13 +01:00
|
|
|
MarkdownView(t.item2)
|
2020-10-17 13:06:11 +02:00
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|