element-ios/Riot/Modules/Rooms/RoomsViewController.m

166 lines
4.8 KiB
Mathematica
Raw Normal View History

/*
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 "RoomsViewController.h"
#import "RecentsDataSource.h"
#import "GeneratedInterface-Swift.h"
@interface RoomsViewController () <MasterTabBarItemDisplayProtocol>
{
RecentsDataSource *recentsDataSource;
}
2020-09-10 11:56:46 +00:00
@property (nonatomic, strong) MXThrottler *tableViewPaginationThrottler;
@end
@implementation RoomsViewController
+ (instancetype)instantiate
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
RoomsViewController *viewController = [storyboard instantiateViewControllerWithIdentifier:@"RoomsViewController"];
return viewController;
}
- (void)finalizeInit
{
[super finalizeInit];
self.screenTracker = [[AnalyticsScreenTracker alloc] initWithScreen:AnalyticsScreenRooms];
self.tableViewPaginationThrottler = [[MXThrottler alloc] initWithMinimumDelay:0.1];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.view.accessibilityIdentifier = @"RoomsVCView";
self.recentsTableView.accessibilityIdentifier = @"RoomsVCTableView";
// Tag the recents table with the its recents data source mode.
// This will be used by the shared RecentsDataSource instance for sanity checks (see UITableViewDataSource methods).
self.recentsTableView.tag = RecentsDataSourceModeRooms;
// Add the (+) button programmatically
plusButtonImageView = [self vc_addFABWithImage:AssetImages.roomsFloatingAction.image
target:self
action:@selector(onPlusButtonPressed)];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
2019-01-11 10:45:27 +00:00
[AppDelegate theDelegate].masterTabBarController.tabBar.tintColor = ThemeService.shared.theme.tintColor;
if ([self.dataSource isKindOfClass:RecentsDataSource.class])
{
// Take the lead on the shared data source.
recentsDataSource = (RecentsDataSource*)self.dataSource;
[recentsDataSource setDelegate:self andRecentsDataSourceMode:RecentsDataSourceModeRooms];
}
}
- (void)destroy
{
[super destroy];
}
#pragma mark - Override RecentsViewController
- (void)refreshCurrentSelectedCell:(BOOL)forceVisible
{
// Check whether the recents data source is correctly configured.
if (recentsDataSource.recentsDataSourceMode != RecentsDataSourceModeRooms)
{
return;
}
[super refreshCurrentSelectedCell:forceVisible];
}
- (void)onPlusButtonPressed
{
[self showRoomDirectory];
}
#pragma mark - UITableView delegate
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([super respondsToSelector:@selector(tableView:willDisplayCell:forRowAtIndexPath:)])
{
[super tableView:tableView willDisplayCell:cell forRowAtIndexPath:indexPath];
}
[self.tableViewPaginationThrottler throttle:^{
NSInteger section = indexPath.section;
2022-03-17 12:37:42 +00:00
if (tableView.numberOfSections <= section)
{
return;
}
NSInteger numberOfRowsInSection = [tableView numberOfRowsInSection:section];
2022-03-17 12:37:42 +00:00
if (indexPath.row == numberOfRowsInSection - 1)
{
[self->recentsDataSource paginateInSection:section];
}
}];
}
#pragma mark -
- (void)scrollToNextRoomWithMissedNotifications
{
// Check whether the recents data source is correctly configured.
if (recentsDataSource.recentsDataSourceMode == RecentsDataSourceModeRooms)
{
2022-04-04 08:24:22 +00:00
[self scrollToTheTopTheNextRoomWithMissedNotificationsInSection:[recentsDataSource.sections sectionTypeForSectionIndex:RecentsDataSourceSectionTypeConversation]];
}
}
#pragma mark - Empty view management
- (void)updateEmptyView
{
[self.emptyView fillWith:[self emptyViewArtwork]
title:[VectorL10n roomsEmptyViewTitle]
informationText:[VectorL10n roomsEmptyViewInformation]];
}
- (UIImage*)emptyViewArtwork
{
if (ThemeService.shared.isCurrentThemeDark)
{
return AssetImages.roomsEmptyScreenArtworkDark.image;
}
else
{
return AssetImages.roomsEmptyScreenArtwork.image;
}
}
#pragma mark - MasterTabBarItemDisplayProtocol
- (NSString *)masterTabBarItemTitle
{
return [VectorL10n titleRooms];
}
@end