diff --git a/lib/widget/album_browser_util.dart b/lib/widget/album_browser_util.dart new file mode 100644 index 00000000..bbe45b6b --- /dev/null +++ b/lib/widget/album_browser_util.dart @@ -0,0 +1,17 @@ +import 'package:flutter/widgets.dart'; +import 'package:nc_photos/account.dart'; +import 'package:nc_photos/entity/album.dart'; +import 'package:nc_photos/entity/album/provider.dart'; +import 'package:nc_photos/widget/album_browser.dart'; +import 'package:nc_photos/widget/dynamic_album_browser.dart'; + +/// Open the corresponding browser for this album +Future open(BuildContext context, Account account, Album album) { + if (album.provider is AlbumStaticProvider) { + return Navigator.of(context).pushNamed(AlbumBrowser.routeName, + arguments: AlbumBrowserArguments(account, album)); + } else { + return Navigator.of(context).pushNamed(DynamicAlbumBrowser.routeName, + arguments: DynamicAlbumBrowserArguments(account, album)); + } +} diff --git a/lib/widget/home_albums.dart b/lib/widget/home_albums.dart index 8dd814e1..c66e461d 100644 --- a/lib/widget/home_albums.dart +++ b/lib/widget/home_albums.dart @@ -18,7 +18,7 @@ import 'package:nc_photos/k.dart' as k; import 'package:nc_photos/snack_bar_manager.dart'; import 'package:nc_photos/theme.dart'; import 'package:nc_photos/use_case/remove.dart'; -import 'package:nc_photos/widget/album_browser.dart'; +import 'package:nc_photos/widget/album_browser_util.dart' as album_browser_util; import 'package:nc_photos/widget/album_importer.dart'; import 'package:nc_photos/widget/album_search_delegate.dart'; import 'package:nc_photos/widget/archive_browser.dart'; @@ -208,7 +208,7 @@ class _HomeAlbumsState extends State album: item.album, isSelected: _selectedItems.contains(item), isShared: item.isSharedByMe || item.isSharedToMe, - onTap: () => _onItemTap(item), + onTap: () => _onItemTap(context, item), onLongPress: _isSelectionMode ? null : () => _onItemLongPress(item), ).build(context); } @@ -265,7 +265,7 @@ class _HomeAlbumsState extends State } } - void _onItemTap(_GridItem item) { + void _onItemTap(BuildContext context, _GridItem item) { if (_isSelectionMode) { if (!_items.contains(item)) { _log.warning("[_onItemTap] Item not found in backing list, ignoring"); @@ -283,7 +283,7 @@ class _HomeAlbumsState extends State }); } } else { - _openAlbum(item.album); + _openAlbum(context, item.album); } } @@ -375,7 +375,7 @@ class _HomeAlbumsState extends State delegate: AlbumSearchDelegate(context, widget.account), ).then((value) { if (value is Album) { - _openAlbum(value); + _openAlbum(context, value); } }); } @@ -419,14 +419,8 @@ class _HomeAlbumsState extends State ..addAll(newSelectedItems); } - void _openAlbum(Album album) { - if (album.provider is AlbumStaticProvider) { - Navigator.of(context).pushNamed(AlbumBrowser.routeName, - arguments: AlbumBrowserArguments(widget.account, album)); - } else { - Navigator.of(context).pushNamed(DynamicAlbumBrowser.routeName, - arguments: DynamicAlbumBrowserArguments(widget.account, album)); - } + void _openAlbum(BuildContext context, Album album) { + album_browser_util.open(context, widget.account, album); } void _reqQuery() {