π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][photos] Show recent add/move folders on top (#8480)
Neeraj483dae15e7a9
diff --git a/mobile/apps/photos/lib/l10n/intl_en.arb b/mobile/apps/photos/lib/l10n/intl_en.arbindex a4b44f8b9f..93baeef6ac 100644--- a/mobile/apps/photos/lib/l10n/intl_en.arb+++ b/mobile/apps/photos/lib/l10n/intl_en.arb@@ -1412,6 +1412,7 @@"localSyncErrorMessage": "Looks like something went wrong since local photos sync is taking more time than expected. Please reach out to our support team","showPerson": "Show person","sort": "Sort",+ "recent": "Recent","mostRecent": "Most recent","mostRelevant": "Most relevant","loadingYourPhotos": "Loading your photos...",diff --git a/mobile/apps/photos/lib/services/collections_service.dart b/mobile/apps/photos/lib/services/collections_service.dartindex a1fd51ed06..1385bda281 100644--- a/mobile/apps/photos/lib/services/collections_service.dart+++ b/mobile/apps/photos/lib/services/collections_service.dart@@ -76,6 +76,11 @@ class CollectionsService {final _cachedPublicCollectionID = <int>[];final _cachedPublicAlbumKey = <int, String>{};+ // In-memory list of recently used collection IDs for add/move actions+ // Most recently used is at the front+ static const int _maxRecentlyUsedCollections = 3;+ final _recentlyUsedCollectionIDs = <int>[];+CollectionsService._privateConstructor() {_db = CollectionsDB.instance;_filesDB = FilesDB.instance;@@ -402,6 +407,31 @@ class CollectionsService {.toList();}+ /// Records a collection as recently used for add/move actions.+ /// Most recently used collection is moved to front.+ void recordCollectionUsage(int collectionID) {+ _recentlyUsedCollectionIDs.remove(collectionID);+ _recentlyUsedCollectionIDs.insert(0, collectionID);+ if (_recentlyUsedCollectionIDs.length > _maxRecentlyUsedCollections) {+ _recentlyUsedCollectionIDs.removeLast();+ }+ }++ /// Returns a list of recently used collections for add/move actions.+ /// Filters out collections that no longer exist or are hidden.+ List<Collection> getRecentlyUsedCollections() {+ final List<Collection> result = [];+ for (final id in _recentlyUsedCollectionIDs) {+ final collection = _collectionIDToCollections[id];+ if (collection != null &&+ !collection.isDeleted &&+ !collection.isHidden()) {+ result.add(collection);+ }+ }+ return result;+ }+bool canRemoveFilesFromAllParticipants(Collection collection) {final int? userID = _config.getUserID();if (userID == null) {diff --git a/mobile/apps/photos/lib/ui/actions/collection/collection_file_actions.dart b/mobile/apps/photos/lib/ui/actions/collection/collection_file_actions.dartindex bc32c07600..4b19995eac 100644--- a/mobile/apps/photos/lib/ui/actions/collection/collection_file_actions.dart+++ b/mobile/apps/photos/lib/ui/actions/collection/collection_file_actions.dart@@ -165,6 +165,7 @@ extension CollectionFileActions on CollectionActions {await CollectionsService.instance.addOrCopyToCollection(collection.id, files);}+ CollectionsService.instance.recordCollectionUsage(collection.id);} catch (e, s) {logger.severe("Failed to add to album", e, s);await dialog?.hide();diff --git a/mobile/apps/photos/lib/ui/collections/album/vertical_list.dart b/mobile/apps/photos/lib/ui/collections/album/vertical_list.dartindex b4786151fc..fd2a3fe85e 100644--- a/mobile/apps/photos/lib/ui/collections/album/vertical_list.dart+++ b/mobile/apps/photos/lib/ui/collections/album/vertical_list.dart@@ -14,6 +14,7 @@ import 'package:photos/models/selected_files.dart';import 'package:photos/services/collections_service.dart';import "package:photos/services/hidden_service.dart";import 'package:photos/services/sync/remote_sync_service.dart';+import "package:photos/theme/ente_theme.dart";import "package:photos/ui/actions/collection/collection_file_actions.dart";import "package:photos/ui/actions/collection/collection_sharing_actions.dart";import "package:photos/ui/collections/album/column_item.dart";@@ -29,6 +30,7 @@ import 'package:receive_sharing_intent/receive_sharing_intent.dart';class AlbumVerticalListWidget extends StatefulWidget {final List<Collection> collections;+ final List<Collection> recentCollections;final CollectionActionType actionType;final SelectedFiles? selectedFiles;final List<SharedMediaFile>? sharedFiles;@@ -48,6 +50,7 @@ class AlbumVerticalListWidget extends StatefulWidget {this.searchQuery,this.shouldShowCreateAlbum, {required this.selectedCollections,+ this.recentCollections = const [],this.enableSelection = false,this.onSelectionChanged,super.key,@@ -72,38 +75,117 @@ class _AlbumVerticalListWidgetState extends State<AlbumVerticalListWidget> {? widget.selectedPeople!.length: widget.selectedFiles?.files.length ?? 0;- if (widget.collections.isEmpty) {+ final hasRecentCollections = widget.recentCollections.isNotEmpty;++ if (widget.collections.isEmpty && !hasRecentCollections) {if (widget.shouldShowCreateAlbum) {return _getNewAlbumWidget(context, filesCount);}return const EmptyState();}++ // Calculate item count:+ // - Create new album (optional)+ // - Recent header (if recent collections exist)+ // - Recent collections+ // - Divider (if recent collections exist and regular collections exist)+ // - All collections+ final createAlbumOffset = widget.shouldShowCreateAlbum ? 1 : 0;+ final recentHeaderOffset = hasRecentCollections ? 1 : 0;+ final recentItemsCount = widget.recentCollections.length;+ final showDivider = hasRecentCollections && widget.collections.isNotEmpty;+ final dividerOffset = showDivider ? 1 : 0;++ final totalItemCount = createAlbumOffset ++ recentHeaderOffset ++ recentItemsCount ++ dividerOffset ++ widget.collections.length;+return ListView.separated(itemBuilder: (context, index) {+ // Create new album buttonif (index == 0 && widget.shouldShowCreateAlbum) {return _getNewAlbumWidget(context, filesCount);}- final item =- widget.collections[index - (widget.shouldShowCreateAlbum ? 1 : 0)];- return GestureDetector(- behavior: HitTestBehavior.opaque,- onTap: () => widget.enableSelection- ? _toggleCollectionSelection(item)- : _albumListItemOnTap(context, item),- child: AlbumColumnItemWidget(- item,- selectedCollections: widget.selectedCollections,- ),- );++ final adjustedIndex = index - createAlbumOffset;++ // Recent header+ if (hasRecentCollections && adjustedIndex == 0) {+ return _buildSectionHeader(+ context,+ AppLocalizations.of(context).recent,+ );+ }++ // Recent collections+ final recentStartIndex = recentHeaderOffset;+ if (hasRecentCollections &&+ adjustedIndex >= recentStartIndex &&+ adjustedIndex < recentStartIndex + recentItemsCount) {+ final recentIndex = adjustedIndex - recentStartIndex;+ final item = widget.recentCollections[recentIndex];+ return _buildCollectionItem(context, item);+ }++ // Divider between recent and regular collections+ final dividerIndex = recentStartIndex + recentItemsCount;+ if (showDivider && adjustedIndex == dividerIndex) {+ return _buildDivider(context);+ }++ // Regular collections+ final collectionsStartIndex =+ recentStartIndex + recentItemsCount + dividerOffset;+ final collectionIndex = adjustedIndex - collectionsStartIndex;+ final item = widget.collections[collectionIndex];+ return _buildCollectionItem(context, item);},separatorBuilder: (context, index) => const SizedBox(height: 8),- itemCount:- widget.collections.length + (widget.shouldShowCreateAlbum ? 1 : 0),+ itemCount: totalItemCount,shrinkWrap: false,physics: const BouncingScrollPhysics(),);}+ Widget _buildSectionHeader(BuildContext context, String title) {+ final textTheme = getEnteTextTheme(context);+ final colorScheme = getEnteColorScheme(context);+ return Padding(+ padding: const EdgeInsets.only(top: 8, bottom: 4),+ child: Text(+ title,+ style: textTheme.smallMuted.copyWith(color: colorScheme.textMuted),+ ),+ );+ }++ Widget _buildDivider(BuildContext context) {+ final colorScheme = getEnteColorScheme(context);+ return Padding(+ padding: const EdgeInsets.symmetric(vertical: 8),+ child: Divider(+ height: 1,+ thickness: 1,+ color: colorScheme.strokeFaint,+ ),+ );+ }++ Widget _buildCollectionItem(BuildContext context, Collection item) {+ return GestureDetector(+ behavior: HitTestBehavior.opaque,+ onTap: () => widget.enableSelection+ ? _toggleCollectionSelection(item)+ : _albumListItemOnTap(context, item),+ child: AlbumColumnItemWidget(+ item,+ selectedCollections: widget.selectedCollections,+ ),+ );+ }+Future<void> _toggleCollectionSelection(Collection collection,) async {@@ -358,6 +440,7 @@ class _AlbumVerticalListWidgetState extends State<AlbumVerticalListWidget> {sharedFiles: widget.sharedFiles,);if (result) {+ CollectionsService.instance.recordCollectionUsage(collectionID);widget.selectedFiles?.clearAll();}return result;@@ -386,6 +469,7 @@ class _AlbumVerticalListWidgetState extends State<AlbumVerticalListWidget> {fromCollectionID: fromCollectionID,);await dialog.hide();+ CollectionsService.instance.recordCollectionUsage(toCollectionID);unawaited(RemoteSyncService.instance.sync(silently: true));widget.selectedFiles?.clearAll();@@ -420,6 +504,7 @@ class _AlbumVerticalListWidgetState extends State<AlbumVerticalListWidget> {try {await CollectionsService.instance.restore(toCollectionID, widget.selectedFiles!.files.toList());+ CollectionsService.instance.recordCollectionUsage(toCollectionID);unawaited(RemoteSyncService.instance.sync(silently: true));widget.selectedFiles?.clearAll();await dialog.hide();diff --git a/mobile/apps/photos/lib/ui/collections/collection_action_sheet.dart b/mobile/apps/photos/lib/ui/collections/collection_action_sheet.dartindex 118bff7039..b0e315edaf 100644--- a/mobile/apps/photos/lib/ui/collections/collection_action_sheet.dart+++ b/mobile/apps/photos/lib/ui/collections/collection_action_sheet.dart@@ -342,6 +342,19 @@ class _CollectionActionSheetState extends State<CollectionActionSheet> {_removeIncomingCollections(collections);final shouldShowCreateAlbum =widget.showOptionToCreateNewAlbum && _searchQuery.isEmpty;++ // Get recently used collections (only when not searching)+ List<Collection> recentCollections = [];+ if (_searchQuery.isEmpty && !_showOnlyHiddenCollections) {+ recentCollections = CollectionsService.instance+ .getRecentlyUsedCollections()+ .where((c) => !c.isQuickLinkCollection())+ .toList();+ // Remove recent collections from the main list to avoid duplicates+ final recentIds = recentCollections.map((c) => c.id).toSet();+ collections.removeWhere((c) => recentIds.contains(c.id));+ }+final searchResults = _searchQuery.isNotEmpty? collections.where(@@ -365,6 +378,7 @@ class _CollectionActionSheetState extends State<CollectionActionSheet> {widget.selectedPeople,_searchQuery,shouldShowCreateAlbum,+ recentCollections: recentCollections,enableSelection: _enableSelection,selectedCollections: _selectedCollections,onSelectionChanged: () {diff --git a/mobile/apps/photos/scripts/internal_changes.txt b/mobile/apps/photos/scripts/internal_changes.txtindex 7339f9f21d..e0b767fde3 100644--- a/mobile/apps/photos/scripts/internal_changes.txt+++ b/mobile/apps/photos/scripts/internal_changes.txt@@ -1,3 +1,4 @@+- Neeraj: Show recent move/add to collections on top (in memory)- Prateek: (i) Stop streaming if not 75% processed for upload and thermal change- Prateek(i): Stop streaming immediately on log-out- Ashil: Move add to album cta in file viewer from popup menu to bottom bar