chore: defaultly save files on Android

- defaultly save files on Android instead of share
- add dedicated share button for files and images on Android
- use ListTile instead of row to display file event
- update file_picker_cross

Signed-off-by: TheOneWithTheBraid <the-one@with-the-braid.cf>
This commit is contained in:
TheOneWithTheBraid 2022-04-30 17:43:38 +02:00
commit 49caad00c0
9 changed files with 137 additions and 68 deletions

View file

@ -8,18 +8,28 @@ import 'package:matrix/matrix.dart';
import 'matrix_file_extension.dart';
extension LocalizedBody on Event {
Future<LoadingDialogResult<MatrixFile?>> _getFile(BuildContext context) =>
showFutureLoadingDialog(
context: context,
future: () => downloadAndDecryptAttachmentCached(),
);
void saveFile(BuildContext context) async {
final matrixFile = await showFutureLoadingDialog(
context: context,
future: () => downloadAndDecryptAttachmentCached(),
);
final matrixFile = await _getFile(context);
matrixFile.result?.save(context);
}
void shareFile(BuildContext context) async {
final matrixFile = await _getFile(context);
matrixFile.result?.share(context);
}
bool get isAttachmentSmallEnough =>
infoMap['size'] is int &&
infoMap['size'] < room.client.database!.maxFileSize;
bool get isThumbnailSmallEnough =>
thumbnailInfoMap['size'] is int &&
thumbnailInfoMap['size'] < room.client.database!.maxFileSize;

View file

@ -13,23 +13,25 @@ import 'package:fluffychat/utils/platform_infos.dart';
extension MatrixFileExtension on MatrixFile {
void save(BuildContext context) async {
final fileName = name.split('/').last;
if (PlatformInfos.isMobile) {
final tmpDirectory = PlatformInfos.isAndroid
? (await getExternalStorageDirectories(
type: StorageDirectory.downloads))!
.first
: await getTemporaryDirectory();
final path = '${tmpDirectory.path}$fileName';
await File(path).writeAsBytes(bytes);
await Share.shareFiles([path]);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(L10n.of(context)!.savedFileAs(path))),
);
return;
} else {
final file = FilePickerCross(bytes);
await file.exportToStorage(fileName: fileName);
}
final file = FilePickerCross(bytes);
await file.exportToStorage(fileName: fileName, share: false);
}
void share(BuildContext context) async {
final fileName = name.split('/').last;
final tmpDirectory = PlatformInfos.isAndroid
? (await getExternalStorageDirectories(
type: StorageDirectory.downloads))!
.first
: await getTemporaryDirectory();
final path = '${tmpDirectory.path}$fileName';
await File(path).writeAsBytes(bytes);
await Share.shareFiles([path]);
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text(L10n.of(context)!.savedFileAs(path))),
);
return;
}
MatrixFile get detectFileType {