mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-30 16:22:39 +00:00
8a744fc9e8
And move all Google Analytics code to AppDelegate.m
223 lines
7.3 KiB
Objective-C
223 lines
7.3 KiB
Objective-C
/*
|
|
Copyright 2016 OpenMarket Ltd
|
|
Copyright 2017 Vector Creations Ltd
|
|
|
|
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 "RoomMessagesSearchViewController.h"
|
|
|
|
#import "RoomSearchViewController.h"
|
|
|
|
#import "UIViewController+RiotSearch.h"
|
|
|
|
// Use RoomViewController cells to display results
|
|
#import "RoomBubbleCellData.h"
|
|
#import "RoomIncomingAttachmentBubbleCell.h"
|
|
#import "RoomIncomingTextMsgBubbleCell.h"
|
|
|
|
#import "AppDelegate.h"
|
|
|
|
@interface RoomMessagesSearchViewController ()
|
|
{
|
|
// Observe kAppDelegateDidTapStatusBarNotification to handle tap on clock status bar.
|
|
id kAppDelegateDidTapStatusBarNotificationObserver;
|
|
|
|
// Observe kRiotDesignValuesDidChangeThemeNotification to handle user interface theme change.
|
|
id kRiotDesignValuesDidChangeThemeNotificationObserver;
|
|
}
|
|
|
|
@end
|
|
|
|
@implementation RoomMessagesSearchViewController
|
|
|
|
- (void)finalizeInit
|
|
{
|
|
[super finalizeInit];
|
|
|
|
// Setup `MXKViewControllerHandling` properties
|
|
self.enableBarTintColorStatusChange = NO;
|
|
self.rageShakeManager = [RageShakeManager sharedManager];
|
|
}
|
|
|
|
- (void)viewDidLoad
|
|
{
|
|
[super viewDidLoad];
|
|
|
|
// Hide line separators of empty cells
|
|
self.searchTableView.tableFooterView = [[UIView alloc] init];
|
|
|
|
// Reuse cells from the RoomViewController to display results
|
|
[self.searchTableView registerClass:RoomIncomingTextMsgBubbleCell.class forCellReuseIdentifier:RoomIncomingTextMsgBubbleCell.defaultReuseIdentifier];
|
|
[self.searchTableView registerClass:RoomIncomingAttachmentBubbleCell.class forCellReuseIdentifier:RoomIncomingAttachmentBubbleCell.defaultReuseIdentifier];
|
|
|
|
// Observe user interface theme change.
|
|
kRiotDesignValuesDidChangeThemeNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kRiotDesignValuesDidChangeThemeNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
|
|
|
|
[self userInterfaceThemeDidChange];
|
|
|
|
}];
|
|
[self userInterfaceThemeDidChange];
|
|
}
|
|
|
|
- (void)userInterfaceThemeDidChange
|
|
{
|
|
self.defaultBarTintColor = kRiotSecondaryBgColor;
|
|
self.barTitleColor = kRiotPrimaryTextColor;
|
|
self.activityIndicator.backgroundColor = kRiotOverlayColor;
|
|
|
|
// Check the table view style to select its bg color.
|
|
self.searchTableView.backgroundColor = ((self.searchTableView.style == UITableViewStylePlain) ? kRiotPrimaryBgColor : kRiotSecondaryBgColor);
|
|
self.view.backgroundColor = self.searchTableView.backgroundColor;
|
|
|
|
self.noResultsLabel.textColor = kRiotPrimaryBgColor;
|
|
|
|
if (self.searchTableView.dataSource)
|
|
{
|
|
[self.searchTableView reloadData];
|
|
}
|
|
}
|
|
|
|
- (UIStatusBarStyle)preferredStatusBarStyle
|
|
{
|
|
return kRiotDesignStatusBarStyle;
|
|
}
|
|
|
|
- (void)destroy
|
|
{
|
|
[super destroy];
|
|
|
|
if (kRiotDesignValuesDidChangeThemeNotificationObserver)
|
|
{
|
|
[[NSNotificationCenter defaultCenter] removeObserver:kRiotDesignValuesDidChangeThemeNotificationObserver];
|
|
kRiotDesignValuesDidChangeThemeNotificationObserver = nil;
|
|
}
|
|
}
|
|
|
|
- (void)viewWillAppear:(BOOL)animated
|
|
{
|
|
[super viewWillAppear:animated];
|
|
|
|
// Screen tracking
|
|
[[AppDelegate theDelegate] trackScreen:@"RoomMessagesSearch"];
|
|
|
|
// Observe kAppDelegateDidTapStatusBarNotificationObserver.
|
|
kAppDelegateDidTapStatusBarNotificationObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kAppDelegateDidTapStatusBarNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) {
|
|
|
|
[self.searchTableView setContentOffset:CGPointMake(-self.searchTableView.mxk_adjustedContentInset.left, -self.searchTableView.mxk_adjustedContentInset.top) animated:YES];
|
|
|
|
}];
|
|
}
|
|
|
|
- (void)viewWillDisappear:(BOOL)animated
|
|
{
|
|
[super viewWillDisappear:animated];
|
|
|
|
if (kAppDelegateDidTapStatusBarNotificationObserver)
|
|
{
|
|
[[NSNotificationCenter defaultCenter] removeObserver:kAppDelegateDidTapStatusBarNotificationObserver];
|
|
kAppDelegateDidTapStatusBarNotificationObserver = nil;
|
|
}
|
|
}
|
|
|
|
#pragma mark - MXKDataSourceDelegate
|
|
|
|
- (Class<MXKCellRendering>)cellViewClassForCellData:(MXKCellData*)cellData
|
|
{
|
|
Class cellViewClass = nil;
|
|
|
|
// Sanity check
|
|
if ([cellData conformsToProtocol:@protocol(MXKRoomBubbleCellDataStoring)])
|
|
{
|
|
id<MXKRoomBubbleCellDataStoring> bubbleData = (id<MXKRoomBubbleCellDataStoring>)cellData;
|
|
|
|
// Select the suitable table view cell class
|
|
if (bubbleData.isAttachmentWithThumbnail)
|
|
{
|
|
cellViewClass = RoomIncomingAttachmentBubbleCell.class;
|
|
}
|
|
else
|
|
{
|
|
cellViewClass = RoomIncomingTextMsgBubbleCell.class;
|
|
}
|
|
}
|
|
|
|
return cellViewClass;
|
|
}
|
|
|
|
- (NSString *)cellReuseIdentifierForCellData:(MXKCellData*)cellData
|
|
{
|
|
Class class = [self cellViewClassForCellData:cellData];
|
|
|
|
if ([class respondsToSelector:@selector(defaultReuseIdentifier)])
|
|
{
|
|
return [class defaultReuseIdentifier];
|
|
}
|
|
|
|
return nil;
|
|
}
|
|
|
|
|
|
#pragma mark - Override UITableView delegate
|
|
|
|
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath;
|
|
{
|
|
cell.backgroundColor = kRiotPrimaryBgColor;
|
|
|
|
// Update the selected background view
|
|
if (kRiotSelectedBgColor)
|
|
{
|
|
cell.selectedBackgroundView = [[UIView alloc] init];
|
|
cell.selectedBackgroundView.backgroundColor = kRiotSelectedBgColor;
|
|
}
|
|
else
|
|
{
|
|
if (tableView.style == UITableViewStylePlain)
|
|
{
|
|
cell.selectedBackgroundView = nil;
|
|
}
|
|
else
|
|
{
|
|
cell.selectedBackgroundView.backgroundColor = nil;
|
|
}
|
|
}
|
|
}
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
// `MXKRoomBubbleTableViewCell` cells displayed by the `RoomViewController`
|
|
// do not have line separators.
|
|
// The +1 here is for the line separator which is displayed by `RoomSearchViewController`.
|
|
return [super tableView:tableView heightForRowAtIndexPath:indexPath] + 1;
|
|
}
|
|
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
|
{
|
|
// Data in the cells are actually Vector RoomBubbleCellData
|
|
RoomBubbleCellData *cellData = (RoomBubbleCellData*)[self.dataSource cellDataAtIndex:indexPath.row];
|
|
_selectedEvent = cellData.bubbleComponents[0].event;
|
|
|
|
// 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
|