Browse Source

Merge branch 'krille/fix-android-download' into 'main'

fix: Android Download

See merge request ChristianPauly/fluffychat-flutter!246
yiffed
Christian Pauly 2 years ago
parent
commit
c221e497bb
  1. 6
      android/app/build.gradle
  2. 12
      lib/utils/matrix_file_extension.dart
  3. 3
      lib/utils/platform_infos.dart
  4. 21
      pubspec.lock
  5. 2
      pubspec.yaml

6
android/app/build.gradle

@ -44,7 +44,7 @@ android { @@ -44,7 +44,7 @@ android {
defaultConfig {
applicationId "chat.fluffy.fluffychat"
minSdkVersion 18
minSdkVersion 21
targetSdkVersion 28
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
@ -87,6 +87,4 @@ dependencies { @@ -87,6 +87,4 @@ dependencies {
implementation "net.zetetic:android-database-sqlcipher:4.4.0" // needed for moor_ffi w/ sqlcipher
}
if(file("google-services.json").exists() || System.getenv('CI')){
apply plugin: 'com.google.gms.google-services'
}
apply plugin: 'com.google.gms.google-services'

12
lib/utils/matrix_file_extension.dart

@ -1,11 +1,14 @@ @@ -1,11 +1,14 @@
import 'dart:io';
import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/utils/platform_infos.dart';
import 'package:flutter/foundation.dart';
import 'package:open_file/open_file.dart';
import 'package:path_provider/path_provider.dart';
import 'package:universal_html/prefer_universal/html.dart' as html;
import 'package:mime_type/mime_type.dart';
import 'package:downloads_path_provider_28/downloads_path_provider_28.dart';
import 'package:permission_handler/permission_handler.dart';
extension MatrixFileExtension on MatrixFile {
void open() async {
@ -24,9 +27,12 @@ extension MatrixFileExtension on MatrixFile { @@ -24,9 +27,12 @@ extension MatrixFileExtension on MatrixFile {
element.click();
element.remove();
} else {
final downloadsDir = Platform.isAndroid
? (await getExternalStorageDirectory())
: (await getApplicationDocumentsDirectory());
if (!(await Permission.storage.request()).isGranted) return;
final downloadsDir = PlatformInfos.isDesktop
? (await getDownloadsDirectory())
: Platform.isAndroid
? (await DownloadsPathProvider.downloadsDirectory)
: (await getApplicationDocumentsDirectory());
final file = File(downloadsDir.path + '/' + name.split('/').last);
file.writeAsBytesSync(bytes);

3
lib/utils/platform_infos.dart

@ -11,5 +11,8 @@ abstract class PlatformInfos { @@ -11,5 +11,8 @@ abstract class PlatformInfos {
static bool get isBetaDesktop =>
!kIsWeb && (Platform.isWindows || Platform.isLinux);
static bool get isDesktop =>
!kIsWeb && (Platform.isLinux || Platform.isWindows || Platform.isMacOS);
static bool get usesTouchscreen => !isMobile;
}

21
pubspec.lock

@ -183,6 +183,13 @@ packages: @@ -183,6 +183,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.3"
downloads_path_provider_28:
dependency: "direct main"
description:
name: downloads_path_provider_28
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.0"
encrypt:
dependency: transitive
description:
@ -683,6 +690,20 @@ packages: @@ -683,6 +690,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.10.0-nullsafety.1"
permission_handler:
dependency: "direct main"
description:
name: permission_handler
url: "https://pub.dartlang.org"
source: hosted
version: "5.0.1+1"
permission_handler_platform_interface:
dependency: transitive
description:
name: permission_handler_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
petitparser:
dependency: transitive
description:

2
pubspec.yaml

@ -39,6 +39,8 @@ dependencies: @@ -39,6 +39,8 @@ dependencies:
# desktop_notifications: ^0.0.0-dev.4 // Currently blocked by: https://github.com/canonical/desktop_notifications.dart/issues/5
matrix_link_text: ^0.3.1
path_provider: ^1.5.1
downloads_path_provider_28: ^0.1.0
permission_handler: ^5.0.1+1
webview_flutter: ^0.3.19+9
share: ^0.6.3+5
flutter_secure_storage: ^3.3.5

Loading…
Cancel
Save