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

fix: Android Download

See merge request ChristianPauly/fluffychat-flutter!246
This commit is contained in:
Christian Pauly 2020-10-28 07:53:49 +00:00
commit c221e497bb
5 changed files with 37 additions and 7 deletions

View file

@ -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 {
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'
}

View file

@ -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,8 +27,11 @@ extension MatrixFileExtension on MatrixFile {
element.click();
element.remove();
} else {
final downloadsDir = Platform.isAndroid
? (await getExternalStorageDirectory())
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);

View file

@ -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;
}

View file

@ -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:
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:

View file

@ -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