media store monitoring: fixed external removal
This commit is contained in:
parent
accfb2c57b
commit
c05b646ddd
7 changed files with 19 additions and 17 deletions
|
@ -95,7 +95,6 @@ object PermissionManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.d(LOG_TAG, "getInaccessibleDirectories dirPaths=$dirPaths -> inaccessibleDirs=$inaccessibleDirs")
|
|
||||||
return inaccessibleDirs
|
return inaccessibleDirs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +123,6 @@ object PermissionManager {
|
||||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) {
|
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) {
|
||||||
accessibleDirs.add(StorageUtils.getPrimaryVolumePath(context))
|
accessibleDirs.add(StorageUtils.getPrimaryVolumePath(context))
|
||||||
}
|
}
|
||||||
Log.d(LOG_TAG, "getAccessibleDirs accessibleDirs=$accessibleDirs")
|
|
||||||
return accessibleDirs
|
return accessibleDirs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,7 +46,7 @@ class CollectionLens with ChangeNotifier, CollectionActivityMixin, CollectionSel
|
||||||
_subscriptions.add(source.eventBus.on<EntryMovedEvent>().listen((e) => _refresh()));
|
_subscriptions.add(source.eventBus.on<EntryMovedEvent>().listen((e) => _refresh()));
|
||||||
_subscriptions.add(source.eventBus.on<CatalogMetadataChangedEvent>().listen((e) => _refresh()));
|
_subscriptions.add(source.eventBus.on<CatalogMetadataChangedEvent>().listen((e) => _refresh()));
|
||||||
_subscriptions.add(source.eventBus.on<AddressMetadataChangedEvent>().listen((e) {
|
_subscriptions.add(source.eventBus.on<AddressMetadataChangedEvent>().listen((e) {
|
||||||
if (filters.any((filter) => filter is LocationFilter)) {
|
if (this.filters.any((filter) => filter is LocationFilter)) {
|
||||||
_refresh();
|
_refresh();
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -71,7 +71,8 @@ abstract class CollectionSource with SourceBase, AlbumMixin, LocationMixin, TagM
|
||||||
eventBus.fire(EntryAddedEvent());
|
eventBus.fire(EntryAddedEvent());
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeEntries(List<AvesEntry> entries) {
|
void removeEntries(Set<AvesEntry> entries) {
|
||||||
|
if (entries.isEmpty) return;
|
||||||
entries.forEach((entry) => entry.removeFromFavourites());
|
entries.forEach((entry) => entry.removeFromFavourites());
|
||||||
_rawEntries.removeWhere(entries.contains);
|
_rawEntries.removeWhere(entries.contains);
|
||||||
cleanEmptyAlbums(entries.map((entry) => entry.directory).toSet());
|
cleanEmptyAlbums(entries.map((entry) => entry.directory).toSet());
|
||||||
|
|
|
@ -123,8 +123,9 @@ class MediaStoreSource extends CollectionSource {
|
||||||
|
|
||||||
// clean up obsolete entries
|
// clean up obsolete entries
|
||||||
final obsoleteContentIds = (await ImageFileService.getObsoleteEntries(uriByContentId.keys.toList())).toSet();
|
final obsoleteContentIds = (await ImageFileService.getObsoleteEntries(uriByContentId.keys.toList())).toSet();
|
||||||
uriByContentId.removeWhere((contentId, _) => obsoleteContentIds.contains(contentId));
|
obsoleteContentIds.forEach(uriByContentId.remove);
|
||||||
metadataDb.removeIds(obsoleteContentIds, updateFavourites: true);
|
final obsoleteEntries = rawEntries.where((e) => obsoleteContentIds.contains(e.contentId)).toSet();
|
||||||
|
removeEntries(obsoleteEntries);
|
||||||
|
|
||||||
// fetch new entries
|
// fetch new entries
|
||||||
final newEntries = <AvesEntry>[];
|
final newEntries = <AvesEntry>[];
|
||||||
|
@ -132,14 +133,16 @@ class MediaStoreSource extends CollectionSource {
|
||||||
final contentId = kv.key;
|
final contentId = kv.key;
|
||||||
final uri = kv.value;
|
final uri = kv.value;
|
||||||
final sourceEntry = await ImageFileService.getEntry(uri, null);
|
final sourceEntry = await ImageFileService.getEntry(uri, null);
|
||||||
final existingEntry = rawEntries.firstWhere((entry) => entry.contentId == contentId, orElse: () => null);
|
if (sourceEntry != null) {
|
||||||
if (existingEntry == null || sourceEntry.dateModifiedSecs > existingEntry.dateModifiedSecs) {
|
final existingEntry = rawEntries.firstWhere((entry) => entry.contentId == contentId, orElse: () => null);
|
||||||
final volume = androidFileUtils.getStorageVolume(sourceEntry.path);
|
if (existingEntry == null || sourceEntry.dateModifiedSecs > existingEntry.dateModifiedSecs) {
|
||||||
if (volume != null) {
|
final volume = androidFileUtils.getStorageVolume(sourceEntry.path);
|
||||||
newEntries.add(sourceEntry);
|
if (volume != null) {
|
||||||
} else {
|
newEntries.add(sourceEntry);
|
||||||
debugPrint('$runtimeType refreshUris entry=$sourceEntry is not located on a known storage volume. Will retry soon...');
|
} else {
|
||||||
tempUris.add(uri);
|
debugPrint('$runtimeType refreshUris entry=$sourceEntry is not located on a known storage volume. Will retry soon...');
|
||||||
|
tempUris.add(uri);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -145,7 +145,7 @@ class EntrySetActionDelegate with FeedbackMixin, PermissionAwareMixin, SizeAware
|
||||||
showFeedback(context, 'Failed to delete ${Intl.plural(count, one: '$count item', other: '$count items')}');
|
showFeedback(context, 'Failed to delete ${Intl.plural(count, one: '$count item', other: '$count items')}');
|
||||||
}
|
}
|
||||||
if (deletedCount > 0) {
|
if (deletedCount > 0) {
|
||||||
source.removeEntries(selection.where((e) => deletedUris.contains(e.uri)).toList());
|
source.removeEntries(selection.where((e) => deletedUris.contains(e.uri)).toSet());
|
||||||
}
|
}
|
||||||
collection.clearSelection();
|
collection.clearSelection();
|
||||||
collection.browse();
|
collection.browse();
|
||||||
|
|
|
@ -92,7 +92,7 @@ class AlbumChipActionDelegate extends ChipActionDelegate with FeedbackMixin, Per
|
||||||
showFeedback(context, 'Failed to delete ${Intl.plural(count, one: '$count item', other: '$count items')}');
|
showFeedback(context, 'Failed to delete ${Intl.plural(count, one: '$count item', other: '$count items')}');
|
||||||
}
|
}
|
||||||
if (deletedCount > 0) {
|
if (deletedCount > 0) {
|
||||||
source.removeEntries(selection.where((e) => deletedUris.contains(e.uri)).toList());
|
source.removeEntries(selection.where((e) => deletedUris.contains(e.uri)).toSet());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -141,7 +141,7 @@ class EntryActionDelegate with FeedbackMixin, PermissionAwareMixin, SizeAwareMix
|
||||||
showFeedback(context, 'Failed');
|
showFeedback(context, 'Failed');
|
||||||
} else {
|
} else {
|
||||||
if (hasCollection) {
|
if (hasCollection) {
|
||||||
collection.source.removeEntries([entry]);
|
collection.source.removeEntries({entry});
|
||||||
}
|
}
|
||||||
EntryDeletedNotification(entry).dispatch(context);
|
EntryDeletedNotification(entry).dispatch(context);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue