2020-09-04 10:56:25 +00:00
|
|
|
import 'package:famedlysdk/famedlysdk.dart';
|
2020-10-03 11:11:07 +00:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2020-09-04 10:56:25 +00:00
|
|
|
|
2020-10-03 11:11:07 +00:00
|
|
|
import '../../components/dialogs/simple_dialogs.dart';
|
2020-09-04 10:56:25 +00:00
|
|
|
import '../../utils/matrix_file_extension.dart';
|
2020-10-06 16:22:50 +00:00
|
|
|
import '../../utils/resize_image.dart';
|
2020-10-15 13:51:24 +00:00
|
|
|
import '../../utils/room_send_file_extension.dart';
|
2020-09-04 10:56:25 +00:00
|
|
|
|
|
|
|
class SendFileDialog extends StatefulWidget {
|
|
|
|
final Room room;
|
|
|
|
final MatrixFile file;
|
|
|
|
|
|
|
|
const SendFileDialog({this.room, this.file, Key key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
_SendFileDialogState createState() => _SendFileDialogState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _SendFileDialogState extends State<SendFileDialog> {
|
|
|
|
bool origImage = false;
|
|
|
|
|
|
|
|
Future<void> _send() async {
|
|
|
|
var file = widget.file;
|
|
|
|
if (file is MatrixImageFile && !origImage) {
|
|
|
|
try {
|
2020-10-06 16:22:50 +00:00
|
|
|
file = await resizeImage(file, max: 1600);
|
2020-09-04 10:56:25 +00:00
|
|
|
} catch (e) {
|
|
|
|
// couldn't resize
|
|
|
|
}
|
|
|
|
}
|
|
|
|
await widget.room.sendFileEventWithThumbnail(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
var sendStr = L10n.of(context).sendFile;
|
|
|
|
if (widget.file is MatrixImageFile) {
|
|
|
|
sendStr = L10n.of(context).sendImage;
|
|
|
|
} else if (widget.file is MatrixAudioFile) {
|
|
|
|
sendStr = L10n.of(context).sendAudio;
|
|
|
|
} else if (widget.file is MatrixVideoFile) {
|
|
|
|
sendStr = L10n.of(context).sendVideo;
|
|
|
|
}
|
|
|
|
Widget contentWidget;
|
|
|
|
if (widget.file is MatrixImageFile) {
|
|
|
|
contentWidget = Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
|
|
|
|
Flexible(
|
|
|
|
child: Image.memory(
|
|
|
|
widget.file.bytes,
|
|
|
|
fit: BoxFit.contain,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Text(widget.file.name),
|
|
|
|
Row(
|
|
|
|
children: <Widget>[
|
|
|
|
Checkbox(
|
|
|
|
value: origImage,
|
|
|
|
onChanged: (v) => setState(() => origImage = v),
|
|
|
|
),
|
|
|
|
InkWell(
|
|
|
|
onTap: () => setState(() => origImage = !origImage),
|
|
|
|
child: Text(L10n.of(context).sendOriginal +
|
|
|
|
' (${widget.file.sizeString})'),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
contentWidget = Text('${widget.file.name} (${widget.file.sizeString})');
|
|
|
|
}
|
|
|
|
return AlertDialog(
|
|
|
|
title: Text(sendStr),
|
|
|
|
content: contentWidget,
|
|
|
|
actions: <Widget>[
|
|
|
|
FlatButton(
|
|
|
|
child: Text(L10n.of(context).cancel),
|
|
|
|
onPressed: () {
|
|
|
|
// just close the dialog
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
FlatButton(
|
|
|
|
child: Text(L10n.of(context).send),
|
|
|
|
onPressed: () async {
|
|
|
|
await SimpleDialogs(context).tryRequestWithLoadingDialog(_send());
|
|
|
|
await Navigator.of(context).pop();
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|