From 4b5eaa3bc58ad737e8c64ea3de6db71c826cad32 Mon Sep 17 00:00:00 2001 From: Benoit Martins Date: Tue, 29 Nov 2022 17:37:36 +0100 Subject: [PATCH] Fix image sharing from gallery, and fix view navigation --- Classes/ChatConversationView.h | 1 + Classes/ChatConversationView.m | 6 +++-- Classes/ChatsListView.h | 2 ++ Classes/ChatsListView.m | 36 ++++++++++++++++++++++--- Classes/LinphoneAppDelegate.m | 12 ++++++++- Classes/PhoneMainView.m | 26 +++++++++++++----- Resources/fr.lproj/Localizable.strings | Bin 74304 -> 74688 bytes 7 files changed, 70 insertions(+), 13 deletions(-) diff --git a/Classes/ChatConversationView.h b/Classes/ChatConversationView.h index 89965a457..edc5eeea6 100644 --- a/Classes/ChatConversationView.h +++ b/Classes/ChatConversationView.h @@ -112,6 +112,7 @@ @property LinphonePlayer *sharedVoicePlayer; @property BOOL showVoiceRecorderView; @property BOOL preservePendingActions; +@property BOOL *sharingMedia; // Reply @property (weak, nonatomic) IBOutlet UIView *replyView; diff --git a/Classes/ChatConversationView.m b/Classes/ChatConversationView.m index 308a453af..11c0a828a 100644 --- a/Classes/ChatConversationView.m +++ b/Classes/ChatConversationView.m @@ -622,9 +622,9 @@ static UICompositeViewDescription *compositeDescription = nil; } - (void)confirmShare:(NSData *)data url:(NSString *)url fileName:(NSString *)fileName { - DTActionSheet *sheet = [[DTActionSheet alloc] initWithTitle:@""]; + DTActionSheet *sheet = [[DTActionSheet alloc] initWithTitle:NSLocalizedString(@"Select or create a conversation to share the file(s)", nil)]; dispatch_async(dispatch_get_main_queue(), ^{ - [sheet addButtonWithTitle:NSLocalizedString(@"send to this conversation", nil) + [sheet addButtonWithTitle:NSLocalizedString(@"Send to this conversation", nil) block:^() { if (![[self.messageField text] isEqualToString:@""]) { [self sendMessageInMessageField:linphone_chat_room_create_empty_message(_chatRoom)]; @@ -812,9 +812,11 @@ static UICompositeViewDescription *compositeDescription = nil; - (IBAction)onBackClick:(id)event { NSString *previousViewName = [PhoneMainView.instance getPreviousViewName]; if ([previousViewName isEqualToString:@"ContactDetailsView"]) { + VIEW(ChatConversationView).sharingMedia = nil; ContactDetailsView *view = VIEW(ContactDetailsView); [PhoneMainView.instance popToView:view.compositeViewDescription]; } else { + VIEW(ChatConversationView).sharingMedia = nil; ChatsListView *view = VIEW(ChatsListView); [PhoneMainView.instance popToView:view.compositeViewDescription]; } diff --git a/Classes/ChatsListView.h b/Classes/ChatsListView.h index c0046957d..143c1cfcb 100644 --- a/Classes/ChatsListView.h +++ b/Classes/ChatsListView.h @@ -43,4 +43,6 @@ - (IBAction)onEditionChangeClick:(id)sender; - (IBAction)onDeleteClick:(id)sender; +-(void) mediaSharing; + @end diff --git a/Classes/ChatsListView.m b/Classes/ChatsListView.m index b6f9316cb..64777a552 100644 --- a/Classes/ChatsListView.m +++ b/Classes/ChatsListView.m @@ -58,20 +58,40 @@ forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:button];*/ - BOOL forwardMode = VIEW(ChatConversationView).pendingForwardMessage != nil; + [self mediaSharing]; +} + +- (void)mediaSharing{ + BOOL forwardMode; + + NSString* groupName = [NSString stringWithFormat:@"group.%@.linphoneExtension",[[NSBundle mainBundle] bundleIdentifier]]; + NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:groupName]; + NSDictionary *dict = [defaults valueForKey:@"photoData"]; + NSDictionary *dictFile = [defaults valueForKey:@"icloudData"]; + NSDictionary *dictUrl = [defaults valueForKey:@"url"]; + if(dict||dictFile||dictUrl) VIEW(ChatConversationView).sharingMedia = TRUE; + + if(VIEW(ChatConversationView).sharingMedia == nil){ + forwardMode = VIEW(ChatConversationView).pendingForwardMessage != nil; + }else{ + forwardMode = VIEW(ChatConversationView).sharingMedia != nil; + } _tableController.editButton.hidden = forwardMode; - _forwardTitle.text = NSLocalizedString(@"Select a discussion or create a new one",nil); + if(VIEW(ChatConversationView).sharingMedia == nil){ + _forwardTitle.text = NSLocalizedString(@"Select a discussion or create a new one",nil); + } + else{ + _forwardTitle.text = NSLocalizedString(@"Select or create a conversation to share the file(s)",nil); + } _forwardTitle.hidden = !forwardMode; _cancelForwardButton.hidden = !forwardMode; _tableController.tableView.frame = CGRectMake(0, 66 + (forwardMode ? _forwardTitle.frame.size.height : 0), _tableController.tableView.frame.size.width, self.view.frame.size.height - 66 - ( forwardMode ? _forwardTitle.frame.size.height : 0 )); _addButton.frame = CGRectMake(forwardMode ? 82 : 0 , _addButton.frame.origin.y, _addButton.frame.size.width, _addButton.frame.size.height); _addGroupChatButton.frame = CGRectMake(forwardMode ? 164 : 82 , _addGroupChatButton.frame.origin.y, _addGroupChatButton.frame.size.width, _addGroupChatButton.frame.size.height); - } - - (void)displayModeChanged{ [self.tableController.tableView reloadData]; } @@ -180,8 +200,16 @@ static UICompositeViewDescription *compositeDescription = nil; } - (IBAction)onCancelForwardClicked:(id)sender { + VIEW(ChatConversationView).sharingMedia = nil; VIEW(ChatConversationView).pendingForwardMessage = nil; + NSString* groupName = [NSString stringWithFormat:@"group.%@.linphoneExtension",[[NSBundle mainBundle] bundleIdentifier]]; + NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:groupName]; + [defaults removeObjectForKey:@"photoData"]; + [defaults removeObjectForKey:@"icloudData"]; + [defaults removeObjectForKey:@"url"]; [PhoneMainView.instance popCurrentView]; } + + @end diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index f594ea452..c4f328b03 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -35,6 +35,8 @@ #import #import "linphoneapp-Swift.h" +#import "SVProgressHUD.h" + #ifdef USE_CRASHLYTICS #include "FIRApp.h" @@ -402,7 +404,15 @@ [PhoneMainView.instance presentViewController:errView animated:YES completion:nil]; } else if([[url scheme] isEqualToString:@"message-linphone"]) { - [PhoneMainView.instance popToView:ChatsListView.compositeViewDescription]; + if ([[PhoneMainView.instance currentView] equal:ChatsListView.compositeViewDescription]) { + VIEW(ChatConversationView).sharingMedia = TRUE; + ChatsListView *view = VIEW(ChatsListView); + [view mediaSharing]; + }else{ + [SVProgressHUD dismiss]; + VIEW(ChatConversationView).sharingMedia = TRUE; + [PhoneMainView.instance popToView:ChatsListView.compositeViewDescription]; + } } else if ([scheme isEqualToString:@"sip"]||[scheme isEqualToString:@"sips"]) { // remove "sip://" from the URI, and do it correctly by taking resourceSpecifier and removing leading and // trailing "/" diff --git a/Classes/PhoneMainView.m b/Classes/PhoneMainView.m index 854d72c36..df6b3617f 100644 --- a/Classes/PhoneMainView.m +++ b/Classes/PhoneMainView.m @@ -453,9 +453,19 @@ static RootViewManager *rootViewManagerInstance = nil; LinphoneManager *lm = LinphoneManager.instance; LOGI(@"%s", linphone_global_state_to_string(linphone_core_get_global_state(LC))); + NSString* groupName = [NSString stringWithFormat:@"group.%@.linphoneExtension",[[NSBundle mainBundle] bundleIdentifier]]; + + + NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:groupName]; + NSDictionary *dict = [defaults valueForKey:@"photoData"]; + NSDictionary *dictFile = [defaults valueForKey:@"icloudData"]; + NSDictionary *dictUrl = [defaults valueForKey:@"url"]; + // If we've been started by a remote push notification, // we'll already be on the corresponding chat conversation view, no need to go anywhere else - if (![[self currentView].name isEqualToString:@"ChatConversationView"]) { + if (dict||dictFile||dictUrl){ + [self changeCurrentView:ChatsListView.compositeViewDescription]; + }else if (![[self currentView].name isEqualToString:@"ChatConversationView"]) { if (linphone_core_get_global_state(LC) != LinphoneGlobalOn) { [self changeCurrentView:DialerView.compositeViewDescription]; @@ -607,7 +617,8 @@ static RootViewManager *rootViewManagerInstance = nil; } [self _changeCurrentView:viewStack.lastObject ?: DialerView.compositeViewDescription transition:[PhoneMainView getBackwardTransition] - animated:ANIMATED]; + animated:ANIMATED + addViewToStack:FALSE]; return [mainViewController getCurrentViewController]; } @@ -621,24 +632,27 @@ static RootViewManager *rootViewManagerInstance = nil; - (void)changeCurrentView:(UICompositeViewDescription *)view { - [self _changeCurrentView:view transition:nil animated:ANIMATED]; + [self _changeCurrentView:view transition:nil animated:ANIMATED addViewToStack:TRUE]; } - (UIViewController *)_changeCurrentView:(UICompositeViewDescription *)view transition:(CATransition *)transition - animated:(BOOL)animated { + animated:(BOOL)animated + addViewToStack:(BOOL)addViewToStack { PhoneMainView *vc = [[RootViewManager instance] setViewControllerForDescription:view]; + LOGI(@"_changeCurrentView : stack size before = %d", [RootViewManager instance].viewDescriptionStack.count); if (![view equal:vc.currentView] || vc != self) { LOGI(@"Change current view to %@", view.name); [self setPreviousViewName:vc.currentView.name]; NSMutableArray *viewStack = [RootViewManager instance].viewDescriptionStack; - [viewStack addObject:view]; + if (addViewToStack) [viewStack addObject:view]; if (animated && transition == nil) transition = [PhoneMainView getTransition:vc.currentView new:view]; [vc.mainViewController setViewTransition:(animated ? transition : nil)]; [vc.mainViewController changeView:view]; vc->currentView = view; } + LOGI(@"_changeCurrentView : stack size after = %d", [RootViewManager instance].viewDescriptionStack.count); //[[RootViewManager instance] setViewControllerForDescription:view]; @@ -653,7 +667,7 @@ static RootViewManager *rootViewManagerInstance = nil; while (viewStack.count > 0 && ![[viewStack lastObject] equal:view]) { [viewStack removeLastObject]; } - return [self _changeCurrentView:view transition:[PhoneMainView getBackwardTransition] animated:ANIMATED]; + return [self _changeCurrentView:view transition:[PhoneMainView getBackwardTransition] animated:ANIMATED addViewToStack:FALSE]; } - (void) setPreviousViewName:(NSString*)previous{ diff --git a/Resources/fr.lproj/Localizable.strings b/Resources/fr.lproj/Localizable.strings index c03e8242c507a735e577ad97d912a4a21bacd7a5..da2f63ca4bd92f76208b11c0a2a6c1da9daf6c7a 100644 GIT binary patch delta 154 zcmX?bgyq0-mJJ!NCwFx7P2TiMYO+R<6n_arK7#^7F+&DJB0~{F>g0(I!kijFz9xeb zgYD$NZrRDdUfCHIfMrX7WI97CP@Mup4v>bZQ(#DA$Ye+cnve;W1B*@%6l4^hyyT^Z ks1i`IEzmGmhCGHcpk