Skip to content

Commit

Permalink
Merge pull request #232 from humhub/f-links-to-humhub-files-are-not-c…
Browse files Browse the repository at this point in the history
…lickable

Use in app external storage.
  • Loading branch information
luke- authored Sep 24, 2024
2 parents 910914a + 660ce06 commit 0384f80
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 24 deletions.
2 changes: 0 additions & 2 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />

<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />

<!-- For older versions (For Android 12 (API 31) and Below) -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Expand Down
1 change: 0 additions & 1 deletion lib/app_flavored.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class FlavoredAppState extends ConsumerState<FlavoredApp> {
SchedulerBinding.instance.addPostFrameCallback((_) async {
await PermissionHandler.requestPermissions([
Permission.notification,
Permission.manageExternalStorage,
]);
});
}
Expand Down
1 change: 0 additions & 1 deletion lib/app_opener.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class OpenerAppState extends ConsumerState<OpenerApp> {
SchedulerBinding.instance.addPostFrameCallback((_) async {
await PermissionHandler.requestPermissions([
Permission.notification,
Permission.manageExternalStorage,
]);
});
}
Expand Down
5 changes: 2 additions & 3 deletions lib/util/file_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:humhub/util/permission_handler.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:path_provider/path_provider.dart';
import 'package:permission_handler/permission_handler.dart';

class FileHandler {
final InAppWebViewController controller;
Expand Down Expand Up @@ -45,7 +44,7 @@ class FileHandler {

download() {
PermissionHandler.runWithPermissionCheck(
permissions: [Permission.storage],
permissions: [],
action: () => _download(),
);
}
Expand Down Expand Up @@ -120,7 +119,7 @@ class FileHandler {
if (Platform.isIOS) {
directory = await getApplicationDocumentsDirectory();
} else {
String check = "/storage/emulated/0/Download";
String check = (await getExternalStorageDirectory())?.path ?? '';

bool dirDownloadExists = await Directory(check).exists();
if (dirDownloadExists) {
Expand Down
19 changes: 2 additions & 17 deletions lib/util/permission_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,7 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart';

class PermissionHandler {
// Static method that takes a list of permissions and handles requests
static Future<void> requestPermissions(List<Permission> permissions) async {
for (Permission permission in permissions) {
// Check the current status of the permission
PermissionStatus status = await permission.status;

// Only request the permission if it has never been asked or is not granted
if (status.isDenied || status.isRestricted || status.isPermanentlyDenied) {
continue; // Don't request again if it's denied or restricted
}

// Request the permission if not granted
if (!status.isGranted) {
await permission.request();
}
}
}
static Future<void> requestPermissions(List<Permission> permissions) async => await permissions.request();

// Static method to check permissions before executing a function
static Future<void> runWithPermissionCheck({
Expand All @@ -44,7 +29,7 @@ class PermissionHandler {
action();
} else {
// Show a SnackBar indicating that permissions are missing
if(navigatorKey.currentState != null && navigatorKey.currentState!.mounted){
if (navigatorKey.currentState != null && navigatorKey.currentState!.mounted) {
scaffoldMessengerStateKey.currentState?.showSnackBar(
SnackBar(
content: Text(AppLocalizations.of(navigatorKey.currentState!.context)!.enable_permissions),
Expand Down

0 comments on commit 0384f80

Please sign in to comment.