Files
bundesmessenger-ios/Vector/Views/Device/DeviceTableViewCell.m
T
2016-11-28 16:26:59 +01:00

111 lines
4.2 KiB
Objective-C

/*
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"
@implementation DeviceTableViewCell
#pragma mark - Class methods
- (void)awakeFromNib
{
[super awakeFromNib];
self.deviceName.textColor = kVectorTextColorBlack;
}
- (void)render:(MXDeviceInfo *)deviceInfo
{
_deviceInfo = deviceInfo;
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;
}
}
+ (CGFloat)cellHeight
{
return 94;
}
#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