Skip to content

Commit

Permalink
Merge pull request #498 from tchapgouv/phlpro/487-restore-room-search
Browse files Browse the repository at this point in the history
[Rooms list] Restore the room search (#487)
  • Loading branch information
Phl-Pro authored Apr 11, 2022
2 parents d69a6fe + 3b9f2f0 commit feb3238
Show file tree
Hide file tree
Showing 6 changed files with 221 additions and 5 deletions.
1 change: 1 addition & 0 deletions Riot/Assets/fr.lproj/Vector.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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…";
Expand Down
3 changes: 2 additions & 1 deletion Riot/Modules/Common/Recents/DataSources/RecentsDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,8 @@ - (NSAttributedString *)attributedStringForHeaderTitleInSection:(NSInteger)secti
}
else
{
title = [VectorL10n roomRecentsConversationsSection];
// Tchap: Update section name to `Conversations`
title = NSLocalizedStringFromTable(@"conversations_main_section", @"Tchap", @"").uppercaseString;
}
}
else if (section == directorySection)
Expand Down
19 changes: 19 additions & 0 deletions Riot/Modules/Common/Recents/RecentsViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
@class AnalyticsScreenTimer;
@class AppActivityIndicatorPresenter;

@protocol SearchBarVisibilityDelegate <NSObject>

/**
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.
*/
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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> searchBarVisibilityDelegate;

/**
Return the sticky header for the specified section of the table view
Expand Down
192 changes: 190 additions & 2 deletions Riot/Modules/Common/Recents/RecentsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

NSString *const RecentsViewControllerDataReadyNotification = @"RecentsViewControllerDataReadyNotification";

@interface RecentsViewController () </*CreateRoomCoordinatorBridgePresenterDelegate, RoomsDirectoryCoordinatorBridgePresenterDelegate,*/ RoomNotificationSettingsCoordinatorBridgePresenterDelegate/*, DialpadViewControllerDelegate, ExploreRoomCoordinatorBridgePresenterDelegate*/>
@interface RecentsViewController () </*CreateRoomCoordinatorBridgePresenterDelegate, RoomsDirectoryCoordinatorBridgePresenterDelegate,*/ RoomNotificationSettingsCoordinatorBridgePresenterDelegate/*, DialpadViewControllerDelegate, ExploreRoomCoordinatorBridgePresenterDelegate*/, SearchBarVisibilityDelegate>
{
// Tell whether a recents refresh is pending (suspended during editing mode).
BOOL isRefreshPending;
Expand All @@ -47,6 +47,10 @@ @interface RecentsViewController () </*CreateRoomCoordinatorBridgePresenterDeleg

MXHTTPOperation *currentRequest;

// The fake search bar displayed at the top of the recents table. We switch on the actual search bar (self.recentsSearchBar)
// when the user selects it.
UISearchBar *tableSearchBar;

// Observe kThemeServiceDidChangeThemeNotification to handle user interface theme change.
__weak id kThemeServiceDidChangeThemeNotificationObserver;
}
Expand Down Expand Up @@ -91,14 +95,28 @@ - (void)finalizeInit
self.enableBarTintColorStatusChange = NO;
self.rageShakeManager = [RageShakeManager sharedManager];

// Remove the search option from the navigation bar.
// Enable the search bar in the recents table, and remove the search option from the navigation bar.
_enableSearchBar = YES;
self.enableBarButtonSearch = NO;
self.searchBarVisibilityDelegate = self;

_enableDragging = NO;

_enableStickyHeaders = NO;
_stickyHeaderHeight = 30.0;

// Tchap: Disable Fake SearchBar
// // Create the fake search bar
// tableSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 600, 44)];
// tableSearchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
// tableSearchBar.showsCancelButton = NO;
// tableSearchBar.placeholder = [VectorL10n searchFilterPlaceholder];
// [tableSearchBar setImage:AssetImages.filterOff.image
// forSearchBarIcon:UISearchBarIconSearch
// state:UIControlStateNormal];
//
// tableSearchBar.delegate = self;

displayedSectionHeaders = [NSMutableArray array];

// Set itself as delegate by default.
Expand All @@ -123,6 +141,9 @@ - (void)viewDidLoad

// Register key verification banner cells
[self.recentsTableView registerNib:CrossSigningSetupBannerCell.nib forCellReuseIdentifier:CrossSigningSetupBannerCell.defaultReuseIdentifier];

[self.recentsTableView registerClass:SectionHeaderView.class
forHeaderFooterViewReuseIdentifier:SectionHeaderView.defaultReuseIdentifier];

// Hide line separators of empty cells
self.recentsTableView.tableFooterView = [[UIView alloc] init];
Expand All @@ -142,6 +163,13 @@ - (void)viewDidLoad

}];

self.recentsSearchBar.autocapitalizationType = UITextAutocapitalizationTypeNone;
self.recentsSearchBar.placeholder = [VectorL10n searchFilterPlaceholder];
[self.recentsSearchBar setImage:AssetImages.filterOff.image
forSearchBarIcon:UISearchBarIconSearch
state:UIControlStateNormal];
[self.recentsSearchBar setShowsCancelButton:FALSE];

// Observe user interface theme change.
kThemeServiceDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kThemeServiceDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {

Expand All @@ -161,8 +189,15 @@ - (void)userInterfaceThemeDidChange

// Use the primary bg color for the recents table view in plain style.
self.recentsTableView.backgroundColor = ThemeService.shared.theme.backgroundColor;
self.recentsTableView.separatorColor = ThemeService.shared.theme.lineBreakColor;
topview.backgroundColor = ThemeService.shared.theme.headerBackgroundColor;
self.view.backgroundColor = ThemeService.shared.theme.backgroundColor;

[ThemeService.shared.theme applyStyleOnSearchBar:tableSearchBar];
[ThemeService.shared.theme applyStyleOnSearchBar:self.recentsSearchBar];

// Force table refresh
[self.recentsTableView reloadData];

if (self.recentsSearchBar)
{
Expand Down Expand Up @@ -212,6 +247,7 @@ - (void)destroy
[[NSNotificationCenter defaultCenter] removeObserver:kThemeServiceDidChangeThemeNotificationObserver];
kThemeServiceDidChangeThemeNotificationObserver = nil;
}
self.searchBarVisibilityDelegate = nil;
}

- (void)setEditing:(BOOL)editing animated:(BOOL)animated
Expand Down Expand Up @@ -359,6 +395,15 @@ - (void)refreshRecentsTable

[self.recentsTableView reloadData];

// Tchap: Disable fake search bar
// Check conditions to display the fake search bar into the table header
// if (_enableSearchBar && self.recentsSearchBar.isHidden && self.recentsTableView.tableHeaderView == nil)
// {
// // Add the search bar by hiding it by default.
// self.recentsTableView.tableHeaderView = tableSearchBar;
// self.recentsTableView.contentOffset = CGPointMake(0, self.recentsTableView.contentOffset.y + tableSearchBar.frame.size.height);
// }

if (_shouldScrollToTopOnRefresh)
{
[self scrollToTop:NO];
Expand All @@ -375,6 +420,19 @@ - (void)refreshRecentsTable
}
}

- (void)hideSearchBar:(BOOL)hidden
{
[super hideSearchBar:hidden];

// Tchap: Disable fake search bar
// if (!hidden)
// {
// // Remove the fake table header view if any
// self.recentsTableView.tableHeaderView = nil;
// self.recentsTableView.contentInset = UIEdgeInsetsZero;
// }
}

#pragma mark -

- (void)refreshCurrentSelectedCell:(BOOL)forceVisible
Expand Down Expand Up @@ -994,6 +1052,18 @@ - (void)dataSource:(MXKDataSource *)dataSource didCellChange:(id)changes
TableViewCellWithCollectionView *collectionViewCell = (TableViewCellWithCollectionView *)cell;
[collectionViewCell.collectionView reloadData];
cellReloaded = YES;

CGRect headerFrame = [self.recentsTableView rectForHeaderInSection:section];
UIView *headerView = [self.recentsTableView headerViewForSection:section];
UIView *updatedHeaderView = [self.dataSource viewForHeaderInSection:section withFrame:headerFrame inTableView:self.recentsTableView];
if ([headerView isKindOfClass:SectionHeaderView.class]
&& [updatedHeaderView isKindOfClass:SectionHeaderView.class])
{
SectionHeaderView *sectionHeaderView = (SectionHeaderView *)headerView;
SectionHeaderView *updatedSectionHeaderView = (SectionHeaderView *)updatedHeaderView;
sectionHeaderView.headerLabel = updatedSectionHeaderView.headerLabel;
sectionHeaderView.accessoryView = updatedSectionHeaderView.accessoryView;
}
}
}
}
Expand Down Expand Up @@ -1433,6 +1503,22 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView
});

[super scrollViewDidScroll:scrollView];

// Tchap: Disable fake search bar
// if (scrollView == self.recentsTableView)
// {
// if (!self.recentsSearchBar.isHidden)
// {
// if (!self.recentsSearchBar.text.length && (scrollView.contentOffset.y + scrollView.adjustedContentInset.top > self.recentsSearchBar.frame.size.height))
// {
// // Hide the search bar
// [self hideSearchBar:YES];
//
// // Refresh display
// [self refreshRecentsTable];
// }
// }
// }
}

#pragma mark - Table view scrolling
Expand Down Expand Up @@ -1504,6 +1590,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
Expand Down Expand Up @@ -1722,4 +1874,40 @@ - (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];
[self.recentsSearchBar becomeFirstResponder];
} 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
10 changes: 8 additions & 2 deletions Riot/Modules/TabBar/TabBarCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -257,7 +257,8 @@ final class TabBarCoordinator: NSObject, TabBarCoordinatorType {
let roomsViewController: RoomsViewController = RoomsViewController.instantiate()
roomsViewController.roomsViewDelegate = self
roomsViewController.tabBarItem.tag = Int(TABBAR_ROOMS_INDEX)
roomsViewController.accessibilityLabel = VectorL10n.titleRooms
// Tchap: Update accessibility label name to `Conversations`
roomsViewController.accessibilityLabel = TchapL10n.conversationsTabTitle
return roomsViewController
}

Expand Down Expand Up @@ -362,6 +363,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)
Expand Down
1 change: 1 addition & 0 deletions changelog.d/487.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Rooms list] Restore the room search

0 comments on commit feb3238

Please sign in to comment.