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>
|
|
|
|
|
2017-06-21 21:45:11 +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;
|
2017-06-21 21:45:11 +00:00
|
|
|
@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
|
|
|
|
|
2017-06-21 21:45:11 +00:00
|
|
|
- (void)configureViews
|
|
|
|
{
|
2017-06-21 18:28:16 +00:00
|
|
|
self.containerView.layer.cornerRadius = 20;
|
|
|
|
self.titleLabel.text = @"Read Receipts List";
|
|
|
|
}
|
|
|
|
|
2017-06-21 21:45:11 +00:00
|
|
|
- (void)configureReceiptsTableView
|
|
|
|
{
|
2017-06-21 18:28:16 +00:00
|
|
|
self.receiptsTableView.dataSource = self;
|
2017-06-21 21:45:11 +00:00
|
|
|
self.receiptsTableView.delegate = self;
|
|
|
|
self.receiptsTableView.showsVerticalScrollIndicator = NO;
|
|
|
|
self.receiptsTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
|
2017-06-21 18:28:16 +00:00
|
|
|
|
2017-06-21 21:45:11 +00:00
|
|
|
[self.receiptsTableView registerNib:[MXKReadReceiptTableViewCell nib] forCellReuseIdentifier:[MXKReadReceiptTableViewCell defaultReuseIdentifier]];
|
2017-06-21 18:28:16 +00:00
|
|
|
}
|
|
|
|
|
2017-06-21 21:45:11 +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
|
|
|
|
{
|
2017-06-21 21:45:11 +00:00
|
|
|
MXKReadReceiptTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[MXKReadReceiptTableViewCell defaultReuseIdentifier] forIndexPath:indexPath];
|
2017-06-21 18:28:16 +00:00
|
|
|
|
|
|
|
if (indexPath.row < self.roomMembers.count)
|
|
|
|
{
|
2017-06-21 21:45:11 +00:00
|
|
|
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)
|
|
|
|
{
|
2017-06-21 21:45:11 +00:00
|
|
|
NSString *avatarUrl = self.roomMembers[indexPath.row].avatarUrl;
|
|
|
|
if (self.restClient && avatarUrl)
|
|
|
|
{
|
|
|
|
CGFloat side = CGRectGetWidth(cell.imageView.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
|
|
|
{
|
2017-06-23 12:40:09 +00:00
|
|
|
NSString *receiptDescription = [(MXKEventFormatter*)self.session.roomSummaryUpdateDelegate dateStringFromTimestamp:self.receipts[indexPath.row].ts withTime:YES];
|
|
|
|
cell.receiptDescriptionLabel.text = receiptDescription;
|
2017-06-21 18:28:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
|
|
|
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
2017-06-21 21:45:11 +00:00
|
|
|
#pragma mark - UITableViewDelegate
|
|
|
|
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
|
|
|
|
{
|
|
|
|
return 70;
|
|
|
|
}
|
|
|
|
|
2017-06-21 18:28:16 +00:00
|
|
|
|
|
|
|
@end
|