Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[mob][photos] refactor: allow favourite album selection for better UX

Aman Raj Singh Mouryadba837c62cbb
diff --git a/mobile/lib/ui/collections/album/list_item.dart b/mobile/lib/ui/collections/album/list_item.dart
index 4d8ffd41ae..ff3837a4b1 100644
--- a/mobile/lib/ui/collections/album/list_item.dart
+++ b/mobile/lib/ui/collections/album/list_item.dart
@@ -30,7 +30,6 @@ class AlbumListItemWidget extends StatelessWidget {
final textTheme = getEnteTextTheme(context);
final colorScheme = getEnteColorScheme(context);
const sideOfThumbnail = 60.0;
- final bool isFavCollection = collection.type == CollectionType.favorites;
return GestureDetector(
onTap: () {
@@ -54,7 +53,7 @@ class AlbumListItemWidget extends StatelessWidget {
duration: const Duration(milliseconds: 200),
decoration: BoxDecoration(
border: Border.all(
- color: isSelected & !isFavCollection
+ color: isSelected
? colorScheme.strokeMuted
: colorScheme.strokeFainter,
),
@@ -153,7 +152,7 @@ class AlbumListItemWidget extends StatelessWidget {
duration: const Duration(milliseconds: 200),
switchInCurve: Curves.easeOut,
switchOutCurve: Curves.easeIn,
- child: isSelected & !isFavCollection
+ child: isSelected
? IconButtonWidget(
key: const ValueKey("selected"),
icon: Icons.check_circle_rounded,
diff --git a/mobile/lib/ui/collections/album/row_item.dart b/mobile/lib/ui/collections/album/row_item.dart
index 481d4bda50..635cbfce88 100644
--- a/mobile/lib/ui/collections/album/row_item.dart
+++ b/mobile/lib/ui/collections/album/row_item.dart
@@ -8,7 +8,6 @@ import "package:photos/models/selected_albums.dart";
import "package:photos/services/collections_service.dart";
import "package:photos/theme/colors.dart";
import 'package:photos/theme/ente_theme.dart';
-import "package:photos/ui/components/buttons/icon_button_widget.dart";
import "package:photos/ui/sharing/album_share_info_widget.dart";
import "package:photos/ui/sharing/user_avator_widget.dart";
import 'package:photos/ui/viewer/file/no_thumbnail_widget.dart';
@@ -40,7 +39,6 @@ class AlbumRowItemWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
- final colorScheme = getEnteColorScheme(context);
final bool isOwner = c.isOwner(Configuration.instance.getUserID()!);
final String tagPrefix = (isOwner ? "collection" : "shared_collection") +
tag +
@@ -53,7 +51,6 @@ class AlbumRowItemWidget extends StatelessWidget {
color: c.publicURLs.first.isExpired ? warning500 : strokeBaseDark,
)
: null;
- final bool isFavCollection = c.type == CollectionType.favorites;
return GestureDetector(
child: Column(
@@ -81,20 +78,33 @@ class AlbumRowItemWidget extends StatelessWidget {
CollectionsService.instance.getCoverCache(c);
}
if (thumbnail != null) {
+ final bool isSelected =
+ selectedAlbums?.isAlbumSelected(c) ?? false;
final String heroTag = tagPrefix + thumbnail.tag;
+ final thumbnailWidget = ThumbnailWidget(
+ thumbnail,
+ shouldShowArchiveStatus: isOwner
+ ? c.isArchived()
+ : c.hasShareeArchived(),
+ showFavForAlbumOnly: true,
+ shouldShowSyncStatus: false,
+ shouldShowPinIcon: isOwner && c.isPinned,
+ key: Key(heroTag),
+ );
return Hero(
tag: heroTag,
transitionOnUserGestures: true,
- child: ThumbnailWidget(
- thumbnail,
- shouldShowArchiveStatus: isOwner
- ? c.isArchived()
- : c.hasShareeArchived(),
- showFavForAlbumOnly: true,
- shouldShowSyncStatus: false,
- shouldShowPinIcon: isOwner && c.isPinned,
- key: Key(heroTag),
- ),
+ child: isSelected
+ ? ColorFiltered(
+ colorFilter: ColorFilter.mode(
+ Colors.black.withOpacity(
+ 0.4,
+ ),
+ BlendMode.darken,
+ ),
+ child: thumbnailWidget,
+ )
+ : thumbnailWidget,
);
} else {
return const NoThumbnailWidget();
@@ -114,8 +124,9 @@ class AlbumRowItemWidget extends StatelessWidget {
),
),
),
- Align(
- alignment: Alignment.topRight,
+ Positioned(
+ top: 6,
+ right: 6,
child: Hero(
tag: tagPrefix + "_album_selection",
transitionOnUserGestures: true,
@@ -128,13 +139,11 @@ class AlbumRowItemWidget extends StatelessWidget {
duration: const Duration(milliseconds: 200),
switchInCurve: Curves.easeOut,
switchOutCurve: Curves.easeIn,
- child: isSelected && !isFavCollection
- ? IconButtonWidget(
- key: const ValueKey("selected"),
- icon: Icons.check_circle_rounded,
- iconButtonType:
- IconButtonType.secondary,
- iconColor: colorScheme.blurStrokeBase,
+ child: isSelected
+ ? const Icon(
+ Icons.check_circle_rounded,
+ color: Colors.white,
+ size: 22,
)
: null,
);
diff --git a/mobile/lib/ui/collections/flex_grid_view.dart b/mobile/lib/ui/collections/flex_grid_view.dart
index 86da018fc8..fb6ef5466d 100644
--- a/mobile/lib/ui/collections/flex_grid_view.dart
+++ b/mobile/lib/ui/collections/flex_grid_view.dart
@@ -88,9 +88,6 @@ class _CollectionsFlexiGridViewWidgetState
Future<void> _toggleAlbumSelection(Collection c) async {
await HapticFeedback.lightImpact();
- if (c.type == CollectionType.favorites) {
- return;
- }
widget.selectedAlbums!.toggleSelection(c);
setState(() {
isAnyAlbumSelected = widget.selectedAlbums!.albums.isNotEmpty;
diff --git a/mobile/lib/ui/viewer/actions/album_selection_action_widget.dart b/mobile/lib/ui/viewer/actions/album_selection_action_widget.dart
index fd8b36ef29..05a47bb33f 100644
--- a/mobile/lib/ui/viewer/actions/album_selection_action_widget.dart
+++ b/mobile/lib/ui/viewer/actions/album_selection_action_widget.dart
@@ -1,3 +1,4 @@
+import "package:flutter/cupertino.dart";
import "package:flutter/material.dart";
import "package:logging/logging.dart";
import "package:photos/db/files_db.dart";
@@ -12,6 +13,7 @@ import "package:photos/ui/components/action_sheet_widget.dart";
import "package:photos/ui/components/bottom_action_bar/selection_action_button_widget.dart";
import "package:photos/ui/components/buttons/button_widget.dart";
import "package:photos/ui/components/models/button_type.dart";
+import "package:photos/ui/notification/toast.dart";
import "package:photos/utils/dialog_util.dart";
import "package:photos/utils/magic_util.dart";
@@ -34,19 +36,31 @@ class _AlbumSelectionActionWidgetState
extends State<AlbumSelectionActionWidget> {
final _logger = Logger("AlbumSelectionActionWidgetState");
late CollectionActions collectionActions;
+ bool hasFavorites = false;
@override
initState() {
collectionActions = CollectionActions(CollectionsService.instance);
+ widget.selectedAlbums.addListener(_selectionChangedListener);
super.initState();
}
+ @override
+ void dispose() {
+ widget.selectedAlbums.removeListener(_selectionChangedListener);
+ super.dispose();
+ }
+
@override
Widget build(BuildContext context) {
if (widget.selectedAlbums.albums.isEmpty) {
return const SizedBox();
}
final List<SelectionActionButton> items = [];
+ final hasPinnedAlbum =
+ widget.selectedAlbums.albums.any((album) => album.isPinned);
+ final hasUnpinnedAlbum =
+ widget.selectedAlbums.albums.any((album) => !album.isPinned);
if (widget.sectionType == UISectionType.homeCollections ||
widget.sectionType == UISectionType.outgoingCollections) {
@@ -62,8 +76,19 @@ class _AlbumSelectionActionWidgetState
labelText: "Pin",
icon: Icons.push_pin_rounded,
onTap: _onPinClick,
+ shouldShow: hasUnpinnedAlbum,
),
);
+
+ items.add(
+ SelectionActionButton(
+ labelText: "Unpin",
+ icon: CupertinoIcons.pin_slash,
+ onTap: _onUnpinClick,
+ shouldShow: hasPinnedAlbum,
+ ),
+ );
+
items.add(
SelectionActionButton(
labelText: S.of(context).delete,
@@ -135,6 +160,9 @@ class _AlbumSelectionActionWidgetState
context,
widget.selectedAlbums.albums.toList(),
);
+ if (hasFavorites) {
+ _showFavToast();
+ }
widget.selectedAlbums.clearAll();
}
@@ -170,6 +198,9 @@ class _AlbumSelectionActionWidgetState
debugPrint("No pop");
}
}
+ if (hasFavorites) {
+ _showFavToast();
+ }
widget.selectedAlbums.clearAll();
}
@@ -185,6 +216,27 @@ class _AlbumSelectionActionWidgetState
collection.isPinned ? 1 : 1,
);
}
+ if (hasFavorites) {
+ _showFavToast();
+ }
+ widget.selectedAlbums.clearAll();
+ }
+
+ Future<void> _onUnpinClick() async {
+ for (final collection in widget.selectedAlbums.albums) {
+ if (collection.type == CollectionType.favorites || !collection.isPinned) {
+ continue;
+ }
+
+ await updateOrder(
+ context,
+ collection,
+ collection.isPinned ? 0 : 0,
+ );
+ }
+ if (hasFavorites) {
+ _showFavToast();
+ }
widget.selectedAlbums.clearAll();
}
@@ -204,6 +256,9 @@ class _AlbumSelectionActionWidgetState
prevVisibility: prevVisiblity,
);
}
+ if (hasFavorites) {
+ _showFavToast();
+ }
widget.selectedAlbums.clearAll();
}
@@ -240,6 +295,9 @@ class _AlbumSelectionActionWidgetState
prevVisibility: prevVisiblity,
);
}
+ if (hasFavorites) {
+ _showFavToast();
+ }
if (mounted) {
setState(() {});
}
@@ -290,4 +348,19 @@ class _AlbumSelectionActionWidgetState
}
}
}
+
+ void _selectionChangedListener() {
+ if (mounted) {
+ hasFavorites = widget.selectedAlbums.albums
+ .any((album) => album.type == CollectionType.favorites);
+ setState(() {});
+ }
+ }
+
+ void _showFavToast() {
+ showShortToast(
+ context,
+ "The Favorites album cannot be modified",
+ );
+ }
}