From 7b373186331c7c9a5226543b84e7c7df43e5eed6 Mon Sep 17 00:00:00 2001 From: Philippe Loriaux Date: Fri, 8 Apr 2022 15:35:42 +0200 Subject: [PATCH 1/8] [Rooms list] Restore the room search (#487) --- .../Common/Recents/RecentsViewController.h | 19 ++ .../Common/Recents/RecentsViewController.m | 194 +++++++++++++++++- Riot/Modules/TabBar/TabBarCoordinator.swift | 5 + changelog.d/487.bugfix | 1 + 4 files changed, 217 insertions(+), 2 deletions(-) create mode 100644 changelog.d/487.bugfix diff --git a/Riot/Modules/Common/Recents/RecentsViewController.h b/Riot/Modules/Common/Recents/RecentsViewController.h index 53755ac79d..7074ae29ed 100644 --- a/Riot/Modules/Common/Recents/RecentsViewController.h +++ b/Riot/Modules/Common/Recents/RecentsViewController.h @@ -21,6 +21,15 @@ @class AnalyticsScreenTimer; @class AppActivityIndicatorPresenter; +@protocol SearchBarVisibilityDelegate + +/** + Will be called when the user wants to show or hide the searchBar. + */ +- (void)toggleSearchBar; + +@end + /** Notification to be posted when recents data is ready. Notification object will be the RecentsViewController instance. */ @@ -66,6 +75,11 @@ FOUNDATION_EXPORT NSString *const RecentsViewControllerDataReadyNotification; */ @property (nonatomic) BOOL shouldScrollToTopOnRefresh; +/** + Tell whether the search bar at the top of the recents table is enabled. YES by default. + */ +@property (nonatomic) BOOL enableSearchBar; + /** Tell whether the drag and drop option are enabled. NO by default. This option is used to move a room from a section to another. @@ -97,6 +111,11 @@ FOUNDATION_EXPORT NSString *const RecentsViewControllerDataReadyNotification; */ @property (nonatomic, strong) AppActivityIndicatorPresenter *activityPresenter; +/** + Protocol to show/hide search bar from an external component. + */ +@property (nonatomic) id searchBarVisibilityDelegate; + /** Return the sticky header for the specified section of the table view diff --git a/Riot/Modules/Common/Recents/RecentsViewController.m b/Riot/Modules/Common/Recents/RecentsViewController.m index 54c2a68bad..9ddfd7227f 100644 --- a/Riot/Modules/Common/Recents/RecentsViewController.m +++ b/Riot/Modules/Common/Recents/RecentsViewController.m @@ -31,7 +31,7 @@ NSString *const RecentsViewControllerDataReadyNotification = @"RecentsViewControllerDataReadyNotification"; -@interface RecentsViewController () +@interface RecentsViewController () { // Tell whether a recents refresh is pending (suspended during editing mode). BOOL isRefreshPending; @@ -47,6 +47,10 @@ @interface RecentsViewController () self.recentsSearchBar.frame.size.height)) +// { +// // Hide the search bar +// [self hideSearchBar:YES]; +// +// // Refresh display +// [self refreshRecentsTable]; +// } +// } +// } } #pragma mark - Table view scrolling @@ -1504,6 +1593,72 @@ - (void)recentListViewController:(MXKRecentListViewController *)recentListViewCo [self showRoomWithRoomId:roomId inMatrixSession:matrixSession]; } +- (void)recentListViewController:(MXKRecentListViewController *)recentListViewController didSelectSuggestedRoom:(MXSpaceChildInfo *)childInfo +{ +// RoomPreviewData *previewData = [[RoomPreviewData alloc] initWithSpaceChildInfo:childInfo andSession:self.mainSession]; +// [self startActivityIndicator]; +// MXWeakify(self); +// [previewData peekInRoom:^(BOOL succeeded) { +// MXStrongifyAndReturnIfNil(self); +// [self stopActivityIndicator]; +// [self showRoomPreviewWithData:previewData]; +// }]; +} + +#pragma mark - UISearchBarDelegate + +- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset +{ + [super scrollViewWillEndDragging:scrollView withVelocity:velocity targetContentOffset:targetContentOffset]; +} + +- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar +{ + // Tchap: Disable fake search bar +// if (searchBar == tableSearchBar) +// { +// [self hideSearchBar:NO]; +// [self.recentsSearchBar becomeFirstResponder]; +// return NO; +// } + + return YES; + +} + +- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar +{ + dispatch_async(dispatch_get_main_queue(), ^{ + + [self.recentsSearchBar setShowsCancelButton:YES animated:NO]; + + }); +} + +- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar +{ + [self.recentsSearchBar setShowsCancelButton:NO animated:NO]; +} + +- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText +{ + [super searchBar:searchBar textDidChange:searchText]; + + UIImage *filterIcon = searchText.length > 0 ? [AssetImages.filterOn.image vc_tintedImageUsingColor: ThemeService.shared.theme.tintColor] : AssetImages.filterOff.image; + [self.recentsSearchBar setImage:filterIcon + forSearchBarIcon:UISearchBarIconSearch + state:UIControlStateNormal]; +} + +// Tchap: Restore default icon after cancel. +- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar { + [super searchBarCancelButtonClicked:searchBar]; + + [self.recentsSearchBar setImage:AssetImages.filterOff.image + forSearchBarIcon:UISearchBarIconSearch + state:UIControlStateNormal]; +} + #pragma mark - CreateRoomCoordinatorBridgePresenterDelegate //- (void)createRoomCoordinatorBridgePresenterDelegate:(CreateRoomCoordinatorBridgePresenter *)coordinatorBridgePresenter didCreateNewRoom:(MXRoom *)room @@ -1722,4 +1877,39 @@ - (void)stopActivityIndicator { // } } +#pragma mark - Search Bar + +- (void)toggleSearchBar { + if (self.recentsSearchBar.isFirstResponder) { + [self.recentsSearchBar resignFirstResponder]; + [self cleanSearchAndHideSearchBar:FALSE]; + } else { + BOOL willShowSearchBar = self.recentsSearchBar.hidden; + if (willShowSearchBar) { + [self hideSearchBar:FALSE]; + } else { + [self cleanSearchAndHideSearchBar:TRUE]; + } + } +} + +- (void)cleanSearchAndHideSearchBar:(BOOL)hide { + // Clear SearchField content and refresh dataSource + self.recentsSearchBar.text = @""; + [self.dataSource searchWithPatterns:nil]; + + // Refresh UI + [self refreshRecentsTable]; + + // Reset icon + [self.recentsSearchBar setImage:AssetImages.filterOff.image + forSearchBarIcon:UISearchBarIconSearch + state:UIControlStateNormal]; + + // Hide Search bar + if (hide) { + [self hideSearchBar:TRUE]; + } +} + @end diff --git a/Riot/Modules/TabBar/TabBarCoordinator.swift b/Riot/Modules/TabBar/TabBarCoordinator.swift index 586d6873f3..ed31200ddb 100644 --- a/Riot/Modules/TabBar/TabBarCoordinator.swift +++ b/Riot/Modules/TabBar/TabBarCoordinator.swift @@ -362,6 +362,11 @@ final class TabBarCoordinator: NSObject, TabBarCoordinatorType { // FIXME: Should be displayed per tab. private func showUnifiedSearch() { + // Tchap: Show filter textField. + guard let vc = masterTabBarController.selectedViewController as? SearchBarVisibilityDelegate else { + return + } + vc.toggleSearchBar() // let viewController = self.createUnifiedSearchController() // // self.navigationRouter.push(viewController, animated: true, popCompletion: nil) diff --git a/changelog.d/487.bugfix b/changelog.d/487.bugfix new file mode 100644 index 0000000000..2a14d9a160 --- /dev/null +++ b/changelog.d/487.bugfix @@ -0,0 +1 @@ +[Rooms list] Restore the room search From a281d8bdceac6936df7781c729f6be7c9bd1bf67 Mon Sep 17 00:00:00 2001 From: Philippe Loriaux Date: Fri, 8 Apr 2022 15:39:20 +0200 Subject: [PATCH 2/8] Remove searchBar by default --- Riot/Modules/Common/Recents/RecentsViewController.m | 3 --- 1 file changed, 3 deletions(-) diff --git a/Riot/Modules/Common/Recents/RecentsViewController.m b/Riot/Modules/Common/Recents/RecentsViewController.m index 9ddfd7227f..c3d2610983 100644 --- a/Riot/Modules/Common/Recents/RecentsViewController.m +++ b/Riot/Modules/Common/Recents/RecentsViewController.m @@ -299,9 +299,6 @@ - (void)viewWillAppear:(BOOL)animated // Apply the current theme [self userInterfaceThemeDidChange]; - - // Tchap: Show SearchBar by default - [self hideSearchBar:FALSE]; } - (void)viewWillDisappear:(BOOL)animated From dc7de2a6c56ed5bc57d86a6e64a4cf569d96c375 Mon Sep 17 00:00:00 2001 From: Philippe Loriaux Date: Mon, 11 Apr 2022 15:43:41 +0200 Subject: [PATCH 3/8] Replace Search icon by Filter in navigation bar --- Riot/Modules/TabBar/TabBarCoordinator.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Riot/Modules/TabBar/TabBarCoordinator.swift b/Riot/Modules/TabBar/TabBarCoordinator.swift index ed31200ddb..fd490443f7 100644 --- a/Riot/Modules/TabBar/TabBarCoordinator.swift +++ b/Riot/Modules/TabBar/TabBarCoordinator.swift @@ -208,7 +208,7 @@ final class TabBarCoordinator: NSObject, TabBarCoordinatorType { tabBarController.navigationItem.leftBarButtonItem = settingsBarButtonItem } - let searchBarButtonItem: MXKBarButtonItem = MXKBarButtonItem(image: Asset.Images.searchIcon.image, style: .plain) { [weak self] in + let searchBarButtonItem: MXKBarButtonItem = MXKBarButtonItem(image: Asset.Images.filterOff.image, style: .plain) { [weak self] in self?.showUnifiedSearch() } searchBarButtonItem.accessibilityLabel = VectorL10n.searchDefaultPlaceholder From aba0f0fd24473a2318203e6802f0b6b5eb55e753 Mon Sep 17 00:00:00 2001 From: Philippe Loriaux Date: Mon, 11 Apr 2022 15:47:09 +0200 Subject: [PATCH 4/8] Show keyboard after the searchBar appears --- Riot/Modules/Common/Recents/RecentsViewController.m | 1 + 1 file changed, 1 insertion(+) diff --git a/Riot/Modules/Common/Recents/RecentsViewController.m b/Riot/Modules/Common/Recents/RecentsViewController.m index c3d2610983..9d6aa5fad9 100644 --- a/Riot/Modules/Common/Recents/RecentsViewController.m +++ b/Riot/Modules/Common/Recents/RecentsViewController.m @@ -1884,6 +1884,7 @@ - (void)toggleSearchBar { BOOL willShowSearchBar = self.recentsSearchBar.hidden; if (willShowSearchBar) { [self hideSearchBar:FALSE]; + [self.recentsSearchBar becomeFirstResponder]; } else { [self cleanSearchAndHideSearchBar:TRUE]; } From 0b8d73b8e1da6ccde7fedbedccfc1301fb24bab7 Mon Sep 17 00:00:00 2001 From: Philippe Loriaux Date: Mon, 11 Apr 2022 16:09:05 +0200 Subject: [PATCH 5/8] Add missing French localisation for Filter --- Riot/Assets/fr.lproj/Vector.strings | 1 + 1 file changed, 1 insertion(+) diff --git a/Riot/Assets/fr.lproj/Vector.strings b/Riot/Assets/fr.lproj/Vector.strings index 61dcc542dd..e0ec2d1687 100644 --- a/Riot/Assets/fr.lproj/Vector.strings +++ b/Riot/Assets/fr.lproj/Vector.strings @@ -123,6 +123,7 @@ "search_people" = "Personnes"; "search_files" = "Fichiers"; "search_default_placeholder" = "Recherche"; +"search_filter_placeholder" = "Filtrer"; "search_people_placeholder" = "Rechercher par identifiant, nom ou e-mail"; "search_no_result" = "Aucun résultat"; "search_in_progress" = "Recherche en cours…"; From f493bdbfdeac1bb468e265bccaf9d018eab023b4 Mon Sep 17 00:00:00 2001 From: Philippe Loriaux Date: Mon, 11 Apr 2022 16:09:36 +0200 Subject: [PATCH 6/8] Update Rooms section and title to Conversations --- Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m | 4 +++- Riot/Modules/TabBar/TabBarCoordinator.swift | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m b/Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m index faaa6554b0..75dfda0278 100644 --- a/Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m +++ b/Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m @@ -624,7 +624,9 @@ - (NSAttributedString *)attributedStringForHeaderTitleInSection:(NSInteger)secti } else { - title = [VectorL10n roomRecentsConversationsSection]; + title = NSLocalizedStringFromTable(@"conversations_main_section", @"Tchap", @"").uppercaseString; + // Tchap: Update section name to `Conversations` +// [VectorL10n roomRecentsConversationsSection]; } } else if (section == directorySection) diff --git a/Riot/Modules/TabBar/TabBarCoordinator.swift b/Riot/Modules/TabBar/TabBarCoordinator.swift index fd490443f7..b50f288c51 100644 --- a/Riot/Modules/TabBar/TabBarCoordinator.swift +++ b/Riot/Modules/TabBar/TabBarCoordinator.swift @@ -257,7 +257,9 @@ final class TabBarCoordinator: NSObject, TabBarCoordinatorType { let roomsViewController: RoomsViewController = RoomsViewController.instantiate() roomsViewController.roomsViewDelegate = self roomsViewController.tabBarItem.tag = Int(TABBAR_ROOMS_INDEX) - roomsViewController.accessibilityLabel = VectorL10n.titleRooms + roomsViewController.accessibilityLabel = TchapL10n.conversationsTabTitle + // Tchap: Update accessibility label name to `Conversations` +// roomsViewController.accessibilityLabel = VectorL10n.titleRooms return roomsViewController } From c2762dd18214880b7e1e045e155511dedcd332c4 Mon Sep 17 00:00:00 2001 From: Philippe Loriaux Date: Mon, 11 Apr 2022 16:41:58 +0200 Subject: [PATCH 7/8] Move comment --- Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m b/Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m index 75dfda0278..d8852c793d 100644 --- a/Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m +++ b/Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m @@ -624,9 +624,8 @@ - (NSAttributedString *)attributedStringForHeaderTitleInSection:(NSInteger)secti } else { - title = NSLocalizedStringFromTable(@"conversations_main_section", @"Tchap", @"").uppercaseString; // Tchap: Update section name to `Conversations` -// [VectorL10n roomRecentsConversationsSection]; + title = NSLocalizedStringFromTable(@"conversations_main_section", @"Tchap", @"").uppercaseString; } } else if (section == directorySection) From 3b9f2f0a5cdcd49903c2ff70adb199d9ba7f7270 Mon Sep 17 00:00:00 2001 From: Philippe Loriaux Date: Mon, 11 Apr 2022 16:43:51 +0200 Subject: [PATCH 8/8] Move comment --- Riot/Modules/TabBar/TabBarCoordinator.swift | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Riot/Modules/TabBar/TabBarCoordinator.swift b/Riot/Modules/TabBar/TabBarCoordinator.swift index b50f288c51..684092ed93 100644 --- a/Riot/Modules/TabBar/TabBarCoordinator.swift +++ b/Riot/Modules/TabBar/TabBarCoordinator.swift @@ -257,9 +257,8 @@ final class TabBarCoordinator: NSObject, TabBarCoordinatorType { let roomsViewController: RoomsViewController = RoomsViewController.instantiate() roomsViewController.roomsViewDelegate = self roomsViewController.tabBarItem.tag = Int(TABBAR_ROOMS_INDEX) - roomsViewController.accessibilityLabel = TchapL10n.conversationsTabTitle // Tchap: Update accessibility label name to `Conversations` -// roomsViewController.accessibilityLabel = VectorL10n.titleRooms + roomsViewController.accessibilityLabel = TchapL10n.conversationsTabTitle return roomsViewController }