Skip to content

armgit / ente

Public Imported from GitHub
0

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

[mob][photos] feat: add searchable app bar and enhance collection filtering

Aman Raj Singh Mourya28f03d35140b
diff --git a/mobile/lib/ui/collections/collection_list_page.dart b/mobile/lib/ui/collections/collection_list_page.dart
index 7bc00c6f13..6a81023886 100644
--- a/mobile/lib/ui/collections/collection_list_page.dart
+++ b/mobile/lib/ui/collections/collection_list_page.dart
@@ -11,6 +11,7 @@ import "package:photos/service_locator.dart";
import "package:photos/services/collections_service.dart";
import "package:photos/ui/collections/flex_grid_view.dart";
import "package:photos/ui/components/buttons/icon_button_widget.dart";
+import "package:photos/ui/components/searchable_appbar.dart";
import "package:photos/utils/local_settings.dart";
enum UISectionType {
@@ -45,6 +46,7 @@ class _CollectionListPageState extends State<CollectionListPage> {
List<Collection>? collections;
AlbumSortKey? sortKey;
AlbumViewType? albumViewType;
+ String _searchQuery = "";
@override
void initState() {
@@ -66,8 +68,8 @@ class _CollectionListPageState extends State<CollectionListPage> {
@override
Widget build(BuildContext context) {
- final displayLimitCount =
- (collections?.length ?? 0) + (widget.tag.isEmpty ? 1 : 0);
+ final displayLimitCount = (collections?.length ?? 0) +
+ (widget.tag.isEmpty && _searchQuery.isEmpty ? 1 : 0);
return Scaffold(
body: SafeArea(
child: CustomScrollView(
@@ -76,19 +78,7 @@ class _CollectionListPageState extends State<CollectionListPage> {
initialScrollOffset: widget.initialScrollOffset ?? 0,
),
slivers: [
- SliverAppBar(
- elevation: 0,
- title: Hero(
- tag: widget.tag,
- child: widget.appTitle ?? const SizedBox.shrink(),
- ),
- floating: true,
- actions: widget.sectionType == UISectionType.homeCollections
- ? [
- _sortMenu(collections!),
- ]
- : null,
- ),
+ _buildAppBar(),
CollectionsFlexiGridViewWidget(
collections,
displayLimitCount: displayLimitCount,
@@ -96,7 +86,8 @@ class _CollectionListPageState extends State<CollectionListPage> {
enableSelectionMode:
widget.sectionType == UISectionType.homeCollections,
albumViewType: albumViewType ?? AlbumViewType.grid,
- shouldShowCreateAlbum: true,
+ shouldShowCreateAlbum:
+ widget.sectionType == UISectionType.homeCollections,
),
],
),
@@ -104,6 +95,29 @@ class _CollectionListPageState extends State<CollectionListPage> {
);
}
+ Widget _buildAppBar() {
+ return SearchableAppBar(
+ title: widget.appTitle ?? const SizedBox.shrink(),
+ heroTag: widget.tag,
+ onSearch: (value) {
+ setState(() {
+ _searchQuery = value;
+ });
+ refreshCollections();
+ },
+ onSearchClosed: () {
+ setState(() {
+ _searchQuery = '';
+ });
+ refreshCollections();
+ },
+ actions: [
+ const SizedBox(width: 8),
+ _sortMenu(collections!),
+ ],
+ );
+ }
+
Widget _sortMenu(List<Collection> collections) {
Text sortOptionText(AlbumSortKey key) {
String text = key.toString();
@@ -187,15 +201,33 @@ class _CollectionListPageState extends State<CollectionListPage> {
if (widget.sectionType == UISectionType.incomingCollections ||
widget.sectionType == UISectionType.outgoingCollections) {
final SharedCollections sharedCollections =
- CollectionsService.instance.getSharedCollections();
+ await CollectionsService.instance.getSharedCollections();
if (widget.sectionType == UISectionType.incomingCollections) {
collections = sharedCollections.incoming;
} else {
collections = sharedCollections.outgoing;
}
+ if (_searchQuery.isNotEmpty) {
+ collections = widget.collections
+ ?.where(
+ (c) => c.displayName
+ .toLowerCase()
+ .contains(_searchQuery.toLowerCase()),
+ )
+ .toList();
+ }
} else if (widget.sectionType == UISectionType.homeCollections) {
collections =
await CollectionsService.instance.getCollectionForOnEnteSection();
+ if (_searchQuery.isNotEmpty) {
+ collections = widget.collections
+ ?.where(
+ (c) => c.displayName
+ .toLowerCase()
+ .contains(_searchQuery.toLowerCase()),
+ )
+ .toList();
+ }
}
if (mounted) {
setState(() {});
diff --git a/mobile/lib/ui/components/searchable_appbar.dart b/mobile/lib/ui/components/searchable_appbar.dart
new file mode 100644
index 0000000000..3ce8e3b5ae
--- /dev/null
+++ b/mobile/lib/ui/components/searchable_appbar.dart
@@ -0,0 +1,131 @@
+import "package:flutter/material.dart";
+import "package:photos/theme/ente_theme.dart";
+import "package:photos/ui/components/buttons/icon_button_widget.dart";
+
+class SearchableAppBar extends StatefulWidget {
+ final Widget title;
+ final List<Widget>? actions;
+ final Function(String) onSearch;
+ final VoidCallback? onSearchClosed;
+ final String heroTag;
+
+ const SearchableAppBar({
+ super.key,
+ required this.title,
+ this.actions,
+ required this.onSearch,
+ this.onSearchClosed,
+ this.heroTag = "",
+ });
+
+ @override
+ State<SearchableAppBar> createState() => _SearchableAppBarState();
+}
+
+class _SearchableAppBarState extends State<SearchableAppBar> {
+ bool _isSearchActive = false;
+ final TextEditingController _searchController = TextEditingController();
+ final FocusNode _searchFocusNode = FocusNode();
+
+ @override
+ void dispose() {
+ _searchController.dispose();
+ _searchFocusNode.dispose();
+ super.dispose();
+ }
+
+ void _activateSearch() {
+ setState(() {
+ _isSearchActive = true;
+ });
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ _searchFocusNode.requestFocus();
+ });
+ }
+
+ void _deactivateSearch() {
+ setState(() {
+ _isSearchActive = false;
+ _searchController.clear();
+ });
+ _searchFocusNode.unfocus();
+ if (widget.onSearchClosed != null) {
+ widget.onSearchClosed!();
+ }
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ return SliverAppBar(
+ floating: true,
+ elevation: 0,
+ automaticallyImplyLeading: !_isSearchActive,
+ title: AnimatedSwitcher(
+ duration: const Duration(milliseconds: 200),
+ switchInCurve: Curves.easeOut,
+ switchOutCurve: Curves.easeIn,
+ transitionBuilder: (Widget child, Animation<double> animation) {
+ return FadeTransition(
+ opacity: animation,
+ child: child,
+ );
+ },
+ child: _isSearchActive
+ ? _buildSearchField()
+ : Hero(
+ key: const ValueKey('titleBar'),
+ tag: widget.heroTag,
+ child: widget.title,
+ ),
+ ),
+ actions: _isSearchActive
+ ? null
+ : [
+ IconButtonWidget(
+ icon: Icons.search,
+ iconButtonType: IconButtonType.secondary,
+ onTap: _activateSearch,
+ ),
+ ...?widget.actions,
+ ],
+ );
+ }
+
+ Widget _buildSearchField() {
+ final colorScheme = getEnteColorScheme(context);
+ return Container(
+ key: const ValueKey('searchBar'),
+ alignment: Alignment.center,
+ child: TextFormField(
+ controller: _searchController,
+ focusNode: _searchFocusNode,
+ decoration: InputDecoration(
+ filled: true,
+ fillColor: colorScheme.fillFaint,
+ prefixIcon: Icon(
+ Icons.search_rounded,
+ color: colorScheme.strokeMuted,
+ ),
+ suffixIcon: IconButton(
+ icon: Icon(
+ Icons.cancel_rounded,
+ color: colorScheme.strokeMuted,
+ ),
+ onPressed: _deactivateSearch,
+ ),
+ border: const UnderlineInputBorder(
+ borderSide: BorderSide.none,
+ ),
+ contentPadding: const EdgeInsets.fromLTRB(12, 12, 0, 12),
+ focusedBorder: OutlineInputBorder(
+ borderSide: BorderSide(
+ color: colorScheme.strokeFaint,
+ ),
+ borderRadius: BorderRadius.circular(8),
+ ),
+ ),
+ onChanged: widget.onSearch,
+ ),
+ );
+ }
+}