Skip to content

armgit / ente

Public Imported from GitHub
0

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

feat: Add new album row item widget and update collections grid view

Aman Raj Singh Mourya51d55ee92b73
diff --git a/mobile/lib/ui/collections/album/new_row_item.dart b/mobile/lib/ui/collections/album/new_row_item.dart
new file mode 100644
index 0000000000..6212d17657
--- /dev/null
+++ b/mobile/lib/ui/collections/album/new_row_item.dart
@@ -0,0 +1,96 @@
+import "package:dotted_border/dotted_border.dart";
+import 'package:flutter/material.dart';
+import "package:logging/logging.dart";
+import "package:photos/generated/l10n.dart";
+import 'package:photos/models/collection/collection.dart';
+import 'package:photos/models/collection/collection_items.dart';
+import "package:photos/services/collections_service.dart";
+import "package:photos/theme/ente_theme.dart";
+import "package:photos/ui/viewer/gallery/collection_page.dart";
+import "package:photos/utils/dialog_util.dart";
+import "package:photos/utils/navigation_util.dart";
+
+class NewAlbumRowItemWidget extends StatelessWidget {
+ final Color? color;
+ final double height;
+ final double width;
+ const NewAlbumRowItemWidget({
+ this.color,
+ super.key,
+ required this.height,
+ required this.width,
+ });
+
+ @override
+ Widget build(BuildContext context) {
+ final enteColorScheme = getEnteColorScheme(context);
+ return Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 2.5),
+ child: GestureDetector(
+ onTap: () async {
+ final result = await showTextInputDialog(
+ context,
+ title: S.of(context).newAlbum,
+ submitButtonLabel: S.of(context).create,
+ hintText: S.of(context).enterAlbumName,
+ alwaysShowSuccessState: false,
+ initialValue: "",
+ textCapitalization: TextCapitalization.words,
+ popnavAfterSubmission: false,
+ onSubmit: (String text) async {
+ if (text.trim() == "") {
+ return;
+ }
+
+ try {
+ final Collection c =
+ await CollectionsService.instance.createAlbum(text);
+ // ignore: unawaited_futures
+ await routeToPage(
+ context,
+ CollectionPage(CollectionWithThumbnail(c, null)),
+ );
+ Navigator.of(context).pop();
+ } catch (e, s) {
+ Logger("CreateNewAlbumRowItemWidget")
+ .severe("Failed to rename album", e, s);
+ rethrow;
+ }
+ },
+ );
+
+ if (result is Exception) {
+ await showGenericErrorDialog(context: context, error: result);
+ }
+ },
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ DottedBorder(
+ borderType: BorderType.RRect,
+ strokeWidth: 1.5,
+ borderPadding: const EdgeInsets.all(0.75),
+ dashPattern: const [3.75, 3.75],
+ radius: const Radius.circular(2.35),
+ padding: EdgeInsets.zero,
+ color: enteColorScheme.blurStrokePressed,
+ child: SizedBox(
+ height: height,
+ width: width,
+ child: Icon(
+ Icons.add,
+ color: enteColorScheme.blurStrokePressed,
+ ),
+ ),
+ ),
+ const SizedBox(height: 4),
+ Text(
+ S.of(context).addNew,
+ style: getEnteTextTheme(context).smallFaint,
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+}
diff --git a/mobile/lib/ui/collections/collection_list_page.dart b/mobile/lib/ui/collections/collection_list_page.dart
index 974acdfdbb..1de8aab906 100644
--- a/mobile/lib/ui/collections/collection_list_page.dart
+++ b/mobile/lib/ui/collections/collection_list_page.dart
@@ -57,6 +57,12 @@ class _CollectionListPageState extends State<CollectionListPage> {
@override
Widget build(BuildContext context) {
+ final displayLimitCount = (collections?.length ?? 0);
+ final bool enableSelectionMode =
+ widget.sectionType == UISectionType.homeCollections ||
+ widget.sectionType == UISectionType.outgoingCollections ||
+ widget.sectionType == UISectionType.incomingCollections;
+
return Scaffold(
body: SafeArea(
child: CustomScrollView(
@@ -75,8 +81,10 @@ class _CollectionListPageState extends State<CollectionListPage> {
),
CollectionsFlexiGridViewWidget(
collections,
- displayLimitCount: collections?.length ?? 0,
+ displayLimitCount: displayLimitCount,
tag: widget.tag,
+ enableSelectionMode: enableSelectionMode,
+ scrollBottomSafeArea: 140,
),
],
),
diff --git a/mobile/lib/ui/collections/flex_grid_view.dart b/mobile/lib/ui/collections/flex_grid_view.dart
index 4114ff0493..5fb3349896 100644
--- a/mobile/lib/ui/collections/flex_grid_view.dart
+++ b/mobile/lib/ui/collections/flex_grid_view.dart
@@ -2,16 +2,17 @@ import 'dart:math';
import 'package:flutter/material.dart';
import 'package:photos/models/collection/collection.dart';
+import "package:photos/ui/collections/album/new_row_item.dart";
import "package:photos/ui/collections/album/row_item.dart";
-class CollectionsFlexiGridViewWidget extends StatelessWidget {
+class CollectionsFlexiGridViewWidget extends StatefulWidget {
/*
Aspect ratio 1:1 Max width 224 Fixed gap 8
Width changes dynamically with screen width such that we can fit 2 in one row.
Keep the width integral (center the albums to distribute excess pixels)
*/
- static const maxThumbnailWidth = 224.0;
- static const fixedGapBetweenAlbum = 8.0;
+ static const maxThumbnailWidth = 170.0;
+ static const fixedGapBetweenAlbum = 2.0;
static const minGapForHorizontalPadding = 8.0;
static const collectionItemsToPreload = 20;
@@ -23,45 +24,83 @@ class CollectionsFlexiGridViewWidget extends StatelessWidget {
final bool shrinkWrap;
final String tag;
+ final bool enableSelectionMode;
+ final bool shouldShowCreateAlbum;
+ final double scrollBottomSafeArea;
+
const CollectionsFlexiGridViewWidget(
this.collections, {
this.displayLimitCount = 10,
this.shrinkWrap = false,
this.tag = "",
super.key,
+ this.enableSelectionMode = false,
+ this.shouldShowCreateAlbum = false,
+ this.scrollBottomSafeArea = 8,
});
+ @override
+ State<CollectionsFlexiGridViewWidget> createState() =>
+ _CollectionsFlexiGridViewWidgetState();
+}
+
+class _CollectionsFlexiGridViewWidgetState
+ extends State<CollectionsFlexiGridViewWidget> {
@override
Widget build(BuildContext context) {
final double screenWidth = MediaQuery.of(context).size.width;
- final int albumsCountInOneRow = max(screenWidth ~/ maxThumbnailWidth, 2);
- final double gapBetweenAlbums =
- (albumsCountInOneRow - 1) * fixedGapBetweenAlbum;
+ final int albumsCountInOneRow =
+ max(screenWidth ~/ CollectionsFlexiGridViewWidget.maxThumbnailWidth, 3);
+ final double gapBetweenAlbums = (albumsCountInOneRow - 1) *
+ CollectionsFlexiGridViewWidget.fixedGapBetweenAlbum;
// gapOnSizeOfAlbums will be
- final double gapOnSizeOfAlbums = minGapForHorizontalPadding +
- (screenWidth - gapBetweenAlbums - (2 * minGapForHorizontalPadding)) %
- albumsCountInOneRow;
+ final double gapOnSizeOfAlbums =
+ CollectionsFlexiGridViewWidget.minGapForHorizontalPadding +
+ (screenWidth -
+ gapBetweenAlbums -
+ (2 *
+ CollectionsFlexiGridViewWidget
+ .minGapForHorizontalPadding)) %
+ albumsCountInOneRow;
final double sideOfThumbnail =
(screenWidth - gapOnSizeOfAlbums - gapBetweenAlbums) /
albumsCountInOneRow;
+ final int totalCollections = widget.collections!.length;
+ final bool showCreateAlbum = widget.shouldShowCreateAlbum;
+ final int totalItemCount = totalCollections + (showCreateAlbum ? 1 : 0);
+ final int displayItemCount = min(totalItemCount, widget.displayLimitCount);
+
return SliverPadding(
- padding: const EdgeInsets.all(8),
+ padding: EdgeInsets.only(
+ top: 8,
+ left: 8,
+ right: 8,
+ bottom: widget.scrollBottomSafeArea,
+ ),
sliver: SliverGrid(
delegate: SliverChildBuilderDelegate(
(context, index) {
+ if (showCreateAlbum && index == 0) {
+ return NewAlbumRowItemWidget(
+ height: sideOfThumbnail,
+ width: sideOfThumbnail,
+ );
+ }
+ final collectionIndex = showCreateAlbum ? index - 1 : index;
return AlbumRowItemWidget(
- collections![index],
+ widget.collections![collectionIndex],
sideOfThumbnail,
- tag: tag,
+ tag: widget.tag,
+ showFileCount: false,
);
},
- childCount: min(collections!.length, displayLimitCount),
+ childCount: displayItemCount,
),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: albumsCountInOneRow,
- mainAxisSpacing: 4,
+ mainAxisSpacing: 2,
crossAxisSpacing: gapBetweenAlbums,
childAspectRatio: sideOfThumbnail / (sideOfThumbnail + 46),
),
diff --git a/mobile/lib/ui/tabs/user_collections_tab.dart b/mobile/lib/ui/tabs/user_collections_tab.dart
index afc6178c24..655f9a016c 100644
--- a/mobile/lib/ui/tabs/user_collections_tab.dart
+++ b/mobile/lib/ui/tabs/user_collections_tab.dart
@@ -57,7 +57,7 @@ class _UserCollectionsTabState extends State<UserCollectionsTab>
leading: true,
);
- static const int _kOnEnteItemLimitCount = 10;
+ static const int _kOnEnteItemLimitCount = 12;
@override
void initState() {
super.initState();
@@ -164,6 +164,8 @@ class _UserCollectionsTabState extends State<UserCollectionsTab>
collections,
displayLimitCount: _kOnEnteItemLimitCount,
shrinkWrap: true,
+ shouldShowCreateAlbum: true,
+ enableSelectionMode: true,
)
: const SliverToBoxAdapter(child: EmptyState()),
collections.length > _kOnEnteItemLimitCount