2014-10-02 15:02:47 +00:00
|
|
|
/*
|
2015-04-03 13:02:16 +00:00
|
|
|
Copyright 2015 OpenMarket Ltd
|
2014-10-02 15:02:47 +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.
|
|
|
|
*/
|
|
|
|
|
2014-10-03 17:26:39 +00:00
|
|
|
#import "RecentsViewController.h"
|
|
|
|
#import "RoomViewController.h"
|
2014-10-02 15:02:47 +00:00
|
|
|
|
2014-10-09 17:06:30 +00:00
|
|
|
#import "AppDelegate.h"
|
|
|
|
|
2015-04-03 13:02:16 +00:00
|
|
|
#import "RageShakeManager.h"
|
|
|
|
|
2015-08-07 08:42:47 +00:00
|
|
|
#import "NSBundle+MatrixKit.h"
|
|
|
|
|
2015-08-12 07:32:45 +00:00
|
|
|
#import "RecentListDataSource.h"
|
|
|
|
|
2015-06-19 22:45:27 +00:00
|
|
|
@interface RecentsViewController ()
|
|
|
|
{
|
2015-05-22 20:32:05 +00:00
|
|
|
// Recents refresh handling
|
2015-04-03 13:02:16 +00:00
|
|
|
BOOL shouldScrollToTopOnRefresh;
|
2014-11-21 15:01:35 +00:00
|
|
|
|
2015-05-21 17:06:34 +00:00
|
|
|
// Selected room description
|
|
|
|
NSString *selectedRoomId;
|
|
|
|
MXSession *selectedRoomSession;
|
|
|
|
|
2015-02-13 13:07:03 +00:00
|
|
|
// Keep reference on the current room view controller to release it correctly
|
2014-11-21 13:26:34 +00:00
|
|
|
RoomViewController *currentRoomViewController;
|
2015-02-13 13:07:03 +00:00
|
|
|
|
|
|
|
// Keep the selected cell index to handle correctly split view controller display in landscape mode
|
2015-05-21 11:12:21 +00:00
|
|
|
NSIndexPath *currentSelectedCellIndexPath;
|
2015-06-19 22:45:27 +00:00
|
|
|
|
2015-06-10 14:02:48 +00:00
|
|
|
// "Mark all as read" option
|
|
|
|
UITapGestureRecognizer *navigationBarTapGesture;
|
|
|
|
MXKAlert *markAllAsReadAlert;
|
2014-10-15 14:13:35 +00:00
|
|
|
}
|
2014-10-02 15:02:47 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
2014-10-03 17:26:39 +00:00
|
|
|
@implementation RecentsViewController
|
2014-10-02 15:02:47 +00:00
|
|
|
|
2015-06-19 22:45:27 +00:00
|
|
|
- (void)awakeFromNib
|
|
|
|
{
|
2014-10-02 15:02:47 +00:00
|
|
|
[super awakeFromNib];
|
2015-06-19 22:45:27 +00:00
|
|
|
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
|
|
|
|
{
|
2014-10-02 15:02:47 +00:00
|
|
|
self.preferredContentSize = CGSizeMake(320.0, 600.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-19 22:45:27 +00:00
|
|
|
- (void)viewDidLoad
|
|
|
|
{
|
2014-10-02 15:02:47 +00:00
|
|
|
[super viewDidLoad];
|
|
|
|
// Do any additional setup after loading the view, typically from a nib.
|
|
|
|
self.navigationItem.leftBarButtonItem = self.editButtonItem;
|
2015-06-19 22:45:27 +00:00
|
|
|
|
2015-06-10 14:02:48 +00:00
|
|
|
// Prepare tap gesture on title bar
|
|
|
|
navigationBarTapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onNavigationBarTap:)];
|
|
|
|
[navigationBarTapGesture setNumberOfTouchesRequired:1];
|
|
|
|
[navigationBarTapGesture setNumberOfTapsRequired:1];
|
|
|
|
[navigationBarTapGesture setDelegate:self];
|
2015-06-10 13:46:59 +00:00
|
|
|
|
2014-10-15 14:13:35 +00:00
|
|
|
// Initialisation
|
2015-05-21 11:12:21 +00:00
|
|
|
currentSelectedCellIndexPath = nil;
|
2014-11-21 15:01:35 +00:00
|
|
|
|
2015-04-03 13:02:16 +00:00
|
|
|
// Setup `MXKRecentListViewController` properties
|
|
|
|
self.rageShakeManager = [RageShakeManager sharedManager];
|
2014-12-11 13:41:02 +00:00
|
|
|
|
2015-04-03 13:02:16 +00:00
|
|
|
// The view controller handles itself the selected recent
|
|
|
|
self.delegate = self;
|
2014-10-09 17:06:30 +00:00
|
|
|
}
|
|
|
|
|
2015-06-19 22:45:27 +00:00
|
|
|
- (void)dealloc
|
|
|
|
{
|
2015-08-10 09:24:44 +00:00
|
|
|
[self closeSelectedRoom];
|
2015-04-03 13:02:16 +00:00
|
|
|
}
|
|
|
|
|
2015-06-10 13:46:59 +00:00
|
|
|
- (void)destroy
|
|
|
|
{
|
2015-06-10 14:02:48 +00:00
|
|
|
if (markAllAsReadAlert)
|
2015-06-19 22:45:27 +00:00
|
|
|
|
2015-06-10 13:46:59 +00:00
|
|
|
{
|
2015-06-10 14:02:48 +00:00
|
|
|
[markAllAsReadAlert dismiss:NO];
|
|
|
|
markAllAsReadAlert = nil;
|
|
|
|
}
|
|
|
|
|
2015-06-19 22:45:27 +00:00
|
|
|
if (navigationBarTapGesture)
|
|
|
|
{
|
2015-06-10 14:02:48 +00:00
|
|
|
[self.navigationController.navigationBar removeGestureRecognizer:navigationBarTapGesture];
|
|
|
|
navigationBarTapGesture = nil;
|
2015-06-10 13:46:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[super destroy];
|
|
|
|
}
|
|
|
|
|
2015-06-19 22:45:27 +00:00
|
|
|
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
|
|
|
|
{
|
2015-04-03 13:02:16 +00:00
|
|
|
[super setEditing:editing animated:animated];
|
2014-11-21 15:01:35 +00:00
|
|
|
|
2015-05-22 20:32:05 +00:00
|
|
|
self.recentsTableView.editing = editing;
|
2014-10-02 15:02:47 +00:00
|
|
|
}
|
|
|
|
|
2015-06-19 22:45:27 +00:00
|
|
|
- (void)didReceiveMemoryWarning
|
|
|
|
{
|
2014-10-02 15:02:47 +00:00
|
|
|
[super didReceiveMemoryWarning];
|
|
|
|
// Dispose of any resources that can be recreated.
|
|
|
|
}
|
|
|
|
|
2015-06-19 22:45:27 +00:00
|
|
|
- (void)viewWillAppear:(BOOL)animated
|
|
|
|
{
|
2014-10-09 17:06:30 +00:00
|
|
|
[super viewWillAppear:animated];
|
|
|
|
|
2015-06-10 13:46:59 +00:00
|
|
|
[self updateNavigationBarTitle];
|
2015-02-17 15:29:52 +00:00
|
|
|
|
2015-04-29 13:27:43 +00:00
|
|
|
// Deselect the current selected row, it will be restored on viewDidAppear (if any)
|
2015-05-22 20:32:05 +00:00
|
|
|
NSIndexPath *indexPath = [self.recentsTableView indexPathForSelectedRow];
|
2015-06-19 22:45:27 +00:00
|
|
|
if (indexPath)
|
|
|
|
{
|
2015-05-22 20:32:05 +00:00
|
|
|
[self.recentsTableView deselectRowAtIndexPath:indexPath animated:NO];
|
2015-02-17 15:29:52 +00:00
|
|
|
}
|
2015-06-10 14:02:48 +00:00
|
|
|
|
2015-08-12 07:32:45 +00:00
|
|
|
RecentListDataSource *recentListDataSource = (RecentListDataSource*)self.dataSource;
|
|
|
|
if (recentListDataSource)
|
|
|
|
{
|
|
|
|
[self startActivityIndicator];
|
|
|
|
[recentListDataSource refreshPublicRooms:nil onComplete:^{
|
|
|
|
[self stopActivityIndicator];
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
2015-06-10 14:02:48 +00:00
|
|
|
[self.navigationController.navigationBar addGestureRecognizer:navigationBarTapGesture];
|
2014-10-09 17:06:30 +00:00
|
|
|
}
|
|
|
|
|
2015-06-19 22:45:27 +00:00
|
|
|
- (void)viewWillDisappear:(BOOL)animated
|
|
|
|
{
|
2014-10-09 17:06:30 +00:00
|
|
|
[super viewWillDisappear:animated];
|
2014-10-15 14:13:35 +00:00
|
|
|
|
|
|
|
// Leave potential editing mode
|
|
|
|
[self setEditing:NO];
|
|
|
|
|
2015-05-21 17:06:34 +00:00
|
|
|
selectedRoomId = nil;
|
|
|
|
selectedRoomSession = nil;
|
2015-06-10 13:46:59 +00:00
|
|
|
|
2015-06-10 14:02:48 +00:00
|
|
|
if (markAllAsReadAlert)
|
2015-06-10 13:46:59 +00:00
|
|
|
{
|
2015-06-10 14:02:48 +00:00
|
|
|
[markAllAsReadAlert dismiss:NO];
|
|
|
|
markAllAsReadAlert = nil;
|
2015-06-10 13:46:59 +00:00
|
|
|
}
|
2015-06-10 14:02:48 +00:00
|
|
|
|
|
|
|
[self.navigationController.navigationBar removeGestureRecognizer:navigationBarTapGesture];
|
2014-10-09 17:06:30 +00:00
|
|
|
}
|
|
|
|
|
2015-06-19 22:45:27 +00:00
|
|
|
- (void)viewDidAppear:(BOOL)animated
|
|
|
|
{
|
2014-12-09 09:39:56 +00:00
|
|
|
[super viewDidAppear:animated];
|
|
|
|
|
2015-02-17 15:29:52 +00:00
|
|
|
// Release the current selected room (if any) except if the Room ViewController is still visible (see splitViewController.isCollapsed condition)
|
2015-06-19 22:45:27 +00:00
|
|
|
if (!self.splitViewController || self.splitViewController.isCollapsed)
|
|
|
|
{
|
2015-05-21 17:06:34 +00:00
|
|
|
// Release the current selected room (if any).
|
|
|
|
[self closeSelectedRoom];
|
2015-06-19 22:45:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-02-17 15:29:52 +00:00
|
|
|
// In case of split view controller where the primary and secondary view controllers are displayed side-by-side onscreen,
|
|
|
|
// the selected room (if any) is highlighted.
|
|
|
|
[self refreshCurrentSelectedCell:YES];
|
2014-12-09 09:39:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-12 07:32:45 +00:00
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
|
|
|
|
{
|
|
|
|
return 35;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
|
|
|
// Check whether the selected row is a public room or not
|
|
|
|
RecentListDataSource *recentListDataSource = (RecentListDataSource*)self.dataSource;
|
|
|
|
if (recentListDataSource && recentListDataSource.publicRoomsFirstSection != -1 && indexPath.section >= recentListDataSource.publicRoomsFirstSection)
|
|
|
|
{
|
|
|
|
MXPublicRoom *publicRoom = [recentListDataSource publicRoomAtIndexPath:indexPath];
|
|
|
|
if (publicRoom)
|
|
|
|
{
|
|
|
|
// Handle multi-sessions here
|
|
|
|
[[AppDelegate theDelegate] selectMatrixAccount:^(MXKAccount *selectedAccount) {
|
|
|
|
// Check whether the user has already joined the selected public room
|
|
|
|
if ([selectedAccount.mxSession roomWithRoomId:publicRoom.roomId])
|
|
|
|
{
|
|
|
|
// Open selected room
|
|
|
|
[[AppDelegate theDelegate].masterTabBarController showRoom:publicRoom.roomId withMatrixSession:selectedAccount.mxSession];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Join the selected room
|
|
|
|
UIActivityIndicatorView *loadingWheel = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
|
|
|
|
UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
|
|
|
|
if (selectedCell)
|
|
|
|
{
|
|
|
|
CGPoint center = CGPointMake(selectedCell.frame.size.width / 2, selectedCell.frame.size.height / 2);
|
|
|
|
loadingWheel.center = center;
|
|
|
|
[selectedCell addSubview:loadingWheel];
|
|
|
|
}
|
|
|
|
[loadingWheel startAnimating];
|
|
|
|
[selectedAccount.mxSession joinRoom:publicRoom.roomId success:^(MXRoom *room)
|
|
|
|
{
|
|
|
|
// Show joined room
|
|
|
|
[loadingWheel stopAnimating];
|
|
|
|
[loadingWheel removeFromSuperview];
|
|
|
|
[[AppDelegate theDelegate].masterTabBarController showRoom:publicRoom.roomId withMatrixSession:selectedAccount.mxSession];
|
|
|
|
} failure:^(NSError *error)
|
|
|
|
{
|
|
|
|
NSLog(@"[HomeVC] Failed to join public room (%@): %@", publicRoom.displayname, error);
|
|
|
|
//Alert user
|
|
|
|
[loadingWheel stopAnimating];
|
|
|
|
[loadingWheel removeFromSuperview];
|
|
|
|
[[AppDelegate theDelegate] showErrorAsAlert:error];
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Let super handle the selected row
|
|
|
|
[super tableView:tableView didSelectRowAtIndexPath:indexPath];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-15 14:13:35 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
2015-06-19 22:45:27 +00:00
|
|
|
- (void)selectRoomWithId:(NSString*)roomId inMatrixSession:(MXSession*)matrixSession
|
|
|
|
{
|
2015-05-21 17:06:34 +00:00
|
|
|
if (selectedRoomId && [selectedRoomId isEqualToString:roomId]
|
2015-06-19 22:45:27 +00:00
|
|
|
&& selectedRoomSession && selectedRoomSession == matrixSession)
|
|
|
|
{
|
2015-04-03 13:02:16 +00:00
|
|
|
// Nothing to do
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-21 17:06:34 +00:00
|
|
|
selectedRoomId = roomId;
|
|
|
|
selectedRoomSession = matrixSession;
|
|
|
|
|
2015-06-19 22:45:27 +00:00
|
|
|
if (roomId && matrixSession)
|
|
|
|
{
|
2015-04-03 13:02:16 +00:00
|
|
|
[self performSegueWithIdentifier:@"showDetails" sender:self];
|
2015-06-19 22:45:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-05-21 17:06:34 +00:00
|
|
|
[self closeSelectedRoom];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-19 22:45:27 +00:00
|
|
|
- (void)closeSelectedRoom
|
|
|
|
{
|
2015-05-21 17:06:34 +00:00
|
|
|
selectedRoomId = nil;
|
|
|
|
selectedRoomSession = nil;
|
|
|
|
|
2015-06-19 22:45:27 +00:00
|
|
|
if (currentRoomViewController)
|
|
|
|
{
|
2015-08-10 09:24:44 +00:00
|
|
|
if (currentRoomViewController.roomDataSource)
|
|
|
|
{
|
|
|
|
// Let the manager release this room data source
|
|
|
|
MXSession *mxSession = currentRoomViewController.roomDataSource.mxSession;
|
|
|
|
MXKRoomDataSourceManager *roomDataSourceManager = [MXKRoomDataSourceManager sharedManagerForMatrixSession:mxSession];
|
|
|
|
[roomDataSourceManager closeRoomDataSource:currentRoomViewController.roomDataSource forceClose:NO];
|
|
|
|
}
|
|
|
|
|
2015-04-01 09:06:48 +00:00
|
|
|
[currentRoomViewController destroy];
|
2015-01-22 16:26:51 +00:00
|
|
|
currentRoomViewController = nil;
|
2014-10-15 14:13:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-16 16:14:17 +00:00
|
|
|
#pragma mark - Internal methods
|
2014-10-15 14:13:35 +00:00
|
|
|
|
2015-06-19 22:45:27 +00:00
|
|
|
- (void)updateNavigationBarTitle
|
|
|
|
{
|
2015-08-12 07:32:45 +00:00
|
|
|
NSString *title = NSLocalizedStringFromTable(@"recents", @"Vector", nil);
|
2015-04-03 13:02:16 +00:00
|
|
|
|
2015-06-19 22:45:27 +00:00
|
|
|
if (self.dataSource.unreadCount)
|
|
|
|
{
|
2015-08-07 08:42:47 +00:00
|
|
|
title = [NSString stringWithFormat:@"%@ (%tu)", title, self.dataSource.unreadCount];
|
2014-12-22 13:19:33 +00:00
|
|
|
}
|
|
|
|
self.navigationItem.title = title;
|
2014-10-09 17:06:30 +00:00
|
|
|
}
|
|
|
|
|
2015-06-19 22:45:27 +00:00
|
|
|
- (void)scrollToTop
|
|
|
|
{
|
2015-01-23 10:01:38 +00:00
|
|
|
// stop any scrolling effect
|
|
|
|
[UIView setAnimationsEnabled:NO];
|
|
|
|
// before scrolling to the tableview top
|
2015-05-22 20:32:05 +00:00
|
|
|
self.recentsTableView.contentOffset = CGPointMake(-self.recentsTableView.contentInset.left, -self.recentsTableView.contentInset.top);
|
2015-01-23 10:01:38 +00:00
|
|
|
[UIView setAnimationsEnabled:YES];
|
|
|
|
}
|
|
|
|
|
2015-06-19 22:45:27 +00:00
|
|
|
- (void)refreshCurrentSelectedCell:(BOOL)forceVisible
|
|
|
|
{
|
2015-02-17 15:29:52 +00:00
|
|
|
// Update here the index of the current selected cell (if any) - Useful in landscape mode with split view controller.
|
2015-05-21 11:12:21 +00:00
|
|
|
currentSelectedCellIndexPath = nil;
|
2015-06-19 22:45:27 +00:00
|
|
|
if (currentRoomViewController)
|
|
|
|
{
|
2015-04-03 13:02:16 +00:00
|
|
|
// Restore the current selected room id, it is erased when view controller disappeared (see viewWillDisappear).
|
2015-06-19 22:45:27 +00:00
|
|
|
if (!selectedRoomId)
|
|
|
|
{
|
2015-05-21 17:06:34 +00:00
|
|
|
selectedRoomId = currentRoomViewController.roomDataSource.roomId;
|
2015-05-28 15:54:50 +00:00
|
|
|
selectedRoomSession = currentRoomViewController.mainSession;
|
2015-04-03 13:02:16 +00:00
|
|
|
}
|
|
|
|
|
2015-02-17 15:29:52 +00:00
|
|
|
// Look for the rank of this selected room in displayed recents
|
2015-05-21 17:06:34 +00:00
|
|
|
currentSelectedCellIndexPath = [self.dataSource cellIndexPathWithRoomId:selectedRoomId andMatrixSession:selectedRoomSession];
|
2015-02-17 15:29:52 +00:00
|
|
|
}
|
|
|
|
|
2015-06-19 22:45:27 +00:00
|
|
|
if (currentSelectedCellIndexPath)
|
|
|
|
{
|
2015-02-17 15:29:52 +00:00
|
|
|
// Select the right row
|
2015-05-22 20:32:05 +00:00
|
|
|
[self.recentsTableView selectRowAtIndexPath:currentSelectedCellIndexPath animated:YES scrollPosition:UITableViewScrollPositionNone];
|
2015-02-17 15:29:52 +00:00
|
|
|
|
2015-06-19 22:45:27 +00:00
|
|
|
if (forceVisible)
|
|
|
|
{
|
2015-02-17 15:29:52 +00:00
|
|
|
// Scroll table view to make the selected row appear at second position
|
2015-05-21 11:12:21 +00:00
|
|
|
NSInteger topCellIndexPathRow = currentSelectedCellIndexPath.row ? currentSelectedCellIndexPath.row - 1: currentSelectedCellIndexPath.row;
|
|
|
|
NSIndexPath* indexPath = [NSIndexPath indexPathForRow:topCellIndexPathRow inSection:currentSelectedCellIndexPath.section];
|
2015-05-22 20:32:05 +00:00
|
|
|
[self.recentsTableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
|
2015-02-17 15:29:52 +00:00
|
|
|
}
|
2015-06-19 22:45:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-05-22 20:32:05 +00:00
|
|
|
NSIndexPath *indexPath = [self.recentsTableView indexPathForSelectedRow];
|
2015-06-19 22:45:27 +00:00
|
|
|
if (indexPath)
|
|
|
|
{
|
2015-05-22 20:32:05 +00:00
|
|
|
[self.recentsTableView deselectRowAtIndexPath:indexPath animated:NO];
|
2015-02-17 15:29:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-10 13:46:59 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
- (void)onNavigationBarTap:(id)sender
|
|
|
|
{
|
|
|
|
if (self.dataSource.unreadCount)
|
2015-06-19 22:45:27 +00:00
|
|
|
|
2015-06-10 13:46:59 +00:00
|
|
|
{
|
|
|
|
__weak typeof(self) weakSelf = self;
|
|
|
|
|
2015-08-12 07:32:45 +00:00
|
|
|
markAllAsReadAlert = [[MXKAlert alloc] initWithTitle:NSLocalizedStringFromTable(@"mark_all_as_read_prompt", @"Vector", nil) message:nil style:MXKAlertStyleAlert];
|
2015-06-10 13:46:59 +00:00
|
|
|
|
2015-08-07 08:42:47 +00:00
|
|
|
markAllAsReadAlert.cancelButtonIndex = [markAllAsReadAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"no"] style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert)
|
2015-06-19 22:45:27 +00:00
|
|
|
{
|
|
|
|
typeof(self) strongSelf = weakSelf;
|
|
|
|
strongSelf->markAllAsReadAlert = nil;
|
|
|
|
}];
|
2015-06-10 13:46:59 +00:00
|
|
|
|
2015-08-07 08:42:47 +00:00
|
|
|
[markAllAsReadAlert addActionWithTitle:[NSBundle mxk_localizedStringForKey:@"yes"] style:MXKAlertActionStyleDefault handler:^(MXKAlert *alert)
|
2015-06-19 22:45:27 +00:00
|
|
|
{
|
|
|
|
typeof(self) strongSelf = weakSelf;
|
|
|
|
|
|
|
|
strongSelf->markAllAsReadAlert = nil;
|
|
|
|
|
|
|
|
[strongSelf.dataSource markAllAsRead];
|
|
|
|
[strongSelf updateNavigationBarTitle];
|
|
|
|
}];
|
2015-06-10 13:46:59 +00:00
|
|
|
|
2015-06-10 14:02:48 +00:00
|
|
|
[markAllAsReadAlert showInViewController:self];
|
2015-06-10 13:46:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-02 15:02:47 +00:00
|
|
|
#pragma mark - Segues
|
|
|
|
|
2015-06-19 22:45:27 +00:00
|
|
|
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
|
|
|
|
{
|
2015-08-14 07:20:03 +00:00
|
|
|
// Keep ref on destinationViewController
|
|
|
|
[super prepareForSegue:segue sender:sender];
|
|
|
|
|
2015-06-19 22:45:27 +00:00
|
|
|
if ([[segue identifier] isEqualToString:@"showDetails"])
|
|
|
|
{
|
2014-10-02 15:02:47 +00:00
|
|
|
UIViewController *controller;
|
2015-06-19 22:45:27 +00:00
|
|
|
if ([[segue destinationViewController] isKindOfClass:[UINavigationController class]])
|
|
|
|
{
|
2014-10-02 15:02:47 +00:00
|
|
|
controller = [[segue destinationViewController] topViewController];
|
2015-06-19 22:45:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-10-02 15:02:47 +00:00
|
|
|
controller = [segue destinationViewController];
|
|
|
|
}
|
|
|
|
|
2015-06-19 22:45:27 +00:00
|
|
|
if ([controller isKindOfClass:[RoomViewController class]])
|
|
|
|
{
|
2015-08-10 09:24:44 +00:00
|
|
|
// Release existing Room view controller (if any)
|
2015-06-19 22:45:27 +00:00
|
|
|
if (currentRoomViewController)
|
|
|
|
{
|
2015-08-10 09:24:44 +00:00
|
|
|
if (currentRoomViewController.roomDataSource)
|
|
|
|
{
|
|
|
|
// Let the manager release this room data source
|
|
|
|
MXSession *mxSession = currentRoomViewController.roomDataSource.mxSession;
|
|
|
|
MXKRoomDataSourceManager *roomDataSourceManager = [MXKRoomDataSourceManager sharedManagerForMatrixSession:mxSession];
|
|
|
|
[roomDataSourceManager closeRoomDataSource:currentRoomViewController.roomDataSource forceClose:NO];
|
|
|
|
}
|
|
|
|
|
2015-04-01 09:06:48 +00:00
|
|
|
[currentRoomViewController destroy];
|
2014-12-09 09:39:56 +00:00
|
|
|
currentRoomViewController = nil;
|
|
|
|
}
|
2015-03-31 13:09:17 +00:00
|
|
|
|
2014-11-21 13:26:34 +00:00
|
|
|
currentRoomViewController = (RoomViewController *)controller;
|
2015-06-19 22:45:27 +00:00
|
|
|
|
2015-05-21 17:06:34 +00:00
|
|
|
MXKRoomDataSourceManager *roomDataSourceManager = [MXKRoomDataSourceManager sharedManagerForMatrixSession:selectedRoomSession];
|
|
|
|
MXKRoomDataSource *roomDataSource = [roomDataSourceManager roomDataSourceForRoom:selectedRoomId create:YES];
|
2015-03-31 13:09:17 +00:00
|
|
|
[currentRoomViewController displayRoom:roomDataSource];
|
2014-10-02 15:02:47 +00:00
|
|
|
}
|
|
|
|
|
2015-06-10 13:46:59 +00:00
|
|
|
[self updateNavigationBarTitle];
|
2014-12-05 16:48:06 +00:00
|
|
|
|
2015-06-19 22:45:27 +00:00
|
|
|
if (self.splitViewController)
|
|
|
|
{
|
2015-02-17 15:29:52 +00:00
|
|
|
// Refresh selected cell without scrolling the selected cell (We suppose it's visible here)
|
|
|
|
[self refreshCurrentSelectedCell:NO];
|
|
|
|
|
2014-12-16 17:30:49 +00:00
|
|
|
// IOS >= 8
|
2015-06-19 22:45:27 +00:00
|
|
|
if ([self.splitViewController respondsToSelector:@selector(displayModeButtonItem)])
|
|
|
|
{
|
2014-12-16 17:30:49 +00:00
|
|
|
controller.navigationItem.leftBarButtonItem = self.splitViewController.displayModeButtonItem;
|
|
|
|
}
|
2015-06-19 22:45:27 +00:00
|
|
|
|
2014-12-16 17:30:49 +00:00
|
|
|
//
|
2014-12-05 16:48:06 +00:00
|
|
|
controller.navigationItem.leftItemsSupplementBackButton = YES;
|
|
|
|
}
|
2014-12-15 15:54:31 +00:00
|
|
|
|
|
|
|
// Hide back button title
|
2015-08-14 07:20:03 +00:00
|
|
|
self.navigationItem.backBarButtonItem =[[UIBarButtonItem alloc] initWithTitle:NSLocalizedStringFromTable(@"back", @"Vector", nil) style:UIBarButtonItemStylePlain target:nil action:nil];
|
2014-10-02 15:02:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 13:02:16 +00:00
|
|
|
#pragma mark - MXKDataSourceDelegate
|
2015-06-19 22:45:27 +00:00
|
|
|
- (void)dataSource:(MXKDataSource *)dataSource didCellChange:(id)changes
|
|
|
|
{
|
2015-06-29 09:41:03 +00:00
|
|
|
// Update the unreadCount in the title
|
|
|
|
[self updateNavigationBarTitle];
|
|
|
|
|
|
|
|
[self.recentsTableView reloadData];
|
|
|
|
|
|
|
|
if (shouldScrollToTopOnRefresh)
|
|
|
|
{
|
|
|
|
[self scrollToTop];
|
|
|
|
shouldScrollToTopOnRefresh = NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
// In case of split view controller where the primary and secondary view controllers are displayed side-by-side onscreen,
|
|
|
|
// the selected room (if any) is updated and kept visible.
|
|
|
|
if (self.splitViewController && !self.splitViewController.isCollapsed)
|
|
|
|
{
|
|
|
|
[self refreshCurrentSelectedCell:YES];
|
|
|
|
}
|
2014-10-09 17:06:30 +00:00
|
|
|
}
|
2014-10-02 15:02:47 +00:00
|
|
|
|
2015-04-03 13:02:16 +00:00
|
|
|
#pragma mark - MXKRecentListViewControllerDelegate
|
2015-06-19 22:45:27 +00:00
|
|
|
- (void)recentListViewController:(MXKRecentListViewController *)recentListViewController didSelectRoom:(NSString *)roomId inMatrixSession:(MXSession *)matrixSession
|
|
|
|
{
|
2015-05-21 17:06:34 +00:00
|
|
|
// Open the room
|
|
|
|
[self selectRoomWithId:roomId inMatrixSession:matrixSession];
|
2014-10-02 15:02:47 +00:00
|
|
|
}
|
|
|
|
|
2015-05-22 20:32:05 +00:00
|
|
|
#pragma mark - Override UISearchBarDelegate
|
2014-12-02 14:25:00 +00:00
|
|
|
|
2015-06-19 22:45:27 +00:00
|
|
|
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
|
|
|
|
{
|
2015-05-22 20:32:05 +00:00
|
|
|
// Prepare table refresh on new search session
|
2015-04-03 13:02:16 +00:00
|
|
|
shouldScrollToTopOnRefresh = YES;
|
2015-05-22 20:32:05 +00:00
|
|
|
|
|
|
|
[super searchBar:searchBar textDidChange:searchText];
|
2014-12-02 14:25:00 +00:00
|
|
|
}
|
|
|
|
|
2015-06-19 22:45:27 +00:00
|
|
|
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
|
|
|
|
{
|
2015-05-22 20:32:05 +00:00
|
|
|
// Prepare table refresh on end of search
|
2015-04-03 13:02:16 +00:00
|
|
|
shouldScrollToTopOnRefresh = YES;
|
2015-05-22 20:32:05 +00:00
|
|
|
|
|
|
|
[super searchBarCancelButtonClicked: searchBar];
|
2014-12-02 14:25:00 +00:00
|
|
|
}
|
|
|
|
|
2014-10-02 15:02:47 +00:00
|
|
|
@end
|