Skip to content

armgit / ente

Public Imported from GitHub
0

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

Enhance CollectionsUpdatedEvent with source parameter and update event firing across services

AmanRajSinghMourya2c87e9512d89
diff --git a/mobile/apps/locker/lib/events/collections_updated_event.dart b/mobile/apps/locker/lib/events/collections_updated_event.dart
index d35e3a15cf..8c88c18b78 100644
--- a/mobile/apps/locker/lib/events/collections_updated_event.dart
+++ b/mobile/apps/locker/lib/events/collections_updated_event.dart
@@ -1,3 +1,7 @@
import 'package:ente_events/models/event.dart';
-class CollectionsUpdatedEvent extends Event {}
+class CollectionsUpdatedEvent extends Event {
+ CollectionsUpdatedEvent(this.source);
+
+ final String source;
+}
diff --git a/mobile/apps/locker/lib/services/collections/collections_api_client.dart b/mobile/apps/locker/lib/services/collections/collections_api_client.dart
index e5bf870f06..05ecac2ce7 100644
--- a/mobile/apps/locker/lib/services/collections/collections_api_client.dart
+++ b/mobile/apps/locker/lib/services/collections/collections_api_client.dart
@@ -429,14 +429,16 @@ class CollectionApiClient {
collection.publicURLs.add(PublicURL.fromMap(response.data["result"]));
await _updateCollectionInDB(collection);
- Bus.instance.fire(CollectionsUpdatedEvent());
+ _logger.info("Firing CollectionsUpdatedEvent: share_url_created");
+ Bus.instance.fire(CollectionsUpdatedEvent("share_url_created"));
}
Future<void> disableShareUrl(Collection collection) async {
await CollectionSharingService.instance.disableShareUrl(collection.id);
collection.publicURLs.clear();
await _updateCollectionInDB(collection);
- Bus.instance.fire(CollectionsUpdatedEvent());
+ _logger.info("Firing CollectionsUpdatedEvent: share_url_disabled");
+ Bus.instance.fire(CollectionsUpdatedEvent("share_url_disabled"));
}
Future<void> updateShareUrl(
@@ -453,7 +455,8 @@ class CollectionApiClient {
collection.publicURLs.clear();
collection.publicURLs.add(PublicURL.fromMap(response.data["result"]));
await _updateCollectionInDB(collection);
- Bus.instance.fire(CollectionsUpdatedEvent());
+ _logger.info("Firing CollectionsUpdatedEvent: share_url_updated");
+ Bus.instance.fire(CollectionsUpdatedEvent("share_url_updated"));
}
Future<List<User>> share(
diff --git a/mobile/apps/locker/lib/services/favorites_service.dart b/mobile/apps/locker/lib/services/favorites_service.dart
index 5e2fba84c3..021357d575 100644
--- a/mobile/apps/locker/lib/services/favorites_service.dart
+++ b/mobile/apps/locker/lib/services/favorites_service.dart
@@ -33,6 +33,9 @@ class FavoritesService {
_db = CollectionDB.instance;
_collectionUpdatesSubscription =
Bus.instance.on<CollectionsUpdatedEvent>().listen((event) {
+ _logger.info(
+ "CollectionsUpdatedEvent received in FavoritesService: ${event.source}",
+ );
// When collections are updated, refresh our cache
_warmUpCache();
});
diff --git a/mobile/apps/locker/lib/ui/collections/collection_flex_grid_view.dart b/mobile/apps/locker/lib/ui/collections/collection_flex_grid_view.dart
index 6f1c6ec92b..62be2afcd4 100644
--- a/mobile/apps/locker/lib/ui/collections/collection_flex_grid_view.dart
+++ b/mobile/apps/locker/lib/ui/collections/collection_flex_grid_view.dart
@@ -1,8 +1,11 @@
import "dart:math";
+import "package:ente_events/event_bus.dart";
import "package:ente_ui/theme/ente_theme.dart";
+import "package:flutter/foundation.dart";
import "package:flutter/material.dart";
import "package:hugeicons/hugeicons.dart";
+import "package:locker/events/collections_updated_event.dart";
import "package:locker/l10n/l10n.dart";
import "package:locker/services/collections/collections_service.dart";
import "package:locker/services/collections/models/collection.dart";
@@ -28,6 +31,21 @@ class _CollectionFlexGridViewWidgetState
void initState() {
super.initState();
_displayedCollections = widget.collections;
+ Bus.instance.on<CollectionsUpdatedEvent>().listen((event) async {
+ if (mounted) {
+ setState(() {});
+ }
+ });
+ }
+
+ @override
+ void didUpdateWidget(CollectionFlexGridViewWidget oldWidget) {
+ super.didUpdateWidget(oldWidget);
+ if (!listEquals(oldWidget.collections, widget.collections)) {
+ setState(() {
+ _displayedCollections = widget.collections;
+ });
+ }
}
@override
diff --git a/mobile/apps/locker/lib/ui/components/collection_popup_menu_widget.dart b/mobile/apps/locker/lib/ui/components/collection_popup_menu_widget.dart
index 2429f17f8b..22dcddaeaa 100644
--- a/mobile/apps/locker/lib/ui/components/collection_popup_menu_widget.dart
+++ b/mobile/apps/locker/lib/ui/components/collection_popup_menu_widget.dart
@@ -178,7 +178,9 @@ class CollectionPopupMenuWidget extends StatelessWidget {
context,
collection,
onSuccess: () {
- Bus.instance.fire(CollectionsUpdatedEvent());
+ Bus.instance.fire(
+ CollectionsUpdatedEvent("rename_collection"),
+ );
},
);
}
@@ -188,7 +190,9 @@ class CollectionPopupMenuWidget extends StatelessWidget {
context,
collection,
onSuccess: () {
- Bus.instance.fire(CollectionsUpdatedEvent());
+ Bus.instance.fire(
+ CollectionsUpdatedEvent("delete_collection"),
+ );
},
);
}
@@ -198,7 +202,9 @@ class CollectionPopupMenuWidget extends StatelessWidget {
context,
collection,
onSuccess: () {
- Bus.instance.fire(CollectionsUpdatedEvent());
+ Bus.instance.fire(
+ CollectionsUpdatedEvent("leave_collection"),
+ );
},
);
}
diff --git a/mobile/apps/locker/lib/ui/components/file_popup_menu_widget.dart b/mobile/apps/locker/lib/ui/components/file_popup_menu_widget.dart
index 106b23bb1c..5e5cfc4f37 100644
--- a/mobile/apps/locker/lib/ui/components/file_popup_menu_widget.dart
+++ b/mobile/apps/locker/lib/ui/components/file_popup_menu_widget.dart
@@ -281,14 +281,21 @@ class FilePopupMenuWidget extends StatelessWidget {
await dialog.show();
try {
- final List<Future<void>> apiCalls = [];
+ final addFutures = <Future<void>>[];
for (final collection in collectionsToAdd) {
- apiCalls.add(
- CollectionService.instance.addToCollection(collection, file),
+ addFutures.add(
+ CollectionService.instance.addToCollection(
+ collection,
+ file,
+ runSync: false,
+ ),
);
}
- await Future.wait(apiCalls);
- apiCalls.clear();
+ if (addFutures.isNotEmpty) {
+ await Future.wait(addFutures);
+ }
+
+ final List<Future<void>> apiCalls = [];
for (final collection in collectionsToRemove) {
apiCalls.add(
diff --git a/mobile/apps/locker/lib/ui/pages/all_collections_page.dart b/mobile/apps/locker/lib/ui/pages/all_collections_page.dart
index 1baa9ebe8f..e396f39219 100644
--- a/mobile/apps/locker/lib/ui/pages/all_collections_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/all_collections_page.dart
@@ -153,20 +153,15 @@ class _AllCollectionsPageState extends State<AllCollectionsPage> {
),
),
),
- body: _buildBody(),
- bottomNavigationBar: widget.selectedCollections != null
- ? ListenableBuilder(
- listenable: widget.selectedCollections!,
- builder: (context, _) {
- return widget.selectedCollections!.hasSelections
- ? CollectionSelectionOverlayBar(
- collection: _sortedCollections,
- selectedCollections: widget.selectedCollections!,
- )
- : const SizedBox.shrink();
- },
- )
- : null,
+ body: Stack(
+ children: [
+ _buildBody(),
+ CollectionSelectionOverlayBar(
+ collection: _sortedCollections,
+ selectedCollections: widget.selectedCollections!,
+ ),
+ ],
+ ),
);
}
diff --git a/mobile/apps/locker/lib/ui/pages/collection_page.dart b/mobile/apps/locker/lib/ui/pages/collection_page.dart
index ba7e958407..3e7b520d5d 100644
--- a/mobile/apps/locker/lib/ui/pages/collection_page.dart
+++ b/mobile/apps/locker/lib/ui/pages/collection_page.dart
@@ -58,6 +58,9 @@ class _CollectionPageState extends UploaderPageState<CollectionPage>
@override
void onFileUploadComplete() {
+ _logger.info(
+ "File upload completed from CollectionPage (${widget.collection.id}), refreshing collection data",
+ );
CollectionService.instance.getCollections().then((collections) {
setState(() {
_initializeData(collections.where((c) => c.id == _collection.id).first);
@@ -108,6 +111,9 @@ class _CollectionPageState extends UploaderPageState<CollectionPage>
_initializeData(widget.collection);
_collectionUpdateSubscription =
Bus.instance.on<CollectionsUpdatedEvent>().listen((event) async {
+ _logger.info(
+ "CollectionsUpdatedEvent received on CollectionPage (${widget.collection.id}): ${event.source}",
+ );
if (!mounted) return;
try {
diff --git a/mobile/apps/locker/lib/ui/viewer/actions/collection_selection_overlay_bar.dart b/mobile/apps/locker/lib/ui/viewer/actions/collection_selection_overlay_bar.dart
index 202b3b0eda..2dc6e30184 100644
--- a/mobile/apps/locker/lib/ui/viewer/actions/collection_selection_overlay_bar.dart
+++ b/mobile/apps/locker/lib/ui/viewer/actions/collection_selection_overlay_bar.dart
@@ -24,142 +24,174 @@ class CollectionSelectionOverlayBar extends StatefulWidget {
class _CollectionSelectionOverlayBarState
extends State<CollectionSelectionOverlayBar> {
+ @override
+ void initState() {
+ super.initState();
+ widget.selectedCollections.addListener(_onSelectionChanged);
+ }
+
+ @override
+ void dispose() {
+ widget.selectedCollections.removeListener(_onSelectionChanged);
+ super.dispose();
+ }
+
+ void _onSelectionChanged() {
+ if (mounted) {
+ setState(() {});
+ }
+ }
+
@override
Widget build(BuildContext context) {
final bottomPadding = MediaQuery.of(context).padding.bottom;
final colorScheme = getEnteColorScheme(context);
final textTheme = getEnteTextTheme(context);
+ final hasSelection = widget.selectedCollections.collections.isNotEmpty;
- return ConstrainedBox(
- constraints: BoxConstraints(
- maxHeight: MediaQuery.of(context).size.height * 0.4,
- ),
- child: Column(
- mainAxisSize: MainAxisSize.min,
- mainAxisAlignment: MainAxisAlignment.end,
- children: [
- Card(
- margin: EdgeInsets.zero,
- shape: const RoundedRectangleBorder(
- borderRadius: BorderRadius.only(
- topLeft: Radius.circular(16),
- topRight: Radius.circular(16),
- ),
- ),
- elevation: 4,
- surfaceTintColor: colorScheme.backdropBase,
- child: Padding(
- padding: EdgeInsets.fromLTRB(16, 16, 16, 28 + bottomPadding),
- child: Column(
- mainAxisSize: MainAxisSize.min,
- children: [
- Row(
- children: [
- ListenableBuilder(
- listenable: widget.selectedCollections,
- builder: (context, child) {
- final isAllSelected =
- widget.selectedCollections.count ==
- widget.collection.length;
- final buttonText = isAllSelected
- ? context.l10n.deselectAll
- : context.l10n.selectAll;
- final iconData = isAllSelected
- ? Icons.remove_circle_outline
- : Icons.check_circle_outline_outlined;
-
- return InkWell(
- onTap: () {
- if (isAllSelected) {
- widget.selectedCollections.clearAll();
- } else {
- widget.selectedCollections
- .select(widget.collection.toSet());
- }
- },
- child: Container(
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(50),
- color: colorScheme.backgroundBase,
- ),
- padding: const EdgeInsets.symmetric(
- horizontal: 12.0,
- vertical: 8.0,
- ),
- child: Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- Text(
- buttonText,
- style: textTheme.small,
- ),
- const SizedBox(width: 6),
- Icon(
- iconData,
- color: colorScheme.textBase,
- size: 16,
- ),
- ],
- ),
- ),
- );
- },
+ return IgnorePointer(
+ ignoring: !hasSelection,
+ child: Align(
+ alignment: Alignment.bottomCenter,
+ child: AnimatedSlide(
+ duration: const Duration(milliseconds: 300),
+ curve: Curves.easeInOutCubic,
+ offset: hasSelection ? Offset.zero : const Offset(0, 1),
+ child: AnimatedOpacity(
+ duration: const Duration(milliseconds: 250),
+ opacity: hasSelection ? 1.0 : 0.0,
+ curve: Curves.easeInOut,
+ child: hasSelection
+ ? Container(
+ decoration: BoxDecoration(
+ color: colorScheme.backdropBase,
+ borderRadius: const BorderRadius.only(
+ topLeft: Radius.circular(16),
+ topRight: Radius.circular(16),
),
- const Spacer(),
- ListenableBuilder(
- listenable: widget.selectedCollections,
- builder: (context, child) {
- final count = widget.selectedCollections.count;
- final countText =
- count == 1 ? '1 selected' : '$count selected';
-
- return InkWell(
- onTap: () {
- widget.selectedCollections.clearAll();
- },
- child: Container(
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(50),
- color: colorScheme.backgroundBase,
- ),
- padding: const EdgeInsets.symmetric(
- horizontal: 12.0,
- vertical: 8.0,
+ border: Border(
+ top: BorderSide(color: colorScheme.strokeFaint),
+ ),
+ ),
+ child: Padding(
+ padding:
+ EdgeInsets.fromLTRB(16, 16, 16, 28 + bottomPadding),
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Row(
+ children: [
+ ListenableBuilder(
+ listenable: widget.selectedCollections,
+ builder: (context, child) {
+ final isAllSelected =
+ widget.selectedCollections.count ==
+ widget.collection.length;
+ final buttonText = isAllSelected
+ ? context.l10n.deselectAll
+ : context.l10n.selectAll;
+ final iconData = isAllSelected
+ ? Icons.remove_circle_outline
+ : Icons.check_circle_outline_outlined;
+
+ return InkWell(
+ onTap: () {
+ if (isAllSelected) {
+ widget.selectedCollections.clearAll();
+ } else {
+ widget.selectedCollections.select(
+ widget.collection.toSet(),
+ );
+ }
+ },
+ child: Container(
+ decoration: BoxDecoration(
+ color: colorScheme.backgroundElevated2,
+ borderRadius: BorderRadius.circular(50),
+ ),
+ padding: const EdgeInsets.symmetric(
+ horizontal: 16.0,
+ vertical: 14.0,
+ ),
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Text(
+ buttonText,
+ style: textTheme.body,
+ ),
+ const SizedBox(width: 6),
+ Icon(
+ iconData,
+ color: getEnteColorScheme(context)
+ .textBase,
+ size: 20,
+ ),
+ ],
+ ),
+ ),
+ );
+ },
),
- child: Row(
- mainAxisSize: MainAxisSize.min,
- children: [
- Text(
- countText,
- style: textTheme.small,
- ),
- const SizedBox(width: 6),
- Icon(
- Icons.close,
- size: 16,
- color: colorScheme.textBase,
- ),
- ],
+ const Spacer(),
+ ListenableBuilder(
+ listenable: widget.selectedCollections,
+ builder: (context, child) {
+ final count =
+ widget.selectedCollections.count;
+ final countText = count == 1
+ ? '1 selected'
+ : '$count selected';
+
+ return InkWell(
+ onTap: () {
+ widget.selectedCollections.clearAll();
+ },
+ child: Container(
+ decoration: BoxDecoration(
+ color: colorScheme.backgroundElevated2,
+ borderRadius: BorderRadius.circular(50),
+ ),
+ padding: const EdgeInsets.symmetric(
+ horizontal: 16.0,
+ vertical: 14.0,
+ ),
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Text(
+ countText,
+ style: textTheme.body,
+ ),
+ const SizedBox(width: 6),
+ Icon(
+ Icons.close,
+ color: getEnteColorScheme(context)
+ .textBase,
+ size: 20,
+ ),
+ ],
+ ),
+ ),
+ );
+ },
),
- ),
- );
- },
+ ],
+ ),
+ const SizedBox(height: 24),
+ _buildActionButtons(),
+ ],
),
- ],
- ),
- const SizedBox(height: 24),
- _buildActionButtons(),
- ],
- ),
- ),
+ ),
+ )
+ : const SizedBox.shrink(),
),
- ],
+ ),
),
);
}
Widget _buildActionButtons() {
- final colorScheme = getEnteColorScheme(context);
return ListenableBuilder(
listenable: widget.selectedCollections,
builder: (context, child) {
@@ -170,22 +202,44 @@ class _CollectionSelectionOverlayBarState
final actions = _getActionsForSelection(selectedCollections);
- return AnimatedContainer(
- duration: const Duration(milliseconds: 200),
- curve: Curves.easeInOut,
- decoration: BoxDecoration(
- color: colorScheme.backgroundBase,
- borderRadius: BorderRadius.circular(12),
- ),
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceEvenly,
- children: actions,
- ),
+ return AnimatedSwitcher(
+ duration: const Duration(milliseconds: 300),
+ switchInCurve: Curves.easeInOut,
+ switchOutCurve: Curves.easeInOut,
+ transitionBuilder: (Widget child, Animation<double> animation) {
+ return FadeTransition(
+ opacity: animation,
+ child: SizeTransition(
+ sizeFactor: animation,
+ child: child,
+ ),
+ );
+ },
+ child: actions.length > 1
+ ? Row(
+ key: const ValueKey('multi_action'),
+ children: _buildActionRow(actions),
+ )
+ : Row(
+ key: const ValueKey('single_action'),
+ children: [Expanded(child: actions.first)],
+ ),
);
},
);
}
+ List<Widget> _buildActionRow(List<Widget> actions) {
+ final children = <Widget>[];
+ for (var i = 0; i < actions.length; i++) {
+ children.add(Expanded(child: actions[i]));
+ if (i != actions.length - 1) {
+ children.add(const SizedBox(width: 12));
+ }
+ }
+ return children;
+ }
+
List<Widget> _getActionsForSelection(
Set<Collection> selectedCollections,
) {
diff --git a/mobile/apps/locker/lib/ui/viewer/actions/file_selection_overlay_bar.dart b/mobile/apps/locker/lib/ui/viewer/actions/file_selection_overlay_bar.dart
index e0be79cd88..d4f7d0d296 100644
--- a/mobile/apps/locker/lib/ui/viewer/actions/file_selection_overlay_bar.dart
+++ b/mobile/apps/locker/lib/ui/viewer/actions/file_selection_overlay_bar.dart
@@ -14,8 +14,6 @@ import "package:locker/ui/components/share_link_dialog.dart";
import "package:locker/utils/snack_bar_utils.dart";
class FileSelectionOverlayBar extends StatefulWidget {
- static const double roughHeight = 300.0;
-
final SelectedFiles selectedFiles;
final List<EnteFile> files;
const FileSelectionOverlayBar({
@@ -439,14 +437,21 @@ class _FileSelectionOverlayBarState extends State<FileSelectionOverlayBar> {
await dialog.show();
try {
- final List<Future<void>> apiCalls = [];
+ final addFutures = <Future<void>>[];
for (final collection in collectionsToAdd) {
- apiCalls.add(
- CollectionService.instance.addToCollection(collection, file),
+ addFutures.add(
+ CollectionService.instance.addToCollection(
+ collection,
+ file,
+ runSync: false,
+ ),
);
}
- await Future.wait(apiCalls);
- apiCalls.clear();
+ if (addFutures.isNotEmpty) {
+ await Future.wait(addFutures);
+ }
+
+ final List<Future<void>> apiCalls = [];
for (final collection in collectionsToRemove) {
apiCalls.add(