summaryrefslogtreecommitdiff
path: root/lib/widgets/explorer
diff options
context:
space:
mode:
authormirror <mirror@localhost>2026-11-22 08:41:00 +0900
committermirror <mirror@localhost>2026-11-22 08:41:00 +0900
commit449d8b74bd6d9dae98a07254cdfad677b920e7b0 (patch)
treec131c3528c4d517f56e19b854a7453fedb097d40 /lib/widgets/explorer
downloadaves-src-master.tar.gz
aves-src-master.zip
snapshot of aves v1.13.12 (secrets removed: android/app/google-services.json)HEADv1.13.12master
Diffstat (limited to 'lib/widgets/explorer')
-rw-r--r--lib/widgets/explorer/app_bar.dart209
-rw-r--r--lib/widgets/explorer/crumb_line.dart46
-rw-r--r--lib/widgets/explorer/explorer_action_delegate.dart124
-rw-r--r--lib/widgets/explorer/explorer_page.dart297
4 files changed, 676 insertions, 0 deletions
diff --git a/lib/widgets/explorer/app_bar.dart b/lib/widgets/explorer/app_bar.dart
new file mode 100644
index 0000000..c0da008
--- /dev/null
+++ b/lib/widgets/explorer/app_bar.dart
@@ -0,0 +1,209 @@
+import 'dart:async';
+
+import 'package:aves/app_mode.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/theme/icons.dart';
+import 'package:aves/theme/themes.dart';
+import 'package:aves/utils/android_file_utils.dart';
+import 'package:aves/view/view.dart';
+import 'package:aves/widgets/common/app_bar/app_bar_subtitle.dart';
+import 'package:aves/widgets/common/app_bar/app_bar_title.dart';
+import 'package:aves/widgets/common/app_bar/crumb_line.dart';
+import 'package:aves/widgets/common/basic/font_size_icon_theme.dart';
+import 'package:aves/widgets/common/basic/popup/menu_row.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/common/identity/aves_app_bar.dart';
+import 'package:aves/widgets/common/search/route.dart';
+import 'package:aves/widgets/dialogs/select_storage_dialog.dart';
+import 'package:aves/widgets/explorer/crumb_line.dart';
+import 'package:aves/widgets/explorer/explorer_action_delegate.dart';
+import 'package:aves/widgets/search/collection_search_delegate.dart';
+import 'package:aves_model/aves_model.dart';
+import 'package:collection/collection.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter/scheduler.dart';
+import 'package:provider/provider.dart';
+
+class ExplorerAppBar extends StatefulWidget {
+ final ValueNotifier<VolumeRelativeDirectory?> directoryNotifier;
+ final void Function(VolumeRelativeDirectory? dir) goToDir;
+
+ const ExplorerAppBar({
+ super.key,
+ required this.directoryNotifier,
+ required this.goToDir,
+ });
+
+ @override
+ State<ExplorerAppBar> createState() => _ExplorerAppBarState();
+}
+
+class _ExplorerAppBarState extends State<ExplorerAppBar> with WidgetsBindingObserver {
+ Set<StorageVolume> get _volumes => androidFileUtils.storageVolumes;
+
+ @override
+ void initState() {
+ super.initState();
+ WidgetsBinding.instance.addObserver(this);
+ }
+
+ @override
+ void dispose() {
+ WidgetsBinding.instance.removeObserver(this);
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return AvesAppBar(
+ contentHeight: appBarContentHeight,
+ pinned: true,
+ leading: const DrawerButton(),
+ title: _buildAppBarTitle(context),
+ actions: _buildActions,
+ bottom: LayoutBuilder(
+ builder: (context, constraints) {
+ return Container(
+ padding: CrumbLine.padding,
+ width: constraints.maxWidth,
+ height: CrumbLine.getPreferredHeight(MediaQuery.textScalerOf(context)),
+ child: ValueListenableBuilder<VolumeRelativeDirectory?>(
+ valueListenable: widget.directoryNotifier,
+ builder: (context, directory, child) {
+ return ExplorerCrumbLine(
+ key: const Key('crumbs'),
+ directory: directory,
+ onTap: widget.goToDir,
+ );
+ },
+ ),
+ );
+ },
+ ),
+ );
+ }
+
+ InteractiveAppBarTitle _buildAppBarTitle(BuildContext context) {
+ final appMode = context.watch<ValueNotifier<AppMode>>().value;
+ Widget title = Text(
+ context.l10n.explorerPageTitle,
+ softWrap: false,
+ overflow: TextOverflow.fade,
+ maxLines: 1,
+ );
+ if (appMode == AppMode.main) {
+ title = SourceStateAwareAppBarTitle(
+ title: title,
+ source: context.read<CollectionSource>(),
+ );
+ }
+ return InteractiveAppBarTitle(
+ onTap: () => _goToSearch(context),
+ child: title,
+ );
+ }
+
+ List<Widget> _buildActions(BuildContext context, double maxWidth) {
+ final animations = context.select<Settings, AccessibilityAnimations>((v) => v.accessibilityAnimations);
+ return [
+ IconButton(
+ icon: const Icon(AIcons.search),
+ onPressed: () => _goToSearch(context),
+ tooltip: MaterialLocalizations.of(context).searchFieldLabel,
+ ),
+ if (_volumes.length > 1) _buildVolumeSelector(context),
+ PopupMenuButton<ExplorerAction>(
+ itemBuilder: (context) {
+ return [
+ ExplorerAction.addShortcut,
+ ExplorerAction.setHome,
+ ExplorerAction.hide,
+ null,
+ ExplorerAction.stats,
+ ].map<PopupMenuEntry<ExplorerAction>>((v) {
+ if (v == null) return const PopupMenuDivider();
+ return PopupMenuItem(
+ value: v,
+ child: MenuRow(text: v.getText(context), icon: v.getIcon()),
+ );
+ }).toList();
+ },
+ onSelected: (action) async {
+ // wait for the popup menu to hide before proceeding with the action
+ await Future.delayed(animations.popUpAnimationDelay * timeDilation);
+ final directory = widget.directoryNotifier.value;
+ if (directory != null) {
+ ExplorerActionDelegate(directory: directory).onActionSelected(context, action);
+ }
+ },
+ popUpAnimationStyle: animations.popUpAnimationStyle,
+ ),
+ ].map((v) => FontSizeIconTheme(child: v)).toList();
+ }
+
+ Widget _buildVolumeSelector(BuildContext context) {
+ if (_volumes.length == 2) {
+ return ValueListenableBuilder<VolumeRelativeDirectory?>(
+ valueListenable: widget.directoryNotifier,
+ builder: (context, directory, child) {
+ final currentVolume = directory?.volumePath;
+ final otherVolume = _volumes.firstWhere((volume) => volume.path != currentVolume);
+ final icon = otherVolume.isRemovable ? AIcons.storageCard : AIcons.storageMain;
+ return IconButton(
+ icon: Icon(icon),
+ onPressed: () => widget.goToDir(VolumeRelativeDirectory.volume(otherVolume)),
+ tooltip: otherVolume.getDescription(context),
+ );
+ },
+ );
+ } else {
+ return IconButton(
+ icon: const Icon(AIcons.storageCard),
+ onPressed: () async {
+ _volumes.map((v) {
+ final selected = widget.directoryNotifier.value?.volumePath == v.path;
+ final icon = v.isRemovable ? AIcons.storageCard : AIcons.storageMain;
+ return PopupMenuItem(
+ value: v,
+ enabled: !selected,
+ child: MenuRow(
+ text: v.getDescription(context),
+ icon: Icon(icon),
+ ),
+ );
+ }).toList();
+ final volumePath = widget.directoryNotifier.value?.volumePath;
+ final initialVolume = _volumes.firstWhereOrNull((v) => v.path == volumePath);
+ final volume = await showDialog<StorageVolume?>(
+ context: context,
+ builder: (context) => SelectStorageDialog(initialVolume: initialVolume),
+ routeSettings: const RouteSettings(name: SelectStorageDialog.routeName),
+ );
+ if (volume != null) {
+ widget.goToDir(VolumeRelativeDirectory.volume(volume));
+ }
+ },
+ tooltip: context.l10n.explorerActionSelectStorageVolume,
+ );
+ }
+ }
+
+ double get appBarContentHeight {
+ final textScaler = MediaQuery.textScalerOf(context);
+ return textScaler.scale(kToolbarHeight) + CrumbLine.getPreferredHeight(textScaler);
+ }
+
+ void _goToSearch(BuildContext context) {
+ Navigator.maybeOf(context)?.push(
+ SearchPageRoute(
+ delegate: CollectionSearchDelegate(
+ searchFieldLabel: context.l10n.searchCollectionFieldHint,
+ searchFieldStyle: Themes.searchFieldStyle(context),
+ source: context.read<CollectionSource>(),
+ ),
+ ),
+ );
+ }
+}
diff --git a/lib/widgets/explorer/crumb_line.dart b/lib/widgets/explorer/crumb_line.dart
new file mode 100644
index 0000000..596a626
--- /dev/null
+++ b/lib/widgets/explorer/crumb_line.dart
@@ -0,0 +1,46 @@
+import 'package:aves/services/common/services.dart';
+import 'package:aves/utils/android_file_utils.dart';
+import 'package:aves/view/view.dart';
+import 'package:aves/widgets/common/app_bar/crumb_line.dart';
+import 'package:aves_model/aves_model.dart';
+import 'package:flutter/material.dart';
+
+class ExplorerCrumbLine extends StatelessWidget {
+ final VolumeRelativeDirectory? directory;
+ final void Function(VolumeRelativeDirectory? combinedPath) onTap;
+
+ const ExplorerCrumbLine({
+ super.key,
+ required this.directory,
+ required this.onTap,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ return CrumbLine<VolumeRelativeDirectory?>(
+ split: _split,
+ combine: _combine,
+ onTap: onTap,
+ );
+ }
+
+ List<String> _split(BuildContext context) {
+ final _directory = directory;
+ if (_directory == null) return [];
+ return [
+ _directory.getVolumeDescription(context),
+ ...pContext.split(_directory.relativeDir),
+ ];
+ }
+
+ VolumeRelativeDirectory? _combine(BuildContext context, int index) {
+ final _directory = directory;
+ if (_directory == null) return null;
+
+ final path = pContext.joinAll([
+ _directory.volumePath,
+ ..._split(context).skip(1).take(index),
+ ]);
+ return androidFileUtils.relativeDirectoryFromPath(path);
+ }
+}
diff --git a/lib/widgets/explorer/explorer_action_delegate.dart b/lib/widgets/explorer/explorer_action_delegate.dart
new file mode 100644
index 0000000..3d8641c
--- /dev/null
+++ b/lib/widgets/explorer/explorer_action_delegate.dart
@@ -0,0 +1,124 @@
+import 'package:aves/app_mode.dart';
+import 'package:aves/model/device.dart';
+import 'package:aves/model/entry/entry.dart';
+import 'package:aves/model/filters/path.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/services/common/services.dart';
+import 'package:aves/widgets/common/action_mixins/feedback.dart';
+import 'package:aves/widgets/common/extensions/build_context.dart';
+import 'package:aves/widgets/dialogs/add_shortcut_dialog.dart';
+import 'package:aves/widgets/explorer/explorer_page.dart';
+import 'package:aves/widgets/filter_grids/common/action_delegates/chip.dart';
+import 'package:aves/widgets/stats/stats_page.dart';
+import 'package:aves_model/aves_model.dart';
+import 'package:flutter/material.dart';
+import 'package:provider/provider.dart';
+
+class ExplorerActionDelegate with FeedbackMixin {
+ final VolumeRelativeDirectory directory;
+
+ ExplorerActionDelegate({required this.directory});
+
+ bool isVisible(
+ ExplorerAction action, {
+ required AppMode appMode,
+ }) {
+ final isMain = appMode == AppMode.main;
+ final useTvLayout = settings.useTvLayout;
+ switch (action) {
+ case ExplorerAction.addShortcut:
+ return isMain && device.canPinShortcut;
+ case ExplorerAction.setHome:
+ return isMain && !useTvLayout;
+ case ExplorerAction.hide:
+ case ExplorerAction.stats:
+ return isMain;
+ }
+ }
+
+ bool canApply(ExplorerAction action) {
+ switch (action) {
+ case ExplorerAction.addShortcut:
+ case ExplorerAction.setHome:
+ case ExplorerAction.hide:
+ case ExplorerAction.stats:
+ return true;
+ }
+ }
+
+ void onActionSelected(BuildContext context, ExplorerAction action) {
+ reportService.log('$runtimeType handles $action');
+ switch (action) {
+ case ExplorerAction.addShortcut:
+ _addShortcut(context);
+ case ExplorerAction.setHome:
+ _setHome(context);
+ case ExplorerAction.hide:
+ _hide(context);
+ case ExplorerAction.stats:
+ _goToStats(context);
+ }
+ }
+
+ PathFilter _getPathFilter() => PathFilter(directory.dirPath);
+
+ Future<void> _addShortcut(BuildContext context) async {
+ final filter = _getPathFilter();
+ final defaultName = filter.getLabel(context);
+ final collection = CollectionLens(
+ source: context.read<CollectionSource>(),
+ filters: {filter},
+ );
+
+ final result = await showDialog<(AvesEntry?, String)>(
+ context: context,
+ builder: (context) => AddShortcutDialog(
+ defaultName: defaultName,
+ collection: collection,
+ ),
+ routeSettings: const RouteSettings(name: AddShortcutDialog.routeName),
+ );
+ if (result == null) return;
+
+ final (coverEntry, name) = result;
+ if (name.isEmpty) return;
+
+ await appService.pinToHomeScreen(name, coverEntry, route: ExplorerPage.routeName, path: filter.path);
+ if (!device.showPinShortcutFeedback) {
+ showFeedback(context, FeedbackType.info, context.l10n.genericSuccessFeedback);
+ }
+ }
+
+ void _setHome(BuildContext context) async {
+ settings.setHome(HomePageSetting.explorer, customExplorerPath: directory.dirPath);
+ showFeedback(context, FeedbackType.info, context.l10n.genericSuccessFeedback);
+ }
+
+ void _hide(BuildContext context) {
+ final chipActionDelegate = ChipActionDelegate();
+ const action = ChipAction.hide;
+ final pathFilter = _getPathFilter();
+ if (chipActionDelegate.isVisible(action, filter: pathFilter)) {
+ chipActionDelegate.onActionSelected(context, pathFilter, action);
+ }
+ }
+
+ void _goToStats(BuildContext context) {
+ final collection = CollectionLens(
+ source: context.read<CollectionSource>(),
+ filters: {_getPathFilter()},
+ );
+
+ Navigator.maybeOf(context)?.push(
+ MaterialPageRoute(
+ settings: const RouteSettings(name: StatsPage.routeName),
+ builder: (context) => StatsPage(
+ entries: collection.sortedEntries.toSet(),
+ source: collection.source,
+ ),
+ ),
+ );
+ }
+}
diff --git a/lib/widgets/explorer/explorer_page.dart b/lib/widgets/explorer/explorer_page.dart
new file mode 100644
index 0000000..e03484d
--- /dev/null
+++ b/lib/widgets/explorer/explorer_page.dart
@@ -0,0 +1,297 @@
+import 'dart:async';
+import 'dart:io';
+
+import 'package:aves/model/filters/covered/stored_album.dart';
+import 'package:aves/model/filters/filters.dart';
+import 'package:aves/model/filters/path.dart';
+import 'package:aves/model/source/album.dart';
+import 'package:aves/model/source/collection_source.dart';
+import 'package:aves/services/common/services.dart';
+import 'package:aves/theme/durations.dart';
+import 'package:aves/theme/icons.dart';
+import 'package:aves/utils/android_file_utils.dart';
+import 'package:aves/widgets/collection/collection_page.dart';
+import 'package:aves/widgets/collection/loading.dart';
+import 'package:aves/widgets/common/basic/insets.dart';
+import 'package:aves/widgets/common/basic/scaffold.dart';
+import 'package:aves/widgets/common/behaviour/pop/double_back.dart';
+import 'package:aves/widgets/common/behaviour/pop/scope.dart';
+import 'package:aves/widgets/common/behaviour/pop/tv_navigation.dart';
+import 'package:aves/widgets/common/identity/aves_filter_chip.dart';
+import 'package:aves/widgets/common/identity/empty.dart';
+import 'package:aves/widgets/explorer/app_bar.dart';
+import 'package:aves/widgets/navigation/drawer/app_drawer.dart';
+import 'package:aves_model/aves_model.dart';
+import 'package:collection/collection.dart';
+import 'package:flutter/foundation.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter/scheduler.dart';
+import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
+import 'package:provider/provider.dart';
+
+class ExplorerPage extends StatefulWidget {
+ static const routeName = '/explorer';
+
+ final String? path;
+
+ const ExplorerPage({super.key, this.path});
+
+ @override
+ State<ExplorerPage> createState() => _ExplorerPageState();
+}
+
+class _ExplorerPageState extends State<ExplorerPage> {
+ final Set<StreamSubscription> _subscriptions = {};
+ final ValueNotifier<VolumeRelativeDirectory?> _directory = ValueNotifier(null);
+ final ValueNotifier<VolumeRelativeDirectory?> _contentsDirectory = ValueNotifier(null);
+ final ValueNotifier<List<Directory>> _contents = ValueNotifier([]);
+
+ Set<StorageVolume> get _volumes => androidFileUtils.storageVolumes;
+
+ String? _pathOf(VolumeRelativeDirectory? dir) => dir != null ? pContext.join(dir.volumePath, dir.relativeDir) : null;
+
+ @override
+ void initState() {
+ super.initState();
+ final path = widget.path;
+ if (path != null && androidFileUtils.getStorageVolume(path) != null) {
+ _goToPath(path);
+ } else {
+ final primaryVolume = _volumes.firstWhereOrNull((v) => v.isPrimary);
+ if (primaryVolume != null) {
+ _goToPath(primaryVolume.path);
+ }
+ }
+ _contents.addListener(() => PrimaryScrollController.of(context).jumpTo(0));
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ final source = context.read<CollectionSource>();
+ _subscriptions.add(source.eventBus.on<AlbumsChangedEvent>().listen((event) => _updateContents()));
+ });
+ }
+
+ @override
+ void dispose() {
+ _subscriptions
+ ..forEach((sub) => sub.cancel())
+ ..clear();
+ _directory.dispose();
+ _contents.dispose();
+ super.dispose();
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return ValueListenableBuilder<VolumeRelativeDirectory?>(
+ valueListenable: _directory,
+ builder: (context, directory, child) {
+ final atRoot = directory?.relativeDir.isEmpty ?? true;
+ final path = _pathOf(directory);
+ return AvesPopScope(
+ handlers: [
+ APopHandler(
+ canPop: (context) => atRoot,
+ onPopBlocked: (context) {
+ if (path != null) {
+ _goToPath(pContext.dirname(path));
+ }
+ },
+ ),
+ tvNavigationPopHandler,
+ doubleBackPopHandler,
+ ],
+ child: AvesScaffold(
+ drawer: AppDrawer(currentExplorerPath: path),
+ body: GestureAreaProtectorStack(
+ child: Column(
+ children: [
+ Expanded(
+ child: ValueListenableBuilder<List<Directory>>(
+ valueListenable: _contents,
+ builder: (context, contents, child) {
+ final durations = context.watch<DurationsData>();
+ return CustomScrollView(
+ // workaround to prevent scrolling the app bar away
+ // when there is no content and we use `SliverFillRemaining`
+ physics: contents.isEmpty ? const NeverScrollableScrollPhysics() : null,
+ slivers: [
+ ExplorerAppBar(
+ key: const Key('appbar'),
+ directoryNotifier: _directory,
+ goToDir: _goToDir,
+ ),
+ AnimationLimiter(
+ // animation limiter should not be above the app bar
+ // so that the crumb line can automatically scroll
+ key: ValueKey(contents),
+ child: SliverList.builder(
+ itemBuilder: (context, index) {
+ return AnimationConfiguration.staggeredList(
+ position: index,
+ duration: durations.staggeredAnimation,
+ delay: durations.staggeredAnimationDelay * timeDilation,
+ child: SlideAnimation(
+ verticalOffset: 50.0,
+ child: FadeInAnimation(
+ child: _buildContentLine(context, contents[index]),
+ ),
+ ),
+ );
+ },
+ itemCount: contents.length,
+ ),
+ ),
+ contents.isEmpty
+ ? SliverFillRemaining(
+ hasScrollBody: false,
+ child: _buildEmptyContent(),
+ )
+ : const SliverPadding(padding: EdgeInsets.only(bottom: 8)),
+ ],
+ );
+ },
+ ),
+ ),
+ const Divider(height: 0),
+ ValueListenableBuilder<VolumeRelativeDirectory?>(
+ valueListenable: _contentsDirectory,
+ builder: (context, contentsDirectory, child) {
+ final dirPath = _pathOf(contentsDirectory);
+ return dirPath != null
+ ? SafeArea(
+ top: false,
+ bottom: true,
+ child: Padding(
+ padding: const EdgeInsets.all(8),
+ child: AvesFilterChip(
+ filter: PathFilter(dirPath),
+ maxWidth: double.infinity,
+ onTap: (filter) => _goToCollectionPage(context, filter),
+ onLongPress: null,
+ ),
+ ),
+ )
+ : const SizedBox();
+ },
+ ),
+ ],
+ ),
+ ),
+ ),
+ );
+ },
+ );
+ }
+
+ Widget _buildEmptyContent() {
+ final source = context.read<CollectionSource>();
+ return ValueListenableBuilder<SourceState>(
+ valueListenable: source.stateNotifier,
+ builder: (context, sourceState, child) {
+ if (sourceState == SourceState.loading) {
+ return LoadingEmptyContent(source: source);
+ }
+
+ Widget? bottom;
+ final dirPath = _pathOf(_contentsDirectory.value);
+ if (dirPath != null) {
+ final album = _getAlbumPath(source, Directory(dirPath));
+ if (album != null) {
+ bottom = AvesFilterChip(
+ filter: StoredAlbumFilter(album, source.getStoredAlbumDisplayName(context, album)),
+ maxWidth: double.infinity,
+ onTap: (filter) => _goToCollectionPage(context, filter),
+ onLongPress: null,
+ );
+ }
+ }
+
+ return EmptyContent(
+ icon: AIcons.folder,
+ text: '',
+ bottom: bottom,
+ );
+ },
+ );
+ }
+
+ String? _getAlbumPath(CollectionSource source, FileSystemEntity content) {
+ final contentPath = content.path.toLowerCase();
+ return source.rawAlbums.firstWhereOrNull((v) => v.toLowerCase() == contentPath);
+ }
+
+ Widget _buildContentLine(BuildContext context, FileSystemEntity content) {
+ final source = context.read<CollectionSource>();
+ final album = _getAlbumPath(source, content);
+ final baseIconTheme = IconTheme.of(context);
+
+ const leadingDim = AvesFilterChip.minChipWidth;
+ return ListTile(
+ leading: album != null
+ ? IconTheme.merge(
+ data: baseIconTheme,
+ child: AvesFilterChip(
+ filter: StoredAlbumFilter(album, source.getStoredAlbumDisplayName(context, album)),
+ showText: false,
+ maxWidth: leadingDim,
+ onTap: (filter) => _goToCollectionPage(context, filter),
+ onLongPress: null,
+ ),
+ )
+ : const SizedBox(
+ width: leadingDim,
+ height: leadingDim,
+ child: Icon(AIcons.folder),
+ ),
+ title: Text('${Unicode.FSI}${pContext.split(content.path).last}${Unicode.PDI}'),
+ onTap: () => _goToPath(content.path),
+ );
+ }
+
+ void _goToDir(VolumeRelativeDirectory? dir) {
+ if (dir != null) {
+ _directory.value = dir;
+ _updateContents();
+ }
+ }
+
+ void _goToPath(String path) => _goToDir(androidFileUtils.relativeDirectoryFromPath(path));
+
+ void _updateContents() {
+ final directory = _directory.value;
+ final dirPath = _pathOf(directory);
+ if (dirPath == null) return;
+
+ final contents = <Directory>[];
+ final source = context.read<CollectionSource>();
+ final albums = source.rawAlbums.map((v) => v.toLowerCase()).toSet();
+ Directory(dirPath).list().listen((event) {
+ final entity = event.absolute;
+ if (entity is Directory) {
+ final dirPath = entity.path.toLowerCase();
+ if (albums.any((v) => v.startsWith(dirPath))) {
+ contents.add(entity);
+ }
+ }
+ }, onDone: () {
+ _contents.value = contents
+ ..sort((a, b) {
+ final nameA = pContext.split(a.path).last;
+ final nameB = pContext.split(b.path).last;
+ return compareAsciiUpperCaseNatural(nameA, nameB);
+ });
+ _contentsDirectory.value = directory;
+ });
+ }
+
+ void _goToCollectionPage(BuildContext context, CollectionFilter filter) {
+ Navigator.maybeOf(context)?.push(
+ MaterialPageRoute(
+ settings: const RouteSettings(name: CollectionPage.routeName),
+ builder: (context) => CollectionPage(
+ source: context.read<CollectionSource>(),
+ filters: {filter},
+ ),
+ ),
+ );
+ }
+}