Skip to content

Commit

Permalink
#888 viewer: prompt to show newly edited item
Browse files Browse the repository at this point in the history
  • Loading branch information
deckerst committed Feb 11, 2024
1 parent 28f7819 commit a575fec
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.

### Added

- Viewer: prompt to show newly edited item
- Catalan translation (thanks Marc Amorós)

## <a id="v1.10.4"></a>[v1.10.4] - 2024-02-07
Expand Down
48 changes: 42 additions & 6 deletions lib/widgets/viewer/action/entry_action_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:aves/model/source/collection_source.dart';
import 'package:aves/model/vaults/vaults.dart';
import 'package:aves/services/common/services.dart';
import 'package:aves/theme/durations.dart';
import 'package:aves/widgets/collection/collection_page.dart';
import 'package:aves/widgets/common/action_mixins/entry_storage.dart';
import 'package:aves/widgets/common/action_mixins/feedback.dart';
import 'package:aves/widgets/common/action_mixins/permission_aware.dart';
Expand Down Expand Up @@ -242,15 +243,14 @@ class EntryActionDelegate with FeedbackMixin, PermissionAwareMixin, SizeAwareMix
).dispatch(context);
}
case EntryAction.edit:
appService.edit(targetEntry.uri, targetEntry.mimeType).then((fields) {
appService.edit(targetEntry.uri, targetEntry.mimeType).then((fields) async {
final error = fields['error'] as String?;
if (error == null) {
final uri = fields['uri'] as String?;
if (uri != null) {
debugPrint('TLAD uri=$uri');
}
final resultUri = fields['uri'] as String?;
final mimeType = fields['mimeType'] as String?;
await _handleEditResult(context, resultUri, mimeType);
} else if (error == 'edit-resolve') {
showNoMatchingAppDialog(context);
await showNoMatchingAppDialog(context);
}
});
case EntryAction.open:
Expand Down Expand Up @@ -288,6 +288,42 @@ class EntryActionDelegate with FeedbackMixin, PermissionAwareMixin, SizeAwareMix
}
}

Future<void> _handleEditResult(BuildContext context, String? resultUri, String? mimeType) async {
final _collection = collection;
if (_collection == null || resultUri == null) return;

final editedEntry = await mediaFetchService.getEntry(resultUri, mimeType);
if (editedEntry == null) return;

final editedUri = editedEntry.uri;
final matchCurrentFilters = _collection.filters.every((filter) => filter.test(editedEntry));

final l10n = context.l10n;
// get navigator beforehand because
// local context may be deactivated when action is triggered after navigation
final navigator = Navigator.maybeOf(context);
final showAction = SnackBarAction(
label: l10n.showButtonLabel,
onPressed: () {
if (navigator != null) {
final source = _collection.source;
navigator.pushAndRemoveUntil(
MaterialPageRoute(
settings: const RouteSettings(name: CollectionPage.routeName),
builder: (context) => CollectionPage(
source: source,
filters: matchCurrentFilters ? _collection.filters : {},
highlightTest: (entry) => entry.uri == editedUri,
),
),
(route) => false,
);
}
},
);
showFeedback(context, FeedbackType.info, l10n.genericSuccessFeedback, showAction);
}

Future<void> quickMove(BuildContext context, String album, {required bool copy}) async {
if (!await unlockAlbum(context, album)) return;

Expand Down

0 comments on commit a575fec

Please sign in to comment.