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:
parent
14a6047fef
commit
49caad00c0
9 changed files with 137 additions and 68 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue