From a0231de55996c1f0650ed790fbf24549e9b72aa7 Mon Sep 17 00:00:00 2001 From: Thibault Deckers Date: Mon, 19 Sep 2022 18:29:04 +0200 Subject: [PATCH] fixed deleting binned item from the Download album --- CHANGELOG.md | 1 + .../deckers/thibault/aves/utils/PermissionManager.kt | 1 + lib/model/entry.dart | 8 ++++++-- lib/widgets/collection/entry_set_action_delegate.dart | 6 +++--- lib/widgets/common/action_mixins/permission_aware.dart | 7 ++++--- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c6a6d10a..383c81cc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ All notable changes to this project will be documented in this file. - photo frame widget rendering in some cases - exporting large images to BMP - replacing entries during move/copy +- deleting binned item from the Download album ## [v1.6.13] - 2022-08-29 diff --git a/android/app/src/main/kotlin/deckers/thibault/aves/utils/PermissionManager.kt b/android/app/src/main/kotlin/deckers/thibault/aves/utils/PermissionManager.kt index 4491eec38..2d78f9a52 100644 --- a/android/app/src/main/kotlin/deckers/thibault/aves/utils/PermissionManager.kt +++ b/android/app/src/main/kotlin/deckers/thibault/aves/utils/PermissionManager.kt @@ -171,6 +171,7 @@ object PermissionManager { // returns paths accessible to the app (granted by the user or by default) private fun getAccessibleDirs(context: Context): Set { val accessibleDirs = HashSet(getGrantedDirs(context)) + accessibleDirs.addAll(context.getExternalFilesDirs(null).filterNotNull().map { it.path }) // until API 18 / Android 4.3 / Jelly Bean MR2, removable storage is accessible by default like primary storage // from API 19 / Android 4.4 / KitKat, removable storage requires access permission, at the file level diff --git a/lib/model/entry.dart b/lib/model/entry.dart index ee392c4b8..65443958b 100644 --- a/lib/model/entry.dart +++ b/lib/model/entry.dart @@ -213,9 +213,13 @@ class AvesEntry { return _extension; } + String? get storagePath => trashed ? trashDetails?.path : path; + + String? get storageDirectory => trashed ? pContext.dirname(trashDetails!.path) : directory; + bool get isMissingAtPath { - final effectivePath = trashed ? trashDetails?.path : path; - return effectivePath != null && !File(effectivePath).existsSync(); + final _storagePath = storagePath; + return _storagePath != null && !File(_storagePath).existsSync(); } // the MIME type reported by the Media Store is unreliable diff --git a/lib/widgets/collection/entry_set_action_delegate.dart b/lib/widgets/collection/entry_set_action_delegate.dart index fe0647d09..c21691f17 100644 --- a/lib/widgets/collection/entry_set_action_delegate.dart +++ b/lib/widgets/collection/entry_set_action_delegate.dart @@ -275,7 +275,7 @@ class EntrySetActionDelegate with FeedbackMixin, PermissionAwareMixin, SizeAware final l10n = context.l10n; final source = context.read(); - final selectionDirs = entries.map((e) => e.directory).whereNotNull().toSet(); + final storageDirs = entries.map((e) => e.storageDirectory).whereNotNull().toSet(); final todoCount = entries.length; if (!await showConfirmationDialog( @@ -285,7 +285,7 @@ class EntrySetActionDelegate with FeedbackMixin, PermissionAwareMixin, SizeAware confirmationButtonLabel: l10n.deleteButtonLabel, )) return; - if (!pureTrash && !await checkStoragePermissionForAlbums(context, selectionDirs, entries: entries)) return; + if (!await checkStoragePermissionForAlbums(context, storageDirs, entries: entries)) return; source.pauseMonitoring(); final opId = mediaEditService.newOpId; @@ -308,7 +308,7 @@ class EntrySetActionDelegate with FeedbackMixin, PermissionAwareMixin, SizeAware } // cleanup - await storageService.deleteEmptyDirectories(selectionDirs); + await storageService.deleteEmptyDirectories(storageDirs); }, ); diff --git a/lib/widgets/common/action_mixins/permission_aware.dart b/lib/widgets/common/action_mixins/permission_aware.dart index 00fab72e0..61a8a918b 100644 --- a/lib/widgets/common/action_mixins/permission_aware.dart +++ b/lib/widgets/common/action_mixins/permission_aware.dart @@ -8,13 +8,14 @@ import 'package:flutter/material.dart'; mixin PermissionAwareMixin { Future checkStoragePermission(BuildContext context, Set entries) { - return checkStoragePermissionForAlbums(context, entries.map((e) => e.directory).whereNotNull().toSet(), entries: entries); + final storageDirs = entries.map((e) => e.storageDirectory).whereNotNull().toSet(); + return checkStoragePermissionForAlbums(context, storageDirs, entries: entries); } - Future checkStoragePermissionForAlbums(BuildContext context, Set albumPaths, {Set? entries}) async { + Future checkStoragePermissionForAlbums(BuildContext context, Set storageDirs, {Set? entries}) async { final restrictedDirs = await storageService.getRestrictedDirectories(); while (true) { - final dirs = await storageService.getInaccessibleDirectories(albumPaths); + final dirs = await storageService.getInaccessibleDirectories(storageDirs); final restrictedInaccessibleDirs = dirs.where(restrictedDirs.contains).toSet(); if (restrictedInaccessibleDirs.isNotEmpty) {