2016-10-05 07:36:52 +00:00
|
|
|
/*
|
|
|
|
Copyright 2016 OpenMarket Ltd
|
2017-03-08 15:14:41 +00:00
|
|
|
Copyright 2017 Vector Creations Ltd
|
2016-10-05 07:36:52 +00:00
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import "RoomFilesSearchViewController.h"
|
|
|
|
|
|
|
|
#import "RoomSearchViewController.h"
|
|
|
|
|
2017-03-09 10:50:12 +00:00
|
|
|
#import "UIViewController+RiotSearch.h"
|
2016-10-05 07:36:52 +00:00
|
|
|
|
|
|
|
#import "FilesSearchCellData.h"
|
|
|
|
#import "FilesSearchTableViewCell.h"
|
|
|
|
|
2019-01-10 15:35:34 +00:00
|
|
|
#import "Riot-Swift.h"
|
2016-10-05 07:36:52 +00:00
|
|
|
|
|
|
|
@interface RoomFilesSearchViewController ()
|
|
|
|
{
|
|
|
|
// Observe kAppDelegateDidTapStatusBarNotification to handle tap on clock status bar.
|
|
|
|
id kAppDelegateDidTapStatusBarNotificationObserver;
|
2017-07-21 09:28:17 +00:00
|
|
|
|
2019-01-11 09:32:56 +00:00
|
|
|
// Observe kThemeServiceDidChangeThemeNotification to handle user interface theme change.
|
|
|
|
id kThemeServiceDidChangeThemeNotificationObserver;
|
2016-10-05 07:36:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RoomFilesSearchViewController
|
|
|
|
|
2017-01-03 13:40:23 +00:00
|
|
|
- (void)finalizeInit
|
2016-10-05 07:36:52 +00:00
|
|
|
{
|
2017-01-03 13:40:23 +00:00
|
|
|
[super finalizeInit];
|
2016-10-05 07:36:52 +00:00
|
|
|
|
|
|
|
// Setup `MXKViewControllerHandling` properties
|
|
|
|
self.enableBarTintColorStatusChange = NO;
|
|
|
|
self.rageShakeManager = [RageShakeManager sharedManager];
|
2017-01-03 13:40:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidLoad
|
|
|
|
{
|
|
|
|
[super viewDidLoad];
|
2016-10-05 07:36:52 +00:00
|
|
|
|
|
|
|
// Hide line separators of empty cells
|
|
|
|
self.searchTableView.tableFooterView = [[UIView alloc] init];
|
|
|
|
|
|
|
|
// Register cell class used to display the files search result
|
|
|
|
[self.searchTableView registerClass:FilesSearchTableViewCell.class forCellReuseIdentifier:FilesSearchTableViewCell.defaultReuseIdentifier];
|
|
|
|
|
|
|
|
self.searchTableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
|
2017-07-21 09:28:17 +00:00
|
|
|
|
|
|
|
// Observe user interface theme change.
|
2019-01-11 09:32:56 +00:00
|
|
|
kThemeServiceDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kThemeServiceDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
|
2017-07-21 09:28:17 +00:00
|
|
|
|
|
|
|
[self userInterfaceThemeDidChange];
|
|
|
|
|
|
|
|
}];
|
|
|
|
[self userInterfaceThemeDidChange];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)userInterfaceThemeDidChange
|
|
|
|
{
|
2019-01-11 10:45:27 +00:00
|
|
|
[ThemeService.shared.theme applyStyleOnNavigationBar:self.navigationController.navigationBar];
|
2018-11-29 16:31:41 +00:00
|
|
|
|
2019-01-11 10:45:27 +00:00
|
|
|
self.activityIndicator.backgroundColor = ThemeService.shared.theme.overlayBackgroundColor;
|
2017-08-11 14:56:09 +00:00
|
|
|
|
|
|
|
// Check the table view style to select its bg color.
|
2019-01-11 10:45:27 +00:00
|
|
|
self.searchTableView.backgroundColor = ((self.searchTableView.style == UITableViewStylePlain) ? ThemeService.shared.theme.backgroundColor : ThemeService.shared.theme.headerBackgroundColor);
|
2017-08-11 14:56:09 +00:00
|
|
|
self.view.backgroundColor = self.searchTableView.backgroundColor;
|
2019-02-18 11:53:13 +00:00
|
|
|
self.searchTableView.separatorColor = ThemeService.shared.theme.lineBreakColor;
|
2017-08-11 14:56:09 +00:00
|
|
|
|
2019-01-11 10:45:27 +00:00
|
|
|
self.noResultsLabel.textColor = ThemeService.shared.theme.backgroundColor;
|
2017-08-11 14:56:09 +00:00
|
|
|
|
|
|
|
if (self.searchTableView.dataSource)
|
|
|
|
{
|
|
|
|
[self.searchTableView reloadData];
|
|
|
|
}
|
2020-04-08 10:58:12 +00:00
|
|
|
|
|
|
|
[self setNeedsStatusBarAppearanceUpdate];
|
2017-08-11 14:56:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (UIStatusBarStyle)preferredStatusBarStyle
|
|
|
|
{
|
2019-01-11 10:45:27 +00:00
|
|
|
return ThemeService.shared.theme.statusBarStyle;
|
2017-07-21 09:28:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)destroy
|
|
|
|
{
|
|
|
|
[super destroy];
|
|
|
|
|
2019-01-11 09:32:56 +00:00
|
|
|
if (kThemeServiceDidChangeThemeNotificationObserver)
|
2017-07-21 09:28:17 +00:00
|
|
|
{
|
2019-01-11 09:32:56 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:kThemeServiceDidChangeThemeNotificationObserver];
|
|
|
|
kThemeServiceDidChangeThemeNotificationObserver = nil;
|
2017-07-21 09:28:17 +00:00
|
|
|
}
|
2016-10-05 07:36:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewWillAppear:(BOOL)animated
|
|
|
|
{
|
|
|
|
[super viewWillAppear:animated];
|
2017-12-22 12:19:40 +00:00
|
|
|
|
|
|
|
// Screen tracking
|
2018-06-27 07:55:06 +00:00
|
|
|
[[Analytics sharedInstance] trackScreen:@"RoomFilesSearch"];
|
2016-10-05 07:36:52 +00:00
|
|
|
|
|
|
|
// Observe kAppDelegateDidTapStatusBarNotificationObserver.
|
|
|
|
kAppDelegateDidTapStatusBarNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kAppDelegateDidTapStatusBarNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
|
|
|
|
|
2017-09-27 07:26:34 +00:00
|
|
|
[self.searchTableView setContentOffset:CGPointMake(-self.searchTableView.mxk_adjustedContentInset.left, -self.searchTableView.mxk_adjustedContentInset.top) animated:YES];
|
2016-10-05 07:36:52 +00:00
|
|
|
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewWillDisappear:(BOOL)animated
|
|
|
|
{
|
|
|
|
[super viewWillDisappear:animated];
|
|
|
|
|
|
|
|
if (kAppDelegateDidTapStatusBarNotificationObserver)
|
|
|
|
{
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:kAppDelegateDidTapStatusBarNotificationObserver];
|
|
|
|
kAppDelegateDidTapStatusBarNotificationObserver = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - MXKDataSourceDelegate
|
|
|
|
|
|
|
|
- (Class<MXKCellRendering>)cellViewClassForCellData:(MXKCellData*)cellData
|
|
|
|
{
|
|
|
|
return FilesSearchTableViewCell.class;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)cellReuseIdentifierForCellData:(MXKCellData*)cellData
|
|
|
|
{
|
|
|
|
return FilesSearchTableViewCell.defaultReuseIdentifier;
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Override UITableView delegate
|
|
|
|
|
2017-08-11 14:56:09 +00:00
|
|
|
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;
|
|
|
|
{
|
2019-01-11 10:45:27 +00:00
|
|
|
cell.backgroundColor = ThemeService.shared.theme.backgroundColor;
|
2017-08-11 14:56:09 +00:00
|
|
|
|
|
|
|
// Update the selected background view
|
2019-01-11 10:45:27 +00:00
|
|
|
if (ThemeService.shared.theme.selectedBackgroundColor)
|
2017-08-11 14:56:09 +00:00
|
|
|
{
|
|
|
|
cell.selectedBackgroundView = [[UIView alloc] init];
|
2019-01-11 10:45:27 +00:00
|
|
|
cell.selectedBackgroundView.backgroundColor = ThemeService.shared.theme.selectedBackgroundColor;
|
2017-08-11 14:56:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (tableView.style == UITableViewStylePlain)
|
|
|
|
{
|
|
|
|
cell.selectedBackgroundView = nil;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cell.selectedBackgroundView.backgroundColor = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-05 07:36:52 +00:00
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
|
|
|
// Data in the cells are actually Vector RoomBubbleCellData
|
|
|
|
FilesSearchCellData *cellData = (FilesSearchCellData*)[self.dataSource cellDataAtIndex:indexPath.row];
|
|
|
|
_selectedEvent = cellData.searchResult.result;
|
|
|
|
|
|
|
|
// Hide the keyboard handled by the search text input which belongs to RoomSearchViewController
|
|
|
|
[((RoomSearchViewController*)self.parentViewController).searchBar resignFirstResponder];
|
|
|
|
|
|
|
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
|
|
|
|
|
|
|
// Make the RoomSearchViewController (that contains this VC) open the RoomViewController
|
|
|
|
[self.parentViewController performSegueWithIdentifier:@"showTimeline" sender:self];
|
|
|
|
|
|
|
|
// Reset the selected event. RoomSearchViewController got it when here
|
|
|
|
_selectedEvent = nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|