diff --git a/Classes/ChatConversationView.h b/Classes/ChatConversationView.h index 55fe33cc7..921b41a9b 100644 --- a/Classes/ChatConversationView.h +++ b/Classes/ChatConversationView.h @@ -69,7 +69,6 @@ @property (weak, nonatomic) IBOutlet UIButton *encryptedButton; + (void)markAsRead:(LinphoneChatRoom *)chatRoom; -+ (UIImage *)getSecurityImageForChatRoom:(LinphoneChatRoom *)chatRoom; - (void)configureForRoom:(BOOL)editing; - (IBAction)onBackClick:(id)event; diff --git a/Classes/ChatConversationView.m b/Classes/ChatConversationView.m index 4a3f0e126..3c9a245b7 100644 --- a/Classes/ChatConversationView.m +++ b/Classes/ChatConversationView.m @@ -84,24 +84,6 @@ static UICompositeViewDescription *compositeDescription = nil; [PhoneMainView.instance updateApplicationBadgeNumber]; } -+ (UIImage *)getSecurityImageForChatRoom:(LinphoneChatRoom *)chatRoom { - if (!chatRoom) - return nil; - - LinphoneChatRoomSecurityLevel securityLevel = linphone_chat_room_get_security_level(chatRoom); - switch (securityLevel) { - case LinphoneChatRoomSecurityLevelUnsafe: - return [UIImage imageNamed:@"security_alert_indicator.png"]; - case LinphoneChatRoomSecurityLevelEncrypted: - return [UIImage imageNamed:@"security_1_indicator.png.png"]; - case LinphoneChatRoomSecurityLevelSafe: - return [UIImage imageNamed:@"security_2_indicator.png.png"]; - - default: - return nil; - } -} - #pragma mark - ViewController Functions - (void)viewDidLoad { diff --git a/Classes/DevicesListView.m b/Classes/DevicesListView.m index cd4c5de69..0b5b274b2 100644 --- a/Classes/DevicesListView.m +++ b/Classes/DevicesListView.m @@ -8,6 +8,7 @@ #import "DevicesListView.h" #import "PhoneMainView.h" #import "UIDevicesDetails.h" +#import "UIDeviceCell.h" @implementation DevicesMenuEntry @@ -50,7 +51,7 @@ static UICompositeViewDescription *compositeDescription = nil; _tableView.delegate = self; _isOneToOne = linphone_chat_room_get_capabilities(_room) & LinphoneChatRoomCapabilitiesOneToOne; bctbx_list_t *participants = linphone_chat_room_get_participants(_room); - _devicesMenuEntries = [[NSMutableArray alloc] init]; + _devicesMenuEntries = [NSMutableArray array]; if (_isOneToOne) { LinphoneParticipant *firstParticipant = participants ? (LinphoneParticipant *)participants->data : NULL; @@ -73,10 +74,6 @@ static UICompositeViewDescription *compositeDescription = nil; [_tableView reloadData]; } -- (void) viewWillDisappear:(BOOL)animated { - [super viewWillDisappear:animated]; -} - #pragma mark - Action Functions - (IBAction)onBackClick:(id)sender { ChatConversationView *view = VIEW(ChatConversationView); @@ -107,10 +104,16 @@ static UICompositeViewDescription *compositeDescription = nil; - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { if (_isOneToOne) { - UITableViewCell *cell = [[UITableViewCell alloc] init]; + NSString *kCellId = NSStringFromClass(UIDeviceCell.class); + UIDeviceCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellId]; + + if (cell == nil) { + cell = [[UIDeviceCell alloc] initWithIdentifier:kCellId]; + } LinphoneParticipantDevice *device = (LinphoneParticipantDevice *)bctbx_list_nth_data(_devices, (int)[indexPath row]); - cell.textLabel.text = [NSString stringWithUTF8String:linphone_address_as_string_uri_only(linphone_participant_device_get_address(device))]; - cell.selectionStyle =UITableViewCellSelectionStyleNone; + cell.device = device; + cell.isOneToOne = TRUE; + [cell update]; return cell; } @@ -121,6 +124,7 @@ static UICompositeViewDescription *compositeDescription = nil; if (cell == nil) { cell = [[UIDevicesDetails alloc] initWithIdentifier:kCellId]; } + DevicesMenuEntry *entry = [_devicesMenuEntries objectAtIndex:indexPath.row]; [ContactDisplay setDisplayNameLabel:cell.addressLabel forAddress:linphone_participant_get_address(entry->participant)]; diff --git a/Classes/LinphoneUI/UIChatCell.m b/Classes/LinphoneUI/UIChatCell.m index d6746db26..1df3d50c7 100644 --- a/Classes/LinphoneUI/UIChatCell.m +++ b/Classes/LinphoneUI/UIChatCell.m @@ -82,7 +82,7 @@ [_avatarImage setImage:[UIImage imageNamed:@"chat_group_avatar.png"] bordered:NO withRoundedRadius:YES]; } // TODO update security image when security level changed - [_securityImage setImage:[ChatConversationView getSecurityImageForChatRoom:chatRoom]]; + [_securityImage setImage:[FastAddressBook imageForSecurityLevel:linphone_chat_room_get_security_level(chatRoom)]]; _chatLatestTimeLabel.text = [LinphoneUtils timeToString:linphone_chat_room_get_last_update_time(chatRoom) withFormat:LinphoneDateChatList]; diff --git a/Classes/LinphoneUI/UIDeviceCell.h b/Classes/LinphoneUI/UIDeviceCell.h new file mode 100644 index 000000000..96e58963e --- /dev/null +++ b/Classes/LinphoneUI/UIDeviceCell.h @@ -0,0 +1,19 @@ +// +// UIDeviceCell.h +// linphone +// +// Created by Danmei Chen on 07/11/2018. +// + +#import + +@interface UIDeviceCell : UITableViewCell + +@property (weak, nonatomic) IBOutlet UILabel *deviceLabel; +@property (weak, nonatomic) IBOutlet UIImageView *securityImage; +@property LinphoneParticipantDevice *device; +@property BOOL isOneToOne; + +- (id)initWithIdentifier:(NSString *)identifier; +- (void)update; +@end diff --git a/Classes/LinphoneUI/UIDeviceCell.m b/Classes/LinphoneUI/UIDeviceCell.m new file mode 100644 index 000000000..03a987aca --- /dev/null +++ b/Classes/LinphoneUI/UIDeviceCell.m @@ -0,0 +1,40 @@ +// +// UIDeviceCell.m +// linphone +// +// Created by Danmei Chen on 07/11/2018. +// + +#import "UIDeviceCell.h" + +@implementation UIDeviceCell +#pragma mark - Lifecycle Functions +- (id)initWithIdentifier:(NSString *)identifier { + if ((self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]) != nil) { + NSArray *arrayOfViews = + [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self.class) owner:self options:nil]; + + // resize cell to match .nib size. It is needed when resized the cell to + // correctly adapt its height too + UIView *sub = ((UIView *)[arrayOfViews objectAtIndex:0]); + [self setFrame:CGRectMake(0, 0, sub.frame.size.width, sub.frame.size.height)]; + [self addSubview:sub]; + } + return self; +} + +- (void)update { + [_securityImage setImage:[FastAddressBook imageForSecurityLevel:linphone_participant_device_get_security_level(_device)]]; + + _deviceLabel.text = [NSString stringWithUTF8String:linphone_address_as_string_uri_only(linphone_participant_device_get_address(_device))]; + if (_isOneToOne) { + CGRect frame =_deviceLabel.frame; + frame.origin.x = 30; + _deviceLabel.frame = frame; + } + + self.selectionStyle =UITableViewCellSelectionStyleNone; +} + + +@end diff --git a/Classes/LinphoneUI/UIDeviceCell.xib b/Classes/LinphoneUI/UIDeviceCell.xib new file mode 100644 index 000000000..cac996e45 --- /dev/null +++ b/Classes/LinphoneUI/UIDeviceCell.xib @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Classes/LinphoneUI/UIDevicesDetails.h b/Classes/LinphoneUI/UIDevicesDetails.h index a7e23fea9..fef26874e 100644 --- a/Classes/LinphoneUI/UIDevicesDetails.h +++ b/Classes/LinphoneUI/UIDevicesDetails.h @@ -11,6 +11,8 @@ @property (weak, nonatomic) IBOutlet UIButton *dropMenuButton; @property (weak, nonatomic) IBOutlet UILabel *addressLabel; +@property (weak, nonatomic) IBOutlet UIRoundedImageView *avatarImage; +@property (weak, nonatomic) IBOutlet UIImageView *securityImage; @property (weak, nonatomic) IBOutlet UITableView *devicesTable; @property bctbx_list_t *devices; diff --git a/Classes/LinphoneUI/UIDevicesDetails.m b/Classes/LinphoneUI/UIDevicesDetails.m index 5c4437e8c..1b529ab22 100644 --- a/Classes/LinphoneUI/UIDevicesDetails.m +++ b/Classes/LinphoneUI/UIDevicesDetails.m @@ -6,6 +6,7 @@ // #import "UIDevicesDetails.h" +#import "UIDeviceCell.h" @implementation UIDevicesDetails #pragma mark - Lifecycle Functions @@ -43,12 +44,18 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - UITableViewCell *cell = [[UITableViewCell alloc] init]; - LinphoneParticipantDevice *device = (LinphoneParticipantDevice *)bctbx_list_nth_data(_devices, (int)[indexPath row]); - - cell.textLabel.text = [NSString stringWithUTF8String:linphone_address_as_string_uri_only(linphone_participant_device_get_address(device))]; + NSString *kCellId = NSStringFromClass(UIDeviceCell.class); + UIDeviceCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellId]; + + if (cell == nil) { + cell = [[UIDeviceCell alloc] initWithIdentifier:kCellId]; + } + LinphoneParticipantDevice *device = (LinphoneParticipantDevice *)bctbx_list_nth_data(_devices, (int)[indexPath row]); + cell.device = device; + cell.isOneToOne = FALSE; + [cell update]; - return cell; + return cell; } - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath @@ -58,5 +65,4 @@ } - @end diff --git a/Classes/LinphoneUI/UIDevicesDetails.xib b/Classes/LinphoneUI/UIDevicesDetails.xib index 78b336fb8..49cd71cf4 100644 --- a/Classes/LinphoneUI/UIDevicesDetails.xib +++ b/Classes/LinphoneUI/UIDevicesDetails.xib @@ -13,8 +13,10 @@ + + diff --git a/Classes/Utils/FastAddressBook.h b/Classes/Utils/FastAddressBook.h index 1d008b036..d0e505517 100644 --- a/Classes/Utils/FastAddressBook.h +++ b/Classes/Utils/FastAddressBook.h @@ -44,6 +44,7 @@ + (UIImage *)imageForContact:(Contact *)contact; + (UIImage *)imageForAddress:(const LinphoneAddress *)addr; ++ (UIImage *)imageForSecurityLevel:(LinphoneChatRoomSecurityLevel)level; + (BOOL)contactHasValidSipDomain:(Contact *)person; + (BOOL)isSipURIValid:(NSString*)addr; diff --git a/Classes/Utils/FastAddressBook.m b/Classes/Utils/FastAddressBook.m index aa0e6f32d..d9c610d41 100644 --- a/Classes/Utils/FastAddressBook.m +++ b/Classes/Utils/FastAddressBook.m @@ -48,6 +48,20 @@ return [FastAddressBook imageForContact:[FastAddressBook getContactWithAddress:addr]]; } ++ (UIImage *)imageForSecurityLevel:(LinphoneChatRoomSecurityLevel)level { + switch (level) { + case LinphoneChatRoomSecurityLevelUnsafe: + return [UIImage imageNamed:@"security_alert_indicator.png"]; + case LinphoneChatRoomSecurityLevelEncrypted: + return [UIImage imageNamed:@"security_1_indicator.png.png"]; + case LinphoneChatRoomSecurityLevelSafe: + return [UIImage imageNamed:@"security_2_indicator.png.png"]; + + default: + return nil; + } +} + + (Contact *)getContact:(NSString *)address { if (LinphoneManager.instance.fastAddressBook != nil) { @synchronized(LinphoneManager.instance.fastAddressBook.addressBookMap) { diff --git a/linphone.xcodeproj/project.pbxproj b/linphone.xcodeproj/project.pbxproj index 403484190..3672fb9c5 100755 --- a/linphone.xcodeproj/project.pbxproj +++ b/linphone.xcodeproj/project.pbxproj @@ -132,6 +132,8 @@ 61AEBEC82191E48400F35E7F /* chevron_list_close@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 61AEBEC72191E48400F35E7F /* chevron_list_close@2x.png */; }; 61AEBECA2191E49300F35E7F /* chevron_list_open.png in Resources */ = {isa = PBXBuildFile; fileRef = 61AEBEC92191E49200F35E7F /* chevron_list_open.png */; }; 61AEBECC2191E4A300F35E7F /* chevron_list_open@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 61AEBECB2191E4A300F35E7F /* chevron_list_open@2x.png */; }; + 61CCC3DF21933B580060EDEA /* UIDeviceCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 61CCC3DE21933B580060EDEA /* UIDeviceCell.m */; }; + 61CCC3E121933B660060EDEA /* UIDeviceCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 61CCC3E021933B660060EDEA /* UIDeviceCell.xib */; }; 61F1997520C6B1D5006B069A /* AVKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 61F1996E20C6B1D5006B069A /* AVKit.framework */; }; 630589E71B4E810900EFAE36 /* ChatTester.m in Sources */ = {isa = PBXBuildFile; fileRef = 630589DF1B4E810900EFAE36 /* ChatTester.m */; }; 630589E81B4E810900EFAE36 /* ContactsTester.m in Sources */ = {isa = PBXBuildFile; fileRef = 630589E11B4E810900EFAE36 /* ContactsTester.m */; }; @@ -1211,6 +1213,9 @@ 61AEBEC72191E48400F35E7F /* chevron_list_close@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "chevron_list_close@2x.png"; sourceTree = ""; }; 61AEBEC92191E49200F35E7F /* chevron_list_open.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = chevron_list_open.png; sourceTree = ""; }; 61AEBECB2191E4A300F35E7F /* chevron_list_open@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "chevron_list_open@2x.png"; sourceTree = ""; }; + 61CCC3D721933B380060EDEA /* UIDeviceCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UIDeviceCell.h; sourceTree = ""; }; + 61CCC3DE21933B580060EDEA /* UIDeviceCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = UIDeviceCell.m; sourceTree = ""; }; + 61CCC3E021933B660060EDEA /* UIDeviceCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = UIDeviceCell.xib; sourceTree = ""; }; 61F1996E20C6B1D5006B069A /* AVKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AVKit.framework; path = System/Library/Frameworks/AVKit.framework; sourceTree = SDKROOT; }; 630589DE1B4E810900EFAE36 /* ChatTester.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ChatTester.h; sourceTree = ""; }; 630589DF1B4E810900EFAE36 /* ChatTester.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ChatTester.m; sourceTree = ""; }; @@ -2507,6 +2512,9 @@ 639E9CAE1C0DB80300019A75 /* UIContactDetailsCell.xib */, 2248E90C12F7E4CF00220D9C /* UIDigitButton.h */, 2248E90D12F7E4CF00220D9C /* UIDigitButton.m */, + 61CCC3D721933B380060EDEA /* UIDeviceCell.h */, + 61CCC3DE21933B580060EDEA /* UIDeviceCell.m */, + 61CCC3E021933B660060EDEA /* UIDeviceCell.xib */, 61AEBEC02191D7B400F35E7F /* UIDevicesDetails.h */, 61AEBEC12191D7C800F35E7F /* UIDevicesDetails.m */, 61AEBEC32191D7D900F35E7F /* UIDevicesDetails.xib */, @@ -3906,6 +3914,7 @@ 633FEF0B1D3CD55A0014B822 /* options_transfer_call_default@2x.png in Resources */, 633FEDE81D3CD5590014B822 /* call_status_missed~ipad.png in Resources */, 63AADBFF1B6A0FF200AA16FD /* assistant_external_sip.rc in Resources */, + 61CCC3E121933B660060EDEA /* UIDeviceCell.xib in Resources */, 633FEE9E1D3CD55A0014B822 /* numpad_0_over@2x.png in Resources */, 634610121B6140A500548952 /* CallOutgoingView.xib in Resources */, 8CE24F581F8268850077AC0A /* conference_delete@2x.png in Resources */, @@ -4666,6 +4675,7 @@ D3F7998115BD32370018C273 /* TPMultiLayoutViewController.m in Sources */, D3807FBF15C28940005BE9BC /* DCRoundSwitch.m in Sources */, D3807FC115C28940005BE9BC /* DCRoundSwitchKnobLayer.m in Sources */, + 61CCC3DF21933B580060EDEA /* UIDeviceCell.m in Sources */, 6306440E1BECB08500134C72 /* FirstLoginView.m in Sources */, D3807FC315C28940005BE9BC /* DCRoundSwitchOutlineLayer.m in Sources */, CF7602E221086EB200749F76 /* RecordingsListTableView.m in Sources */,