From 47425e688276e62b55df1864d38c917a9776bc23 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Wed, 14 Oct 2015 15:41:28 +0200 Subject: [PATCH] Call: more work on paused calls --- Classes/Base.lproj/CallView.xib | 61 ++++++-- Classes/CallPausedTableView.m | 19 ++- Classes/CallView.h | 2 + Classes/CallView.m | 193 +++++++++++++----------- Classes/HistoryDetailsView.m | 2 +- Classes/LinphoneUI/UICallPausedCell.xib | 14 +- Classes/LinphoneUI/UIRoundedImageView.m | 2 +- submodules/linphone | 2 +- 8 files changed, 180 insertions(+), 115 deletions(-) diff --git a/Classes/Base.lproj/CallView.xib b/Classes/Base.lproj/CallView.xib index 4f85bb291..90df395d4 100644 --- a/Classes/Base.lproj/CallView.xib +++ b/Classes/Base.lproj/CallView.xib @@ -17,6 +17,7 @@ + @@ -26,6 +27,7 @@ + @@ -69,28 +71,28 @@ - - - - - - - - + + + + + + + + + + @@ -153,8 +191,6 @@ - - @@ -567,6 +603,7 @@ + diff --git a/Classes/CallPausedTableView.m b/Classes/CallPausedTableView.m index 6e7fd9e2c..7a402f71b 100644 --- a/Classes/CallPausedTableView.m +++ b/Classes/CallPausedTableView.m @@ -49,14 +49,22 @@ newOrigin.size.height = [self tableView:self.tableView heightForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]] * [self tableView:self.tableView numberOfRowsInSection:0]; - newOrigin.origin.y = self.tableView.frame.origin.y + self.tableView.frame.size.height - newOrigin.size.height; + newOrigin.origin.y += self.tableView.frame.size.height - newOrigin.size.height; self.tableView.frame = newOrigin; } #pragma mark - UITableViewDataSource Functions - (LinphoneCall *)pausedCallForRow:(NSInteger)row { const MSList *calls = linphone_core_get_calls([LinphoneManager getLc]); - return (row < ms_list_size(calls) - 1) ? ms_list_nth_data(calls, (int)row) : NULL; + LinphoneCall *currentCall = linphone_core_get_current_call([LinphoneManager getLc]); + int i = 0; + while (calls && i < row) { + if (calls->data != currentCall) { + i++; + } + calls = calls->next; + } + return (calls ? calls->data : NULL); } #pragma mark - UITableViewDataSource Functions @@ -72,17 +80,14 @@ } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return ms_list_size(linphone_core_get_calls([LinphoneManager getLc])) - 1; + return ms_list_size(linphone_core_get_calls([LinphoneManager getLc])) - + (linphone_core_get_current_call([LinphoneManager getLc]) ? 1 : 0); } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } -- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { - return [self tableView:tableView cellForRowAtIndexPath:indexPath].frame.size.height; -} - - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 1e-5; } diff --git a/Classes/CallView.h b/Classes/CallView.h index 389f62d2d..0e2f8a3a1 100644 --- a/Classes/CallView.h +++ b/Classes/CallView.h @@ -87,6 +87,8 @@ @property(weak, nonatomic) IBOutlet UIRoundedImageView *avatarImage; @property(weak, nonatomic) IBOutlet UILabel *nameLabel; @property(weak, nonatomic) IBOutlet UILabel *durationLabel; +@property(weak, nonatomic) IBOutlet UIView *pausedByRemoteView; +@property(weak, nonatomic) IBOutlet UIView *noActiveCallView; - (IBAction)onRoutesClick:(id)sender; - (IBAction)onRoutesBluetoothClick:(id)sender; diff --git a/Classes/CallView.m b/Classes/CallView.m index 8cfae5847..0425915b8 100644 --- a/Classes/CallView.m +++ b/Classes/CallView.m @@ -122,6 +122,7 @@ static UICompositeViewDescription *compositeDescription = nil; [self hidePad:FALSE]; [self showSpeaker]; [self callDurationUpdate]; + [self onCurrentCallChange]; // Set windows (warn memory leaks) linphone_core_set_native_video_window_id([LinphoneManager getLc], (__bridge void *)(_videoView)); @@ -139,14 +140,6 @@ static UICompositeViewDescription *compositeDescription = nil; name:kLinphoneBluetoothAvailabilityUpdate object:nil]; - const LinphoneAddress *addr = linphone_call_get_remote_address(call); - [ContactDisplay setDisplayNameLabel:_nameLabel forAddress:addr]; - char *uri = linphone_address_as_string_uri_only(addr); - _addressLabel.text = [NSString stringWithUTF8String:uri]; - ms_free(uri); - _avatarImage.image = - [FastAddressBook getContactImage:[FastAddressBook getContactWithLinphoneAddress:addr] thumbnail:NO]; - [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(callDurationUpdate) @@ -236,80 +229,6 @@ static UICompositeViewDescription *compositeDescription = nil; #pragma mark - -- (void)callUpdate:(LinphoneCall *)call state:(LinphoneCallState)state animated:(BOOL)animated { - LinphoneCore *lc = [LinphoneManager getLc]; - [self updateBottomBar:call state:state]; - if (hiddenVolume) { - [PhoneMainView.instance setVolumeHidden:FALSE]; - hiddenVolume = FALSE; - } - - // Update table - [_pausedCallsTableView.tableView reloadData]; - - // Fake call update - if (call == NULL) { - return; - } - - switch (state) { - case LinphoneCallIncomingReceived: - case LinphoneCallOutgoingInit: - case LinphoneCallConnected: - case LinphoneCallStreamsRunning: { - // check video - if (linphone_call_params_video_enabled(linphone_call_get_current_params(call))) { - [self displayVideoCall:animated]; - } else { - [self displayTableCall:animated]; - const LinphoneCallParams *param = linphone_call_get_current_params(call); - const LinphoneCallAppData *callAppData = - (__bridge const LinphoneCallAppData *)(linphone_call_get_user_pointer(call)); - if (state == LinphoneCallStreamsRunning && callAppData->videoRequested && - linphone_call_params_low_bandwidth_enabled(param)) { - // too bad video was not enabled because low bandwidth - UIAlertView *alert = [[UIAlertView alloc] - initWithTitle:NSLocalizedString(@"Low bandwidth", nil) - message:NSLocalizedString(@"Video cannot be activated because of low bandwidth " - @"condition, only audio is available", - nil) - delegate:nil - cancelButtonTitle:NSLocalizedString(@"Continue", nil) - otherButtonTitles:nil]; - [alert show]; - callAppData->videoRequested = FALSE; /*reset field*/ - } - } - break; - } - case LinphoneCallUpdatedByRemote: { - const LinphoneCallParams *current = linphone_call_get_current_params(call); - const LinphoneCallParams *remote = linphone_call_get_remote_params(call); - - /* remote wants to add video */ - if (linphone_core_video_enabled(lc) && !linphone_call_params_video_enabled(current) && - linphone_call_params_video_enabled(remote) && - !linphone_core_get_video_policy(lc)->automatically_accept) { - linphone_core_defer_call_update(lc, call); - [self displayAskToEnableVideoCall:call]; - } else if (linphone_call_params_video_enabled(current) && !linphone_call_params_video_enabled(remote)) { - [self displayTableCall:animated]; - } - break; - } - case LinphoneCallPausing: - case LinphoneCallPaused: - case LinphoneCallPausedByRemote: { - [self displayTableCall:animated]; - break; - } - case LinphoneCallEnd: - case LinphoneCallError: - default: - break; - } -} - - (void)updateBottomBar:(LinphoneCall *)call state:(LinphoneCallState)state { LinphoneCore *lc = [LinphoneManager getLc]; @@ -491,12 +410,11 @@ static UICompositeViewDescription *compositeDescription = nil; [_videoGroup setAlpha:0.0]; [PhoneMainView.instance showTabBar:true]; - UIEdgeInsets insets = {10, 0, 25, 0}; - [_pausedCallsTableView.tableView setContentInset:insets]; - [_pausedCallsTableView.tableView setScrollIndicatorInsets:insets]; + // UIEdgeInsets insets = {10, 0, 25, 0}; + // [_pausedCallsTableView.tableView setContentInset:insets]; + // [_pausedCallsTableView.tableView setScrollIndicatorInsets:insets]; [_pausedCallsTableView.tableView setAlpha:1.0]; - [_pausedCallsTableView.tableView setAlpha:1.0]; [_videoCameraSwitch setHidden:TRUE]; if (animation) { @@ -540,6 +458,22 @@ static void hideSpinner(LinphoneCall *call, void *user_data) { } } +- (void)onCurrentCallChange { + LinphoneCall *call = linphone_core_get_current_call([LinphoneManager getLc]); + if (call) { + const LinphoneAddress *addr = linphone_call_get_remote_address(call); + [ContactDisplay setDisplayNameLabel:_nameLabel forAddress:addr]; + char *uri = linphone_address_as_string_uri_only(addr); + _addressLabel.text = [NSString stringWithUTF8String:uri]; + ms_free(uri); + _avatarImage.image = + [FastAddressBook getContactImage:[FastAddressBook getContactWithLinphoneAddress:addr] thumbnail:NO]; + _noActiveCallView.hidden = YES; + } else { + _noActiveCallView.hidden = NO; + } +} + - (void)showPad:(BOOL)animated { [_numpadButton setOn]; if ([_numpadView isHidden]) { @@ -659,6 +593,93 @@ static void hideSpinner(LinphoneCall *call, void *user_data) { [self callUpdate:call state:state animated:TRUE]; } +- (void)callUpdate:(LinphoneCall *)call state:(LinphoneCallState)state animated:(BOOL)animated { + LinphoneCore *lc = [LinphoneManager getLc]; + [self updateBottomBar:call state:state]; + if (hiddenVolume) { + [PhoneMainView.instance setVolumeHidden:FALSE]; + hiddenVolume = FALSE; + } + + // Update table + [_pausedCallsTableView.tableView reloadData]; + + static LinphoneCall *currentCall = NULL; + if (!currentCall || linphone_core_get_current_call(lc) != currentCall) { + currentCall = linphone_core_get_current_call(lc); + [self onCurrentCallChange]; + } + + // Fake call update + if (call == NULL) { + return; + } + + if (state != LinphoneCallPausedByRemote) { + _pausedByRemoteView.hidden = YES; + } + + switch (state) { + case LinphoneCallIncomingReceived: + case LinphoneCallOutgoingInit: + case LinphoneCallConnected: + case LinphoneCallStreamsRunning: { + // check video + if (linphone_call_params_video_enabled(linphone_call_get_current_params(call))) { + [self displayVideoCall:animated]; + } else { + [self displayTableCall:animated]; + const LinphoneCallParams *param = linphone_call_get_current_params(call); + const LinphoneCallAppData *callAppData = + (__bridge const LinphoneCallAppData *)(linphone_call_get_user_pointer(call)); + if (state == LinphoneCallStreamsRunning && callAppData->videoRequested && + linphone_call_params_low_bandwidth_enabled(param)) { + // too bad video was not enabled because low bandwidth + UIAlertView *alert = [[UIAlertView alloc] + initWithTitle:NSLocalizedString(@"Low bandwidth", nil) + message:NSLocalizedString(@"Video cannot be activated because of low bandwidth " + @"condition, only audio is available", + nil) + delegate:nil + cancelButtonTitle:NSLocalizedString(@"Continue", nil) + otherButtonTitles:nil]; + [alert show]; + callAppData->videoRequested = FALSE; /*reset field*/ + } + } + break; + } + case LinphoneCallUpdatedByRemote: { + const LinphoneCallParams *current = linphone_call_get_current_params(call); + const LinphoneCallParams *remote = linphone_call_get_remote_params(call); + + /* remote wants to add video */ + if (linphone_core_video_enabled(lc) && !linphone_call_params_video_enabled(current) && + linphone_call_params_video_enabled(remote) && + !linphone_core_get_video_policy(lc)->automatically_accept) { + linphone_core_defer_call_update(lc, call); + [self displayAskToEnableVideoCall:call]; + } else if (linphone_call_params_video_enabled(current) && !linphone_call_params_video_enabled(remote)) { + [self displayTableCall:animated]; + } + break; + } + case LinphoneCallPausing: + case LinphoneCallPaused: + [self displayTableCall:animated]; + break; + case LinphoneCallPausedByRemote: + if (call == linphone_core_get_current_call(lc)) { + _pausedByRemoteView.hidden = NO; + } + break; + case LinphoneCallEnd: + case LinphoneCallError: + default: + break; + } +} + #pragma mark - ActionSheet Functions - (void)displayAskToEnableVideoCall:(LinphoneCall *)call { diff --git a/Classes/HistoryDetailsView.m b/Classes/HistoryDetailsView.m index 3e9fc76a0..57ac70496 100644 --- a/Classes/HistoryDetailsView.m +++ b/Classes/HistoryDetailsView.m @@ -161,7 +161,7 @@ static UICompositeViewDescription *compositeDescription = nil; LinphoneAddress *addr = linphone_call_log_get_remote_address(callLog); ABRecordRef contact = [FastAddressBook getContactWithLinphoneAddress:addr]; _addContactButton.hidden = (contact != nil); - [ContactDisplay setDisplayNameLabel:_contactLabel forContact:contact]; + [ContactDisplay setDisplayNameLabel:_contactLabel forAddress:addr]; _avatarImage.image = [FastAddressBook getContactImage:contact thumbnail:NO]; char *addrURI = linphone_address_as_string_uri_only(addr); _addressLabel.text = [NSString stringWithUTF8String:addrURI]; diff --git a/Classes/LinphoneUI/UICallPausedCell.xib b/Classes/LinphoneUI/UICallPausedCell.xib index b1536b1b8..e3169004a 100644 --- a/Classes/LinphoneUI/UICallPausedCell.xib +++ b/Classes/LinphoneUI/UICallPausedCell.xib @@ -55,12 +55,12 @@ - + - - - + + +