2020-11-08 15:00:13 +08:00
|
|
|
import 'dart:convert';
|
|
|
|
|
2020-01-29 18:50:17 +08:00
|
|
|
import 'package:filesize/filesize.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:git_touch/models/auth.dart';
|
|
|
|
import 'package:git_touch/models/gitea.dart';
|
|
|
|
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';
|
|
|
|
import 'package:git_touch/widgets/markdown_view.dart';
|
|
|
|
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-08 15:00:13 +08:00
|
|
|
import 'package:http/http.dart' as http;
|
2021-02-03 09:34:41 +05:30
|
|
|
import 'package:flutter_gen/gen_l10n/S.dart';
|
2020-01-29 18:50:17 +08:00
|
|
|
|
2020-02-07 22:20:06 +08:00
|
|
|
class GtRepoScreen extends StatelessWidget {
|
2020-01-29 18:50:17 +08:00
|
|
|
final String owner;
|
|
|
|
final String name;
|
2020-02-07 22:20:06 +08:00
|
|
|
GtRepoScreen(this.owner, this.name);
|
2020-01-29 18:50:17 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-11-08 15:00:13 +08:00
|
|
|
return RefreshStatefulScaffold<Tuple2<GiteaRepository, MarkdownViewData>>(
|
2021-05-16 15:16:35 +08:00
|
|
|
title: AppBarTitle(AppLocalizations.of(context)!.repository),
|
2020-10-06 20:52:40 +08:00
|
|
|
fetch: () async {
|
2020-10-04 20:37:23 +08:00
|
|
|
final auth = context.read<AuthModel>();
|
2020-11-08 15:00:13 +08:00
|
|
|
final repo = await auth.fetchGitea('/repos/$owner/$name').then((v) {
|
|
|
|
return GiteaRepository.fromJson(v);
|
|
|
|
});
|
|
|
|
|
|
|
|
final md = () =>
|
|
|
|
auth.fetchGitea('/repos/$owner/$name/contents/README.md').then((v) {
|
2021-05-16 15:16:35 +08:00
|
|
|
return (v['content'] as String?)?.base64ToUtf8 ?? '';
|
2020-11-08 15:00:13 +08:00
|
|
|
});
|
|
|
|
final html = () => md().then((v) async {
|
|
|
|
final res = await http.post(
|
2021-05-16 15:16:35 +08:00
|
|
|
Uri.parse('${auth.activeAccount!.domain}/api/v1/markdown/raw'),
|
2020-11-08 15:00:13 +08:00
|
|
|
headers: {'Authorization': 'token ${auth.token}'},
|
|
|
|
body: v,
|
|
|
|
);
|
|
|
|
return utf8.decode(res.bodyBytes).normalizedHtml;
|
|
|
|
});
|
|
|
|
final readmeData = MarkdownViewData(context, md: md, html: html);
|
|
|
|
|
|
|
|
return Tuple2(repo, readmeData);
|
2020-01-29 18:50:17 +08:00
|
|
|
},
|
2021-01-31 15:49:28 +08:00
|
|
|
bodyBuilder: (t, _) {
|
2020-01-29 18:50:17 +08:00
|
|
|
final p = t.item1;
|
|
|
|
return Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
|
|
children: <Widget>[
|
|
|
|
RepoHeader(
|
2021-05-16 15:16:35 +08:00
|
|
|
avatarUrl: p.owner!.avatarUrl,
|
|
|
|
avatarLink: '/gitea/${p.owner!.login}',
|
|
|
|
owner: p.owner!.login,
|
2020-01-29 18:50:17 +08:00
|
|
|
name: p.name,
|
|
|
|
description: p.description,
|
|
|
|
homepageUrl: p.website,
|
|
|
|
),
|
|
|
|
CommonStyle.border,
|
|
|
|
Row(
|
|
|
|
children: <Widget>[
|
2020-10-05 18:20:00 +08:00
|
|
|
EntryItem(
|
|
|
|
text: 'Watchers',
|
|
|
|
url: '/gitea/$owner/$name/watchers',
|
|
|
|
),
|
2020-01-29 18:50:17 +08:00
|
|
|
EntryItem(
|
|
|
|
count: p.starsCount,
|
|
|
|
text: 'Stars',
|
2020-10-05 18:20:00 +08:00
|
|
|
url: '/gitea/$owner/$name/stargazers',
|
2020-01-29 18:50:17 +08:00
|
|
|
),
|
|
|
|
EntryItem(
|
|
|
|
count: p.forksCount,
|
2020-10-05 18:20:00 +08:00
|
|
|
text: 'Forks',
|
|
|
|
url: '/gitea/$owner/$name/forks',
|
2020-01-29 18:50:17 +08:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
CommonStyle.border,
|
|
|
|
TableView(
|
|
|
|
hasIcon: true,
|
|
|
|
items: [
|
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.code,
|
|
|
|
text: Text('Code'),
|
2021-05-16 15:16:35 +08:00
|
|
|
rightWidget: Text(filesize(p.size! * 1000)),
|
2020-01-30 15:04:29 +08:00
|
|
|
url: '/gitea/$owner/$name/blob',
|
2020-01-29 18:50:17 +08:00
|
|
|
),
|
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.issue_opened,
|
|
|
|
text: Text('Issues'),
|
|
|
|
rightWidget: Text(numberFormat.format(p.openIssuesCount)),
|
|
|
|
url: '/gitea/$owner/$name/issues',
|
|
|
|
),
|
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.git_pull_request,
|
|
|
|
text: Text('Pull requests'),
|
|
|
|
rightWidget: Text(numberFormat.format(p.openPrCounter)),
|
|
|
|
url: '/gitea/$owner/$name/pulls',
|
|
|
|
),
|
|
|
|
TableViewItem(
|
|
|
|
leftIconData: Octicons.history,
|
|
|
|
text: Text('Commits'),
|
|
|
|
url: '/gitea/$owner/$name/commits',
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
CommonStyle.verticalGap,
|
2020-11-08 15:00:13 +08:00
|
|
|
MarkdownView(t.item2),
|
2020-01-29 18:50:17 +08:00
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|