2022-09-17 16:35:45 +02:00
|
|
|
import 'package:antd_mobile/antd_mobile.dart';
|
2022-09-13 17:52:35 +02:00
|
|
|
import 'package:file_icon/file_icon.dart';
|
2020-01-30 08:31:46 +01:00
|
|
|
import 'package:filesize/filesize.dart';
|
2022-09-17 14:35:45 +02:00
|
|
|
import 'package:flutter/widgets.dart';
|
2020-01-30 05:55:55 +01:00
|
|
|
import 'package:git_touch/utils/utils.dart';
|
|
|
|
import 'package:git_touch/widgets/table_view.dart';
|
2021-06-14 05:28:12 +02:00
|
|
|
|
2022-09-13 17:52:35 +02:00
|
|
|
Widget _buildIcon(String type, String name) {
|
|
|
|
switch (type) {
|
|
|
|
case 'blob': // github gql, gitlab
|
|
|
|
case 'file': // github rest, gitea
|
|
|
|
case 'commit_file': // bitbucket
|
2022-09-17 16:35:45 +02:00
|
|
|
return FileIcon(name, size: 26); // TODO: size
|
2022-09-13 17:52:35 +02:00
|
|
|
case 'tree': // github gql, gitlab
|
|
|
|
case 'dir': // github rest, gitea
|
|
|
|
case 'commit_directory': // bitbucket
|
2022-09-17 16:35:45 +02:00
|
|
|
return const Icon(AntIcons.folderOutline);
|
2022-09-13 17:52:35 +02:00
|
|
|
case 'commit':
|
2022-09-17 16:35:45 +02:00
|
|
|
return const Icon(AntIcons.fileOutline);
|
2022-09-13 17:52:35 +02:00
|
|
|
default:
|
|
|
|
throw 'object type error';
|
2020-01-30 05:55:55 +01:00
|
|
|
}
|
2022-09-13 17:52:35 +02:00
|
|
|
}
|
2020-01-30 05:55:55 +01:00
|
|
|
|
2022-09-13 17:52:35 +02:00
|
|
|
TableViewItem createObjectTreeItem({
|
|
|
|
required String name,
|
|
|
|
required String type,
|
|
|
|
required String url,
|
|
|
|
String? downloadUrl,
|
|
|
|
int? size,
|
|
|
|
}) {
|
|
|
|
return TableViewItem(
|
2022-09-13 19:19:52 +02:00
|
|
|
prefix: _buildIcon(type, name),
|
|
|
|
child: Text(name),
|
|
|
|
extra: size == null ? null : Text(filesize(size)),
|
2022-09-13 17:52:35 +02:00
|
|
|
url: [
|
|
|
|
// Let system browser handle these files
|
|
|
|
//
|
|
|
|
// TODO:
|
|
|
|
// Unhandled Exception: PlatformException(Error, Error while launching
|
|
|
|
// https://github.com/flutter/flutter/issues/49162
|
2020-01-31 09:40:20 +01:00
|
|
|
|
2022-09-13 17:52:35 +02:00
|
|
|
// Docs
|
|
|
|
'pdf', 'docx', 'doc', 'pptx', 'ppt', 'xlsx', 'xls',
|
|
|
|
// Fonts
|
|
|
|
'ttf', 'otf', 'eot', 'woff', 'woff2',
|
|
|
|
'svg',
|
|
|
|
].contains(name.ext)
|
|
|
|
? downloadUrl
|
|
|
|
: url,
|
|
|
|
hideRightChevron: size != null,
|
|
|
|
);
|
2020-01-30 05:55:55 +01:00
|
|
|
}
|