From 46d5d1a11c8e89cfa40c9c06bc6f6e85f100c6b8 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Thu, 23 Oct 2014 11:02:23 +0200 Subject: [PATCH] Improve UIStatebar voice mail from telefonica --- Classes/LinphoneUI/UIStateBar.m | 48 ++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/Classes/LinphoneUI/UIStateBar.m b/Classes/LinphoneUI/UIStateBar.m index a17f149a0..2263111b7 100644 --- a/Classes/LinphoneUI/UIStateBar.m +++ b/Classes/LinphoneUI/UIStateBar.m @@ -31,7 +31,7 @@ NSTimer *callQualityTimer; NSTimer *callSecurityTimer; - +int messagesUnreadCount; #pragma mark - Lifecycle Functions @@ -97,15 +97,23 @@ NSTimer *callSecurityTimer; name:kLinphoneNotifyReceived object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(callUpdate:) + name:kLinphoneCallUpdate + object:nil]; + + [callQualityImage setHidden: true]; [callSecurityImage setHidden: true]; - self.voicemailCount.hidden = true; // Update to default state LinphoneProxyConfig* config = NULL; - if([LinphoneManager isLcReady]) + if([LinphoneManager isLcReady]) { linphone_core_get_default_proxy([LinphoneManager getLc], &config); + messagesUnreadCount = lp_config_get_int(linphone_core_get_config([LinphoneManager getLc]), "app", "voice_mail_messages_count", 0); + } [self proxyConfigUpdate: config]; + [self updateVoicemail]; } - (void)viewWillDisappear:(BOOL)animated { @@ -122,6 +130,10 @@ NSTimer *callSecurityTimer; [[NSNotificationCenter defaultCenter] removeObserver:self name:kLinphoneNotifyReceived object:nil]; + [[NSNotificationCenter defaultCenter] removeObserver:self + name:kLinphoneCallUpdate + object:nil]; + if(callQualityTimer != nil) { [callQualityTimer invalidate]; callQualityTimer = nil; @@ -161,19 +173,36 @@ NSTimer *callSecurityTimer; return; } - int unreadCount = 0; - sscanf(body, "voice-message: %d", &unreadCount); + sscanf(body, "voice-message: %d", &messagesUnreadCount); - [LinphoneLogger log:LinphoneLoggerLog format:@"Received new NOTIFY from voice mail: there is/are now %d message(s) unread", unreadCount]; + [LinphoneLogger log:LinphoneLoggerLog format:@"Received new NOTIFY from voice mail: there is/are now %d message(s) unread", messagesUnreadCount]; - if (unreadCount > 0) { - self.voicemailCount.hidden = FALSE; - self.voicemailCount.text = [NSString stringWithFormat:NSLocalizedString(@"%d unread messages", @"%d"), unreadCount]; + // save in lpconfig for future + lp_config_set_int(linphone_core_get_config([LinphoneManager getLc]), "app", "voice_mail_messages_count", messagesUnreadCount); + + [self updateVoicemail]; +} + +- (void) updateVoicemail { + if (messagesUnreadCount > 0) { + self.voicemailCount.hidden = (linphone_core_get_calls([LinphoneManager getLc]) != NULL); + self.voicemailCount.text = [[NSString stringWithFormat:NSLocalizedString(@"%d unread messages", @"%d"), messagesUnreadCount] uppercaseString]; } else { self.voicemailCount.hidden = TRUE; } } +- (void) callUpdate:(NSNotification*) notif { +// LinphoneCall *call = [[notif.userInfo objectForKey: @"call"] pointerValue]; +// LinphoneCallState state = [[notif.userInfo objectForKey: @"state"] intValue]; + + bool isOnCall = [LinphoneManager isLcReady] && (linphone_core_get_calls_nb([LinphoneManager getLc]) > 0); + + //show voicemail only when there is no call + [self updateVoicemail]; +} + + #pragma mark - - (void)proxyConfigUpdate: (LinphoneProxyConfig*) config { @@ -244,6 +273,7 @@ NSTimer *callSecurityTimer; return; } const MSList *list = linphone_core_get_calls([LinphoneManager getLc]); + if(list == NULL) { if(securitySheet) { [securitySheet dismissWithClickedButtonIndex:securitySheet.destructiveButtonIndex animated:TRUE];