mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2024-11-27 14:59:29 +01:00
Merge branch 'krille/send-file-dialog' into 'main'
Krille/send file dialog See merge request famedly/fluffychat!599
This commit is contained in:
commit
bf87052f7b
@ -1,3 +1,5 @@
|
||||
//@dart=2.12
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||
@ -13,9 +15,9 @@ class SendFileDialog extends StatefulWidget {
|
||||
final MatrixFile file;
|
||||
|
||||
const SendFileDialog({
|
||||
this.room,
|
||||
this.file,
|
||||
Key key,
|
||||
required this.room,
|
||||
required this.file,
|
||||
Key? key,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
@ -26,9 +28,14 @@ class _SendFileDialogState extends State<SendFileDialog> {
|
||||
bool origImage = false;
|
||||
bool _isSending = false;
|
||||
|
||||
/// Images smaller than 20kb don't need compression.
|
||||
static const int minSizeToCompress = 20 * 1024;
|
||||
|
||||
Future<void> _send() async {
|
||||
var file = widget.file;
|
||||
if (file is MatrixImageFile && !origImage) {
|
||||
if (file is MatrixImageFile &&
|
||||
!origImage &&
|
||||
file.bytes.length > minSizeToCompress) {
|
||||
file = await file.resizeImage(quality: 40, max: 1200);
|
||||
}
|
||||
await widget.room.sendFileEventWithThumbnail(file);
|
||||
@ -36,13 +43,13 @@ class _SendFileDialogState extends State<SendFileDialog> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var sendStr = L10n.of(context).sendFile;
|
||||
var sendStr = L10n.of(context)!.sendFile;
|
||||
if (widget.file is MatrixImageFile) {
|
||||
sendStr = L10n.of(context).sendImage;
|
||||
sendStr = L10n.of(context)!.sendImage;
|
||||
} else if (widget.file is MatrixAudioFile) {
|
||||
sendStr = L10n.of(context).sendAudio;
|
||||
sendStr = L10n.of(context)!.sendAudio;
|
||||
} else if (widget.file is MatrixVideoFile) {
|
||||
sendStr = L10n.of(context).sendVideo;
|
||||
sendStr = L10n.of(context)!.sendVideo;
|
||||
}
|
||||
Widget contentWidget;
|
||||
if (widget.file is MatrixImageFile) {
|
||||
@ -53,16 +60,15 @@ class _SendFileDialogState extends State<SendFileDialog> {
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
),
|
||||
Text(widget.file.name),
|
||||
Row(
|
||||
children: <Widget>[
|
||||
Checkbox(
|
||||
value: origImage,
|
||||
onChanged: (v) => setState(() => origImage = v),
|
||||
onChanged: (v) => setState(() => origImage = v ?? false),
|
||||
),
|
||||
InkWell(
|
||||
onTap: () => setState(() => origImage = !origImage),
|
||||
child: Text(L10n.of(context).sendOriginal +
|
||||
child: Text(L10n.of(context)!.sendOriginal +
|
||||
' (${widget.file.sizeString})'),
|
||||
),
|
||||
],
|
||||
@ -80,7 +86,7 @@ class _SendFileDialogState extends State<SendFileDialog> {
|
||||
// just close the dialog
|
||||
Navigator.of(context, rootNavigator: false).pop();
|
||||
},
|
||||
child: Text(L10n.of(context).cancel),
|
||||
child: Text(L10n.of(context)!.cancel),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: _isSending
|
||||
@ -93,7 +99,7 @@ class _SendFileDialogState extends State<SendFileDialog> {
|
||||
context: context, future: () => _send());
|
||||
Navigator.of(context, rootNavigator: false).pop();
|
||||
},
|
||||
child: Text(L10n.of(context).send),
|
||||
child: Text(L10n.of(context)!.send),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user