element-ios/Riot/ViewController/ReadReceiptsViewController.m

170 lines
6.2 KiB
Mathematica
Raw Normal View History

2017-06-21 18:28:16 +00:00
/*
Copyright 2017 Aram Sargsyan
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 "ReadReceiptsViewController.h"
#import <MatrixKit/MatrixKit.h>
#import "RiotDesignValues.h"
2017-06-21 18:28:16 +00:00
@interface ReadReceiptsViewController () <UITableViewDataSource, UITableViewDelegate>
2017-06-21 18:28:16 +00:00
@property (nonatomic) MXRestClient* restClient;
2017-06-23 12:40:09 +00:00
@property (nonatomic) MXSession *session;
2017-06-21 18:28:16 +00:00
@property (nonatomic) NSArray <MXRoomMember *> *roomMembers;
@property (nonatomic) NSArray <UIImage *> *placeholders;
2017-06-23 12:40:09 +00:00
@property (nonatomic) NSArray <MXReceiptData *> *receipts;
2017-06-21 18:28:16 +00:00
@property (weak, nonatomic) IBOutlet UIView *overlayView;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UIView *containerView;
@property (weak, nonatomic) IBOutlet UITableView *receiptsTableView;
2017-06-21 18:28:16 +00:00
@end
@implementation ReadReceiptsViewController
#pragma mark - Public
2017-06-23 12:40:09 +00:00
+ (void)openInViewController:(UIViewController *)viewController withRestClient:(MXRestClient *)restClient session:(MXSession *)session withRoomMembers:(NSArray <MXRoomMember *> *)roomMembers placeholders:(NSArray <UIImage *> *)placeholders receipts:(NSArray <MXReceiptData *> *)receipts
2017-06-21 18:28:16 +00:00
{
ReadReceiptsViewController *receiptsController = [[[self class] alloc] initWithNibName:NSStringFromClass([self class]) bundle:nil];
receiptsController.restClient = restClient;
2017-06-23 12:40:09 +00:00
receiptsController.session = session;
2017-06-21 18:28:16 +00:00
receiptsController.roomMembers = roomMembers;
receiptsController.placeholders = placeholders;
2017-06-23 12:40:09 +00:00
receiptsController.receipts = receipts;
2017-06-21 18:28:16 +00:00
receiptsController.providesPresentationContextTransitionStyle = YES;
receiptsController.definesPresentationContext = YES;
receiptsController.modalPresentationStyle = UIModalPresentationOverFullScreen;
receiptsController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[viewController presentViewController:receiptsController animated:YES completion:nil];
}
#pragma mark - Lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
[self configureViews];
[self configureReceiptsTableView];
[self addOverlayViewGesture];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Views
- (void)configureViews
{
2017-06-21 18:28:16 +00:00
self.containerView.layer.cornerRadius = 20;
self.titleLabel.text = NSLocalizedStringFromTable(@"read_receipts_list", @"Vector", nil);
2017-06-21 18:28:16 +00:00
}
- (void)configureReceiptsTableView
{
2017-06-21 18:28:16 +00:00
self.receiptsTableView.dataSource = self;
self.receiptsTableView.delegate = self;
self.receiptsTableView.showsVerticalScrollIndicator = NO;
self.receiptsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
2017-06-21 18:28:16 +00:00
[self.receiptsTableView registerNib:[MXKReadReceiptTableViewCell nib] forCellReuseIdentifier:[MXKReadReceiptTableViewCell defaultReuseIdentifier]];
2017-06-21 18:28:16 +00:00
}
- (void)addOverlayViewGesture
{
2017-06-21 18:28:16 +00:00
UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(overlayTap)];
[tapRecognizer setNumberOfTapsRequired:1];
[tapRecognizer setNumberOfTouchesRequired:1];
[self.overlayView addGestureRecognizer:tapRecognizer];
}
#pragma mark - Actions
2017-06-21 22:03:03 +00:00
- (void)overlayTap
{
2017-06-21 18:28:16 +00:00
[self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.roomMembers.count;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MXKReadReceiptTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[MXKReadReceiptTableViewCell defaultReuseIdentifier] forIndexPath:indexPath];
2017-06-21 18:28:16 +00:00
if (indexPath.row < self.roomMembers.count)
{
NSString *name = self.roomMembers[indexPath.row].displayname;
if (name.length == 0) {
name = self.roomMembers[indexPath.row].userId;
}
cell.displayNameLabel.text = name;
2017-06-21 18:28:16 +00:00
}
if (indexPath.row < self.placeholders.count)
{
NSString *avatarUrl = self.roomMembers[indexPath.row].avatarUrl;
if (self.restClient && avatarUrl)
{
2017-06-26 16:51:13 +00:00
CGFloat side = CGRectGetWidth(cell.avatarImageView.frame);
avatarUrl = [self.restClient urlOfContentThumbnail:avatarUrl toFitViewSize:CGSizeMake(side, side) withMethod:MXThumbnailingMethodCrop];
}
[cell.avatarImageView setImageURL:avatarUrl withType:nil andImageOrientation:UIImageOrientationUp previewImage:self.placeholders[indexPath.row]];
2017-06-21 18:28:16 +00:00
}
2017-06-23 12:40:09 +00:00
if (indexPath.row < self.receipts.count)
2017-06-21 18:28:16 +00:00
{
NSString *receiptReadText = [NSBundle mxk_localizedStringForKey:@"receipt_status_read"];
NSString *receiptTimeText = [(MXKEventFormatter*)self.session.roomSummaryUpdateDelegate dateStringFromTimestamp:self.receipts[indexPath.row].ts withTime:YES];
cell.receiptDescriptionLabel.text = receiptTimeText;
NSMutableAttributedString *receiptDescription = [[NSMutableAttributedString alloc] initWithString:receiptReadText attributes:@{NSForegroundColorAttributeName : kRiotTextColorGray, NSFontAttributeName : [UIFont boldSystemFontOfSize:15]}];
[receiptDescription appendAttributedString:[[NSAttributedString alloc] initWithString:receiptTimeText attributes:@{NSForegroundColorAttributeName : kRiotTextColorGray, NSFontAttributeName : [UIFont systemFontOfSize:15]}]];
cell.receiptDescriptionLabel.attributedText = receiptDescription;
2017-06-21 18:28:16 +00:00
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 70;
}
2017-06-21 18:28:16 +00:00
@end