TF-32 Add presentation layer of export attachment for ios platform

This commit is contained in:
dab246
2021-09-16 09:46:49 +07:00
committed by Dat H. Pham
parent afae25a97a
commit d168900975
19 changed files with 517 additions and 119 deletions
@@ -7,20 +7,38 @@ import 'package:flutter_svg/flutter_svg.dart';
import 'package:model/model.dart';
typedef OnDownloadAttachmentFileActionClick = void Function(Attachment attachment);
typedef OnExpandAttachmentActionClick = void Function();
class AttachmentFileTileBuilder {
final ImagePaths _imagePaths;
final Attachment _attachment;
final int _attachmentSize;
final int _limitDisplayAttachment;
ExpandMode? _expandMode;
OnDownloadAttachmentFileActionClick? _onDownloadAttachmentFileActionClick;
OnExpandAttachmentActionClick? _onExpandAttachmentActionClick;
AttachmentFileTileBuilder(this._imagePaths, this._attachment);
AttachmentFileTileBuilder(
this._imagePaths,
this._attachment,
this._attachmentSize,
this._limitDisplayAttachment,
);
void onDownloadAttachmentFileActionClick(OnDownloadAttachmentFileActionClick onDownloadAttachmentFileActionClick) {
_onDownloadAttachmentFileActionClick = onDownloadAttachmentFileActionClick;
}
void onExpandAttachmentActionClick(OnExpandAttachmentActionClick onExpandAttachmentActionClick) {
_onExpandAttachmentActionClick = onExpandAttachmentActionClick;
}
void setExpandMode(ExpandMode? expandMode) {
_expandMode = expandMode;
}
Widget build() {
return Theme(
data: ThemeData(
@@ -35,37 +53,72 @@ class AttachmentFileTileBuilder {
color: Colors.white),
child: MediaQuery(
data: MediaQueryData(padding: EdgeInsets.zero),
child: ListTile(
contentPadding: EdgeInsets.zero,
focusColor: AppColor.primaryColor,
hoverColor: AppColor.primaryColor,
onTap: () {
if (_onDownloadAttachmentFileActionClick != null) {
_onDownloadAttachmentFileActionClick!(_attachment);
}},
leading: Transform(
transform: Matrix4.translationValues(14.0, 2.0, 0.0),
child: SvgPicture.asset(_imagePaths.icAttachmentFile, width: 24, height: 24, fit: BoxFit.fill)),
title: Transform(
transform: Matrix4.translationValues(-8.0, -8.0, 0.0),
child: Text(
_attachment.name ?? '',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 12, color: AppColor.attachmentFileNameColor, fontWeight: FontWeight.w500),
)),
subtitle: _attachment.size != null && _attachment.size?.value != 0
? Transform(
child: Stack(
alignment: AlignmentDirectional.bottomEnd,
children: [
ListTile(
contentPadding: EdgeInsets.zero,
focusColor: AppColor.primaryColor,
hoverColor: AppColor.primaryColor,
onTap: () {
if (_onDownloadAttachmentFileActionClick != null) {
_onDownloadAttachmentFileActionClick!(_attachment);
}},
leading: Transform(
transform: Matrix4.translationValues(14.0, 2.0, 0.0),
child: SvgPicture.asset(_imagePaths.icAttachmentFile, width: 24, height: 24, fit: BoxFit.fill)),
title: Transform(
transform: Matrix4.translationValues(-8.0, -8.0, 0.0),
child: Text(
filesize(_attachment.size?.value),
_attachment.name ?? '',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 12, color: AppColor.attachmentFileSizeColor)))
: null
),
style: TextStyle(fontSize: 12, color: AppColor.attachmentFileNameColor, fontWeight: FontWeight.w500),
)),
subtitle: _attachment.size != null && _attachment.size?.value != 0
? Transform(
transform: Matrix4.translationValues(-8.0, -8.0, 0.0),
child: Text(
filesize(_attachment.size?.value),
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 12, color: AppColor.attachmentFileSizeColor)))
: null
),
Transform(
transform: Matrix4.translationValues(5.0, 5.0, 0.0),
child: IconButton(
icon: SvgPicture.asset(_imagePaths.icDownload, width: 24, height: 24, fit: BoxFit.fill),
onPressed: () {
if (_onDownloadAttachmentFileActionClick != null) {
_onDownloadAttachmentFileActionClick!(_attachment);
}
}
)),
if (_attachmentSize > _limitDisplayAttachment && _expandMode == ExpandMode.COLLAPSE) _buildItemBackground()
]
)
)
)
);
}
Widget _buildItemBackground() {
return GestureDetector(
onTap: () {
if (_onExpandAttachmentActionClick != null) {
_onExpandAttachmentActionClick!();
}
},
child: Stack(
alignment: AlignmentDirectional.center,
children: [
Container(color: AppColor.backgroundCountAttachment),
Text(
'+${_attachmentSize - _limitDisplayAttachment + 1}',
style: TextStyle(fontSize: 16, color: Colors.white, fontWeight: FontWeight.bold))
],
),
);
}
}