chore: Follow up send file dialog

pull/1470/head
Krille 1 year ago
parent cbe2e6b02a
commit ae8965b03f
No known key found for this signature in database
GPG Key ID: E067ECD60F1A0652

@ -2805,5 +2805,6 @@
"serverInformation": "Server information:", "serverInformation": "Server information:",
"name": "Name", "name": "Name",
"version": "Version", "version": "Version",
"website": "Website" "website": "Website",
"compressBeforeSending": "Compress before sending"
} }

@ -34,7 +34,7 @@ class SendFileDialog extends StatefulWidget {
} }
class SendFileDialogState extends State<SendFileDialog> { class SendFileDialogState extends State<SendFileDialog> {
bool origImage = false; bool compress = true;
/// Images smaller than 20kb don't need compression. /// Images smaller than 20kb don't need compression.
static const int minSizeToCompress = 20 * 1024; static const int minSizeToCompress = 20 * 1024;
@ -60,7 +60,7 @@ class SendFileDialogState extends State<SendFileDialog> {
mimeType != null && mimeType != null &&
mimeType.startsWith('video') && mimeType.startsWith('video') &&
length > minSizeToCompress && length > minSizeToCompress &&
!origImage) { compress) {
scaffoldMessenger.showLoadingSnackBar(l10n.compressVideo); scaffoldMessenger.showLoadingSnackBar(l10n.compressVideo);
file = await xfile.resizeVideo(); file = await xfile.resizeVideo();
scaffoldMessenger.showLoadingSnackBar(l10n.generatingVideoThumbnail); scaffoldMessenger.showLoadingSnackBar(l10n.generatingVideoThumbnail);
@ -70,7 +70,7 @@ class SendFileDialogState extends State<SendFileDialog> {
file = MatrixFile( file = MatrixFile(
bytes: await xfile.readAsBytes(), bytes: await xfile.readAsBytes(),
name: xfile.name, name: xfile.name,
mimeType: xfile.mimeType, mimeType: mimeType,
).detectFileType; ).detectFileType;
} }
@ -93,7 +93,7 @@ class SendFileDialogState extends State<SendFileDialog> {
await widget.room.sendFileEvent( await widget.room.sendFileEvent(
file, file,
thumbnail: thumbnail, thumbnail: thumbnail,
shrinkImageMaxDimension: origImage ? null : 1600, shrinkImageMaxDimension: compress ? 1600 : null,
); );
} on MatrixException catch (e) { } on MatrixException catch (e) {
final retryAfterMs = e.retryAfterMs; final retryAfterMs = e.retryAfterMs;
@ -117,7 +117,7 @@ class SendFileDialogState extends State<SendFileDialog> {
await widget.room.sendFileEvent( await widget.room.sendFileEvent(
file, file,
thumbnail: thumbnail, thumbnail: thumbnail,
shrinkImageMaxDimension: origImage ? null : 1600, shrinkImageMaxDimension: compress ? null : 1600,
); );
} }
} }
@ -156,6 +156,11 @@ class SendFileDialogState extends State<SendFileDialog> {
final fileName = widget.files.length == 1 final fileName = widget.files.length == 1
? widget.files.single.name ? widget.files.single.name
: L10n.of(context).countFiles(widget.files.length.toString()); : L10n.of(context).countFiles(widget.files.length.toString());
final fileTypes = widget.files
.map((file) => file.name.split('.').last)
.toSet()
.join(', ')
.toUpperCase();
if (uniqueMimeType?.startsWith('image') ?? false) { if (uniqueMimeType?.startsWith('image') ?? false) {
sendStr = L10n.of(context).sendImage; sendStr = L10n.of(context).sendImage;
@ -171,98 +176,86 @@ class SendFileDialogState extends State<SendFileDialog> {
final sizeString = final sizeString =
snapshot.data ?? L10n.of(context).calculatingFileSize; snapshot.data ?? L10n.of(context).calculatingFileSize;
Widget contentWidget; return AlertDialog.adaptive(
if (uniqueMimeType?.startsWith('image') ?? false) { title: Text(sendStr),
contentWidget = Column( content: SizedBox(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Flexible(
child: Material(
borderRadius: BorderRadius.circular(AppConfig.borderRadius),
elevation: theme.appBarTheme.scrolledUnderElevation ?? 4,
shadowColor: theme.appBarTheme.shadowColor,
clipBehavior: Clip.hardEdge,
child: kIsWeb
? Image.network(
widget.files.first.path,
fit: BoxFit.contain,
height: 256,
)
: Image.file(
File(widget.files.first.path),
fit: BoxFit.contain,
height: 256,
),
),
),
const SizedBox(height: 16),
// Workaround for SwitchListTile.adaptive crashes in CupertinoDialog
Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
CupertinoSwitch(
value: origImage,
onChanged: (v) => setState(() => origImage = v),
),
const SizedBox(width: 16),
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
L10n.of(context).sendOriginal,
style: const TextStyle(fontWeight: FontWeight.bold),
),
Text(sizeString),
],
),
),
],
),
],
);
} else {
final fileNameParts = fileName.split('.');
contentWidget = SizedBox(
width: 256, width: 256,
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
Row( const SizedBox(height: 12),
children: [ if (uniqueMimeType?.startsWith('image') ?? false)
Icon( Padding(
uniqueMimeType == null padding: const EdgeInsets.only(bottom: 16.0),
? Icons.description_outlined child: Material(
: uniqueMimeType.startsWith('video') borderRadius:
? Icons.video_file_outlined BorderRadius.circular(AppConfig.borderRadius / 2),
: uniqueMimeType.startsWith('audio') clipBehavior: Clip.hardEdge,
? Icons.audio_file_outlined child: kIsWeb
: Icons.description_outlined, ? Image.network(
widget.files.first.path,
fit: BoxFit.contain,
height: 156,
)
: Image.file(
File(widget.files.first.path),
fit: BoxFit.contain,
height: 156,
),
), ),
const SizedBox(width: 8), ),
Expanded( if (uniqueMimeType?.startsWith('image') != true ||
child: Text( widget.files.length > 1)
fileNameParts.first, Padding(
maxLines: 1, padding: const EdgeInsets.only(bottom: 16.0),
overflow: TextOverflow.ellipsis, child: Row(
), children: [
Icon(
uniqueMimeType == null
? Icons.description_outlined
: uniqueMimeType.startsWith('video')
? Icons.video_file_outlined
: uniqueMimeType.startsWith('audio')
? Icons.audio_file_outlined
: Icons.description_outlined,
size: 32,
),
const SizedBox(width: 8),
Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
fileName,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
Text(
'$sizeString - $fileTypes',
style: theme.textTheme.labelSmall,
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
),
),
],
), ),
if (fileNameParts.length > 1) ),
Text('.${fileNameParts.last}'),
Text(' ($sizeString)'),
],
),
// Workaround for SwitchListTile.adaptive crashes in CupertinoDialog // Workaround for SwitchListTile.adaptive crashes in CupertinoDialog
if (uniqueMimeType != null && if (uniqueMimeType != null &&
uniqueMimeType.startsWith('video') && (uniqueMimeType.startsWith('image') ||
PlatformInfos.isMobile) uniqueMimeType.startsWith('video')))
Row( Row(
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
CupertinoSwitch( CupertinoSwitch(
value: origImage, value: compress,
onChanged: (v) => setState(() => origImage = v), onChanged: uniqueMimeType.startsWith('video') &&
!PlatformInfos.isMobile
? null
: (v) => setState(() => compress = v),
), ),
const SizedBox(width: 16), const SizedBox(width: 16),
Expanded( Expanded(
@ -271,11 +264,10 @@ class SendFileDialogState extends State<SendFileDialog> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text( Text(
L10n.of(context).sendOriginal, L10n.of(context).compressBeforeSending,
style: style: theme.textTheme.labelMedium,
const TextStyle(fontWeight: FontWeight.bold), textAlign: TextAlign.left,
), ),
Text(sizeString),
], ],
), ),
), ),
@ -283,11 +275,7 @@ class SendFileDialogState extends State<SendFileDialog> {
), ),
], ],
), ),
); ),
}
return AlertDialog.adaptive(
title: Text(sendStr),
content: contentWidget,
actions: <Widget>[ actions: <Widget>[
AdaptiveDialogAction( AdaptiveDialogAction(
onPressed: () => onPressed: () =>

Loading…
Cancel
Save