2022-09-17 20:35:45 +08:00
|
|
|
import 'package:flutter/widgets.dart';
|
2021-02-03 09:34:41 +05:30
|
|
|
import 'package:flutter_gen/gen_l10n/S.dart';
|
2021-01-23 19:38:05 +05:30
|
|
|
import 'package:git_touch/models/auth.dart';
|
|
|
|
import 'package:git_touch/models/gogs.dart';
|
|
|
|
import 'package:git_touch/scaffolds/refresh_stateful.dart';
|
|
|
|
import 'package:git_touch/utils/utils.dart';
|
|
|
|
import 'package:git_touch/widgets/action_entry.dart';
|
|
|
|
import 'package:git_touch/widgets/app_bar_title.dart';
|
|
|
|
import 'package:git_touch/widgets/blob_view.dart';
|
|
|
|
import 'package:git_touch/widgets/object_tree.dart';
|
2021-06-14 11:28:12 +08:00
|
|
|
import 'package:git_touch/widgets/table_view.dart';
|
2021-01-23 19:38:05 +05:30
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
class GoObjectScreen extends StatelessWidget {
|
|
|
|
final String owner;
|
|
|
|
final String name;
|
2021-05-16 15:16:35 +08:00
|
|
|
final String? path;
|
|
|
|
final String? ref;
|
2022-09-07 00:28:12 +08:00
|
|
|
const GoObjectScreen(this.owner, this.name, {this.path, this.ref});
|
2021-01-23 19:38:05 +05:30
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return RefreshStatefulScaffold(
|
2021-05-16 15:16:35 +08:00
|
|
|
title: AppBarTitle(path ?? AppLocalizations.of(context)!.files),
|
2021-01-23 19:38:05 +05:30
|
|
|
fetch: () async {
|
|
|
|
final suffix = path == null ? '' : '/$path';
|
|
|
|
final res = await context
|
|
|
|
.read<AuthModel>()
|
|
|
|
.fetchGogs('/repos/$owner/$name/contents$suffix?ref=$ref');
|
|
|
|
return res;
|
|
|
|
},
|
2021-05-16 15:16:35 +08:00
|
|
|
actionBuilder: (dynamic p, _) {
|
2021-01-23 19:38:05 +05:30
|
|
|
if (p is List) {
|
|
|
|
return null;
|
|
|
|
} else {
|
2022-09-07 00:28:12 +08:00
|
|
|
return const ActionEntry(
|
2021-02-14 22:17:22 +08:00
|
|
|
iconData: Ionicons.cog,
|
2021-01-23 19:38:05 +05:30
|
|
|
url: '/choose-code-theme',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
2021-05-16 15:16:35 +08:00
|
|
|
bodyBuilder: (dynamic p, _) {
|
2021-01-23 19:38:05 +05:30
|
|
|
if (p is List) {
|
|
|
|
final items = p.map((t) => GogsTree.fromJson(t)).toList();
|
|
|
|
items.sort((a, b) {
|
|
|
|
return sortByKey('dir', a.type, b.type);
|
|
|
|
});
|
2021-06-14 11:28:12 +08:00
|
|
|
return TableView(items: [
|
2021-01-23 19:38:05 +05:30
|
|
|
for (var v in items)
|
2022-09-13 23:52:35 +08:00
|
|
|
createObjectTreeItem(
|
2021-01-23 19:38:05 +05:30
|
|
|
name: v.name,
|
|
|
|
type: v.type,
|
|
|
|
size: v.type == 'file' ? v.size : null,
|
|
|
|
url:
|
2021-05-16 15:16:35 +08:00
|
|
|
'/gogs/$owner/$name/blob?path=${v.path!.urlencode}&ref=$ref',
|
2021-01-23 19:38:05 +05:30
|
|
|
downloadUrl: v.downloadUrl,
|
|
|
|
),
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
final v = GogsBlob.fromJson(p);
|
2021-06-14 00:59:06 +08:00
|
|
|
return BlobView(v.name, base64Text: v.content);
|
2021-01-23 19:38:05 +05:30
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|