diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index ca5c9bebe..067399278 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -445,8 +445,8 @@ "@collectionActionCopy": {}, "collectionActionMove": "Move to album", "@collectionActionMove": {}, - "collectionActionRefreshMetadata": "Refresh metadata", - "@collectionActionRefreshMetadata": {}, + "collectionActionRescan": "Rescan", + "@collectionActionRescan": {}, "collectionSortTitle": "Sort", "@collectionSortTitle": {}, diff --git a/lib/l10n/app_ko.arb b/lib/l10n/app_ko.arb index c401ee7ff..7030d5d9b 100644 --- a/lib/l10n/app_ko.arb +++ b/lib/l10n/app_ko.arb @@ -213,7 +213,7 @@ "collectionActionAddShortcut": "홈 화면에 추가", "collectionActionCopy": "앨범으로 복사", "collectionActionMove": "앨범으로 이동", - "collectionActionRefreshMetadata": "새로 분석", + "collectionActionRescan": "새로 분석", "collectionSortTitle": "정렬", "collectionSortDate": "날짜", diff --git a/lib/model/actions/entry_set_actions.dart b/lib/model/actions/entry_set_actions.dart index 732c55ad6..b156e3b88 100644 --- a/lib/model/actions/entry_set_actions.dart +++ b/lib/model/actions/entry_set_actions.dart @@ -19,7 +19,7 @@ enum EntrySetAction { delete, copy, move, - refreshMetadata, + rescan, } class EntrySetActions { @@ -28,7 +28,7 @@ class EntrySetActions { EntrySetAction.delete, EntrySetAction.copy, EntrySetAction.move, - EntrySetAction.refreshMetadata, + EntrySetAction.rescan, EntrySetAction.map, EntrySetAction.stats, ]; @@ -65,8 +65,8 @@ extension ExtraEntrySetAction on EntrySetAction { return context.l10n.collectionActionCopy; case EntrySetAction.move: return context.l10n.collectionActionMove; - case EntrySetAction.refreshMetadata: - return context.l10n.collectionActionRefreshMetadata; + case EntrySetAction.rescan: + return context.l10n.collectionActionRescan; } } @@ -104,7 +104,7 @@ extension ExtraEntrySetAction on EntrySetAction { return AIcons.copy; case EntrySetAction.move: return AIcons.move; - case EntrySetAction.refreshMetadata: + case EntrySetAction.rescan: return AIcons.refresh; } } diff --git a/lib/model/entry.dart b/lib/model/entry.dart index 62122fb12..6177764b8 100644 --- a/lib/model/entry.dart +++ b/lib/model/entry.dart @@ -638,20 +638,14 @@ class AvesEntry { return true; } - Future editDate(DateModifier modifier, {required bool persist}) async { + Future editDate(DateModifier modifier) async { final newFields = await metadataEditService.editDate(this, modifier); - if (newFields.isEmpty) return false; - - await refresh(persist: persist); - return true; + return newFields.isNotEmpty; } - Future removeMetadata(Set types, {required bool persist}) async { + Future removeMetadata(Set types) async { final newFields = await metadataEditService.removeTypes(this, types); - if (newFields.isEmpty) return false; - - await refresh(persist: persist); - return true; + return newFields.isNotEmpty; } Future delete() { diff --git a/lib/model/metadata_db.dart b/lib/model/metadata_db.dart index eae41c6e0..4fb1f07a8 100644 --- a/lib/model/metadata_db.dart +++ b/lib/model/metadata_db.dart @@ -171,7 +171,7 @@ class SqfliteMetadataDb implements MetadataDb { Future removeIds(Set contentIds, {required bool metadataOnly}) async { if (contentIds.isEmpty) return; - final stopwatch = Stopwatch()..start(); + // final stopwatch = Stopwatch()..start(); final db = await _database; // using array in `whereArgs` and using it with `where contentId IN ?` is a pain, so we prefer `batch` instead final batch = db.batch(); @@ -188,7 +188,7 @@ class SqfliteMetadataDb implements MetadataDb { } }); await batch.commit(noResult: true); - debugPrint('$runtimeType removeIds complete in ${stopwatch.elapsed.inMilliseconds}ms for ${contentIds.length} entries'); + // debugPrint('$runtimeType removeIds complete in ${stopwatch.elapsed.inMilliseconds}ms for ${contentIds.length} entries'); } // entries diff --git a/lib/model/settings/settings.dart b/lib/model/settings/settings.dart index 87fa14a61..ba43111e3 100644 --- a/lib/model/settings/settings.dart +++ b/lib/model/settings/settings.dart @@ -122,7 +122,7 @@ class Settings extends ChangeNotifier { if (includeInternalKeys) { await _prefs!.clear(); } else { - await Future.forEach(_prefs!.getKeys().whereNot(internalKeys.contains), _prefs!.remove); + await Future.forEach(_prefs!.getKeys().whereNot(internalKeys.contains), _prefs!.remove); } } diff --git a/lib/model/source/collection_lens.dart b/lib/model/source/collection_lens.dart index 7ca8abac4..2bd814aa3 100644 --- a/lib/model/source/collection_lens.dart +++ b/lib/model/source/collection_lens.dart @@ -47,6 +47,7 @@ class CollectionLens with ChangeNotifier { _subscriptions.add(sourceEvents.on().listen((e) => onEntryAdded(e.entries))); _subscriptions.add(sourceEvents.on().listen((e) => onEntryRemoved(e.entries))); _subscriptions.add(sourceEvents.on().listen((e) => _refresh())); + _subscriptions.add(sourceEvents.on().listen((e) => _refresh())); _subscriptions.add(sourceEvents.on().listen((e) => _refresh())); _subscriptions.add(sourceEvents.on().listen((e) => _refresh())); _subscriptions.add(sourceEvents.on().listen((e) { diff --git a/lib/model/source/collection_source.dart b/lib/model/source/collection_source.dart index 78672a7a1..2a8579a02 100644 --- a/lib/model/source/collection_source.dart +++ b/lib/model/source/collection_source.dart @@ -254,7 +254,17 @@ abstract class CollectionSource with SourceBase, AlbumMixin, LocationMixin, TagM Future refresh(); - Future refreshMetadata(Set entries); + Future rescan(Set entries); + + Future refreshMetadata(Set entries) async { + await Future.forEach(entries, (entry) => entry.refresh(persist: true)); + + _invalidate(entries); + updateLocations(); + updateTags(); + + eventBus.fire(EntryRefreshedEvent(entries)); + } // monitoring @@ -334,6 +344,12 @@ class EntryMovedEvent { const EntryMovedEvent(this.entries); } +class EntryRefreshedEvent { + final Set entries; + + const EntryRefreshedEvent(this.entries); +} + class FilterVisibilityChangedEvent { final Set filters; final bool visible; diff --git a/lib/model/source/media_store_source.dart b/lib/model/source/media_store_source.dart index 8aa4ccee0..13e1d3955 100644 --- a/lib/model/source/media_store_source.dart +++ b/lib/model/source/media_store_source.dart @@ -189,9 +189,9 @@ class MediaStoreSource extends CollectionSource { } @override - Future refreshMetadata(Set entries) { + Future rescan(Set entries) async { final contentIds = entries.map((entry) => entry.contentId).whereNotNull().toSet(); - metadataDb.removeIds(contentIds, metadataOnly: true); + await metadataDb.removeIds(contentIds, metadataOnly: true); return refresh(); } } diff --git a/lib/widgets/collection/app_bar.dart b/lib/widgets/collection/app_bar.dart index 9ee8527c5..fa9f6381d 100644 --- a/lib/widgets/collection/app_bar.dart +++ b/lib/widgets/collection/app_bar.dart @@ -289,7 +289,7 @@ class _CollectionAppBarState extends State with SingleTickerPr case EntrySetAction.delete: case EntrySetAction.copy: case EntrySetAction.move: - case EntrySetAction.refreshMetadata: + case EntrySetAction.rescan: case EntrySetAction.map: case EntrySetAction.stats: _actionDelegate.onActionSelected(context, action); diff --git a/lib/widgets/collection/entry_set_action_delegate.dart b/lib/widgets/collection/entry_set_action_delegate.dart index 968d67f80..7fb7d2d67 100644 --- a/lib/widgets/collection/entry_set_action_delegate.dart +++ b/lib/widgets/collection/entry_set_action_delegate.dart @@ -42,8 +42,8 @@ class EntrySetActionDelegate with FeedbackMixin, PermissionAwareMixin, SizeAware case EntrySetAction.move: _moveSelection(context, moveType: MoveType.move); break; - case EntrySetAction.refreshMetadata: - _refreshMetadata(context); + case EntrySetAction.rescan: + _rescan(context); break; case EntrySetAction.map: _goToMap(context); @@ -68,12 +68,12 @@ class EntrySetActionDelegate with FeedbackMixin, PermissionAwareMixin, SizeAware }); } - void _refreshMetadata(BuildContext context) { + void _rescan(BuildContext context) { final source = context.read(); final selection = context.read>(); final selectedItems = _getExpandedSelectedItems(selection); - source.refreshMetadata(selectedItems); + source.rescan(selectedItems); selection.browse(); } diff --git a/lib/widgets/viewer/info/entry_info_action_delegate.dart b/lib/widgets/viewer/info/entry_info_action_delegate.dart index 0f6c8b2a1..b3185bbb8 100644 --- a/lib/widgets/viewer/info/entry_info_action_delegate.dart +++ b/lib/widgets/viewer/info/entry_info_action_delegate.dart @@ -34,13 +34,19 @@ class EntryInfoActionDelegate with FeedbackMixin, PermissionAwareMixin { Future _edit(BuildContext context, Future Function() apply) async { if (!await checkStoragePermission(context, {entry})) return; + final l10n = context.l10n; final source = context.read(); source?.pauseMonitoring(); final success = await apply(); if (success) { - showFeedback(context, context.l10n.genericSuccessFeedback); + if (_isMainMode(context) && source != null) { + await source.refreshMetadata({entry}); + } else { + await entry.refresh(persist: false); + } + showFeedback(context, l10n.genericSuccessFeedback); } else { - showFeedback(context, context.l10n.genericFailureFeedback); + showFeedback(context, l10n.genericFailureFeedback); } source?.resumeMonitoring(); } @@ -52,7 +58,7 @@ class EntryInfoActionDelegate with FeedbackMixin, PermissionAwareMixin { ); if (modifier == null) return; - await _edit(context, () => entry.editDate(modifier, persist: _isMainMode(context))); + await _edit(context, () => entry.editDate(modifier)); } Future _showMetadataRemovalDialog(BuildContext context) async { @@ -85,6 +91,6 @@ class EntryInfoActionDelegate with FeedbackMixin, PermissionAwareMixin { if (proceed == null || !proceed) return; } - await _edit(context, () => entry.removeMetadata(types, persist: _isMainMode(context))); + await _edit(context, () => entry.removeMetadata(types)); } }