summaryrefslogtreecommitdiff
path: root/lib/widgets/dialogs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/widgets/dialogs')
-rw-r--r--lib/widgets/dialogs/add_shortcut_dialog.dart149
-rw-r--r--lib/widgets/dialogs/aves_confirmation_dialog.dart158
-rw-r--r--lib/widgets/dialogs/aves_dialog.dart185
-rw-r--r--lib/widgets/dialogs/cast_dialog.dart63
-rw-r--r--lib/widgets/dialogs/convert_entry_dialog.dart374
-rw-r--r--lib/widgets/dialogs/duration_dialog.dart123
-rw-r--r--lib/widgets/dialogs/entry_editors/edit_date_dialog.dart332
-rw-r--r--lib/widgets/dialogs/entry_editors/edit_description_dialog.dart116
-rw-r--r--lib/widgets/dialogs/entry_editors/edit_location_dialog.dart629
-rw-r--r--lib/widgets/dialogs/entry_editors/edit_rating_dialog.dart133
-rw-r--r--lib/widgets/dialogs/entry_editors/remove_metadata_dialog.dart158
-rw-r--r--lib/widgets/dialogs/entry_editors/rename_entry_dialog.dart105
-rw-r--r--lib/widgets/dialogs/entry_editors/rename_entry_set_page.dart256
-rw-r--r--lib/widgets/dialogs/entry_editors/tag_editor_page.dart379
-rw-r--r--lib/widgets/dialogs/filter_editors/cover_selection_dialog.dart458
-rw-r--r--lib/widgets/dialogs/filter_editors/create_dynamic_album_dialog.dart92
-rw-r--r--lib/widgets/dialogs/filter_editors/create_group_dialog.dart99
-rw-r--r--lib/widgets/dialogs/filter_editors/create_stored_album_dialog.dart204
-rw-r--r--lib/widgets/dialogs/filter_editors/edit_vault_dialog.dart189
-rw-r--r--lib/widgets/dialogs/filter_editors/password_dialog.dart85
-rw-r--r--lib/widgets/dialogs/filter_editors/pattern_dialog.dart74
-rw-r--r--lib/widgets/dialogs/filter_editors/pin_dialog.dart91
-rw-r--r--lib/widgets/dialogs/filter_editors/rename_dynamic_album_dialog.dart93
-rw-r--r--lib/widgets/dialogs/filter_editors/rename_group_dialog.dart101
-rw-r--r--lib/widgets/dialogs/filter_editors/rename_stored_album_dialog.dart96
-rw-r--r--lib/widgets/dialogs/item_picker.dart74
-rw-r--r--lib/widgets/dialogs/map/style_editor_dialog.dart146
-rw-r--r--lib/widgets/dialogs/map/style_selection_dialog.dart185
-rw-r--r--lib/widgets/dialogs/pick_dialogs/album_pick_page.dart387
-rw-r--r--lib/widgets/dialogs/pick_dialogs/app_pick_page.dart155
-rw-r--r--lib/widgets/dialogs/pick_dialogs/item_pick_page.dart74
-rw-r--r--lib/widgets/dialogs/pick_dialogs/location_pick_page.dart342
-rw-r--r--lib/widgets/dialogs/pick_dialogs/tag_pick_page.dart314
-rw-r--r--lib/widgets/dialogs/select_storage_dialog.dart75
-rw-r--r--lib/widgets/dialogs/selection_dialogs/common.dart23
-rw-r--r--lib/widgets/dialogs/selection_dialogs/multi_selection.dart91
-rw-r--r--lib/widgets/dialogs/selection_dialogs/radio_list_tile.dart61
-rw-r--r--lib/widgets/dialogs/selection_dialogs/single_selection.dart82
-rw-r--r--lib/widgets/dialogs/tile_view_dialog.dart264
-rw-r--r--lib/widgets/dialogs/time_shift_dialog.dart52
-rw-r--r--lib/widgets/dialogs/video_speed_dialog.dart76
-rw-r--r--lib/widgets/dialogs/video_stream_selection_dialog.dart164
-rw-r--r--lib/widgets/dialogs/wallpaper_settings_dialog.dart51
43 files changed, 7358 insertions, 0 deletions
diff --git a/lib/widgets/dialogs/add_shortcut_dialog.dart b/lib/widgets/dialogs/add_shortcut_dialog.dart
new file mode 100644
index 0000000..0154b44
--- /dev/null
+++ b/lib/widgets/dialogs/add_shortcut_dialog.dart
@@ -0,0 +1,149 @@
+import 'package:aves/model/covers.dart';
+import 'package:aves/model/entry/entry.dart';
+import 'package:aves/model/filters/query.dart';
+import 'package:aves/model/source/collection_lens.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/common/providers/media_query_data_provider.dart';
+import 'package:aves/widgets/dialogs/item_picker.dart';
+import 'package:aves/widgets/dialogs/pick_dialogs/item_pick_page.dart';
+import 'package:collection/collection.dart';
+import 'package:flutter/material.dart';
+
+import 'aves_dialog.dart';
+
+class AddShortcutDialog extends StatefulWidget {
+ static const routeName = '/dialog/add_shortcut';
+
+ final CollectionLens? collection;
+ final String defaultName;
+
+ const AddShortcutDialog({
+ super.key,
+ required this.defaultName,
+ this.collection,
+ });
+
+ @override
+ State<AddShortcutDialog> createState() => _AddShortcutDialogState();
+}
+
+class _AddShortcutDialogState extends State<AddShortcutDialog> {
+ final TextEditingController _nameController = TextEditingController();
+ final ValueNotifier<bool> _isValidNotifier = ValueNotifier(false);
+ AvesEntry? _coverEntry;
+
+ @override
+ void initState() {
+ super.initState();
+ final _collection = widget.collection;
+ if (_collection != null) {
+ final entries = _collection.sortedEntries;
+ if (entries.isNotEmpty) {
+ final coverEntries = _collection.filters.map((filter) => covers.of(filter)?.$1).nonNulls.map((id) => entries.firstWhereOrNull((entry) => entry.id == id)).nonNulls;
+ _coverEntry = coverEntries.firstOrNull ?? entries.first;
+ }
+ }
+ _nameController.text = widget.defaultName;
+ _validate();
+ }
+
+ @override
+ void dispose() {
+ _nameController.dispose();
+ _isValidNotifier.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return MediaQueryDataProvider(
+ child: Builder(
+ builder: (context) {
+ final shortestSide = MediaQuery.sizeOf(context).shortestSide;
+ final extent = (shortestSide / 3.0).clamp(60.0, 160.0);
+ return AvesDialog(
+ scrollableContent: [
+ if (_coverEntry != null)
+ Container(
+ alignment: Alignment.center,
+ padding: const EdgeInsets.only(top: 16),
+ child: ItemPicker(
+ extent: extent,
+ entry: _coverEntry!,
+ onTap: _pickEntry,
+ ),
+ ),
+ Padding(
+ padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 24),
+ child: TextField(
+ controller: _nameController,
+ decoration: InputDecoration(
+ labelText: context.l10n.addShortcutDialogLabel,
+ ),
+ autofocus: true,
+ maxLength: 25,
+ onChanged: (_) => _validate(),
+ onSubmitted: (_) => _submit(context),
+ ),
+ ),
+ ],
+ actions: [
+ const CancelButton(),
+ ValueListenableBuilder<bool>(
+ valueListenable: _isValidNotifier,
+ builder: (context, isValid, child) {
+ return TextButton(
+ onPressed: isValid ? () => _submit(context) : null,
+ child: Text(context.l10n.addShortcutButtonLabel),
+ );
+ },
+ )
+ ],
+ );
+ },
+ ),
+ );
+ }
+
+ Future<void> _pickEntry() async {
+ final _collection = widget.collection;
+ if (_collection == null) return;
+
+ final entry = await Navigator.maybeOf(context)?.push<AvesEntry>(
+ MaterialPageRoute(
+ settings: const RouteSettings(name: ItemPickPage.routeName),
+ builder: (context) {
+ final pickFilters = _collection.filters.toSet();
+ final liveFilters = pickFilters.whereType<QueryFilter>().where((v) => v.live).toSet();
+ liveFilters.forEach((filter) {
+ pickFilters.remove(filter);
+ pickFilters.add(QueryFilter(filter.query));
+ });
+ return ItemPickPage(
+ collection: CollectionLens(
+ source: _collection.source,
+ filters: pickFilters,
+ ),
+ canRemoveFilters: false,
+ );
+ },
+ fullscreenDialog: true,
+ ),
+ );
+ if (entry != null) {
+ _coverEntry = entry;
+ setState(() {});
+ }
+ }
+
+ Future<void> _validate() async {
+ final name = _nameController.text;
+ _isValidNotifier.value = name.isNotEmpty;
+ }
+
+ void _submit(BuildContext context) {
+ if (_isValidNotifier.value) {
+ Navigator.maybeOf(context)?.pop<(AvesEntry?, String)>((_coverEntry, _nameController.text));
+ }
+ }
+}
diff --git a/lib/widgets/dialogs/aves_confirmation_dialog.dart b/lib/widgets/dialogs/aves_confirmation_dialog.dart
new file mode 100644
index 0000000..6e1a61a
--- /dev/null
+++ b/lib/widgets/dialogs/aves_confirmation_dialog.dart
@@ -0,0 +1,158 @@
+import 'package:aves/model/settings/settings.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves_model/aves_model.dart';
+import 'package:flutter/material.dart';
+
+import 'aves_dialog.dart';
+
+Future<bool> showConfirmationDialog({
+ required BuildContext context,
+ required String message,
+ required String confirmationButtonLabel,
+}) async {
+ final confirmed = await showDialog<bool>(
+ context: context,
+ builder: (context) => AvesDialog(
+ content: Text(message),
+ actions: [
+ const CancelButton(),
+ TextButton(
+ onPressed: () => Navigator.maybeOf(context)?.pop(true),
+ child: Text(confirmationButtonLabel),
+ ),
+ ],
+ ),
+ routeSettings: const RouteSettings(name: AvesDialog.confirmationRouteName),
+ );
+ return confirmed ?? false;
+}
+
+Future<bool> showSkippableConfirmationDialog({
+ required BuildContext context,
+ required ConfirmationDialog type,
+ String? message,
+ ConfirmationDialogDelegate? delegate,
+ required String confirmationButtonLabel,
+}) async {
+ if (!_shouldConfirm(type)) return true;
+
+ assert((message != null) ^ (delegate != null));
+ final effectiveDelegate = delegate ?? MessageConfirmationDialogDelegate(message!);
+ final confirmed = await showDialog<bool>(
+ context: context,
+ builder: (context) => _SkippableConfirmationDialog(
+ type: type,
+ delegate: effectiveDelegate,
+ confirmationButtonLabel: confirmationButtonLabel,
+ ),
+ routeSettings: const RouteSettings(name: _SkippableConfirmationDialog.routeName),
+ );
+ if (confirmed == null) return false;
+
+ if (confirmed) {
+ effectiveDelegate.apply();
+ }
+ return confirmed;
+}
+
+bool _shouldConfirm(ConfirmationDialog type) {
+ switch (type) {
+ case ConfirmationDialog.createVault:
+ return settings.confirmCreateVault;
+ case ConfirmationDialog.deleteForever:
+ return settings.confirmDeleteForever;
+ case ConfirmationDialog.moveToBin:
+ return settings.confirmMoveToBin;
+ case ConfirmationDialog.moveUndatedItems:
+ return settings.confirmMoveUndatedItems;
+ }
+}
+
+void _skipConfirmation(ConfirmationDialog type) {
+ switch (type) {
+ case ConfirmationDialog.createVault:
+ settings.confirmCreateVault = false;
+ case ConfirmationDialog.deleteForever:
+ settings.confirmDeleteForever = false;
+ case ConfirmationDialog.moveToBin:
+ settings.confirmMoveToBin = false;
+ case ConfirmationDialog.moveUndatedItems:
+ settings.confirmMoveUndatedItems = false;
+ }
+}
+
+abstract class ConfirmationDialogDelegate {
+ List<Widget> build(BuildContext context);
+
+ void apply() {}
+}
+
+class MessageConfirmationDialogDelegate extends ConfirmationDialogDelegate {
+ final String message;
+
+ MessageConfirmationDialogDelegate(this.message);
+
+ @override
+ List<Widget> build(BuildContext context) => [
+ Padding(
+ padding: const EdgeInsets.all(16) + const EdgeInsets.only(top: 8),
+ child: Text(message),
+ ),
+ ];
+}
+
+class _SkippableConfirmationDialog extends StatefulWidget {
+ static const routeName = '/dialog/skippable_confirmation';
+
+ final ConfirmationDialog type;
+ final ConfirmationDialogDelegate delegate;
+ final String confirmationButtonLabel;
+
+ const _SkippableConfirmationDialog({
+ required this.type,
+ required this.delegate,
+ required this.confirmationButtonLabel,
+ });
+
+ @override
+ State<_SkippableConfirmationDialog> createState() => _SkippableConfirmationDialogState();
+}
+
+class _SkippableConfirmationDialogState extends State<_SkippableConfirmationDialog> {
+ final ValueNotifier<bool> _skipNotifier = ValueNotifier(false);
+
+ @override
+ void dispose() {
+ _skipNotifier.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return AvesDialog(
+ scrollableContent: [
+ ...widget.delegate.build(context),
+ ValueListenableBuilder<bool>(
+ valueListenable: _skipNotifier,
+ builder: (context, flag, child) => SwitchListTile(
+ value: flag,
+ onChanged: (v) => _skipNotifier.value = v,
+ title: Text(context.l10n.doNotAskAgain),
+ ),
+ ),
+ ],
+ actions: [
+ const CancelButton(),
+ TextButton(
+ onPressed: () {
+ if (_skipNotifier.value) {
+ _skipConfirmation(widget.type);
+ }
+ Navigator.maybeOf(context)?.pop(true);
+ },
+ child: Text(widget.confirmationButtonLabel),
+ ),
+ ],
+ );
+ }
+}
diff --git a/lib/widgets/dialogs/aves_dialog.dart b/lib/widgets/dialogs/aves_dialog.dart
new file mode 100644
index 0000000..924f961
--- /dev/null
+++ b/lib/widgets/dialogs/aves_dialog.dart
@@ -0,0 +1,185 @@
+import 'package:aves/model/settings/settings.dart';
+import 'package:aves/theme/themes.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:flutter/material.dart';
+
+class AvesDialog extends StatelessWidget {
+ static const confirmationRouteName = '/dialog/confirmation';
+ static const warningRouteName = '/dialog/warning';
+
+ final String? title;
+ final ScrollController scrollController;
+ final List<Widget>? scrollableContent;
+ final double horizontalContentPadding;
+ final Widget? content;
+ final List<Widget> actions;
+
+ static const Radius cornerRadius = Radius.circular(24);
+ static const double defaultHorizontalContentPadding = 24;
+ static const double controlCaptionPadding = 16;
+ static const double borderWidth = 1.0;
+ static const EdgeInsets actionsPadding = EdgeInsets.symmetric(vertical: 4, horizontal: 16);
+ static const EdgeInsets buttonPadding = EdgeInsets.symmetric(horizontal: 8);
+
+ AvesDialog({
+ super.key,
+ this.title,
+ ScrollController? scrollController,
+ this.scrollableContent,
+ this.horizontalContentPadding = defaultHorizontalContentPadding,
+ this.content,
+ this.actions = const [],
+ }) : assert((scrollableContent != null) ^ (content != null)),
+ scrollController = scrollController ?? ScrollController();
+
+ @override
+ Widget build(BuildContext context) {
+ return AlertDialog(
+ title: title != null
+ ? Padding(
+ // padding to avoid transparent border overlapping
+ padding: const EdgeInsets.symmetric(horizontal: borderWidth),
+ child: DialogTitle(title: title!),
+ )
+ : null,
+ titlePadding: EdgeInsets.zero,
+ // the `scrollable` flag of `AlertDialog` makes it
+ // scroll both the title and the content together,
+ // and overflow feedback ignores the dialog shape,
+ // so we restrict scrolling to the content instead
+ content: _buildContent(context),
+ contentPadding: scrollableContent != null ? EdgeInsets.zero : EdgeInsets.only(left: horizontalContentPadding, top: 20, right: horizontalContentPadding),
+ actions: actions,
+ actionsPadding: actionsPadding,
+ buttonPadding: buttonPadding,
+ // clipping to prevent highlighted material to bleed through rounded corners
+ clipBehavior: Clip.antiAlias,
+ shape: shape(context),
+ );
+ }
+
+ Widget _buildContent(BuildContext context) {
+ if (content != null) {
+ return content!;
+ }
+
+ if (scrollableContent != null) {
+ Widget child = ListView(
+ controller: scrollController,
+ shrinkWrap: true,
+ children: scrollableContent!,
+ );
+
+ if (!settings.useTvLayout) {
+ child = Theme(
+ data: Theme.of(context).copyWith(
+ scrollbarTheme: ScrollbarThemeData(
+ thumbVisibility: WidgetStateProperty.all(true),
+ radius: const Radius.circular(16),
+ crossAxisMargin: 4,
+ // adapt margin when corner is around content itself, not outside for the title
+ mainAxisMargin: 4 + (title != null ? 0 : cornerRadius.y / 2),
+ interactive: true,
+ ),
+ ),
+ child: Scrollbar(
+ controller: scrollController,
+ notificationPredicate: (notification) {
+ // as of Flutter v3.0.1, the `Scrollbar` does not only respond to the nearest `ScrollView`
+ // despite the `defaultScrollNotificationPredicate` checking notification depth,
+ // as the notifications coming from the controller in `ListWheelScrollView` in `WheelSelector` still have a depth of 0.
+ // Cancelling notification bubbling seems ineffective, so we check the metrics type as a workaround.
+ return defaultScrollNotificationPredicate(notification) && notification.metrics is! FixedExtentMetrics;
+ },
+ child: child,
+ ),
+ );
+ }
+
+ return Container(
+ // padding to avoid transparent border overlapping
+ padding: const EdgeInsets.symmetric(horizontal: borderWidth),
+ // workaround because the dialog tries
+ // to size itself to the content intrinsic size,
+ // but the `ListView` viewport does not have one
+ width: MediaQuery.sizeOf(context).width / 2,
+ child: DecoratedBox(
+ decoration: contentDecoration(context),
+ child: child,
+ ),
+ );
+ }
+
+ return const SizedBox();
+ }
+
+ static Decoration contentDecoration(BuildContext context) => BoxDecoration(
+ border: Border(
+ bottom: Divider.createBorderSide(context, width: borderWidth),
+ ),
+ );
+
+ static ShapeBorder shape(BuildContext context) {
+ return RoundedRectangleBorder(
+ side: Divider.createBorderSide(context, width: borderWidth),
+ borderRadius: const BorderRadius.all(cornerRadius),
+ );
+ }
+}
+
+class DialogTitle extends StatelessWidget {
+ final String title;
+
+ const DialogTitle({
+ super.key,
+ required this.title,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ return Container(
+ alignment: Alignment.center,
+ padding: const EdgeInsets.symmetric(vertical: 18, horizontal: 16),
+ decoration: AvesDialog.contentDecoration(context),
+ child: Text(
+ title,
+ textAlign: TextAlign.center,
+ ),
+ );
+ }
+}
+
+Future<void> showNoMatchingAppDialog(BuildContext context) => showDialog(
+ context: context,
+ builder: (context) => AvesDialog(
+ content: Text(context.l10n.noMatchingAppDialogMessage),
+ actions: const [OkButton()],
+ ),
+ routeSettings: const RouteSettings(name: AvesDialog.warningRouteName),
+ );
+
+class CancelButton extends StatelessWidget {
+ const CancelButton({super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ return TextButton(
+ onPressed: () => Navigator.maybeOf(context)?.pop(),
+ // MD2 button labels were upper case but they are lower case in MD3
+ child: Text(Themes.asButtonLabel(context.l10n.cancelTooltip)),
+ );
+ }
+}
+
+class OkButton extends StatelessWidget {
+ const OkButton({super.key});
+
+ @override
+ Widget build(BuildContext context) {
+ return TextButton(
+ onPressed: () => Navigator.maybeOf(context)?.pop(),
+ // MD2 button labels were upper case but they are lower case in MD3
+ child: Text(Themes.asButtonLabel(MaterialLocalizations.of(context).okButtonLabel)),
+ );
+ }
+}
diff --git a/lib/widgets/dialogs/cast_dialog.dart b/lib/widgets/dialogs/cast_dialog.dart
new file mode 100644
index 0000000..3b7ba60
--- /dev/null
+++ b/lib/widgets/dialogs/cast_dialog.dart
@@ -0,0 +1,63 @@
+import 'package:aves/ref/upnp.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/dialogs/aves_dialog.dart';
+import 'package:dlna_dart/dlna.dart';
+import 'package:flutter/material.dart';
+
+class CastDialog extends StatefulWidget {
+ static const routeName = '/dialog/cast';
+
+ const CastDialog({super.key});
+
+ @override
+ State<CastDialog> createState() => _CastDialogState();
+}
+
+class _CastDialogState extends State<CastDialog> {
+ final DLNAManager _dlnaManager = DLNAManager();
+ final Map<String, DLNADevice> _seenRenderers = {};
+
+ @override
+ void initState() {
+ super.initState();
+
+ _dlnaManager.start().then((deviceManager) {
+ deviceManager.devices.stream.listen((devices) {
+ _seenRenderers.addAll(Map.fromEntries(devices.entries.where((kv) => kv.value.info.deviceType == Upnp.upnpDeviceTypeMediaRenderer).map((kv) {
+ final device = kv.value;
+ return MapEntry(device.info.friendlyName, device);
+ })));
+ setState(() {});
+ });
+ });
+ }
+
+ @override
+ void dispose() {
+ _dlnaManager.stop();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return AvesDialog(
+ title: context.l10n.castDialogTitle,
+ scrollableContent: [
+ if (_seenRenderers.isEmpty)
+ const Padding(
+ padding: EdgeInsets.all(16),
+ child: Center(
+ child: CircularProgressIndicator(),
+ ),
+ ),
+ ..._seenRenderers.values.map((dev) => ListTile(
+ title: Text(dev.info.friendlyName),
+ onTap: () => Navigator.maybeOf(context)?.pop<DLNADevice>(dev),
+ )),
+ ],
+ actions: const [
+ CancelButton(),
+ ],
+ );
+ }
+}
diff --git a/lib/widgets/dialogs/convert_entry_dialog.dart b/lib/widgets/dialogs/convert_entry_dialog.dart
new file mode 100644
index 0000000..cc1974c
--- /dev/null
+++ b/lib/widgets/dialogs/convert_entry_dialog.dart
@@ -0,0 +1,374 @@
+import 'package:aves/model/app/support.dart';
+import 'package:aves/model/entry/entry.dart';
+import 'package:aves/model/entry/extensions/multipage.dart';
+import 'package:aves/model/settings/settings.dart';
+import 'package:aves/ref/mime_types.dart';
+import 'package:aves/services/media/media_edit_service.dart';
+import 'package:aves/theme/durations.dart';
+import 'package:aves/theme/text.dart';
+import 'package:aves/theme/themes.dart';
+import 'package:aves/utils/mime_utils.dart';
+import 'package:aves/view/view.dart';
+import 'package:aves/widgets/common/basic/list_tiles/slider.dart';
+import 'package:aves/widgets/common/basic/text/change_highlight.dart';
+import 'package:aves/widgets/common/basic/text_dropdown_button.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/common/fx/transitions.dart';
+import 'package:aves_model/aves_model.dart';
+import 'package:flutter/material.dart';
+import 'package:provider/provider.dart';
+
+import 'aves_dialog.dart';
+
+class ConvertEntryDialog extends StatefulWidget {
+ static const routeName = '/dialog/convert_entry';
+
+ final Set<AvesEntry> entries;
+
+ const ConvertEntryDialog({
+ super.key,
+ required this.entries,
+ });
+
+ @override
+ State<ConvertEntryDialog> createState() => _ConvertEntryDialogState();
+}
+
+class _ConvertEntryDialogState extends State<ConvertEntryDialog> {
+ late List<EntryConvertAction> _actionOptions;
+ EntryConvertAction _action = EntryConvertAction.convert;
+ final TextEditingController _widthController = TextEditingController(), _heightController = TextEditingController();
+ final ValueNotifier<bool> _isValidNotifier = ValueNotifier(false);
+ late ValueNotifier<String> _mimeTypeNotifier;
+ late int _quality;
+ late bool _writeMetadata, _sameSized;
+ late List<LengthUnit> _lengthUnitOptions;
+ late LengthUnit _lengthUnit;
+
+ Set<AvesEntry> get entries => widget.entries;
+
+ EdgeInsets get contentHorizontalPadding => const EdgeInsets.symmetric(horizontal: AvesDialog.defaultHorizontalContentPadding);
+
+ static const _imageExportFormats = [
+ MimeTypes.bmp,
+ MimeTypes.jpeg,
+ MimeTypes.png,
+ MimeTypes.webp,
+ ];
+
+ static const _qualityFormats = [
+ MimeTypes.jpeg,
+ MimeTypes.webp,
+ ];
+
+ @override
+ void initState() {
+ super.initState();
+ _actionOptions = [
+ EntryConvertAction.convert,
+ if (entries.any((entry) => entry.isMotionPhoto)) EntryConvertAction.convertMotionPhotoToStillImage,
+ ];
+ _mimeTypeNotifier = ValueNotifier(settings.convertMimeType);
+ _quality = settings.convertQuality;
+ _writeMetadata = settings.convertWriteMetadata;
+ _sameSized = entries.map((entry) => entry.displaySize).toSet().length == 1;
+ _lengthUnitOptions = [
+ if (_sameSized) LengthUnit.px,
+ LengthUnit.percent,
+ ];
+ _lengthUnit = _lengthUnitOptions.first;
+ _initDimensions();
+ _validate();
+ }
+
+ void _initDimensions() {
+ switch (_lengthUnit) {
+ case LengthUnit.px:
+ final displaySize = entries.first.displaySize;
+ _widthController.text = '${displaySize.width.round()}';
+ _heightController.text = '${displaySize.height.round()}';
+ case LengthUnit.percent:
+ _widthController.text = '100';
+ _heightController.text = '100';
+ }
+ }
+
+ @override
+ void dispose() {
+ _widthController.dispose();
+ _heightController.dispose();
+ _isValidNotifier.dispose();
+ _mimeTypeNotifier.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return AvesDialog(
+ scrollableContent: [
+ const SizedBox(height: 16),
+ if (_actionOptions.length > 1)
+ Padding(
+ padding: contentHorizontalPadding,
+ child: TextDropdownButton<EntryConvertAction>(
+ values: _actionOptions,
+ valueText: (v) => v.getText(context),
+ valueIcon: (v) => v.getIconData(),
+ value: _action,
+ onChanged: (v) {
+ _action = v!;
+ _validate();
+ setState(() {});
+ },
+ isExpanded: true,
+ dropdownColor: Themes.thirdLayerColor(context),
+ ),
+ ),
+ AnimatedSwitcher(
+ duration: context.read<DurationsData>().formTransition,
+ switchInCurve: Curves.easeInOutCubic,
+ switchOutCurve: Curves.easeInOutCubic,
+ transitionBuilder: AvesTransitions.formTransitionBuilder,
+ child: Column(
+ key: ValueKey(_action),
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ if (_action == EntryConvertAction.convert) ..._buildConvertContent(context),
+ if (_action == EntryConvertAction.convertMotionPhotoToStillImage) const SizedBox(height: 16),
+ ],
+ ),
+ ),
+ ],
+ actions: [
+ const CancelButton(),
+ ValueListenableBuilder<bool>(
+ valueListenable: _isValidNotifier,
+ builder: (context, isValid, child) {
+ return TextButton(
+ onPressed: isValid
+ ? () {
+ final width = int.tryParse(_widthController.text);
+ final height = int.tryParse(_heightController.text);
+ final options = (width != null && height != null)
+ ? EntryConvertOptions(
+ action: _action,
+ mimeType: _mimeTypeNotifier.value,
+ writeMetadata: _writeMetadata,
+ lengthUnit: _lengthUnit,
+ width: width,
+ height: height,
+ quality: _quality,
+ )
+ : null;
+
+ if (options != null) {
+ settings.convertMimeType = options.mimeType;
+ settings.convertQuality = options.quality;
+ settings.convertWriteMetadata = options.writeMetadata;
+ }
+
+ Navigator.maybeOf(context)?.pop(options);
+ }
+ : null,
+ child: Text(context.l10n.applyButtonLabel),
+ );
+ },
+ ),
+ ],
+ );
+ }
+
+ List<Widget> _buildConvertContent(BuildContext context) {
+ final l10n = context.l10n;
+ final colorScheme = Theme.of(context).colorScheme;
+ final trailingStyle = TextStyle(color: colorScheme.onSurfaceVariant);
+ final trailingChangeShadowColor = colorScheme.onSurface;
+
+ // used by the drop down to match input decoration
+ final textFieldDecorationBorder = Border(
+ bottom: BorderSide(
+ color: colorScheme.onSurface.withValues(alpha: .38),
+ width: 1.0,
+ ),
+ );
+
+ return [
+ Padding(
+ padding: contentHorizontalPadding,
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Text(l10n.exportEntryDialogFormat),
+ const SizedBox(width: AvesDialog.controlCaptionPadding),
+ TextDropdownButton<String>(
+ values: _imageExportFormats,
+ valueText: MimeUtils.displayType,
+ value: _mimeTypeNotifier.value,
+ onChanged: (selected) {
+ if (selected != null) {
+ setState(() => _mimeTypeNotifier.value = selected);
+ }
+ },
+ ),
+ ],
+ ),
+ ),
+ Padding(
+ padding: contentHorizontalPadding,
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.baseline,
+ textBaseline: TextBaseline.alphabetic,
+ children: [
+ Expanded(
+ child: TextField(
+ controller: _widthController,
+ decoration: InputDecoration(labelText: l10n.exportEntryDialogWidth),
+ keyboardType: TextInputType.number,
+ onChanged: (value) {
+ final width = int.tryParse(value);
+ if (width != null) {
+ switch (_lengthUnit) {
+ case LengthUnit.px:
+ _heightController.text = '${(width / entries.first.displayAspectRatio).round()}';
+ case LengthUnit.percent:
+ _heightController.text = '$width';
+ }
+ } else {
+ _heightController.text = '';
+ }
+ _validate();
+ },
+ ),
+ ),
+ const SizedBox(width: 8),
+ const Text(AText.resolutionSeparator),
+ const SizedBox(width: 8),
+ Expanded(
+ child: TextField(
+ controller: _heightController,
+ decoration: InputDecoration(labelText: l10n.exportEntryDialogHeight),
+ keyboardType: TextInputType.number,
+ onChanged: (value) {
+ final height = int.tryParse(value);
+ if (height != null) {
+ switch (_lengthUnit) {
+ case LengthUnit.px:
+ _widthController.text = '${(height * entries.first.displayAspectRatio).round()}';
+ case LengthUnit.percent:
+ _widthController.text = '$height';
+ }
+ } else {
+ _widthController.text = '';
+ }
+ _validate();
+ },
+ ),
+ ),
+ const SizedBox(width: 16),
+ TextDropdownButton<LengthUnit>(
+ values: _lengthUnitOptions,
+ valueText: (v) => v.getText(context),
+ value: _lengthUnit,
+ onChanged: _lengthUnitOptions.length > 1
+ ? (v) {
+ if (v != null && _lengthUnit != v) {
+ _lengthUnit = v;
+ _initDimensions();
+ _validate();
+ setState(() {});
+ }
+ }
+ : null,
+ underline: Container(
+ height: 1.0,
+ decoration: BoxDecoration(
+ border: textFieldDecorationBorder,
+ ),
+ ),
+ itemHeight: 60,
+ dropdownColor: Themes.thirdLayerColor(context),
+ ),
+ ],
+ ),
+ ),
+ ValueListenableBuilder<String>(
+ valueListenable: _mimeTypeNotifier,
+ builder: (context, mimeType, child) {
+ Widget child;
+ if (_qualityFormats.contains(mimeType)) {
+ child = SliderListTile(
+ value: _quality.toDouble(),
+ onChanged: (v) => setState(() => _quality = v.round()),
+ min: 0,
+ max: 100,
+ title: context.l10n.exportEntryDialogQuality,
+ titlePadding: contentHorizontalPadding,
+ titleTrailing: (context, value) => ChangeHighlightText(
+ '${value.round()}',
+ style: trailingStyle.copyWith(
+ shadows: [
+ Shadow(
+ color: trailingChangeShadowColor.withAlpha(0),
+ blurRadius: 0,
+ )
+ ],
+ ),
+ changedStyle: trailingStyle.copyWith(
+ shadows: [
+ Shadow(
+ color: trailingChangeShadowColor,
+ blurRadius: 3,
+ )
+ ],
+ ),
+ duration: context.read<DurationsData>().formTextStyleTransition,
+ ),
+ );
+ } else {
+ child = const SizedBox();
+ }
+ return AnimatedSwitcher(
+ duration: context.read<DurationsData>().formTransition,
+ switchInCurve: Curves.easeInOutCubic,
+ switchOutCurve: Curves.easeInOutCubic,
+ transitionBuilder: AvesTransitions.formTransitionBuilder,
+ child: child,
+ );
+ },
+ ),
+ ValueListenableBuilder<String>(
+ valueListenable: _mimeTypeNotifier,
+ builder: (context, mimeType, child) {
+ Widget child;
+ if (AppSupport.canEditExif(mimeType) || AppSupport.canEditIptc(mimeType) || AppSupport.canEditXmp(mimeType)) {
+ child = SwitchListTile(
+ value: _writeMetadata,
+ onChanged: (v) => setState(() => _writeMetadata = v),
+ title: Text(context.l10n.exportEntryDialogWriteMetadata),
+ contentPadding: const EdgeInsetsDirectional.only(
+ start: AvesDialog.defaultHorizontalContentPadding,
+ end: AvesDialog.defaultHorizontalContentPadding - 8,
+ ),
+ );
+ } else {
+ child = const SizedBox(height: 16);
+ }
+ return AnimatedSwitcher(
+ duration: context.read<DurationsData>().formTransition,
+ switchInCurve: Curves.easeInOutCubic,
+ switchOutCurve: Curves.easeInOutCubic,
+ transitionBuilder: AvesTransitions.formTransitionBuilder,
+ child: child,
+ );
+ },
+ ),
+ ];
+ }
+
+ Future<void> _validate() async {
+ final width = int.tryParse(_widthController.text);
+ final height = int.tryParse(_heightController.text);
+ _isValidNotifier.value = (width ?? 0) > 0 && (height ?? 0) > 0;
+ }
+}
diff --git a/lib/widgets/dialogs/duration_dialog.dart b/lib/widgets/dialogs/duration_dialog.dart
new file mode 100644
index 0000000..ad742c4
--- /dev/null
+++ b/lib/widgets/dialogs/duration_dialog.dart
@@ -0,0 +1,123 @@
+import 'package:aves/ref/locales.dart';
+import 'package:aves/utils/time_utils.dart';
+import 'package:aves/widgets/common/basic/wheel.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/common/providers/media_query_data_provider.dart';
+import 'package:aves/widgets/dialogs/aves_dialog.dart';
+import 'package:flutter/material.dart';
+import 'package:intl/intl.dart';
+
+class DurationDialog extends StatefulWidget {
+ final int initialSeconds;
+
+ const DurationDialog({
+ super.key,
+ required this.initialSeconds,
+ });
+
+ @override
+ State<DurationDialog> createState() => _DurationDialogState();
+}
+
+class _DurationDialogState extends State<DurationDialog> {
+ late ValueNotifier<int> _minutes, _seconds;
+
+ @override
+ void initState() {
+ super.initState();
+ final seconds = widget.initialSeconds;
+ _minutes = ValueNotifier(seconds ~/ secondsInMinute);
+ _seconds = ValueNotifier(seconds % secondsInMinute);
+ }
+
+ @override
+ void dispose() {
+ _minutes.dispose();
+ _seconds.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return MediaQueryDataProvider(
+ child: Builder(builder: (context) {
+ final l10n = context.l10n;
+ final timeComponentFormatter = NumberFormat('0', context.locale);
+
+ const textStyle = TextStyle(fontSize: 34);
+ const digitsAlign = TextAlign.right;
+
+ return AvesDialog(
+ scrollableContent: [
+ Padding(
+ padding: const EdgeInsets.only(top: 16),
+ child: Center(
+ child: Table(
+ textDirection: timeComponentsDirection,
+ children: [
+ TableRow(
+ children: [
+ Center(child: Text(l10n.durationDialogMinutes)),
+ const SizedBox(width: 16),
+ Center(child: Text(l10n.durationDialogSeconds)),
+ ],
+ ),
+ TableRow(
+ children: [
+ Align(
+ alignment: Alignment.centerRight,
+ child: WheelSelector(
+ valueNotifier: _minutes,
+ values: List.generate(minutesInHour, (i) => i),
+ textStyle: textStyle,
+ textAlign: digitsAlign,
+ format: timeComponentFormatter.format,
+ ),
+ ),
+ const Padding(
+ padding: EdgeInsets.only(bottom: 2),
+ child: Text(
+ ':',
+ style: textStyle,
+ ),
+ ),
+ Align(
+ alignment: Alignment.centerLeft,
+ child: WheelSelector(
+ valueNotifier: _seconds,
+ values: List.generate(secondsInMinute, (i) => i),
+ textStyle: textStyle,
+ textAlign: digitsAlign,
+ format: timeComponentFormatter.format,
+ ),
+ ),
+ ],
+ )
+ ],
+ defaultColumnWidth: const IntrinsicColumnWidth(),
+ defaultVerticalAlignment: TableCellVerticalAlignment.middle,
+ ),
+ ),
+ ),
+ ],
+ actions: [
+ const CancelButton(),
+ AnimatedBuilder(
+ animation: Listenable.merge([_minutes, _seconds]),
+ builder: (context, child) {
+ final isValid = _minutes.value > 0 || _seconds.value > 0;
+ return TextButton(
+ onPressed: isValid ? () => _submit(context) : null,
+ child: child!,
+ );
+ },
+ child: Text(l10n.applyButtonLabel),
+ ),
+ ],
+ );
+ }),
+ );
+ }
+
+ void _submit(BuildContext context) => Navigator.maybeOf(context)?.pop(_minutes.value * secondsInMinute + _seconds.value);
+}
diff --git a/lib/widgets/dialogs/entry_editors/edit_date_dialog.dart b/lib/widgets/dialogs/entry_editors/edit_date_dialog.dart
new file mode 100644
index 0000000..0d027d5
--- /dev/null
+++ b/lib/widgets/dialogs/entry_editors/edit_date_dialog.dart
@@ -0,0 +1,332 @@
+import 'package:aves/model/entry/entry.dart';
+import 'package:aves/model/metadata/date_modifier.dart';
+import 'package:aves/model/source/collection_lens.dart';
+import 'package:aves/theme/durations.dart';
+import 'package:aves/theme/format.dart';
+import 'package:aves/theme/icons.dart';
+import 'package:aves/theme/themes.dart';
+import 'package:aves/view/view.dart';
+import 'package:aves/widgets/common/basic/text_dropdown_button.dart';
+import 'package:aves/widgets/common/basic/time_shift_selector.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/common/fx/transitions.dart';
+import 'package:aves/widgets/common/providers/media_query_data_provider.dart';
+import 'package:aves/widgets/dialogs/aves_dialog.dart';
+import 'package:aves/widgets/dialogs/item_picker.dart';
+import 'package:aves/widgets/dialogs/pick_dialogs/item_pick_page.dart';
+import 'package:aves_model/aves_model.dart';
+import 'package:flutter/material.dart';
+import 'package:provider/provider.dart';
+
+class EditEntryDateDialog extends StatefulWidget {
+ static const routeName = '/dialog/edit_entry_date';
+
+ final AvesEntry entry;
+ final CollectionLens? collection;
+
+ const EditEntryDateDialog({
+ super.key,
+ required this.entry,
+ this.collection,
+ });
+
+ @override
+ State<EditEntryDateDialog> createState() => _EditEntryDateDialogState();
+}
+
+class _EditEntryDateDialogState extends State<EditEntryDateDialog> {
+ DateEditAction _action = DateEditAction.setCustom;
+ DateFieldSource _copyFieldSource = DateFieldSource.fileModifiedDate;
+ late AvesEntry _copyItemSource;
+ late DateTime _customDateTime;
+ late TimeShiftController _timeShiftController;
+ bool _showOptions = false;
+ final Set<MetadataField> _fields = {...DateModifier.writableFields};
+ final ValueNotifier<bool> _isValidNotifier = ValueNotifier(false);
+
+ DateTime get copyItemDate => _copyItemSource.bestDate ?? DateTime.now();
+
+ @override
+ void initState() {
+ super.initState();
+ _initCustom();
+ _initCopyItem();
+ _initShift();
+ _validate();
+ }
+
+ @override
+ void dispose() {
+ _isValidNotifier.dispose();
+ super.dispose();
+ }
+
+ void _initCustom() {
+ _customDateTime = widget.entry.bestDate ?? DateTime.now();
+ }
+
+ void _initCopyItem() {
+ _copyItemSource = widget.entry;
+ }
+
+ void _initShift() {
+ _timeShiftController = TimeShiftController(
+ initialValue: const Duration(hours: 1),
+ );
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return MediaQueryDataProvider(
+ child: TooltipTheme(
+ data: TooltipTheme.of(context).copyWith(
+ preferBelow: false,
+ ),
+ child: Builder(builder: (context) {
+ final l10n = context.l10n;
+
+ return AvesDialog(
+ title: l10n.editEntryDateDialogTitle,
+ scrollableContent: [
+ Padding(
+ padding: const EdgeInsets.only(left: 16, top: 8, right: 16),
+ child: TextDropdownButton<DateEditAction>(
+ values: DateEditAction.values,
+ valueText: (v) => v.getText(context),
+ value: _action,
+ onChanged: (v) {
+ _action = v!;
+ _validate();
+ setState(() {});
+ },
+ isExpanded: true,
+ dropdownColor: Themes.thirdLayerColor(context),
+ ),
+ ),
+ AnimatedSwitcher(
+ duration: context.read<DurationsData>().formTransition,
+ switchInCurve: Curves.easeInOutCubic,
+ switchOutCurve: Curves.easeInOutCubic,
+ transitionBuilder: AvesTransitions.formTransitionBuilder,
+ child: Column(
+ key: ValueKey(_action),
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ if (_action == DateEditAction.setCustom) _buildSetCustomContent(context),
+ if (_action == DateEditAction.copyField) _buildCopyFieldContent(context),
+ if (_action == DateEditAction.copyItem) _buildCopyItemContent(context),
+ if (_action == DateEditAction.shift) _buildShiftContent(context),
+ (_action == DateEditAction.shift || _action == DateEditAction.remove) ? _buildDestinationFields(context) : const SizedBox(height: 8),
+ ],
+ ),
+ ),
+ ],
+ actions: [
+ const CancelButton(),
+ ValueListenableBuilder<bool>(
+ valueListenable: _isValidNotifier,
+ builder: (context, isValid, child) {
+ return TextButton(
+ onPressed: isValid ? () => _submit(context) : null,
+ child: Text(l10n.applyButtonLabel),
+ );
+ },
+ ),
+ ],
+ );
+ }),
+ ),
+ );
+ }
+
+ Widget _buildSetCustomContent(BuildContext context) {
+ final use24hour = MediaQuery.alwaysUse24HourFormatOf(context);
+
+ return Padding(
+ padding: const EdgeInsetsDirectional.only(start: 16, end: 8),
+ child: Row(
+ children: [
+ Expanded(child: Text(formatDateTime(_customDateTime, context.locale, use24hour))),
+ IconButton(
+ icon: const Icon(AIcons.edit),
+ onPressed: _editDate,
+ tooltip: context.l10n.changeTooltip,
+ ),
+ ],
+ ),
+ );
+ }
+
+ Widget _buildCopyFieldContent(BuildContext context) {
+ return Padding(
+ padding: const EdgeInsets.only(left: 16, top: 0, right: 16),
+ child: TextDropdownButton<DateFieldSource>(
+ values: DateFieldSource.values,
+ valueText: (v) => v.getText(context),
+ value: _copyFieldSource,
+ onChanged: (v) => setState(() => _copyFieldSource = v!),
+ isExpanded: true,
+ dropdownColor: Themes.thirdLayerColor(context),
+ ),
+ );
+ }
+
+ Widget _buildCopyItemContent(BuildContext context) {
+ final use24hour = MediaQuery.alwaysUse24HourFormatOf(context);
+
+ return Padding(
+ padding: const EdgeInsetsDirectional.only(start: 16, end: 8),
+ child: Row(
+ children: [
+ Expanded(child: Text(formatDateTime(copyItemDate, context.locale, use24hour))),
+ const SizedBox(width: 8),
+ ItemPicker(
+ extent: 48,
+ entry: _copyItemSource,
+ onTap: _pickCopyItemSource,
+ ),
+ ],
+ ),
+ );
+ }
+
+ Widget _buildShiftContent(BuildContext context) {
+ return TimeShiftSelector(controller: _timeShiftController);
+ }
+
+ Widget _buildDestinationFields(BuildContext context) {
+ return Padding(
+ // small padding as a workaround to show dialog action divider
+ padding: const EdgeInsets.only(bottom: 1),
+ child: ExpansionPanelList(
+ expansionCallback: (index, isExpanded) {
+ setState(() => _showOptions = isExpanded);
+ },
+ animationDuration: context.read<DurationsData>().expansionTileAnimation,
+ expandedHeaderPadding: EdgeInsets.zero,
+ elevation: 0,
+ children: [
+ ExpansionPanel(
+ headerBuilder: (context, isExpanded) => ListTile(
+ title: Text(context.l10n.editEntryDialogTargetFieldsHeader),
+ ),
+ body: Column(
+ children: DateModifier.writableFields
+ .map((field) => SwitchListTile(
+ value: _fields.contains(field),
+ onChanged: (selected) {
+ selected ? _fields.add(field) : _fields.remove(field);
+ _validate();
+ setState(() {});
+ },
+ title: Text(field.title),
+ ))
+ .toList(),
+ ),
+ isExpanded: _showOptions,
+ canTapOnHeader: true,
+ backgroundColor: Colors.transparent,
+ ),
+ ],
+ ),
+ );
+ }
+
+ Future<void> _editDate() async {
+ final l10n = context.l10n;
+ final cancelText = Themes.asButtonLabel(l10n.cancelTooltip);
+
+ final _date = await showDatePicker(
+ context: context,
+ initialDate: _customDateTime,
+ firstDate: DateTime(0),
+ lastDate: DateTime(2100),
+ cancelText: cancelText,
+ confirmText: l10n.nextButtonLabel,
+ );
+ if (_date == null) return;
+
+ final _time = await showTimePicker(
+ context: context,
+ initialTime: TimeOfDay.fromDateTime(_customDateTime),
+ cancelText: cancelText,
+ );
+ if (_time == null) return;
+
+ setState(() => _customDateTime = DateTime(
+ _date.year,
+ _date.month,
+ _date.day,
+ _time.hour,
+ _time.minute,
+ ));
+ }
+
+ CollectionLens? _createPickCollection() {
+ final baseCollection = widget.collection;
+ return baseCollection != null
+ ? CollectionLens(
+ source: baseCollection.source,
+ filters: baseCollection.filters,
+ )
+ : null;
+ }
+
+ Future<void> _pickCopyItemSource() async {
+ final pickCollection = _createPickCollection();
+ if (pickCollection == null) return;
+
+ final entry = await Navigator.maybeOf(context)?.push<AvesEntry>(
+ MaterialPageRoute(
+ settings: const RouteSettings(name: ItemPickPage.routeName),
+ builder: (context) => ItemPickPage(
+ collection: pickCollection,
+ canRemoveFilters: true,
+ ),
+ fullscreenDialog: true,
+ ),
+ );
+ if (entry != null) {
+ setState(() => _copyItemSource = entry);
+ }
+ }
+
+ DateModifier _getModifier() {
+ // fields to modify are only set for the `shift` and `remove` actions,
+ // as the effective fields for the other actions will depend on
+ // whether each item supports Exif edition
+ switch (_action) {
+ case DateEditAction.setCustom:
+ return DateModifier.setCustom(const {}, _customDateTime);
+ case DateEditAction.copyField:
+ return DateModifier.copyField(_copyFieldSource);
+ case DateEditAction.copyItem:
+ return DateModifier.setCustom(const {}, copyItemDate);
+ case DateEditAction.extractFromTitle:
+ return DateModifier.extractFromTitle();
+ case DateEditAction.shift:
+ return DateModifier.shift(_fields, _timeShiftController.value.inSeconds);
+ case DateEditAction.remove:
+ return DateModifier.remove(_fields);
+ }
+ }
+
+ void _validate() {
+ switch (_action) {
+ case DateEditAction.setCustom:
+ case DateEditAction.copyField:
+ case DateEditAction.copyItem:
+ case DateEditAction.extractFromTitle:
+ _isValidNotifier.value = true;
+ case DateEditAction.shift:
+ case DateEditAction.remove:
+ _isValidNotifier.value = _fields.isNotEmpty;
+ }
+ }
+
+ void _submit(BuildContext context) {
+ if (_isValidNotifier.value) {
+ Navigator.maybeOf(context)?.pop(_getModifier());
+ }
+ }
+}
diff --git a/lib/widgets/dialogs/entry_editors/edit_description_dialog.dart b/lib/widgets/dialogs/entry_editors/edit_description_dialog.dart
new file mode 100644
index 0000000..60c77b9
--- /dev/null
+++ b/lib/widgets/dialogs/entry_editors/edit_description_dialog.dart
@@ -0,0 +1,116 @@
+import 'package:aves/model/entry/extensions/metadata_edition.dart';
+import 'package:aves/widgets/common/basic/labeled_checkbox.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/common/providers/media_query_data_provider.dart';
+import 'package:aves/widgets/dialogs/aves_dialog.dart';
+import 'package:flutter/material.dart';
+
+class EditEntryTitleDescriptionDialog extends StatefulWidget {
+ static const routeName = '/dialog/edit_entry_title_description';
+
+ final String initialTitle, initialDescription;
+
+ const EditEntryTitleDescriptionDialog({
+ super.key,
+ required this.initialTitle,
+ required this.initialDescription,
+ });
+
+ @override
+ State<EditEntryTitleDescriptionDialog> createState() => _EditEntryTitleDescriptionDialogState();
+}
+
+class _EditEntryTitleDescriptionDialogState extends State<EditEntryTitleDescriptionDialog> {
+ final Set<DescriptionField> fields = {
+ DescriptionField.title,
+ DescriptionField.description,
+ };
+ late final TextEditingController _titleTextController, _descriptionTextController;
+
+ @override
+ void initState() {
+ super.initState();
+ _titleTextController = TextEditingController(text: widget.initialTitle);
+ _descriptionTextController = TextEditingController(text: widget.initialDescription);
+ }
+
+ @override
+ void dispose() {
+ _titleTextController.dispose();
+ _descriptionTextController.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return MediaQueryDataProvider(
+ child: Builder(builder: (context) {
+ return AvesDialog(
+ scrollableContent: [
+ const SizedBox(height: 8),
+ ..._buildFieldEditor(DescriptionField.title),
+ ..._buildFieldEditor(DescriptionField.description),
+ const SizedBox(height: 8),
+ ],
+ actions: [
+ const CancelButton(),
+ TextButton(
+ onPressed: fields.isEmpty ? null : () => _submit(context),
+ child: Text(context.l10n.applyButtonLabel),
+ ),
+ ],
+ );
+ }),
+ );
+ }
+
+ List<Widget> _buildFieldEditor(DescriptionField field) {
+ final editing = fields.contains(field);
+ return [
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 4),
+ child: LabeledCheckbox(
+ value: editing,
+ onChanged: (v) => setState(() => editing ? fields.remove(field) : fields.add(field)),
+ text: _fieldName(field),
+ ),
+ ),
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 8),
+ child: TextField(
+ controller: _fieldController(field),
+ decoration: const InputDecoration(
+ border: OutlineInputBorder(),
+ ),
+ maxLines: null,
+ enabled: editing,
+ ),
+ ),
+ ];
+ }
+
+ TextEditingController _fieldController(DescriptionField field) {
+ switch (field) {
+ case DescriptionField.title:
+ return _titleTextController;
+ case DescriptionField.description:
+ return _descriptionTextController;
+ }
+ }
+
+ String _fieldName(DescriptionField field) {
+ final l10n = context.l10n;
+ return switch (field) {
+ DescriptionField.title => l10n.viewerInfoLabelTitle,
+ DescriptionField.description => l10n.viewerInfoLabelDescription,
+ };
+ }
+
+ void _submit(BuildContext context) {
+ final modifier = Map.fromEntries(fields.map((field) {
+ final text = _fieldController(field).text;
+ return MapEntry(field, text.isEmpty ? null : text);
+ }));
+ return Navigator.maybeOf(context)?.pop<Map<DescriptionField, String?>>(modifier);
+ }
+}
diff --git a/lib/widgets/dialogs/entry_editors/edit_location_dialog.dart b/lib/widgets/dialogs/entry_editors/edit_location_dialog.dart
new file mode 100644
index 0000000..6c51a13
--- /dev/null
+++ b/lib/widgets/dialogs/entry_editors/edit_location_dialog.dart
@@ -0,0 +1,629 @@
+import 'dart:async';
+import 'dart:convert';
+import 'dart:ui';
+
+import 'package:aves/app_mode.dart';
+import 'package:aves/model/entry/entry.dart';
+import 'package:aves/model/entry/extensions/location.dart';
+import 'package:aves/model/entry/extensions/metadata_edition.dart';
+import 'package:aves/model/entry/sort.dart';
+import 'package:aves/model/filters/covered/location.dart';
+import 'package:aves/model/metadata/catalog.dart';
+import 'package:aves/model/settings/enums/coordinate_format.dart';
+import 'package:aves/model/settings/settings.dart';
+import 'package:aves/model/source/collection_lens.dart';
+import 'package:aves/ref/poi.dart';
+import 'package:aves/services/common/services.dart';
+import 'package:aves/theme/durations.dart';
+import 'package:aves/theme/format.dart';
+import 'package:aves/theme/icons.dart';
+import 'package:aves/theme/themes.dart';
+import 'package:aves/view/view.dart';
+import 'package:aves/widgets/aves_app.dart';
+import 'package:aves/widgets/common/action_mixins/feedback.dart';
+import 'package:aves/widgets/common/basic/text_dropdown_button.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/common/fx/transitions.dart';
+import 'package:aves/widgets/common/identity/aves_caption.dart';
+import 'package:aves/widgets/common/providers/media_query_data_provider.dart';
+import 'package:aves/widgets/dialogs/aves_dialog.dart';
+import 'package:aves/widgets/dialogs/item_picker.dart';
+import 'package:aves/widgets/dialogs/pick_dialogs/item_pick_page.dart';
+import 'package:aves/widgets/dialogs/pick_dialogs/location_pick_page.dart';
+import 'package:aves/widgets/dialogs/time_shift_dialog.dart';
+import 'package:aves/widgets/map/map_page.dart';
+import 'package:aves_model/aves_model.dart';
+import 'package:collection/collection.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter_map/flutter_map.dart';
+import 'package:gpx/gpx.dart';
+import 'package:intl/intl.dart';
+import 'package:latlong2/latlong.dart';
+import 'package:provider/provider.dart';
+
+class EditEntryLocationDialog extends StatefulWidget {
+ static const routeName = '/dialog/edit_entry_location';
+
+ final Set<AvesEntry> entries;
+ final CollectionLens? collection;
+
+ const EditEntryLocationDialog({
+ super.key,
+ required this.entries,
+ this.collection,
+ });
+
+ @override
+ State<EditEntryLocationDialog> createState() => _EditEntryLocationDialogState();
+}
+
+class _EditEntryLocationDialogState extends State<EditEntryLocationDialog> with FeedbackMixin {
+ final Set<StreamSubscription> _subscriptions = {};
+ LocationEditAction _action = LocationEditAction.chooseOnMap;
+ LatLng? _mapCoordinates;
+ late final AvesEntry mainEntry;
+ late AvesEntry _copyItemSource;
+ Gpx? _gpx;
+ Duration _gpxShift = Duration.zero;
+ final Map<AvesEntry, LatLng> _gpxMap = {};
+ final TextEditingController _latitudeController = TextEditingController(), _longitudeController = TextEditingController();
+ final ValueNotifier<bool> _isValidNotifier = ValueNotifier(false);
+
+ late NumberFormat coordinateFormatter;
+ static const _gpxProjection = SphericalMercator();
+ static const _minDurationToGpxPoint = Duration(hours: 1);
+
+ @override
+ void initState() {
+ super.initState();
+ final entries = widget.entries;
+ mainEntry = entries.firstWhereOrNull((entry) => entry.hasGps) ?? entries.first;
+ _mapCoordinates = mainEntry.latLng;
+ _copyItemSource = mainEntry;
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ coordinateFormatter = NumberFormat('0.000000', context.locale);
+ final latLng = mainEntry.latLng;
+ if (latLng != null) {
+ _latitudeController.text = coordinateFormatter.format(latLng.latitude);
+ _longitudeController.text = coordinateFormatter.format(latLng.longitude);
+ } else {
+ _latitudeController.text = '';
+ _longitudeController.text = '';
+ }
+ setState(_validate);
+ });
+ _subscriptions.add(AvesApp.intentEventBus.on<LocationReceivedEvent>().listen((event) => _setCustomLocation(event.location)));
+ }
+
+ @override
+ void dispose() {
+ _subscriptions
+ ..forEach((sub) => sub.cancel())
+ ..clear();
+ _latitudeController.dispose();
+ _longitudeController.dispose();
+ _isValidNotifier.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return MediaQueryDataProvider(
+ child: TooltipTheme(
+ data: TooltipTheme.of(context).copyWith(
+ preferBelow: false,
+ ),
+ child: Builder(builder: (context) {
+ final l10n = context.l10n;
+
+ return AvesDialog(
+ title: l10n.editEntryLocationDialogTitle,
+ scrollableContent: [
+ Padding(
+ padding: const EdgeInsets.only(left: 16, top: 8, right: 16),
+ child: TextDropdownButton<LocationEditAction>(
+ values: LocationEditAction.values,
+ valueText: (v) => v.getText(context),
+ value: _action,
+ onChanged: (v) => setState(() {
+ _action = v!;
+ _validate();
+ }),
+ isExpanded: true,
+ dropdownColor: Themes.thirdLayerColor(context),
+ ),
+ ),
+ AnimatedSwitcher(
+ duration: context.read<DurationsData>().formTransition,
+ switchInCurve: Curves.easeInOutCubic,
+ switchOutCurve: Curves.easeInOutCubic,
+ transitionBuilder: AvesTransitions.formTransitionBuilder,
+ child: KeyedSubtree(
+ key: ValueKey(_action),
+ child: _buildContent(),
+ ),
+ ),
+ const SizedBox(height: 8),
+ ],
+ actions: [
+ const CancelButton(),
+ ValueListenableBuilder<bool>(
+ valueListenable: _isValidNotifier,
+ builder: (context, isValid, child) {
+ return TextButton(
+ onPressed: isValid ? () => _submit(context) : null,
+ child: Text(l10n.applyButtonLabel),
+ );
+ },
+ ),
+ ],
+ );
+ }),
+ ),
+ );
+ }
+
+ Widget _buildContent() {
+ switch (_action) {
+ case LocationEditAction.chooseOnMap:
+ return _buildChooseOnMapContent(context);
+ case LocationEditAction.copyItem:
+ return _buildCopyItemContent(context);
+ case LocationEditAction.setCustom:
+ return _buildSetCustomContent(context);
+ case LocationEditAction.importGpx:
+ return _buildImportGpxContent(context);
+ case LocationEditAction.remove:
+ return const SizedBox();
+ }
+ }
+
+ Widget _buildChooseOnMapContent(BuildContext context) {
+ return Padding(
+ padding: const EdgeInsetsDirectional.only(start: 16, end: 8),
+ child: Row(
+ children: [
+ Expanded(child: _coordinatesText(context, _mapCoordinates)),
+ const SizedBox(width: 8),
+ IconButton(
+ icon: const Icon(AIcons.map),
+ onPressed: _pickLocation,
+ tooltip: context.l10n.editEntryLocationDialogChooseOnMap,
+ ),
+ ],
+ ),
+ );
+ }
+
+ void _setCustomLocation(LatLng latLng) {
+ _latitudeController.text = coordinateFormatter.format(latLng.latitude);
+ _longitudeController.text = coordinateFormatter.format(latLng.longitude);
+ _action = LocationEditAction.setCustom;
+ setState(_validate);
+ }
+
+ CollectionLens? _createPickCollection() {
+ final baseCollection = widget.collection;
+ return baseCollection != null
+ ? CollectionLens(
+ source: baseCollection.source,
+ filters: {
+ ...baseCollection.filters.whereNot((filter) => filter == LocationFilter.unlocated),
+ LocationFilter.located,
+ },
+ )
+ : null;
+ }
+
+ Future<void> _pickLocation() async {
+ final pickCollection = _createPickCollection();
+ final latLng = await Navigator.maybeOf(context)?.push(
+ MaterialPageRoute(
+ settings: const RouteSettings(name: LocationPickPage.routeName),
+ builder: (context) => LocationPickPage(
+ collection: pickCollection,
+ initialLocation: _mapCoordinates,
+ ),
+ fullscreenDialog: true,
+ ),
+ );
+ if (latLng != null) {
+ settings.mapDefaultCenter = latLng;
+ setState(() {
+ _mapCoordinates = latLng;
+ _validate();
+ });
+ }
+ }
+
+ Widget _buildCopyItemContent(BuildContext context) {
+ return Padding(
+ padding: const EdgeInsetsDirectional.only(start: 16, end: 8),
+ child: Row(
+ children: [
+ Expanded(child: _coordinatesText(context, _copyItemSource.latLng)),
+ const SizedBox(width: 8),
+ ItemPicker(
+ extent: 48,
+ entry: _copyItemSource,
+ onTap: _pickCopyItemSource,
+ ),
+ ],
+ ),
+ );
+ }
+
+ Future<void> _pickCopyItemSource() async {
+ final pickCollection = _createPickCollection();
+ if (pickCollection == null) return;
+
+ final entry = await Navigator.maybeOf(context)?.push<AvesEntry>(
+ MaterialPageRoute(
+ settings: const RouteSettings(name: ItemPickPage.routeName),
+ builder: (context) => ItemPickPage(
+ collection: pickCollection,
+ canRemoveFilters: true,
+ ),
+ fullscreenDialog: true,
+ ),
+ );
+ if (entry != null) {
+ setState(() {
+ _copyItemSource = entry;
+ _validate();
+ });
+ }
+ }
+
+ Widget _buildSetCustomContent(BuildContext context) {
+ final l10n = context.l10n;
+
+ return Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Expanded(
+ child: Column(
+ children: [
+ TextField(
+ controller: _latitudeController,
+ decoration: InputDecoration(
+ labelText: l10n.editEntryLocationDialogLatitude,
+ hintText: coordinateFormatter.format(PointsOfInterest.pointNemo.latitude),
+ ),
+ onChanged: (_) => _validate(),
+ ),
+ TextField(
+ controller: _longitudeController,
+ decoration: InputDecoration(
+ labelText: l10n.editEntryLocationDialogLongitude,
+ hintText: coordinateFormatter.format(PointsOfInterest.pointNemo.longitude),
+ ),
+ onChanged: (_) => _validate(),
+ ),
+ ],
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+
+ Widget _buildImportGpxContent(BuildContext context) {
+ final l10n = context.l10n;
+ return Padding(
+ padding: const EdgeInsetsDirectional.only(start: 16, end: 8),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Row(
+ children: [
+ Expanded(child: _gpxDateRangeText(context, _gpx)),
+ const SizedBox(width: 8),
+ IconButton(
+ icon: Icon(AIcons.fileImport),
+ onPressed: _pickGpx,
+ tooltip: l10n.pickTooltip,
+ ),
+ ],
+ ),
+ if (_gpx != null) ...[
+ Row(
+ children: [
+ Expanded(
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(l10n.editEntryLocationDialogTimeShift),
+ AvesCaption(_formatShiftDuration(_gpxShift)),
+ ],
+ ),
+ ),
+ const SizedBox(width: 8),
+ IconButton(
+ icon: const Icon(AIcons.edit),
+ onPressed: _pickGpxShift,
+ tooltip: l10n.changeTooltip,
+ ),
+ ],
+ ),
+ Row(
+ children: [
+ Expanded(child: Text(l10n.statsWithGps(_gpxMap.length))),
+ const SizedBox(width: 8),
+ IconButton(
+ icon: const Icon(AIcons.map),
+ onPressed: _previewGpx,
+ tooltip: l10n.openMapPageTooltip,
+ ),
+ ],
+ ),
+ ],
+ ],
+ ),
+ );
+ }
+
+ Future<void> _pickGpx() async {
+ final bytes = await storageService.openFile();
+ if (bytes.isNotEmpty) {
+ try {
+ final allXmlString = utf8.decode(bytes);
+ final gpx = GpxReader().fromString(allXmlString);
+
+ _gpx = gpx;
+ _gpxShift = Duration.zero;
+ _updateGpxMapping();
+
+ showFeedback(context, FeedbackType.info, context.l10n.genericSuccessFeedback);
+ } catch (error, stack) {
+ debugPrint('failed to import GPX, error=$error\n$stack');
+ showFeedback(context, FeedbackType.warn, context.l10n.genericFailureFeedback);
+ }
+ }
+ }
+
+ Future<void> _pickGpxShift() async {
+ final newShift = await showDialog<Duration>(
+ context: context,
+ builder: (context) => TimeShiftDialog(
+ initialValue: _gpxShift,
+ ),
+ routeSettings: const RouteSettings(name: TimeShiftDialog.routeName),
+ );
+ if (newShift == null) return;
+
+ _gpxShift = newShift;
+ _updateGpxMapping();
+ }
+
+ String _formatShiftDuration(Duration duration) {
+ final sign = duration.isNegative ? '-' : '+';
+ duration = duration.abs();
+ final hours = duration.inHours;
+ duration -= Duration(hours: hours);
+ final minutes = duration.inMinutes;
+ duration -= Duration(minutes: minutes);
+ final seconds = duration.inSeconds;
+ return '$sign$hours:${minutes.toString().padLeft(2, '0')}:${seconds.toString().padLeft(2, '0')}';
+ }
+
+ void _updateGpxMapping() {
+ _gpxMap.clear();
+
+ final gpx = _gpx;
+ if (gpx == null) return;
+
+ // dated items and points, oldest first
+ final sortedEntries = widget.entries.where((v) => v.bestDate != null).sorted(AvesEntrySort.compareByDate).reversed.toList();
+ final sortedPoints = gpx.trks.expand((trk) => trk.trksegs).expand((trkSeg) => trkSeg.trkpts).where((v) => v.time != null && v.lat != null && v.lon != null).sortedBy((v) => v.time!);
+ if (sortedEntries.isNotEmpty && sortedPoints.isNotEmpty) {
+ int entryIndex = 0;
+ int pointIndex = 0;
+
+ DateTime getEntryDate(AvesEntry entry) => entry.bestDate!;
+ DateTime getCorrectedPointDate(Wpt wpt) => wpt.time!.add(_gpxShift);
+ Duration getDurationToPoint(AvesEntry entry, Wpt wpt) => getEntryDate(entry).difference(getCorrectedPointDate(wpt)).abs();
+
+ while (entryIndex < sortedEntries.length && pointIndex < sortedPoints.length) {
+ final entry = sortedEntries[entryIndex];
+ final wpt = sortedPoints[pointIndex];
+
+ final entryDate = getEntryDate(entry);
+ final wptDate = getCorrectedPointDate(wpt);
+ final durationToPoint = getDurationToPoint(entry, wpt);
+
+ if (entryDate.isAfter(wptDate)) {
+ if (wpt == sortedPoints.last) {
+ if (durationToPoint < _minDurationToGpxPoint) {
+ // assign late entry to last point
+ _gpxMap[entry] = LatLng(wpt.lat!, wpt.lon!);
+ }
+ entryIndex++;
+ } else {
+ pointIndex++;
+ }
+ } else if (entryDate.isAtSameMomentAs(wptDate)) {
+ // assign entry to current point
+ _gpxMap[entry] = LatLng(wpt.lat!, wpt.lon!);
+ entryIndex++;
+ } else {
+ if (wpt == sortedPoints.first) {
+ if (durationToPoint < _minDurationToGpxPoint) {
+ // assign early entry to first point
+ _gpxMap[entry] = LatLng(wpt.lat!, wpt.lon!);
+ }
+ } else {
+ // interpolate entry between previous and current point
+ final from = sortedPoints[pointIndex - 1];
+ final to = wpt;
+
+ final secondsFromStart = getDurationToPoint(entry, from).inSeconds;
+ final secondsToEnd = getDurationToPoint(entry, to).inSeconds;
+ final t = (secondsFromStart.toDouble()) / (secondsFromStart + secondsToEnd);
+
+ final fromXY = _gpxProjection.projectXY(LatLng(from.lat!, from.lon!));
+ final toXY = _gpxProjection.projectXY(LatLng(to.lat!, to.lon!));
+ final entryXY = (
+ lerpDouble(fromXY.$1, toXY.$1, t)!,
+ lerpDouble(fromXY.$2, toXY.$2, t)!,
+ );
+ _gpxMap[entry] = _gpxProjection.unprojectXY(entryXY.$1, entryXY.$2);
+ }
+ entryIndex++;
+ }
+ }
+ }
+
+ setState(_validate);
+ }
+
+ Future<void> _previewGpx() async {
+ final source = widget.collection?.source;
+ if (source == null) return;
+
+ final previewEntries = _gpxMap.entries.map((kv) {
+ final entry = kv.key.copyWith();
+ final latLng = kv.value;
+ final catalogMetadata = entry.catalogMetadata?.copyWith() ?? CatalogMetadata(id: entry.id);
+ catalogMetadata.latitude = latLng.latitude;
+ catalogMetadata.longitude = latLng.longitude;
+ entry.catalogMetadata = catalogMetadata;
+ return entry;
+ }).toList();
+
+ final mapCollection = CollectionLens(
+ source: source,
+ listenToSource: false,
+ fixedSelection: previewEntries,
+ );
+
+ final tracks = _gpx?.trks
+ .expand((trk) => trk.trksegs)
+ .map((trkSeg) => trkSeg.trkpts
+ .map((wpt) {
+ final lat = wpt.lat;
+ final lon = wpt.lon;
+ return (lat != null && lon != null) ? LatLng(lat, lon) : null;
+ })
+ .nonNulls
+ .toList())
+ .toSet();
+
+ await Navigator.maybeOf(context)?.push(
+ MaterialPageRoute(
+ settings: const RouteSettings(name: LocationPickPage.routeName),
+ builder: (context) {
+ return ListenableProvider<ValueNotifier<AppMode>>.value(
+ value: ValueNotifier(AppMode.previewMap),
+ child: MapPage(
+ collection: mapCollection,
+ tracks: tracks,
+ ),
+ );
+ },
+ fullscreenDialog: true,
+ ),
+ );
+ }
+
+ Text _unknownText(BuildContext context) {
+ final l10n = context.l10n;
+ return Text(
+ l10n.viewerInfoUnknown,
+ style: TextStyle(
+ color: Theme.of(context).colorScheme.onSurfaceVariant,
+ ),
+ );
+ }
+
+ (DateTime, DateTime)? _gpxDateRange(Gpx? gpx) {
+ final firstDate = gpx?.trks.firstOrNull?.trksegs.firstOrNull?.trkpts.firstOrNull?.time;
+ final lastDate = gpx?.trks.lastOrNull?.trksegs.lastOrNull?.trkpts.lastOrNull?.time;
+ return firstDate != null && lastDate != null ? (firstDate, lastDate) : null;
+ }
+
+ Text _gpxDateRangeText(BuildContext context, Gpx? gpx) {
+ final dateRange = _gpxDateRange(gpx);
+ if (dateRange != null) {
+ final (firstDate, lastDate) = dateRange;
+ final locale = context.locale;
+ final use24hour = MediaQuery.alwaysUse24HourFormatOf(context);
+ return Text(
+ [
+ formatDateTime(firstDate.toLocal(), locale, use24hour),
+ formatDateTime(lastDate.toLocal(), locale, use24hour),
+ ].join('\n'),
+ );
+ } else {
+ return _unknownText(context);
+ }
+ }
+
+ Text _coordinatesText(BuildContext context, LatLng? latLng) {
+ final l10n = context.l10n;
+ if (latLng != null) {
+ return Text(
+ ExtraCoordinateFormat.toDMS(l10n, latLng).join('\n'),
+ );
+ } else {
+ return _unknownText(context);
+ }
+ }
+
+ LatLng? _parseLatLng() {
+ double? tryParse(String text) {
+ try {
+ return double.tryParse(text) ?? (coordinateFormatter.parse(text).toDouble());
+ } catch (error) {
+ // ignore
+ return null;
+ }
+ }
+
+ final lat = tryParse(_latitudeController.text);
+ final lng = tryParse(_longitudeController.text);
+ if (lat == null || lng == null) return null;
+ if (lat < -90 || lat > 90 || lng < -180 || lng > 180) return null;
+ return LatLng(lat, lng);
+ }
+
+ void _validate() {
+ switch (_action) {
+ case LocationEditAction.chooseOnMap:
+ _isValidNotifier.value = _mapCoordinates != null;
+ case LocationEditAction.copyItem:
+ _isValidNotifier.value = _copyItemSource.hasGps;
+ case LocationEditAction.setCustom:
+ _isValidNotifier.value = _parseLatLng() != null;
+ case LocationEditAction.importGpx:
+ _isValidNotifier.value = _gpxMap.isNotEmpty;
+ case LocationEditAction.remove:
+ _isValidNotifier.value = true;
+ }
+ }
+
+ void _submit(BuildContext context) {
+ final navigator = Navigator.maybeOf(context);
+ final entries = widget.entries;
+ final LocationEditActionResult result = {};
+ void addLocationForAllEntries(LatLng? latLng) => result.addEntries(entries.map((v) => MapEntry(v, latLng)));
+ switch (_action) {
+ case LocationEditAction.chooseOnMap:
+ addLocationForAllEntries(_mapCoordinates);
+ case LocationEditAction.copyItem:
+ addLocationForAllEntries(_copyItemSource.latLng);
+ case LocationEditAction.setCustom:
+ addLocationForAllEntries(_parseLatLng());
+ case LocationEditAction.importGpx:
+ result.addAll(_gpxMap);
+ case LocationEditAction.remove:
+ addLocationForAllEntries(ExtraAvesEntryMetadataEdition.removalLocation);
+ }
+ navigator?.pop(result);
+ }
+}
+
+typedef LocationEditActionResult = Map<AvesEntry, LatLng?>;
diff --git a/lib/widgets/dialogs/entry_editors/edit_rating_dialog.dart b/lib/widgets/dialogs/entry_editors/edit_rating_dialog.dart
new file mode 100644
index 0000000..771ab6f
--- /dev/null
+++ b/lib/widgets/dialogs/entry_editors/edit_rating_dialog.dart
@@ -0,0 +1,133 @@
+import 'package:aves/model/entry/entry.dart';
+import 'package:aves/theme/colors.dart';
+import 'package:aves/theme/icons.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/common/providers/media_query_data_provider.dart';
+import 'package:aves/widgets/dialogs/aves_dialog.dart';
+import 'package:flutter/material.dart';
+
+class EditEntryRatingDialog extends StatefulWidget {
+ static const routeName = '/dialog/edit_entry_rating';
+
+ final AvesEntry entry;
+
+ const EditEntryRatingDialog({
+ super.key,
+ required this.entry,
+ });
+
+ @override
+ State<EditEntryRatingDialog> createState() => _EditEntryRatingDialogState();
+}
+
+class _EditEntryRatingDialogState extends State<EditEntryRatingDialog> {
+ late _RatingAction _action;
+ late int _rating;
+
+ @override
+ void initState() {
+ super.initState();
+ final entryRating = widget.entry.rating;
+ switch (entryRating) {
+ case -1:
+ _action = _RatingAction.rejected;
+ _rating = 0;
+ case 0:
+ _action = _RatingAction.unrated;
+ _rating = 0;
+ default:
+ _action = _RatingAction.set;
+ _rating = entryRating;
+ }
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return MediaQueryDataProvider(
+ child: TooltipTheme(
+ data: TooltipTheme.of(context).copyWith(
+ preferBelow: false,
+ ),
+ child: Builder(builder: (context) {
+ final l10n = context.l10n;
+
+ return AvesDialog(
+ title: l10n.editEntryRatingDialogTitle,
+ scrollableContent: [
+ RadioListTile<_RatingAction>(
+ value: _RatingAction.set,
+ groupValue: _action,
+ onChanged: (v) => setState(() => _action = v!),
+ title: Wrap(
+ children: [
+ ...List.generate(5, (i) {
+ final thisRating = i + 1;
+ final disabled = _rating < thisRating;
+ return GestureDetector(
+ onTap: () => setState(() {
+ _action = _RatingAction.set;
+ _rating = thisRating;
+ }),
+ behavior: HitTestBehavior.opaque,
+ child: Padding(
+ padding: const EdgeInsets.all(4),
+ child: Icon(
+ AIcons.rating,
+ fill: disabled ? 0 : 1,
+ color: disabled ? AColors.starDisabled : AColors.starEnabled,
+ ),
+ ),
+ );
+ })
+ ],
+ ),
+ ),
+ RadioListTile<_RatingAction>(
+ value: _RatingAction.rejected,
+ groupValue: _action,
+ onChanged: (v) => setState(() {
+ _action = v!;
+ _rating = 0;
+ }),
+ title: Text(l10n.filterRatingRejectedLabel),
+ ),
+ RadioListTile<_RatingAction>(
+ value: _RatingAction.unrated,
+ groupValue: _action,
+ onChanged: (v) => setState(() {
+ _action = v!;
+ _rating = 0;
+ }),
+ title: Text(l10n.filterNoRatingLabel),
+ ),
+ ],
+ actions: [
+ const CancelButton(),
+ TextButton(
+ onPressed: isValid ? () => _submit(context) : null,
+ child: Text(l10n.applyButtonLabel),
+ ),
+ ],
+ );
+ }),
+ ),
+ );
+ }
+
+ bool get isValid => !(_action == _RatingAction.set && _rating <= 0);
+
+ void _submit(BuildContext context) {
+ late int entryRating;
+ switch (_action) {
+ case _RatingAction.set:
+ entryRating = _rating;
+ case _RatingAction.rejected:
+ entryRating = -1;
+ case _RatingAction.unrated:
+ entryRating = 0;
+ }
+ Navigator.maybeOf(context)?.pop(entryRating);
+ }
+}
+
+enum _RatingAction { set, rejected, unrated }
diff --git a/lib/widgets/dialogs/entry_editors/remove_metadata_dialog.dart b/lib/widgets/dialogs/entry_editors/remove_metadata_dialog.dart
new file mode 100644
index 0000000..adebe66
--- /dev/null
+++ b/lib/widgets/dialogs/entry_editors/remove_metadata_dialog.dart
@@ -0,0 +1,158 @@
+import 'package:aves/model/settings/settings.dart';
+import 'package:aves/ref/brand_colors.dart';
+import 'package:aves/theme/colors.dart';
+import 'package:aves/theme/durations.dart';
+import 'package:aves/theme/themes.dart';
+import 'package:aves/view/view.dart';
+import 'package:aves/widgets/common/basic/text/outlined.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/common/fx/highlight_decoration.dart';
+import 'package:aves/widgets/common/identity/highlight_title.dart';
+import 'package:aves/widgets/dialogs/aves_dialog.dart';
+import 'package:aves_model/aves_model.dart';
+import 'package:collection/collection.dart';
+import 'package:flutter/material.dart';
+import 'package:provider/provider.dart';
+
+class RemoveEntryMetadataDialog extends StatefulWidget {
+ static const routeName = '/dialog/remove_entry_metadata';
+
+ final bool showJpegTypes;
+
+ const RemoveEntryMetadataDialog({
+ super.key,
+ required this.showJpegTypes,
+ });
+
+ @override
+ State<RemoveEntryMetadataDialog> createState() => _RemoveEntryMetadataDialogState();
+}
+
+class _RemoveEntryMetadataDialogState extends State<RemoveEntryMetadataDialog> {
+ late final List<MetadataType> _allOptions, _mainOptions, _moreOptions;
+ final Set<MetadataType> _types = {};
+ bool _showMore = false;
+ final ValueNotifier<bool> _isValidNotifier = ValueNotifier(false);
+
+ @override
+ void initState() {
+ super.initState();
+ _allOptions = [
+ ...MetadataTypes.common,
+ if (widget.showJpegTypes) ...MetadataTypes.jpeg,
+ ];
+ final byMain = groupBy(_allOptions, MetadataTypes.main.contains);
+ _mainOptions = (byMain[true] ?? [])..sort(_compareTypeText);
+ _moreOptions = (byMain[false] ?? [])..sort(_compareTypeText);
+ _validate();
+ }
+
+ @override
+ void dispose() {
+ _isValidNotifier.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final l10n = context.l10n;
+ final animationDuration = context.select<DurationsData, Duration>((v) => v.expansionTileAnimation);
+ return AvesDialog(
+ title: l10n.removeEntryMetadataDialogTitle,
+ scrollableContent: [
+ SwitchListTile(
+ value: _types.length == _allOptions.length,
+ onChanged: (selected) {
+ selected ? _types.addAll(_allOptions) : _types.clear();
+ setState(_validate);
+ },
+ title: Align(
+ alignment: Alignment.centerLeft,
+ child: Text(l10n.removeEntryMetadataDialogAll),
+ ),
+ ),
+ ..._mainOptions.map(_toTile),
+ if (_moreOptions.isNotEmpty)
+ Padding(
+ padding: const EdgeInsets.only(bottom: 1),
+ child: ExpansionPanelList(
+ expansionCallback: (index, isExpanded) {
+ setState(() => _showMore = isExpanded);
+ },
+ animationDuration: animationDuration,
+ expandedHeaderPadding: EdgeInsets.zero,
+ elevation: 0,
+ children: [
+ ExpansionPanel(
+ headerBuilder: (context, isExpanded) => ListTile(
+ title: Text(l10n.removeEntryMetadataDialogMore),
+ ),
+ body: Column(
+ children: _moreOptions.map(_toTile).toList(),
+ ),
+ isExpanded: _showMore,
+ canTapOnHeader: true,
+ backgroundColor: Colors.transparent,
+ ),
+ ],
+ ),
+ ),
+ ],
+ actions: [
+ const CancelButton(),
+ ValueListenableBuilder<bool>(
+ valueListenable: _isValidNotifier,
+ builder: (context, isValid, child) {
+ return TextButton(
+ onPressed: isValid ? () => _submit(context) : null,
+ child: Text(context.l10n.applyButtonLabel),
+ );
+ },
+ ),
+ ],
+ );
+ }
+
+ int _compareTypeText(MetadataType a, MetadataType b) => a.getText().compareTo(b.getText());
+
+ Widget _toTile(MetadataType type) {
+ final text = type.getText();
+ Widget child = OutlinedText(
+ textSpans: [
+ TextSpan(
+ text: text,
+ style: TextStyle(
+ shadows: HighlightTitle.shadows(context),
+ ),
+ ),
+ ],
+ outlineColor: Themes.firstLayerColor(context),
+ );
+ if (context.select<Settings, bool>((v) => v.themeColorMode == AvesThemeColorMode.polychrome)) {
+ final colors = context.watch<AvesColorsData>();
+ child = Container(
+ padding: const EdgeInsets.symmetric(horizontal: 2),
+ decoration: HighlightDecoration(
+ color: colors.fromBrandColor(BrandColors.get(text)) ?? colors.fromString(text),
+ ),
+ child: child,
+ );
+ }
+
+ return SwitchListTile(
+ value: _types.contains(type),
+ onChanged: (selected) {
+ selected ? _types.add(type) : _types.remove(type);
+ setState(_validate);
+ },
+ title: Align(
+ alignment: Alignment.centerLeft,
+ child: child,
+ ),
+ );
+ }
+
+ void _validate() => _isValidNotifier.value = _types.isNotEmpty;
+
+ void _submit(BuildContext context) => Navigator.maybeOf(context)?.pop(_types);
+}
diff --git a/lib/widgets/dialogs/entry_editors/rename_entry_dialog.dart b/lib/widgets/dialogs/entry_editors/rename_entry_dialog.dart
new file mode 100644
index 0000000..05d4f89
--- /dev/null
+++ b/lib/widgets/dialogs/entry_editors/rename_entry_dialog.dart
@@ -0,0 +1,105 @@
+import 'dart:io';
+
+import 'package:aves/model/entry/entry.dart';
+import 'package:aves/services/common/services.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/dialogs/aves_dialog.dart';
+import 'package:flutter/foundation.dart';
+import 'package:flutter/material.dart';
+
+class RenameEntryDialog extends StatefulWidget {
+ static const routeName = '/dialog/rename_entry';
+
+ final AvesEntry entry;
+
+ const RenameEntryDialog({
+ super.key,
+ required this.entry,
+ });
+
+ @override
+ State<RenameEntryDialog> createState() => _RenameEntryDialogState();
+}
+
+class _RenameEntryDialogState extends State<RenameEntryDialog> {
+ final TextEditingController _nameController = TextEditingController();
+ final ValueNotifier<bool> _isValidNotifier = ValueNotifier(false);
+
+ AvesEntry get entry => widget.entry;
+
+ @override
+ void initState() {
+ super.initState();
+ _nameController.text = entry.filenameWithoutExtension ?? entry.sourceTitle ?? '';
+ _validate();
+ }
+
+ @override
+ void dispose() {
+ _nameController.dispose();
+ _isValidNotifier.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return AvesDialog(
+ content: Row(
+ crossAxisAlignment: CrossAxisAlignment.end,
+ children: [
+ Expanded(
+ child: TextField(
+ controller: _nameController,
+ decoration: InputDecoration(
+ labelText: context.l10n.renameEntryDialogLabel,
+ ),
+ autofocus: true,
+ maxLines: null,
+ onChanged: (_) => _validate(),
+ onSubmitted: (_) => _submit(context),
+ ),
+ ),
+ Padding(
+ padding: const EdgeInsetsDirectional.only(start: 4, bottom: 12),
+ child: Text(
+ '${Unicode.FSI}${entry.extension}${Unicode.PDI}',
+ style: TextStyle(color: Theme.of(context).hintColor),
+ ),
+ ),
+ ],
+ ),
+ actions: [
+ const CancelButton(),
+ ValueListenableBuilder<bool>(
+ valueListenable: _isValidNotifier,
+ builder: (context, isValid, child) {
+ return TextButton(
+ onPressed: isValid ? () => _submit(context) : null,
+ child: Text(context.l10n.applyButtonLabel),
+ );
+ },
+ ),
+ ],
+ );
+ }
+
+ String _buildEntryPath(String name) {
+ if (name.isEmpty) return '';
+ return pContext.join(entry.directory!, '$name${entry.extension}');
+ }
+
+ String get newName => _nameController.text.trimLeft().replaceAll('\n', '');
+
+ Future<void> _validate() async {
+ final _newName = newName;
+ final path = _buildEntryPath(_newName);
+ final exists = _newName.isNotEmpty && await FileSystemEntity.type(path) != FileSystemEntityType.notFound;
+ _isValidNotifier.value = _newName.isNotEmpty && !exists;
+ }
+
+ void _submit(BuildContext context) {
+ if (_isValidNotifier.value) {
+ Navigator.maybeOf(context)?.pop(newName);
+ }
+ }
+}
diff --git a/lib/widgets/dialogs/entry_editors/rename_entry_set_page.dart b/lib/widgets/dialogs/entry_editors/rename_entry_set_page.dart
new file mode 100644
index 0000000..85f1d81
--- /dev/null
+++ b/lib/widgets/dialogs/entry_editors/rename_entry_set_page.dart
@@ -0,0 +1,256 @@
+import 'dart:math';
+
+import 'package:aves/model/entry/entry.dart';
+import 'package:aves/model/naming_pattern.dart';
+import 'package:aves/model/settings/enums/accessibility_animations.dart';
+import 'package:aves/model/settings/settings.dart';
+import 'package:aves/theme/icons.dart';
+import 'package:aves/theme/styles.dart';
+import 'package:aves/view/view.dart';
+import 'package:aves/widgets/collection/collection_grid.dart';
+import 'package:aves/widgets/common/basic/font_size_icon_theme.dart';
+import 'package:aves/widgets/common/basic/popup/expansion_panel.dart';
+import 'package:aves/widgets/common/basic/popup/menu_row.dart';
+import 'package:aves/widgets/common/basic/scaffold.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/common/grid/theme.dart';
+import 'package:aves/widgets/common/identity/buttons/outlined_button.dart';
+import 'package:aves/widgets/common/thumbnail/decorated.dart';
+import 'package:aves_model/aves_model.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter/scheduler.dart';
+import 'package:provider/provider.dart';
+
+class RenameEntrySetPage extends StatefulWidget {
+ static const routeName = '/rename_entry_set';
+
+ final List<AvesEntry> entries;
+
+ const RenameEntrySetPage({
+ super.key,
+ required this.entries,
+ });
+
+ @override
+ State<RenameEntrySetPage> createState() => _RenameEntrySetPageState();
+}
+
+class _RenameEntrySetPageState extends State<RenameEntrySetPage> {
+ final TextEditingController _patternTextController = TextEditingController();
+ final ValueNotifier<NamingPattern> _namingPatternNotifier = ValueNotifier<NamingPattern>(const NamingPattern([]));
+ late final String locale;
+
+ static const int previewMax = 10;
+ static const double thumbnailExtent = 48;
+
+ List<AvesEntry> get entries => widget.entries;
+
+ int get entryCount => entries.length;
+
+ @override
+ void initState() {
+ super.initState();
+ _patternTextController.text = settings.entryRenamingPattern;
+ _patternTextController.addListener(_onUserPatternChanged);
+
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ locale = context.locale;
+ _onUserPatternChanged();
+ });
+ }
+
+ @override
+ void dispose() {
+ _patternTextController.dispose();
+ _namingPatternNotifier.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final l10n = context.l10n;
+ final textScaler = MediaQuery.textScalerOf(context);
+ final effectiveThumbnailExtent = max(thumbnailExtent, textScaler.scale(thumbnailExtent));
+ final animations = context.select<Settings, AccessibilityAnimations>((v) => v.accessibilityAnimations);
+ return AvesScaffold(
+ appBar: AppBar(
+ title: Text(l10n.renameEntrySetPageTitle),
+ ),
+ body: SafeArea(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Padding(
+ padding: const EdgeInsets.all(8),
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.end,
+ children: [
+ Expanded(
+ child: TextField(
+ controller: _patternTextController,
+ decoration: InputDecoration(
+ labelText: l10n.renameEntrySetPagePatternFieldLabel,
+ ),
+ autofocus: true,
+ ),
+ ),
+ FontSizeIconTheme(
+ child: PopupMenuButton<String>(
+ itemBuilder: (context) {
+ return [
+ PopupMenuItem(
+ value: NameNamingProcessor.key,
+ child: MenuRow(text: l10n.renameProcessorName, icon: const Icon(AIcons.name)),
+ ),
+ PopupMenuItem(
+ value: CounterNamingProcessor.key,
+ child: MenuRow(text: l10n.renameProcessorCounter, icon: const Icon(AIcons.counter)),
+ ),
+ PopupMenuItem(
+ value: DateNamingProcessor.key,
+ child: MenuRow(text: l10n.viewerInfoLabelDate, icon: const Icon(AIcons.date)),
+ ),
+ PopupMenuItem(
+ value: TagsNamingProcessor.key,
+ child: MenuRow(text: l10n.tagPageTitle, icon: const Icon(AIcons.tag)),
+ ),
+ PopupMenuExpansionPanel<String>(
+ value: MetadataFieldNamingProcessor.key,
+ icon: AIcons.more,
+ title: MaterialLocalizations.of(context).moreButtonTooltip,
+ items: [
+ ...[
+ MetadataField.exifMake,
+ MetadataField.exifModel,
+ ].map((field) => PopupMenuItem(
+ value: MetadataFieldNamingProcessor.keyWithField(field),
+ child: MenuRow(text: field.title),
+ )),
+ PopupMenuItem(
+ value: HashNamingProcessor.key,
+ child: MenuRow(text: l10n.renameProcessorHash),
+ )
+ ],
+ ),
+ ];
+ },
+ onSelected: (key) async {
+ // wait for the popup menu to hide before proceeding with the action
+ await Future.delayed(animations.popUpAnimationDelay * timeDilation);
+ _insertProcessor(key);
+ },
+ tooltip: l10n.renameEntrySetPageInsertTooltip,
+ icon: const Icon(AIcons.add),
+ popUpAnimationStyle: animations.popUpAnimationStyle,
+ ),
+ ),
+ ],
+ ),
+ ),
+ const Divider(),
+ Padding(
+ padding: const EdgeInsets.all(16),
+ child: Text(
+ l10n.renameEntrySetPagePreviewSectionTitle,
+ style: AStyles.knownTitleText,
+ ),
+ ),
+ Expanded(
+ child: GridTheme(
+ extent: effectiveThumbnailExtent,
+ child: ListView.separated(
+ physics: const NeverScrollableScrollPhysics(),
+ padding: const EdgeInsets.symmetric(vertical: 12),
+ itemBuilder: (context, index) {
+ final entry = entries[index];
+ final sourceName = entry.filenameWithoutExtension ?? '';
+ return Row(
+ children: [
+ DecoratedThumbnail(
+ entry: entry,
+ tileExtent: effectiveThumbnailExtent,
+ selectable: false,
+ highlightable: false,
+ ),
+ const SizedBox(width: 8),
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Text(
+ sourceName,
+ style: TextStyle(color: Theme.of(context).colorScheme.onSurfaceVariant),
+ softWrap: false,
+ overflow: TextOverflow.fade,
+ maxLines: 1,
+ ),
+ const SizedBox(height: 4),
+ ValueListenableBuilder<NamingPattern>(
+ valueListenable: _namingPatternNotifier,
+ builder: (context, pattern, child) {
+ return FutureBuilder<String>(
+ future: pattern.apply(entry, index),
+ builder: (context, snapshot) {
+ final info = snapshot.data;
+ return Text(
+ info ?? '…',
+ softWrap: false,
+ overflow: TextOverflow.fade,
+ maxLines: 1,
+ );
+ },
+ );
+ },
+ ),
+ ],
+ ),
+ ),
+ ],
+ );
+ },
+ separatorBuilder: (context, index) => const SizedBox(
+ height: CollectionGrid.fixedExtentLayoutSpacing,
+ ),
+ itemCount: min(entryCount, previewMax),
+ ),
+ ),
+ ),
+ const Divider(height: 0),
+ Center(
+ child: Padding(
+ padding: const EdgeInsets.all(8),
+ child: AvesOutlinedButton(
+ label: l10n.entryActionRename,
+ onPressed: () {
+ settings.entryRenamingPattern = _patternTextController.text;
+ Navigator.maybeOf(context)?.pop<NamingPattern>(_namingPatternNotifier.value);
+ },
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+
+ void _onUserPatternChanged() {
+ _namingPatternNotifier.value = NamingPattern.from(
+ userPattern: _patternTextController.text,
+ entryCount: entryCount,
+ locale: locale,
+ );
+ }
+
+ void _insertProcessor(String key) {
+ final userPattern = _patternTextController.text;
+ final selection = _patternTextController.selection;
+ _patternTextController.value = _patternTextController.value.replaced(
+ TextRange(
+ start: NamingPattern.getInsertionOffset(userPattern, selection.start),
+ end: NamingPattern.getInsertionOffset(userPattern, selection.end),
+ ),
+ NamingPattern.defaultPatternFor(key),
+ );
+ }
+}
diff --git a/lib/widgets/dialogs/entry_editors/tag_editor_page.dart b/lib/widgets/dialogs/entry_editors/tag_editor_page.dart
new file mode 100644
index 0000000..97efae4
--- /dev/null
+++ b/lib/widgets/dialogs/entry_editors/tag_editor_page.dart
@@ -0,0 +1,379 @@
+import 'package:aves/model/entry/entry.dart';
+import 'package:aves/model/filters/covered/tag.dart';
+import 'package:aves/model/filters/filters.dart';
+import 'package:aves/model/filters/placeholder.dart';
+import 'package:aves/model/settings/settings.dart';
+import 'package:aves/model/source/collection_source.dart';
+import 'package:aves/theme/durations.dart';
+import 'package:aves/theme/icons.dart';
+import 'package:aves/theme/themes.dart';
+import 'package:aves/widgets/common/basic/scaffold.dart';
+import 'package:aves/widgets/common/expandable_filter_row.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/common/identity/aves_filter_chip.dart';
+import 'package:aves/widgets/dialogs/aves_dialog.dart';
+import 'package:flutter/material.dart';
+import 'package:provider/provider.dart';
+
+class TagEditorPage extends StatefulWidget {
+ static const routeName = '/info/tag_editor';
+
+ final Map<AvesEntry, Set<TagFilter>> tagsByEntry;
+
+ const TagEditorPage({
+ super.key,
+ required this.tagsByEntry,
+ });
+
+ @override
+ State<TagEditorPage> createState() => _TagEditorPageState();
+}
+
+class _TagEditorPageState extends State<TagEditorPage> {
+ final TextEditingController _newTagTextController = TextEditingController();
+ final FocusNode _newTagTextFocusNode = FocusNode();
+ final ValueNotifier<String?> _expandedSectionNotifier = ValueNotifier(null);
+ late final Map<AvesEntry, Set<CollectionFilter>> filtersByEntry;
+ late final List<CollectionFilter> _topTags;
+ final List<CollectionFilter> _userAddedFilters = [];
+
+ static final List<PlaceholderFilter> _placeholders = [
+ PlaceholderFilter.country,
+ PlaceholderFilter.state,
+ PlaceholderFilter.place,
+ ];
+
+ @override
+ void initState() {
+ super.initState();
+ filtersByEntry = widget.tagsByEntry.map((key, value) => MapEntry(key, value.cast<CollectionFilter>().toSet()));
+ _expandedSectionNotifier.value = settings.tagEditorExpandedSection;
+ _expandedSectionNotifier.addListener(() => settings.tagEditorExpandedSection = _expandedSectionNotifier.value);
+ _initTopTags();
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ final source = context.read<CollectionSource?>();
+ settings.removeObsoleteRecentTags(source);
+ });
+ }
+
+ @override
+ void dispose() {
+ _newTagTextController.dispose();
+ _newTagTextFocusNode.dispose();
+ _expandedSectionNotifier.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final l10n = context.l10n;
+ final showCount = filtersByEntry.length > 1;
+ final Map<CollectionFilter, int> entryCountByTag = {};
+ filtersByEntry.entries.forEach((kv) {
+ kv.value.forEach((tag) => entryCountByTag[tag] = (entryCountByTag[tag] ?? 0) + 1);
+ });
+ List<MapEntry<CollectionFilter, int>> sortedTags = _sortCurrentTags(entryCountByTag);
+
+ final untaggedColor = Themes.backgroundTextColor(context);
+
+ return PopScope(
+ canPop: !_isModified,
+ onPopInvokedWithResult: (didPop, result) async {
+ if (didPop) return;
+
+ final NavigatorState navigator = Navigator.of(context);
+ final confirmed = await showDialog<bool>(
+ context: context,
+ builder: (context) => AvesDialog(
+ content: Text(context.l10n.tagEditorDiscardDialogMessage),
+ actions: [
+ const CancelButton(),
+ TextButton(
+ onPressed: () => Navigator.maybeOf(context)?.pop(true),
+ child: Text(Themes.asButtonLabel(MaterialLocalizations.of(context).okButtonLabel)),
+ ),
+ ],
+ ),
+ routeSettings: const RouteSettings(name: AvesDialog.warningRouteName),
+ ) ??
+ false;
+ if (confirmed) {
+ navigator.pop();
+ }
+ },
+ child: AvesScaffold(
+ appBar: AppBar(
+ title: Text(l10n.tagEditorPageTitle),
+ actions: [
+ IconButton(
+ icon: const Icon(AIcons.reset),
+ onPressed: _reset,
+ tooltip: l10n.resetTooltip,
+ ),
+ IconButton(
+ icon: const Icon(AIcons.apply),
+ onPressed: () => Navigator.maybeOf(context)?.pop(filtersByEntry),
+ tooltip: l10n.saveTooltip,
+ ),
+ const SizedBox(width: 16),
+ ],
+ ),
+ body: SafeArea(
+ child: ValueListenableBuilder<String?>(
+ valueListenable: _expandedSectionNotifier,
+ builder: (context, expandedSection, child) {
+ return ValueListenableBuilder<TextEditingValue>(
+ valueListenable: _newTagTextController,
+ builder: (context, value, child) {
+ final upQuery = value.text.trim().toUpperCase();
+ bool containQuery(CollectionFilter v) => v.getLabel(context).toUpperCase().contains(upQuery);
+ final recentFilters = settings.recentTags.where(containQuery).toList();
+ final topTagFilters = _topTags.where(containQuery).toList();
+ final placeholderFilters = _placeholders.where(containQuery).toList();
+ return ListView(
+ children: [
+ Padding(
+ padding: const EdgeInsetsDirectional.only(start: 8, end: 16),
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.end,
+ children: [
+ Expanded(
+ child: TextField(
+ controller: _newTagTextController,
+ focusNode: _newTagTextFocusNode,
+ decoration: InputDecoration(
+ labelText: l10n.tagEditorPageNewTagFieldLabel,
+ ),
+ autofocus: true,
+ onSubmitted: (newTag) {
+ _addCustomTag(newTag);
+ _newTagTextFocusNode.requestFocus();
+ },
+ ),
+ ),
+ ValueListenableBuilder<TextEditingValue>(
+ valueListenable: _newTagTextController,
+ builder: (context, value, child) {
+ return IconButton(
+ icon: const Icon(AIcons.add),
+ onPressed: value.text.trim().isEmpty ? null : () => _addCustomTag(_newTagTextController.text),
+ tooltip: l10n.tagEditorPageAddTagTooltip,
+ );
+ },
+ ),
+ Selector<Settings, bool>(
+ selector: (context, s) => s.tagEditorCurrentFilterSectionExpanded,
+ builder: (context, isExpanded, child) {
+ return IconButton(
+ icon: Icon(isExpanded ? AIcons.collapse : AIcons.expand),
+ onPressed: sortedTags.isEmpty ? null : () => settings.tagEditorCurrentFilterSectionExpanded = !isExpanded,
+ tooltip: isExpanded ? MaterialLocalizations.of(context).expandedIconTapHint : MaterialLocalizations.of(context).collapsedIconTapHint,
+ );
+ },
+ ),
+ ],
+ ),
+ ),
+ Padding(
+ padding: const EdgeInsets.symmetric(vertical: 16),
+ child: AnimatedCrossFade(
+ firstChild: ConstrainedBox(
+ constraints: const BoxConstraints(minHeight: AvesFilterChip.minChipHeight),
+ child: Center(
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Icon(AIcons.tagUntagged, color: untaggedColor),
+ const SizedBox(width: 8),
+ Text(
+ l10n.filterNoTagLabel,
+ style: TextStyle(color: untaggedColor),
+ ),
+ ],
+ ),
+ ),
+ ),
+ secondChild: ExpandableFilterRow(
+ filters: sortedTags.map((kv) => kv.key).toList(),
+ isExpanded: context.select<Settings, bool>((v) => v.tagEditorCurrentFilterSectionExpanded),
+ showGenericIcon: false,
+ leadingBuilder: showCount
+ ? (filter) => _TagCount(
+ count: sortedTags.firstWhere((kv) => kv.key == filter).value,
+ )
+ : null,
+ onTap: (filter) {
+ if (filtersByEntry.keys.length > 1) {
+ // for multiple entries, set tag for all of them
+ filtersByEntry.forEach((entry, filters) => filters.add(filter));
+ setState(() {});
+ } else {
+ // for single entry, remove tag (like pressing on the remove icon)
+ _removeTag(filter);
+ }
+ },
+ onRemove: _removeTag,
+ onLongPress: null,
+ ),
+ crossFadeState: sortedTags.isEmpty ? CrossFadeState.showFirst : CrossFadeState.showSecond,
+ duration: ADurations.tagEditorTransition,
+ ),
+ ),
+ const Divider(height: 0),
+ _FilterRow(
+ title: l10n.statsTopTagsSectionTitle,
+ filters: topTagFilters,
+ expandedNotifier: _expandedSectionNotifier,
+ onTap: _addTag,
+ ),
+ _FilterRow(
+ title: l10n.tagEditorSectionRecent,
+ filters: recentFilters,
+ expandedNotifier: _expandedSectionNotifier,
+ onTap: _addTag,
+ ),
+ _FilterRow(
+ title: l10n.tagEditorSectionPlaceholders,
+ filters: placeholderFilters,
+ expandedNotifier: _expandedSectionNotifier,
+ onTap: _addTag,
+ ),
+ ],
+ );
+ },
+ );
+ },
+ ),
+ ),
+ ),
+ );
+ }
+
+ void _initTopTags() {
+ final Map<String, int> entryCountByTag = {};
+ final visibleEntries = context.read<CollectionSource?>()?.visibleEntries;
+ visibleEntries?.forEach((entry) {
+ entry.tags.forEach((tag) => entryCountByTag[tag] = (entryCountByTag[tag] ?? 0) + 1);
+ });
+ List<MapEntry<CollectionFilter, int>> sortedTopTags = _sortCurrentTags(entryCountByTag.map((key, value) => MapEntry(TagFilter(key), value)));
+ _topTags = sortedTopTags.map((kv) => kv.key).toList();
+ }
+
+ List<MapEntry<CollectionFilter, int>> _sortCurrentTags(Map<CollectionFilter, int> entryCountByTag) {
+ return entryCountByTag.entries.toList()
+ ..sort((kv1, kv2) {
+ final filter1 = kv1.key;
+ final filter2 = kv2.key;
+
+ final recent1 = _userAddedFilters.indexOf(filter1);
+ final recent2 = _userAddedFilters.indexOf(filter2);
+ var c = recent2.compareTo(recent1);
+ if (c != 0) return c;
+
+ final count1 = kv1.value;
+ final count2 = kv2.value;
+ c = count2.compareTo(count1);
+ if (c != 0) return c;
+
+ return filter1.compareTo(filter2);
+ });
+ }
+
+ bool get _isModified {
+ for (final kv in filtersByEntry.entries) {
+ final oldFilters = kv.key.tags.map(TagFilter.new).toSet();
+ final newFilters = kv.value;
+ if (newFilters.length != oldFilters.length || !newFilters.containsAll(oldFilters)) return true;
+ }
+ return false;
+ }
+
+ void _reset() {
+ _userAddedFilters.clear();
+ filtersByEntry.forEach((entry, tags) {
+ final originalFilters = entry.tags.map(TagFilter.new).toSet();
+ tags
+ ..clear()
+ ..addAll(originalFilters);
+ });
+ setState(() {});
+ }
+
+ void _addCustomTag(String newTag) {
+ newTag = newTag.trim();
+ if (newTag.isNotEmpty) {
+ _addTag(TagFilter(newTag));
+ }
+ }
+
+ void _addTag(CollectionFilter filter) {
+ settings.recentTags = settings.recentTags
+ ..remove(filter)
+ ..insert(0, filter);
+ _userAddedFilters
+ ..remove(filter)
+ ..add(filter);
+ filtersByEntry.forEach((entry, tags) => tags.add(filter));
+ _newTagTextController.clear();
+ setState(() {});
+ }
+
+ void _removeTag(CollectionFilter filter) {
+ _userAddedFilters.remove(filter);
+ filtersByEntry.forEach((entry, filters) => filters.remove(filter));
+ setState(() {});
+ }
+}
+
+class _FilterRow extends StatelessWidget {
+ final String title;
+ final List<CollectionFilter> filters;
+ final ValueNotifier<String?> expandedNotifier;
+ final void Function(CollectionFilter filter) onTap;
+
+ const _FilterRow({
+ required this.title,
+ required this.filters,
+ required this.expandedNotifier,
+ required this.onTap,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ return filters.isEmpty
+ ? const SizedBox()
+ : TitledExpandableFilterRow(
+ title: title,
+ filters: filters,
+ expandedNotifier: expandedNotifier,
+ showGenericIcon: false,
+ onTap: onTap,
+ onLongPress: null,
+ );
+ }
+}
+
+class _TagCount extends StatelessWidget {
+ final int count;
+
+ const _TagCount({
+ required this.count,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ return Container(
+ padding: const EdgeInsets.symmetric(vertical: 2, horizontal: 6),
+ decoration: BoxDecoration(
+ border: Border.fromBorderSide(BorderSide(
+ color: DefaultTextStyle.of(context).style.color!,
+ )),
+ borderRadius: const BorderRadius.all(Radius.circular(123)),
+ ),
+ child: Text(
+ '$count',
+ style: const TextStyle(fontSize: AvesFilterChip.fontSize),
+ ),
+ );
+ }
+}
diff --git a/lib/widgets/dialogs/filter_editors/cover_selection_dialog.dart b/lib/widgets/dialogs/filter_editors/cover_selection_dialog.dart
new file mode 100644
index 0000000..11ffb00
--- /dev/null
+++ b/lib/widgets/dialogs/filter_editors/cover_selection_dialog.dart
@@ -0,0 +1,458 @@
+import 'dart:math';
+
+import 'package:aves/image_providers/app_icon_image_provider.dart';
+import 'package:aves/model/entry/entry.dart';
+import 'package:aves/model/filters/covered/stored_album.dart';
+import 'package:aves/model/filters/filters.dart';
+import 'package:aves/model/settings/settings.dart';
+import 'package:aves/model/source/collection_lens.dart';
+import 'package:aves/model/source/collection_source.dart';
+import 'package:aves/theme/icons.dart';
+import 'package:aves/widgets/common/basic/color_indicator.dart';
+import 'package:aves/widgets/common/basic/list_tiles/color.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/common/fx/borders.dart';
+import 'package:aves/widgets/dialogs/aves_dialog.dart';
+import 'package:aves/widgets/dialogs/item_picker.dart';
+import 'package:aves/widgets/dialogs/pick_dialogs/app_pick_page.dart';
+import 'package:aves/widgets/dialogs/pick_dialogs/item_pick_page.dart';
+import 'package:aves_model/aves_model.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter/rendering.dart';
+import 'package:provider/provider.dart';
+
+class CoverSelectionDialog extends StatefulWidget {
+ static const routeName = '/dialog/select_cover';
+
+ final CollectionFilter filter;
+ final AvesEntry? customEntry;
+ final String? customPackage;
+ final Color? customColor;
+
+ const CoverSelectionDialog({
+ super.key,
+ required this.filter,
+ required this.customEntry,
+ required this.customPackage,
+ required this.customColor,
+ });
+
+ @override
+ State<CoverSelectionDialog> createState() => _CoverSelectionDialogState();
+}
+
+class _CoverSelectionDialogState extends State<CoverSelectionDialog> {
+ late bool _isCustomEntry, _isCustomPackage, _isCustomColor;
+ AvesEntry? _customEntry;
+ String? _customPackage;
+ Color? _customColor;
+
+ CollectionFilter get filter => widget.filter;
+
+ bool get showAppTab => filter is StoredAlbumFilter && settings.isInstalledAppAccessAllowed;
+
+ bool get showColorTab => settings.themeColorMode == AvesThemeColorMode.polychrome;
+
+ static const double itemPickerExtent = 46;
+ static const double appPickerExtent = 32;
+
+ double tabBarHeight(BuildContext context) {
+ return MediaQuery.textScalerOf(context).clamp(minScaleFactor: 1).scale(64);
+ }
+
+ static const double tabIndicatorWeight = 2;
+
+ @override
+ void initState() {
+ super.initState();
+
+ _customEntry = widget.customEntry;
+ _isCustomEntry = _customEntry != null;
+
+ _customPackage = widget.customPackage;
+ _isCustomPackage = _customPackage != null;
+
+ _customColor = widget.customColor;
+ _isCustomColor = _customColor != null;
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final l10n = context.l10n;
+ final tabs = <(Tab, Widget)>[
+ (
+ _buildTab(
+ context,
+ const Key('tab-entry'),
+ AIcons.image,
+ l10n.coverDialogTabCover,
+ ),
+ Column(children: _buildEntryOptions()),
+ ),
+ if (showAppTab)
+ (
+ _buildTab(
+ context,
+ const Key('tab-package'),
+ AIcons.app,
+ l10n.coverDialogTabApp,
+ ),
+ Column(children: _buildAppOptions()),
+ ),
+ if (showColorTab)
+ (
+ _buildTab(
+ context,
+ const Key('tab-color'),
+ AIcons.palette,
+ l10n.coverDialogTabColor,
+ ),
+ Column(children: _buildColorOptions()),
+ ),
+ ];
+
+ final contentWidget = DecoratedBox(
+ decoration: AvesDialog.contentDecoration(context),
+ child: LayoutBuilder(
+ builder: (context, constraints) {
+ final availableBodyHeight = constraints.maxHeight - tabBarHeight(context) - tabIndicatorWeight;
+ final maxHeight = min(availableBodyHeight, tabBodyMaxHeight(context));
+ return DefaultTabController(
+ length: 1 + (showAppTab ? 1 : 0) + (showColorTab ? 1 : 0),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Material(
+ borderRadius: const BorderRadius.vertical(
+ top: AvesDialog.cornerRadius,
+ ),
+ clipBehavior: Clip.antiAlias,
+ child: TabBar(
+ indicatorWeight: tabIndicatorWeight,
+ tabs: tabs.map((t) => t.$1).toList(),
+ ),
+ ),
+ ConstrainedBox(
+ constraints: BoxConstraints(maxHeight: maxHeight),
+ child: TabBarView(
+ physics: const NeverScrollableScrollPhysics(),
+ children: tabs
+ .map((t) => SingleChildScrollView(
+ child: t.$2,
+ ))
+ .toList(),
+ ),
+ ),
+ ],
+ ),
+ );
+ },
+ ),
+ );
+
+ final actionsWidget = Padding(
+ padding: AvesDialog.actionsPadding,
+ child: OverflowBar(
+ alignment: MainAxisAlignment.end,
+ spacing: AvesDialog.buttonPadding.horizontal / 2,
+ overflowAlignment: OverflowBarAlignment.end,
+ children: [
+ const CancelButton(),
+ TextButton(
+ onPressed: () {
+ final entry = _isCustomEntry ? _customEntry : null;
+ final package = _isCustomPackage ? _customPackage : null;
+ final color = _isCustomColor ? _customColor : null;
+ return Navigator.maybeOf(context)?.pop<(AvesEntry?, String?, Color?)>((entry, package, color));
+ },
+ child: Text(l10n.applyButtonLabel),
+ )
+ ],
+ ),
+ );
+
+ Widget dialogChild = LayoutBuilder(
+ builder: (context, constraints) {
+ final availableBodyWidth = constraints.maxWidth;
+ final maxWidth = min(availableBodyWidth, tabBodyMaxWidth(context));
+ return ConstrainedBox(
+ constraints: BoxConstraints(maxWidth: maxWidth),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ Flexible(child: contentWidget),
+ actionsWidget,
+ ],
+ ),
+ );
+ },
+ );
+
+ return Dialog(
+ shape: AvesDialog.shape(context),
+ child: dialogChild,
+ );
+ }
+
+ List<Widget> _buildEntryOptions() {
+ final l10n = context.l10n;
+ return [false, true].map(
+ (isCustom) {
+ final title = Text(
+ isCustom ? l10n.setCoverDialogCustom : l10n.setCoverDialogLatest,
+ softWrap: false,
+ overflow: TextOverflow.fade,
+ maxLines: 1,
+ );
+ return ListTileTheme.merge(
+ minVerticalPadding: isCustom && _customEntry != null ? 0 : null,
+ child: RadioListTile<bool>(
+ value: isCustom,
+ groupValue: _isCustomEntry,
+ onChanged: (v) {
+ if (v == null) return;
+ if (v && _customEntry == null) {
+ _pickEntry();
+ return;
+ }
+ _isCustomEntry = v;
+ setState(() {});
+ },
+ title: isCustom
+ ? Row(
+ children: [
+ title,
+ const Spacer(),
+ if (_customEntry != null)
+ ItemPicker(
+ extent: itemPickerExtent,
+ entry: _customEntry!,
+ onTap: _pickEntry,
+ ),
+ ],
+ )
+ : title,
+ ),
+ );
+ },
+ ).toList();
+ }
+
+ List<Widget> _buildAppOptions() {
+ final l10n = context.l10n;
+ return [false, true].map(
+ (isCustom) {
+ final title = Text(
+ isCustom ? l10n.setCoverDialogCustom : l10n.setCoverDialogAuto,
+ softWrap: false,
+ overflow: TextOverflow.fade,
+ maxLines: 1,
+ );
+ return RadioListTile<bool>(
+ value: isCustom,
+ groupValue: _isCustomPackage,
+ onChanged: (v) {
+ if (v == null) return;
+ if (v && _customPackage == null) {
+ _pickPackage();
+ return;
+ }
+ _isCustomPackage = v;
+ setState(() {});
+ },
+ title: isCustom
+ ? Row(
+ children: [
+ title,
+ const Spacer(),
+ if (_customPackage != null)
+ GestureDetector(
+ onTap: _pickPackage,
+ child: _customPackage!.isNotEmpty
+ ? Image(
+ image: AppIconImage(
+ packageName: _customPackage!,
+ size: appPickerExtent,
+ ),
+ width: appPickerExtent,
+ height: appPickerExtent,
+ )
+ : Container(
+ height: appPickerExtent,
+ width: appPickerExtent,
+ decoration: BoxDecoration(
+ border: AvesBorder.border(context),
+ shape: BoxShape.circle,
+ ),
+ child: const Icon(AIcons.clear),
+ ),
+ ),
+ ],
+ )
+ : title,
+ );
+ },
+ ).toList();
+ }
+
+ List<Widget> _buildColorOptions() {
+ final l10n = context.l10n;
+ return [false, true].map(
+ (isCustom) {
+ final title = Text(
+ isCustom ? l10n.setCoverDialogCustom : l10n.setCoverDialogAuto,
+ softWrap: false,
+ overflow: TextOverflow.fade,
+ maxLines: 1,
+ );
+ return RadioListTile<bool>(
+ value: isCustom,
+ groupValue: _isCustomColor,
+ onChanged: (v) {
+ if (v == null) return;
+ if (v && _customColor == null) {
+ _pickColor();
+ return;
+ }
+ _isCustomColor = v;
+ setState(() {});
+ },
+ title: isCustom
+ ? Row(
+ children: [
+ title,
+ const Spacer(),
+ if (_customColor != null)
+ GestureDetector(
+ onTap: _pickColor,
+ child: ColorIndicator(
+ value: _customColor,
+ ),
+ ),
+ ],
+ )
+ : title,
+ );
+ },
+ ).toList();
+ }
+
+ Future<void> _pickEntry() async {
+ final entry = await Navigator.maybeOf(context)?.push<AvesEntry>(
+ MaterialPageRoute(
+ settings: const RouteSettings(name: ItemPickPage.routeName),
+ builder: (context) => ItemPickPage(
+ collection: CollectionLens(
+ source: context.read<CollectionSource>(),
+ filters: {filter},
+ ),
+ canRemoveFilters: false,
+ ),
+ fullscreenDialog: true,
+ ),
+ );
+ if (entry != null) {
+ _customEntry = entry;
+ _isCustomEntry = true;
+ setState(() {});
+ }
+ }
+
+ Future<void> _pickPackage() async {
+ final package = await Navigator.maybeOf(context)?.push<String>(
+ MaterialPageRoute(
+ settings: const RouteSettings(name: AppPickPage.routeName),
+ builder: (context) => AppPickPage(
+ initialValue: _customPackage,
+ ),
+ fullscreenDialog: true,
+ ),
+ );
+ if (package != null) {
+ _customPackage = package;
+ _isCustomPackage = true;
+ setState(() {});
+ }
+ }
+
+ Future<void> _pickColor() async {
+ final color = await showDialog<Color>(
+ context: context,
+ builder: (context) => ColorPickerDialog(
+ // avoid a pure material color as the default, so that
+ // picker controls are not on edge and palette panel is more stable
+ initialValue: _customColor ?? const Color(0xff3f51b5),
+ ),
+ routeSettings: const RouteSettings(name: ColorPickerDialog.routeName),
+ );
+ if (color != null) {
+ _customColor = color;
+ _isCustomColor = true;
+ setState(() {});
+ }
+ }
+
+ // tabs
+
+ Tab _buildTab(
+ BuildContext context,
+ Key key,
+ IconData icon,
+ String text, {
+ Color? color,
+ }) {
+ // cannot use `IconTheme` over `TabBar` to change size,
+ // because `TabBar` does so internally
+ final textScaler = MediaQuery.textScalerOf(context);
+ final iconSize = textScaler.scale(IconTheme.of(context).size!);
+ return Tab(
+ key: key,
+ height: tabBarHeight(context),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Icon(
+ icon,
+ size: iconSize,
+ color: color,
+ ),
+ const SizedBox(height: 4),
+ Text(
+ text,
+ style: TextStyle(color: color),
+ softWrap: false,
+ overflow: TextOverflow.fade,
+ ),
+ ],
+ ),
+ );
+ }
+
+ // based on `ListTile` height computation (one line, no subtitle, not dense)
+ double singleOptionTileHeight(BuildContext context) => 56.0 + Theme.of(context).visualDensity.baseSizeAdjustment.dy;
+
+ double tabBodyMaxWidth(BuildContext context) {
+ final l10n = context.l10n;
+ final _optionLines = {
+ l10n.setCoverDialogLatest,
+ l10n.setCoverDialogAuto,
+ l10n.setCoverDialogCustom,
+ }.fold('', (previousValue, element) => '$previousValue\n$element');
+
+ final paragraph = RenderParagraph(
+ TextSpan(text: _optionLines, style: Theme.of(context).textTheme.titleMedium!),
+ textDirection: TextDirection.ltr,
+ textScaler: MediaQuery.textScalerOf(context),
+ )..layout(const BoxConstraints(), parentUsesSize: true);
+ final textWidth = paragraph.getMaxIntrinsicWidth(double.infinity);
+ paragraph.dispose();
+
+ // from `RadioListTile` layout
+ const contentPadding = 32;
+ const leadingWidth = kMinInteractiveDimension + 8;
+ return contentPadding + leadingWidth + textWidth + itemPickerExtent;
+ }
+
+ double tabBodyMaxHeight(BuildContext context) => 2 * singleOptionTileHeight(context);
+}
diff --git a/lib/widgets/dialogs/filter_editors/create_dynamic_album_dialog.dart b/lib/widgets/dialogs/filter_editors/create_dynamic_album_dialog.dart
new file mode 100644
index 0000000..6dc3e68
--- /dev/null
+++ b/lib/widgets/dialogs/filter_editors/create_dynamic_album_dialog.dart
@@ -0,0 +1,92 @@
+import 'package:aves/model/dynamic_albums.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/dialogs/aves_dialog.dart';
+import 'package:flutter/material.dart';
+
+class CreateDynamicAlbumDialog extends StatefulWidget {
+ static const routeName = '/dialog/create_dynamic_album';
+
+ const CreateDynamicAlbumDialog({super.key});
+
+ @override
+ State<CreateDynamicAlbumDialog> createState() => _CreateDynamicAlbumDialogState();
+}
+
+class _CreateDynamicAlbumDialogState extends State<CreateDynamicAlbumDialog> {
+ final TextEditingController _nameController = TextEditingController();
+ final ValueNotifier<bool> _existsNotifier = ValueNotifier(false);
+ final ValueNotifier<bool> _isValidNotifier = ValueNotifier(false);
+
+ @override
+ void initState() {
+ super.initState();
+ _validate();
+ }
+
+ @override
+ void dispose() {
+ _nameController.dispose();
+ _existsNotifier.dispose();
+ _isValidNotifier.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final l10n = context.l10n;
+
+ return AvesDialog(
+ title: l10n.newDynamicAlbumDialogTitle,
+ content: ValueListenableBuilder<bool>(
+ valueListenable: _existsNotifier,
+ builder: (context, exists, child) {
+ return TextField(
+ controller: _nameController,
+ decoration: InputDecoration(
+ labelText: l10n.newAlbumDialogNameLabel,
+ helperText: exists ? l10n.dynamicAlbumAlreadyExists : '',
+ ),
+ autofocus: true,
+ onChanged: (_) => _validate(),
+ onSubmitted: (_) => _submit(context),
+ );
+ }),
+ actions: [
+ const CancelButton(),
+ ValueListenableBuilder<bool>(
+ valueListenable: _existsNotifier,
+ builder: (context, exists, child) {
+ return ValueListenableBuilder<bool>(
+ valueListenable: _isValidNotifier,
+ builder: (context, isValid, child) {
+ return TextButton(
+ onPressed: isValid ? () => _submit(context) : null,
+ child: Text(exists ? l10n.showButtonLabel : l10n.createAlbumButtonLabel),
+ );
+ },
+ );
+ },
+ ),
+ ],
+ );
+ }
+
+ String? _formatAlbumName() {
+ final name = _nameController.text.trim();
+ if (name.isEmpty) return null;
+
+ return name;
+ }
+
+ void _validate() {
+ final name = _formatAlbumName();
+ _isValidNotifier.value = name != null;
+ _existsNotifier.value = dynamicAlbums.contains(name);
+ }
+
+ void _submit(BuildContext context) {
+ if (_isValidNotifier.value) {
+ Navigator.maybeOf(context)?.pop(_formatAlbumName());
+ }
+ }
+}
diff --git a/lib/widgets/dialogs/filter_editors/create_group_dialog.dart b/lib/widgets/dialogs/filter_editors/create_group_dialog.dart
new file mode 100644
index 0000000..055c5fb
--- /dev/null
+++ b/lib/widgets/dialogs/filter_editors/create_group_dialog.dart
@@ -0,0 +1,99 @@
+import 'package:aves/model/grouping/common.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/dialogs/aves_dialog.dart';
+import 'package:flutter/material.dart';
+
+class CreateGroupDialog extends StatefulWidget {
+ static const routeName = '/dialog/create_group';
+
+ final FilterGrouping grouping;
+ final Uri? parentGroupUri;
+
+ const CreateGroupDialog({
+ super.key,
+ required this.grouping,
+ required this.parentGroupUri,
+ });
+
+ @override
+ State<CreateGroupDialog> createState() => _CreateGroupDialogState();
+}
+
+class _CreateGroupDialogState extends State<CreateGroupDialog> {
+ final TextEditingController _nameController = TextEditingController();
+ final ValueNotifier<bool> _existsNotifier = ValueNotifier(false);
+ final ValueNotifier<bool> _isValidNotifier = ValueNotifier(false);
+
+ FilterGrouping get grouping => widget.grouping;
+
+ Uri? get parentGroupUri => widget.parentGroupUri;
+
+ @override
+ void initState() {
+ super.initState();
+ _validate();
+ }
+
+ @override
+ void dispose() {
+ _nameController.dispose();
+ _existsNotifier.dispose();
+ _isValidNotifier.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final l10n = context.l10n;
+
+ return AvesDialog(
+ title: l10n.newGroupDialogTitle,
+ content: ValueListenableBuilder<bool>(
+ valueListenable: _existsNotifier,
+ builder: (context, exists, child) {
+ return TextField(
+ controller: _nameController,
+ decoration: InputDecoration(
+ labelText: l10n.newGroupDialogNameLabel,
+ helperText: exists ? l10n.groupAlreadyExists : '',
+ ),
+ autofocus: true,
+ onChanged: (_) => _validate(),
+ onSubmitted: (_) => _submit(context),
+ );
+ },
+ ),
+ actions: [
+ const CancelButton(),
+ ValueListenableBuilder<bool>(
+ valueListenable: _isValidNotifier,
+ builder: (context, isValid, child) {
+ return TextButton(
+ onPressed: isValid ? () => _submit(context) : null,
+ child: Text(l10n.createButtonLabel),
+ );
+ },
+ ),
+ ],
+ );
+ }
+
+ Uri? _getNewGroupUri() {
+ final name = _nameController.text.trim();
+ if (name.isEmpty) return null;
+ return grouping.buildGroupUri(parentGroupUri, name);
+ }
+
+ void _validate() {
+ final newGroupUri = _getNewGroupUri();
+ final exists = grouping.exists(newGroupUri);
+ _isValidNotifier.value = newGroupUri != null && !exists;
+ _existsNotifier.value = exists;
+ }
+
+ void _submit(BuildContext context) {
+ if (_isValidNotifier.value) {
+ Navigator.maybeOf(context)?.pop(_getNewGroupUri());
+ }
+ }
+}
diff --git a/lib/widgets/dialogs/filter_editors/create_stored_album_dialog.dart b/lib/widgets/dialogs/filter_editors/create_stored_album_dialog.dart
new file mode 100644
index 0000000..cd07ca0
--- /dev/null
+++ b/lib/widgets/dialogs/filter_editors/create_stored_album_dialog.dart
@@ -0,0 +1,204 @@
+import 'dart:io';
+
+import 'package:aves/model/source/collection_source.dart';
+import 'package:aves/services/common/services.dart';
+import 'package:aves/theme/durations.dart';
+import 'package:aves/utils/android_file_utils.dart';
+import 'package:aves/view/view.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/dialogs/aves_dialog.dart';
+import 'package:aves_model/aves_model.dart';
+import 'package:collection/collection.dart';
+import 'package:flutter/material.dart';
+import 'package:provider/provider.dart';
+
+class CreateStoredAlbumDialog extends StatefulWidget {
+ static const routeName = '/dialog/create_stored_album';
+
+ const CreateStoredAlbumDialog({super.key});
+
+ @override
+ State<CreateStoredAlbumDialog> createState() => _CreateStoredAlbumDialogState();
+}
+
+class _CreateStoredAlbumDialogState extends State<CreateStoredAlbumDialog> {
+ final ScrollController _scrollController = ScrollController();
+ final TextEditingController _nameController = TextEditingController();
+ final FocusNode _nameFieldFocusNode = FocusNode();
+ final ValueNotifier<bool> _directoryExistsNotifier = ValueNotifier(false);
+ final ValueNotifier<bool> _albumExistsNotifier = ValueNotifier(false);
+ final ValueNotifier<bool> _isValidNotifier = ValueNotifier(false);
+ late Set<StorageVolume> _allVolumes;
+ late StorageVolume? _primaryVolume, _selectedVolume;
+
+ @override
+ void initState() {
+ super.initState();
+ _allVolumes = androidFileUtils.storageVolumes;
+ _primaryVolume = _allVolumes.firstWhereOrNull((volume) => volume.isPrimary) ?? _allVolumes.firstOrNull;
+ _selectedVolume = _primaryVolume;
+ _nameFieldFocusNode.addListener(_onFocus);
+ }
+
+ @override
+ void dispose() {
+ _scrollController.dispose();
+ _nameController.dispose();
+ _nameFieldFocusNode.removeListener(_onFocus);
+ _nameFieldFocusNode.dispose();
+ _directoryExistsNotifier.dispose();
+ _isValidNotifier.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final l10n = context.l10n;
+ const contentHorizontalPadding = EdgeInsets.symmetric(horizontal: AvesDialog.defaultHorizontalContentPadding);
+
+ final volumeTiles = <Widget>[];
+ if (_allVolumes.length > 1) {
+ final byPrimary = groupBy<StorageVolume, bool>(_allVolumes, (volume) => volume.isPrimary);
+ int compare(StorageVolume a, StorageVolume b) => compareAsciiUpperCaseNatural(a.path, b.path);
+ final primaryVolumes = (byPrimary[true] ?? [])..sort(compare);
+ final otherVolumes = (byPrimary[false] ?? [])..sort(compare);
+ volumeTiles.addAll([
+ Padding(
+ padding: contentHorizontalPadding + const EdgeInsets.only(top: 20),
+ child: Text(l10n.newAlbumDialogStorageLabel),
+ ),
+ ...primaryVolumes.map((volume) => _buildVolumeTile(context, volume)),
+ ...otherVolumes.map((volume) => _buildVolumeTile(context, volume)),
+ const SizedBox(height: 8),
+ ]);
+ }
+
+ return AvesDialog(
+ title: l10n.newAlbumDialogTitle,
+ scrollController: _scrollController,
+ scrollableContent: [
+ ...volumeTiles,
+ Padding(
+ padding: contentHorizontalPadding + const EdgeInsets.only(bottom: 8),
+ child: AnimatedBuilder(
+ animation: Listenable.merge([_albumExistsNotifier, _directoryExistsNotifier]),
+ builder: (context, child) {
+ var helperText = '';
+ if (_albumExistsNotifier.value) {
+ helperText = l10n.newAlbumDialogAlbumAlreadyExistsHelper;
+ } else if (_directoryExistsNotifier.value) {
+ helperText = l10n.newAlbumDialogNameLabelAlreadyExistsHelper;
+ }
+ return TextField(
+ controller: _nameController,
+ focusNode: _nameFieldFocusNode,
+ decoration: InputDecoration(
+ labelText: l10n.newAlbumDialogNameLabel,
+ helperText: helperText,
+ ),
+ autofocus: _allVolumes.length == 1,
+ onChanged: (_) => _validate(),
+ onSubmitted: (_) => _submit(context),
+ );
+ }),
+ ),
+ ],
+ actions: [
+ const CancelButton(),
+ ValueListenableBuilder<bool>(
+ valueListenable: _albumExistsNotifier,
+ builder: (context, albumExists, child) {
+ return ValueListenableBuilder<bool>(
+ valueListenable: _isValidNotifier,
+ builder: (context, isValid, child) {
+ return TextButton(
+ onPressed: isValid ? () => _submit(context) : null,
+ child: Text(albumExists ? l10n.showButtonLabel : l10n.createAlbumButtonLabel),
+ );
+ },
+ );
+ },
+ ),
+ ],
+ );
+ }
+
+ Widget _buildVolumeTile(BuildContext context, StorageVolume volume) => RadioListTile<StorageVolume>(
+ value: volume,
+ groupValue: _selectedVolume,
+ onChanged: (volume) {
+ _selectedVolume = volume!;
+ _validate();
+ setState(() {});
+ },
+ title: Text(
+ volume.getDescription(context),
+ softWrap: false,
+ overflow: TextOverflow.fade,
+ maxLines: 1,
+ ),
+ subtitle: Text(
+ volume.path,
+ softWrap: false,
+ overflow: TextOverflow.fade,
+ maxLines: 1,
+ ),
+ );
+
+ void _onFocus() async {
+ // when the field gets focus, we wait for the soft keyboard to appear
+ // then scroll to the bottom to make sure the field is in view
+ if (_nameFieldFocusNode.hasFocus) {
+ await Future.delayed(ADurations.softKeyboardDisplayDelay + const Duration(milliseconds: 500));
+ _scrollToBottom();
+ }
+ }
+
+ void _scrollToBottom() {
+ _scrollController.animateTo(
+ _scrollController.position.maxScrollExtent,
+ duration: ADurations.dialogFieldReachAnimation,
+ curve: Curves.easeInOut,
+ );
+ }
+
+ Future<String?> _buildAlbumPath() async {
+ final name = _nameController.text.trim();
+ if (name.isEmpty) return null;
+
+ final volumePath = _selectedVolume?.path;
+ if (volumePath == null) return null;
+
+ final candidatePath = pContext.join(volumePath, AndroidFileUtils.standardDirPictures, name);
+
+ // uses resolved directory name case if it exists
+ var resolvedPath = volumePath;
+ final relativePathSegments = pContext.split(pContext.relative(candidatePath, from: volumePath));
+ for (final targetSegment in relativePathSegments) {
+ String? resolvedSegment;
+ final directory = Directory(resolvedPath);
+ if (await directory.exists()) {
+ final lowerTargetSegment = targetSegment.toLowerCase();
+ resolvedSegment = directory.listSync().map((v) => pContext.basename(v.path)).firstWhereOrNull((v) => v.toLowerCase() == lowerTargetSegment);
+ }
+ resolvedPath = pContext.join(resolvedPath, resolvedSegment ?? targetSegment);
+ }
+
+ return resolvedPath;
+ }
+
+ Future<void> _validate() async {
+ final path = await _buildAlbumPath();
+ final isValid = path != null;
+ _isValidNotifier.value = isValid;
+ _directoryExistsNotifier.value = isValid && await Directory(path).exists();
+ _albumExistsNotifier.value = isValid && context.read<CollectionSource>().rawAlbums.contains(path);
+ }
+
+ Future<void> _submit(BuildContext context) async {
+ final path = await _buildAlbumPath();
+ if (path == null) return;
+
+ Navigator.maybeOf(context)?.pop(path);
+ }
+}
diff --git a/lib/widgets/dialogs/filter_editors/edit_vault_dialog.dart b/lib/widgets/dialogs/filter_editors/edit_vault_dialog.dart
new file mode 100644
index 0000000..2017d21
--- /dev/null
+++ b/lib/widgets/dialogs/filter_editors/edit_vault_dialog.dart
@@ -0,0 +1,189 @@
+import 'package:aves/model/device.dart';
+import 'package:aves/model/filters/covered/stored_album.dart';
+import 'package:aves/model/settings/settings.dart';
+import 'package:aves/model/source/collection_source.dart';
+import 'package:aves/model/vaults/details.dart';
+import 'package:aves/model/vaults/vaults.dart';
+import 'package:aves/view/view.dart';
+import 'package:aves/widgets/common/action_mixins/feedback.dart';
+import 'package:aves/widgets/common/action_mixins/vault_aware.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/common/identity/aves_caption.dart';
+import 'package:aves/widgets/dialogs/aves_confirmation_dialog.dart';
+import 'package:aves/widgets/dialogs/aves_dialog.dart';
+import 'package:aves/widgets/dialogs/selection_dialogs/common.dart';
+import 'package:aves/widgets/dialogs/selection_dialogs/single_selection.dart';
+import 'package:aves_model/aves_model.dart';
+import 'package:flutter/material.dart';
+import 'package:provider/provider.dart';
+
+class EditVaultDialog extends StatefulWidget {
+ static const routeName = '/dialog/edit_vault';
+
+ final VaultDetails? initialDetails;
+
+ const EditVaultDialog({
+ super.key,
+ this.initialDetails,
+ });
+
+ @override
+ State<EditVaultDialog> createState() => _EditVaultDialogState();
+}
+
+class _EditVaultDialogState extends State<EditVaultDialog> with FeedbackMixin, VaultAwareMixin {
+ final TextEditingController _nameController = TextEditingController();
+ late bool _useBin;
+ late bool _autoLockScreenOff;
+ late VaultLockType _lockType;
+
+ final ValueNotifier<bool> _existsNotifier = ValueNotifier(false);
+ final ValueNotifier<bool> _isValidNotifier = ValueNotifier(false);
+
+ final List<VaultLockType> _lockTypeOptions = [
+ if (device.canAuthenticateUser) VaultLockType.system,
+ VaultLockType.pattern,
+ VaultLockType.pin,
+ VaultLockType.password,
+ ];
+
+ VaultDetails? get initialDetails => widget.initialDetails;
+
+ String get newName => _nameController.text;
+
+ @override
+ void initState() {
+ super.initState();
+ final details = initialDetails ??
+ VaultDetails(
+ name: '',
+ autoLockScreenOff: true,
+ useBin: settings.enableBin,
+ lockType: _lockTypeOptions.first,
+ );
+ _nameController.text = details.name;
+ _useBin = details.useBin;
+ _autoLockScreenOff = details.autoLockScreenOff;
+ _lockType = details.lockType;
+ _validate();
+ }
+
+ @override
+ void dispose() {
+ _nameController.dispose();
+ _existsNotifier.dispose();
+ _isValidNotifier.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final l10n = context.l10n;
+ final isNew = initialDetails == null;
+ return AvesDialog(
+ title: isNew ? l10n.newVaultDialogTitle : l10n.configureVaultDialogTitle,
+ scrollableContent: [
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ child: ValueListenableBuilder<bool>(
+ valueListenable: _existsNotifier,
+ builder: (context, exists, child) {
+ return TextField(
+ controller: _nameController,
+ decoration: InputDecoration(
+ labelText: l10n.newAlbumDialogNameLabel,
+ helperText: exists ? l10n.newAlbumDialogNameLabelAlreadyExistsHelper : '',
+ ),
+ onChanged: (_) => _validate(),
+ onSubmitted: (_) => _submit(context),
+ );
+ }),
+ ),
+ if (_lockTypeOptions.length > 1)
+ ListTile(
+ title: Text(l10n.vaultDialogLockTypeLabel),
+ subtitle: AvesCaption(_lockType.getText(context)),
+ onTap: () {
+ _unfocus();
+ showSelectionDialog<VaultLockType>(
+ context: context,
+ builder: (context) => AvesSingleSelectionDialog<VaultLockType>(
+ initialValue: _lockType,
+ options: Map.fromEntries(_lockTypeOptions.map((v) => MapEntry(v, v.getText(context)))),
+ ),
+ onSelection: (v) => setState(() => _lockType = v),
+ );
+ },
+ ),
+ SwitchListTile(
+ value: _autoLockScreenOff,
+ onChanged: (v) => setState(() => _autoLockScreenOff = v),
+ title: Text(l10n.vaultDialogLockModeWhenScreenOff),
+ ),
+ if (settings.enableBin)
+ SwitchListTile(
+ value: _useBin,
+ onChanged: (v) async {
+ if (!v) {
+ final album = initialDetails?.path;
+ if (album != null) {
+ final filter = StoredAlbumFilter(album, null);
+ final source = context.read<CollectionSource>();
+ if (source.trashedEntries.any(filter.test)) {
+ if (!await showConfirmationDialog(
+ context: context,
+ message: l10n.settingsDisablingBinWarningDialogMessage,
+ confirmationButtonLabel: l10n.applyButtonLabel,
+ )) {
+ return;
+ }
+ }
+ }
+ }
+ setState(() => _useBin = v);
+ },
+ title: Text(l10n.settingsEnableBin),
+ ),
+ ],
+ actions: [
+ const CancelButton(),
+ ValueListenableBuilder<bool>(
+ valueListenable: _isValidNotifier,
+ builder: (context, isValid, child) {
+ return TextButton(
+ onPressed: isValid ? () => _submit(context) : null,
+ child: Text(isNew ? l10n.createAlbumButtonLabel : l10n.applyButtonLabel),
+ );
+ },
+ ),
+ ],
+ );
+ }
+
+ // remove focus, if any, to prevent the keyboard from showing up
+ // after the user is done with the dialog
+ void _unfocus() => FocusManager.instance.primaryFocus?.unfocus();
+
+ Future<void> _validate() async {
+ final notEmpty = newName.isNotEmpty;
+ final exists = notEmpty && vaults.all.map((v) => v.name).contains(newName) && newName != initialDetails?.name;
+ _existsNotifier.value = exists;
+ _isValidNotifier.value = notEmpty && !exists;
+ }
+
+ Future<void> _submit(BuildContext context) async {
+ if (!_isValidNotifier.value) return;
+
+ _unfocus();
+
+ final details = VaultDetails(
+ name: newName,
+ autoLockScreenOff: _autoLockScreenOff,
+ useBin: _useBin,
+ lockType: _lockType,
+ );
+ if (!await setVaultPass(context, details)) return;
+
+ Navigator.maybeOf(context)?.pop(details);
+ }
+}
diff --git a/lib/widgets/dialogs/filter_editors/password_dialog.dart b/lib/widgets/dialogs/filter_editors/password_dialog.dart
new file mode 100644
index 0000000..72f6331
--- /dev/null
+++ b/lib/widgets/dialogs/filter_editors/password_dialog.dart
@@ -0,0 +1,85 @@
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/dialogs/aves_dialog.dart';
+import 'package:flutter/material.dart';
+
+class PasswordDialog extends StatefulWidget {
+ static const routeName = '/dialog/password';
+
+ final bool needConfirmation;
+
+ const PasswordDialog({
+ super.key,
+ required this.needConfirmation,
+ });
+
+ @override
+ State<PasswordDialog> createState() => _PasswordDialogState();
+}
+
+class _PasswordDialogState extends State<PasswordDialog> {
+ final _controller = TextEditingController();
+ final _focusNode = FocusNode();
+ bool _confirming = false;
+ String? _firstPassword;
+
+ @override
+ void initState() {
+ super.initState();
+ _focusNode.requestFocus();
+ }
+
+ @override
+ void dispose() {
+ _controller.dispose();
+ _focusNode.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return AvesDialog(
+ content: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Text(_confirming ? context.l10n.passwordDialogConfirm : context.l10n.passwordDialogEnter),
+ Padding(
+ padding: const EdgeInsets.symmetric(vertical: 16),
+ child: TextField(
+ controller: _controller,
+ focusNode: _focusNode,
+ obscureText: true,
+ onSubmitted: _submit,
+ autofillHints: const [AutofillHints.password],
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+
+ void _submit(String password) {
+ if (widget.needConfirmation) {
+ if (_confirming) {
+ final match = _firstPassword == password;
+ Navigator.maybeOf(context)?.pop<String>(match ? password : null);
+ if (!match) {
+ showDialog(
+ context: context,
+ builder: (context) => AvesDialog(
+ content: Text(context.l10n.genericFailureFeedback),
+ actions: const [OkButton()],
+ ),
+ routeSettings: const RouteSettings(name: AvesDialog.warningRouteName),
+ );
+ }
+ } else {
+ _firstPassword = password;
+ _controller.clear();
+ setState(() => _confirming = true);
+ WidgetsBinding.instance.addPostFrameCallback((_) => _focusNode.requestFocus());
+ }
+ } else {
+ Navigator.maybeOf(context)?.pop<String>(password);
+ }
+ }
+}
diff --git a/lib/widgets/dialogs/filter_editors/pattern_dialog.dart b/lib/widgets/dialogs/filter_editors/pattern_dialog.dart
new file mode 100644
index 0000000..7bfd49a
--- /dev/null
+++ b/lib/widgets/dialogs/filter_editors/pattern_dialog.dart
@@ -0,0 +1,74 @@
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/dialogs/aves_dialog.dart';
+import 'package:flutter/material.dart';
+import 'package:pattern_lock/pattern_lock.dart';
+
+class PatternDialog extends StatefulWidget {
+ static const routeName = '/dialog/pattern';
+
+ final bool needConfirmation;
+
+ const PatternDialog({
+ super.key,
+ required this.needConfirmation,
+ });
+
+ @override
+ State<PatternDialog> createState() => _PatternDialogState();
+}
+
+class _PatternDialogState extends State<PatternDialog> {
+ bool _confirming = false;
+ String? _firstPattern;
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = Theme.of(context).colorScheme;
+ return AvesDialog(
+ content: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Text(_confirming ? context.l10n.patternDialogConfirm : context.l10n.patternDialogEnter),
+ Padding(
+ padding: const EdgeInsets.symmetric(vertical: 16),
+ child: SizedBox.square(
+ dimension: MediaQuery.sizeOf(context).shortestSide / 2,
+ child: PatternLock(
+ relativePadding: .4,
+ selectedColor: colorScheme.primary,
+ notSelectedColor: colorScheme.onSurface,
+ pointRadius: 8,
+ fillPoints: true,
+ onInputComplete: (input) => _submit(input.join()),
+ ),
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+
+ void _submit(String pattern) {
+ if (widget.needConfirmation) {
+ if (_confirming) {
+ final match = _firstPattern == pattern;
+ Navigator.maybeOf(context)?.pop<String>(match ? pattern : null);
+ if (!match) {
+ showDialog(
+ context: context,
+ builder: (context) => AvesDialog(
+ content: Text(context.l10n.genericFailureFeedback),
+ actions: const [OkButton()],
+ ),
+ routeSettings: const RouteSettings(name: AvesDialog.warningRouteName),
+ );
+ }
+ } else {
+ _firstPattern = pattern;
+ setState(() => _confirming = true);
+ }
+ } else {
+ Navigator.maybeOf(context)?.pop<String>(pattern);
+ }
+ }
+}
diff --git a/lib/widgets/dialogs/filter_editors/pin_dialog.dart b/lib/widgets/dialogs/filter_editors/pin_dialog.dart
new file mode 100644
index 0000000..00b8bc2
--- /dev/null
+++ b/lib/widgets/dialogs/filter_editors/pin_dialog.dart
@@ -0,0 +1,91 @@
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/dialogs/aves_dialog.dart';
+import 'package:flutter/material.dart';
+import 'package:pin_code_fields/pin_code_fields.dart';
+
+class PinDialog extends StatefulWidget {
+ static const routeName = '/dialog/pin';
+
+ final bool needConfirmation;
+
+ const PinDialog({
+ super.key,
+ required this.needConfirmation,
+ });
+
+ @override
+ State<PinDialog> createState() => _PinDialogState();
+}
+
+class _PinDialogState extends State<PinDialog> {
+ final _controller = TextEditingController();
+ bool _confirming = false;
+ String? _firstPin;
+
+ @override
+ void dispose() {
+ _controller.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final colorScheme = Theme.of(context).colorScheme;
+ return AvesDialog(
+ content: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Text(_confirming ? context.l10n.pinDialogConfirm : context.l10n.pinDialogEnter),
+ Padding(
+ padding: const EdgeInsets.symmetric(vertical: 16),
+ child: PinCodeTextField(
+ appContext: context,
+ length: 4,
+ controller: _controller,
+ obscureText: true,
+ onChanged: (v) {},
+ onCompleted: _submit,
+ animationType: AnimationType.scale,
+ keyboardType: TextInputType.number,
+ autoFocus: true,
+ autoDismissKeyboard: !widget.needConfirmation || _confirming,
+ pinTheme: PinTheme(
+ activeColor: colorScheme.onSurface,
+ inactiveColor: colorScheme.onSurface,
+ selectedColor: colorScheme.primary,
+ selectedFillColor: colorScheme.primary,
+ borderRadius: BorderRadius.circular(8),
+ shape: PinCodeFieldShape.box,
+ ),
+ ),
+ ),
+ ],
+ ),
+ );
+ }
+
+ void _submit(String pin) {
+ if (widget.needConfirmation) {
+ if (_confirming) {
+ final match = _firstPin == pin;
+ Navigator.maybeOf(context)?.pop<String>(match ? pin : null);
+ if (!match) {
+ showDialog(
+ context: context,
+ builder: (context) => AvesDialog(
+ content: Text(context.l10n.genericFailureFeedback),
+ actions: const [OkButton()],
+ ),
+ routeSettings: const RouteSettings(name: AvesDialog.warningRouteName),
+ );
+ }
+ } else {
+ _firstPin = pin;
+ _controller.clear();
+ setState(() => _confirming = true);
+ }
+ } else {
+ Navigator.maybeOf(context)?.pop<String>(pin);
+ }
+ }
+}
diff --git a/lib/widgets/dialogs/filter_editors/rename_dynamic_album_dialog.dart b/lib/widgets/dialogs/filter_editors/rename_dynamic_album_dialog.dart
new file mode 100644
index 0000000..7af1bc6
--- /dev/null
+++ b/lib/widgets/dialogs/filter_editors/rename_dynamic_album_dialog.dart
@@ -0,0 +1,93 @@
+import 'package:aves/model/dynamic_albums.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/dialogs/aves_dialog.dart';
+import 'package:flutter/material.dart';
+
+class RenameDynamicAlbumDialog extends StatefulWidget {
+ static const routeName = '/dialog/rename_dynamic_album';
+
+ final String name;
+
+ const RenameDynamicAlbumDialog({
+ super.key,
+ required this.name,
+ });
+
+ @override
+ State<RenameDynamicAlbumDialog> createState() => _RenameDynamicAlbumDialogState();
+}
+
+class _RenameDynamicAlbumDialogState extends State<RenameDynamicAlbumDialog> {
+ final TextEditingController _nameController = TextEditingController();
+ final ValueNotifier<bool> _existsNotifier = ValueNotifier(false);
+ final ValueNotifier<bool> _isValidNotifier = ValueNotifier(false);
+
+ String get initialValue => widget.name;
+
+ @override
+ void initState() {
+ super.initState();
+ _nameController.text = initialValue;
+ _validate();
+ }
+
+ @override
+ void dispose() {
+ _nameController.dispose();
+ _existsNotifier.dispose();
+ _isValidNotifier.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return AvesDialog(
+ content: ValueListenableBuilder<bool>(
+ valueListenable: _existsNotifier,
+ builder: (context, exists, child) {
+ return TextField(
+ controller: _nameController,
+ decoration: InputDecoration(
+ labelText: context.l10n.renameAlbumDialogLabel,
+ helperText: exists ? context.l10n.dynamicAlbumAlreadyExists : '',
+ ),
+ autofocus: true,
+ onChanged: (_) => _validate(),
+ onSubmitted: (_) => _submit(context),
+ );
+ }),
+ actions: [
+ const CancelButton(),
+ ValueListenableBuilder<bool>(
+ valueListenable: _isValidNotifier,
+ builder: (context, isValid, child) {
+ return TextButton(
+ onPressed: isValid ? () => _submit(context) : null,
+ child: Text(context.l10n.applyButtonLabel),
+ );
+ },
+ ),
+ ],
+ );
+ }
+
+ String? _formatAlbumName() {
+ final name = _nameController.text.trim();
+ if (name.isEmpty) return null;
+
+ return name;
+ }
+
+ Future<void> _validate() async {
+ final newName = _formatAlbumName();
+ final exists = dynamicAlbums.contains(newName);
+ _isValidNotifier.value = newName != null && !exists;
+ _existsNotifier.value = exists && newName != initialValue;
+ }
+
+ void _submit(BuildContext context) {
+ if (_isValidNotifier.value) {
+ Navigator.maybeOf(context)?.pop(_formatAlbumName());
+ }
+ }
+}
diff --git a/lib/widgets/dialogs/filter_editors/rename_group_dialog.dart b/lib/widgets/dialogs/filter_editors/rename_group_dialog.dart
new file mode 100644
index 0000000..7cf9d4c
--- /dev/null
+++ b/lib/widgets/dialogs/filter_editors/rename_group_dialog.dart
@@ -0,0 +1,101 @@
+import 'package:aves/model/grouping/common.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/dialogs/aves_dialog.dart';
+import 'package:flutter/material.dart';
+
+class RenameGroupDialog extends StatefulWidget {
+ static const routeName = '/dialog/rename_group';
+
+ final FilterGrouping grouping;
+ final Uri groupUri;
+
+ const RenameGroupDialog({
+ super.key,
+ required this.grouping,
+ required this.groupUri,
+ });
+
+ @override
+ State<RenameGroupDialog> createState() => _RenameGroupDialogState();
+}
+
+class _RenameGroupDialogState extends State<RenameGroupDialog> {
+ final TextEditingController _nameController = TextEditingController();
+ final ValueNotifier<bool> _existsNotifier = ValueNotifier(false);
+ final ValueNotifier<bool> _isValidNotifier = ValueNotifier(false);
+
+ FilterGrouping get grouping => widget.grouping;
+
+ Uri get initialGroupUri => widget.groupUri;
+
+ Uri? get parentGroupUri => FilterGrouping.getParentGroup(initialGroupUri);
+
+ @override
+ void initState() {
+ super.initState();
+ _nameController.text = FilterGrouping.getGroupName(initialGroupUri) ?? '';
+ _validate();
+ }
+
+ @override
+ void dispose() {
+ _nameController.dispose();
+ _existsNotifier.dispose();
+ _isValidNotifier.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final l10n = context.l10n;
+
+ return AvesDialog(
+ content: ValueListenableBuilder<bool>(
+ valueListenable: _existsNotifier,
+ builder: (context, exists, child) {
+ return TextField(
+ controller: _nameController,
+ decoration: InputDecoration(
+ labelText: l10n.renameAlbumDialogLabel,
+ helperText: exists ? l10n.groupAlreadyExists : '',
+ ),
+ autofocus: true,
+ onChanged: (_) => _validate(),
+ onSubmitted: (_) => _submit(context),
+ );
+ },
+ ),
+ actions: [
+ const CancelButton(),
+ ValueListenableBuilder<bool>(
+ valueListenable: _isValidNotifier,
+ builder: (context, isValid, child) {
+ return TextButton(
+ onPressed: isValid ? () => _submit(context) : null,
+ child: Text(l10n.applyButtonLabel),
+ );
+ },
+ ),
+ ],
+ );
+ }
+
+ Uri? _getNewGroupUri() {
+ final name = _nameController.text.trim();
+ if (name.isEmpty) return null;
+ return grouping.buildGroupUri(parentGroupUri, name);
+ }
+
+ void _validate() {
+ final newGroupUri = _getNewGroupUri();
+ final exists = grouping.exists(newGroupUri);
+ _isValidNotifier.value = newGroupUri != null && !exists;
+ _existsNotifier.value = exists && newGroupUri != initialGroupUri;
+ }
+
+ void _submit(BuildContext context) {
+ if (_isValidNotifier.value) {
+ Navigator.maybeOf(context)?.pop(_getNewGroupUri());
+ }
+ }
+}
diff --git a/lib/widgets/dialogs/filter_editors/rename_stored_album_dialog.dart b/lib/widgets/dialogs/filter_editors/rename_stored_album_dialog.dart
new file mode 100644
index 0000000..cee4f75
--- /dev/null
+++ b/lib/widgets/dialogs/filter_editors/rename_stored_album_dialog.dart
@@ -0,0 +1,96 @@
+import 'dart:io';
+
+import 'package:aves/services/common/services.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/dialogs/aves_dialog.dart';
+import 'package:flutter/material.dart';
+
+class RenameStoredAlbumDialog extends StatefulWidget {
+ static const routeName = '/dialog/rename_stored_album';
+
+ final String album;
+
+ const RenameStoredAlbumDialog({
+ super.key,
+ required this.album,
+ });
+
+ @override
+ State<RenameStoredAlbumDialog> createState() => _RenameStoredAlbumDialogState();
+}
+
+class _RenameStoredAlbumDialogState extends State<RenameStoredAlbumDialog> {
+ final TextEditingController _nameController = TextEditingController();
+ final ValueNotifier<bool> _existsNotifier = ValueNotifier(false);
+ final ValueNotifier<bool> _isValidNotifier = ValueNotifier(false);
+
+ String get album => widget.album;
+
+ String get initialValue => pContext.basename(album);
+
+ @override
+ void initState() {
+ super.initState();
+ _nameController.text = initialValue;
+ _validate();
+ }
+
+ @override
+ void dispose() {
+ _nameController.dispose();
+ _existsNotifier.dispose();
+ _isValidNotifier.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return AvesDialog(
+ content: ValueListenableBuilder<bool>(
+ valueListenable: _existsNotifier,
+ builder: (context, exists, child) {
+ return TextField(
+ controller: _nameController,
+ decoration: InputDecoration(
+ labelText: context.l10n.renameAlbumDialogLabel,
+ helperText: exists ? context.l10n.renameAlbumDialogLabelAlreadyExistsHelper : '',
+ ),
+ autofocus: true,
+ onChanged: (_) => _validate(),
+ onSubmitted: (_) => _submit(context),
+ );
+ }),
+ actions: [
+ const CancelButton(),
+ ValueListenableBuilder<bool>(
+ valueListenable: _isValidNotifier,
+ builder: (context, isValid, child) {
+ return TextButton(
+ onPressed: isValid ? () => _submit(context) : null,
+ child: Text(context.l10n.applyButtonLabel),
+ );
+ },
+ ),
+ ],
+ );
+ }
+
+ String _buildAlbumPath(String name) {
+ if (name.isEmpty) return '';
+ return pContext.join(pContext.dirname(album), name);
+ }
+
+ Future<void> _validate() async {
+ final newName = _nameController.text;
+ final path = _buildAlbumPath(newName);
+ final exists = newName.isNotEmpty && await FileSystemEntity.type(path) != FileSystemEntityType.notFound;
+ _existsNotifier.value = exists && newName != initialValue;
+ _isValidNotifier.value = newName.isNotEmpty;
+ }
+
+ void _submit(BuildContext context) {
+ if (_isValidNotifier.value) {
+ Navigator.maybeOf(context)?.pop(_nameController.text);
+ }
+ }
+}
diff --git a/lib/widgets/dialogs/item_picker.dart b/lib/widgets/dialogs/item_picker.dart
new file mode 100644
index 0000000..91fff90
--- /dev/null
+++ b/lib/widgets/dialogs/item_picker.dart
@@ -0,0 +1,74 @@
+import 'dart:math';
+
+import 'package:aves/model/entry/entry.dart';
+import 'package:aves/theme/icons.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/common/extensions/theme.dart';
+import 'package:aves/widgets/common/fx/borders.dart';
+import 'package:aves/widgets/common/thumbnail/image.dart';
+import 'package:flutter/material.dart';
+
+class ItemPicker extends StatelessWidget {
+ final double extent;
+ final AvesEntry entry;
+ final GestureTapCallback? onTap;
+
+ const ItemPicker({
+ super.key,
+ required this.extent,
+ required this.entry,
+ this.onTap,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ final imageBorderRadius = BorderRadius.all(Radius.circular(extent * .25));
+ final actionBoxDimension = min(40.0, extent * .4);
+ final actionBoxBorderRadius = BorderRadiusDirectional.only(topStart: Radius.circular(actionBoxDimension * .6));
+ return Tooltip(
+ message: context.l10n.changeTooltip,
+ child: GestureDetector(
+ onTap: onTap,
+ child: Container(
+ decoration: BoxDecoration(
+ border: AvesBorder.border(context),
+ borderRadius: imageBorderRadius,
+ ),
+ child: ClipRRect(
+ borderRadius: imageBorderRadius,
+ child: SizedBox(
+ width: extent,
+ height: extent,
+ child: Stack(
+ children: [
+ ThumbnailImage(
+ entry: entry,
+ extent: extent,
+ devicePixelRatio: MediaQuery.devicePixelRatioOf(context),
+ ),
+ PositionedDirectional(
+ end: -1,
+ bottom: -1,
+ child: Container(
+ decoration: BoxDecoration(
+ color: Theme.of(context).isDark ? const Color(0xAA000000) : const Color(0xCCFFFFFF),
+ border: AvesBorder.border(context),
+ borderRadius: actionBoxBorderRadius,
+ ),
+ width: actionBoxDimension,
+ height: actionBoxDimension,
+ child: Icon(
+ AIcons.edit,
+ size: actionBoxDimension * .6,
+ ),
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+}
diff --git a/lib/widgets/dialogs/map/style_editor_dialog.dart b/lib/widgets/dialogs/map/style_editor_dialog.dart
new file mode 100644
index 0000000..620994b
--- /dev/null
+++ b/lib/widgets/dialogs/map/style_editor_dialog.dart
@@ -0,0 +1,146 @@
+import 'package:aves/model/settings/settings.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/dialogs/aves_dialog.dart';
+import 'package:aves_map/aves_map.dart';
+import 'package:flutter/material.dart';
+
+class MapStyleEditorDialog extends StatefulWidget {
+ static const routeName = '/dialog/map_style_editor';
+
+ final EntryMapStyle? initialValue;
+
+ const MapStyleEditorDialog({
+ super.key,
+ this.initialValue,
+ });
+
+ @override
+ State<MapStyleEditorDialog> createState() => _MapStyleEditorDialogState();
+}
+
+class _MapStyleEditorDialogState extends State<MapStyleEditorDialog> {
+ late final Set<EntryMapStyle> _otherCustomStyles;
+ final TextEditingController _nameController = TextEditingController();
+ final TextEditingController _urlController = TextEditingController();
+ final TextEditingController _subdomainsController = TextEditingController();
+ final TextEditingController _userAgentController = TextEditingController();
+ final ValueNotifier<bool> _isValidNotifier = ValueNotifier(false);
+
+ @override
+ void initState() {
+ super.initState();
+ final initialValue = widget.initialValue;
+ _otherCustomStyles = settings.customMapStyles.where((v) => v != initialValue).toSet();
+ _nameController.text = initialValue?.name ?? '';
+ _urlController.text = initialValue?.url ?? '';
+ _subdomainsController.text = initialValue?.subdomains.join(',') ?? '';
+ _userAgentController.text = initialValue?.userAgent ?? '';
+ _validate();
+ }
+
+ @override
+ void dispose() {
+ _nameController.dispose();
+ _urlController.dispose();
+ _subdomainsController.dispose();
+ _userAgentController.dispose();
+ _isValidNotifier.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final l10n = context.l10n;
+ return AvesDialog(
+ scrollableContent: [
+ Padding(
+ padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
+ child: TextField(
+ controller: _nameController,
+ decoration: InputDecoration(
+ labelText: l10n.mapStyleEditorDialogName,
+ ),
+ autofocus: true,
+ onChanged: (_) => _validate(),
+ ),
+ ),
+ Padding(
+ padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
+ child: TextField(
+ controller: _urlController,
+ decoration: InputDecoration(
+ labelText: l10n.mapStyleEditorDialogUrl,
+ ),
+ keyboardType: TextInputType.url,
+ onChanged: (_) => _validate(),
+ ),
+ ),
+ Padding(
+ padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
+ child: TextField(
+ controller: _subdomainsController,
+ decoration: InputDecoration(
+ labelText: l10n.mapStyleEditorDialogSubdomains,
+ ),
+ ),
+ ),
+ Padding(
+ padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
+ child: TextField(
+ controller: _userAgentController,
+ decoration: InputDecoration(
+ labelText: l10n.mapStyleEditorDialogUserAgent,
+ ),
+ ),
+ ),
+ ],
+ actions: [
+ const CancelButton(),
+ ValueListenableBuilder<bool>(
+ valueListenable: _isValidNotifier,
+ builder: (context, isValid, child) {
+ return TextButton(
+ onPressed: isValid ? () => _submit(context) : null,
+ child: Text(widget.initialValue != null ? l10n.applyButtonLabel : l10n.createButtonLabel),
+ );
+ },
+ )
+ ],
+ );
+ }
+
+ EntryMapStyle _buildStyle() {
+ final name = _nameController.text.trim();
+ final url = _urlController.text.trim();
+ final subdomains = _subdomainsController.text.split(',').map((v) => v.trim()).toList();
+ final userAgent = _userAgentController.text.trim();
+ return EntryMapStyle(
+ key: 'custom_$name',
+ name: name,
+ url: url,
+ subdomains: subdomains,
+ userAgent: userAgent.isNotEmpty ? userAgent : null,
+ );
+ }
+
+ Future<void> _validate() async {
+ final style = _buildStyle();
+
+ final name = style.name ?? '';
+ final url = style.url ?? '';
+ if (name.isEmpty || url.isEmpty) {
+ _isValidNotifier.value = false;
+ return;
+ }
+
+ final key = style.key;
+ final duplicate = _otherCustomStyles.any((v) => v.key == key || v.url == url);
+ _isValidNotifier.value = !duplicate;
+ }
+
+ void _submit(BuildContext context) {
+ if (_isValidNotifier.value) {
+ Navigator.maybeOf(context)?.pop<EntryMapStyle>(_buildStyle());
+ }
+ }
+}
diff --git a/lib/widgets/dialogs/map/style_selection_dialog.dart b/lib/widgets/dialogs/map/style_selection_dialog.dart
new file mode 100644
index 0000000..ea78ce4
--- /dev/null
+++ b/lib/widgets/dialogs/map/style_selection_dialog.dart
@@ -0,0 +1,185 @@
+import 'package:aves/model/settings/settings.dart';
+import 'package:aves/services/common/services.dart';
+import 'package:aves/theme/icons.dart';
+import 'package:aves/utils/collection_utils.dart';
+import 'package:aves/view/src/settings/enums.dart';
+import 'package:aves/widgets/common/basic/scaffold.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/common/identity/buttons/outlined_button.dart';
+import 'package:aves/widgets/dialogs/aves_dialog.dart';
+import 'package:aves/widgets/dialogs/map/style_editor_dialog.dart';
+import 'package:aves/widgets/dialogs/selection_dialogs/radio_list_tile.dart';
+import 'package:aves_map/aves_map.dart';
+import 'package:collection/collection.dart';
+import 'package:flutter/material.dart';
+import 'package:provider/provider.dart';
+
+class MapStyleSelectionDialog extends StatefulWidget {
+ static const routeName = '/dialog/map_style_selection';
+
+ const MapStyleSelectionDialog({super.key});
+
+ @override
+ State<MapStyleSelectionDialog> createState() => _MapStyleSelectionDialogState();
+}
+
+class _MapStyleSelectionDialogState extends State<MapStyleSelectionDialog> {
+ late EntryMapStyle? _selectedValue;
+
+ @override
+ void initState() {
+ super.initState();
+ _selectedValue = settings.mapStyle;
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final useTvLayout = settings.useTvLayout;
+ final l10n = context.l10n;
+ final defaultStyles = availability.mapStyles;
+ final customStyles = context.select<Settings, Set<EntryMapStyle>>((v) => v.customMapStyles).sortedBy((v) => v.getName(context));
+
+ return PopScope(
+ onPopInvokedWithResult: (didPop, result) => settings.mapStyle = _selectedValue,
+ child: AvesScaffold(
+ appBar: AppBar(
+ automaticallyImplyLeading: !useTvLayout,
+ title: Text(context.l10n.mapStyleDialogTitle),
+ ),
+ body: SafeArea(
+ bottom: false,
+ child: ListView(
+ children: [
+ ...defaultStyles.map((v) {
+ return SelectionRadioListTile(
+ // key is expected by test driver
+ key: Key(v.key),
+ value: v,
+ title: v.getName(context),
+ needConfirmation: false,
+ secondary: _getDefaultStylePreview(v),
+ getGroupValue: () => _selectedValue,
+ setGroupValue: _setGroupValue,
+ );
+ }),
+ ...customStyles.map((v) {
+ return SelectionRadioListTile(
+ // key is expected by test driver
+ key: Key(v.key),
+ value: v,
+ title: v.getName(context),
+ needConfirmation: false,
+ secondary: _buildCustomStyleButtons(v),
+ getGroupValue: () => _selectedValue,
+ setGroupValue: _setGroupValue,
+ );
+ }),
+ if (!settings.useTvLayout)
+ Container(
+ alignment: Alignment.center,
+ padding: const EdgeInsets.only(top: 4, bottom: 8),
+ child: AvesOutlinedButton(
+ icon: const Icon(AIcons.add),
+ label: l10n.mapStyleDialogAddStyle,
+ onPressed: _add,
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ );
+ }
+
+ void _setGroupValue(EntryMapStyle? style) => setState(() => _selectedValue = style);
+
+ Widget? _getDefaultStylePreview(EntryMapStyle style) {
+ final assetName = _getImageAssetName(style);
+ if (assetName == null) return null;
+
+ return ImageMarker(
+ count: null,
+ locale: null,
+ drawArrow: false,
+ buildThumbnailImage: (_) => Image.asset('assets/$assetName'),
+ );
+ }
+
+ String? _getImageAssetName(EntryMapStyle style) {
+ if (style == EntryMapStyles.googleNormal) return 'map_tile_128_google_normal.png';
+ if (style == EntryMapStyles.googleHybrid) return 'map_tile_128_google_hybrid.png';
+ if (style == EntryMapStyles.googleTerrain) return 'map_tile_128_google_terrain.png';
+ if (style == EntryMapStyles.osmLiberty) return 'map_tile_128_osm_liberty.png';
+ if (style == EntryMapStyles.openTopoMap) return 'map_tile_128_opentopomap.png';
+ if (style == EntryMapStyles.osmHot) return 'map_tile_128_osm_hot.png';
+ if (style == EntryMapStyles.stamenWatercolor) return 'map_tile_128_stamen_watercolor.png';
+ return null;
+ }
+
+ Widget _buildCustomStyleButtons(EntryMapStyle style) {
+ final l10n = context.l10n;
+ return Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ IconButton(
+ icon: const Icon(AIcons.edit),
+ onPressed: () => _edit(style),
+ tooltip: l10n.changeTooltip,
+ ),
+ IconButton(
+ icon: const Icon(AIcons.clear),
+ onPressed: () => _remove(style),
+ tooltip: l10n.actionRemove,
+ ),
+ ],
+ );
+ }
+
+ Future<void> _add() async {
+ final newStyle = await showDialog<EntryMapStyle>(
+ context: context,
+ builder: (context) => const MapStyleEditorDialog(),
+ routeSettings: const RouteSettings(name: MapStyleEditorDialog.routeName),
+ );
+ if (newStyle == null) return;
+
+ settings.customMapStyles = settings.customMapStyles..add(newStyle);
+ _setGroupValue(newStyle);
+ }
+
+ Future<void> _edit(EntryMapStyle style) async {
+ final newStyle = await showDialog<EntryMapStyle>(
+ context: context,
+ builder: (context) => MapStyleEditorDialog(initialValue: style),
+ routeSettings: const RouteSettings(name: MapStyleEditorDialog.routeName),
+ );
+ if (newStyle == null) return;
+
+ settings.customMapStyles = settings.customMapStyles..replace(style, newStyle);
+ _setGroupValue(newStyle);
+ }
+
+ Future<void> _remove(EntryMapStyle style) async {
+ final l10n = context.l10n;
+ final confirmed = await showDialog<bool>(
+ context: context,
+ builder: (context) => AvesDialog(
+ content: Text(l10n.genericDangerWarningDialogMessage),
+ actions: [
+ const CancelButton(),
+ TextButton(
+ onPressed: () => Navigator.maybeOf(context)?.pop(true),
+ child: Text(l10n.applyButtonLabel),
+ ),
+ ],
+ ),
+ routeSettings: const RouteSettings(name: AvesDialog.warningRouteName),
+ );
+ if (confirmed == null || !confirmed) return;
+
+ settings.customMapStyles = settings.customMapStyles..remove(style);
+ if (_selectedValue == style) {
+ _setGroupValue(null);
+ }
+ }
+}
diff --git a/lib/widgets/dialogs/pick_dialogs/album_pick_page.dart b/lib/widgets/dialogs/pick_dialogs/album_pick_page.dart
new file mode 100644
index 0000000..5ef1fd3
--- /dev/null
+++ b/lib/widgets/dialogs/pick_dialogs/album_pick_page.dart
@@ -0,0 +1,387 @@
+import 'package:aves/app_mode.dart';
+import 'package:aves/model/filters/container/album_group.dart';
+import 'package:aves/model/filters/container/dynamic_album.dart';
+import 'package:aves/model/filters/covered/stored_album.dart';
+import 'package:aves/model/filters/filters.dart';
+import 'package:aves/model/grouping/common.dart';
+import 'package:aves/model/selection.dart';
+import 'package:aves/model/settings/enums/accessibility_animations.dart';
+import 'package:aves/model/settings/settings.dart';
+import 'package:aves/model/source/album.dart';
+import 'package:aves/model/source/collection_source.dart';
+import 'package:aves/model/vaults/details.dart';
+import 'package:aves/model/vaults/vaults.dart';
+import 'package:aves/services/common/services.dart';
+import 'package:aves/theme/durations.dart';
+import 'package:aves/theme/icons.dart';
+import 'package:aves/view/view.dart';
+import 'package:aves/widgets/common/action_mixins/feedback.dart';
+import 'package:aves/widgets/common/action_mixins/vault_aware.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/common/identity/aves_filter_chip.dart';
+import 'package:aves/widgets/common/identity/buttons/captioned_button.dart';
+import 'package:aves/widgets/common/identity/empty.dart';
+import 'package:aves/widgets/common/providers/filter_group_provider.dart';
+import 'package:aves/widgets/common/providers/query_provider.dart';
+import 'package:aves/widgets/common/providers/selection_provider.dart';
+import 'package:aves/widgets/dialogs/aves_confirmation_dialog.dart';
+import 'package:aves/widgets/dialogs/filter_editors/create_group_dialog.dart';
+import 'package:aves/widgets/dialogs/filter_editors/create_stored_album_dialog.dart';
+import 'package:aves/widgets/dialogs/filter_editors/edit_vault_dialog.dart';
+import 'package:aves/widgets/filter_grids/albums_page.dart';
+import 'package:aves/widgets/filter_grids/common/action_delegates/album_set.dart';
+import 'package:aves/widgets/filter_grids/common/app_bar.dart';
+import 'package:aves/widgets/filter_grids/common/enums.dart';
+import 'package:aves/widgets/filter_grids/common/filter_grid_page.dart';
+import 'package:aves_model/aves_model.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter/scheduler.dart';
+import 'package:provider/provider.dart';
+
+Future<AlbumBaseFilter?> pickAlbum({
+ required BuildContext context,
+ required MoveType? moveType,
+ required Iterable<AlbumChipType> chipTypes,
+ required Uri? initialGroup,
+}) async {
+ final source = context.read<CollectionSource>();
+ if (source.targetScope != CollectionSource.fullScope) {
+ await reportService.log('Complete source initialization to pick album');
+ // source may not be fully initialized in view mode
+ source.canAnalyze = true;
+ await source.init(scope: CollectionSource.fullScope);
+ }
+ return await Navigator.maybeOf(context)?.push(
+ MaterialPageRoute<AlbumBaseFilter>(
+ settings: const RouteSettings(name: _AlbumPickPage.routeName),
+ builder: (context) => _AlbumPickPage(
+ source: source,
+ moveType: moveType,
+ chipTypes: chipTypes,
+ initialGroup: initialGroup,
+ ),
+ ),
+ );
+}
+
+class _AlbumPickPage extends StatefulWidget {
+ static const routeName = '/album_pick';
+
+ final CollectionSource source;
+ final MoveType? moveType;
+ final Iterable<AlbumChipType> chipTypes;
+ final Uri? initialGroup;
+
+ const _AlbumPickPage({
+ required this.source,
+ required this.moveType,
+ required this.chipTypes,
+ required this.initialGroup,
+ });
+
+ @override
+ State<_AlbumPickPage> createState() => _AlbumPickPageState();
+}
+
+class _AlbumPickPageState extends State<_AlbumPickPage> with FeedbackMixin, VaultAwareMixin {
+ final ValueNotifier<double> _appBarHeightNotifier = ValueNotifier(0);
+ final ValueNotifier<AppMode> _appModeNotifier = ValueNotifier(AppMode.pickFilterInternal);
+
+ CollectionSource get source => widget.source;
+
+ Iterable<AlbumChipType> get albumChipTypes => widget.chipTypes;
+
+ bool get isPickingGroup => albumChipTypes.length == 1 && albumChipTypes.contains(AlbumChipType.group);
+
+ String get title {
+ final l10n = context.l10n;
+ if (isPickingGroup) {
+ return l10n.groupPickerTitle;
+ } else {
+ return switch (widget.moveType) {
+ MoveType.copy => l10n.albumPickPageTitleCopy,
+ MoveType.move => l10n.albumPickPageTitleMove,
+ MoveType.export => l10n.albumPickPageTitleExport,
+ MoveType.toBin || MoveType.fromBin || null => l10n.albumPickPageTitlePick,
+ };
+ }
+ }
+
+ @override
+ void dispose() {
+ _appBarHeightNotifier.dispose();
+ _appModeNotifier.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return ListenableProvider<ValueNotifier<AppMode>>.value(
+ value: _appModeNotifier,
+ child: MultiProvider(
+ providers: [
+ ChangeNotifierProvider<FilterGrouping>.value(value: albumGrouping),
+ FilterGroupProvider(initialValue: widget.initialGroup),
+ ],
+ child: Builder(
+ // to access filter group provider from subtree context
+ builder: (context) {
+ return Selector<Settings, (AlbumChipSectionFactor, ChipSortFactor)>(
+ selector: (context, s) => (s.albumSectionFactor, s.albumSortFactor),
+ builder: (context, s, child) {
+ return StreamBuilder(
+ stream: source.eventBus.on<AlbumsChangedEvent>(),
+ builder: (context, snapshot) {
+ final groupUri = context.watch<FilterGroupNotifier>().value;
+ final gridItems = AlbumListPage.getGridItems(context, source, albumChipTypes, groupUri);
+ final scrollController = PrimaryScrollController.of(context);
+ return SelectionProvider<FilterGridItem<AlbumBaseFilter>>(
+ child: QueryProvider(
+ startEnabled: settings.getShowTitleQuery(context.currentRouteName!),
+ child: FilterGridPage<AlbumBaseFilter>(
+ settingsRouteKey: AlbumListPage.routeName,
+ appBar: FilterGridAppBar(
+ source: source,
+ title: title,
+ actionDelegate: AlbumChipSetActionDelegate(gridItems),
+ actionsBuilder: _buildActions,
+ isEmpty: false,
+ appBarHeightNotifier: _appBarHeightNotifier,
+ scrollController: scrollController,
+ ),
+ appBarHeightNotifier: _appBarHeightNotifier,
+ scrollController: scrollController,
+ sections: AlbumListPage.groupToSections(context, source, gridItems),
+ newFilters: source.getNewAlbumFilters(context),
+ sortFactor: settings.albumSortFactor,
+ showHeaders: settings.albumSectionFactor != AlbumChipSectionFactor.none,
+ selectable: false,
+ emptyBuilder: () => isPickingGroup
+ ? EmptyContent(
+ icon: AIcons.group,
+ text: context.l10n.groupEmpty,
+ )
+ : EmptyContent(
+ icon: AIcons.album,
+ text: context.l10n.albumEmpty,
+ ),
+ heroType: HeroType.never,
+ floatingActionButton: _buildFab(context),
+ onTileTap: (gridItem, _) async {
+ final filter = gridItem.filter;
+ if (!await unlockFilter(context, filter)) return;
+ switch (filter) {
+ case AlbumGroupFilter _:
+ context.read<FilterGroupNotifier>().value = filter.uri;
+ case StoredAlbumFilter _:
+ case DynamicAlbumFilter _:
+ _pickFilter(context, filter);
+ }
+ },
+ ),
+ ),
+ );
+ },
+ );
+ },
+ );
+ },
+ ),
+ ),
+ );
+ }
+
+ Widget? _buildFab(BuildContext context) {
+ return isPickingGroup
+ ? FloatingActionButton.extended(
+ onPressed: () {
+ final groupUri = context.read<FilterGroupNotifier>().value;
+ final filter = groupUri != null ? albumGrouping.uriToFilter(groupUri) : AlbumGroupFilter.root;
+ if (filter is AlbumBaseFilter) {
+ _pickFilter(context, filter);
+ }
+ },
+ icon: const Icon(AIcons.apply),
+ label: Text(context.l10n.groupPickerUseThisGroupButton),
+ )
+ : null;
+ }
+
+ List<Widget> _buildActions(
+ BuildContext context,
+ AppMode appMode,
+ Selection<FilterGridItem<AlbumBaseFilter>> selection,
+ AlbumChipSetActionDelegate actionDelegate,
+ ) {
+ final itemCount = actionDelegate.allItems.length;
+ final isSelecting = selection.isSelecting;
+ final selectedItems = selection.selectedItems;
+ final selectedFilters = selectedItems.map((v) => v.filter).toSet();
+
+ bool isVisible(ChipSetAction action) => actionDelegate.isVisible(
+ action,
+ appMode: appMode,
+ isSelecting: isSelecting,
+ itemCount: itemCount,
+ selectedFilters: selectedFilters,
+ );
+
+ void onActionSelected(ChipSetAction action) {
+ switch (action) {
+ case ChipSetAction.createGroup:
+ final parentGroupUri = context.read<FilterGroupNotifier>().value;
+ _createGroup(parentGroupUri);
+ case ChipSetAction.createAlbum:
+ _createAlbum();
+ case ChipSetAction.createVault:
+ _createVault();
+ default:
+ actionDelegate.onActionSelected(context, action);
+ }
+ }
+
+ return settings.useTvLayout
+ ? _buildTelevisionActions(
+ context: context,
+ isVisible: isVisible,
+ onActionSelected: onActionSelected,
+ )
+ : _buildMobileActions(
+ context: context,
+ isVisible: isVisible,
+ onActionSelected: onActionSelected,
+ );
+ }
+
+ List<Widget> _buildTelevisionActions({
+ required BuildContext context,
+ required bool Function(ChipSetAction action) isVisible,
+ required void Function(ChipSetAction action) onActionSelected,
+ }) {
+ return [
+ ...ChipSetActions.general,
+ ].where(isVisible).map((action) {
+ return CaptionedButton(
+ icon: action.getIcon(),
+ caption: action.getText(context),
+ onPressed: () => onActionSelected(action),
+ );
+ }).toList();
+ }
+
+ List<Widget> _buildMobileActions({
+ required BuildContext context,
+ required bool Function(ChipSetAction action) isVisible,
+ required void Function(ChipSetAction action) onActionSelected,
+ }) {
+ final animations = context.select<Settings, AccessibilityAnimations>((v) => v.accessibilityAnimations);
+
+ final canCreateStoredAlbums = widget.moveType != null;
+ final quickActions = [
+ if (isPickingGroup) ChipSetAction.createGroup,
+ if (canCreateStoredAlbums) ChipSetAction.createAlbum,
+ ];
+
+ // `null` items are converted to dividers
+ final menuActions = [
+ ...ChipSetActions.general,
+ null,
+ ChipSetAction.toggleTitleSearch,
+ if (canCreateStoredAlbums) ...[
+ null,
+ ChipSetAction.createVault,
+ ]
+ ];
+
+ return [
+ ...quickActions.where(isVisible).map(
+ (action) => IconButton(
+ icon: action.getIcon(),
+ onPressed: () => onActionSelected(action),
+ tooltip: action.getText(context),
+ ),
+ ),
+ PopupMenuButton<ChipSetAction>(
+ itemBuilder: (context) {
+ return menuActions.where((v) => v == null || isVisible(v)).map((action) {
+ if (action == null) return const PopupMenuDivider();
+ return FilterGridAppBar.toMenuItem(context, action, enabled: true);
+ }).toList();
+ },
+ onSelected: (action) async {
+ // remove focus, if any, to prevent the keyboard from showing up
+ // after the user is done with the popup menu
+ FocusManager.instance.primaryFocus?.unfocus();
+
+ // wait for the popup menu to hide before proceeding with the action
+ await Future.delayed(animations.popUpAnimationDelay * timeDilation);
+ onActionSelected(action);
+ },
+ popUpAnimationStyle: animations.popUpAnimationStyle,
+ ),
+ ];
+ }
+
+ Future<void> _createGroup(Uri? parentGroupUri) async {
+ final uri = await showDialog<Uri>(
+ context: context,
+ builder: (context) => CreateGroupDialog(grouping: albumGrouping, parentGroupUri: parentGroupUri),
+ routeSettings: const RouteSettings(name: CreateGroupDialog.routeName),
+ );
+ if (uri == null) return;
+
+ // wait for the dialog to hide
+ await Future.delayed(ADurations.dialogTransitionLoose * timeDilation);
+
+ _pickFilter(context, AlbumGroupFilter.empty(uri));
+ }
+
+ Future<void> _createAlbum() async {
+ final directory = await showDialog<String>(
+ context: context,
+ builder: (context) => const CreateStoredAlbumDialog(),
+ routeSettings: const RouteSettings(name: CreateStoredAlbumDialog.routeName),
+ );
+ if (directory == null) return;
+
+ // wait for the dialog to hide
+ await Future.delayed(ADurations.dialogTransitionLoose * timeDilation);
+
+ _pickStoredAlbum(context, directory);
+ }
+
+ Future<void> _createVault() async {
+ final l10n = context.l10n;
+ if (!await showSkippableConfirmationDialog(
+ context: context,
+ type: ConfirmationDialog.createVault,
+ message: l10n.newVaultWarningDialogMessage,
+ confirmationButtonLabel: l10n.continueButtonLabel,
+ )) {
+ return;
+ }
+
+ final details = await showDialog<VaultDetails>(
+ context: context,
+ builder: (context) => const EditVaultDialog(),
+ routeSettings: const RouteSettings(name: EditVaultDialog.routeName),
+ );
+ if (details == null) return;
+
+ // wait for the dialog to hide
+ await Future.delayed(ADurations.dialogTransitionLoose * timeDilation);
+
+ await vaults.create(details);
+ _pickStoredAlbum(context, details.path);
+ }
+
+ void _pickStoredAlbum(BuildContext context, String directory) {
+ source.createStoredAlbum(directory);
+ final displayName = source.getStoredAlbumDisplayName(context, directory);
+ _pickFilter(context, StoredAlbumFilter(directory, displayName));
+ }
+
+ void _pickFilter(BuildContext context, AlbumBaseFilter filter) async {
+ Navigator.maybeOf(context)?.pop<AlbumBaseFilter>(filter);
+ }
+}
diff --git a/lib/widgets/dialogs/pick_dialogs/app_pick_page.dart b/lib/widgets/dialogs/pick_dialogs/app_pick_page.dart
new file mode 100644
index 0000000..54bd575
--- /dev/null
+++ b/lib/widgets/dialogs/pick_dialogs/app_pick_page.dart
@@ -0,0 +1,155 @@
+import 'package:aves/image_providers/app_icon_image_provider.dart';
+import 'package:aves/model/app_inventory.dart';
+import 'package:aves/model/settings/settings.dart';
+import 'package:aves/services/common/services.dart';
+import 'package:aves/widgets/common/basic/list_tiles/reselectable_radio.dart';
+import 'package:aves/widgets/common/basic/query_bar.dart';
+import 'package:aves/widgets/common/basic/scaffold.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:collection/collection.dart';
+import 'package:flutter/material.dart';
+
+class AppPickPage extends StatefulWidget {
+ static const routeName = '/app_pick';
+
+ final String? initialValue;
+
+ const AppPickPage({
+ super.key,
+ required this.initialValue,
+ });
+
+ @override
+ State<AppPickPage> createState() => _AppPickPageState();
+}
+
+class _AppPickPageState extends State<AppPickPage> {
+ late String? _selectedValue;
+ late Future<Set<Package>> _loader;
+ final ValueNotifier<String> _queryNotifier = ValueNotifier('');
+
+ static const double iconSize = 32;
+
+ @override
+ void initState() {
+ super.initState();
+ _selectedValue = widget.initialValue;
+ _loader = appService.getPackages();
+ }
+
+ @override
+ void dispose() {
+ _queryNotifier.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final useTvLayout = settings.useTvLayout;
+ return AvesScaffold(
+ appBar: AppBar(
+ automaticallyImplyLeading: !useTvLayout,
+ title: Text(context.l10n.appPickDialogTitle),
+ ),
+ body: SafeArea(
+ bottom: false,
+ child: FutureBuilder<Set<Package>>(
+ future: _loader,
+ builder: (context, snapshot) {
+ if (snapshot.hasError) return Text(snapshot.error.toString());
+ if (snapshot.connectionState != ConnectionState.done) {
+ return const Center(
+ child: CircularProgressIndicator(),
+ );
+ }
+
+ final allPackages = snapshot.data;
+ if (allPackages == null) return const SizedBox();
+ final packages = allPackages.where((package) => package.categoryLauncher).toList()..sort((a, b) => compareAsciiUpperCase(_displayName(a), _displayName(b)));
+ return Column(
+ children: [
+ if (!useTvLayout) QueryBar(queryNotifier: _queryNotifier),
+ ValueListenableBuilder<String>(
+ valueListenable: _queryNotifier,
+ builder: (context, query, child) {
+ final upQuery = query.toUpperCase().trim();
+ final visiblePackages = packages.where((package) {
+ return {
+ package.packageName,
+ package.currentLabel,
+ package.englishLabel,
+ ...package.potentialDirs,
+ }.any((v) => v != null && v.toUpperCase().contains(upQuery));
+ }).toList();
+ final showNoneOption = upQuery.isEmpty;
+ final itemCount = visiblePackages.length + (showNoneOption ? 1 : 0);
+ return Expanded(
+ child: ListView.builder(
+ itemBuilder: (context, index) {
+ if (showNoneOption) {
+ if (index == 0) {
+ return ReselectableRadioListTile<String?>(
+ value: '',
+ groupValue: _selectedValue,
+ onChanged: (v) => Navigator.maybeOf(context)?.pop(v),
+ reselectable: true,
+ title: Text(
+ context.l10n.appPickDialogNone,
+ softWrap: false,
+ overflow: TextOverflow.fade,
+ maxLines: 1,
+ ),
+ );
+ }
+ index--;
+ }
+
+ final package = visiblePackages[index];
+ return ReselectableRadioListTile<String?>(
+ value: package.packageName,
+ groupValue: _selectedValue,
+ onChanged: (v) => Navigator.maybeOf(context)?.pop(v),
+ reselectable: true,
+ title: Text.rich(
+ TextSpan(
+ children: [
+ WidgetSpan(
+ alignment: PlaceholderAlignment.middle,
+ child: Padding(
+ padding: const EdgeInsetsDirectional.only(end: 16),
+ child: Image(
+ image: AppIconImage(
+ packageName: package.packageName,
+ size: iconSize,
+ ),
+ width: iconSize,
+ height: iconSize,
+ ),
+ ),
+ ),
+ TextSpan(
+ text: _displayName(package),
+ ),
+ ],
+ ),
+ softWrap: false,
+ overflow: TextOverflow.fade,
+ maxLines: 1,
+ ),
+ );
+ },
+ itemCount: itemCount,
+ ),
+ );
+ },
+ ),
+ ],
+ );
+ },
+ ),
+ ),
+ );
+ }
+
+ String _displayName(Package package) => package.currentLabel ?? package.packageName;
+}
diff --git a/lib/widgets/dialogs/pick_dialogs/item_pick_page.dart b/lib/widgets/dialogs/pick_dialogs/item_pick_page.dart
new file mode 100644
index 0000000..25d3607
--- /dev/null
+++ b/lib/widgets/dialogs/pick_dialogs/item_pick_page.dart
@@ -0,0 +1,74 @@
+import 'package:aves/app_mode.dart';
+import 'package:aves/model/entry/entry.dart';
+import 'package:aves/model/filters/query.dart';
+import 'package:aves/model/settings/settings.dart';
+import 'package:aves/model/source/collection_lens.dart';
+import 'package:aves/widgets/collection/collection_grid.dart';
+import 'package:aves/widgets/collection/collection_page.dart';
+import 'package:aves/widgets/common/basic/insets.dart';
+import 'package:aves/widgets/common/basic/scaffold.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/common/providers/query_provider.dart';
+import 'package:aves/widgets/common/providers/selection_provider.dart';
+import 'package:collection/collection.dart';
+import 'package:flutter/material.dart';
+import 'package:provider/provider.dart';
+
+class ItemPickPage extends StatefulWidget {
+ static const routeName = '/item_pick';
+
+ final CollectionLens collection;
+ final bool canRemoveFilters;
+
+ const ItemPickPage({
+ super.key,
+ required this.collection,
+ required this.canRemoveFilters,
+ });
+
+ @override
+ State<ItemPickPage> createState() => _ItemPickPageState();
+}
+
+class _ItemPickPageState extends State<ItemPickPage> {
+ final ValueNotifier<AppMode> _appModeNotifier = ValueNotifier(AppMode.initialization);
+
+ @override
+ void dispose() {
+ _appModeNotifier.dispose();
+ // provided collection should be a new instance specifically created
+ // for the `ItemPickPage` widget, so it can be safely disposed here
+ widget.collection.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final collection = widget.collection;
+ final liveFilter = collection.filters.firstWhereOrNull((v) => v is QueryFilter && v.live) as QueryFilter?;
+ _appModeNotifier.value = widget.canRemoveFilters ? AppMode.pickUnfilteredMediaInternal : AppMode.pickFilteredMediaInternal;
+ return ListenableProvider<ValueNotifier<AppMode>>.value(
+ value: _appModeNotifier,
+ child: AvesScaffold(
+ body: SelectionProvider<AvesEntry>(
+ child: QueryProvider(
+ startEnabled: settings.getShowTitleQuery(context.currentRouteName!),
+ initialQuery: liveFilter?.query,
+ child: GestureAreaProtectorStack(
+ child: SafeArea(
+ top: false,
+ bottom: false,
+ child: ChangeNotifierProvider<CollectionLens>.value(
+ value: collection,
+ child: const CollectionGrid(
+ settingsRouteKey: CollectionPage.routeName,
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ ),
+ );
+ }
+}
diff --git a/lib/widgets/dialogs/pick_dialogs/location_pick_page.dart b/lib/widgets/dialogs/pick_dialogs/location_pick_page.dart
new file mode 100644
index 0000000..2182888
--- /dev/null
+++ b/lib/widgets/dialogs/pick_dialogs/location_pick_page.dart
@@ -0,0 +1,342 @@
+import 'dart:async';
+
+import 'package:aves/model/settings/enums/coordinate_format.dart';
+import 'package:aves/model/settings/settings.dart';
+import 'package:aves/model/source/collection_lens.dart';
+import 'package:aves/services/common/services.dart';
+import 'package:aves/services/geocoding_service.dart';
+import 'package:aves/theme/durations.dart';
+import 'package:aves/theme/icons.dart';
+import 'package:aves/theme/text.dart';
+import 'package:aves/utils/debouncer.dart';
+import 'package:aves/widgets/common/basic/scaffold.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/common/identity/buttons/outlined_button.dart';
+import 'package:aves/widgets/common/map/geo_map.dart';
+import 'package:aves/widgets/common/providers/map_theme_provider.dart';
+import 'package:aves_map/aves_map.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter/scheduler.dart';
+import 'package:latlong2/latlong.dart';
+
+class LocationPickPage extends StatelessWidget {
+ static const routeName = '/location_pick';
+
+ final CollectionLens? collection;
+ final LatLng? initialLocation;
+
+ const LocationPickPage({
+ super.key,
+ required this.collection,
+ required this.initialLocation,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ return AvesScaffold(
+ body: SafeArea(
+ left: false,
+ top: false,
+ right: false,
+ bottom: true,
+ child: _Content(
+ collection: collection,
+ initialLocation: initialLocation,
+ ),
+ ),
+ );
+ }
+}
+
+class _Content extends StatefulWidget {
+ final CollectionLens? collection;
+ final LatLng? initialLocation;
+
+ const _Content({
+ required this.collection,
+ required this.initialLocation,
+ });
+
+ @override
+ State<_Content> createState() => _ContentState();
+}
+
+class _ContentState extends State<_Content> with SingleTickerProviderStateMixin {
+ final Set<StreamSubscription> _subscriptions = {};
+ final AvesMapController _mapController = AvesMapController();
+ late final ValueNotifier<bool> _isPageAnimatingNotifier;
+ final ValueNotifier<LatLng?> _dotLocationNotifier = ValueNotifier(null), _infoLocationNotifier = ValueNotifier(null);
+ final Debouncer _infoDebouncer = Debouncer(delay: ADurations.mapInfoDebounceDelay);
+
+ CollectionLens? get openingCollection => widget.collection;
+
+ @override
+ void initState() {
+ super.initState();
+
+ if (settings.mapStyle?.isHeavy ?? false) {
+ _isPageAnimatingNotifier = ValueNotifier(true);
+ Future.delayed(ADurations.pageTransitionLoose * timeDilation).then((_) {
+ if (!mounted) return;
+ _isPageAnimatingNotifier.value = false;
+ });
+ } else {
+ _isPageAnimatingNotifier = ValueNotifier(false);
+ }
+
+ _dotLocationNotifier.addListener(_updateLocationInfo);
+
+ _subscriptions.add(_mapController.idleUpdates.listen((event) => _onIdle(event.bounds)));
+ }
+
+ @override
+ void dispose() {
+ _subscriptions
+ ..forEach((sub) => sub.cancel())
+ ..clear();
+ _mapController.dispose();
+ _isPageAnimatingNotifier.dispose();
+ _dotLocationNotifier.dispose();
+ _infoLocationNotifier.dispose();
+ // provided collection should be a new instance specifically created
+ // for the `LocationPickPage` widget, so it can be safely disposed here
+ widget.collection?.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return Column(
+ children: [
+ Expanded(child: _buildMap()),
+ Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ const SizedBox(height: 8),
+ const Divider(height: 0),
+ SafeArea(
+ top: false,
+ bottom: false,
+ child: _LocationInfo(locationNotifier: _infoLocationNotifier),
+ ),
+ const SizedBox(height: 8),
+ AvesOutlinedButton(
+ label: context.l10n.locationPickerUseThisLocationButton,
+ onPressed: () => Navigator.maybeOf(context)?.pop(_dotLocationNotifier.value),
+ ),
+ ],
+ ),
+ ],
+ );
+ }
+
+ Widget _buildMap() {
+ return MapTheme(
+ interactive: true,
+ showCoordinateFilter: false,
+ navigationButton: MapNavigationButton.back,
+ attributionPadding: const EdgeInsets.symmetric(horizontal: 8),
+ child: GeoMap(
+ controller: _mapController,
+ collection: openingCollection,
+ availableSize: MediaQuery.sizeOf(context),
+ initialCenter: widget.initialLocation,
+ isAnimatingNotifier: _isPageAnimatingNotifier,
+ dotLocationNotifier: _dotLocationNotifier,
+ onMapTap: _setLocation,
+ onMarkerTap: (location, entry) => _setLocation(location),
+ ),
+ );
+ }
+
+ void _setLocation(LatLng location) {
+ _dotLocationNotifier.value = location;
+ _mapController.moveTo(location);
+ }
+
+ void _onIdle(ZoomedBounds bounds) {
+ _dotLocationNotifier.value = bounds.projectedCenter;
+ }
+
+ void _updateLocationInfo() {
+ final selectedLocation = _dotLocationNotifier.value;
+ if (_infoLocationNotifier.value == null || selectedLocation == null) {
+ _infoLocationNotifier.value = selectedLocation;
+ } else {
+ _infoDebouncer(() => _infoLocationNotifier.value = selectedLocation);
+ }
+ }
+}
+
+class _LocationInfo extends StatelessWidget {
+ final ValueNotifier<LatLng?> locationNotifier;
+
+ static const double iconPadding = 8.0;
+ static const double _interRowPadding = 2.0;
+
+ const _LocationInfo({
+ required this.locationNotifier,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ return ValueListenableBuilder<LatLng?>(
+ valueListenable: locationNotifier,
+ builder: (context, location, child) {
+ final isPortrait = MediaQuery.orientationOf(context) == Orientation.portrait;
+ final content = isPortrait
+ ? [
+ Expanded(
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ _AddressRow(location: location),
+ const SizedBox(height: _interRowPadding),
+ _CoordinateRow(location: location),
+ ],
+ ),
+ ),
+ ]
+ : [
+ _CoordinateRow(location: location),
+ Expanded(
+ child: _AddressRow(location: location),
+ ),
+ ];
+
+ return Opacity(
+ opacity: location != null ? 1 : 0,
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ const SizedBox(width: iconPadding),
+ const DotMarker(),
+ ...content,
+ ],
+ ),
+ );
+ },
+ );
+ }
+
+ static double getIconSize(BuildContext context) {
+ final textScaler = MediaQuery.textScalerOf(context);
+ return textScaler.scale(16);
+ }
+}
+
+class _AddressRow extends StatefulWidget {
+ final LatLng? location;
+
+ const _AddressRow({
+ required this.location,
+ });
+
+ @override
+ State<_AddressRow> createState() => _AddressRowState();
+}
+
+class _AddressRowState extends State<_AddressRow> {
+ final ValueNotifier<String?> _addressLineNotifier = ValueNotifier(null);
+
+ @override
+ void initState() {
+ super.initState();
+ _updateAddress();
+ }
+
+ @override
+ void didUpdateWidget(covariant _AddressRow oldWidget) {
+ super.didUpdateWidget(oldWidget);
+ if (oldWidget.location != widget.location) {
+ _updateAddress();
+ }
+ }
+
+ @override
+ void dispose() {
+ _addressLineNotifier.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final textScaler = MediaQuery.textScalerOf(context);
+ return Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ const SizedBox(width: _LocationInfo.iconPadding),
+ Icon(AIcons.location, size: _LocationInfo.getIconSize(context)),
+ const SizedBox(width: _LocationInfo.iconPadding),
+ Expanded(
+ child: Container(
+ alignment: AlignmentDirectional.centerStart,
+ // addresses can include non-latin scripts with inconsistent line height,
+ // which is especially an issue for relayout/painting of heavy Google map,
+ // so we give extra height to give breathing room to the text and stabilize layout
+ height: textScaler.scale(Theme.of(context).textTheme.bodyMedium!.fontSize!) * 2,
+ child: ValueListenableBuilder<String?>(
+ valueListenable: _addressLineNotifier,
+ builder: (context, addressLine, child) {
+ return Text(
+ addressLine ?? AText.valueNotAvailable,
+ softWrap: false,
+ overflow: TextOverflow.fade,
+ maxLines: 1,
+ );
+ },
+ ),
+ ),
+ ),
+ ],
+ );
+ }
+
+ Future<void> _updateAddress() async {
+ final location = widget.location;
+ final addressLine = await _getAddressLine(location);
+ if (!mounted) return;
+ if (location == widget.location) {
+ _addressLineNotifier.value = addressLine;
+ }
+ }
+
+ Future<String?> _getAddressLine(LatLng? location) async {
+ if (location != null && await availability.canLocatePlaces) {
+ final addresses = await GeocodingService.getAddress(location, settings.appliedLocale);
+ if (addresses.isNotEmpty) {
+ final address = addresses.first;
+ return address.addressLine;
+ }
+ }
+ return null;
+ }
+}
+
+class _CoordinateRow extends StatelessWidget {
+ final LatLng? location;
+
+ const _CoordinateRow({
+ required this.location,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ return Row(
+ children: [
+ const SizedBox(width: _LocationInfo.iconPadding),
+ Icon(AIcons.geoBounds, size: _LocationInfo.getIconSize(context)),
+ const SizedBox(width: _LocationInfo.iconPadding),
+ Expanded(
+ child: Text(
+ location != null ? settings.coordinateFormat.format(context, location!) : AText.valueNotAvailable,
+ softWrap: false,
+ overflow: TextOverflow.fade,
+ maxLines: 1,
+ ),
+ ),
+ ],
+ );
+ }
+}
diff --git a/lib/widgets/dialogs/pick_dialogs/tag_pick_page.dart b/lib/widgets/dialogs/pick_dialogs/tag_pick_page.dart
new file mode 100644
index 0000000..f54018e
--- /dev/null
+++ b/lib/widgets/dialogs/pick_dialogs/tag_pick_page.dart
@@ -0,0 +1,314 @@
+import 'package:aves/app_mode.dart';
+import 'package:aves/model/filters/container/tag_group.dart';
+import 'package:aves/model/filters/covered/tag.dart';
+import 'package:aves/model/filters/filters.dart';
+import 'package:aves/model/grouping/common.dart';
+import 'package:aves/model/selection.dart';
+import 'package:aves/model/settings/enums/accessibility_animations.dart';
+import 'package:aves/model/settings/settings.dart';
+import 'package:aves/model/source/collection_source.dart';
+import 'package:aves/model/source/tag.dart';
+import 'package:aves/services/common/services.dart';
+import 'package:aves/theme/durations.dart';
+import 'package:aves/theme/icons.dart';
+import 'package:aves/view/view.dart';
+import 'package:aves/widgets/common/action_mixins/feedback.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/common/identity/aves_filter_chip.dart';
+import 'package:aves/widgets/common/identity/buttons/captioned_button.dart';
+import 'package:aves/widgets/common/identity/empty.dart';
+import 'package:aves/widgets/common/providers/filter_group_provider.dart';
+import 'package:aves/widgets/common/providers/query_provider.dart';
+import 'package:aves/widgets/common/providers/selection_provider.dart';
+import 'package:aves/widgets/dialogs/filter_editors/create_group_dialog.dart';
+import 'package:aves/widgets/filter_grids/common/action_delegates/tag_set.dart';
+import 'package:aves/widgets/filter_grids/common/app_bar.dart';
+import 'package:aves/widgets/filter_grids/common/enums.dart';
+import 'package:aves/widgets/filter_grids/common/filter_grid_page.dart';
+import 'package:aves/widgets/filter_grids/tags_page.dart';
+import 'package:aves_model/aves_model.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter/scheduler.dart';
+import 'package:provider/provider.dart';
+
+Future<TagBaseFilter?> pickTag({
+ required BuildContext context,
+ required Iterable<ChipType> chipTypes,
+ required Uri? initialGroup,
+}) async {
+ final source = context.read<CollectionSource>();
+ if (source.targetScope != CollectionSource.fullScope) {
+ await reportService.log('Complete source initialization to pick tag');
+ // source may not be fully initialized in view mode
+ source.canAnalyze = true;
+ await source.init(scope: CollectionSource.fullScope);
+ }
+ return await Navigator.maybeOf(context)?.push(
+ MaterialPageRoute<TagBaseFilter>(
+ settings: const RouteSettings(name: _TagPickPage.routeName),
+ builder: (context) => _TagPickPage(
+ source: source,
+ chipTypes: chipTypes,
+ initialGroup: initialGroup,
+ ),
+ ),
+ );
+}
+
+class _TagPickPage extends StatefulWidget {
+ static const routeName = '/tag_pick';
+
+ final CollectionSource source;
+ final Iterable<ChipType> chipTypes;
+ final Uri? initialGroup;
+
+ const _TagPickPage({
+ required this.source,
+ required this.chipTypes,
+ required this.initialGroup,
+ });
+
+ @override
+ State<_TagPickPage> createState() => _TagPickPageState();
+}
+
+class _TagPickPageState extends State<_TagPickPage> with FeedbackMixin {
+ final ValueNotifier<double> _appBarHeightNotifier = ValueNotifier(0);
+ final ValueNotifier<AppMode> _appModeNotifier = ValueNotifier(AppMode.pickFilterInternal);
+
+ CollectionSource get source => widget.source;
+
+ Iterable<ChipType> get chipTypes => widget.chipTypes;
+
+ bool get isPickingGroup => chipTypes.length == 1 && chipTypes.contains(ChipType.group);
+
+ String get title {
+ final l10n = context.l10n;
+ if (isPickingGroup) {
+ return l10n.groupPickerTitle;
+ } else {
+ return l10n.tagPickPageTitle;
+ }
+ }
+
+ @override
+ void dispose() {
+ _appBarHeightNotifier.dispose();
+ _appModeNotifier.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return ListenableProvider<ValueNotifier<AppMode>>.value(
+ value: _appModeNotifier,
+ child: MultiProvider(
+ providers: [
+ ChangeNotifierProvider<FilterGrouping>.value(value: tagGrouping),
+ FilterGroupProvider(initialValue: widget.initialGroup),
+ ],
+ child: Builder(
+ // to access filter group provider from subtree context
+ builder: (context) {
+ return Selector<Settings, ChipSortFactor>(
+ selector: (context, s) => s.tagSortFactor,
+ builder: (context, s, child) {
+ return StreamBuilder(
+ stream: source.eventBus.on<TagsChangedEvent>(),
+ builder: (context, snapshot) {
+ final groupUri = context.watch<FilterGroupNotifier>().value;
+ final gridItems = TagListPage.getGridItems(source, chipTypes, groupUri);
+ final scrollController = PrimaryScrollController.of(context);
+ return SelectionProvider<FilterGridItem<TagBaseFilter>>(
+ child: QueryProvider(
+ startEnabled: settings.getShowTitleQuery(context.currentRouteName!),
+ child: FilterGridPage<TagBaseFilter>(
+ settingsRouteKey: TagListPage.routeName,
+ appBar: FilterGridAppBar(
+ source: source,
+ title: title,
+ actionDelegate: TagChipSetActionDelegate(gridItems),
+ actionsBuilder: _buildActions,
+ isEmpty: false,
+ appBarHeightNotifier: _appBarHeightNotifier,
+ scrollController: scrollController,
+ ),
+ appBarHeightNotifier: _appBarHeightNotifier,
+ scrollController: scrollController,
+ sections: TagListPage.groupToSections(gridItems),
+ newFilters: const {},
+ sortFactor: settings.tagSortFactor,
+ showHeaders: false,
+ selectable: false,
+ emptyBuilder: () => isPickingGroup
+ ? EmptyContent(
+ icon: AIcons.group,
+ text: context.l10n.groupEmpty,
+ )
+ : EmptyContent(
+ icon: AIcons.tag,
+ text: context.l10n.tagEmpty,
+ ),
+ heroType: HeroType.never,
+ floatingActionButton: _buildFab(context),
+ onTileTap: (gridItem, _) async {
+ final filter = gridItem.filter;
+ switch (filter) {
+ case TagGroupFilter _:
+ context.read<FilterGroupNotifier>().value = filter.uri;
+ case TagFilter _:
+ _pickFilter(context, filter);
+ }
+ },
+ ),
+ ),
+ );
+ },
+ );
+ },
+ );
+ },
+ ),
+ ),
+ );
+ }
+
+ Widget? _buildFab(BuildContext context) {
+ return isPickingGroup
+ ? FloatingActionButton.extended(
+ onPressed: () {
+ final groupUri = context.read<FilterGroupNotifier>().value;
+ final filter = groupUri != null ? tagGrouping.uriToFilter(groupUri) : TagGroupFilter.root;
+ if (filter is TagBaseFilter) {
+ _pickFilter(context, filter);
+ }
+ },
+ icon: const Icon(AIcons.apply),
+ label: Text(context.l10n.groupPickerUseThisGroupButton),
+ )
+ : null;
+ }
+
+ List<Widget> _buildActions(
+ BuildContext context,
+ AppMode appMode,
+ Selection<FilterGridItem<TagBaseFilter>> selection,
+ TagChipSetActionDelegate actionDelegate,
+ ) {
+ final itemCount = actionDelegate.allItems.length;
+ final isSelecting = selection.isSelecting;
+ final selectedItems = selection.selectedItems;
+ final selectedFilters = selectedItems.map((v) => v.filter).toSet();
+
+ bool isVisible(ChipSetAction action) => actionDelegate.isVisible(
+ action,
+ appMode: appMode,
+ isSelecting: isSelecting,
+ itemCount: itemCount,
+ selectedFilters: selectedFilters,
+ );
+
+ void onActionSelected(ChipSetAction action) {
+ switch (action) {
+ case ChipSetAction.createGroup:
+ final parentGroupUri = context.read<FilterGroupNotifier>().value;
+ _createGroup(parentGroupUri);
+ default:
+ actionDelegate.onActionSelected(context, action);
+ }
+ }
+
+ return settings.useTvLayout
+ ? _buildTelevisionActions(
+ context: context,
+ isVisible: isVisible,
+ onActionSelected: onActionSelected,
+ )
+ : _buildMobileActions(
+ context: context,
+ isVisible: isVisible,
+ onActionSelected: onActionSelected,
+ );
+ }
+
+ List<Widget> _buildTelevisionActions({
+ required BuildContext context,
+ required bool Function(ChipSetAction action) isVisible,
+ required void Function(ChipSetAction action) onActionSelected,
+ }) {
+ return [
+ ...ChipSetActions.general,
+ ].where(isVisible).map((action) {
+ return CaptionedButton(
+ icon: action.getIcon(),
+ caption: action.getText(context),
+ onPressed: () => onActionSelected(action),
+ );
+ }).toList();
+ }
+
+ List<Widget> _buildMobileActions({
+ required BuildContext context,
+ required bool Function(ChipSetAction action) isVisible,
+ required void Function(ChipSetAction action) onActionSelected,
+ }) {
+ final animations = context.select<Settings, AccessibilityAnimations>((v) => v.accessibilityAnimations);
+
+ final quickActions = [
+ if (isPickingGroup) ChipSetAction.createGroup,
+ ];
+
+ // `null` items are converted to dividers
+ final menuActions = [
+ ...ChipSetActions.general,
+ null,
+ ChipSetAction.toggleTitleSearch,
+ ];
+
+ return [
+ ...quickActions.where(isVisible).map(
+ (action) => IconButton(
+ icon: action.getIcon(),
+ onPressed: () => onActionSelected(action),
+ tooltip: action.getText(context),
+ ),
+ ),
+ PopupMenuButton<ChipSetAction>(
+ itemBuilder: (context) {
+ return menuActions.where((v) => v == null || isVisible(v)).map((action) {
+ if (action == null) return const PopupMenuDivider();
+ return FilterGridAppBar.toMenuItem(context, action, enabled: true);
+ }).toList();
+ },
+ onSelected: (action) async {
+ // remove focus, if any, to prevent the keyboard from showing up
+ // after the user is done with the popup menu
+ FocusManager.instance.primaryFocus?.unfocus();
+
+ // wait for the popup menu to hide before proceeding with the action
+ await Future.delayed(animations.popUpAnimationDelay * timeDilation);
+ onActionSelected(action);
+ },
+ popUpAnimationStyle: animations.popUpAnimationStyle,
+ ),
+ ];
+ }
+
+ Future<void> _createGroup(Uri? parentGroupUri) async {
+ final uri = await showDialog<Uri>(
+ context: context,
+ builder: (context) => CreateGroupDialog(grouping: tagGrouping, parentGroupUri: parentGroupUri),
+ routeSettings: const RouteSettings(name: CreateGroupDialog.routeName),
+ );
+ if (uri == null) return;
+
+ // wait for the dialog to hide
+ await Future.delayed(ADurations.dialogTransitionLoose * timeDilation);
+
+ _pickFilter(context, TagGroupFilter.empty(uri));
+ }
+
+ void _pickFilter(BuildContext context, TagBaseFilter filter) async {
+ Navigator.maybeOf(context)?.pop<TagBaseFilter>(filter);
+ }
+}
diff --git a/lib/widgets/dialogs/select_storage_dialog.dart b/lib/widgets/dialogs/select_storage_dialog.dart
new file mode 100644
index 0000000..fa667c1
--- /dev/null
+++ b/lib/widgets/dialogs/select_storage_dialog.dart
@@ -0,0 +1,75 @@
+import 'package:aves/utils/android_file_utils.dart';
+import 'package:aves/view/view.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/dialogs/aves_dialog.dart';
+import 'package:aves_model/aves_model.dart';
+import 'package:collection/collection.dart';
+import 'package:flutter/material.dart';
+
+class SelectStorageDialog extends StatefulWidget {
+ static const routeName = '/dialog/select_storage';
+
+ final StorageVolume? initialVolume;
+
+ const SelectStorageDialog({super.key, this.initialVolume});
+
+ @override
+ State<SelectStorageDialog> createState() => _SelectStorageDialogState();
+}
+
+class _SelectStorageDialogState extends State<SelectStorageDialog> {
+ late Set<StorageVolume> _allVolumes;
+ late StorageVolume? _primaryVolume, _selectedVolume;
+
+ @override
+ void initState() {
+ super.initState();
+ _allVolumes = androidFileUtils.storageVolumes;
+ _primaryVolume = _allVolumes.firstWhereOrNull((volume) => volume.isPrimary) ?? _allVolumes.firstOrNull;
+ _selectedVolume = widget.initialVolume ?? _primaryVolume;
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final byPrimary = groupBy<StorageVolume, bool>(_allVolumes, (volume) => volume.isPrimary);
+ int compare(StorageVolume a, StorageVolume b) => compareAsciiUpperCaseNatural(a.path, b.path);
+ final primaryVolumes = (byPrimary[true] ?? [])..sort(compare);
+ final otherVolumes = (byPrimary[false] ?? [])..sort(compare);
+
+ return AvesDialog(
+ title: context.l10n.selectStorageVolumeDialogTitle,
+ scrollableContent: [
+ ...primaryVolumes.map((volume) => _buildVolumeTile(context, volume)),
+ ...otherVolumes.map((volume) => _buildVolumeTile(context, volume)),
+ ],
+ actions: [
+ const CancelButton(),
+ TextButton(
+ onPressed: () => Navigator.maybeOf(context)?.pop(_selectedVolume),
+ child: Text(context.l10n.applyButtonLabel),
+ ),
+ ],
+ );
+ }
+
+ Widget _buildVolumeTile(BuildContext context, StorageVolume volume) => RadioListTile<StorageVolume>(
+ value: volume,
+ groupValue: _selectedVolume,
+ onChanged: (volume) {
+ _selectedVolume = volume!;
+ setState(() {});
+ },
+ title: Text(
+ volume.getDescription(context),
+ softWrap: false,
+ overflow: TextOverflow.fade,
+ maxLines: 1,
+ ),
+ subtitle: Text(
+ volume.path,
+ softWrap: false,
+ overflow: TextOverflow.fade,
+ maxLines: 1,
+ ),
+ );
+}
diff --git a/lib/widgets/dialogs/selection_dialogs/common.dart b/lib/widgets/dialogs/selection_dialogs/common.dart
new file mode 100644
index 0000000..fe34e4f
--- /dev/null
+++ b/lib/widgets/dialogs/selection_dialogs/common.dart
@@ -0,0 +1,23 @@
+import 'package:aves/theme/durations.dart';
+import 'package:aves/widgets/dialogs/selection_dialogs/single_selection.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter/scheduler.dart';
+
+Future<void> showSelectionDialog<T>({
+ required BuildContext context,
+ required WidgetBuilder builder,
+ required void Function(T value) onSelection,
+}) async {
+ final value = await showDialog<T>(
+ context: context,
+ builder: builder,
+ routeSettings: const RouteSettings(name: AvesSingleSelectionDialog.routeName),
+ );
+ // wait for the dialog to hide
+ await Future.delayed(ADurations.dialogTransitionLoose * timeDilation);
+ if (value != null) {
+ onSelection(value);
+ }
+}
+
+typedef TextBuilder<T> = String? Function(T value);
diff --git a/lib/widgets/dialogs/selection_dialogs/multi_selection.dart b/lib/widgets/dialogs/selection_dialogs/multi_selection.dart
new file mode 100644
index 0000000..a9079b3
--- /dev/null
+++ b/lib/widgets/dialogs/selection_dialogs/multi_selection.dart
@@ -0,0 +1,91 @@
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/dialogs/aves_dialog.dart';
+import 'package:aves/widgets/dialogs/selection_dialogs/common.dart';
+import 'package:flutter/material.dart';
+
+class AvesMultiSelectionDialog<T> extends StatefulWidget {
+ static const routeName = '/dialog/multi_selection';
+
+ final Set<T> initialValue;
+ final Map<T, String> options;
+ final TextBuilder<T>? optionSubtitleBuilder;
+ final String? title, message;
+ final bool? dense;
+
+ const AvesMultiSelectionDialog({
+ super.key,
+ required this.initialValue,
+ required this.options,
+ this.optionSubtitleBuilder,
+ this.title,
+ this.message,
+ this.dense,
+ });
+
+ @override
+ State<AvesMultiSelectionDialog<T>> createState() => _AvesMultiSelectionDialogState<T>();
+}
+
+class _AvesMultiSelectionDialogState<T> extends State<AvesMultiSelectionDialog<T>> {
+ late Set<T> _selectedValues;
+
+ @override
+ void initState() {
+ super.initState();
+ _selectedValues = widget.initialValue;
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final title = widget.title;
+ final message = widget.message;
+ final verticalPadding = (title == null && message == null) ? AvesDialog.cornerRadius.y / 2 : .0;
+ return AvesDialog(
+ title: title,
+ scrollableContent: [
+ if (verticalPadding != 0) SizedBox(height: verticalPadding),
+ if (message != null)
+ Padding(
+ padding: const EdgeInsets.all(16),
+ child: Text(message),
+ ),
+ ...widget.options.entries.map((kv) {
+ final value = kv.key;
+ final title = kv.value;
+ final subtitle = widget.optionSubtitleBuilder?.call(value);
+ return SwitchListTile(
+ value: _selectedValues.contains(value),
+ onChanged: (v) {
+ if (v) {
+ _selectedValues.add(value);
+ } else {
+ _selectedValues.remove(value);
+ }
+ setState(() {});
+ },
+ title: Align(
+ alignment: AlignmentDirectional.centerStart,
+ child: Text(title),
+ ),
+ subtitle: subtitle != null
+ ? Text(
+ subtitle,
+ softWrap: false,
+ overflow: TextOverflow.fade,
+ )
+ : null,
+ dense: widget.dense,
+ );
+ }),
+ if (verticalPadding != 0) SizedBox(height: verticalPadding),
+ ],
+ actions: [
+ const CancelButton(),
+ TextButton(
+ onPressed: () => Navigator.maybeOf(context)?.pop(widget.options.keys.where(_selectedValues.contains).toList()),
+ child: Text(context.l10n.applyButtonLabel),
+ ),
+ ],
+ );
+ }
+}
diff --git a/lib/widgets/dialogs/selection_dialogs/radio_list_tile.dart b/lib/widgets/dialogs/selection_dialogs/radio_list_tile.dart
new file mode 100644
index 0000000..9307ff9
--- /dev/null
+++ b/lib/widgets/dialogs/selection_dialogs/radio_list_tile.dart
@@ -0,0 +1,61 @@
+import 'package:aves/widgets/common/basic/list_tiles/reselectable_radio.dart';
+import 'package:aves/widgets/dialogs/selection_dialogs/common.dart';
+import 'package:flutter/material.dart';
+
+class SelectionRadioListTile<T> extends StatelessWidget {
+ final T value;
+ final String title;
+ final TextBuilder<T>? optionSubtitleBuilder;
+ final bool needConfirmation;
+ final bool? dense;
+ final Widget? secondary;
+ final T Function() getGroupValue;
+ final void Function(T value) setGroupValue;
+
+ const SelectionRadioListTile({
+ super.key,
+ required this.value,
+ required this.title,
+ this.optionSubtitleBuilder,
+ required this.needConfirmation,
+ this.dense,
+ this.secondary,
+ required this.getGroupValue,
+ required this.setGroupValue,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ final subtitle = optionSubtitleBuilder?.call(value);
+ return ReselectableRadioListTile<T>(
+ // key is expected by test driver
+ key: Key('$value'),
+ value: value,
+ groupValue: getGroupValue(),
+ onChanged: (v) {
+ // always update the group value even when popping afterwards,
+ // so that the group value can be used in pop handlers
+ // as well as the regular return value from navigation
+ setGroupValue(v as T);
+ if (!needConfirmation) {
+ Navigator.maybeOf(context)?.pop(v);
+ }
+ },
+ reselectable: true,
+ title: Text(
+ title,
+ overflow: TextOverflow.ellipsis,
+ maxLines: 2,
+ ),
+ subtitle: subtitle != null
+ ? Text(
+ subtitle,
+ softWrap: false,
+ overflow: TextOverflow.fade,
+ )
+ : null,
+ dense: dense,
+ secondary: secondary,
+ );
+ }
+}
diff --git a/lib/widgets/dialogs/selection_dialogs/single_selection.dart b/lib/widgets/dialogs/selection_dialogs/single_selection.dart
new file mode 100644
index 0000000..a39b030
--- /dev/null
+++ b/lib/widgets/dialogs/selection_dialogs/single_selection.dart
@@ -0,0 +1,82 @@
+import 'package:aves/widgets/dialogs/aves_dialog.dart';
+import 'package:aves/widgets/dialogs/selection_dialogs/common.dart';
+import 'package:aves/widgets/dialogs/selection_dialogs/radio_list_tile.dart';
+import 'package:flutter/material.dart';
+
+// do not use as `T` a record containing a collection
+// because radio value comparison will fail without deep equality
+class AvesSingleSelectionDialog<T> extends StatefulWidget {
+ static const routeName = '/dialog/selection';
+
+ final T initialValue;
+ final Map<T, String> options;
+ final TextBuilder<T>? optionSubtitleBuilder;
+ final String? title, message, confirmationButtonLabel;
+ final bool? dense;
+
+ const AvesSingleSelectionDialog({
+ super.key,
+ required this.initialValue,
+ required this.options,
+ this.optionSubtitleBuilder,
+ this.title,
+ this.message,
+ this.confirmationButtonLabel,
+ this.dense,
+ });
+
+ @override
+ State<AvesSingleSelectionDialog<T>> createState() => _AvesSingleSelectionDialogState<T>();
+}
+
+class _AvesSingleSelectionDialogState<T> extends State<AvesSingleSelectionDialog<T>> {
+ late T _selectedValue;
+
+ @override
+ void initState() {
+ super.initState();
+ _selectedValue = widget.initialValue;
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final title = widget.title;
+ final message = widget.message;
+ final verticalPadding = (title == null && message == null) ? AvesDialog.cornerRadius.y / 2 : .0;
+ final confirmationButtonLabel = widget.confirmationButtonLabel;
+ final needConfirmation = confirmationButtonLabel != null;
+ return AvesDialog(
+ title: title,
+ scrollableContent: [
+ if (verticalPadding != 0) SizedBox(height: verticalPadding),
+ if (message != null)
+ Padding(
+ padding: const EdgeInsets.all(16),
+ child: Text(message),
+ ),
+ ...widget.options.entries.map((kv) {
+ final radioValue = kv.key;
+ final radioTitle = kv.value;
+ return SelectionRadioListTile(
+ value: radioValue,
+ title: radioTitle,
+ optionSubtitleBuilder: widget.optionSubtitleBuilder,
+ needConfirmation: needConfirmation,
+ dense: widget.dense,
+ getGroupValue: () => _selectedValue,
+ setGroupValue: (v) => setState(() => _selectedValue = v),
+ );
+ }),
+ if (verticalPadding != 0) SizedBox(height: verticalPadding),
+ ],
+ actions: [
+ const CancelButton(),
+ if (needConfirmation)
+ TextButton(
+ onPressed: () => Navigator.maybeOf(context)?.pop(_selectedValue),
+ child: Text(confirmationButtonLabel),
+ ),
+ ],
+ );
+ }
+}
diff --git a/lib/widgets/dialogs/tile_view_dialog.dart b/lib/widgets/dialogs/tile_view_dialog.dart
new file mode 100644
index 0000000..1e1b514
--- /dev/null
+++ b/lib/widgets/dialogs/tile_view_dialog.dart
@@ -0,0 +1,264 @@
+import 'package:aves/model/settings/settings.dart';
+import 'package:aves/theme/durations.dart';
+import 'package:aves/theme/icons.dart';
+import 'package:aves/theme/themes.dart';
+import 'package:aves/widgets/common/basic/font_size_icon_theme.dart';
+import 'package:aves/widgets/common/basic/text_dropdown_button.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/common/fx/transitions.dart';
+import 'package:aves/widgets/common/identity/aves_caption.dart';
+import 'package:aves/widgets/common/identity/highlight_title.dart';
+import 'package:aves/widgets/common/tile_extent_controller.dart';
+import 'package:flutter/material.dart';
+import 'package:provider/provider.dart';
+
+import 'aves_dialog.dart';
+
+class TileViewDialog<S, G, L> extends StatefulWidget {
+ static const routeName = '/dialog/tile_view';
+
+ final (S? sort, G? section, L? layout, bool reverse) initialValue;
+ final List<TileViewDialogOption<S>> sortOptions;
+ final List<TileViewDialogOption<G>> sectionOptions;
+ final List<TileViewDialogOption<L>> layoutOptions;
+ final String Function(S sort, bool reverse) sortOrder;
+ final TileExtentController tileExtentController;
+ final bool Function(S? sort, G? section, L? layout)? canSection;
+
+ const TileViewDialog({
+ super.key,
+ required this.initialValue,
+ this.sortOptions = const [],
+ this.sectionOptions = const [],
+ this.layoutOptions = const [],
+ required this.sortOrder,
+ this.canSection,
+ required this.tileExtentController,
+ });
+
+ @override
+ State<TileViewDialog> createState() => _TileViewDialogState<S, G, L>();
+}
+
+class _TileViewDialogState<S, G, L> extends State<TileViewDialog<S, G, L>> with SingleTickerProviderStateMixin {
+ late S? _selectedSort;
+ late G? _selectedSection;
+ late L? _selectedLayout;
+ late bool _reverseSort;
+ late int _columnMin, _columnMax;
+ late final ValueNotifier<int> _columnCountNotifier = ValueNotifier(tileExtentController.columnCount);
+
+ List<TileViewDialogOption<S>> get sortOptions => widget.sortOptions;
+
+ List<TileViewDialogOption<G>> get sectionOptions => widget.sectionOptions;
+
+ List<TileViewDialogOption<L>> get layoutOptions => widget.layoutOptions;
+
+ TileExtentController get tileExtentController => widget.tileExtentController;
+
+ bool get canSection => (widget.canSection ?? (s, g, l) => true).call(_selectedSort, _selectedSection, _selectedLayout);
+
+ @override
+ void initState() {
+ super.initState();
+ final initialValue = widget.initialValue;
+ _selectedSort = initialValue.$1;
+ _selectedSection = initialValue.$2;
+ _selectedLayout = initialValue.$3;
+ _reverseSort = initialValue.$4;
+
+ final extentController = tileExtentController;
+ final columnRange = extentController.effectiveColumnRange;
+ _columnMin = columnRange.$1;
+ _columnMax = columnRange.$2;
+ }
+
+ @override
+ void dispose() {
+ _columnCountNotifier.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final l10n = context.l10n;
+
+ return AvesDialog(
+ scrollableContent: [
+ _buildSection(
+ icon: AIcons.sort,
+ title: l10n.viewDialogSortSectionTitle,
+ trailing: IconButton(
+ icon: const Icon(AIcons.sortOrder),
+ onPressed: () => setState(() => _reverseSort = !_reverseSort),
+ tooltip: l10n.viewDialogReverseSortOrder,
+ ),
+ options: sortOptions,
+ value: _selectedSort,
+ onChanged: (v) {
+ _selectedSort = v;
+ _reverseSort = false;
+ },
+ bottom: _selectedSort != null ? AvesCaption(widget.sortOrder(_selectedSort as S, _reverseSort)) : null,
+ ),
+ AnimatedSwitcher(
+ duration: context.read<DurationsData>().formTransition,
+ switchInCurve: Curves.easeInOutCubic,
+ switchOutCurve: Curves.easeInOutCubic,
+ transitionBuilder: AvesTransitions.formTransitionBuilder,
+ child: _buildSection(
+ show: canSection,
+ icon: AIcons.section,
+ title: l10n.viewDialogGroupSectionTitle,
+ options: sectionOptions,
+ value: _selectedSection,
+ onChanged: (v) => _selectedSection = v,
+ ),
+ ),
+ _buildSection(
+ icon: AIcons.layout,
+ title: l10n.viewDialogLayoutSectionTitle,
+ options: layoutOptions,
+ value: _selectedLayout,
+ onChanged: (v) => _selectedLayout = v,
+ ),
+ if (settings.showPinchGestureAlternatives)
+ Padding(
+ padding: const EdgeInsets.symmetric(vertical: 8, horizontal: 16),
+ child: Row(
+ children: [
+ const Icon(AIcons.thumbnailLarge),
+ Expanded(
+ child: ValueListenableBuilder<int>(
+ valueListenable: _columnCountNotifier,
+ builder: (context, columnCount, child) => Slider(
+ label: context.l10n.columnCount(columnCount),
+ value: columnCount.toDouble(),
+ onChanged: (v) => _columnCountNotifier.value = v.round(),
+ min: _columnMin.toDouble(),
+ max: _columnMax.toDouble(),
+ divisions: (_columnMax - _columnMin),
+ ),
+ ),
+ ),
+ const Icon(AIcons.thumbnailSmall),
+ ],
+ ),
+ ),
+ ],
+ actions: [
+ const CancelButton(),
+ TextButton(
+ key: const Key('button-apply'),
+ onPressed: () {
+ tileExtentController.setUserPreferredColumnCount(_columnCountNotifier.value);
+ Navigator.maybeOf(context)?.pop<(S?, G?, L?, bool)>((_selectedSort, _selectedSection, _selectedLayout, _reverseSort));
+ },
+ child: Text(l10n.applyButtonLabel),
+ )
+ ],
+ );
+ }
+
+ Widget _buildSection<T>({
+ bool show = true,
+ required IconData icon,
+ required String title,
+ Widget? trailing,
+ required List<TileViewDialogOption<T>> options,
+ required T value,
+ required ValueChanged<T?> onChanged,
+ Widget? bottom,
+ }) {
+ if (options.isEmpty || !show) return const SizedBox();
+
+ final label = ConstrainedBox(
+ constraints: const BoxConstraints(minHeight: kMinInteractiveDimension),
+ child: FontSizeIconTheme(
+ child: Row(
+ children: [
+ Icon(icon),
+ const SizedBox(width: 16),
+ Expanded(
+ child: HighlightTitle(
+ title: title,
+ showHighlight: false,
+ ),
+ ),
+ if (trailing != null) trailing,
+ ],
+ ),
+ ),
+ );
+ final selector = TextDropdownButton<T>(
+ values: options.map((v) => v.value).toList(),
+ valueText: (v) => options.firstWhere((option) => option.value == v).title,
+ valueIcon: (v) => options.firstWhere((option) => option.value == v).icon,
+ value: value,
+ onChanged: (v) => setState(() => onChanged(v)),
+ isExpanded: true,
+ dropdownColor: Themes.thirdLayerColor(context),
+ );
+
+ final textScaler = MediaQuery.textScalerOf(context);
+ final iconSize = textScaler.scale(IconTheme.of(context).size!);
+ final isPortrait = MediaQuery.orientationOf(context) == Orientation.portrait;
+ final child = isPortrait
+ ? Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ label,
+ Padding(
+ padding: EdgeInsetsDirectional.only(start: iconSize + 16, end: 12),
+ child: selector,
+ ),
+ if (bottom != null)
+ Padding(
+ padding: EdgeInsetsDirectional.only(start: iconSize + 16),
+ child: bottom,
+ ),
+ ],
+ )
+ : Row(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Expanded(child: label),
+ const SizedBox(width: 8),
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ selector,
+ if (bottom != null) bottom,
+ ],
+ ),
+ ),
+ ],
+ );
+
+ return TooltipTheme(
+ data: TooltipTheme.of(context).copyWith(
+ preferBelow: false,
+ ),
+ child: Padding(
+ padding: const EdgeInsets.only(left: 16, top: 8, right: 16),
+ child: child,
+ ),
+ );
+ }
+}
+
+@immutable
+class TileViewDialogOption<T> {
+ final T value;
+ final String title;
+ final IconData icon;
+
+ const TileViewDialogOption({
+ required this.value,
+ required this.title,
+ required this.icon,
+ });
+}
diff --git a/lib/widgets/dialogs/time_shift_dialog.dart b/lib/widgets/dialogs/time_shift_dialog.dart
new file mode 100644
index 0000000..92f3a74
--- /dev/null
+++ b/lib/widgets/dialogs/time_shift_dialog.dart
@@ -0,0 +1,52 @@
+import 'package:aves/widgets/common/basic/time_shift_selector.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:flutter/material.dart';
+
+import 'aves_dialog.dart';
+
+class TimeShiftDialog extends StatefulWidget {
+ static const routeName = '/dialog/time_shift';
+
+ final Duration initialValue;
+
+ const TimeShiftDialog({
+ super.key,
+ required this.initialValue,
+ });
+
+ @override
+ State<TimeShiftDialog> createState() => _TimeShiftDialogState();
+}
+
+class _TimeShiftDialogState extends State<TimeShiftDialog> {
+ late TimeShiftController _timeShiftController;
+
+ @override
+ void initState() {
+ super.initState();
+ _timeShiftController = TimeShiftController(
+ initialValue: widget.initialValue,
+ );
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return AvesDialog(
+ scrollableContent: [
+ Padding(
+ padding: const EdgeInsets.symmetric(vertical: 16),
+ child: TimeShiftSelector(controller: _timeShiftController),
+ ),
+ ],
+ actions: [
+ const CancelButton(),
+ TextButton(
+ onPressed: () => _submit(context),
+ child: Text(context.l10n.applyButtonLabel),
+ ),
+ ],
+ );
+ }
+
+ void _submit(BuildContext context) => Navigator.maybeOf(context)?.pop(_timeShiftController.value);
+}
diff --git a/lib/widgets/dialogs/video_speed_dialog.dart b/lib/widgets/dialogs/video_speed_dialog.dart
new file mode 100644
index 0000000..eb1f671
--- /dev/null
+++ b/lib/widgets/dialogs/video_speed_dialog.dart
@@ -0,0 +1,76 @@
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:flutter/material.dart';
+
+import 'aves_dialog.dart';
+
+class VideoSpeedDialog extends StatefulWidget {
+ static const routeName = '/dialog/select_video_speed';
+
+ final double current, min, max;
+
+ const VideoSpeedDialog({
+ super.key,
+ required this.current,
+ required this.min,
+ required this.max,
+ });
+
+ @override
+ State<VideoSpeedDialog> createState() => _VideoSpeedDialogState();
+}
+
+class _VideoSpeedDialogState extends State<VideoSpeedDialog> {
+ late double _speed;
+
+ static const interval = .25;
+
+ @override
+ void initState() {
+ super.initState();
+ _speed = widget.current;
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return AvesDialog(
+ horizontalContentPadding: 4,
+ content: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 24),
+ child: Wrap(
+ children: [
+ Text(context.l10n.videoSpeedDialogLabel),
+ const SizedBox(width: 16),
+ Text('x$_speed'),
+ ],
+ ),
+ ),
+ const SizedBox(height: 16),
+ Slider(
+ value: _speed,
+ onChanged: (v) => setState(() {
+ // provided value may be imprecise on some platforms
+ // e.g. 1.7499999999999998 instead of 1.75
+ _speed = (v / interval).round() * interval;
+ }),
+ min: widget.min,
+ max: widget.max,
+ divisions: ((widget.max - widget.min) / interval).round(),
+ ),
+ ],
+ ),
+ actions: [
+ const CancelButton(),
+ TextButton(
+ onPressed: () => _submit(context),
+ child: Text(context.l10n.applyButtonLabel),
+ ),
+ ],
+ );
+ }
+
+ void _submit(BuildContext context) => Navigator.maybeOf(context)?.pop(_speed);
+}
diff --git a/lib/widgets/dialogs/video_stream_selection_dialog.dart b/lib/widgets/dialogs/video_stream_selection_dialog.dart
new file mode 100644
index 0000000..668ac50
--- /dev/null
+++ b/lib/widgets/dialogs/video_stream_selection_dialog.dart
@@ -0,0 +1,164 @@
+import 'package:aves/ref/languages.dart';
+import 'package:aves/theme/icons.dart';
+import 'package:aves/theme/text.dart';
+import 'package:aves/theme/themes.dart';
+import 'package:aves/widgets/common/basic/text_dropdown_button.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves_video/aves_video.dart';
+import 'package:collection/collection.dart';
+import 'package:flutter/material.dart';
+
+import 'aves_dialog.dart';
+
+class VideoStreamSelectionDialog extends StatefulWidget {
+ static const routeName = '/dialog/select_video_stream';
+
+ final Map<MediaStreamSummary, bool> streams;
+
+ const VideoStreamSelectionDialog({
+ super.key,
+ required this.streams,
+ });
+
+ @override
+ State<VideoStreamSelectionDialog> createState() => _VideoStreamSelectionDialogState();
+}
+
+class _VideoStreamSelectionDialogState extends State<VideoStreamSelectionDialog> {
+ late List<MediaStreamSummary?> _videoStreams, _audioStreams, _textStreams;
+ MediaStreamSummary? _currentVideo, _currentAudio, _currentText;
+
+ @override
+ void initState() {
+ super.initState();
+
+ final byType = groupBy<MediaStreamSummary, MediaStreamType>(widget.streams.keys, (v) => v.type);
+ // check width/height to exclude image streams (that are included among video streams)
+ _videoStreams = (byType[MediaStreamType.video] ?? []).where((v) => v.width != null && v.height != null).toList();
+ _audioStreams = (byType[MediaStreamType.audio] ?? []);
+ _textStreams = [null, ...byType[MediaStreamType.text] ?? []];
+
+ final streamEntries = widget.streams.entries;
+ _currentVideo = streamEntries.firstWhereOrNull((kv) => kv.key.type == MediaStreamType.video && kv.value)?.key;
+ _currentAudio = streamEntries.firstWhereOrNull((kv) => kv.key.type == MediaStreamType.audio && kv.value)?.key;
+ _currentText = streamEntries.firstWhereOrNull((kv) => kv.key.type == MediaStreamType.text && kv.value)?.key;
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final canSelectVideo = _videoStreams.length > 1;
+ final canSelectAudio = _audioStreams.length > 1;
+ final canSelectText = _textStreams.length > 1;
+ final canSelect = canSelectVideo || canSelectAudio || canSelectText;
+ return AvesDialog(
+ content: canSelect ? null : Text(context.l10n.videoStreamSelectionDialogNoSelection),
+ scrollableContent: canSelect
+ ? [
+ if (canSelectVideo)
+ ..._buildSection(
+ icon: AIcons.streamVideo,
+ title: context.l10n.videoStreamSelectionDialogVideo,
+ streams: _videoStreams,
+ current: _currentVideo,
+ setter: (v) => _currentVideo = v,
+ ),
+ if (canSelectAudio)
+ ..._buildSection(
+ icon: AIcons.streamAudio,
+ title: context.l10n.videoStreamSelectionDialogAudio,
+ streams: _audioStreams,
+ current: _currentAudio,
+ setter: (v) => _currentAudio = v,
+ ),
+ if (canSelectText)
+ ..._buildSection(
+ icon: AIcons.streamText,
+ title: context.l10n.videoStreamSelectionDialogText,
+ streams: _textStreams,
+ current: _currentText,
+ setter: (v) => _currentText = v,
+ ),
+ const SizedBox(height: 8),
+ ]
+ : null,
+ actions: [
+ const CancelButton(),
+ if (canSelect)
+ TextButton(
+ onPressed: () => _submit(context),
+ child: Text(context.l10n.applyButtonLabel),
+ ),
+ ],
+ );
+ }
+
+ static String _formatLanguage(String value) {
+ final language = Language.living639_2.firstWhereOrNull((language) => language.iso639_2 == value);
+ return language?.native ?? value;
+ }
+
+ String _commonStreamName(MediaStreamSummary? stream) {
+ if (stream == null) return context.l10n.videoStreamSelectionDialogOff;
+ final title = stream.title;
+ final language = stream.language;
+ if (language != null && language != 'und') {
+ final formattedLanguage = _formatLanguage(language);
+ return '$formattedLanguage${title != null && title != formattedLanguage ? ' • $title' : ''}';
+ } else if (title != null) {
+ return title;
+ } else {
+ return '${context.l10n.videoStreamSelectionDialogTrack} ${stream.index} (${stream.codecName})';
+ }
+ }
+
+ String _streamName(MediaStreamSummary? stream) {
+ final common = _commonStreamName(stream);
+ if (stream != null && stream.type == MediaStreamType.video) {
+ final w = stream.width;
+ final h = stream.height;
+ if (w != null && h != null) {
+ return '$common • $w${AText.resolutionSeparator}$h';
+ }
+ }
+ return common;
+ }
+
+ List<Widget> _buildSection({
+ required IconData icon,
+ required String title,
+ required List<MediaStreamSummary?> streams,
+ required MediaStreamSummary? current,
+ required ValueSetter<MediaStreamSummary?> setter,
+ }) {
+ return [
+ Padding(
+ padding: const EdgeInsets.only(left: 16, top: 16, right: 16),
+ child: Row(
+ children: [
+ Icon(icon),
+ const SizedBox(width: 16),
+ Text(title),
+ ],
+ ),
+ ),
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ // allow `null` subtitle stream to disable subtitles
+ child: TextDropdownButton<MediaStreamSummary?>(
+ values: streams,
+ valueText: _streamName,
+ value: current,
+ onChanged: streams.length > 1 ? (newValue) => setState(() => setter(newValue)) : null,
+ isExpanded: true,
+ dropdownColor: Themes.thirdLayerColor(context),
+ ),
+ ),
+ ];
+ }
+
+ void _submit(BuildContext context) => Navigator.maybeOf(context)?.pop({
+ MediaStreamType.video: _currentVideo,
+ MediaStreamType.audio: _currentAudio,
+ MediaStreamType.text: _currentText,
+ });
+}
diff --git a/lib/widgets/dialogs/wallpaper_settings_dialog.dart b/lib/widgets/dialogs/wallpaper_settings_dialog.dart
new file mode 100644
index 0000000..20cddd7
--- /dev/null
+++ b/lib/widgets/dialogs/wallpaper_settings_dialog.dart
@@ -0,0 +1,51 @@
+import 'package:aves/model/device.dart';
+import 'package:aves/view/view.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/dialogs/aves_dialog.dart';
+import 'package:aves/widgets/dialogs/selection_dialogs/radio_list_tile.dart';
+import 'package:aves_model/aves_model.dart';
+import 'package:flutter/material.dart';
+
+class WallpaperSettingsDialog extends StatefulWidget {
+ static const routeName = '/dialog/wallpaper_settings';
+
+ const WallpaperSettingsDialog({super.key});
+
+ @override
+ State<WallpaperSettingsDialog> createState() => _WallpaperSettingsDialogState();
+}
+
+class _WallpaperSettingsDialogState extends State<WallpaperSettingsDialog> {
+ WallpaperTarget _selectedTarget = WallpaperTarget.home;
+ bool _useScrollEffect = true;
+
+ @override
+ Widget build(BuildContext context) {
+ return AvesDialog(
+ scrollableContent: [
+ if (device.canSetLockScreenWallpaper)
+ ...WallpaperTarget.values.map((value) {
+ return SelectionRadioListTile(
+ value: value,
+ title: value.getName(context),
+ needConfirmation: true,
+ getGroupValue: () => _selectedTarget,
+ setGroupValue: (v) => setState(() => _selectedTarget = v),
+ );
+ }),
+ SwitchListTile(
+ value: _useScrollEffect,
+ onChanged: (v) => setState(() => _useScrollEffect = v),
+ title: Text(context.l10n.wallpaperUseScrollEffect),
+ )
+ ],
+ actions: [
+ const CancelButton(),
+ TextButton(
+ onPressed: () => Navigator.maybeOf(context)?.pop<(WallpaperTarget, bool)>((_selectedTarget, _useScrollEffect)),
+ child: Text(context.l10n.applyButtonLabel),
+ ),
+ ],
+ );
+ }
+}