From 9413a28869eef38bba69bf3474bb80478ba21043 Mon Sep 17 00:00:00 2001 From: Danmei Chen Date: Wed, 16 Jan 2019 11:57:51 +0100 Subject: [PATCH] enable open files with preview controller --- Classes/ChatConversationView.h | 19 +++++++++-- Classes/ChatConversationView.m | 54 +++++++++++++++++++++++++----- linphone.xcodeproj/project.pbxproj | 10 ++++-- 3 files changed, 69 insertions(+), 14 deletions(-) diff --git a/Classes/ChatConversationView.h b/Classes/ChatConversationView.h index 616e1457a..9f54956a1 100644 --- a/Classes/ChatConversationView.h +++ b/Classes/ChatConversationView.h @@ -18,6 +18,8 @@ */ #import +#import +#import #import "UIToggleButton.h" #import "UICompositeView.h" @@ -32,9 +34,20 @@ #include "linphone/linphonecore.h" +//Quicklook Preview Item +@interface PreviewItem : NSObject +@property(readonly, nonatomic) NSURL *previewItemURL; +@property(readonly, nonatomic) NSString *previewItemTitle; +@end + +//QuickLook Datasource for rending PDF docs +@interface FileDataSource : NSObject +@property (strong, nonatomic) PreviewItem *item; +@end + @interface ChatConversationView : TPMultiLayoutViewController { + UIDocumentInteractionControllerDelegate, UISearchBarDelegate, UIImageViewDeletableDelegate,QLPreviewControllerDelegate, UICollectionViewDataSource> { OrderedDictionary *imageQualities; BOOL scrollOnGrowingEnabled; BOOL composingVisible; @@ -46,6 +59,8 @@ @property(nonatomic) LinphoneChatRoomCbs *chatRoomCbs; @property(nonatomic) Boolean markAsRead; +@property (strong, nonatomic) FileDataSource *FileDataSource; + @property(weak, nonatomic) IBOutlet UIIconButton *backButton; @property(nonatomic, strong) IBOutlet ChatConversationTableView *tableController; @property(weak, nonatomic) IBOutlet HPGrowingTextView *messageField; @@ -63,7 +78,7 @@ @property(weak, nonatomic) IBOutlet UIBackToCallButton *backToCallButton; @property (weak, nonatomic) IBOutlet UIIconButton *infoButton; @property (weak, nonatomic) IBOutlet UILabel *particpantsLabel; -@property (nonatomic, strong) UIDocumentInteractionController *documentInteractionController; +//@property (nonatomic, strong) UIDocumentInteractionController *documentInteractionController; @property NSMutableArray *imagesArray; @property NSMutableArray *assetIdsArray; @property NSMutableArray *qualitySettingsArray; diff --git a/Classes/ChatConversationView.m b/Classes/ChatConversationView.m index db00435b9..72b1b3bf7 100644 --- a/Classes/ChatConversationView.m +++ b/Classes/ChatConversationView.m @@ -26,6 +26,34 @@ #import "UIChatBubbleTextCell.h" #import "DevicesListView.h" +@implementation PreviewItem +- (instancetype)initPreviewURL:(NSURL *)docURL + WithTitle:(NSString *)title { + self = [super init]; + if (self) { + _previewItemURL = [docURL copy]; + _previewItemTitle = [title copy]; + } + return self; +} +@end + +@implementation FileDataSource +- (instancetype)initWithPreviewItem:(PreviewItem *)item { + self = [super init]; + if (self) { + _item = item; + } + return self; +} +- (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller { + return 1; +} +- (id)previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index { + return self.item; +} +@end + @implementation ChatConversationView #pragma mark - Lifecycle Functions @@ -1016,16 +1044,24 @@ void on_chat_room_conference_alert(LinphoneChatRoom *cr, const LinphoneEventLog - (void)openFileWithURL:(NSURL *)url { - // Open the controller. - _documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:url]; - _documentInteractionController.delegate = self; + //create the Quicklook controller. + QLPreviewController *qlController = [[QLPreviewController alloc] init]; - BOOL canOpen = [_documentInteractionController presentOpenInMenuFromRect:CGRectZero inView:self.view animated:YES]; - //NO app can open the file - if (canOpen == NO) { - [[[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Info", nil) message:NSLocalizedString(@"There is no app to open it.", nil) delegate:nil cancelButtonTitle:NSLocalizedString(@"Cancel", nil) otherButtonTitles:nil, nil] show]; - - } + PreviewItem *item = [[PreviewItem alloc] initPreviewURL:url WithTitle:[url lastPathComponent]]; + self.FileDataSource = [[FileDataSource alloc] initWithPreviewItem:item]; + + qlController.dataSource = self.FileDataSource; + qlController.delegate = self; + + //present the document. + [self presentViewController:qlController animated:YES completion:nil]; +} + + +- (void)previewControllerDidDismiss:(QLPreviewController *)controller +{ + // QuickLook: When done button is pushed + [PhoneMainView.instance fullScreen:NO]; } - (NSURL *)getICloudFileUrl:(NSString *)name { diff --git a/linphone.xcodeproj/project.pbxproj b/linphone.xcodeproj/project.pbxproj index 81c3f58e8..9b8c29ed6 100644 --- a/linphone.xcodeproj/project.pbxproj +++ b/linphone.xcodeproj/project.pbxproj @@ -121,6 +121,7 @@ 615A28402180A2620060F920 /* invite_linphone@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 615A283F2180A2620060F920 /* invite_linphone@2x.png */; }; 615A28422180C0870060F920 /* recording.png in Resources */ = {isa = PBXBuildFile; fileRef = 615A28412180C0820060F920 /* recording.png */; }; 615A28442180C0900060F920 /* recording@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 615A28432180C08F0060F920 /* recording@2x.png */; }; + 6180D6FE21EE41A800AD9CB6 /* QuickLook.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6180D6FD21EE41A800AD9CB6 /* QuickLook.framework */; }; 61AE364F20C00B370089D9D3 /* ShareViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 61AE364E20C00B370089D9D3 /* ShareViewController.m */; }; 61AE365220C00B370089D9D3 /* MainInterface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 61AE365020C00B370089D9D3 /* MainInterface.storyboard */; }; 61AE365620C00B370089D9D3 /* linphoneExtension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 61AE364B20C00B370089D9D3 /* linphoneExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; @@ -1109,6 +1110,7 @@ 615A283F2180A2620060F920 /* invite_linphone@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "invite_linphone@2x.png"; sourceTree = ""; }; 615A28412180C0820060F920 /* recording.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = recording.png; sourceTree = ""; }; 615A28432180C08F0060F920 /* recording@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "recording@2x.png"; sourceTree = ""; }; + 6180D6FD21EE41A800AD9CB6 /* QuickLook.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuickLook.framework; path = System/Library/Frameworks/QuickLook.framework; sourceTree = SDKROOT; }; 61AE364B20C00B370089D9D3 /* linphoneExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = linphoneExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; }; 61AE364D20C00B370089D9D3 /* ShareViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ShareViewController.h; sourceTree = ""; }; 61AE364E20C00B370089D9D3 /* ShareViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ShareViewController.m; sourceTree = ""; }; @@ -2076,7 +2078,8 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 61AEBEA321906AFC00F35E7F /* BuildFile in Frameworks */, + 6180D6FE21EE41A800AD9CB6 /* QuickLook.framework in Frameworks */, + 61AEBEA321906AFC00F35E7F /* (null) in Frameworks */, D37DC7181594AF3400B2A5EB /* MessageUI.framework in Frameworks */, 61F1997520C6B1D5006B069A /* AVKit.framework in Frameworks */, 249660951FD6A35F001D55AA /* Photos.framework in Frameworks */, @@ -2504,6 +2507,7 @@ 29B97323FDCFA39411CA2CEA /* Frameworks */ = { isa = PBXGroup; children = ( + 6180D6FD21EE41A800AD9CB6 /* QuickLook.framework */, 22B5F03410CE6B2F00777D97 /* AddressBook.framework */, 22B5EFA210CE50BD00777D97 /* AddressBookUI.framework */, 22405EED1600B4E400B92522 /* AssetsLibrary.framework */, @@ -3732,7 +3736,7 @@ zh_CN, fr, ); - mainGroup = 29B97314FDCFA39411CA2CEA; + mainGroup = 29B97314FDCFA39411CA2CEA /* CustomTemplate */; productRefGroup = 19C28FACFE9D520D11CA2CBB /* Products */; projectDirPath = ""; projectReferences = ( @@ -3847,7 +3851,7 @@ 633FEED41D3CD55A0014B822 /* numpad_7_default@2x.png in Resources */, 633FEEE01D3CD55A0014B822 /* numpad_8_over~ipad@2x.png in Resources */, 633FEDDC1D3CD5590014B822 /* call_start_body_disabled~ipad.png in Resources */, - 63E802DB1C625AEF000D5509 /* BuildFile in Resources */, + 63E802DB1C625AEF000D5509 /* (null) in Resources */, 633FEE2E1D3CD5590014B822 /* color_F.png in Resources */, 633FEDC51D3CD5590014B822 /* call_hangup_disabled@2x.png in Resources */, 633FEEDF1D3CD55A0014B822 /* numpad_8_over~ipad.png in Resources */,