add my devices list

This commit is contained in:
Danmei Chen 2019-08-06 16:26:52 +02:00
parent 12b9bdeb84
commit 882cf5afa3
7 changed files with 94 additions and 82 deletions

View file

@ -650,29 +650,8 @@ static UICompositeViewDescription *compositeDescription = nil;
}
- (IBAction)onEncryptedDevicesClick:(id)sender {
BOOL isOneToOne = linphone_chat_room_get_capabilities(_chatRoom) & LinphoneChatRoomCapabilitiesOneToOne;
NSString *message = NSLocalizedString(@"Instant messages are end-to-end encrypted in secured conversations. It is possible to upgrade the security level of a conversation by authenticating participants. To do so, call the contact and follow the authentification process.",nil);
BOOL notAskAgain = [LinphoneManager.instance lpConfigBoolForKey:@"confirmation_dialog_before_sas_call_not_ask_again"];
if (isOneToOne) {
bctbx_list_t *participants = linphone_chat_room_get_participants(_chatRoom);
LinphoneParticipant *firstParticipant = participants ? (LinphoneParticipant *)participants->data : NULL;
const LinphoneAddress *addr = firstParticipant ? linphone_participant_get_address(firstParticipant) : linphone_chat_room_get_peer_address(_chatRoom);
if (bctbx_list_size(linphone_participant_get_devices(firstParticipant)) == 1) {
if (notAskAgain) {
[LinphoneManager.instance doCallWithSas:addr isSas:TRUE];
} else {
securityDialog = [UIConfirmationDialog ShowWithMessage:message cancelMessage:NSLocalizedString(@"CANCEL", nil) confirmMessage:NSLocalizedString(@"CALL", nil) onCancelClick:^() {
} onConfirmationClick:^() {
[LinphoneManager.instance doCallWithSas:addr isSas:TRUE];
}];
[_messageField resignFirstResponder];
securityDialog.authView.hidden = FALSE;
[securityDialog setSpecialColor];
}
return;
}
}
if (notAskAgain) {
[self goToDeviceListView];

View file

@ -11,6 +11,7 @@
@public
LinphoneParticipant *participant;
NSInteger numberOfDevices;
BOOL myself;
};
@end
@ -22,7 +23,6 @@
@property(nonatomic) LinphoneChatRoom *room;
@property bctbx_list_t *devices;
@property NSMutableArray *devicesMenuEntries;
@property BOOL isOneToOne;
- (IBAction)onBackClick:(id)sender;

View file

@ -12,10 +12,11 @@
@implementation DevicesMenuEntry
- (id)initWithTitle:(LinphoneParticipant *)par number:(NSInteger)num {
- (id)initWithTitle:(LinphoneParticipant *)par number:(NSInteger)num isMe:(BOOL)isMe{
if ((self = [super init])) {
participant = par;
numberOfDevices = num;
myself = isMe;
}
return self;
}
@ -49,27 +50,33 @@ static UICompositeViewDescription *compositeDescription = nil;
[super viewWillAppear:animated];
_tableView.dataSource = self;
_tableView.delegate = self;
_isOneToOne = linphone_chat_room_get_capabilities(_room) & LinphoneChatRoomCapabilitiesOneToOne;
bctbx_list_t *participants = linphone_chat_room_get_participants(_room);
_devicesMenuEntries = [NSMutableArray array];
if (_isOneToOne) {
if (linphone_chat_room_get_capabilities(_room) & LinphoneChatRoomCapabilitiesOneToOne) {
LinphoneParticipant *firstParticipant = participants ? (LinphoneParticipant *)participants->data : NULL;
const LinphoneAddress *addr = firstParticipant ? linphone_participant_get_address(firstParticipant) : linphone_chat_room_get_peer_address(_room);
[ContactDisplay setDisplayNameLabel:_addressLabel forAddress:addr];
_devices = linphone_participant_get_devices(firstParticipant);
_addressLabel.text = [NSString stringWithFormat:NSLocalizedString(@"devices", nil)];
[_devicesMenuEntries
addObject:[[DevicesMenuEntry alloc] initWithTitle:firstParticipant number:0 isMe:FALSE]];
} else {
LinphoneParticipant *participant;
for (int i=0; i<bctbx_list_size(participants); i++) {
participant = (LinphoneParticipant *)bctbx_list_nth_data(participants,i);
[_devicesMenuEntries
addObject:[[DevicesMenuEntry alloc] initWithTitle:participant number:0]];
addObject:[[DevicesMenuEntry alloc] initWithTitle:participant number:0 isMe:FALSE]];
}
_addressLabel.text = [NSString stringWithUTF8String:linphone_chat_room_get_subject(_room) ?: LINPHONE_DUMMY_SUBJECT];
_addressLabel.text = [NSString stringWithFormat:NSLocalizedString(@"%@'s devices", nil), _addressLabel.text];
}
_addressLabel.text = [NSString stringWithFormat:NSLocalizedString(@"%@'s devices", nil), _addressLabel.text];
LinphoneParticipant *me = linphone_chat_room_get_me(_room);
[_devicesMenuEntries
addObject:[[DevicesMenuEntry alloc] initWithTitle:me number:0 isMe:TRUE]];
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[_tableView reloadData];
}
@ -88,35 +95,17 @@ static UICompositeViewDescription *compositeDescription = nil;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return _isOneToOne ? bctbx_list_size(_devices) : [_devicesMenuEntries count];
return [_devicesMenuEntries count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath
{
if (!_isOneToOne) {
DevicesMenuEntry *entry = [_devicesMenuEntries objectAtIndex:indexPath.row];
return entry->numberOfDevices > 1 ? (entry->numberOfDevices + 1) * 56.0 : 56.0;
}
return 56.0;
DevicesMenuEntry *entry = [_devicesMenuEntries objectAtIndex:indexPath.row];
return entry->numberOfDevices > 1 ? (entry->numberOfDevices + 1) * 56.0 : 56.0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (_isOneToOne) {
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 = TRUE;
[cell update];
return cell;
}
NSString *kCellId = NSStringFromClass(UIDevicesDetails.class);
UIDevicesDetails *cell = [tableView dequeueReusableCellWithIdentifier:kCellId];
@ -126,7 +115,7 @@ static UICompositeViewDescription *compositeDescription = nil;
DevicesMenuEntry *entry = [_devicesMenuEntries objectAtIndex:indexPath.row];
[ContactDisplay setDisplayNameLabel:cell.addressLabel forAddress:linphone_participant_get_address(entry->participant)];
entry->myself ? cell.addressLabel.text = NSLocalizedString(@"Me", nil) : [ContactDisplay setDisplayNameLabel:cell.addressLabel forAddress:linphone_participant_get_address(entry->participant)];
cell.participant = entry->participant;
[cell update:(entry->numberOfDevices != 0)];
@ -134,12 +123,10 @@ static UICompositeViewDescription *compositeDescription = nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (!_isOneToOne) {
DevicesMenuEntry *entry = [_devicesMenuEntries objectAtIndex:indexPath.row];
NSInteger num = (entry->numberOfDevices != 0) ? 0: bctbx_list_size(linphone_participant_get_devices(entry->participant));
[_devicesMenuEntries replaceObjectAtIndex:indexPath.row withObject:[[DevicesMenuEntry alloc] initWithTitle:entry->participant number:num]];
[_tableView reloadData];
}
DevicesMenuEntry *entry = [_devicesMenuEntries objectAtIndex:indexPath.row];
NSInteger num = (entry->numberOfDevices != 0) ? 0: bctbx_list_size(linphone_participant_get_devices(entry->participant));
[_devicesMenuEntries replaceObjectAtIndex:indexPath.row withObject:[[DevicesMenuEntry alloc] initWithTitle:entry->participant number:num isMe:entry->myself]];
[_tableView reloadData];
}
@end

View file

@ -1,9 +1,21 @@
//
// UIDeviceCell.h
// linphone
//
// Created by Danmei Chen on 07/11/2018.
//
/* UIDeviceCell.h
*
* Copyright (C) 2019 Belledonne Comunications, Grenoble, France
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#import <UIKit/UIKit.h>

View file

@ -1,9 +1,21 @@
//
// UIDeviceCell.m
// linphone
//
// Created by Danmei Chen on 07/11/2018.
//
/* UIDeviceCell.m
*
* Copyright (C) 2019 Belledonne Comunications, Grenoble, France
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#import "UIDeviceCell.h"

View file

@ -1,10 +1,21 @@
//
// UIDevicesDetails.h
// linphone
//
// Created by Danmei Chen on 06/11/2018.
//
/* UIDevicesDetails.h
*
* Copyright (C) 2019 Belledonne Comunications, Grenoble, France
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#import <UIKit/UIKit.h>
@interface UIDevicesDetails : UITableViewCell <UITableViewDelegate, UITableViewDataSource, UIGestureRecognizerDelegate>

View file

@ -1,10 +1,21 @@
//
// UIDevicesDetails.m
// linphone
//
// Created by Danmei Chen on 06/11/2018.
//
/* UIDevicesDetails.m
*
* Copyright (C) 2019 Belledonne Comunications, Grenoble, France
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#import "UIDevicesDetails.h"
#import "UIDeviceCell.h"