diff --git a/lib/utils/matrix_sdk_extensions.dart/matrix_file_extension.dart b/lib/utils/matrix_sdk_extensions.dart/matrix_file_extension.dart index 9b7ad7f2..979b02e4 100644 --- a/lib/utils/matrix_sdk_extensions.dart/matrix_file_extension.dart +++ b/lib/utils/matrix_sdk_extensions.dart/matrix_file_extension.dart @@ -4,54 +4,24 @@ import 'package:matrix/matrix.dart'; import 'package:fluffychat/utils/platform_infos.dart'; import 'package:flutter/material.dart'; import 'package:path_provider/path_provider.dart'; -import 'package:permission_handler/permission_handler.dart'; import 'package:file_picker_cross/file_picker_cross.dart'; -import 'package:filesystem_picker/filesystem_picker.dart'; -import 'package:flutter_gen/gen_l10n/l10n.dart'; import 'package:share/share.dart'; +import 'package:flutter_gen/gen_l10n/l10n.dart'; extension MatrixFileExtension on MatrixFile { void save(BuildContext context) async { final fileName = name.split('/').last; - if (PlatformInfos.isIOS) { - final tmpDirectory = await getTemporaryDirectory(); + if (PlatformInfos.isMobile) { + final tmpDirectory = PlatformInfos.isAndroid + ? Directory('/storage/emulated/0/Download') + : await getTemporaryDirectory(); final path = '${tmpDirectory.path}$fileName'; await File(path).writeAsBytes(bytes); await Share.shareFiles([path]); - return; - } - if (PlatformInfos.isAndroid) { - if (!(await Permission.storage.request()).isGranted) return; - final path = await FilesystemPicker.open( - title: L10n.of(context).saveFile, - context: context, - rootDirectory: Directory('/sdcard/'), - fsType: FilesystemType.folder, - pickText: L10n.of(context).saveFileToFolder, - folderIconColor: Theme.of(context).primaryColor, - requestPermission: () async => - await Permission.storage.request().isGranted, + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text(L10n.of(context).savedFileAs(path))), ); - if (path != null) { - // determine a unique filename - // somefile-number.extension, e.g. helloworld-1.txt - var file = File('$path/$fileName'); - var i = 0; - var extension = ''; - if (fileName.contains('.')) { - extension = fileName.substring(fileName.lastIndexOf('.')); - } - final fileNameWithoutExtension = - fileName.substring(0, fileName.lastIndexOf('.')); - while (await file.exists()) { - i++; - file = File('$path/$fileNameWithoutExtension-$i$extension'); - } - await file.writeAsBytes(bytes); - ScaffoldMessenger.of(context).showSnackBar(SnackBar( - content: - Text(L10n.of(context).savedFileAs(file.path.split('/').last)))); - } + return; } else { final file = FilePickerCross(bytes); await file.exportToStorage(fileName: fileName); diff --git a/pubspec.lock b/pubspec.lock index 9258bf26..3ea87468 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -309,13 +309,6 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.0.2" - filesystem_picker: - dependency: "direct main" - description: - name: filesystem_picker - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.0-nullsafety.0" flutter: dependency: "direct main" description: flutter diff --git a/pubspec.yaml b/pubspec.yaml index 47c64c38..bef71b90 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -19,7 +19,6 @@ dependencies: #fcm_shared_isolate: # git: https://gitlab.com/famedly/libraries/fcm_shared_isolate.git file_picker_cross: ^4.5.0 - filesystem_picker: 2.0.0-nullsafety.0 # Using pre release to be compatible with Flutter 2.5 flutter: sdk: flutter # From this fix: https://github.com/g123k/flutter_app_badger/pull/47 diff --git a/scripts/code_analyze.sh b/scripts/code_analyze.sh index e211b715..719fcfb1 100755 --- a/scripts/code_analyze.sh +++ b/scripts/code_analyze.sh @@ -1,4 +1,4 @@ #!/bin/sh -ve +git apply ./scripts/enable-android-google-services.patch flutter format lib/ test/ --set-exit-if-changed flutter analyze -git apply ./scripts/enable-android-google-services.patch --check diff --git a/scripts/enable-android-google-services.patch b/scripts/enable-android-google-services.patch index 285f902b..64ddd836 100644 --- a/scripts/enable-android-google-services.patch +++ b/scripts/enable-android-google-services.patch @@ -99,5 +99,5 @@ index 9e7f148c..ea2d90f9 100644 + fcm_shared_isolate: + git: https://gitlab.com/famedly/libraries/fcm_shared_isolate.git file_picker_cross: ^4.5.0 - filesystem_picker: 2.0.0-nullsafety.0 # Using pre release to be compatible with Flutter 2.5 flutter: + sdk: flutter