π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob][locker] Restore collection chips in upload V2 (#13672)
aman-pilot52ea9911c339
diff --git a/mobile/apps/locker/changes/upload-collection-chips.md b/mobile/apps/locker/changes/upload-collection-chips.mdnew file mode 100644index 0000000000..82faa173db--- /dev/null+++ b/mobile/apps/locker/changes/upload-collection-chips.md@@ -0,0 +1 @@+- Restored collection chips in the redesigned upload screen.diff --git a/mobile/apps/locker/lib/ui/components/collection_selection_widget_v2.dart b/mobile/apps/locker/lib/ui/components/collection_selection_widget_v2.dartdeleted file mode 100644index 3059e2094b..0000000000--- a/mobile/apps/locker/lib/ui/components/collection_selection_widget_v2.dart+++ /dev/null@@ -1,201 +0,0 @@-import 'package:ente_components/ente_components.dart';-import 'package:ente_strings/ente_strings.dart';-import 'package:flutter/material.dart';-import 'package:hugeicons/hugeicons.dart';-import 'package:locker/extensions/collection_extension.dart';-import 'package:locker/services/collections/collections_service.dart';-import 'package:locker/services/collections/models/collection.dart';-import 'package:locker/utils/collection_actions.dart';-import 'package:locker/utils/collection_list_util.dart';-import 'package:locker/utils/file_icon_utils.dart';--class CollectionSelectionWidgetV2 extends StatefulWidget {- final List<Collection> collections;- final Set<int> selectedCollectionIds;- final void Function(int) onToggleCollection;- final void Function(List<Collection>) onCollectionsUpdated;-- const CollectionSelectionWidgetV2({- super.key,- required this.collections,- required this.selectedCollectionIds,- required this.onToggleCollection,- required this.onCollectionsUpdated,- });-- @override- State<CollectionSelectionWidgetV2> createState() =>- _CollectionSelectionWidgetV2State();-}--class _CollectionSelectionWidgetV2State- extends State<CollectionSelectionWidgetV2> {- final Map<int, Future<int>> _fileCounts = {};- final List<Collection> _created = [];-- Future<void> _createCollection() async {- final created = await CollectionActions.createCollection(context);- if (created == null || !mounted) return;- _created.insert(0, created);- widget.onCollectionsUpdated([...widget.collections, created]);- widget.onToggleCollection(created.id);- }-- @override- Widget build(BuildContext context) {- final colors = context.componentColors;- final l10n = context.strings;- final collections = uniqueCollectionsById([- ..._created,- ...widget.collections,- ]);- return ScrollCard(- showScrollbar: true,- itemCount: collections.length + 1,- itemBuilder: (context, index) {- if (index == 0) {- return MenuComponent(- title: l10n.newCollection,- titleColor: colors.primary,- iconColor: colors.primary,- leading: const HugeIcon(- icon: HugeIcons.strokeRoundedAdd01,- size: null,- ),- onTap: _createCollection,- );- }- final collection = collections[index - 1];- return FutureBuilder<int>(- key: ValueKey(collection.id),- future: _fileCounts.putIfAbsent(- collection.id,- () => CollectionService.instance.getFileCount(collection),- ),- builder: (context, count) => MenuComponent(- title: collection.type == CollectionType.uncategorized- ? l10n.uncategorized- : collection.displayName ?? l10n.unnamedCollection,- titleMaxLines: 1,- subtitle: l10n.itemCount(count: count.data ?? 0),- leading: HugeIcon(- icon: collection.type == CollectionType.favorites- ? HugeIcons.strokeRoundedStar- : HugeIcons.strokeRoundedFolder01,- size: null,- ),- trailing: widget.selectedCollectionIds.contains(collection.id)- ? const SelectionCheckBadge()- : null,- onTap: () => widget.onToggleCollection(collection.id),- ),- );- },- );- }-}--class ScrollCard extends StatefulWidget {- final int itemCount;- final IndexedWidgetBuilder itemBuilder;- final bool showScrollbar;-- const ScrollCard({- super.key,- required this.itemCount,- required this.itemBuilder,- this.showScrollbar = false,- });-- @override- State<ScrollCard> createState() => _ScrollCardState();-}--class _ScrollCardState extends State<ScrollCard> {- final _controller = ScrollController();- bool _hasMore = false;-- @override- void dispose() {- _controller.dispose();- super.dispose();- }-- bool _onScroll(Notification notification) {- if (notification- case ScrollMetricsNotification(:final metrics) ||- ScrollUpdateNotification(:final metrics)) {- final hasMore = metrics.extentAfter > 0;- if (hasMore != _hasMore) setState(() => _hasMore = hasMore);- }- return false;- }-- @override- Widget build(BuildContext context) {- final colors = context.componentColors;- return DecoratedBox(- position: DecorationPosition.foreground,- decoration: BoxDecoration(- border: Border.all(color: colors.strokeFaint),- borderRadius: Radii.buttonBorder,- ),- child: ClipRRect(- borderRadius: Radii.buttonBorder,- child: NotificationListener<Notification>(- onNotification: _onScroll,- child: Stack(- children: [- Scrollbar(- controller: _controller,- thumbVisibility: widget.showScrollbar,- child: ListView.separated(- controller: _controller,- physics: const ClampingScrollPhysics(),- shrinkWrap: true,- padding: EdgeInsets.zero,- itemCount: widget.itemCount,- separatorBuilder: (_, _) => ColoredBox(- color: colors.fillLight,- child: const DividerComponent(),- ),- itemBuilder: (context, index) => MenuGroupComponent(- borderRadius: MenuGroupComponent.itemBorderRadius(- index: index,- itemCount: widget.itemCount,- ),- items: [widget.itemBuilder(context, index)],- ),- ),- ),- Positioned(- left: 0,- right: 0,- bottom: 0,- height: Spacing.xxl,- child: IgnorePointer(- child: AnimatedOpacity(- opacity: _hasMore ? 1 : 0,- duration: Motion.quick,- child: DecoratedBox(- decoration: BoxDecoration(- gradient: LinearGradient(- begin: Alignment.topCenter,- end: Alignment.bottomCenter,- colors: [- colors.fillLight.withValues(alpha: 0),- colors.fillLight,- ],- ),- ),- ),- ),- ),- ),- ],- ),- ),- ),- );- }-}diff --git a/mobile/apps/locker/lib/ui/pages/file_upload_screen_v2.dart b/mobile/apps/locker/lib/ui/pages/file_upload_screen_v2.dartindex 96935dfd23..c6ca89c882 100644--- a/mobile/apps/locker/lib/ui/pages/file_upload_screen_v2.dart+++ b/mobile/apps/locker/lib/ui/pages/file_upload_screen_v2.dart@@ -8,7 +8,7 @@ import 'package:flutter/material.dart';import 'package:hugeicons/hugeicons.dart';import 'package:locker/services/collections/models/collection.dart';import 'package:locker/services/configuration.dart';-import 'package:locker/ui/components/collection_selection_widget_v2.dart';+import 'package:locker/ui/components/collection_selection_widget.dart';import 'package:locker/ui/components/text_input_sheet.dart';import 'package:locker/ui/pages/file_upload_screen.dart';import 'package:locker/utils/bottom_sheet_illustration.dart';@@ -109,23 +109,30 @@ class _FileUploadScreenV2State extends State<FileUploadScreenV2> {child: AnimatedOpacity(duration: Motion.standard,opacity: hasFiles ? 1 : 0.5,- child: CollectionSelectionWidgetV2(- collections: _collections,- selectedCollectionIds: _selectedIds,- onToggleCollection: (id) => setState(() {- if (!_selectedIds.remove(id)) {- _selectedIds.add(id);- }- }),- onCollectionsUpdated: (collections) =>- setState(() => _collections = collections),+ child: LayoutBuilder(+ builder: (context, constraints) =>+ CollectionSelectionWidget(+ title: '',+ maxHeight: constraints.maxHeight,+ collections: _collections,+ selectedCollectionIds: _selectedIds,+ onToggleCollection: (id) => setState(() {+ if (!_selectedIds.remove(id)) {+ _selectedIds.add(id);+ }+ }),+ onCollectionsUpdated: (collections) =>+ setState(+ () => _collections = collections,+ ),+ ),),),);final files = AnimatedSwitcher(duration: Motion.standard,child: hasFiles- ? ScrollCard(+ ? _ScrollCard(itemCount: _files.length,itemBuilder: (context, index) {final file = _files[index];@@ -427,3 +434,101 @@ class _EmptyItems extends StatelessWidget {);}}++class _ScrollCard extends StatefulWidget {+ final int itemCount;+ final IndexedWidgetBuilder itemBuilder;++ const _ScrollCard({required this.itemCount, required this.itemBuilder});++ @override+ State<_ScrollCard> createState() => _ScrollCardState();+}++class _ScrollCardState extends State<_ScrollCard> {+ final _controller = ScrollController();+ bool _hasMore = false;++ @override+ void dispose() {+ _controller.dispose();+ super.dispose();+ }++ bool _onScroll(Notification notification) {+ if (notification+ case ScrollMetricsNotification(:final metrics) ||+ ScrollUpdateNotification(:final metrics)) {+ final hasMore = metrics.extentAfter > 0;+ if (hasMore != _hasMore) setState(() => _hasMore = hasMore);+ }+ return false;+ }++ @override+ Widget build(BuildContext context) {+ final colors = context.componentColors;+ return DecoratedBox(+ position: DecorationPosition.foreground,+ decoration: BoxDecoration(+ border: Border.all(color: colors.strokeFaint),+ borderRadius: Radii.buttonBorder,+ ),+ child: ClipRRect(+ borderRadius: Radii.buttonBorder,+ child: NotificationListener<Notification>(+ onNotification: _onScroll,+ child: Stack(+ children: [+ Scrollbar(+ controller: _controller,+ child: ListView.separated(+ controller: _controller,+ physics: const ClampingScrollPhysics(),+ shrinkWrap: true,+ padding: EdgeInsets.zero,+ itemCount: widget.itemCount,+ separatorBuilder: (_, _) => ColoredBox(+ color: colors.fillLight,+ child: const DividerComponent(),+ ),+ itemBuilder: (context, index) => MenuGroupComponent(+ borderRadius: MenuGroupComponent.itemBorderRadius(+ index: index,+ itemCount: widget.itemCount,+ ),+ items: [widget.itemBuilder(context, index)],+ ),+ ),+ ),+ Positioned(+ left: 0,+ right: 0,+ bottom: 0,+ height: Spacing.xxl,+ child: IgnorePointer(+ child: AnimatedOpacity(+ opacity: _hasMore ? 1 : 0,+ duration: Motion.quick,+ child: DecoratedBox(+ decoration: BoxDecoration(+ gradient: LinearGradient(+ begin: Alignment.topCenter,+ end: Alignment.bottomCenter,+ colors: [+ colors.fillLight.withValues(alpha: 0),+ colors.fillLight,+ ],+ ),+ ),+ ),+ ),+ ),+ ),+ ],+ ),+ ),+ ),+ );+ }+}diff --git a/mobile/apps/locker/test/ui/pages/file_upload_screen_v2_test.dart b/mobile/apps/locker/test/ui/pages/file_upload_screen_v2_test.dartindex d212bfe63b..5f2243567c 100644--- a/mobile/apps/locker/test/ui/pages/file_upload_screen_v2_test.dart+++ b/mobile/apps/locker/test/ui/pages/file_upload_screen_v2_test.dart@@ -4,32 +4,74 @@ import 'package:ente_components/ente_components.dart';import 'package:ente_sharing/models/user.dart';import 'package:ente_strings/ente_strings.dart';import 'package:flutter/material.dart';-import 'package:flutter/services.dart';import 'package:flutter_test/flutter_test.dart';import 'package:hugeicons/hugeicons.dart';import 'package:locker/services/collections/models/collection.dart';-import 'package:locker/ui/components/collection_selection_widget_v2.dart';+import 'package:locker/services/configuration.dart';+import 'package:locker/ui/components/collection_selection_widget.dart';+import 'package:locker/ui/pages/file_upload_screen.dart';import 'package:locker/ui/pages/file_upload_screen_v2.dart';+import '../../test_utils/configuration_test_util.dart';+void main() {+ late Directory testRoot;++ setUp(() async {+ testRoot = await setupLockerConfigurationForTest('upload_v2');+ await Configuration.instance.setUserID(1);+ });++ tearDown(() async {+ clearLockerConfigurationTestHandlers();+ await testRoot.delete(recursive: true);+ });++ Collection collection(int id, String name) => Collection(+ id,+ User(id: 1, email: '[email protected]'),+ '',+ null,+ name,+ null,+ null,+ CollectionType.folder,+ CollectionAttributes(),+ const [],+ const [],+ 0,+ );final files = [File('/upload/Passport_scan.pdf'),File('/upload/IMG_4821.png'),];- Future<void> showScreen(WidgetTester tester) async {+ Future<void> showScreen(+ WidgetTester tester, {+ List<Collection> collections = const [],+ List<File>? uploadFiles,+ Collection? selectedCollection,+ void Function(FileUploadScreenResult?)? onSaved,+ }) async {await tester.pumpWidget(MaterialApp(localizationsDelegates: StringsLocalizations.localizationsDelegates,supportedLocales: const [Locale('en')],home: Builder(builder: (context) => TextButton(- onPressed: () => Navigator.of(context).push(- MaterialPageRoute(- builder: (_) =>- FileUploadScreenV2(files: files, collections: const []),- ),- ),+ onPressed: () async {+ final result = await Navigator.of(context)+ .push<FileUploadScreenResult>(+ MaterialPageRoute(+ builder: (_) => FileUploadScreenV2(+ files: uploadFiles ?? files,+ collections: collections,+ selectedCollection: selectedCollection,+ ),+ ),+ );+ onSaved?.call(result);+ },child: const Text('open'),),),@@ -51,6 +93,51 @@ void main() {await tester.pumpAndSettle();}+ testWidgets('collection chips toggle and save the selected destinations', (+ tester,+ ) async {+ final passport = collection(10, 'Passport');+ final travel = collection(20, 'Travel');+ FileUploadScreenResult? saved;+ await showScreen(+ tester,+ collections: [passport, travel],+ selectedCollection: passport,+ onSaved: (result) => saved = result,+ );++ final passportChip = find.widgetWithText(TagChipComponent, 'Passport');+ final travelChip = find.widgetWithText(TagChipComponent, 'Travel');+ expect(+ tester.widget<TagChipComponent>(passportChip).state,+ TagChipComponentState.selected,+ );+ await tester.tap(travelChip);+ await tester.pumpAndSettle();+ expect(find.text('2 selected'), findsOneWidget);+ await tester.tap(passportChip);+ await tester.pumpAndSettle();+ await tester.tap(find.widgetWithText(ButtonComponent, 'Save'));+ await tester.pumpAndSettle();++ expect(saved!.selectedCollections.map((c) => c.id), [20]);+ expect(saved!.files.map((file) => file.path), [+ '/upload/Passport_scan.pdf',+ '/upload/IMG_4821.png',+ ]);+ });++ testWidgets(+ 'saving with no selected collection uses the uncategorized path',+ (tester) async {+ FileUploadScreenResult? saved;+ await showScreen(tester, onSaved: (result) => saved = result);+ await tester.tap(find.widgetWithText(ButtonComponent, 'Save'));+ await tester.pumpAndSettle();+ expect(saved!.selectedCollections, isEmpty);+ },+ );+testWidgets('removing every file shows the empty state instead of popping', (tester,) async {@@ -103,219 +190,65 @@ void main() {expect(find.byType(FileUploadScreenV2), findsNothing);});- testWidgets('a removed file comes back with its original name', (- tester,- ) async {- tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(- const MethodChannel('miguelruivo.flutter.plugins.filepicker'),- (call) async => [- {- 'name': 'Passport_scan.pdf',- 'path': '/upload/Passport_scan.pdf',- 'size': 1,- },- ],- );- addTearDown(- () => tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(- const MethodChannel('miguelruivo.flutter.plugins.filepicker'),- null,- ),- );- await showScreen(tester);-- await openRowMenu(tester);- await tester.tap(find.text('Rename'));- await tester.pumpAndSettle();- await tester.enterText(find.byType(TextField), 'Passport 2026');- await tester.tap(- find.descendant(- of: find.byType(BottomSheetComponent),- matching: find.text('Save'),- ),- );- await tester.pumpAndSettle();- for (var i = 0; i < files.length; i++) {- await openRowMenu(tester);- await tester.tap(find.text('Remove'));- await tester.pumpAndSettle();- }-- await tester.tap(find.text('Add items'));- await tester.pumpAndSettle();-- expect(find.text('Passport_scan.pdf'), findsOneWidget);- expect(find.text('Passport 2026.pdf'), findsNothing);- });-- Future<List<double>> cardHeights(- WidgetTester tester, {- required int files,- required int collections,- TargetPlatform? platform,- }) async {- tester.view.physicalSize = const Size(390, 844);+ Future<void> showLongLists(WidgetTester tester) async {+ tester.view.physicalSize = const Size(320, 520);tester.view.devicePixelRatio = 1;addTearDown(tester.view.reset);- await tester.pumpWidget(- MaterialApp(- theme: ThemeData(platform: platform),- localizationsDelegates: StringsLocalizations.localizationsDelegates,- supportedLocales: const [Locale('en')],- home: FileUploadScreenV2(- key: ValueKey((files, collections)),- files: [for (var i = 0; i < files; i++) File('/upload/f$i.pdf')],- collections: [- for (var i = 0; i < collections; i++)- Collection(- i,- User(id: 1, email: '[email protected]'),- '',- null,- 'Collection $i',- null,- null,- CollectionType.folder,- CollectionAttributes(),- const [],- const [],- 0,- ),- ],- ),- ),+ await showScreen(+ tester,+ uploadFiles: [for (var i = 0; i < 10; i++) File('/upload/f$i.pdf')],+ collections: [+ for (var i = 0; i < 30; i++) collection(i, 'Collection $i'),+ ],);- await tester.pumpAndSettle();- return [- for (final card in tester.widgetList(find.byType(ScrollCard)))- tester.getSize(find.byWidget(card)).height,- ];}- testWidgets('long lists each stop at the same share of the screen', (- tester,- ) async {- final heights = await cardHeights(tester, files: 10, collections: 10);- expect(heights[0], moreOrLessEquals(heights[1]));- expect(heights[0], lessThan(844 * 0.35));- });-- testWidgets('a large batch only builds the visible file rows', (+ testWidgets('file list stops at both scroll boundaries on iOS', (tester,) async {- await cardHeights(tester, files: 1000, collections: 0);- expect(- find.byType(MenuComponent, skipOffstage: false).evaluate().length,- lessThan(50),- );- });-- testWidgets('large system text keeps Save on screen', (tester) async {- tester.view.physicalSize = const Size(320, 568);- tester.view.devicePixelRatio = 1;- tester.platformDispatcher.textScaleFactorTestValue = 3;- addTearDown(tester.view.reset);- addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);- await tester.pumpWidget(- MaterialApp(- localizationsDelegates: StringsLocalizations.localizationsDelegates,- supportedLocales: const [Locale('en')],- home: FileUploadScreenV2(- files: [for (var i = 0; i < 10; i++) File('/upload/f$i.pdf')],- collections: const [],- ),- ),+ await showLongLists(tester);+ final card = find.byType(ListView);+ final scrollable = find.descendant(+ of: card,+ matching: find.byType(Scrollable),);+ final position = tester.state<ScrollableState>(scrollable).position;+ final gesture = await tester.startGesture(tester.getCenter(card));+ await gesture.moveBy(const Offset(0, 30));+ await gesture.moveBy(const Offset(0, 150));+ await tester.pump();+ expect(position.pixels, 0);+ await gesture.up();await tester.pumpAndSettle();- expect(tester.takeException(), isNull);- expect(find.text('Save').hitTestable(), findsOneWidget);- });-- testWidgets('a short file list leaves the rest to collections', (- tester,- ) async {- final heights = await cardHeights(tester, files: 1, collections: 10);- expect(heights[1], greaterThan(heights[0] * 3));- });-- testWidgets('a short portrait phone keeps collections reachable', (- tester,- ) async {- tester.view.physicalSize = const Size(320, 520);- tester.view.devicePixelRatio = 1;- addTearDown(tester.view.reset);- await tester.pumpWidget(- MaterialApp(- localizationsDelegates: StringsLocalizations.localizationsDelegates,- supportedLocales: const [Locale('en')],- home: FileUploadScreenV2(- files: [for (var i = 0; i < 10; i++) File('/upload/f$i.pdf')],- collections: const [],- ),- ),- );+ await tester.drag(card, const Offset(0, -1000));await tester.pumpAndSettle();+ expect(position.pixels, position.maxScrollExtent);+ final endGesture = await tester.startGesture(tester.getCenter(card));+ await endGesture.moveBy(const Offset(0, -30));+ await endGesture.moveBy(const Offset(0, -150));+ await tester.pump();+ expect(position.pixels, position.maxScrollExtent);+ await endGesture.up();+ await tester.pumpAndSettle();+ }, variant: TargetPlatformVariant.only(TargetPlatform.iOS));- expect(tester.takeException(), isNull);- expect(find.text('New collection').hitTestable(), findsOneWidget);- });-- for (var index = 0; index < 2; index++) {- final section = index == 0 ? 'items' : 'collections';- testWidgets('$section stops at both scroll boundaries on iOS', (- tester,- ) async {- await cardHeights(- tester,- files: 10,- collections: 10,- platform: TargetPlatform.iOS,- );-- final card = find.byType(ScrollCard).at(index);- final scrollable = find.descendant(- of: card,- matching: find.byType(Scrollable),- );- final position = tester.state<ScrollableState>(scrollable).position;- final gesture = await tester.startGesture(tester.getCenter(card));- await gesture.moveBy(const Offset(0, 30));- await gesture.moveBy(const Offset(0, 150));- await tester.pump();- expect(position.pixels, 0);- await gesture.up();- await tester.pumpAndSettle();-- await tester.drag(card, const Offset(0, -1000));- await tester.pumpAndSettle();- expect(position.pixels, position.maxScrollExtent);- final endGesture = await tester.startGesture(tester.getCenter(card));- await endGesture.moveBy(const Offset(0, -30));- await endGesture.moveBy(const Offset(0, -150));- await tester.pump();- expect(position.pixels, position.maxScrollExtent);- await endGesture.up();- await tester.pumpAndSettle();- });- }-- testWidgets('file, collection and add icons render at the same size', (+ testWidgets('long collection lists keep selection and Save reachable', (tester,) async {- await cardHeights(tester, files: 2, collections: 1);- final icons = tester.widgetList<HugeIcon>(- find.byWidgetPredicate(- (widget) =>- widget is HugeIcon &&- (widget.icon == HugeIcons.strokeRoundedFile01 ||- widget.icon == HugeIcons.strokeRoundedFolder01 ||- widget.icon == HugeIcons.strokeRoundedAdd01),- ),+ await showLongLists(tester);+ expect(tester.takeException(), isNull);+ expect(find.text('Save').hitTestable(), findsOneWidget);+ final chips = find.byType(CollectionSelectionWidget);+ await tester.drag(chips, const Offset(0, -2000));+ await tester.pumpAndSettle();+ final lastChip = find.widgetWithText(TagChipComponent, 'Collection 29');+ expect(lastChip.hitTestable(), findsOneWidget);+ await tester.tap(lastChip);+ await tester.pumpAndSettle();+ expect(+ tester.widget<TagChipComponent>(lastChip).state,+ TagChipComponentState.selected,);- expect(icons.length, 4);- for (final icon in icons) {- expect(tester.getSize(find.byWidget(icon)), const Size(18, 18));- }});}