From 4fe2af4be1d1f96031459d20fa87b07097044730 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Mon, 18 Jul 2022 10:15:06 +0530 Subject: [PATCH 01/29] made search icon and search text field --- lib/ui/status_bar_widget.dart | 36 +++++++----- lib/ui/viewer/search/searchWidget.dart | 81 ++++++++++++++++++++++++++ lib/utils/date_time_util.dart | 2 + 3 files changed, 106 insertions(+), 13 deletions(-) create mode 100644 lib/ui/viewer/search/searchWidget.dart diff --git a/lib/ui/status_bar_widget.dart b/lib/ui/status_bar_widget.dart index 66b6ed8de..f2b10ee79 100644 --- a/lib/ui/status_bar_widget.dart +++ b/lib/ui/status_bar_widget.dart @@ -6,6 +6,7 @@ import 'package:photos/ente_theme_data.dart'; import 'package:photos/events/sync_status_update_event.dart'; import 'package:photos/services/sync_service.dart'; import 'package:photos/ui/header_error_widget.dart'; +import 'package:photos/ui/viewer/search/searchWidget.dart'; const double kContainerHeight = 36; @@ -209,21 +210,30 @@ class StatusBarBrandingWidget extends StatelessWidget { @override Widget build(BuildContext context) { - return Container( - height: kContainerHeight, - padding: const EdgeInsets.only(left: 12), - child: const Align( - alignment: Alignment.centerLeft, - child: Text( - "ente", - style: TextStyle( - fontWeight: FontWeight.bold, - fontFamily: 'Montserrat', - fontSize: 24, - height: 1, + return Stack( + children: [ + Container( + height: kContainerHeight, + padding: const EdgeInsets.only(left: 12), + child: const Align( + alignment: Alignment.centerLeft, + child: Text( + "ente", + style: TextStyle( + fontWeight: FontWeight.bold, + fontFamily: 'Montserrat', + fontSize: 24, + height: 1, + ), + ), ), ), - ), + SizedBox( + width: MediaQuery.of(context).size.width, + child: Align( + alignment: Alignment.centerRight, child: SearchIconWidget()), + ), + ], ); } } diff --git a/lib/ui/viewer/search/searchWidget.dart b/lib/ui/viewer/search/searchWidget.dart new file mode 100644 index 000000000..43515324d --- /dev/null +++ b/lib/ui/viewer/search/searchWidget.dart @@ -0,0 +1,81 @@ +import 'package:flutter/material.dart'; +import 'package:flutter/src/foundation/key.dart'; +import 'package:flutter/src/widgets/framework.dart'; +import 'package:photos/ente_theme_data.dart'; + +class SearchIconWidget extends StatefulWidget { + bool openSearch; + SearchIconWidget({Key key, this.openSearch = false}) : super(key: key); + + @override + State createState() => _SearchIconWidgetState(); +} + +class _SearchIconWidgetState extends State { + @override + Widget build(BuildContext context) { + return widget.openSearch + ? Searchwidget(widget.openSearch) + : IconButton( + onPressed: () { + setState( + () { + widget.openSearch = !widget.openSearch; + }, + ); + }, + icon: const Icon(Icons.search), + ); + } +} + +class Searchwidget extends StatefulWidget { + bool openSearch; + Searchwidget(this.openSearch, {Key key}) : super(key: key); + + @override + State createState() => _SearchwidgetState(); +} + +class _SearchwidgetState extends State { + TextEditingController searchQuery = TextEditingController(); + + @override + Widget build(BuildContext context) { + return widget.openSearch + ? Row( + children: [ + const SizedBox(width: 12), + Flexible( + child: Container( + color: Theme.of(context).colorScheme.defaultBackgroundColor, + child: TextFormField( + style: Theme.of(context).textTheme.subtitle1, + controller: searchQuery, + decoration: InputDecoration( + filled: true, + contentPadding: const EdgeInsets.symmetric( + horizontal: 16, + vertical: 14, + ), + border: UnderlineInputBorder( + borderSide: BorderSide.none, + borderRadius: BorderRadius.circular(8), + ), + ), + ), + ), + ), + IconButton( + onPressed: () { + setState(() { + widget.openSearch = !widget.openSearch; + }); + }, + icon: const Icon(Icons.close), + ), + ], + ) + : SearchIconWidget(); + } +} diff --git a/lib/utils/date_time_util.dart b/lib/utils/date_time_util.dart index 3991f46b9..4936581ff 100644 --- a/lib/utils/date_time_util.dart +++ b/lib/utils/date_time_util.dart @@ -224,6 +224,8 @@ String getDayTitle(int timestamp) { } String secondsToHHMMSS(int value) { + print("value is ----------------"); + print(value); int h, m, s; h = value ~/ 3600; m = ((value - h * 3600)) ~/ 60; From c281c3dc73bbc3925b37c014a48a279661a8e8f8 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Tue, 19 Jul 2022 14:51:52 +0530 Subject: [PATCH 02/29] made a service to get cached collection ids on search --- lib/services/collections_service.dart | 35 ++++++++++++++++++++++++++ lib/ui/status_bar_widget.dart | 4 ++- lib/ui/viewer/search/searchWidget.dart | 11 ++++++-- 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/lib/services/collections_service.dart b/lib/services/collections_service.dart index b6febdb76..b3d5a5815 100644 --- a/lib/services/collections_service.dart +++ b/lib/services/collections_service.dart @@ -863,6 +863,41 @@ class CollectionsService { } } } + + Set getSearchedCollectionsId(String query) { + Set stringStartsWithQuery = _collectionIDToCollections.values + .toList() + .where( + (element) => + element.name.startsWith(RegExp(query, caseSensitive: false)), + ) + .map((e) => e.id) + .toSet(); + + Set wordStartsWithQuery = _collectionIDToCollections.values + .toList() + .where( + (element) => //"query" for words that come after the 1st word + element.name.contains(RegExp(" $query", caseSensitive: false)), + ) + .map((e) => e.id) + .toSet(); + + Set containesQuery = _collectionIDToCollections.values + .toList() + .where( + (element) => + element.name.contains(RegExp(query, caseSensitive: false)), + ) + .map((e) => e.id) + .toSet(); + + return { + ...stringStartsWithQuery, + ...wordStartsWithQuery, + ...containesQuery + }; + } } class AddFilesRequest { diff --git a/lib/ui/status_bar_widget.dart b/lib/ui/status_bar_widget.dart index f2b10ee79..e1e2da605 100644 --- a/lib/ui/status_bar_widget.dart +++ b/lib/ui/status_bar_widget.dart @@ -231,7 +231,9 @@ class StatusBarBrandingWidget extends StatelessWidget { SizedBox( width: MediaQuery.of(context).size.width, child: Align( - alignment: Alignment.centerRight, child: SearchIconWidget()), + alignment: Alignment.centerRight, + child: SearchIconWidget(), + ), ), ], ); diff --git a/lib/ui/viewer/search/searchWidget.dart b/lib/ui/viewer/search/searchWidget.dart index 43515324d..ef38edcb1 100644 --- a/lib/ui/viewer/search/searchWidget.dart +++ b/lib/ui/viewer/search/searchWidget.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/src/foundation/key.dart'; import 'package:flutter/src/widgets/framework.dart'; import 'package:photos/ente_theme_data.dart'; +import 'package:photos/services/collections_service.dart'; class SearchIconWidget extends StatefulWidget { bool openSearch; @@ -38,7 +39,7 @@ class Searchwidget extends StatefulWidget { } class _SearchwidgetState extends State { - TextEditingController searchQuery = TextEditingController(); + TextEditingController searchController = TextEditingController(); @override Widget build(BuildContext context) { @@ -51,7 +52,7 @@ class _SearchwidgetState extends State { color: Theme.of(context).colorScheme.defaultBackgroundColor, child: TextFormField( style: Theme.of(context).textTheme.subtitle1, - controller: searchQuery, + controller: searchController, decoration: InputDecoration( filled: true, contentPadding: const EdgeInsets.symmetric( @@ -62,7 +63,13 @@ class _SearchwidgetState extends State { borderSide: BorderSide.none, borderRadius: BorderRadius.circular(8), ), + prefixIcon: const Icon(Icons.search), ), + onChanged: (value) { + Set ids = CollectionsService.instance + .getSearchedCollectionsId(value); + debugPrint(ids.toString()); + }, ), ), ), From fd2f89e1b9c1c7a6ab88e09f2193855ea2306873 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Tue, 19 Jul 2022 17:22:16 +0530 Subject: [PATCH 03/29] renamed file + collection search service now returns an object with results marked with levels of relevance --- lib/services/collections_service.dart | 11 ++- .../search/SearchResultsSuggestions.dart | 20 +++++ lib/ui/viewer/search/searchWidget.dart | 80 +++++++++++-------- 3 files changed, 73 insertions(+), 38 deletions(-) create mode 100644 lib/ui/viewer/search/SearchResultsSuggestions.dart diff --git a/lib/services/collections_service.dart b/lib/services/collections_service.dart index b3d5a5815..de465bdf3 100644 --- a/lib/services/collections_service.dart +++ b/lib/services/collections_service.dart @@ -864,7 +864,7 @@ class CollectionsService { } } - Set getSearchedCollectionsId(String query) { + Map getSearchedCollectionsId(String query) { Set stringStartsWithQuery = _collectionIDToCollections.values .toList() .where( @@ -892,10 +892,13 @@ class CollectionsService { .map((e) => e.id) .toSet(); + containesQuery = containesQuery + .difference({...stringStartsWithQuery, ...wordStartsWithQuery}); + return { - ...stringStartsWithQuery, - ...wordStartsWithQuery, - ...containesQuery + 'p1': stringStartsWithQuery, + 'p2': wordStartsWithQuery, + 'p3': containesQuery, }; } } diff --git a/lib/ui/viewer/search/SearchResultsSuggestions.dart b/lib/ui/viewer/search/SearchResultsSuggestions.dart new file mode 100644 index 000000000..9774dbae2 --- /dev/null +++ b/lib/ui/viewer/search/SearchResultsSuggestions.dart @@ -0,0 +1,20 @@ +import 'package:flutter/src/foundation/key.dart'; +import 'package:flutter/src/widgets/framework.dart'; +import 'package:flutter/widgets.dart'; + +class SearchResultsSuggestions extends StatefulWidget { + final Set collectionIds; + const SearchResultsSuggestions({Key key, this.collectionIds}) + : super(key: key); + + @override + State createState() => + _SearchResultsSuggestionsState(); +} + +class _SearchResultsSuggestionsState extends State { + @override + Widget build(BuildContext context) { + return Text('Test'); + } +} diff --git a/lib/ui/viewer/search/searchWidget.dart b/lib/ui/viewer/search/searchWidget.dart index ef38edcb1..4de480264 100644 --- a/lib/ui/viewer/search/searchWidget.dart +++ b/lib/ui/viewer/search/searchWidget.dart @@ -3,6 +3,7 @@ import 'package:flutter/src/foundation/key.dart'; import 'package:flutter/src/widgets/framework.dart'; import 'package:photos/ente_theme_data.dart'; import 'package:photos/services/collections_service.dart'; +import 'package:photos/ui/viewer/search/SearchResultsSuggestions.dart'; class SearchIconWidget extends StatefulWidget { bool openSearch; @@ -32,6 +33,7 @@ class _SearchIconWidgetState extends State { class Searchwidget extends StatefulWidget { bool openSearch; + String searchQuery = ''; Searchwidget(this.openSearch, {Key key}) : super(key: key); @override @@ -39,48 +41,58 @@ class Searchwidget extends StatefulWidget { } class _SearchwidgetState extends State { - TextEditingController searchController = TextEditingController(); - @override Widget build(BuildContext context) { + Map collectionIDs; return widget.openSearch - ? Row( + ? Column( children: [ - const SizedBox(width: 12), - Flexible( - child: Container( - color: Theme.of(context).colorScheme.defaultBackgroundColor, - child: TextFormField( - style: Theme.of(context).textTheme.subtitle1, - controller: searchController, - decoration: InputDecoration( - filled: true, - contentPadding: const EdgeInsets.symmetric( - horizontal: 16, - vertical: 14, + Row( + children: [ + const SizedBox(width: 12), + Flexible( + child: Container( + color: + Theme.of(context).colorScheme.defaultBackgroundColor, + child: TextFormField( + style: Theme.of(context).textTheme.subtitle1, + decoration: InputDecoration( + filled: true, + contentPadding: const EdgeInsets.symmetric( + horizontal: 16, + vertical: 14, + ), + border: UnderlineInputBorder( + borderSide: BorderSide.none, + borderRadius: BorderRadius.circular(8), + ), + prefixIcon: const Icon(Icons.search), + ), + onChanged: (value) { + collectionIDs = CollectionsService.instance + .getSearchedCollectionsId(value); + debugPrint(collectionIDs.toString()); + setState(() { + widget.searchQuery = value; + }); + }, ), - border: UnderlineInputBorder( - borderSide: BorderSide.none, - borderRadius: BorderRadius.circular(8), - ), - prefixIcon: const Icon(Icons.search), ), - onChanged: (value) { - Set ids = CollectionsService.instance - .getSearchedCollectionsId(value); - debugPrint(ids.toString()); - }, ), - ), - ), - IconButton( - onPressed: () { - setState(() { - widget.openSearch = !widget.openSearch; - }); - }, - icon: const Icon(Icons.close), + IconButton( + onPressed: () { + setState(() { + widget.openSearch = !widget.openSearch; + }); + }, + icon: const Icon(Icons.close), + ), + ], ), + const SizedBox(height: 20), + widget.searchQuery != '' + ? SearchResultsSuggestions() + : const SizedBox.shrink(), ], ) : SearchIconWidget(); From ee01b8a0b77cb6acfb0d0e0b4e1e8a4e425090c4 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Wed, 20 Jul 2022 15:47:35 +0530 Subject: [PATCH 04/29] minor changes --- .../viewer/search/SearchResultsSuggestions.dart | 15 ++++++++++++--- lib/ui/viewer/search/searchWidget.dart | 8 ++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/ui/viewer/search/SearchResultsSuggestions.dart b/lib/ui/viewer/search/SearchResultsSuggestions.dart index 9774dbae2..416760ea1 100644 --- a/lib/ui/viewer/search/SearchResultsSuggestions.dart +++ b/lib/ui/viewer/search/SearchResultsSuggestions.dart @@ -3,8 +3,8 @@ import 'package:flutter/src/widgets/framework.dart'; import 'package:flutter/widgets.dart'; class SearchResultsSuggestions extends StatefulWidget { - final Set collectionIds; - const SearchResultsSuggestions({Key key, this.collectionIds}) + final Map collectionIDs; + const SearchResultsSuggestions({Key key, this.collectionIDs}) : super(key: key); @override @@ -15,6 +15,15 @@ class SearchResultsSuggestions extends StatefulWidget { class _SearchResultsSuggestionsState extends State { @override Widget build(BuildContext context) { - return Text('Test'); + return CollectionSuggestions(); + } +} + +class CollectionSuggestions extends StatelessWidget { + const CollectionSuggestions({Key key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return Text('test'); } } diff --git a/lib/ui/viewer/search/searchWidget.dart b/lib/ui/viewer/search/searchWidget.dart index 4de480264..d1575f8c6 100644 --- a/lib/ui/viewer/search/searchWidget.dart +++ b/lib/ui/viewer/search/searchWidget.dart @@ -35,12 +35,13 @@ class Searchwidget extends StatefulWidget { bool openSearch; String searchQuery = ''; Searchwidget(this.openSearch, {Key key}) : super(key: key); - @override State createState() => _SearchwidgetState(); } class _SearchwidgetState extends State { + TextEditingController searchController = TextEditingController(); + @override Widget build(BuildContext context) { Map collectionIDs; @@ -55,6 +56,7 @@ class _SearchwidgetState extends State { color: Theme.of(context).colorScheme.defaultBackgroundColor, child: TextFormField( + controller: searchController, style: Theme.of(context).textTheme.subtitle1, decoration: InputDecoration( filled: true, @@ -91,7 +93,9 @@ class _SearchwidgetState extends State { ), const SizedBox(height: 20), widget.searchQuery != '' - ? SearchResultsSuggestions() + ? SearchResultsSuggestions( + collectionIDs: collectionIDs, + ) : const SizedBox.shrink(), ], ) From 16f89345794096bd3ff895666085c1e92f7d1cdd Mon Sep 17 00:00:00 2001 From: ashilkn Date: Wed, 20 Jul 2022 16:27:45 +0530 Subject: [PATCH 05/29] used valueNotifier to avoid rebuilding the whole searchWidget class on search queries --- lib/ui/viewer/search/searchWidget.dart | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/ui/viewer/search/searchWidget.dart b/lib/ui/viewer/search/searchWidget.dart index d1575f8c6..518c83c3a 100644 --- a/lib/ui/viewer/search/searchWidget.dart +++ b/lib/ui/viewer/search/searchWidget.dart @@ -41,7 +41,7 @@ class Searchwidget extends StatefulWidget { class _SearchwidgetState extends State { TextEditingController searchController = TextEditingController(); - + final ValueNotifier _searchQ = ValueNotifier(''); @override Widget build(BuildContext context) { Map collectionIDs; @@ -74,9 +74,7 @@ class _SearchwidgetState extends State { collectionIDs = CollectionsService.instance .getSearchedCollectionsId(value); debugPrint(collectionIDs.toString()); - setState(() { - widget.searchQuery = value; - }); + _searchQ.value = value; }, ), ), @@ -92,11 +90,21 @@ class _SearchwidgetState extends State { ], ), const SizedBox(height: 20), - widget.searchQuery != '' - ? SearchResultsSuggestions( - collectionIDs: collectionIDs, - ) - : const SizedBox.shrink(), + ValueListenableBuilder( + valueListenable: _searchQ, + builder: ( + BuildContext context, + String newQuery, + Widget child, + ) { + debugPrint('listening to search value'); + return newQuery != '' + ? SearchResultsSuggestions( + collectionIDs: collectionIDs, + ) + : const SizedBox.shrink(); + }, + ), ], ) : SearchIconWidget(); From cb56fc0e6a3570b248bfa2dc204a87da917149cb Mon Sep 17 00:00:00 2001 From: ashilkn Date: Thu, 21 Jul 2022 10:59:57 +0530 Subject: [PATCH 06/29] Widget structure and logic for search suggestion + p1 search for collections --- .../search/SearchResultsSuggestions.dart | 61 +++++++++++++++++-- 1 file changed, 55 insertions(+), 6 deletions(-) diff --git a/lib/ui/viewer/search/SearchResultsSuggestions.dart b/lib/ui/viewer/search/SearchResultsSuggestions.dart index 416760ea1..21e81f527 100644 --- a/lib/ui/viewer/search/SearchResultsSuggestions.dart +++ b/lib/ui/viewer/search/SearchResultsSuggestions.dart @@ -1,6 +1,9 @@ +import 'package:flutter/material.dart'; import 'package:flutter/src/foundation/key.dart'; import 'package:flutter/src/widgets/framework.dart'; import 'package:flutter/widgets.dart'; +import 'package:photos/models/collection.dart'; +import 'package:photos/services/collections_service.dart'; class SearchResultsSuggestions extends StatefulWidget { final Map collectionIDs; @@ -15,15 +18,61 @@ class SearchResultsSuggestions extends StatefulWidget { class _SearchResultsSuggestionsState extends State { @override Widget build(BuildContext context) { - return CollectionSuggestions(); + List p1suggestions = []; + p1suggestions = CollectionSuggestions(widget.collectionIDs) + .getSuggestions(); //add other p1 suggestions to this + return Container( + constraints: + BoxConstraints(maxHeight: MediaQuery.of(context).size.height * 0.7), + child: ListView.builder( + itemCount: p1suggestions.length, + itemBuilder: (context, index) { + return p1suggestions[index]; + }, + ), + ); } } -class CollectionSuggestions extends StatelessWidget { - const CollectionSuggestions({Key key}) : super(key: key); +class CollectionSuggestions { + final Map collectionIDs; + const CollectionSuggestions(this.collectionIDs); - @override - Widget build(BuildContext context) { - return Text('test'); + List getSuggestions() { + List p1IDs = collectionIDs['p1'].toList(); + List p2IDs = collectionIDs['p2'].toList(); + List p3IDs = collectionIDs['p3'].toList(); + List collectionsP1 = []; + List collectionsP2 = []; + List collectionsP3 = []; + Collection collection = + CollectionsService.instance.getCollectionByID(p1IDs[0]); + p1IDs.forEach( + (element) { + Collection collection = + CollectionsService.instance.getCollectionByID(element); + collectionsP1.add( + Row( + children: [ + Column( + children: [ + const Text('Album'), + Text(collection.name), + Text('10 memories'), + ], + ), + Row( + children: [ + Icon(Icons.access_alarms), + Icon(Icons.access_alarms), + Icon(Icons.access_alarms), + ], + ) + ], + ), + ); + }, + ); + return collectionsP1; } } From ee2d15dc68905591c6695ed8707e71a80341bde8 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Thu, 21 Jul 2022 11:25:25 +0530 Subject: [PATCH 07/29] code refactoring --- .../search/SearchResultsSuggestions.dart | 48 +------------------ .../viewer/search/collectionSuggestions.dart | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+), 47 deletions(-) create mode 100644 lib/ui/viewer/search/collectionSuggestions.dart diff --git a/lib/ui/viewer/search/SearchResultsSuggestions.dart b/lib/ui/viewer/search/SearchResultsSuggestions.dart index 21e81f527..89ef9eafb 100644 --- a/lib/ui/viewer/search/SearchResultsSuggestions.dart +++ b/lib/ui/viewer/search/SearchResultsSuggestions.dart @@ -1,9 +1,6 @@ import 'package:flutter/material.dart'; -import 'package:flutter/src/foundation/key.dart'; -import 'package:flutter/src/widgets/framework.dart'; import 'package:flutter/widgets.dart'; -import 'package:photos/models/collection.dart'; -import 'package:photos/services/collections_service.dart'; +import 'package:photos/ui/viewer/search/collectionSuggestions.dart'; class SearchResultsSuggestions extends StatefulWidget { final Map collectionIDs; @@ -33,46 +30,3 @@ class _SearchResultsSuggestionsState extends State { ); } } - -class CollectionSuggestions { - final Map collectionIDs; - const CollectionSuggestions(this.collectionIDs); - - List getSuggestions() { - List p1IDs = collectionIDs['p1'].toList(); - List p2IDs = collectionIDs['p2'].toList(); - List p3IDs = collectionIDs['p3'].toList(); - List collectionsP1 = []; - List collectionsP2 = []; - List collectionsP3 = []; - Collection collection = - CollectionsService.instance.getCollectionByID(p1IDs[0]); - p1IDs.forEach( - (element) { - Collection collection = - CollectionsService.instance.getCollectionByID(element); - collectionsP1.add( - Row( - children: [ - Column( - children: [ - const Text('Album'), - Text(collection.name), - Text('10 memories'), - ], - ), - Row( - children: [ - Icon(Icons.access_alarms), - Icon(Icons.access_alarms), - Icon(Icons.access_alarms), - ], - ) - ], - ), - ); - }, - ); - return collectionsP1; - } -} diff --git a/lib/ui/viewer/search/collectionSuggestions.dart b/lib/ui/viewer/search/collectionSuggestions.dart new file mode 100644 index 000000000..86b5142db --- /dev/null +++ b/lib/ui/viewer/search/collectionSuggestions.dart @@ -0,0 +1,48 @@ +import 'package:flutter/material.dart'; +import 'package:photos/models/collection.dart'; +import 'package:photos/services/collections_service.dart'; + +class CollectionSuggestions { + final Map collectionIDs; + const CollectionSuggestions(this.collectionIDs); + + List getSuggestions() { + List p1IDs = collectionIDs['p1'].toList(); + List p2IDs = collectionIDs['p2'].toList(); + List p3IDs = collectionIDs['p3'].toList(); + List collectionsP1 = []; + List collectionsP2 = []; + List collectionsP3 = []; + return collectionsP1 = generateSuggestionWidgets(p1IDs, collectionsP1); + } + + List generateSuggestionWidgets( + List pIDs, + List pCollection, + ) { + for (int id in pIDs) { + Collection collection = CollectionsService.instance.getCollectionByID(id); + pCollection.add( + Row( + children: [ + Column( + children: [ + const Text('Album'), + Text(collection.name), + Text('10 memories'), + ], + ), + Row( + children: [ + Icon(Icons.access_alarms), + Icon(Icons.access_alarms), + Icon(Icons.access_alarms), + ], + ) + ], + ), + ); + } + return pCollection; + } +} From 92a5e4443722756975569fcb833e30f6578c19e1 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Thu, 21 Jul 2022 11:42:41 +0530 Subject: [PATCH 08/29] search suggestions for collections now include p1, p2, p3 results --- lib/ui/viewer/search/collectionSuggestions.dart | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/ui/viewer/search/collectionSuggestions.dart b/lib/ui/viewer/search/collectionSuggestions.dart index 86b5142db..3545250f9 100644 --- a/lib/ui/viewer/search/collectionSuggestions.dart +++ b/lib/ui/viewer/search/collectionSuggestions.dart @@ -13,16 +13,19 @@ class CollectionSuggestions { List collectionsP1 = []; List collectionsP2 = []; List collectionsP3 = []; - return collectionsP1 = generateSuggestionWidgets(p1IDs, collectionsP1); + collectionsP1 = generateSuggestionWidgets(p1IDs, collectionsP1); + collectionsP2 = generateSuggestionWidgets(p2IDs, collectionsP2); + collectionsP3 = generateSuggestionWidgets(p3IDs, collectionsP3); + return [...collectionsP1, ...collectionsP2, ...collectionsP3]; } List generateSuggestionWidgets( List pIDs, - List pCollection, + List pCollections, ) { for (int id in pIDs) { Collection collection = CollectionsService.instance.getCollectionByID(id); - pCollection.add( + pCollections.add( Row( children: [ Column( @@ -43,6 +46,6 @@ class CollectionSuggestions { ), ); } - return pCollection; + return pCollections; } } From f63c6974c99c00d8fbb50595a7b222def72dc5e0 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Thu, 21 Jul 2022 19:17:41 +0530 Subject: [PATCH 09/29] minor changes --- lib/ui/common/dynamic_fab.dart | 4 +--- lib/ui/home_widget.dart | 1 + lib/ui/viewer/search/searchWidget.dart | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/ui/common/dynamic_fab.dart b/lib/ui/common/dynamic_fab.dart index 5045e7df5..1b89ba1ac 100644 --- a/lib/ui/common/dynamic_fab.dart +++ b/lib/ui/common/dynamic_fab.dart @@ -63,9 +63,7 @@ class DynamicFAB extends StatelessWidget { height: 56, padding: const EdgeInsets.symmetric(horizontal: 20), child: OutlinedButton( - onPressed: isFormValid //var here - ? onPressedFunction - : null, + onPressed: isFormValid ? onPressedFunction : null, child: Text(buttonText), ), ); diff --git a/lib/ui/home_widget.dart b/lib/ui/home_widget.dart index 898204d29..14c964801 100644 --- a/lib/ui/home_widget.dart +++ b/lib/ui/home_widget.dart @@ -260,6 +260,7 @@ class _HomeWidgetState extends State { child: Container(), ), body: _getBody(), + resizeToAvoidBottomInset: false, ), onWillPop: () async { if (_selectedTabIndex == 0) { diff --git a/lib/ui/viewer/search/searchWidget.dart b/lib/ui/viewer/search/searchWidget.dart index 518c83c3a..dea681a42 100644 --- a/lib/ui/viewer/search/searchWidget.dart +++ b/lib/ui/viewer/search/searchWidget.dart @@ -40,7 +40,6 @@ class Searchwidget extends StatefulWidget { } class _SearchwidgetState extends State { - TextEditingController searchController = TextEditingController(); final ValueNotifier _searchQ = ValueNotifier(''); @override Widget build(BuildContext context) { @@ -56,7 +55,6 @@ class _SearchwidgetState extends State { color: Theme.of(context).colorScheme.defaultBackgroundColor, child: TextFormField( - controller: searchController, style: Theme.of(context).textTheme.subtitle1, decoration: InputDecoration( filled: true, @@ -76,6 +74,7 @@ class _SearchwidgetState extends State { debugPrint(collectionIDs.toString()); _searchQ.value = value; }, + autofocus: true, ), ), ), From 5088800c7c0f5734dc699966e3a0fa17d186b4bd Mon Sep 17 00:00:00 2001 From: ashilkn Date: Sat, 23 Jul 2022 11:30:12 +0530 Subject: [PATCH 10/29] clicking on suggested colleciton now routes to colleciton page --- lib/ui/collections_gallery_widget.dart | 1 - .../search/SearchResultsSuggestions.dart | 4 +- .../viewer/search/collectionSuggestions.dart | 46 +++++++++++-------- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/lib/ui/collections_gallery_widget.dart b/lib/ui/collections_gallery_widget.dart index 44595a02b..0e8942f99 100644 --- a/lib/ui/collections_gallery_widget.dart +++ b/lib/ui/collections_gallery_widget.dart @@ -591,7 +591,6 @@ class DeviceFolderIcon extends StatelessWidget { child: SizedBox( height: 140, width: 120, - // padding: const EdgeInsets.all(8.0), child: Column( children: [ ClipRRect( diff --git a/lib/ui/viewer/search/SearchResultsSuggestions.dart b/lib/ui/viewer/search/SearchResultsSuggestions.dart index 89ef9eafb..98c77fd0d 100644 --- a/lib/ui/viewer/search/SearchResultsSuggestions.dart +++ b/lib/ui/viewer/search/SearchResultsSuggestions.dart @@ -16,8 +16,8 @@ class _SearchResultsSuggestionsState extends State { @override Widget build(BuildContext context) { List p1suggestions = []; - p1suggestions = CollectionSuggestions(widget.collectionIDs) - .getSuggestions(); //add other p1 suggestions to this + p1suggestions = CollectionSuggestions(widget.collectionIDs, context) + .getSuggestions(); //add other search type p1 suggestions to this return Container( constraints: BoxConstraints(maxHeight: MediaQuery.of(context).size.height * 0.7), diff --git a/lib/ui/viewer/search/collectionSuggestions.dart b/lib/ui/viewer/search/collectionSuggestions.dart index 3545250f9..c228e9bc4 100644 --- a/lib/ui/viewer/search/collectionSuggestions.dart +++ b/lib/ui/viewer/search/collectionSuggestions.dart @@ -1,10 +1,14 @@ import 'package:flutter/material.dart'; import 'package:photos/models/collection.dart'; +import 'package:photos/models/collection_items.dart'; import 'package:photos/services/collections_service.dart'; +import 'package:photos/ui/viewer/gallery/collection_page.dart'; +import 'package:photos/utils/navigation_util.dart'; class CollectionSuggestions { final Map collectionIDs; - const CollectionSuggestions(this.collectionIDs); + final BuildContext context; + const CollectionSuggestions(this.collectionIDs, this.context); List getSuggestions() { List p1IDs = collectionIDs['p1'].toList(); @@ -25,24 +29,30 @@ class CollectionSuggestions { ) { for (int id in pIDs) { Collection collection = CollectionsService.instance.getCollectionByID(id); + CollectionWithThumbnail c = CollectionWithThumbnail(collection, null); pCollections.add( - Row( - children: [ - Column( - children: [ - const Text('Album'), - Text(collection.name), - Text('10 memories'), - ], - ), - Row( - children: [ - Icon(Icons.access_alarms), - Icon(Icons.access_alarms), - Icon(Icons.access_alarms), - ], - ) - ], + GestureDetector( + child: Row( + children: [ + Column( + children: [ + const Text('Album'), + Text(collection.name), + Text('10 memories'), + ], + ), + Row( + children: [ + Icon(Icons.access_alarms), + Icon(Icons.access_alarms), + Icon(Icons.access_alarms), + ], + ) + ], + ), + onTap: () { + routeToPage(context, CollectionPage(c)); + }, ), ); } From 3fa69c774ae16a0047236b9477624b20c36919a3 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Sat, 23 Jul 2022 12:45:07 +0530 Subject: [PATCH 11/29] added number of memories (number of files) for seach suggested collections --- lib/ui/collections_gallery_widget.dart | 2 +- .../viewer/search/collectionSuggestions.dart | 30 ++++++++++++++++++- lib/ui/viewer/search/searchWidget.dart | 2 +- 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/lib/ui/collections_gallery_widget.dart b/lib/ui/collections_gallery_widget.dart index 0e8942f99..6fe93af72 100644 --- a/lib/ui/collections_gallery_widget.dart +++ b/lib/ui/collections_gallery_widget.dart @@ -708,7 +708,7 @@ class CollectionItem extends StatelessWidget { ), ); } else { - return Container(); + return const SizedBox.shrink(); } }, ), diff --git a/lib/ui/viewer/search/collectionSuggestions.dart b/lib/ui/viewer/search/collectionSuggestions.dart index c228e9bc4..7df4c07ba 100644 --- a/lib/ui/viewer/search/collectionSuggestions.dart +++ b/lib/ui/viewer/search/collectionSuggestions.dart @@ -1,4 +1,6 @@ import 'package:flutter/material.dart'; +import 'package:photos/db/files_db.dart'; +import 'package:photos/ente_theme_data.dart'; import 'package:photos/models/collection.dart'; import 'package:photos/models/collection_items.dart'; import 'package:photos/services/collections_service.dart'; @@ -38,7 +40,33 @@ class CollectionSuggestions { children: [ const Text('Album'), Text(collection.name), - Text('10 memories'), + FutureBuilder( + future: FilesDB.instance.collectionFileCount(id), + builder: (context, snapshot) { + if (snapshot.hasData && snapshot.data > 0) { + int noOfMemories = snapshot.data; + + return RichText( + text: TextSpan( + style: TextStyle( + color: Theme.of(context) + .colorScheme + .defaultTextColor, + ), + children: [ + TextSpan(text: noOfMemories.toString()), + TextSpan( + text: + noOfMemories != 1 ? ' memories' : ' memory', + ), + ], + ), + ); + } else { + return const SizedBox.shrink(); + } + }, + ), ], ), Row( diff --git a/lib/ui/viewer/search/searchWidget.dart b/lib/ui/viewer/search/searchWidget.dart index dea681a42..d679dc12d 100644 --- a/lib/ui/viewer/search/searchWidget.dart +++ b/lib/ui/viewer/search/searchWidget.dart @@ -33,7 +33,7 @@ class _SearchIconWidgetState extends State { class Searchwidget extends StatefulWidget { bool openSearch; - String searchQuery = ''; + final String searchQuery = ''; Searchwidget(this.openSearch, {Key key}) : super(key: key); @override State createState() => _SearchwidgetState(); From bf9a4479bc799d64e77a3d9b8dd199ed9071f067 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Mon, 25 Jul 2022 11:24:04 +0530 Subject: [PATCH 12/29] added thumbnail for collection suggestions --- .../viewer/search/collectionSuggestions.dart | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/lib/ui/viewer/search/collectionSuggestions.dart b/lib/ui/viewer/search/collectionSuggestions.dart index 7df4c07ba..af0ba6eae 100644 --- a/lib/ui/viewer/search/collectionSuggestions.dart +++ b/lib/ui/viewer/search/collectionSuggestions.dart @@ -1,9 +1,13 @@ +import 'dart:developer'; + import 'package:flutter/material.dart'; import 'package:photos/db/files_db.dart'; import 'package:photos/ente_theme_data.dart'; import 'package:photos/models/collection.dart'; import 'package:photos/models/collection_items.dart'; +import 'package:photos/models/file.dart'; import 'package:photos/services/collections_service.dart'; +import 'package:photos/ui/viewer/file/thumbnail_widget.dart'; import 'package:photos/ui/viewer/gallery/collection_page.dart'; import 'package:photos/utils/navigation_util.dart'; @@ -29,12 +33,16 @@ class CollectionSuggestions { List pIDs, List pCollections, ) { + Future> latestCollectionFiles = + CollectionsService.instance.getLatestCollectionFiles(); for (int id in pIDs) { Collection collection = CollectionsService.instance.getCollectionByID(id); - CollectionWithThumbnail c = CollectionWithThumbnail(collection, null); + // CollectionWithThumbnail c = CollectionWithThumbnail(collection, null); + CollectionWithThumbnail c; pCollections.add( GestureDetector( child: Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ Column( children: [ @@ -69,12 +77,26 @@ class CollectionSuggestions { ), ], ), - Row( - children: [ - Icon(Icons.access_alarms), - Icon(Icons.access_alarms), - Icon(Icons.access_alarms), - ], + FutureBuilder( + future: latestCollectionFiles, + builder: (context, snapshot) { + log(snapshot.data.toString()); + for (File file in snapshot.data) { + if (file.collectionID == id) { + c = CollectionWithThumbnail(collection, file); + break; + } + } + return Row( + children: [ + SizedBox( + height: 50, + width: 50, + child: ThumbnailWidget(c.thumbnail), + ), + ], + ); + }, ) ], ), From 5ecda81dbdb9a24094c85f9ccf35d19b47624728 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Mon, 25 Jul 2022 15:38:19 +0530 Subject: [PATCH 13/29] remove priority search + refactor --- lib/services/collections_service.dart | 56 ++++++++----------- .../search/SearchResultsSuggestions.dart | 8 +-- .../viewer/search/collectionSuggestions.dart | 54 ++++++++---------- lib/ui/viewer/search/searchWidget.dart | 13 +++-- 4 files changed, 58 insertions(+), 73 deletions(-) diff --git a/lib/services/collections_service.dart b/lib/services/collections_service.dart index de465bdf3..f3275cf7d 100644 --- a/lib/services/collections_service.dart +++ b/lib/services/collections_service.dart @@ -170,6 +170,24 @@ class CollectionsService { .toList(); } +// getCollectionsForSearch removes deleted or archived collections from search result //implement for files that have atleast one file + + Future> getCollectionsForSearch() async { + List latestCollectionFiles = await getLatestCollectionFiles(); + Set collectionWithAtleastOneFile = + latestCollectionFiles.map((e) => e.collectionID).toSet(); + + return _collectionIDToCollections.values + .toList() + .where( + (element) => + !element.isDeleted && + !element.isArchived() && + collectionWithAtleastOneFile.contains(element.id), + ) + .toList(); + } + Future> getSharees(int collectionID) { return _dio .get( @@ -825,7 +843,7 @@ class CollectionsService { bool hasSyncedCollections() { return _prefs.containsKey(_collectionsSyncTimeKey); - } + } /* */ Collection _getCollectionWithDecryptedName(Collection collection) { if (collection.encryptedName != null && @@ -864,42 +882,14 @@ class CollectionsService { } } - Map getSearchedCollectionsId(String query) { - Set stringStartsWithQuery = _collectionIDToCollections.values - .toList() - .where( - (element) => - element.name.startsWith(RegExp(query, caseSensitive: false)), - ) - .map((e) => e.id) - .toSet(); - - Set wordStartsWithQuery = _collectionIDToCollections.values - .toList() - .where( - (element) => //"query" for words that come after the 1st word - element.name.contains(RegExp(" $query", caseSensitive: false)), - ) - .map((e) => e.id) - .toSet(); - - Set containesQuery = _collectionIDToCollections.values - .toList() + Future> getSearchedCollections(String query) async { + List collectionsToSearch = await getCollectionsForSearch(); + return collectionsToSearch .where( (element) => element.name.contains(RegExp(query, caseSensitive: false)), ) - .map((e) => e.id) - .toSet(); - - containesQuery = containesQuery - .difference({...stringStartsWithQuery, ...wordStartsWithQuery}); - - return { - 'p1': stringStartsWithQuery, - 'p2': wordStartsWithQuery, - 'p3': containesQuery, - }; + .toList(); } } diff --git a/lib/ui/viewer/search/SearchResultsSuggestions.dart b/lib/ui/viewer/search/SearchResultsSuggestions.dart index 98c77fd0d..55cb969e9 100644 --- a/lib/ui/viewer/search/SearchResultsSuggestions.dart +++ b/lib/ui/viewer/search/SearchResultsSuggestions.dart @@ -1,11 +1,11 @@ import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; +import 'package:photos/models/collection.dart'; import 'package:photos/ui/viewer/search/collectionSuggestions.dart'; class SearchResultsSuggestions extends StatefulWidget { - final Map collectionIDs; - const SearchResultsSuggestions({Key key, this.collectionIDs}) - : super(key: key); + final List collections; + const SearchResultsSuggestions({Key key, this.collections}) : super(key: key); @override State createState() => @@ -16,7 +16,7 @@ class _SearchResultsSuggestionsState extends State { @override Widget build(BuildContext context) { List p1suggestions = []; - p1suggestions = CollectionSuggestions(widget.collectionIDs, context) + p1suggestions = CollectionSuggestions(widget.collections, context) .getSuggestions(); //add other search type p1 suggestions to this return Container( constraints: diff --git a/lib/ui/viewer/search/collectionSuggestions.dart b/lib/ui/viewer/search/collectionSuggestions.dart index af0ba6eae..9c35a3a66 100644 --- a/lib/ui/viewer/search/collectionSuggestions.dart +++ b/lib/ui/viewer/search/collectionSuggestions.dart @@ -12,32 +12,22 @@ import 'package:photos/ui/viewer/gallery/collection_page.dart'; import 'package:photos/utils/navigation_util.dart'; class CollectionSuggestions { - final Map collectionIDs; + final List matchedCollections; final BuildContext context; - const CollectionSuggestions(this.collectionIDs, this.context); + const CollectionSuggestions(this.matchedCollections, this.context); List getSuggestions() { - List p1IDs = collectionIDs['p1'].toList(); - List p2IDs = collectionIDs['p2'].toList(); - List p3IDs = collectionIDs['p3'].toList(); List collectionsP1 = []; - List collectionsP2 = []; - List collectionsP3 = []; - collectionsP1 = generateSuggestionWidgets(p1IDs, collectionsP1); - collectionsP2 = generateSuggestionWidgets(p2IDs, collectionsP2); - collectionsP3 = generateSuggestionWidgets(p3IDs, collectionsP3); - return [...collectionsP1, ...collectionsP2, ...collectionsP3]; + collectionsP1 = generateSuggestionWidgets(collectionsP1); + return [...collectionsP1]; } List generateSuggestionWidgets( - List pIDs, List pCollections, ) { Future> latestCollectionFiles = CollectionsService.instance.getLatestCollectionFiles(); - for (int id in pIDs) { - Collection collection = CollectionsService.instance.getCollectionByID(id); - // CollectionWithThumbnail c = CollectionWithThumbnail(collection, null); + for (Collection collection in matchedCollections) { CollectionWithThumbnail c; pCollections.add( GestureDetector( @@ -49,7 +39,7 @@ class CollectionSuggestions { const Text('Album'), Text(collection.name), FutureBuilder( - future: FilesDB.instance.collectionFileCount(id), + future: FilesDB.instance.collectionFileCount(collection.id), builder: (context, snapshot) { if (snapshot.hasData && snapshot.data > 0) { int noOfMemories = snapshot.data; @@ -80,22 +70,26 @@ class CollectionSuggestions { FutureBuilder( future: latestCollectionFiles, builder: (context, snapshot) { - log(snapshot.data.toString()); - for (File file in snapshot.data) { - if (file.collectionID == id) { - c = CollectionWithThumbnail(collection, file); - break; + if (snapshot.hasData) { + for (File file in snapshot.data) { + if (file.collectionID == collection.id) { + c = CollectionWithThumbnail(collection, file); + break; + } } + + return Row( + children: [ + SizedBox( + height: 50, + width: 50, + child: ThumbnailWidget(c.thumbnail), + ), + ], + ); + } else { + return const SizedBox.shrink(); } - return Row( - children: [ - SizedBox( - height: 50, - width: 50, - child: ThumbnailWidget(c.thumbnail), - ), - ], - ); }, ) ], diff --git a/lib/ui/viewer/search/searchWidget.dart b/lib/ui/viewer/search/searchWidget.dart index d679dc12d..0f0ae8be1 100644 --- a/lib/ui/viewer/search/searchWidget.dart +++ b/lib/ui/viewer/search/searchWidget.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/src/foundation/key.dart'; import 'package:flutter/src/widgets/framework.dart'; import 'package:photos/ente_theme_data.dart'; +import 'package:photos/models/collection.dart'; import 'package:photos/services/collections_service.dart'; import 'package:photos/ui/viewer/search/SearchResultsSuggestions.dart'; @@ -43,7 +44,7 @@ class _SearchwidgetState extends State { final ValueNotifier _searchQ = ValueNotifier(''); @override Widget build(BuildContext context) { - Map collectionIDs; + List matchedCollections; return widget.openSearch ? Column( children: [ @@ -68,10 +69,10 @@ class _SearchwidgetState extends State { ), prefixIcon: const Icon(Icons.search), ), - onChanged: (value) { - collectionIDs = CollectionsService.instance - .getSearchedCollectionsId(value); - debugPrint(collectionIDs.toString()); + onChanged: (value) async { + matchedCollections = await CollectionsService.instance + .getSearchedCollections(value); + debugPrint(matchedCollections.toString()); _searchQ.value = value; }, autofocus: true, @@ -99,7 +100,7 @@ class _SearchwidgetState extends State { debugPrint('listening to search value'); return newQuery != '' ? SearchResultsSuggestions( - collectionIDs: collectionIDs, + collections: matchedCollections, ) : const SizedBox.shrink(); }, From 1eae826f6025edfdba351c97db67eff493a517bd Mon Sep 17 00:00:00 2001 From: ashilkn Date: Mon, 25 Jul 2022 15:54:06 +0530 Subject: [PATCH 14/29] rename files to follow naming convention --- lib/ui/status_bar_widget.dart | 2 +- ...tions.dart => collection_suggestions.dart} | 2 - .../search/location_search_results_page.dart | 69 ---------- .../viewer/search/location_search_widget.dart | 121 ------------------ lib/ui/viewer/search/search_page.dart | 27 ---- ...s.dart => search_results_suggestions.dart} | 2 +- .../{searchWidget.dart => search_widget.dart} | 2 +- 7 files changed, 3 insertions(+), 222 deletions(-) rename lib/ui/viewer/search/{collectionSuggestions.dart => collection_suggestions.dart} (99%) delete mode 100644 lib/ui/viewer/search/location_search_results_page.dart delete mode 100644 lib/ui/viewer/search/location_search_widget.dart delete mode 100644 lib/ui/viewer/search/search_page.dart rename lib/ui/viewer/search/{SearchResultsSuggestions.dart => search_results_suggestions.dart} (93%) rename lib/ui/viewer/search/{searchWidget.dart => search_widget.dart} (98%) diff --git a/lib/ui/status_bar_widget.dart b/lib/ui/status_bar_widget.dart index e1e2da605..b782ca930 100644 --- a/lib/ui/status_bar_widget.dart +++ b/lib/ui/status_bar_widget.dart @@ -6,7 +6,7 @@ import 'package:photos/ente_theme_data.dart'; import 'package:photos/events/sync_status_update_event.dart'; import 'package:photos/services/sync_service.dart'; import 'package:photos/ui/header_error_widget.dart'; -import 'package:photos/ui/viewer/search/searchWidget.dart'; +import 'package:photos/ui/viewer/search/search_widget.dart'; const double kContainerHeight = 36; diff --git a/lib/ui/viewer/search/collectionSuggestions.dart b/lib/ui/viewer/search/collection_suggestions.dart similarity index 99% rename from lib/ui/viewer/search/collectionSuggestions.dart rename to lib/ui/viewer/search/collection_suggestions.dart index 9c35a3a66..5b6e0cf6b 100644 --- a/lib/ui/viewer/search/collectionSuggestions.dart +++ b/lib/ui/viewer/search/collection_suggestions.dart @@ -1,5 +1,3 @@ -import 'dart:developer'; - import 'package:flutter/material.dart'; import 'package:photos/db/files_db.dart'; import 'package:photos/ente_theme_data.dart'; diff --git a/lib/ui/viewer/search/location_search_results_page.dart b/lib/ui/viewer/search/location_search_results_page.dart deleted file mode 100644 index 51249c69e..000000000 --- a/lib/ui/viewer/search/location_search_results_page.dart +++ /dev/null @@ -1,69 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:photos/models/file.dart'; -import 'package:photos/models/location.dart'; -import 'package:photos/models/selected_files.dart'; -import 'package:photos/ui/viewer/gallery/gallery.dart'; - -class ViewPort { - final Location northEast; - final Location southWest; - - ViewPort(this.northEast, this.southWest); - - @override - String toString() => 'ViewPort(northEast: $northEast, southWest: $southWest)'; -} - -class LocationSearchResultsPage extends StatefulWidget { - final ViewPort viewPort; - final String name; - - const LocationSearchResultsPage(this.viewPort, this.name, {Key key}) - : super(key: key); - - @override - State createState() => - _LocationSearchResultsPageState(); -} - -class _LocationSearchResultsPageState extends State { - final _selectedFiles = SelectedFiles(); - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: Text(widget.name), - ), - body: Gallery( - tagPrefix: "location_search", - selectedFiles: _selectedFiles, - footer: const SizedBox(height: 120), - ), - ); - } - - List _getResult() { - List files = []; - final Map args = {}; - args['files'] = files; - args['viewPort'] = widget.viewPort; - return _filterPhotos(args); - } - - static List _filterPhotos(Map args) { - List files = args['files']; - ViewPort viewPort = args['viewPort']; - final result = []; - for (final file in files) { - if (file.location != null && - viewPort.northEast.latitude > file.location.latitude && - viewPort.southWest.latitude < file.location.latitude && - viewPort.northEast.longitude > file.location.longitude && - viewPort.southWest.longitude < file.location.longitude) { - result.add(file); - } else {} - } - return result; - } -} diff --git a/lib/ui/viewer/search/location_search_widget.dart b/lib/ui/viewer/search/location_search_widget.dart deleted file mode 100644 index 9467bb831..000000000 --- a/lib/ui/viewer/search/location_search_widget.dart +++ /dev/null @@ -1,121 +0,0 @@ -import 'package:dio/dio.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_typeahead/flutter_typeahead.dart'; -import 'package:photos/core/configuration.dart'; -import 'package:photos/core/network.dart'; -import 'package:photos/models/location.dart'; -import 'package:photos/ui/common/loading_widget.dart'; -import 'package:photos/ui/viewer/search/location_search_results_page.dart'; - -class LocationSearchWidget extends StatefulWidget { - const LocationSearchWidget({ - Key key, - }) : super(key: key); - - @override - State createState() => _LocationSearchWidgetState(); -} - -class _LocationSearchWidgetState extends State { - String _searchString; - - @override - Widget build(BuildContext context) { - return TypeAheadField( - textFieldConfiguration: const TextFieldConfiguration( - autofocus: true, - decoration: InputDecoration( - border: InputBorder.none, - hintText: 'Eg: Rome, Paris, New York', - contentPadding: EdgeInsets.all(0.0), - ), - ), - hideOnEmpty: true, - loadingBuilder: (context) { - return const EnteLoadingWidget(); - }, - suggestionsCallback: (pattern) async { - if (pattern.isEmpty || pattern.length < 2) { - return null; - } - _searchString = pattern; - return Network.instance - .getDio() - .get( - Configuration.instance.getHttpEndpoint() + "/search/location", - queryParameters: { - "query": pattern, - }, - options: Options( - headers: {"X-Auth-Token": Configuration.instance.getToken()}, - ), - ) - .then((response) { - if (_searchString == pattern) { - // Query has not changed - return response.data["results"]; - } - return null; - }); - }, - itemBuilder: (context, suggestion) { - return LocationSearchResultWidget(suggestion['name']); - }, - onSuggestionSelected: (suggestion) { - Navigator.pop(context); - Navigator.of(context).push( - MaterialPageRoute( - builder: (context) => LocationSearchResultsPage( - ViewPort( - Location( - suggestion['geometry']['viewport']['northeast']['lat'], - suggestion['geometry']['viewport']['northeast']['lng'], - ), - Location( - suggestion['geometry']['viewport']['southwest']['lat'], - suggestion['geometry']['viewport']['southwest']['lng'], - ), - ), - suggestion['name'], - ), - ), - ); - }, - ); - } -} - -class LocationSearchResultWidget extends StatelessWidget { - final String name; - const LocationSearchResultWidget( - this.name, { - Key key, - }) : super(key: key); - - @override - Widget build(BuildContext context) { - return Container( - padding: const EdgeInsets.symmetric(vertical: 6.0, horizontal: 6.0), - margin: const EdgeInsets.symmetric(vertical: 6.0), - child: Column( - children: [ - Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - const Icon( - Icons.location_on, - ), - const Padding(padding: EdgeInsets.only(left: 20.0)), - Flexible( - child: Text( - name, - overflow: TextOverflow.clip, - ), - ), - ], - ), - ], - ), - ); - } -} diff --git a/lib/ui/viewer/search/search_page.dart b/lib/ui/viewer/search/search_page.dart deleted file mode 100644 index d5e912cba..000000000 --- a/lib/ui/viewer/search/search_page.dart +++ /dev/null @@ -1,27 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:photos/ui/viewer/search/location_search_widget.dart'; - -class SearchPage extends StatefulWidget { - const SearchPage({Key key}) : super(key: key); - - @override - State createState() => _SearchPageState(); -} - -class _SearchPageState extends State { - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: AppBar( - title: const LocationSearchWidget(), - actions: [ - IconButton( - icon: const Icon(Icons.search), - onPressed: () {}, - ) - ], - ), - body: Container(), - ); - } -} diff --git a/lib/ui/viewer/search/SearchResultsSuggestions.dart b/lib/ui/viewer/search/search_results_suggestions.dart similarity index 93% rename from lib/ui/viewer/search/SearchResultsSuggestions.dart rename to lib/ui/viewer/search/search_results_suggestions.dart index 55cb969e9..d372cdd47 100644 --- a/lib/ui/viewer/search/SearchResultsSuggestions.dart +++ b/lib/ui/viewer/search/search_results_suggestions.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:photos/models/collection.dart'; -import 'package:photos/ui/viewer/search/collectionSuggestions.dart'; +import 'package:photos/ui/viewer/search/collection_suggestions.dart'; class SearchResultsSuggestions extends StatefulWidget { final List collections; diff --git a/lib/ui/viewer/search/searchWidget.dart b/lib/ui/viewer/search/search_widget.dart similarity index 98% rename from lib/ui/viewer/search/searchWidget.dart rename to lib/ui/viewer/search/search_widget.dart index 0f0ae8be1..3ee1c91de 100644 --- a/lib/ui/viewer/search/searchWidget.dart +++ b/lib/ui/viewer/search/search_widget.dart @@ -4,7 +4,7 @@ import 'package:flutter/src/widgets/framework.dart'; import 'package:photos/ente_theme_data.dart'; import 'package:photos/models/collection.dart'; import 'package:photos/services/collections_service.dart'; -import 'package:photos/ui/viewer/search/SearchResultsSuggestions.dart'; +import 'package:photos/ui/viewer/search/search_results_suggestions.dart'; class SearchIconWidget extends StatefulWidget { bool openSearch; From dc658d4acfdbb11d6a17b166f2f3b3b892e2c38f Mon Sep 17 00:00:00 2001 From: ashilkn Date: Mon, 25 Jul 2022 16:16:40 +0530 Subject: [PATCH 15/29] UI changes + renaming variables for better understanding --- .../viewer/search/collection_suggestions.dart | 142 ++++++++++-------- .../search/search_results_suggestions.dart | 10 +- lib/ui/viewer/search/search_widget.dart | 1 - 3 files changed, 83 insertions(+), 70 deletions(-) diff --git a/lib/ui/viewer/search/collection_suggestions.dart b/lib/ui/viewer/search/collection_suggestions.dart index 5b6e0cf6b..e962476c4 100644 --- a/lib/ui/viewer/search/collection_suggestions.dart +++ b/lib/ui/viewer/search/collection_suggestions.dart @@ -15,82 +15,96 @@ class CollectionSuggestions { const CollectionSuggestions(this.matchedCollections, this.context); List getSuggestions() { - List collectionsP1 = []; - collectionsP1 = generateSuggestionWidgets(collectionsP1); - return [...collectionsP1]; + List collectionSuggestionWidgets = []; + collectionSuggestionWidgets = + generateSuggestionWidgets(collectionSuggestionWidgets); + return collectionSuggestionWidgets; } List generateSuggestionWidgets( - List pCollections, + List collectionSuggestionWidgets, ) { Future> latestCollectionFiles = CollectionsService.instance.getLatestCollectionFiles(); for (Collection collection in matchedCollections) { CollectionWithThumbnail c; - pCollections.add( + collectionSuggestionWidgets.add( GestureDetector( - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceAround, - children: [ - Column( - children: [ - const Text('Album'), - Text(collection.name), - FutureBuilder( - future: FilesDB.instance.collectionFileCount(collection.id), - builder: (context, snapshot) { - if (snapshot.hasData && snapshot.data > 0) { - int noOfMemories = snapshot.data; + child: Padding( + padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 12), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text( + 'Album', + style: TextStyle(fontSize: 12), + ), + const SizedBox(height: 8), + Text( + collection.name, + style: const TextStyle(fontSize: 18), + ), + FutureBuilder( + future: + FilesDB.instance.collectionFileCount(collection.id), + builder: (context, snapshot) { + if (snapshot.hasData && snapshot.data > 0) { + int noOfMemories = snapshot.data; - return RichText( - text: TextSpan( - style: TextStyle( - color: Theme.of(context) - .colorScheme - .defaultTextColor, - ), - children: [ - TextSpan(text: noOfMemories.toString()), - TextSpan( - text: - noOfMemories != 1 ? ' memories' : ' memory', + return RichText( + text: TextSpan( + style: TextStyle( + color: Theme.of(context) + .colorScheme + .defaultTextColor, ), - ], - ), - ); - } else { - return const SizedBox.shrink(); + children: [ + TextSpan(text: noOfMemories.toString()), + TextSpan( + text: noOfMemories != 1 + ? ' memories' + : ' memory', + ), + ], + ), + ); + } else { + return const SizedBox.shrink(); + } + }, + ), + ], + ), + FutureBuilder( + future: latestCollectionFiles, + builder: (context, snapshot) { + if (snapshot.hasData) { + for (File file in snapshot.data) { + if (file.collectionID == collection.id) { + c = CollectionWithThumbnail(collection, file); + break; + } } - }, - ), - ], - ), - FutureBuilder( - future: latestCollectionFiles, - builder: (context, snapshot) { - if (snapshot.hasData) { - for (File file in snapshot.data) { - if (file.collectionID == collection.id) { - c = CollectionWithThumbnail(collection, file); - break; - } - } - return Row( - children: [ - SizedBox( - height: 50, - width: 50, - child: ThumbnailWidget(c.thumbnail), - ), - ], - ); - } else { - return const SizedBox.shrink(); - } - }, - ) - ], + return Row( + children: [ + SizedBox( + height: 50, + width: 50, + child: ThumbnailWidget(c.thumbnail), + ), + ], + ); + } else { + return const SizedBox.shrink(); + } + }, + ) + ], + ), ), onTap: () { routeToPage(context, CollectionPage(c)); @@ -98,6 +112,6 @@ class CollectionSuggestions { ), ); } - return pCollections; + return collectionSuggestionWidgets; } } diff --git a/lib/ui/viewer/search/search_results_suggestions.dart b/lib/ui/viewer/search/search_results_suggestions.dart index d372cdd47..75e30b01f 100644 --- a/lib/ui/viewer/search/search_results_suggestions.dart +++ b/lib/ui/viewer/search/search_results_suggestions.dart @@ -15,16 +15,16 @@ class SearchResultsSuggestions extends StatefulWidget { class _SearchResultsSuggestionsState extends State { @override Widget build(BuildContext context) { - List p1suggestions = []; - p1suggestions = CollectionSuggestions(widget.collections, context) - .getSuggestions(); //add other search type p1 suggestions to this + List suggestions = []; + suggestions = + CollectionSuggestions(widget.collections, context).getSuggestions(); return Container( constraints: BoxConstraints(maxHeight: MediaQuery.of(context).size.height * 0.7), child: ListView.builder( - itemCount: p1suggestions.length, + itemCount: suggestions.length, itemBuilder: (context, index) { - return p1suggestions[index]; + return suggestions[index]; }, ), ); diff --git a/lib/ui/viewer/search/search_widget.dart b/lib/ui/viewer/search/search_widget.dart index 3ee1c91de..2b5a6a3f7 100644 --- a/lib/ui/viewer/search/search_widget.dart +++ b/lib/ui/viewer/search/search_widget.dart @@ -97,7 +97,6 @@ class _SearchwidgetState extends State { String newQuery, Widget child, ) { - debugPrint('listening to search value'); return newQuery != '' ? SearchResultsSuggestions( collections: matchedCollections, From 2e8708de977a2e20575014930c0c4308c7897c7d Mon Sep 17 00:00:00 2001 From: ashilkn Date: Mon, 25 Jul 2022 16:34:38 +0530 Subject: [PATCH 16/29] minor changes --- lib/ui/home_widget.dart | 1 - lib/ui/viewer/search/search_results_suggestions.dart | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/ui/home_widget.dart b/lib/ui/home_widget.dart index 14c964801..898204d29 100644 --- a/lib/ui/home_widget.dart +++ b/lib/ui/home_widget.dart @@ -260,7 +260,6 @@ class _HomeWidgetState extends State { child: Container(), ), body: _getBody(), - resizeToAvoidBottomInset: false, ), onWillPop: () async { if (_selectedTabIndex == 0) { diff --git a/lib/ui/viewer/search/search_results_suggestions.dart b/lib/ui/viewer/search/search_results_suggestions.dart index 75e30b01f..e514877ba 100644 --- a/lib/ui/viewer/search/search_results_suggestions.dart +++ b/lib/ui/viewer/search/search_results_suggestions.dart @@ -20,7 +20,7 @@ class _SearchResultsSuggestionsState extends State { CollectionSuggestions(widget.collections, context).getSuggestions(); return Container( constraints: - BoxConstraints(maxHeight: MediaQuery.of(context).size.height * 0.7), + BoxConstraints(maxHeight: MediaQuery.of(context).size.height * 0.6), child: ListView.builder( itemCount: suggestions.length, itemBuilder: (context, index) { From 950ae2645cf8051976193e1d0802b1f745c66950 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Mon, 25 Jul 2022 17:22:16 +0530 Subject: [PATCH 17/29] added feature flag for search feature --- lib/services/feature_flag_service.dart | 10 ++++++++++ lib/ui/status_bar_widget.dart | 18 +++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/services/feature_flag_service.dart b/lib/services/feature_flag_service.dart index 4f7c8a54e..06e7395e0 100644 --- a/lib/services/feature_flag_service.dart +++ b/lib/services/feature_flag_service.dart @@ -3,6 +3,7 @@ import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:logging/logging.dart'; +import 'package:photos/core/configuration.dart'; import 'package:photos/core/constants.dart'; import 'package:photos/core/network.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -83,6 +84,15 @@ class FeatureFlagService { } } + bool enableSearchFeature() { + String email = Configuration.instance.getEmail(); + if (email.endsWith("@ente.io") || email == 'ashilkn99+ente77@gmail.com') { + return true; + } else { + return false; + } + } + Future fetchFeatureFlags() async { try { final response = await Network.instance diff --git a/lib/ui/status_bar_widget.dart b/lib/ui/status_bar_widget.dart index b782ca930..1c5838890 100644 --- a/lib/ui/status_bar_widget.dart +++ b/lib/ui/status_bar_widget.dart @@ -4,6 +4,7 @@ import 'package:flutter/material.dart'; import 'package:photos/core/event_bus.dart'; import 'package:photos/ente_theme_data.dart'; import 'package:photos/events/sync_status_update_event.dart'; +import 'package:photos/services/feature_flag_service.dart'; import 'package:photos/services/sync_service.dart'; import 'package:photos/ui/header_error_widget.dart'; import 'package:photos/ui/viewer/search/search_widget.dart'; @@ -210,6 +211,7 @@ class StatusBarBrandingWidget extends StatelessWidget { @override Widget build(BuildContext context) { + FeatureFlagService.instance.enableSearchFeature(); return Stack( children: [ Container( @@ -228,13 +230,15 @@ class StatusBarBrandingWidget extends StatelessWidget { ), ), ), - SizedBox( - width: MediaQuery.of(context).size.width, - child: Align( - alignment: Alignment.centerRight, - child: SearchIconWidget(), - ), - ), + FeatureFlagService.instance.enableSearchFeature() + ? SizedBox( + width: MediaQuery.of(context).size.width, + child: Align( + alignment: Alignment.centerRight, + child: SearchIconWidget(), + ), + ) + : const SizedBox.shrink(), ], ); } From 8df8a2a1cbe92d6020748de8fd9e33d297008dc9 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Mon, 25 Jul 2022 19:20:51 +0530 Subject: [PATCH 18/29] minor changes --- lib/ui/viewer/search/search_widget.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ui/viewer/search/search_widget.dart b/lib/ui/viewer/search/search_widget.dart index 2b5a6a3f7..ba2369521 100644 --- a/lib/ui/viewer/search/search_widget.dart +++ b/lib/ui/viewer/search/search_widget.dart @@ -1,11 +1,10 @@ import 'package:flutter/material.dart'; -import 'package:flutter/src/foundation/key.dart'; -import 'package:flutter/src/widgets/framework.dart'; import 'package:photos/ente_theme_data.dart'; import 'package:photos/models/collection.dart'; import 'package:photos/services/collections_service.dart'; import 'package:photos/ui/viewer/search/search_results_suggestions.dart'; +// ignore: must_be_immutable class SearchIconWidget extends StatefulWidget { bool openSearch; SearchIconWidget({Key key, this.openSearch = false}) : super(key: key); @@ -32,6 +31,7 @@ class _SearchIconWidgetState extends State { } } +// ignore: must_be_immutable class Searchwidget extends StatefulWidget { bool openSearch; final String searchQuery = ''; From c7f1d182be945844ee746a6127818d72925cc296 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Mon, 25 Jul 2022 19:30:07 +0530 Subject: [PATCH 19/29] removed print and debug print statements --- lib/services/collections_service.dart | 2 +- lib/ui/viewer/search/search_widget.dart | 1 - lib/utils/date_time_util.dart | 2 -- 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/services/collections_service.dart b/lib/services/collections_service.dart index f3275cf7d..9307d2ffe 100644 --- a/lib/services/collections_service.dart +++ b/lib/services/collections_service.dart @@ -843,7 +843,7 @@ class CollectionsService { bool hasSyncedCollections() { return _prefs.containsKey(_collectionsSyncTimeKey); - } /* */ + } Collection _getCollectionWithDecryptedName(Collection collection) { if (collection.encryptedName != null && diff --git a/lib/ui/viewer/search/search_widget.dart b/lib/ui/viewer/search/search_widget.dart index ba2369521..549de7274 100644 --- a/lib/ui/viewer/search/search_widget.dart +++ b/lib/ui/viewer/search/search_widget.dart @@ -72,7 +72,6 @@ class _SearchwidgetState extends State { onChanged: (value) async { matchedCollections = await CollectionsService.instance .getSearchedCollections(value); - debugPrint(matchedCollections.toString()); _searchQ.value = value; }, autofocus: true, diff --git a/lib/utils/date_time_util.dart b/lib/utils/date_time_util.dart index 4936581ff..3991f46b9 100644 --- a/lib/utils/date_time_util.dart +++ b/lib/utils/date_time_util.dart @@ -224,8 +224,6 @@ String getDayTitle(int timestamp) { } String secondsToHHMMSS(int value) { - print("value is ----------------"); - print(value); int h, m, s; h = value ~/ 3600; m = ((value - h * 3600)) ~/ 60; From f6addb0eb7d8a34a3b3533f44bf25ea315119124 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Mon, 25 Jul 2022 19:38:11 +0530 Subject: [PATCH 20/29] changed searchResultsSuggestion to a stateless widget --- lib/ui/viewer/search/search_results_suggestions.dart | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/lib/ui/viewer/search/search_results_suggestions.dart b/lib/ui/viewer/search/search_results_suggestions.dart index e514877ba..130c29834 100644 --- a/lib/ui/viewer/search/search_results_suggestions.dart +++ b/lib/ui/viewer/search/search_results_suggestions.dart @@ -3,21 +3,14 @@ import 'package:flutter/widgets.dart'; import 'package:photos/models/collection.dart'; import 'package:photos/ui/viewer/search/collection_suggestions.dart'; -class SearchResultsSuggestions extends StatefulWidget { +class SearchResultsSuggestions extends StatelessWidget { final List collections; const SearchResultsSuggestions({Key key, this.collections}) : super(key: key); - @override - State createState() => - _SearchResultsSuggestionsState(); -} - -class _SearchResultsSuggestionsState extends State { @override Widget build(BuildContext context) { List suggestions = []; - suggestions = - CollectionSuggestions(widget.collections, context).getSuggestions(); + suggestions = CollectionSuggestions(collections, context).getSuggestions(); return Container( constraints: BoxConstraints(maxHeight: MediaQuery.of(context).size.height * 0.6), From ab4a2db60bd71d839c6409bf695ee3710f7ea7b1 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Tue, 26 Jul 2022 13:02:55 +0530 Subject: [PATCH 21/29] minor changes + refactoring --- lib/services/collections_service.dart | 2 +- lib/services/feature_flag_service.dart | 6 +----- lib/ui/status_bar_widget.dart | 1 - ...ns.dart => collection_suggestion_widgets.dart} | 15 +++------------ .../viewer/search/search_results_suggestions.dart | 5 ++++- 5 files changed, 9 insertions(+), 20 deletions(-) rename lib/ui/viewer/search/{collection_suggestions.dart => collection_suggestion_widgets.dart} (91%) diff --git a/lib/services/collections_service.dart b/lib/services/collections_service.dart index 9307d2ffe..cb3835741 100644 --- a/lib/services/collections_service.dart +++ b/lib/services/collections_service.dart @@ -884,7 +884,7 @@ class CollectionsService { Future> getSearchedCollections(String query) async { List collectionsToSearch = await getCollectionsForSearch(); - return collectionsToSearch + return collectionsToSearch //return collection with thumbnail here .where( (element) => element.name.contains(RegExp(query, caseSensitive: false)), diff --git a/lib/services/feature_flag_service.dart b/lib/services/feature_flag_service.dart index 06e7395e0..772e3d678 100644 --- a/lib/services/feature_flag_service.dart +++ b/lib/services/feature_flag_service.dart @@ -86,11 +86,7 @@ class FeatureFlagService { bool enableSearchFeature() { String email = Configuration.instance.getEmail(); - if (email.endsWith("@ente.io") || email == 'ashilkn99+ente77@gmail.com') { - return true; - } else { - return false; - } + return (email != null && email.endsWith("@ente.io")) || kDebugMode; } Future fetchFeatureFlags() async { diff --git a/lib/ui/status_bar_widget.dart b/lib/ui/status_bar_widget.dart index 1c5838890..d610b2021 100644 --- a/lib/ui/status_bar_widget.dart +++ b/lib/ui/status_bar_widget.dart @@ -211,7 +211,6 @@ class StatusBarBrandingWidget extends StatelessWidget { @override Widget build(BuildContext context) { - FeatureFlagService.instance.enableSearchFeature(); return Stack( children: [ Container( diff --git a/lib/ui/viewer/search/collection_suggestions.dart b/lib/ui/viewer/search/collection_suggestion_widgets.dart similarity index 91% rename from lib/ui/viewer/search/collection_suggestions.dart rename to lib/ui/viewer/search/collection_suggestion_widgets.dart index e962476c4..e4fe4a6a6 100644 --- a/lib/ui/viewer/search/collection_suggestions.dart +++ b/lib/ui/viewer/search/collection_suggestion_widgets.dart @@ -9,21 +9,12 @@ import 'package:photos/ui/viewer/file/thumbnail_widget.dart'; import 'package:photos/ui/viewer/gallery/collection_page.dart'; import 'package:photos/utils/navigation_util.dart'; -class CollectionSuggestions { +class CollectionSuggestionWidgets { final List matchedCollections; final BuildContext context; - const CollectionSuggestions(this.matchedCollections, this.context); - - List getSuggestions() { + CollectionSuggestionWidgets(this.matchedCollections, this.context); + List generateSuggestionWidgets() { List collectionSuggestionWidgets = []; - collectionSuggestionWidgets = - generateSuggestionWidgets(collectionSuggestionWidgets); - return collectionSuggestionWidgets; - } - - List generateSuggestionWidgets( - List collectionSuggestionWidgets, - ) { Future> latestCollectionFiles = CollectionsService.instance.getLatestCollectionFiles(); for (Collection collection in matchedCollections) { diff --git a/lib/ui/viewer/search/search_results_suggestions.dart b/lib/ui/viewer/search/search_results_suggestions.dart index 130c29834..14f71bb44 100644 --- a/lib/ui/viewer/search/search_results_suggestions.dart +++ b/lib/ui/viewer/search/search_results_suggestions.dart @@ -10,7 +10,10 @@ class SearchResultsSuggestions extends StatelessWidget { @override Widget build(BuildContext context) { List suggestions = []; - suggestions = CollectionSuggestions(collections, context).getSuggestions(); + // for(Collection c in collections) { + // } + suggestions = CollectionSuggestionWidgets(collections, context) + .generateSuggestionWidgets(); return Container( constraints: BoxConstraints(maxHeight: MediaQuery.of(context).size.height * 0.6), From 8e0e9e9e1e3c30be50eff580cbc6ba0fe21ba1c3 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Wed, 27 Jul 2022 11:15:20 +0530 Subject: [PATCH 22/29] created CollectionWithThumbnail object list which is to be returned by getSearchedCollections() --- lib/services/collections_service.dart | 75 +++++++++++++++---- .../search/collection_suggestion_widgets.dart | 2 +- .../search/search_results_suggestions.dart | 11 +-- lib/ui/viewer/search/search_widget.dart | 6 +- 4 files changed, 70 insertions(+), 24 deletions(-) diff --git a/lib/services/collections_service.dart b/lib/services/collections_service.dart index cb3835741..7880920dc 100644 --- a/lib/services/collections_service.dart +++ b/lib/services/collections_service.dart @@ -1,4 +1,5 @@ import 'dart:convert'; +import 'dart:developer' as dartDeveloper; import 'dart:math'; import 'dart:typed_data'; @@ -19,6 +20,7 @@ import 'package:photos/events/force_reload_home_gallery_event.dart'; import 'package:photos/events/local_photos_updated_event.dart'; import 'package:photos/models/collection.dart'; import 'package:photos/models/collection_file_item.dart'; +import 'package:photos/models/collection_items.dart'; import 'package:photos/models/file.dart'; import 'package:photos/models/magic_metadata.dart'; import 'package:photos/services/app_lifecycle_service.dart'; @@ -172,20 +174,60 @@ class CollectionsService { // getCollectionsForSearch removes deleted or archived collections from search result //implement for files that have atleast one file - Future> getCollectionsForSearch() async { + Future> getCollectionsForSearch() async { List latestCollectionFiles = await getLatestCollectionFiles(); - Set collectionWithAtleastOneFile = - latestCollectionFiles.map((e) => e.collectionID).toSet(); + Map collectionIDtoFileForCollectionWithAtleastOneFile = { + for (var file in latestCollectionFiles) file.collectionID: file + }; - return _collectionIDToCollections.values - .toList() - .where( - (element) => - !element.isDeleted && - !element.isArchived() && - collectionWithAtleastOneFile.contains(element.id), + var collectionIDToCollectionsForSearch = _collectionIDToCollections; + + collectionIDToCollectionsForSearch.removeWhere( + (key, value) => + value.isDeleted || + value.isArchived() || + !collectionIDtoFileForCollectionWithAtleastOneFile + .containsKey(value.id), + ); + // return { + // 'collectionIDToFile': collectionIDtoFileForCollectionWithAtleastOneFile, + // 'collectionIDtoCollection': collectionIDToCollectionsForSearch + // }; + + List collectionIDsForSearch = collectionIDToCollectionsForSearch.keys + .toSet() + .intersection( + collectionIDtoFileForCollectionWithAtleastOneFile.keys.toSet(), ) .toList(); + + List collectionWithThumbnailForSerach; + + for (int collectionID in collectionIDsForSearch) { + CollectionWithThumbnail obj = CollectionWithThumbnail( + collectionIDToCollectionsForSearch[collectionID], + collectionIDtoFileForCollectionWithAtleastOneFile[collectionID], + ); + collectionWithThumbnailForSerach.add(obj); + } + + print('collectionWithThumbnailForSerach------------'); + dartDeveloper.log(collectionWithThumbnailForSerach.toString()); + + return collectionWithThumbnailForSerach; + + // return _collectionIDToCollections.values + // .toList() + // .where( + // (element) => + // !element.isDeleted && + // !element.isArchived() && + // collectionIDtoFileForCollectionWithAtleastOneFile + // .containsKey(element.id), + // ) + // .toList(); + + //return collcetionWithThumbnailhereAfter filtering } Future> getSharees(int collectionID) { @@ -882,12 +924,15 @@ class CollectionsService { } } - Future> getSearchedCollections(String query) async { - List collectionsToSearch = await getCollectionsForSearch(); - return collectionsToSearch //return collection with thumbnail here + Future> getSearchedCollections( + String query, + ) async { + List collectionsWithThumbnailToSearch = + await getCollectionsForSearch(); + return collectionsWithThumbnailToSearch .where( - (element) => - element.name.contains(RegExp(query, caseSensitive: false)), + (element) => element.collection.name + .contains(RegExp(query, caseSensitive: false)), ) .toList(); } diff --git a/lib/ui/viewer/search/collection_suggestion_widgets.dart b/lib/ui/viewer/search/collection_suggestion_widgets.dart index e4fe4a6a6..091459c4e 100644 --- a/lib/ui/viewer/search/collection_suggestion_widgets.dart +++ b/lib/ui/viewer/search/collection_suggestion_widgets.dart @@ -10,7 +10,7 @@ import 'package:photos/ui/viewer/gallery/collection_page.dart'; import 'package:photos/utils/navigation_util.dart'; class CollectionSuggestionWidgets { - final List matchedCollections; + final List matchedCollections; final BuildContext context; CollectionSuggestionWidgets(this.matchedCollections, this.context); List generateSuggestionWidgets() { diff --git a/lib/ui/viewer/search/search_results_suggestions.dart b/lib/ui/viewer/search/search_results_suggestions.dart index 14f71bb44..6e643df10 100644 --- a/lib/ui/viewer/search/search_results_suggestions.dart +++ b/lib/ui/viewer/search/search_results_suggestions.dart @@ -1,18 +1,19 @@ import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; -import 'package:photos/models/collection.dart'; -import 'package:photos/ui/viewer/search/collection_suggestions.dart'; +import 'package:photos/models/collection_items.dart'; +import 'package:photos/ui/viewer/search/collection_suggestion_widgets.dart'; class SearchResultsSuggestions extends StatelessWidget { - final List collections; - const SearchResultsSuggestions({Key key, this.collections}) : super(key: key); + final List collectionsWithThumbnail; + const SearchResultsSuggestions({Key key, this.collectionsWithThumbnail}) + : super(key: key); @override Widget build(BuildContext context) { List suggestions = []; // for(Collection c in collections) { // } - suggestions = CollectionSuggestionWidgets(collections, context) + suggestions = CollectionSuggestionWidgets(collectionsWithThumbnail, context) .generateSuggestionWidgets(); return Container( constraints: diff --git a/lib/ui/viewer/search/search_widget.dart b/lib/ui/viewer/search/search_widget.dart index 549de7274..4fb442381 100644 --- a/lib/ui/viewer/search/search_widget.dart +++ b/lib/ui/viewer/search/search_widget.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:photos/ente_theme_data.dart'; -import 'package:photos/models/collection.dart'; +import 'package:photos/models/collection_items.dart'; import 'package:photos/services/collections_service.dart'; import 'package:photos/ui/viewer/search/search_results_suggestions.dart'; @@ -44,7 +44,7 @@ class _SearchwidgetState extends State { final ValueNotifier _searchQ = ValueNotifier(''); @override Widget build(BuildContext context) { - List matchedCollections; + List matchedCollections; return widget.openSearch ? Column( children: [ @@ -98,7 +98,7 @@ class _SearchwidgetState extends State { ) { return newQuery != '' ? SearchResultsSuggestions( - collections: matchedCollections, + collectionsWithThumbnail: matchedCollections, ) : const SizedBox.shrink(); }, From af492c61a174c6c99d220dee930245a39575f9cd Mon Sep 17 00:00:00 2001 From: ashilkn Date: Wed, 27 Jul 2022 11:45:15 +0530 Subject: [PATCH 23/29] fixed no such method error --- lib/services/collections_service.dart | 25 ++----------------- .../search/collection_suggestion_widgets.dart | 19 ++++++++------ 2 files changed, 14 insertions(+), 30 deletions(-) diff --git a/lib/services/collections_service.dart b/lib/services/collections_service.dart index 7880920dc..9ab972a71 100644 --- a/lib/services/collections_service.dart +++ b/lib/services/collections_service.dart @@ -1,5 +1,4 @@ import 'dart:convert'; -import 'dart:developer' as dartDeveloper; import 'dart:math'; import 'dart:typed_data'; @@ -172,7 +171,7 @@ class CollectionsService { .toList(); } -// getCollectionsForSearch removes deleted or archived collections from search result //implement for files that have atleast one file +// getCollectionsForSearch removes deleted or archived or collections which don't have a file from search result Future> getCollectionsForSearch() async { List latestCollectionFiles = await getLatestCollectionFiles(); @@ -189,10 +188,6 @@ class CollectionsService { !collectionIDtoFileForCollectionWithAtleastOneFile .containsKey(value.id), ); - // return { - // 'collectionIDToFile': collectionIDtoFileForCollectionWithAtleastOneFile, - // 'collectionIDtoCollection': collectionIDToCollectionsForSearch - // }; List collectionIDsForSearch = collectionIDToCollectionsForSearch.keys .toSet() @@ -201,7 +196,7 @@ class CollectionsService { ) .toList(); - List collectionWithThumbnailForSerach; + List collectionWithThumbnailForSerach = []; for (int collectionID in collectionIDsForSearch) { CollectionWithThumbnail obj = CollectionWithThumbnail( @@ -211,23 +206,7 @@ class CollectionsService { collectionWithThumbnailForSerach.add(obj); } - print('collectionWithThumbnailForSerach------------'); - dartDeveloper.log(collectionWithThumbnailForSerach.toString()); - return collectionWithThumbnailForSerach; - - // return _collectionIDToCollections.values - // .toList() - // .where( - // (element) => - // !element.isDeleted && - // !element.isArchived() && - // collectionIDtoFileForCollectionWithAtleastOneFile - // .containsKey(element.id), - // ) - // .toList(); - - //return collcetionWithThumbnailhereAfter filtering } Future> getSharees(int collectionID) { diff --git a/lib/ui/viewer/search/collection_suggestion_widgets.dart b/lib/ui/viewer/search/collection_suggestion_widgets.dart index 091459c4e..19bf08a04 100644 --- a/lib/ui/viewer/search/collection_suggestion_widgets.dart +++ b/lib/ui/viewer/search/collection_suggestion_widgets.dart @@ -1,7 +1,6 @@ import 'package:flutter/material.dart'; import 'package:photos/db/files_db.dart'; import 'package:photos/ente_theme_data.dart'; -import 'package:photos/models/collection.dart'; import 'package:photos/models/collection_items.dart'; import 'package:photos/models/file.dart'; import 'package:photos/services/collections_service.dart'; @@ -17,7 +16,8 @@ class CollectionSuggestionWidgets { List collectionSuggestionWidgets = []; Future> latestCollectionFiles = CollectionsService.instance.getLatestCollectionFiles(); - for (Collection collection in matchedCollections) { + for (CollectionWithThumbnail collectionWithThumbnail + in matchedCollections) { CollectionWithThumbnail c; collectionSuggestionWidgets.add( GestureDetector( @@ -35,12 +35,13 @@ class CollectionSuggestionWidgets { ), const SizedBox(height: 8), Text( - collection.name, + collectionWithThumbnail.collection.name, style: const TextStyle(fontSize: 18), ), FutureBuilder( - future: - FilesDB.instance.collectionFileCount(collection.id), + future: FilesDB.instance.collectionFileCount( + collectionWithThumbnail.collection.id, + ), builder: (context, snapshot) { if (snapshot.hasData && snapshot.data > 0) { int noOfMemories = snapshot.data; @@ -74,8 +75,12 @@ class CollectionSuggestionWidgets { builder: (context, snapshot) { if (snapshot.hasData) { for (File file in snapshot.data) { - if (file.collectionID == collection.id) { - c = CollectionWithThumbnail(collection, file); + if (file.collectionID == + collectionWithThumbnail.collection.id) { + c = CollectionWithThumbnail( + collectionWithThumbnail.collection, + file, + ); break; } } From 62ee463f9d7b30d2f466842baf5d6922fea75f65 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Wed, 27 Jul 2022 11:52:54 +0530 Subject: [PATCH 24/29] code refactor - removed futureBuilder for generating thumbnail --- .../search/collection_suggestion_widgets.dart | 44 +++++-------------- 1 file changed, 10 insertions(+), 34 deletions(-) diff --git a/lib/ui/viewer/search/collection_suggestion_widgets.dart b/lib/ui/viewer/search/collection_suggestion_widgets.dart index 19bf08a04..3b121fcfd 100644 --- a/lib/ui/viewer/search/collection_suggestion_widgets.dart +++ b/lib/ui/viewer/search/collection_suggestion_widgets.dart @@ -2,8 +2,6 @@ import 'package:flutter/material.dart'; import 'package:photos/db/files_db.dart'; import 'package:photos/ente_theme_data.dart'; import 'package:photos/models/collection_items.dart'; -import 'package:photos/models/file.dart'; -import 'package:photos/services/collections_service.dart'; import 'package:photos/ui/viewer/file/thumbnail_widget.dart'; import 'package:photos/ui/viewer/gallery/collection_page.dart'; import 'package:photos/utils/navigation_util.dart'; @@ -14,11 +12,9 @@ class CollectionSuggestionWidgets { CollectionSuggestionWidgets(this.matchedCollections, this.context); List generateSuggestionWidgets() { List collectionSuggestionWidgets = []; - Future> latestCollectionFiles = - CollectionsService.instance.getLatestCollectionFiles(); + for (CollectionWithThumbnail collectionWithThumbnail in matchedCollections) { - CollectionWithThumbnail c; collectionSuggestionWidgets.add( GestureDetector( child: Padding( @@ -70,40 +66,20 @@ class CollectionSuggestionWidgets { ), ], ), - FutureBuilder( - future: latestCollectionFiles, - builder: (context, snapshot) { - if (snapshot.hasData) { - for (File file in snapshot.data) { - if (file.collectionID == - collectionWithThumbnail.collection.id) { - c = CollectionWithThumbnail( - collectionWithThumbnail.collection, - file, - ); - break; - } - } - - return Row( - children: [ - SizedBox( - height: 50, - width: 50, - child: ThumbnailWidget(c.thumbnail), - ), - ], - ); - } else { - return const SizedBox.shrink(); - } - }, + Row( + children: [ + SizedBox( + height: 50, + width: 50, + child: ThumbnailWidget(collectionWithThumbnail.thumbnail), + ), + ], ) ], ), ), onTap: () { - routeToPage(context, CollectionPage(c)); + routeToPage(context, CollectionPage(collectionWithThumbnail)); }, ), ); From c1b4ad8e38c36b25a50f11de09030e2b5fe2fb06 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Wed, 27 Jul 2022 12:43:22 +0530 Subject: [PATCH 25/29] minor changes --- lib/services/collections_service.dart | 13 +++++++------ .../search/collection_suggestion_widgets.dart | 11 +++++------ .../viewer/search/search_results_suggestions.dart | 3 ++- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/services/collections_service.dart b/lib/services/collections_service.dart index 9ab972a71..ca22d3557 100644 --- a/lib/services/collections_service.dart +++ b/lib/services/collections_service.dart @@ -171,12 +171,13 @@ class CollectionsService { .toList(); } -// getCollectionsForSearch removes deleted or archived or collections which don't have a file from search result +// getCollectionsWithThumbnailForSearch removes deleted or archived or collections which don't have a file from search result - Future> getCollectionsForSearch() async { + Future> + getCollectionsWithThumbnailForSearch() async { List latestCollectionFiles = await getLatestCollectionFiles(); Map collectionIDtoFileForCollectionWithAtleastOneFile = { - for (var file in latestCollectionFiles) file.collectionID: file + for (File file in latestCollectionFiles) file.collectionID: file }; var collectionIDToCollectionsForSearch = _collectionIDToCollections; @@ -199,11 +200,11 @@ class CollectionsService { List collectionWithThumbnailForSerach = []; for (int collectionID in collectionIDsForSearch) { - CollectionWithThumbnail obj = CollectionWithThumbnail( + CollectionWithThumbnail c = CollectionWithThumbnail( collectionIDToCollectionsForSearch[collectionID], collectionIDtoFileForCollectionWithAtleastOneFile[collectionID], ); - collectionWithThumbnailForSerach.add(obj); + collectionWithThumbnailForSerach.add(c); } return collectionWithThumbnailForSerach; @@ -907,7 +908,7 @@ class CollectionsService { String query, ) async { List collectionsWithThumbnailToSearch = - await getCollectionsForSearch(); + await getCollectionsWithThumbnailForSearch(); return collectionsWithThumbnailToSearch .where( (element) => element.collection.name diff --git a/lib/ui/viewer/search/collection_suggestion_widgets.dart b/lib/ui/viewer/search/collection_suggestion_widgets.dart index 3b121fcfd..d93266c8c 100644 --- a/lib/ui/viewer/search/collection_suggestion_widgets.dart +++ b/lib/ui/viewer/search/collection_suggestion_widgets.dart @@ -13,8 +13,7 @@ class CollectionSuggestionWidgets { List generateSuggestionWidgets() { List collectionSuggestionWidgets = []; - for (CollectionWithThumbnail collectionWithThumbnail - in matchedCollections) { + for (CollectionWithThumbnail c in matchedCollections) { collectionSuggestionWidgets.add( GestureDetector( child: Padding( @@ -31,12 +30,12 @@ class CollectionSuggestionWidgets { ), const SizedBox(height: 8), Text( - collectionWithThumbnail.collection.name, + c.collection.name, style: const TextStyle(fontSize: 18), ), FutureBuilder( future: FilesDB.instance.collectionFileCount( - collectionWithThumbnail.collection.id, + c.collection.id, ), builder: (context, snapshot) { if (snapshot.hasData && snapshot.data > 0) { @@ -71,7 +70,7 @@ class CollectionSuggestionWidgets { SizedBox( height: 50, width: 50, - child: ThumbnailWidget(collectionWithThumbnail.thumbnail), + child: ThumbnailWidget(c.thumbnail), ), ], ) @@ -79,7 +78,7 @@ class CollectionSuggestionWidgets { ), ), onTap: () { - routeToPage(context, CollectionPage(collectionWithThumbnail)); + routeToPage(context, CollectionPage(c)); }, ), ); diff --git a/lib/ui/viewer/search/search_results_suggestions.dart b/lib/ui/viewer/search/search_results_suggestions.dart index 6e643df10..698a8e407 100644 --- a/lib/ui/viewer/search/search_results_suggestions.dart +++ b/lib/ui/viewer/search/search_results_suggestions.dart @@ -11,7 +11,8 @@ class SearchResultsSuggestions extends StatelessWidget { @override Widget build(BuildContext context) { List suggestions = []; - // for(Collection c in collections) { + // for (CollectionWithThumbnail c in collectionsWithThumbnail) { + // suggestions.add{} // } suggestions = CollectionSuggestionWidgets(collectionsWithThumbnail, context) .generateSuggestionWidgets(); From 834209ef8015bc1e515a12e3fd7921371da8f8c6 Mon Sep 17 00:00:00 2001 From: ashilkn Date: Wed, 27 Jul 2022 13:00:51 +0530 Subject: [PATCH 26/29] code refactoring --- ...ollection_suggestion_widget_generator.dart | 80 +++++++++++++++++ .../search/collection_suggestion_widgets.dart | 88 ------------------- .../search/search_results_suggestions.dart | 11 ++- 3 files changed, 85 insertions(+), 94 deletions(-) create mode 100644 lib/ui/viewer/search/collection_suggestion_widget_generator.dart delete mode 100644 lib/ui/viewer/search/collection_suggestion_widgets.dart diff --git a/lib/ui/viewer/search/collection_suggestion_widget_generator.dart b/lib/ui/viewer/search/collection_suggestion_widget_generator.dart new file mode 100644 index 000000000..64b70d8da --- /dev/null +++ b/lib/ui/viewer/search/collection_suggestion_widget_generator.dart @@ -0,0 +1,80 @@ +import 'package:flutter/material.dart'; +import 'package:photos/db/files_db.dart'; +import 'package:photos/ente_theme_data.dart'; +import 'package:photos/models/collection_items.dart'; +import 'package:photos/ui/viewer/file/thumbnail_widget.dart'; +import 'package:photos/ui/viewer/gallery/collection_page.dart'; +import 'package:photos/utils/navigation_util.dart'; + +class CollectionSuggestionWidgetGenerator extends StatelessWidget { + final CollectionWithThumbnail c; + const CollectionSuggestionWidgetGenerator(this.c, {Key key}) + : super(key: key); + + @override + Widget build(BuildContext context) { + return GestureDetector( + child: Padding( + padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 12), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Text( + 'Album', + style: TextStyle(fontSize: 12), + ), + const SizedBox(height: 8), + Text( + c.collection.name, + style: const TextStyle(fontSize: 18), + ), + FutureBuilder( + future: FilesDB.instance.collectionFileCount( + c.collection.id, + ), + builder: (context, snapshot) { + if (snapshot.hasData && snapshot.data > 0) { + int noOfMemories = snapshot.data; + + return RichText( + text: TextSpan( + style: TextStyle( + color: + Theme.of(context).colorScheme.defaultTextColor, + ), + children: [ + TextSpan(text: noOfMemories.toString()), + TextSpan( + text: noOfMemories != 1 ? ' memories' : ' memory', + ), + ], + ), + ); + } else { + return const SizedBox.shrink(); + } + }, + ), + ], + ), + Row( + children: [ + SizedBox( + height: 50, + width: 50, + child: ThumbnailWidget(c.thumbnail), + ), + ], + ) + ], + ), + ), + onTap: () { + routeToPage(context, CollectionPage(c)); + }, + ); + } +} diff --git a/lib/ui/viewer/search/collection_suggestion_widgets.dart b/lib/ui/viewer/search/collection_suggestion_widgets.dart deleted file mode 100644 index d93266c8c..000000000 --- a/lib/ui/viewer/search/collection_suggestion_widgets.dart +++ /dev/null @@ -1,88 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:photos/db/files_db.dart'; -import 'package:photos/ente_theme_data.dart'; -import 'package:photos/models/collection_items.dart'; -import 'package:photos/ui/viewer/file/thumbnail_widget.dart'; -import 'package:photos/ui/viewer/gallery/collection_page.dart'; -import 'package:photos/utils/navigation_util.dart'; - -class CollectionSuggestionWidgets { - final List matchedCollections; - final BuildContext context; - CollectionSuggestionWidgets(this.matchedCollections, this.context); - List generateSuggestionWidgets() { - List collectionSuggestionWidgets = []; - - for (CollectionWithThumbnail c in matchedCollections) { - collectionSuggestionWidgets.add( - GestureDetector( - child: Padding( - padding: const EdgeInsets.symmetric(vertical: 6, horizontal: 12), - child: Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const Text( - 'Album', - style: TextStyle(fontSize: 12), - ), - const SizedBox(height: 8), - Text( - c.collection.name, - style: const TextStyle(fontSize: 18), - ), - FutureBuilder( - future: FilesDB.instance.collectionFileCount( - c.collection.id, - ), - builder: (context, snapshot) { - if (snapshot.hasData && snapshot.data > 0) { - int noOfMemories = snapshot.data; - - return RichText( - text: TextSpan( - style: TextStyle( - color: Theme.of(context) - .colorScheme - .defaultTextColor, - ), - children: [ - TextSpan(text: noOfMemories.toString()), - TextSpan( - text: noOfMemories != 1 - ? ' memories' - : ' memory', - ), - ], - ), - ); - } else { - return const SizedBox.shrink(); - } - }, - ), - ], - ), - Row( - children: [ - SizedBox( - height: 50, - width: 50, - child: ThumbnailWidget(c.thumbnail), - ), - ], - ) - ], - ), - ), - onTap: () { - routeToPage(context, CollectionPage(c)); - }, - ), - ); - } - return collectionSuggestionWidgets; - } -} diff --git a/lib/ui/viewer/search/search_results_suggestions.dart b/lib/ui/viewer/search/search_results_suggestions.dart index 698a8e407..8547dbee5 100644 --- a/lib/ui/viewer/search/search_results_suggestions.dart +++ b/lib/ui/viewer/search/search_results_suggestions.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:photos/models/collection_items.dart'; -import 'package:photos/ui/viewer/search/collection_suggestion_widgets.dart'; +import 'package:photos/ui/viewer/search/collection_suggestion_widget_generator.dart'; class SearchResultsSuggestions extends StatelessWidget { final List collectionsWithThumbnail; @@ -11,11 +11,10 @@ class SearchResultsSuggestions extends StatelessWidget { @override Widget build(BuildContext context) { List suggestions = []; - // for (CollectionWithThumbnail c in collectionsWithThumbnail) { - // suggestions.add{} - // } - suggestions = CollectionSuggestionWidgets(collectionsWithThumbnail, context) - .generateSuggestionWidgets(); + for (CollectionWithThumbnail c in collectionsWithThumbnail) { + suggestions.add(CollectionSuggestionWidgetGenerator(c)); + } + return Container( constraints: BoxConstraints(maxHeight: MediaQuery.of(context).size.height * 0.6), From b2cf52c31abf91256da1c002d362c4a36a788fbd Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Thu, 28 Jul 2022 10:25:54 +0530 Subject: [PATCH 27/29] minor refactor --- lib/services/collections_service.dart | 70 ++++++++++--------------- lib/ui/viewer/search/search_widget.dart | 2 +- 2 files changed, 30 insertions(+), 42 deletions(-) diff --git a/lib/services/collections_service.dart b/lib/services/collections_service.dart index ca22d3557..80f237d2c 100644 --- a/lib/services/collections_service.dart +++ b/lib/services/collections_service.dart @@ -171,43 +171,44 @@ class CollectionsService { .toList(); } -// getCollectionsWithThumbnailForSearch removes deleted or archived or collections which don't have a file from search result + // getFilteredCollectionsWithThumbnail removes deleted or archived or + // collections which don't have a file from search result + Future> getFilteredCollectionsWithThumbnail( + String query, + ) async { + // identify collections which have at least one file as we don't display + // empty collection - Future> - getCollectionsWithThumbnailForSearch() async { List latestCollectionFiles = await getLatestCollectionFiles(); - Map collectionIDtoFileForCollectionWithAtleastOneFile = { + Map collectionIDToLatestFileMap = { for (File file in latestCollectionFiles) file.collectionID: file }; - var collectionIDToCollectionsForSearch = _collectionIDToCollections; + /* Identify collections whose name matches the search query + and is not archived + and is not deleted + and has at-least one file + */ - collectionIDToCollectionsForSearch.removeWhere( - (key, value) => - value.isDeleted || - value.isArchived() || - !collectionIDtoFileForCollectionWithAtleastOneFile - .containsKey(value.id), - ); - - List collectionIDsForSearch = collectionIDToCollectionsForSearch.keys - .toSet() - .intersection( - collectionIDtoFileForCollectionWithAtleastOneFile.keys.toSet(), + List matchedCollection = _collectionIDToCollections.values + .where( + (c) => + !c.isDeleted && // not deleted + !c.isArchived() // not archived + && + collectionIDToLatestFileMap.containsKey(c.id) && // the + // collection is not empty + c.name.contains(RegExp(query, caseSensitive: false)), ) .toList(); - - List collectionWithThumbnailForSerach = []; - - for (int collectionID in collectionIDsForSearch) { - CollectionWithThumbnail c = CollectionWithThumbnail( - collectionIDToCollectionsForSearch[collectionID], - collectionIDtoFileForCollectionWithAtleastOneFile[collectionID], - ); - collectionWithThumbnailForSerach.add(c); + List result = []; + for (Collection collection in matchedCollection) { + result.add(CollectionWithThumbnail( + collection, + collectionIDToLatestFileMap[collection.id], + )); } - - return collectionWithThumbnailForSerach; + return result; } Future> getSharees(int collectionID) { @@ -903,19 +904,6 @@ class CollectionsService { } } } - - Future> getSearchedCollections( - String query, - ) async { - List collectionsWithThumbnailToSearch = - await getCollectionsWithThumbnailForSearch(); - return collectionsWithThumbnailToSearch - .where( - (element) => element.collection.name - .contains(RegExp(query, caseSensitive: false)), - ) - .toList(); - } } class AddFilesRequest { diff --git a/lib/ui/viewer/search/search_widget.dart b/lib/ui/viewer/search/search_widget.dart index 4fb442381..ac49b3469 100644 --- a/lib/ui/viewer/search/search_widget.dart +++ b/lib/ui/viewer/search/search_widget.dart @@ -71,7 +71,7 @@ class _SearchwidgetState extends State { ), onChanged: (value) async { matchedCollections = await CollectionsService.instance - .getSearchedCollections(value); + .getFilteredCollectionsWithThumbnail(value); _searchQ.value = value; }, autofocus: true, From 5b21bc0aa6a23a87ea53a97a279865a12c298d4e Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Thu, 28 Jul 2022 10:37:52 +0530 Subject: [PATCH 28/29] rename --- ...n_widget_generator.dart => collection_result_widget.dart} | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) rename lib/ui/viewer/search/{collection_suggestion_widget_generator.dart => collection_result_widget.dart} (94%) diff --git a/lib/ui/viewer/search/collection_suggestion_widget_generator.dart b/lib/ui/viewer/search/collection_result_widget.dart similarity index 94% rename from lib/ui/viewer/search/collection_suggestion_widget_generator.dart rename to lib/ui/viewer/search/collection_result_widget.dart index 64b70d8da..987b0fdbd 100644 --- a/lib/ui/viewer/search/collection_suggestion_widget_generator.dart +++ b/lib/ui/viewer/search/collection_result_widget.dart @@ -6,10 +6,9 @@ import 'package:photos/ui/viewer/file/thumbnail_widget.dart'; import 'package:photos/ui/viewer/gallery/collection_page.dart'; import 'package:photos/utils/navigation_util.dart'; -class CollectionSuggestionWidgetGenerator extends StatelessWidget { +class CollectionSearchResultWidget extends StatelessWidget { final CollectionWithThumbnail c; - const CollectionSuggestionWidgetGenerator(this.c, {Key key}) - : super(key: key); + const CollectionSearchResultWidget(this.c, {Key key}) : super(key: key); @override Widget build(BuildContext context) { From 40ed037327c8a168c165e1d6a9b11d094e2ef446 Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Thu, 28 Jul 2022 10:38:20 +0530 Subject: [PATCH 29/29] Refactor search UI --- lib/ui/status_bar_widget.dart | 2 +- .../search/collection_result_widget.dart | 20 ++++++++----------- .../search/search_results_suggestions.dart | 4 ++-- lib/ui/viewer/search/search_widget.dart | 17 ++++++++++------ 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/lib/ui/status_bar_widget.dart b/lib/ui/status_bar_widget.dart index d610b2021..951560430 100644 --- a/lib/ui/status_bar_widget.dart +++ b/lib/ui/status_bar_widget.dart @@ -232,7 +232,7 @@ class StatusBarBrandingWidget extends StatelessWidget { FeatureFlagService.instance.enableSearchFeature() ? SizedBox( width: MediaQuery.of(context).size.width, - child: Align( + child: const Align( alignment: Alignment.centerRight, child: SearchIconWidget(), ), diff --git a/lib/ui/viewer/search/collection_result_widget.dart b/lib/ui/viewer/search/collection_result_widget.dart index 987b0fdbd..308534112 100644 --- a/lib/ui/viewer/search/collection_result_widget.dart +++ b/lib/ui/viewer/search/collection_result_widget.dart @@ -6,9 +6,10 @@ import 'package:photos/ui/viewer/file/thumbnail_widget.dart'; import 'package:photos/ui/viewer/gallery/collection_page.dart'; import 'package:photos/utils/navigation_util.dart'; -class CollectionSearchResultWidget extends StatelessWidget { +class CollectionResultWidget extends StatelessWidget { final CollectionWithThumbnail c; - const CollectionSearchResultWidget(this.c, {Key key}) : super(key: key); + + const CollectionResultWidget(this.c, {Key key}) : super(key: key); @override Widget build(BuildContext context) { @@ -37,7 +38,6 @@ class CollectionSearchResultWidget extends StatelessWidget { builder: (context, snapshot) { if (snapshot.hasData && snapshot.data > 0) { int noOfMemories = snapshot.data; - return RichText( text: TextSpan( style: TextStyle( @@ -59,20 +59,16 @@ class CollectionSearchResultWidget extends StatelessWidget { ), ], ), - Row( - children: [ - SizedBox( - height: 50, - width: 50, - child: ThumbnailWidget(c.thumbnail), - ), - ], + SizedBox( + height: 50, + width: 50, + child: ThumbnailWidget(c.thumbnail), ) ], ), ), onTap: () { - routeToPage(context, CollectionPage(c)); + routeToPage(context, CollectionPage(c), forceCustomPageRoute: true); }, ); } diff --git a/lib/ui/viewer/search/search_results_suggestions.dart b/lib/ui/viewer/search/search_results_suggestions.dart index 8547dbee5..d4d4d71ad 100644 --- a/lib/ui/viewer/search/search_results_suggestions.dart +++ b/lib/ui/viewer/search/search_results_suggestions.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:photos/models/collection_items.dart'; -import 'package:photos/ui/viewer/search/collection_suggestion_widget_generator.dart'; +import 'package:photos/ui/viewer/search/collection_result_widget.dart'; class SearchResultsSuggestions extends StatelessWidget { final List collectionsWithThumbnail; @@ -12,7 +12,7 @@ class SearchResultsSuggestions extends StatelessWidget { Widget build(BuildContext context) { List suggestions = []; for (CollectionWithThumbnail c in collectionsWithThumbnail) { - suggestions.add(CollectionSuggestionWidgetGenerator(c)); + suggestions.add(CollectionResultWidget(c)); } return Container( diff --git a/lib/ui/viewer/search/search_widget.dart b/lib/ui/viewer/search/search_widget.dart index ac49b3469..5d38ecccd 100644 --- a/lib/ui/viewer/search/search_widget.dart +++ b/lib/ui/viewer/search/search_widget.dart @@ -4,25 +4,30 @@ import 'package:photos/models/collection_items.dart'; import 'package:photos/services/collections_service.dart'; import 'package:photos/ui/viewer/search/search_results_suggestions.dart'; -// ignore: must_be_immutable class SearchIconWidget extends StatefulWidget { - bool openSearch; - SearchIconWidget({Key key, this.openSearch = false}) : super(key: key); + const SearchIconWidget({Key key}) : super(key: key); @override State createState() => _SearchIconWidgetState(); } class _SearchIconWidgetState extends State { + bool showSearchWidget; + @override + void initState() { + super.initState(); + showSearchWidget = false; + } + @override Widget build(BuildContext context) { - return widget.openSearch - ? Searchwidget(widget.openSearch) + return showSearchWidget + ? Searchwidget(showSearchWidget) : IconButton( onPressed: () { setState( () { - widget.openSearch = !widget.openSearch; + showSearchWidget = !showSearchWidget; }, ); },