2016-11-28 15:26:59 +00:00
|
|
|
/*
|
|
|
|
Copyright 2016 OpenMarket 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 "DeviceTableViewCell.h"
|
|
|
|
|
|
|
|
#import "VectorDesignValues.h"
|
|
|
|
#import "MXRoom+Vector.h"
|
|
|
|
|
2016-11-28 18:43:43 +00:00
|
|
|
#define DEVICE_TABLEVIEW_ROW_CELL_HEIGHT_WITHOUT_LABEL_HEIGHT 59
|
2016-11-28 16:16:21 +00:00
|
|
|
|
2016-11-28 15:26:59 +00:00
|
|
|
@implementation DeviceTableViewCell
|
|
|
|
|
|
|
|
#pragma mark - Class methods
|
|
|
|
|
|
|
|
- (void)awakeFromNib
|
|
|
|
{
|
|
|
|
[super awakeFromNib];
|
|
|
|
|
|
|
|
self.deviceName.textColor = kVectorTextColorBlack;
|
2016-11-28 18:43:43 +00:00
|
|
|
|
|
|
|
[self.verifyButton.layer setCornerRadius:5];
|
|
|
|
self.verifyButton.clipsToBounds = YES;
|
|
|
|
self.verifyButton.backgroundColor = kVectorColorGreen;
|
|
|
|
|
|
|
|
[self.blockButton.layer setCornerRadius:5];
|
|
|
|
self.blockButton.clipsToBounds = YES;
|
|
|
|
self.blockButton.backgroundColor = kVectorColorGreen;
|
2016-11-28 15:26:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)render:(MXDeviceInfo *)deviceInfo
|
|
|
|
{
|
|
|
|
_deviceInfo = deviceInfo;
|
|
|
|
|
2016-11-28 18:43:43 +00:00
|
|
|
self.deviceName.numberOfLines = 0;
|
2016-11-28 15:26:59 +00:00
|
|
|
self.deviceName.text = (deviceInfo.displayName.length ? [NSString stringWithFormat:@"%@ (%@)", deviceInfo.displayName, deviceInfo.deviceId] : [NSString stringWithFormat:@"(%@)", deviceInfo.deviceId]);
|
|
|
|
|
|
|
|
switch (deviceInfo.verified)
|
|
|
|
{
|
|
|
|
case MXDeviceUnverified:
|
|
|
|
{
|
|
|
|
self.deviceStatus.image = [UIImage imageNamed:@"e2e_warning"];
|
|
|
|
|
|
|
|
[_verifyButton setTitle:[NSBundle mxk_localizedStringForKey:@"room_event_encryption_info_verify"] forState:UIControlStateNormal];
|
|
|
|
[_verifyButton setTitle:[NSBundle mxk_localizedStringForKey:@"room_event_encryption_info_verify"] forState:UIControlStateHighlighted];
|
|
|
|
[_blockButton setTitle:[NSBundle mxk_localizedStringForKey:@"room_event_encryption_info_block"] forState:UIControlStateNormal];
|
|
|
|
[_blockButton setTitle:[NSBundle mxk_localizedStringForKey:@"room_event_encryption_info_block"] forState:UIControlStateHighlighted];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MXDeviceVerified:
|
|
|
|
{
|
|
|
|
self.deviceStatus.image = [UIImage imageNamed:@"e2e_verified"];
|
|
|
|
|
|
|
|
[_verifyButton setTitle:[NSBundle mxk_localizedStringForKey:@"room_event_encryption_info_unverify"] forState:UIControlStateNormal];
|
|
|
|
[_verifyButton setTitle:[NSBundle mxk_localizedStringForKey:@"room_event_encryption_info_unverify"] forState:UIControlStateHighlighted];
|
|
|
|
[_blockButton setTitle:[NSBundle mxk_localizedStringForKey:@"room_event_encryption_info_block"] forState:UIControlStateNormal];
|
|
|
|
[_blockButton setTitle:[NSBundle mxk_localizedStringForKey:@"room_event_encryption_info_block"] forState:UIControlStateHighlighted];
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case MXDeviceBlocked:
|
|
|
|
{
|
|
|
|
self.deviceStatus.image = [UIImage imageNamed:@"e2e_blocked"];
|
|
|
|
|
|
|
|
[_verifyButton setTitle:[NSBundle mxk_localizedStringForKey:@"room_event_encryption_info_verify"] forState:UIControlStateNormal];
|
|
|
|
[_verifyButton setTitle:[NSBundle mxk_localizedStringForKey:@"room_event_encryption_info_verify"] forState:UIControlStateHighlighted];
|
|
|
|
[_blockButton setTitle:[NSBundle mxk_localizedStringForKey:@"room_event_encryption_info_unblock"] forState:UIControlStateNormal];
|
|
|
|
[_blockButton setTitle:[NSBundle mxk_localizedStringForKey:@"room_event_encryption_info_unblock"] forState:UIControlStateHighlighted];
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-28 16:16:21 +00:00
|
|
|
+ (CGFloat)cellHeightWithDeviceInfo:(MXDeviceInfo*)deviceInfo andCellWidth:(CGFloat)width
|
2016-11-28 15:26:59 +00:00
|
|
|
{
|
2016-11-28 16:16:21 +00:00
|
|
|
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, width, 50)];
|
|
|
|
label.numberOfLines = 0;
|
|
|
|
label.text = (deviceInfo.displayName.length ? [NSString stringWithFormat:@"%@ (%@)", deviceInfo.displayName, deviceInfo.deviceId] : [NSString stringWithFormat:@"(%@)", deviceInfo.deviceId]);
|
|
|
|
[label sizeToFit];
|
|
|
|
|
|
|
|
return label.frame.size.height + DEVICE_TABLEVIEW_ROW_CELL_HEIGHT_WITHOUT_LABEL_HEIGHT;
|
2016-11-28 15:26:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark - Actions
|
|
|
|
|
|
|
|
- (IBAction)onButtonPressed:(id)sender
|
|
|
|
{
|
|
|
|
if (self.delegate)
|
|
|
|
{
|
|
|
|
MXDeviceVerification verificationStatus;
|
|
|
|
|
|
|
|
if (sender == _verifyButton)
|
|
|
|
{
|
|
|
|
verificationStatus = ((_deviceInfo.verified == MXDeviceVerified) ? MXDeviceUnverified : MXDeviceVerified);
|
|
|
|
}
|
|
|
|
else if (sender == _blockButton)
|
|
|
|
{
|
|
|
|
verificationStatus = ((_deviceInfo.verified == MXDeviceBlocked) ? MXDeviceUnverified : MXDeviceBlocked);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Unexpected case
|
|
|
|
NSLog(@"[DeviceTableViewCell] Invalid button pressed.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
[self.delegate deviceTableViewCell:self updateDeviceVerification:verificationStatus];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|