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