diff --git a/lib/ui/viewer/gallery/gallery_app_bar_widget.dart b/lib/ui/viewer/gallery/gallery_app_bar_widget.dart index 78423addd..b5350f244 100644 --- a/lib/ui/viewer/gallery/gallery_app_bar_widget.dart +++ b/lib/ui/viewer/gallery/gallery_app_bar_widget.dart @@ -68,6 +68,7 @@ enum AlbumPopupAction { setCover, addPhotos, pinAlbum, + removeLink, } class _GalleryAppBarWidgetState extends State { @@ -77,9 +78,12 @@ class _GalleryAppBarWidgetState extends State { String? _appBarTitle; late CollectionActions collectionActions; final GlobalKey shareButtonKey = GlobalKey(); + bool isQuickLink = false; + late GalleryType galleryType; @override void initState() { + super.initState(); _selectedFilesListener = () { setState(() {}); }; @@ -90,7 +94,7 @@ class _GalleryAppBarWidgetState extends State { setState(() {}); }); _appBarTitle = widget.title; - super.initState(); + galleryType = widget.type; } @override @@ -102,15 +106,15 @@ class _GalleryAppBarWidgetState extends State { @override Widget build(BuildContext context) { - return widget.type == GalleryType.homepage + return galleryType == GalleryType.homepage ? const SizedBox.shrink() : AppBar( - backgroundColor: widget.type == GalleryType.homepage + backgroundColor: galleryType == GalleryType.homepage ? const Color(0x00000000) : null, elevation: 0, centerTitle: false, - title: widget.type == GalleryType.homepage + title: galleryType == GalleryType.homepage ? const SizedBox.shrink() : TextButton( child: Text( @@ -127,11 +131,13 @@ class _GalleryAppBarWidgetState extends State { } Future _renameAlbum(BuildContext context) async { - final bool isQuickLink = widget.type == GalleryType.quickLink; - if (widget.type != GalleryType.ownedCollection && widget.type != - GalleryType.quickLink) { - showToast(context, 'Type of galler ${widget.type} is not supported for ' - 'rename',); + if (galleryType != GalleryType.ownedCollection && + galleryType != GalleryType.quickLink) { + showToast( + context, + 'Type of galler $galleryType is not supported for ' + 'rename', + ); return; } final result = await showTextInputDialog( @@ -152,6 +158,11 @@ class _GalleryAppBarWidgetState extends State { await CollectionsService.instance.rename(widget.collection!, text); if (mounted) { _appBarTitle = text; + if (isQuickLink) { + // update the gallery type to owned collection so that correct + // actions are shown + galleryType = GalleryType.ownedCollection; + } setState(() {}); } } catch (e, s) { @@ -265,12 +276,12 @@ class _GalleryAppBarWidgetState extends State { return actions; } final int userID = Configuration.instance.getUserID()!; - final bool isQuickLink = widget.type == GalleryType.quickLink; - if ((widget.type == GalleryType.ownedCollection || - widget.type == GalleryType.sharedCollection || - widget.type == GalleryType.quickLink) && + isQuickLink = widget.collection?.isQuickLinkCollection() ?? false; + if ((galleryType == GalleryType.ownedCollection || + galleryType == GalleryType.sharedCollection || + isQuickLink) && widget.collection?.type != CollectionType.favorites) { - final bool canAddFiles = widget.type == GalleryType.ownedCollection || + final bool canAddFiles = galleryType == GalleryType.ownedCollection || widget.collection!.getRole(userID) == CollectionParticipantRole.collaborator; if (canAddFiles) { @@ -291,8 +302,7 @@ class _GalleryAppBarWidgetState extends State { message: "Share", child: IconButton( icon: Icon( - widget.type == GalleryType.quickLink - ? Icons.link_outlined + isQuickLink ? Icons.link_outlined : Icons.people_outlined, ), onPressed: () async { @@ -303,7 +313,7 @@ class _GalleryAppBarWidgetState extends State { ); } final List> items = []; - if (widget.type == GalleryType.ownedCollection || isQuickLink) { + if (galleryType == GalleryType.ownedCollection || isQuickLink) { if (widget.collection!.type != CollectionType.favorites) { items.add( PopupMenuItem( @@ -340,8 +350,9 @@ class _GalleryAppBarWidgetState extends State { ); } } - if (widget.type == GalleryType.ownedCollection || - widget.type == GalleryType.sharedCollection || isQuickLink) { + if (galleryType == GalleryType.ownedCollection || + galleryType == GalleryType.sharedCollection || + isQuickLink) { items.add( PopupMenuItem( value: AlbumPopupAction.map, @@ -437,7 +448,9 @@ class _GalleryAppBarWidgetState extends State { if (widget.collection!.type != CollectionType.favorites) { items.add( PopupMenuItem( - value: AlbumPopupAction.delete, + value: isQuickLink + ? AlbumPopupAction.removeLink + : AlbumPopupAction.delete, child: Row( children: [ const Icon(Icons.delete_outline), @@ -452,7 +465,7 @@ class _GalleryAppBarWidgetState extends State { } } // ownedCollection open ends - if (widget.type == GalleryType.sharedCollection) { + if (galleryType == GalleryType.sharedCollection) { final bool hasShareeArchived = widget.collection!.hasShareeArchived(); items.add( PopupMenuItem( @@ -489,7 +502,7 @@ class _GalleryAppBarWidgetState extends State { ), ); } - if (widget.type == GalleryType.localFolder) { + if (galleryType == GalleryType.localFolder) { items.add( PopupMenuItem( value: AlbumPopupAction.freeUpSpace, @@ -652,11 +665,11 @@ class _GalleryAppBarWidgetState extends State { final collection = widget.collection; try { if (collection == null || - (widget.type != GalleryType.ownedCollection && - widget.type != GalleryType.sharedCollection && - widget.type != GalleryType.quickLink)) { + (galleryType != GalleryType.ownedCollection && + galleryType != GalleryType.sharedCollection && + !isQuickLink)) { throw Exception( - "Cannot share empty collection of typex ${widget.type}", + "Cannot share empty collection of type $galleryType", ); } if (Configuration.instance.getUserID() == widget.collection!.owner!.id) {