From dfcf39e4bf076c2853ba1e9fe4a4af507e0983bc Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Sat, 8 Jul 2017 18:06:29 -0500 Subject: [PATCH 001/102] Initial commit. Added a new target for the share extension, created an app group to share info between the app and the extension. --- .../Base.lproj/MainInterface.storyboard | 26 +++ Riot Share Extension/Info.plist | 36 ++++ .../Riot Share Extension.entitlements | 10 + Riot Share Extension/ShareViewController.h | 14 ++ Riot Share Extension/ShareViewController.m | 70 +++++++ Riot.xcodeproj/project.pbxproj | 183 ++++++++++++++++++ Riot/Riot.entitlements | 4 + 7 files changed, 343 insertions(+) create mode 100644 Riot Share Extension/Base.lproj/MainInterface.storyboard create mode 100644 Riot Share Extension/Info.plist create mode 100644 Riot Share Extension/Riot Share Extension.entitlements create mode 100644 Riot Share Extension/ShareViewController.h create mode 100644 Riot Share Extension/ShareViewController.m diff --git a/Riot Share Extension/Base.lproj/MainInterface.storyboard b/Riot Share Extension/Base.lproj/MainInterface.storyboard new file mode 100644 index 000000000..85e8a08b3 --- /dev/null +++ b/Riot Share Extension/Base.lproj/MainInterface.storyboard @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Riot Share Extension/Info.plist b/Riot Share Extension/Info.plist new file mode 100644 index 000000000..9f0587146 --- /dev/null +++ b/Riot Share Extension/Info.plist @@ -0,0 +1,36 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleDisplayName + Riot.im + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + XPC! + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + NSExtension + + NSExtensionAttributes + + NSExtensionActivationRule + TRUEPREDICATE + + NSExtensionMainStoryboard + MainInterface + NSExtensionPointIdentifier + com.apple.share-services + + + diff --git a/Riot Share Extension/Riot Share Extension.entitlements b/Riot Share Extension/Riot Share Extension.entitlements new file mode 100644 index 000000000..7dd58ac09 --- /dev/null +++ b/Riot Share Extension/Riot Share Extension.entitlements @@ -0,0 +1,10 @@ + + + + + com.apple.security.application-groups + + group.org.matrix.riot + + + diff --git a/Riot Share Extension/ShareViewController.h b/Riot Share Extension/ShareViewController.h new file mode 100644 index 000000000..8080d984c --- /dev/null +++ b/Riot Share Extension/ShareViewController.h @@ -0,0 +1,14 @@ +// +// ShareViewController.h +// Riot Share Extension +// +// Created by Aram Sargsyan on 7/6/17. +// Copyright © 2017 matrix.org. All rights reserved. +// + +#import +#import + +@interface ShareViewController : UIViewController + +@end diff --git a/Riot Share Extension/ShareViewController.m b/Riot Share Extension/ShareViewController.m new file mode 100644 index 000000000..8c64d1beb --- /dev/null +++ b/Riot Share Extension/ShareViewController.m @@ -0,0 +1,70 @@ +// +// ShareViewController.m +// Riot Share Extension +// +// Created by Aram Sargsyan on 7/6/17. +// Copyright © 2017 matrix.org. All rights reserved. +// + +#import "ShareViewController.h" + +//#import "ReadReceiptsViewController.h" + +//#import + + +@interface ShareViewController () + +@end + +@implementation ShareViewController + +#pragma mark - Lifecycle + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + //UI configuration + self.view.opaque = YES; + + [self.view setBackgroundColor:[UIColor yellowColor]]; + self.view.alpha = 0.5; + + //MatrixSDK test + //NSLog(@"SDK VERSION ====== %@", MatrixSDKVersion); + + //UserDefaults test + //NSUserDefaults *sharedUserDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.org.matrix.riot"]; +} + +- (void)viewDidAppear:(BOOL)animated { + [super viewDidAppear:animated]; + + //[ReadReceiptsViewController openInViewController:self fromContainer:nil withSession:nil]; +} + + +#pragma mark - SLComposeServiceViewController + +- (BOOL)isContentValid +{ + // Do validation of contentText and/or NSExtensionContext attachments here + return YES; +} + +- (void)didSelectPost +{ + // This is called after the user selects Post. Do the upload of contentText and/or NSExtensionContext attachments. + + // Inform the host that we're done, so it un-blocks its UI. Note: Alternatively you could call super's -didSelectPost, which will similarly complete the extension context. + [self.extensionContext completeRequestReturningItems:@[] completionHandler:nil]; +} + +- (NSArray *)configurationItems +{ + // To add configuration options via table cells at the bottom of the sheet, return an array of SLComposeSheetConfigurationItem here. + return @[]; +} + +@end diff --git a/Riot.xcodeproj/project.pbxproj b/Riot.xcodeproj/project.pbxproj index 9f6329224..3de4f9ba6 100644 --- a/Riot.xcodeproj/project.pbxproj +++ b/Riot.xcodeproj/project.pbxproj @@ -9,6 +9,9 @@ /* Begin PBXBuildFile section */ 24B5103E1EFA7083004C6AD2 /* ReadReceiptsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 24B5103D1EFA7083004C6AD2 /* ReadReceiptsViewController.m */; }; 24B510401EFA88CC004C6AD2 /* ReadReceiptsViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 24B5103F1EFA88CC004C6AD2 /* ReadReceiptsViewController.xib */; }; + 24CBEC521F0EAD310093EABB /* ShareViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 24CBEC511F0EAD310093EABB /* ShareViewController.m */; }; + 24CBEC551F0EAD310093EABB /* MainInterface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 24CBEC531F0EAD310093EABB /* MainInterface.storyboard */; }; + 24CBEC591F0EAD310093EABB /* Riot Share Extension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 24CBEC4E1F0EAD310093EABB /* Riot Share Extension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 3205ED7D1E976C8A003D65FA /* DirectoryServerPickerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3205ED7C1E976C8A003D65FA /* DirectoryServerPickerViewController.m */; }; 3205ED841E97725E003D65FA /* DirectoryServerTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 3205ED821E97725E003D65FA /* DirectoryServerTableViewCell.m */; }; 3205ED851E97725E003D65FA /* DirectoryServerTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3205ED831E97725E003D65FA /* DirectoryServerTableViewCell.xib */; }; @@ -466,9 +469,17 @@ F0E05A451EA0F9EB004B83FB /* tab_rooms.png in Resources */ = {isa = PBXBuildFile; fileRef = F0E05A2D1EA0F9EB004B83FB /* tab_rooms.png */; }; F0E05A461EA0F9EB004B83FB /* tab_rooms@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F0E05A2E1EA0F9EB004B83FB /* tab_rooms@2x.png */; }; F0E05A471EA0F9EB004B83FB /* tab_rooms@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = F0E05A2F1EA0F9EB004B83FB /* tab_rooms@3x.png */; }; + FBF371BE240C8AADBC113365 /* libPods-Riot Targets-Riot.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4CB1D3DA81B94A281F404FEC /* libPods-Riot Targets-Riot.a */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ + 24CBEC571F0EAD310093EABB /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = F094A99A1B78D8F000B1FBBF /* Project object */; + proxyType = 1; + remoteGlobalIDString = 24CBEC4D1F0EAD310093EABB; + remoteInfo = "Riot Share Extension"; + }; F094A9BF1B78D8F000B1FBBF /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = F094A99A1B78D8F000B1FBBF /* Project object */; @@ -478,11 +489,31 @@ }; /* End PBXContainerItemProxy section */ +/* Begin PBXCopyFilesBuildPhase section */ + 24CBEC5D1F0EAD310093EABB /* Embed App Extensions */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 13; + files = ( + 24CBEC591F0EAD310093EABB /* Riot Share Extension.appex in Embed App Extensions */, + ); + name = "Embed App Extensions"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + /* Begin PBXFileReference section */ 1129C74A281B080432B1A1A1 /* Pods-Riot.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Riot.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Riot/Pods-Riot.debug.xcconfig"; sourceTree = ""; }; 24B5103C1EFA7083004C6AD2 /* ReadReceiptsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReadReceiptsViewController.h; sourceTree = ""; }; 24B5103D1EFA7083004C6AD2 /* ReadReceiptsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ReadReceiptsViewController.m; sourceTree = ""; }; 24B5103F1EFA88CC004C6AD2 /* ReadReceiptsViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ReadReceiptsViewController.xib; sourceTree = ""; }; + 24CBEC4E1F0EAD310093EABB /* Riot Share Extension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = "Riot Share Extension.appex"; sourceTree = BUILT_PRODUCTS_DIR; }; + 24CBEC501F0EAD310093EABB /* ShareViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ShareViewController.h; sourceTree = ""; }; + 24CBEC511F0EAD310093EABB /* ShareViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ShareViewController.m; sourceTree = ""; }; + 24CBEC541F0EAD310093EABB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/MainInterface.storyboard; sourceTree = ""; }; + 24CBEC561F0EAD310093EABB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 24CBEC5E1F0EB15D0093EABB /* Riot Share Extension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "Riot Share Extension.entitlements"; sourceTree = ""; }; 3205ED7B1E976C8A003D65FA /* DirectoryServerPickerViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DirectoryServerPickerViewController.h; sourceTree = ""; }; 3205ED7C1E976C8A003D65FA /* DirectoryServerPickerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DirectoryServerPickerViewController.m; sourceTree = ""; }; 3205ED811E97725E003D65FA /* DirectoryServerTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DirectoryServerTableViewCell.h; sourceTree = ""; }; @@ -505,7 +536,16 @@ 32FD0A3A1EB0CD9B0072B066 /* BugReportViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BugReportViewController.h; sourceTree = ""; }; 32FD0A3B1EB0CD9B0072B066 /* BugReportViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BugReportViewController.m; sourceTree = ""; }; 32FD0A3C1EB0CD9B0072B066 /* BugReportViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = BugReportViewController.xib; sourceTree = ""; }; + 4AB8072E21D9EC377EDB0ED5 /* Pods-Riot-Riot Share Extension.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Riot-Riot Share Extension.release.xcconfig"; path = "Pods/Target Support Files/Pods-Riot-Riot Share Extension/Pods-Riot-Riot Share Extension.release.xcconfig"; sourceTree = ""; }; + 4CB1D3DA81B94A281F404FEC /* libPods-Riot Targets-Riot.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Riot Targets-Riot.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 51481EE04F8ED8C76DF00CC2 /* Pods-Riot Targets-Riot Share Extension.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Riot Targets-Riot Share Extension.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Riot Targets-Riot Share Extension/Pods-Riot Targets-Riot Share Extension.debug.xcconfig"; sourceTree = ""; }; + 68571F15FD88B1FE4A4DEDE7 /* Pods-Riot Targets-Riot.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Riot Targets-Riot.release.xcconfig"; path = "Pods/Target Support Files/Pods-Riot Targets-Riot/Pods-Riot Targets-Riot.release.xcconfig"; sourceTree = ""; }; + 6B58373020E541A6BF349B58 /* Pods-Riot-Riot Share Extension.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Riot-Riot Share Extension.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Riot-Riot Share Extension/Pods-Riot-Riot Share Extension.debug.xcconfig"; sourceTree = ""; }; 7D8737F782E108CFD6908691 /* libPods-Riot.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Riot.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 819E16C311F0444E87E41D61 /* libPods-Riot-Riot Share Extension.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Riot-Riot Share Extension.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 83D4B8215EAB127C0AA0A3C9 /* Pods-Riot Targets-Riot Share Extension.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Riot Targets-Riot Share Extension.release.xcconfig"; path = "Pods/Target Support Files/Pods-Riot Targets-Riot Share Extension/Pods-Riot Targets-Riot Share Extension.release.xcconfig"; sourceTree = ""; }; + 9D6C6C16BBCEDA740E3D8F79 /* libPods-Riot Targets-Riot Share Extension.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Riot Targets-Riot Share Extension.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + C6EEF4817F530E6D3263CE0B /* libPods-Riot Share Extension.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Riot Share Extension.a"; sourceTree = BUILT_PRODUCTS_DIR; }; F02C1A831E8EB04C0045A404 /* PeopleViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PeopleViewController.h; sourceTree = ""; }; F02C1A841E8EB04C0045A404 /* PeopleViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PeopleViewController.m; sourceTree = ""; }; F05BD79C1E7AEBF800C69941 /* UnifiedSearchViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UnifiedSearchViewController.h; sourceTree = ""; }; @@ -1069,15 +1109,24 @@ F0E05A2D1EA0F9EB004B83FB /* tab_rooms.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = tab_rooms.png; sourceTree = ""; }; F0E05A2E1EA0F9EB004B83FB /* tab_rooms@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "tab_rooms@2x.png"; sourceTree = ""; }; F0E05A2F1EA0F9EB004B83FB /* tab_rooms@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "tab_rooms@3x.png"; sourceTree = ""; }; + F98A1D0268D43A19387BC583 /* Pods-Riot Targets-Riot.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Riot Targets-Riot.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Riot Targets-Riot/Pods-Riot Targets-Riot.debug.xcconfig"; sourceTree = ""; }; F9D678EF54918C036FDEDBF9 /* Pods-Riot.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Riot.release.xcconfig"; path = "Pods/Target Support Files/Pods-Riot/Pods-Riot.release.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ + 24CBEC4B1F0EAD310093EABB /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; F094A99F1B78D8F000B1FBBF /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( E2EAC1A4FBD6FE5228584591 /* libPods-Riot.a in Frameworks */, + FBF371BE240C8AADBC113365 /* libPods-Riot Targets-Riot.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1091,6 +1140,18 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 24CBEC4F1F0EAD310093EABB /* Riot Share Extension */ = { + isa = PBXGroup; + children = ( + 24CBEC5E1F0EB15D0093EABB /* Riot Share Extension.entitlements */, + 24CBEC501F0EAD310093EABB /* ShareViewController.h */, + 24CBEC511F0EAD310093EABB /* ShareViewController.m */, + 24CBEC531F0EAD310093EABB /* MainInterface.storyboard */, + 24CBEC561F0EAD310093EABB /* Info.plist */, + ); + path = "Riot Share Extension"; + sourceTree = ""; + }; 3205ED801E97725E003D65FA /* Directory */ = { isa = PBXGroup; children = ( @@ -1118,6 +1179,10 @@ isa = PBXGroup; children = ( 7D8737F782E108CFD6908691 /* libPods-Riot.a */, + C6EEF4817F530E6D3263CE0B /* libPods-Riot Share Extension.a */, + 819E16C311F0444E87E41D61 /* libPods-Riot-Riot Share Extension.a */, + 4CB1D3DA81B94A281F404FEC /* libPods-Riot Targets-Riot.a */, + 9D6C6C16BBCEDA740E3D8F79 /* libPods-Riot Targets-Riot Share Extension.a */, ); name = Frameworks; sourceTree = ""; @@ -1127,6 +1192,12 @@ children = ( 1129C74A281B080432B1A1A1 /* Pods-Riot.debug.xcconfig */, F9D678EF54918C036FDEDBF9 /* Pods-Riot.release.xcconfig */, + 6B58373020E541A6BF349B58 /* Pods-Riot-Riot Share Extension.debug.xcconfig */, + 4AB8072E21D9EC377EDB0ED5 /* Pods-Riot-Riot Share Extension.release.xcconfig */, + F98A1D0268D43A19387BC583 /* Pods-Riot Targets-Riot.debug.xcconfig */, + 68571F15FD88B1FE4A4DEDE7 /* Pods-Riot Targets-Riot.release.xcconfig */, + 51481EE04F8ED8C76DF00CC2 /* Pods-Riot Targets-Riot Share Extension.debug.xcconfig */, + 83D4B8215EAB127C0AA0A3C9 /* Pods-Riot Targets-Riot Share Extension.release.xcconfig */, ); name = Pods; sourceTree = ""; @@ -1961,6 +2032,7 @@ children = ( F083BB081E7009EC00A9B29C /* Riot */, F083BB021E7005FD00A9B29C /* RiotTests */, + 24CBEC4F1F0EAD310093EABB /* Riot Share Extension */, F094A9A31B78D8F000B1FBBF /* Products */, E1451F540F8BC02A7FB7AA31 /* Pods */, 6567B0BBF3C05D7F7A7F79CC /* Frameworks */, @@ -1972,6 +2044,7 @@ children = ( F094A9A21B78D8F000B1FBBF /* Riot.app */, F094A9BE1B78D8F000B1FBBF /* RiotTests.xctest */, + 24CBEC4E1F0EAD310093EABB /* Riot Share Extension.appex */, ); name = Products; sourceTree = ""; @@ -1979,6 +2052,23 @@ /* End PBXGroup section */ /* Begin PBXNativeTarget section */ + 24CBEC4D1F0EAD310093EABB /* Riot Share Extension */ = { + isa = PBXNativeTarget; + buildConfigurationList = 24CBEC5C1F0EAD310093EABB /* Build configuration list for PBXNativeTarget "Riot Share Extension" */; + buildPhases = ( + 24CBEC4A1F0EAD310093EABB /* Sources */, + 24CBEC4B1F0EAD310093EABB /* Frameworks */, + 24CBEC4C1F0EAD310093EABB /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "Riot Share Extension"; + productName = "Riot Share Extension"; + productReference = 24CBEC4E1F0EAD310093EABB /* Riot Share Extension.appex */; + productType = "com.apple.product-type.app-extension"; + }; F094A9A11B78D8F000B1FBBF /* Riot */ = { isa = PBXNativeTarget; buildConfigurationList = F094A9C81B78D8F000B1FBBF /* Build configuration list for PBXNativeTarget "Riot" */; @@ -1989,10 +2079,12 @@ F094A9A01B78D8F000B1FBBF /* Resources */, 44C35695CFA4F9799C449367 /* [CP] Copy Pods Resources */, 381DA4CC07D2104BFA23E45A /* [CP] Embed Pods Frameworks */, + 24CBEC5D1F0EAD310093EABB /* Embed App Extensions */, ); buildRules = ( ); dependencies = ( + 24CBEC581F0EAD310093EABB /* PBXTargetDependency */, ); name = Riot; productName = Vector; @@ -2026,11 +2118,24 @@ LastUpgradeCheck = 0800; ORGANIZATIONNAME = matrix.org; TargetAttributes = { + 24CBEC4D1F0EAD310093EABB = { + CreatedOnToolsVersion = 8.3.2; + DevelopmentTeam = 7J4U792NQT; + ProvisioningStyle = Automatic; + SystemCapabilities = { + com.apple.ApplicationGroups.iOS = { + enabled = 1; + }; + }; + }; F094A9A11B78D8F000B1FBBF = { CreatedOnToolsVersion = 6.2; DevelopmentTeam = 7J4U792NQT; ProvisioningStyle = Automatic; SystemCapabilities = { + com.apple.ApplicationGroups.iOS = { + enabled = 1; + }; com.apple.Push = { enabled = 1; }; @@ -2059,11 +2164,20 @@ targets = ( F094A9A11B78D8F000B1FBBF /* Riot */, F094A9BD1B78D8F000B1FBBF /* RiotTests */, + 24CBEC4D1F0EAD310093EABB /* Riot Share Extension */, ); }; /* End PBXProject section */ /* Begin PBXResourcesBuildPhase section */ + 24CBEC4C1F0EAD310093EABB /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 24CBEC551F0EAD310093EABB /* MainInterface.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; F094A9A01B78D8F000B1FBBF /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -2459,6 +2573,14 @@ /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ + 24CBEC4A1F0EAD310093EABB /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 24CBEC521F0EAD310093EABB /* ShareViewController.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; F094A99E1B78D8F000B1FBBF /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -2604,6 +2726,11 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ + 24CBEC581F0EAD310093EABB /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 24CBEC4D1F0EAD310093EABB /* Riot Share Extension */; + targetProxy = 24CBEC571F0EAD310093EABB /* PBXContainerItemProxy */; + }; F094A9C01B78D8F000B1FBBF /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = F094A9A11B78D8F000B1FBBF /* Riot */; @@ -2612,6 +2739,14 @@ /* End PBXTargetDependency section */ /* Begin PBXVariantGroup section */ + 24CBEC531F0EAD310093EABB /* MainInterface.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 24CBEC541F0EAD310093EABB /* Base */, + ); + name = MainInterface.storyboard; + sourceTree = ""; + }; 325E1C131E8D03950018D91E /* LaunchScreen.storyboard */ = { isa = PBXVariantGroup; children = ( @@ -2679,6 +2814,45 @@ /* End PBXVariantGroup section */ /* Begin XCBuildConfiguration section */ + 24CBEC5A1F0EAD310093EABB /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + APPLICATION_EXTENSION_API_ONLY = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CODE_SIGN_ENTITLEMENTS = "Riot Share Extension/Riot Share Extension.entitlements"; + DEBUG_INFORMATION_FORMAT = dwarf; + DEVELOPMENT_TEAM = 7J4U792NQT; + INFOPLIST_FILE = "Riot Share Extension/Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "im.vector.app.Riot-Share-Extension"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + }; + name = Debug; + }; + 24CBEC5B1F0EAD310093EABB /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + APPLICATION_EXTENSION_API_ONLY = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CODE_SIGN_ENTITLEMENTS = "Riot Share Extension/Riot Share Extension.entitlements"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + DEVELOPMENT_TEAM = 7J4U792NQT; + INFOPLIST_FILE = "Riot Share Extension/Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "im.vector.app.Riot-Share-Extension"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SKIP_INSTALL = YES; + }; + name = Release; + }; F094A9C61B78D8F000B1FBBF /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { @@ -2840,6 +3014,15 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ + 24CBEC5C1F0EAD310093EABB /* Build configuration list for PBXNativeTarget "Riot Share Extension" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 24CBEC5A1F0EAD310093EABB /* Debug */, + 24CBEC5B1F0EAD310093EABB /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; F094A99D1B78D8F000B1FBBF /* Build configuration list for PBXProject "Riot" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/Riot/Riot.entitlements b/Riot/Riot.entitlements index 4cbad96a1..e9e76f7b2 100644 --- a/Riot/Riot.entitlements +++ b/Riot/Riot.entitlements @@ -11,5 +11,9 @@ applinks:riot.im applinks:www.riot.im + com.apple.security.application-groups + + group.org.matrix.riot + From 2df475a26b1d6a0984e9ee1be9a4f5513c3531b0 Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Sat, 8 Jul 2017 23:08:48 -0500 Subject: [PATCH 002/102] Fix project file --- Riot.xcodeproj/project.pbxproj | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/Riot.xcodeproj/project.pbxproj b/Riot.xcodeproj/project.pbxproj index 3de4f9ba6..d4f08ce6b 100644 --- a/Riot.xcodeproj/project.pbxproj +++ b/Riot.xcodeproj/project.pbxproj @@ -469,7 +469,6 @@ F0E05A451EA0F9EB004B83FB /* tab_rooms.png in Resources */ = {isa = PBXBuildFile; fileRef = F0E05A2D1EA0F9EB004B83FB /* tab_rooms.png */; }; F0E05A461EA0F9EB004B83FB /* tab_rooms@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F0E05A2E1EA0F9EB004B83FB /* tab_rooms@2x.png */; }; F0E05A471EA0F9EB004B83FB /* tab_rooms@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = F0E05A2F1EA0F9EB004B83FB /* tab_rooms@3x.png */; }; - FBF371BE240C8AADBC113365 /* libPods-Riot Targets-Riot.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 4CB1D3DA81B94A281F404FEC /* libPods-Riot Targets-Riot.a */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -537,14 +536,9 @@ 32FD0A3B1EB0CD9B0072B066 /* BugReportViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BugReportViewController.m; sourceTree = ""; }; 32FD0A3C1EB0CD9B0072B066 /* BugReportViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = BugReportViewController.xib; sourceTree = ""; }; 4AB8072E21D9EC377EDB0ED5 /* Pods-Riot-Riot Share Extension.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Riot-Riot Share Extension.release.xcconfig"; path = "Pods/Target Support Files/Pods-Riot-Riot Share Extension/Pods-Riot-Riot Share Extension.release.xcconfig"; sourceTree = ""; }; - 4CB1D3DA81B94A281F404FEC /* libPods-Riot Targets-Riot.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Riot Targets-Riot.a"; sourceTree = BUILT_PRODUCTS_DIR; }; - 51481EE04F8ED8C76DF00CC2 /* Pods-Riot Targets-Riot Share Extension.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Riot Targets-Riot Share Extension.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Riot Targets-Riot Share Extension/Pods-Riot Targets-Riot Share Extension.debug.xcconfig"; sourceTree = ""; }; - 68571F15FD88B1FE4A4DEDE7 /* Pods-Riot Targets-Riot.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Riot Targets-Riot.release.xcconfig"; path = "Pods/Target Support Files/Pods-Riot Targets-Riot/Pods-Riot Targets-Riot.release.xcconfig"; sourceTree = ""; }; 6B58373020E541A6BF349B58 /* Pods-Riot-Riot Share Extension.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Riot-Riot Share Extension.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Riot-Riot Share Extension/Pods-Riot-Riot Share Extension.debug.xcconfig"; sourceTree = ""; }; 7D8737F782E108CFD6908691 /* libPods-Riot.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Riot.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 819E16C311F0444E87E41D61 /* libPods-Riot-Riot Share Extension.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Riot-Riot Share Extension.a"; sourceTree = BUILT_PRODUCTS_DIR; }; - 83D4B8215EAB127C0AA0A3C9 /* Pods-Riot Targets-Riot Share Extension.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Riot Targets-Riot Share Extension.release.xcconfig"; path = "Pods/Target Support Files/Pods-Riot Targets-Riot Share Extension/Pods-Riot Targets-Riot Share Extension.release.xcconfig"; sourceTree = ""; }; - 9D6C6C16BBCEDA740E3D8F79 /* libPods-Riot Targets-Riot Share Extension.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Riot Targets-Riot Share Extension.a"; sourceTree = BUILT_PRODUCTS_DIR; }; C6EEF4817F530E6D3263CE0B /* libPods-Riot Share Extension.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Riot Share Extension.a"; sourceTree = BUILT_PRODUCTS_DIR; }; F02C1A831E8EB04C0045A404 /* PeopleViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PeopleViewController.h; sourceTree = ""; }; F02C1A841E8EB04C0045A404 /* PeopleViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PeopleViewController.m; sourceTree = ""; }; @@ -1109,7 +1103,6 @@ F0E05A2D1EA0F9EB004B83FB /* tab_rooms.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = tab_rooms.png; sourceTree = ""; }; F0E05A2E1EA0F9EB004B83FB /* tab_rooms@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "tab_rooms@2x.png"; sourceTree = ""; }; F0E05A2F1EA0F9EB004B83FB /* tab_rooms@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "tab_rooms@3x.png"; sourceTree = ""; }; - F98A1D0268D43A19387BC583 /* Pods-Riot Targets-Riot.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Riot Targets-Riot.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Riot Targets-Riot/Pods-Riot Targets-Riot.debug.xcconfig"; sourceTree = ""; }; F9D678EF54918C036FDEDBF9 /* Pods-Riot.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Riot.release.xcconfig"; path = "Pods/Target Support Files/Pods-Riot/Pods-Riot.release.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ @@ -1126,7 +1119,6 @@ buildActionMask = 2147483647; files = ( E2EAC1A4FBD6FE5228584591 /* libPods-Riot.a in Frameworks */, - FBF371BE240C8AADBC113365 /* libPods-Riot Targets-Riot.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1181,8 +1173,6 @@ 7D8737F782E108CFD6908691 /* libPods-Riot.a */, C6EEF4817F530E6D3263CE0B /* libPods-Riot Share Extension.a */, 819E16C311F0444E87E41D61 /* libPods-Riot-Riot Share Extension.a */, - 4CB1D3DA81B94A281F404FEC /* libPods-Riot Targets-Riot.a */, - 9D6C6C16BBCEDA740E3D8F79 /* libPods-Riot Targets-Riot Share Extension.a */, ); name = Frameworks; sourceTree = ""; @@ -1194,10 +1184,6 @@ F9D678EF54918C036FDEDBF9 /* Pods-Riot.release.xcconfig */, 6B58373020E541A6BF349B58 /* Pods-Riot-Riot Share Extension.debug.xcconfig */, 4AB8072E21D9EC377EDB0ED5 /* Pods-Riot-Riot Share Extension.release.xcconfig */, - F98A1D0268D43A19387BC583 /* Pods-Riot Targets-Riot.debug.xcconfig */, - 68571F15FD88B1FE4A4DEDE7 /* Pods-Riot Targets-Riot.release.xcconfig */, - 51481EE04F8ED8C76DF00CC2 /* Pods-Riot Targets-Riot Share Extension.debug.xcconfig */, - 83D4B8215EAB127C0AA0A3C9 /* Pods-Riot Targets-Riot Share Extension.release.xcconfig */, ); name = Pods; sourceTree = ""; From 90be1ff34bccc636bce87d2c4315ef889b860ed0 Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Mon, 10 Jul 2017 00:23:55 -0500 Subject: [PATCH 003/102] Using the App Extension compaitable versions of the MatrixSDK and MatrioxKit for the Share Extension. --- Podfile | 27 ++++- Podfile.lock | 46 +++++++- Riot Share Extension/ShareViewController.h | 22 ++-- Riot Share Extension/ShareViewController.m | 48 ++++---- Riot.xcodeproj/project.pbxproj | 130 +++++++++++++-------- 5 files changed, 184 insertions(+), 89 deletions(-) diff --git a/Podfile b/Podfile index dee294bb5..9ea336f34 100644 --- a/Podfile +++ b/Podfile @@ -8,9 +8,9 @@ target "Riot" do # Different flavours of pods to MatrixKit # The tagged version on which this version of Riot has been built -pod 'MatrixKit', '0.5.2' +#pod 'MatrixKit', '0.5.2' -# The lastest release available on the CocoaPods repository +# The lastest release available on the CocoaPods repository #pod 'MatrixKit' # The develop branch version @@ -19,8 +19,8 @@ pod 'MatrixKit', '0.5.2' # The one used for developing both MatrixSDK and MatrixKit # Note that MatrixSDK must be cloned into a folder called matrix-ios-sdk next to the MatrixKit folder -#pod 'MatrixKit', :path => '../matrix-ios-kit/MatrixKit.podspec' -#pod 'MatrixSDK', :path => '../matrix-ios-sdk/MatrixSDK.podspec' +pod 'MatrixKit', :path => '../matrix-ios-kit/MatrixKit.podspec' +pod 'MatrixSDK', :path => '../matrix-ios-sdk/MatrixSDK.podspec' pod 'GBDeviceInfo', '~> 4.3.0' @@ -38,6 +38,25 @@ pod 'Realm', '~> 2.8.1' pod 'OLMKit', :inhibit_warnings => true pod 'cmark', :inhibit_warnings => true pod 'DTCoreText', :inhibit_warnings => true + +end + + +target "RiotShareExtension" do + +pod 'GoogleAnalytics' +# The Google WebRTC stack +pod 'WebRTC', '58.17.16937' +# OLMKit for crypto +pod 'OLMKit' +#pod 'OLMKit', :path => '../olm/OLMKit.podspec' +pod 'Realm', '~> 2.8.1' + +pod 'MatrixSDK/AppExtension', :path => '../matrix-ios-sdk/MatrixSDK.podspec' +pod 'MatrixKit/AppExtension', :path => '../matrix-ios-kitMatrixKit.podspec' end + + + diff --git a/Podfile.lock b/Podfile.lock index 34664183d..12508a98a 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -26,6 +26,11 @@ PODS: - DTFoundation/DTAnimatedGIF (~> 1.7.5) - DTFoundation/DTHTMLParser (~> 1.7.5) - DTFoundation/UIKit (~> 1.7.5) + - DTCoreText/Extension (1.6.20): + - DTFoundation/Core (~> 1.7.5) + - DTFoundation/DTAnimatedGIF (~> 1.7.5) + - DTFoundation/DTHTMLParser (~> 1.7.5) + - DTFoundation/UIKit (~> 1.7.5) - DTFoundation/Core (1.7.12) - DTFoundation/DTAnimatedGIF (1.7.12) - DTFoundation/DTHTMLParser (1.7.12): @@ -41,13 +46,33 @@ PODS: - libPhoneNumber-iOS (0.9.10) - MatrixKit (0.5.2): - cmark (~> 0.24.1) - - DTCoreText (~> 1.6.17) - HPGrowingTextView (~> 1.1) - libPhoneNumber-iOS (~> 0.9.10) - - MatrixSDK (= 0.8.2) + - MatrixKit/Core (= 0.5.2) + - MatrixKit/AppExtension (0.5.2): + - cmark (~> 0.24.1) + - DTCoreText/Extension + - HPGrowingTextView (~> 1.1) + - libPhoneNumber-iOS (~> 0.9.10) + - MatrixKit/Core + - MatrixSDK/AppExtension + - MatrixKit/Core (0.5.2): + - cmark (~> 0.24.1) + - DTCoreText + - HPGrowingTextView (~> 1.1) + - libPhoneNumber-iOS (~> 0.9.10) + - MatrixSDK/Core - MatrixSDK (0.8.2): - AFNetworking (~> 3.1.0) - GZIP (~> 1.1.1) + - MatrixSDK/Core (= 0.8.2) + - MatrixSDK/AppExtension (0.8.2): + - AFNetworking (~> 3.1.0) + - GZIP (~> 1.1.1) + - MatrixSDK/Core + - MatrixSDK/Core (0.8.2): + - AFNetworking (~> 3.1.0) + - GZIP (~> 1.1.1) - OLMKit (2.2.2): - OLMKit/olmc (= 2.2.2) - OLMKit/olmcpp (= 2.2.2) @@ -63,11 +88,20 @@ DEPENDENCIES: - DTCoreText - GBDeviceInfo (~> 4.3.0) - GoogleAnalytics - - MatrixKit (= 0.5.2) + - MatrixKit (from `../matrix-ios-kit/MatrixKit.podspec`) + - MatrixKit/AppExtension (from `../matrix-ios-kit/MatrixKit.podspec`) + - MatrixSDK (from `../matrix-ios-sdk/MatrixSDK.podspec`) + - MatrixSDK/AppExtension (from `../matrix-ios-sdk/MatrixSDK.podspec`) - OLMKit - Realm (~> 2.8.1) - WebRTC (= 58.17.16937) +EXTERNAL SOURCES: + MatrixKit: + :path: ../matrix-ios-kit/MatrixKit.podspec + MatrixSDK: + :path: ../matrix-ios-sdk/MatrixSDK.podspec + SPEC CHECKSUMS: AFNetworking: 5e0e199f73d8626b11e79750991f5d173d1f8b67 cmark: ec0275215b504780287b6fca360224e384368af8 @@ -78,12 +112,12 @@ SPEC CHECKSUMS: GZIP: f8beb59597f651e6970a45b816508a9c6d700b77 HPGrowingTextView: 88a716d97fb853bcb08a4a08e4727da17efc9b19 libPhoneNumber-iOS: f721ae4d5854bce60934f9fb9b0b28e8e68913cb - MatrixKit: daad23e5724d8f26a44a322f4d259a26b614ddc6 - MatrixSDK: 1f9b5fa6334485c431884d2d2ea9ac5f65557528 + MatrixKit: ca0494158f6acaf725e31ef94b7a481c5280b6ae + MatrixSDK: 3210d156fee0d4628dbe9180bb1709cfb155cf31 OLMKit: b9d8c0ffee9ea8c45bc0aaa9afb47f93fba7efbd Realm: 3601ef091c8c499a31101d8563b991e75546cdce WebRTC: 1e9a85bf75509eec44be6478c64e9de65ac82332 -PODFILE CHECKSUM: ba9311a74b4af32f75db5053d87c9f7181a42d17 +PODFILE CHECKSUM: 72052e939c3aeb10e1f729ff8e934cc1f3dc7d72 COCOAPODS: 1.2.1 diff --git a/Riot Share Extension/ShareViewController.h b/Riot Share Extension/ShareViewController.h index 8080d984c..bb08cdc97 100644 --- a/Riot Share Extension/ShareViewController.h +++ b/Riot Share Extension/ShareViewController.h @@ -1,10 +1,18 @@ -// -// ShareViewController.h -// Riot Share Extension -// -// Created by Aram Sargsyan on 7/6/17. -// Copyright © 2017 matrix.org. All rights reserved. -// +/* + Copyright 2017 Aram Sargsyan + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ #import #import diff --git a/Riot Share Extension/ShareViewController.m b/Riot Share Extension/ShareViewController.m index 8c64d1beb..218cbfced 100644 --- a/Riot Share Extension/ShareViewController.m +++ b/Riot Share Extension/ShareViewController.m @@ -1,21 +1,24 @@ -// -// ShareViewController.m -// Riot Share Extension -// -// Created by Aram Sargsyan on 7/6/17. -// Copyright © 2017 matrix.org. All rights reserved. -// +/* + Copyright 2017 Aram Sargsyan + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ #import "ShareViewController.h" -//#import "ReadReceiptsViewController.h" +#import +#import -//#import - - -@interface ShareViewController () - -@end @implementation ShareViewController @@ -26,26 +29,21 @@ [super viewDidLoad]; //UI configuration - self.view.opaque = YES; - [self.view setBackgroundColor:[UIColor yellowColor]]; self.view.alpha = 0.5; //MatrixSDK test - //NSLog(@"SDK VERSION ====== %@", MatrixSDKVersion); + NSLog(@"SDK VERSION ====== %@", MatrixSDKVersion); + + //MatrixKit test + NSLog(@"KIT VERSION ====== %@", MatrixKitVersion); //UserDefaults test //NSUserDefaults *sharedUserDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.org.matrix.riot"]; } -- (void)viewDidAppear:(BOOL)animated { - [super viewDidAppear:animated]; - - //[ReadReceiptsViewController openInViewController:self fromContainer:nil withSession:nil]; -} - -#pragma mark - SLComposeServiceViewController +/*#pragma mark - SLComposeServiceViewController - (BOOL)isContentValid { @@ -65,6 +63,6 @@ { // To add configuration options via table cells at the bottom of the sheet, return an array of SLComposeSheetConfigurationItem here. return @[]; -} +}*/ @end diff --git a/Riot.xcodeproj/project.pbxproj b/Riot.xcodeproj/project.pbxproj index d4f08ce6b..313b9e3b4 100644 --- a/Riot.xcodeproj/project.pbxproj +++ b/Riot.xcodeproj/project.pbxproj @@ -7,11 +7,12 @@ objects = { /* Begin PBXBuildFile section */ + 05D592A32FF1D1877B89F73C /* libPods-Riot.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD9D0BDE9232898950554DD5 /* libPods-Riot.a */; }; 24B5103E1EFA7083004C6AD2 /* ReadReceiptsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 24B5103D1EFA7083004C6AD2 /* ReadReceiptsViewController.m */; }; 24B510401EFA88CC004C6AD2 /* ReadReceiptsViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 24B5103F1EFA88CC004C6AD2 /* ReadReceiptsViewController.xib */; }; 24CBEC521F0EAD310093EABB /* ShareViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 24CBEC511F0EAD310093EABB /* ShareViewController.m */; }; 24CBEC551F0EAD310093EABB /* MainInterface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 24CBEC531F0EAD310093EABB /* MainInterface.storyboard */; }; - 24CBEC591F0EAD310093EABB /* Riot Share Extension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 24CBEC4E1F0EAD310093EABB /* Riot Share Extension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; + 24CBEC591F0EAD310093EABB /* RiotShareExtension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 24CBEC4E1F0EAD310093EABB /* RiotShareExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 3205ED7D1E976C8A003D65FA /* DirectoryServerPickerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3205ED7C1E976C8A003D65FA /* DirectoryServerPickerViewController.m */; }; 3205ED841E97725E003D65FA /* DirectoryServerTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 3205ED821E97725E003D65FA /* DirectoryServerTableViewCell.m */; }; 3205ED851E97725E003D65FA /* DirectoryServerTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3205ED831E97725E003D65FA /* DirectoryServerTableViewCell.xib */; }; @@ -28,7 +29,7 @@ 32D392191EB9B7AB009A2BAF /* DirectoryServerDetailTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 32D392171EB9B7AB009A2BAF /* DirectoryServerDetailTableViewCell.xib */; }; 32FD0A3D1EB0CD9B0072B066 /* BugReportViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 32FD0A3B1EB0CD9B0072B066 /* BugReportViewController.m */; }; 32FD0A3E1EB0CD9B0072B066 /* BugReportViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 32FD0A3C1EB0CD9B0072B066 /* BugReportViewController.xib */; }; - E2EAC1A4FBD6FE5228584591 /* libPods-Riot.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7D8737F782E108CFD6908691 /* libPods-Riot.a */; }; + A27ECCE3FC4971745D2CB78D /* libPods-RiotShareExtension.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7246451C668D6782166E22EC /* libPods-RiotShareExtension.a */; }; F02C1A861E8EB04C0045A404 /* PeopleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F02C1A841E8EB04C0045A404 /* PeopleViewController.m */; }; F05BD79E1E7AEBF800C69941 /* UnifiedSearchViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F05BD79D1E7AEBF800C69941 /* UnifiedSearchViewController.m */; }; F05BD7A11E7C0E4500C69941 /* MasterTabBarController.m in Sources */ = {isa = PBXBuildFile; fileRef = F05BD7A01E7C0E4500C69941 /* MasterTabBarController.m */; }; @@ -472,7 +473,7 @@ /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ - 24CBEC571F0EAD310093EABB /* PBXContainerItemProxy */ = { + 242661F51F12B1BA00D3FC08 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = F094A99A1B78D8F000B1FBBF /* Project object */; proxyType = 1; @@ -495,7 +496,7 @@ dstPath = ""; dstSubfolderSpec = 13; files = ( - 24CBEC591F0EAD310093EABB /* Riot Share Extension.appex in Embed App Extensions */, + 24CBEC591F0EAD310093EABB /* RiotShareExtension.appex in Embed App Extensions */, ); name = "Embed App Extensions"; runOnlyForDeploymentPostprocessing = 0; @@ -503,11 +504,11 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 1129C74A281B080432B1A1A1 /* Pods-Riot.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Riot.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Riot/Pods-Riot.debug.xcconfig"; sourceTree = ""; }; + 12AA0005C8B3D8D8162584C5 /* Pods-RiotShareExtension.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RiotShareExtension.debug.xcconfig"; path = "Pods/Target Support Files/Pods-RiotShareExtension/Pods-RiotShareExtension.debug.xcconfig"; sourceTree = ""; }; 24B5103C1EFA7083004C6AD2 /* ReadReceiptsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReadReceiptsViewController.h; sourceTree = ""; }; 24B5103D1EFA7083004C6AD2 /* ReadReceiptsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ReadReceiptsViewController.m; sourceTree = ""; }; 24B5103F1EFA88CC004C6AD2 /* ReadReceiptsViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ReadReceiptsViewController.xib; sourceTree = ""; }; - 24CBEC4E1F0EAD310093EABB /* Riot Share Extension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = "Riot Share Extension.appex"; sourceTree = BUILT_PRODUCTS_DIR; }; + 24CBEC4E1F0EAD310093EABB /* RiotShareExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = RiotShareExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; }; 24CBEC501F0EAD310093EABB /* ShareViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ShareViewController.h; sourceTree = ""; }; 24CBEC511F0EAD310093EABB /* ShareViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ShareViewController.m; sourceTree = ""; }; 24CBEC541F0EAD310093EABB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/MainInterface.storyboard; sourceTree = ""; }; @@ -535,11 +536,10 @@ 32FD0A3A1EB0CD9B0072B066 /* BugReportViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BugReportViewController.h; sourceTree = ""; }; 32FD0A3B1EB0CD9B0072B066 /* BugReportViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BugReportViewController.m; sourceTree = ""; }; 32FD0A3C1EB0CD9B0072B066 /* BugReportViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = BugReportViewController.xib; sourceTree = ""; }; - 4AB8072E21D9EC377EDB0ED5 /* Pods-Riot-Riot Share Extension.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Riot-Riot Share Extension.release.xcconfig"; path = "Pods/Target Support Files/Pods-Riot-Riot Share Extension/Pods-Riot-Riot Share Extension.release.xcconfig"; sourceTree = ""; }; - 6B58373020E541A6BF349B58 /* Pods-Riot-Riot Share Extension.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Riot-Riot Share Extension.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Riot-Riot Share Extension/Pods-Riot-Riot Share Extension.debug.xcconfig"; sourceTree = ""; }; - 7D8737F782E108CFD6908691 /* libPods-Riot.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Riot.a"; sourceTree = BUILT_PRODUCTS_DIR; }; - 819E16C311F0444E87E41D61 /* libPods-Riot-Riot Share Extension.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Riot-Riot Share Extension.a"; sourceTree = BUILT_PRODUCTS_DIR; }; - C6EEF4817F530E6D3263CE0B /* libPods-Riot Share Extension.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Riot Share Extension.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 7246451C668D6782166E22EC /* libPods-RiotShareExtension.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-RiotShareExtension.a"; sourceTree = BUILT_PRODUCTS_DIR; }; + 765F5104DB3EC39713DEB3A4 /* Pods-RiotShareExtension.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RiotShareExtension.release.xcconfig"; path = "Pods/Target Support Files/Pods-RiotShareExtension/Pods-RiotShareExtension.release.xcconfig"; sourceTree = ""; }; + 839BB91240D350D5607D55BA /* Pods-Riot.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Riot.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Riot/Pods-Riot.debug.xcconfig"; sourceTree = ""; }; + C195C53961EA28E6900AEB68 /* Pods-Riot.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Riot.release.xcconfig"; path = "Pods/Target Support Files/Pods-Riot/Pods-Riot.release.xcconfig"; sourceTree = ""; }; F02C1A831E8EB04C0045A404 /* PeopleViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PeopleViewController.h; sourceTree = ""; }; F02C1A841E8EB04C0045A404 /* PeopleViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PeopleViewController.m; sourceTree = ""; }; F05BD79C1E7AEBF800C69941 /* UnifiedSearchViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UnifiedSearchViewController.h; sourceTree = ""; }; @@ -1103,7 +1103,7 @@ F0E05A2D1EA0F9EB004B83FB /* tab_rooms.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = tab_rooms.png; sourceTree = ""; }; F0E05A2E1EA0F9EB004B83FB /* tab_rooms@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "tab_rooms@2x.png"; sourceTree = ""; }; F0E05A2F1EA0F9EB004B83FB /* tab_rooms@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "tab_rooms@3x.png"; sourceTree = ""; }; - F9D678EF54918C036FDEDBF9 /* Pods-Riot.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Riot.release.xcconfig"; path = "Pods/Target Support Files/Pods-Riot/Pods-Riot.release.xcconfig"; sourceTree = ""; }; + FD9D0BDE9232898950554DD5 /* libPods-Riot.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Riot.a"; sourceTree = BUILT_PRODUCTS_DIR; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -1111,6 +1111,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + A27ECCE3FC4971745D2CB78D /* libPods-RiotShareExtension.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1118,7 +1119,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - E2EAC1A4FBD6FE5228584591 /* libPods-Riot.a in Frameworks */, + 05D592A32FF1D1877B89F73C /* libPods-Riot.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1167,23 +1168,22 @@ path = nl.lproj; sourceTree = ""; }; - 6567B0BBF3C05D7F7A7F79CC /* Frameworks */ = { + 5FC42FA41F5186AFFB6A2404 /* Frameworks */ = { isa = PBXGroup; children = ( - 7D8737F782E108CFD6908691 /* libPods-Riot.a */, - C6EEF4817F530E6D3263CE0B /* libPods-Riot Share Extension.a */, - 819E16C311F0444E87E41D61 /* libPods-Riot-Riot Share Extension.a */, + FD9D0BDE9232898950554DD5 /* libPods-Riot.a */, + 7246451C668D6782166E22EC /* libPods-RiotShareExtension.a */, ); name = Frameworks; sourceTree = ""; }; - E1451F540F8BC02A7FB7AA31 /* Pods */ = { + 7471DF3720D498384A068DA7 /* Pods */ = { isa = PBXGroup; children = ( - 1129C74A281B080432B1A1A1 /* Pods-Riot.debug.xcconfig */, - F9D678EF54918C036FDEDBF9 /* Pods-Riot.release.xcconfig */, - 6B58373020E541A6BF349B58 /* Pods-Riot-Riot Share Extension.debug.xcconfig */, - 4AB8072E21D9EC377EDB0ED5 /* Pods-Riot-Riot Share Extension.release.xcconfig */, + 839BB91240D350D5607D55BA /* Pods-Riot.debug.xcconfig */, + C195C53961EA28E6900AEB68 /* Pods-Riot.release.xcconfig */, + 12AA0005C8B3D8D8162584C5 /* Pods-RiotShareExtension.debug.xcconfig */, + 765F5104DB3EC39713DEB3A4 /* Pods-RiotShareExtension.release.xcconfig */, ); name = Pods; sourceTree = ""; @@ -2020,8 +2020,8 @@ F083BB021E7005FD00A9B29C /* RiotTests */, 24CBEC4F1F0EAD310093EABB /* Riot Share Extension */, F094A9A31B78D8F000B1FBBF /* Products */, - E1451F540F8BC02A7FB7AA31 /* Pods */, - 6567B0BBF3C05D7F7A7F79CC /* Frameworks */, + 7471DF3720D498384A068DA7 /* Pods */, + 5FC42FA41F5186AFFB6A2404 /* Frameworks */, ); sourceTree = ""; }; @@ -2030,7 +2030,7 @@ children = ( F094A9A21B78D8F000B1FBBF /* Riot.app */, F094A9BE1B78D8F000B1FBBF /* RiotTests.xctest */, - 24CBEC4E1F0EAD310093EABB /* Riot Share Extension.appex */, + 24CBEC4E1F0EAD310093EABB /* RiotShareExtension.appex */, ); name = Products; sourceTree = ""; @@ -2038,39 +2038,41 @@ /* End PBXGroup section */ /* Begin PBXNativeTarget section */ - 24CBEC4D1F0EAD310093EABB /* Riot Share Extension */ = { + 24CBEC4D1F0EAD310093EABB /* RiotShareExtension */ = { isa = PBXNativeTarget; - buildConfigurationList = 24CBEC5C1F0EAD310093EABB /* Build configuration list for PBXNativeTarget "Riot Share Extension" */; + buildConfigurationList = 24CBEC5C1F0EAD310093EABB /* Build configuration list for PBXNativeTarget "RiotShareExtension" */; buildPhases = ( + 3051A9ED306E05F8AE91C906 /* [CP] Check Pods Manifest.lock */, 24CBEC4A1F0EAD310093EABB /* Sources */, 24CBEC4B1F0EAD310093EABB /* Frameworks */, 24CBEC4C1F0EAD310093EABB /* Resources */, + 8EA19F5011654D3BD5EDAC33 /* [CP] Copy Pods Resources */, ); buildRules = ( ); dependencies = ( ); - name = "Riot Share Extension"; + name = RiotShareExtension; productName = "Riot Share Extension"; - productReference = 24CBEC4E1F0EAD310093EABB /* Riot Share Extension.appex */; + productReference = 24CBEC4E1F0EAD310093EABB /* RiotShareExtension.appex */; productType = "com.apple.product-type.app-extension"; }; F094A9A11B78D8F000B1FBBF /* Riot */ = { isa = PBXNativeTarget; buildConfigurationList = F094A9C81B78D8F000B1FBBF /* Build configuration list for PBXNativeTarget "Riot" */; buildPhases = ( - 9131C24971B46D743282FCF6 /* [CP] Check Pods Manifest.lock */, + 2372F8E1A49557FE0072BC56 /* [CP] Check Pods Manifest.lock */, F094A99E1B78D8F000B1FBBF /* Sources */, F094A99F1B78D8F000B1FBBF /* Frameworks */, F094A9A01B78D8F000B1FBBF /* Resources */, - 44C35695CFA4F9799C449367 /* [CP] Copy Pods Resources */, - 381DA4CC07D2104BFA23E45A /* [CP] Embed Pods Frameworks */, 24CBEC5D1F0EAD310093EABB /* Embed App Extensions */, + 7FFD40AA75DB32D83350D225 /* [CP] Embed Pods Frameworks */, + 68D6013FA64A4507DC9DB95B /* [CP] Copy Pods Resources */, ); buildRules = ( ); dependencies = ( - 24CBEC581F0EAD310093EABB /* PBXTargetDependency */, + 242661F61F12B1BA00D3FC08 /* PBXTargetDependency */, ); name = Riot; productName = Vector; @@ -2150,7 +2152,7 @@ targets = ( F094A9A11B78D8F000B1FBBF /* Riot */, F094A9BD1B78D8F000B1FBBF /* RiotTests */, - 24CBEC4D1F0EAD310093EABB /* Riot Share Extension */, + 24CBEC4D1F0EAD310093EABB /* RiotShareExtension */, ); }; /* End PBXProject section */ @@ -2511,22 +2513,37 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 381DA4CC07D2104BFA23E45A /* [CP] Embed Pods Frameworks */ = { + 2372F8E1A49557FE0072BC56 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); - name = "[CP] Embed Pods Frameworks"; + name = "[CP] Check Pods Manifest.lock"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Riot/Pods-Riot-frameworks.sh\"\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; - 44C35695CFA4F9799C449367 /* [CP] Copy Pods Resources */ = { + 3051A9ED306E05F8AE91C906 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "[CP] Check Pods Manifest.lock"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; + showEnvVarsInLog = 0; + }; + 68D6013FA64A4507DC9DB95B /* [CP] Copy Pods Resources */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( @@ -2541,19 +2558,34 @@ shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Riot/Pods-Riot-resources.sh\"\n"; showEnvVarsInLog = 0; }; - 9131C24971B46D743282FCF6 /* [CP] Check Pods Manifest.lock */ = { + 7FFD40AA75DB32D83350D225 /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( ); - name = "[CP] Check Pods Manifest.lock"; + name = "[CP] Embed Pods Frameworks"; outputPaths = ( ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Riot/Pods-Riot-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; + 8EA19F5011654D3BD5EDAC33 /* [CP] Copy Pods Resources */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "[CP] Copy Pods Resources"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-RiotShareExtension/Pods-RiotShareExtension-resources.sh\"\n"; showEnvVarsInLog = 0; }; /* End PBXShellScriptBuildPhase section */ @@ -2712,10 +2744,10 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ - 24CBEC581F0EAD310093EABB /* PBXTargetDependency */ = { + 242661F61F12B1BA00D3FC08 /* PBXTargetDependency */ = { isa = PBXTargetDependency; - target = 24CBEC4D1F0EAD310093EABB /* Riot Share Extension */; - targetProxy = 24CBEC571F0EAD310093EABB /* PBXContainerItemProxy */; + target = 24CBEC4D1F0EAD310093EABB /* RiotShareExtension */; + targetProxy = 242661F51F12B1BA00D3FC08 /* PBXContainerItemProxy */; }; F094A9C01B78D8F000B1FBBF /* PBXTargetDependency */ = { isa = PBXTargetDependency; @@ -2802,6 +2834,7 @@ /* Begin XCBuildConfiguration section */ 24CBEC5A1F0EAD310093EABB /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 12AA0005C8B3D8D8162584C5 /* Pods-RiotShareExtension.debug.xcconfig */; buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; CLANG_ANALYZER_NONNULL = YES; @@ -2810,6 +2843,7 @@ CODE_SIGN_ENTITLEMENTS = "Riot Share Extension/Riot Share Extension.entitlements"; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = 7J4U792NQT; + ENABLE_BITCODE = NO; INFOPLIST_FILE = "Riot Share Extension/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; @@ -2821,6 +2855,7 @@ }; 24CBEC5B1F0EAD310093EABB /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 765F5104DB3EC39713DEB3A4 /* Pods-RiotShareExtension.release.xcconfig */; buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; CLANG_ANALYZER_NONNULL = YES; @@ -2830,6 +2865,7 @@ COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = 7J4U792NQT; + ENABLE_BITCODE = NO; INFOPLIST_FILE = "Riot Share Extension/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; @@ -2926,7 +2962,7 @@ }; F094A9C91B78D8F000B1FBBF /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 1129C74A281B080432B1A1A1 /* Pods-Riot.debug.xcconfig */; + baseConfigurationReference = 839BB91240D350D5607D55BA /* Pods-Riot.debug.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = Riot/Riot.entitlements; @@ -2944,7 +2980,7 @@ }; F094A9CA1B78D8F000B1FBBF /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = F9D678EF54918C036FDEDBF9 /* Pods-Riot.release.xcconfig */; + baseConfigurationReference = C195C53961EA28E6900AEB68 /* Pods-Riot.release.xcconfig */; buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_ENTITLEMENTS = Riot/Riot.entitlements; @@ -3000,7 +3036,7 @@ /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ - 24CBEC5C1F0EAD310093EABB /* Build configuration list for PBXNativeTarget "Riot Share Extension" */ = { + 24CBEC5C1F0EAD310093EABB /* Build configuration list for PBXNativeTarget "RiotShareExtension" */ = { isa = XCConfigurationList; buildConfigurations = ( 24CBEC5A1F0EAD310093EABB /* Debug */, From a73ab31d84374973a204e19ad176526cf861028c Mon Sep 17 00:00:00 2001 From: Giom Foret Date: Wed, 12 Jul 2017 17:45:12 +0200 Subject: [PATCH 004/102] Fix pod install error --- Podfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Podfile b/Podfile index 9ea336f34..ff0a51b80 100644 --- a/Podfile +++ b/Podfile @@ -53,7 +53,7 @@ pod 'OLMKit' pod 'Realm', '~> 2.8.1' pod 'MatrixSDK/AppExtension', :path => '../matrix-ios-sdk/MatrixSDK.podspec' -pod 'MatrixKit/AppExtension', :path => '../matrix-ios-kitMatrixKit.podspec' +pod 'MatrixKit/AppExtension', :path => '../matrix-ios-kit/MatrixKit.podspec' end From 0115b292be2cf96ef953545a6e806bb1aec1f950 Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Wed, 19 Jul 2017 12:40:11 +0400 Subject: [PATCH 005/102] Updated the Podfile according to changes in MatrixSDK podspec --- Podfile | 2 +- Podfile.lock | 25 +++++++++---------------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/Podfile b/Podfile index ff0a51b80..5cac1961e 100644 --- a/Podfile +++ b/Podfile @@ -52,7 +52,7 @@ pod 'OLMKit' #pod 'OLMKit', :path => '../olm/OLMKit.podspec' pod 'Realm', '~> 2.8.1' -pod 'MatrixSDK/AppExtension', :path => '../matrix-ios-sdk/MatrixSDK.podspec' +pod 'MatrixSDK', :path => '../matrix-ios-sdk/MatrixSDK.podspec' pod 'MatrixKit/AppExtension', :path => '../matrix-ios-kit/MatrixKit.podspec' end diff --git a/Podfile.lock b/Podfile.lock index 12508a98a..dd93dddc6 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -46,33 +46,27 @@ PODS: - libPhoneNumber-iOS (0.9.10) - MatrixKit (0.5.2): - cmark (~> 0.24.1) + - DTCoreText (~> 1.6.17) - HPGrowingTextView (~> 1.1) - libPhoneNumber-iOS (~> 0.9.10) - MatrixKit/Core (= 0.5.2) + - MatrixSDK (= 0.8.2) - MatrixKit/AppExtension (0.5.2): - cmark (~> 0.24.1) + - DTCoreText (~> 1.6.17) - DTCoreText/Extension - HPGrowingTextView (~> 1.1) - libPhoneNumber-iOS (~> 0.9.10) - - MatrixKit/Core - - MatrixSDK/AppExtension + - MatrixSDK (= 0.8.2) - MatrixKit/Core (0.5.2): - cmark (~> 0.24.1) - - DTCoreText + - DTCoreText (~> 1.6.17) - HPGrowingTextView (~> 1.1) - libPhoneNumber-iOS (~> 0.9.10) - - MatrixSDK/Core + - MatrixSDK (= 0.8.2) - MatrixSDK (0.8.2): - AFNetworking (~> 3.1.0) - GZIP (~> 1.1.1) - - MatrixSDK/Core (= 0.8.2) - - MatrixSDK/AppExtension (0.8.2): - - AFNetworking (~> 3.1.0) - - GZIP (~> 1.1.1) - - MatrixSDK/Core - - MatrixSDK/Core (0.8.2): - - AFNetworking (~> 3.1.0) - - GZIP (~> 1.1.1) - OLMKit (2.2.2): - OLMKit/olmc (= 2.2.2) - OLMKit/olmcpp (= 2.2.2) @@ -91,7 +85,6 @@ DEPENDENCIES: - MatrixKit (from `../matrix-ios-kit/MatrixKit.podspec`) - MatrixKit/AppExtension (from `../matrix-ios-kit/MatrixKit.podspec`) - MatrixSDK (from `../matrix-ios-sdk/MatrixSDK.podspec`) - - MatrixSDK/AppExtension (from `../matrix-ios-sdk/MatrixSDK.podspec`) - OLMKit - Realm (~> 2.8.1) - WebRTC (= 58.17.16937) @@ -112,12 +105,12 @@ SPEC CHECKSUMS: GZIP: f8beb59597f651e6970a45b816508a9c6d700b77 HPGrowingTextView: 88a716d97fb853bcb08a4a08e4727da17efc9b19 libPhoneNumber-iOS: f721ae4d5854bce60934f9fb9b0b28e8e68913cb - MatrixKit: ca0494158f6acaf725e31ef94b7a481c5280b6ae - MatrixSDK: 3210d156fee0d4628dbe9180bb1709cfb155cf31 + MatrixKit: c922a006e0b7610e5ee4cbb28ab6357da105cdb1 + MatrixSDK: 1f9b5fa6334485c431884d2d2ea9ac5f65557528 OLMKit: b9d8c0ffee9ea8c45bc0aaa9afb47f93fba7efbd Realm: 3601ef091c8c499a31101d8563b991e75546cdce WebRTC: 1e9a85bf75509eec44be6478c64e9de65ac82332 -PODFILE CHECKSUM: 72052e939c3aeb10e1f729ff8e934cc1f3dc7d72 +PODFILE CHECKSUM: bfbfe09d771c6904f7ec20e0cae2e99614b6a52c COCOAPODS: 1.2.1 From edf602b0627138a74c73ed142b7da7475aaff844 Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Mon, 24 Jul 2017 16:56:31 +0400 Subject: [PATCH 006/102] 1st version --- .../Base.lproj/MainInterface.storyboard | 26 ---- Riot Share Extension/Info.plist | 4 +- .../RoomsListViewController.h | 24 ++++ .../RoomsListViewController.m | 105 ++++++++++++++++ .../SharePresentingViewController.h | 21 ++++ .../SharePresentingViewController.m | 47 +++++++ Riot Share Extension/ShareViewController.h | 5 +- Riot Share Extension/ShareViewController.m | 118 ++++++++++++++++-- Riot Share Extension/ShareViewController.xib | 103 +++++++++++++++ Riot.xcodeproj/project.pbxproj | 56 ++++++--- Riot/ViewController/SegmentedViewController.h | 2 +- Riot/ViewController/SegmentedViewController.m | 6 +- 12 files changed, 458 insertions(+), 59 deletions(-) delete mode 100644 Riot Share Extension/Base.lproj/MainInterface.storyboard create mode 100644 Riot Share Extension/RoomsListViewController.h create mode 100644 Riot Share Extension/RoomsListViewController.m create mode 100644 Riot Share Extension/SharePresentingViewController.h create mode 100644 Riot Share Extension/SharePresentingViewController.m create mode 100644 Riot Share Extension/ShareViewController.xib diff --git a/Riot Share Extension/Base.lproj/MainInterface.storyboard b/Riot Share Extension/Base.lproj/MainInterface.storyboard deleted file mode 100644 index 85e8a08b3..000000000 --- a/Riot Share Extension/Base.lproj/MainInterface.storyboard +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Riot Share Extension/Info.plist b/Riot Share Extension/Info.plist index 9f0587146..80e0c0df7 100644 --- a/Riot Share Extension/Info.plist +++ b/Riot Share Extension/Info.plist @@ -22,13 +22,13 @@ 1 NSExtension + NSExtensionPrincipalClass + SharePresentingViewController NSExtensionAttributes NSExtensionActivationRule TRUEPREDICATE - NSExtensionMainStoryboard - MainInterface NSExtensionPointIdentifier com.apple.share-services diff --git a/Riot Share Extension/RoomsListViewController.h b/Riot Share Extension/RoomsListViewController.h new file mode 100644 index 000000000..69f88465b --- /dev/null +++ b/Riot Share Extension/RoomsListViewController.h @@ -0,0 +1,24 @@ +/* + Copyright 2017 Aram Sargsyan + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#import +#import "MXRoom+Riot.h" + +@interface RoomsListViewController : UIViewController + +- (void)updateWithRooms:(NSArray *)rooms; + +@end diff --git a/Riot Share Extension/RoomsListViewController.m b/Riot Share Extension/RoomsListViewController.m new file mode 100644 index 000000000..e3216c2e0 --- /dev/null +++ b/Riot Share Extension/RoomsListViewController.m @@ -0,0 +1,105 @@ +/* + Copyright 2017 Aram Sargsyan + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#import "RoomsListViewController.h" +#import "RoomTableViewCell.h" + +@interface RoomsListViewController () + +@property (nonatomic) NSArray *rooms; +@property (nonatomic) UITableView *mainTableView; + +@end + +@implementation RoomsListViewController + +#pragma mark - Lifecycle + +- (void)viewDidLoad +{ + [super viewDidLoad]; + [self configureTableView]; +} + +#pragma mark - Public + +- (void)updateWithRooms:(NSArray *)rooms +{ + self.rooms = rooms; + [self.mainTableView reloadData]; +} + +#pragma mark - Views + +- (void)configureTableView +{ + self.mainTableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain]; + self.mainTableView.dataSource = self; + self.mainTableView.delegate = self; + [self.mainTableView registerNib:[RoomTableViewCell nib] forCellReuseIdentifier:[RoomTableViewCell defaultReuseIdentifier]]; + + [self.view addSubview:self.mainTableView]; + self.mainTableView.translatesAutoresizingMaskIntoConstraints = NO; + self.view.translatesAutoresizingMaskIntoConstraints = NO; + NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:self.mainTableView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeWidth multiplier:1 constant:0]; + widthConstraint.active = YES; + NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:self.mainTableView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeHeight multiplier:1 constant:0]; + heightConstraint.active = YES; + NSLayoutConstraint *centerXConstraint = [NSLayoutConstraint constraintWithItem:self.mainTableView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]; + centerXConstraint.active = YES; + NSLayoutConstraint *centerYConstraint = [NSLayoutConstraint constraintWithItem:self.mainTableView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]; + centerYConstraint.active = YES; +} + +#pragma mark - UITableViewDataSource + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + return self.rooms.count; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + RoomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[RoomTableViewCell defaultReuseIdentifier]]; + MXRoom *room = self.rooms[indexPath.row]; + + [cell render:room]; + if (!room.summary.displayname.length && !cell.titleLabel.text.length) + { + cell.titleLabel.text = NSLocalizedStringFromTable(@"room_displayname_no_title", @"Vector", nil); + } + + return cell; +} + +#pragma mark - UITableViewDelegate + +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath +{ + return [RoomTableViewCell cellHeight]; +} + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + NSLog(@"%@", self.rooms[indexPath.row]); +} + +@end diff --git a/Riot Share Extension/SharePresentingViewController.h b/Riot Share Extension/SharePresentingViewController.h new file mode 100644 index 000000000..430f568ba --- /dev/null +++ b/Riot Share Extension/SharePresentingViewController.h @@ -0,0 +1,21 @@ +/* + Copyright 2017 Aram Sargsyan + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#import + +@interface SharePresentingViewController : UIViewController + +@end diff --git a/Riot Share Extension/SharePresentingViewController.m b/Riot Share Extension/SharePresentingViewController.m new file mode 100644 index 000000000..6a1aa756a --- /dev/null +++ b/Riot Share Extension/SharePresentingViewController.m @@ -0,0 +1,47 @@ +/* + Copyright 2017 Aram Sargsyan + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#import "SharePresentingViewController.h" +#import "ShareViewController.h" + +@interface SharePresentingViewController () + +@end + +@implementation SharePresentingViewController + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + ShareViewController *shareViewController = [[ShareViewController alloc] init]; + shareViewController.shareExtensionContext = self.extensionContext; + + shareViewController.providesPresentationContextTransitionStyle = YES; + shareViewController.definesPresentationContext = YES; + shareViewController.modalPresentationStyle = UIModalPresentationOverFullScreen; + shareViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; + + [self presentViewController:shareViewController animated:YES completion:nil]; +} + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + + +@end diff --git a/Riot Share Extension/ShareViewController.h b/Riot Share Extension/ShareViewController.h index bb08cdc97..a3d464ee1 100644 --- a/Riot Share Extension/ShareViewController.h +++ b/Riot Share Extension/ShareViewController.h @@ -16,7 +16,10 @@ #import #import +#import -@interface ShareViewController : UIViewController +@interface ShareViewController : MXKViewController + +@property (nonatomic) NSExtensionContext *shareExtensionContext; @end diff --git a/Riot Share Extension/ShareViewController.m b/Riot Share Extension/ShareViewController.m index 218cbfced..41a7491c2 100644 --- a/Riot Share Extension/ShareViewController.m +++ b/Riot Share Extension/ShareViewController.m @@ -15,9 +15,23 @@ */ #import "ShareViewController.h" +#import "RoomTableViewCell.h" +#import "RoomsListViewController.h" +#import "SegmentedViewController.h" -#import -#import + +@interface ShareViewController () + +@property (nonatomic) NSArray *rooms; + +@property (weak, nonatomic) IBOutlet UIView *masterContainerView; +@property (weak, nonatomic) IBOutlet UILabel *tittleLabel; +@property (weak, nonatomic) IBOutlet UIView *contentView; + +@property (nonatomic) SegmentedViewController *segmentedViewController; + + +@end @implementation ShareViewController @@ -28,20 +42,98 @@ { [super viewDidLoad]; - //UI configuration - [self.view setBackgroundColor:[UIColor yellowColor]]; - self.view.alpha = 0.5; + [self prepareSession]; + [self configureViews]; - //MatrixSDK test - NSLog(@"SDK VERSION ====== %@", MatrixSDKVersion); - - //MatrixKit test - NSLog(@"KIT VERSION ====== %@", MatrixKitVersion); - - //UserDefaults test - //NSUserDefaults *sharedUserDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.org.matrix.riot"]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onSessionSync:) name:kMXSessionDidSyncNotification object:nil]; } +- (void)viewWillDisappear:(BOOL)animated +{ + [super viewWillDisappear:animated]; + + [[NSNotificationCenter defaultCenter] removeObserver:self]; +} + +#pragma mark - Private + +- (void)prepareSession +{ + // Prepare account manager + MXKAccountManager *accountManager = [MXKAccountManager sharedManager]; + + // Use MXFileStore as MXStore to permanently store events. + accountManager.storeClass = [MXFileStore class]; + + // Start a matrix session for each enabled accounts. + NSLog(@"[AppDelegate] initMatrixSessions: prepareSessionForActiveAccounts"); + [accountManager prepareSessionForActiveAccounts]; + + // Resume all existing matrix sessions + NSArray *mxAccounts = accountManager.activeAccounts; + for (MXKAccount *account in mxAccounts) + { + [account resume]; + [self addMatrixSession:account.mxSession]; + } +} + +- (void)configureViews +{ + self.masterContainerView.layer.cornerRadius = 7; + self.tittleLabel.text = @"Send to"; + + self.segmentedViewController = [SegmentedViewController segmentedViewController]; + NSArray *titles = @[@"v1", @"v2"]; + NSArray *vcs = @[[RoomsListViewController new], [RoomsListViewController new]]; + [self.segmentedViewController initWithTitles:titles viewControllers:vcs defaultSelected:0]; + + [self addChildViewController:self.segmentedViewController]; + [self.contentView addSubview:self.segmentedViewController.view]; + [self.segmentedViewController didMoveToParentViewController:self]; + + self.segmentedViewController.view.translatesAutoresizingMaskIntoConstraints = NO; + NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:self.segmentedViewController.view attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeWidth multiplier:1 constant:0]; + widthConstraint.active = YES; + NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:self.segmentedViewController.view attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeHeight multiplier:1 constant:0]; + heightConstraint.active = YES; + NSLayoutConstraint *centerXConstraint = [NSLayoutConstraint constraintWithItem:self.segmentedViewController.view attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]; + centerXConstraint.active = YES; + NSLayoutConstraint *centerYConstraint = [NSLayoutConstraint constraintWithItem:self.segmentedViewController.view attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]; + centerYConstraint.active = YES; +} + +- (void)cancelSharing +{ + [self dismissViewControllerAnimated:YES completion:^{ + NSError *error = [NSError errorWithDomain:@"cancel" code:4201 userInfo:nil]; + [self.shareExtensionContext cancelRequestWithError:error]; + }]; +} + +#pragma mark - Notifications + +- (void)onSessionSync:(NSNotification *)notification +{ + if ([notification.object isEqual:self.mainSession] && !self.rooms.count) + { + self.rooms = self.mainSession.rooms; + if (self.rooms.count) + { + //update the tab controllers + [((RoomsListViewController *)self.segmentedViewController.viewControllers[0]) updateWithRooms:self.rooms]; + [((RoomsListViewController *)self.segmentedViewController.viewControllers[1]) updateWithRooms:self.rooms]; + NSLog(@"THE ARRAY IS HERE --- \n%@", self.rooms); + } + } +} + +#pragma mark - Actions + +- (IBAction)close:(UIButton *)sender +{ + [self cancelSharing]; +} /*#pragma mark - SLComposeServiceViewController diff --git a/Riot Share Extension/ShareViewController.xib b/Riot Share Extension/ShareViewController.xib new file mode 100644 index 000000000..ab0444174 --- /dev/null +++ b/Riot Share Extension/ShareViewController.xib @@ -0,0 +1,103 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Riot.xcodeproj/project.pbxproj b/Riot.xcodeproj/project.pbxproj index dfee8a8e5..10eb7d42f 100644 --- a/Riot.xcodeproj/project.pbxproj +++ b/Riot.xcodeproj/project.pbxproj @@ -11,8 +11,21 @@ 24B5103E1EFA7083004C6AD2 /* ReadReceiptsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 24B5103D1EFA7083004C6AD2 /* ReadReceiptsViewController.m */; }; 24B510401EFA88CC004C6AD2 /* ReadReceiptsViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 24B5103F1EFA88CC004C6AD2 /* ReadReceiptsViewController.xib */; }; 24CBEC521F0EAD310093EABB /* ShareViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 24CBEC511F0EAD310093EABB /* ShareViewController.m */; }; - 24CBEC551F0EAD310093EABB /* MainInterface.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 24CBEC531F0EAD310093EABB /* MainInterface.storyboard */; }; 24CBEC591F0EAD310093EABB /* RiotShareExtension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 24CBEC4E1F0EAD310093EABB /* RiotShareExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; + 24EEE5A01F23A08900B3C705 /* RoomTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F083BCED1E7009EC00A9B29C /* RoomTableViewCell.m */; }; + 24EEE5A11F23A09A00B3C705 /* RiotDesignValues.m in Sources */ = {isa = PBXBuildFile; fileRef = F083BC171E7009EC00A9B29C /* RiotDesignValues.m */; }; + 24EEE5A21F23A8B400B3C705 /* MXRoom+Riot.m in Sources */ = {isa = PBXBuildFile; fileRef = F083BBE81E7009EC00A9B29C /* MXRoom+Riot.m */; }; + 24EEE5A31F23A8C300B3C705 /* AvatarGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = F083BC111E7009EC00A9B29C /* AvatarGenerator.m */; }; + 24EEE5A41F24C06E00B3C705 /* Vector.strings in Resources */ = {isa = PBXBuildFile; fileRef = F083BB131E7009EC00A9B29C /* Vector.strings */; }; + 24EEE5A71F24E03400B3C705 /* ShareViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 24EEE5A51F24DD5500B3C705 /* ShareViewController.xib */; }; + 24EEE5A81F25529600B3C705 /* cancel@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = F0614A121EDEE65000F5DC9A /* cancel@3x.png */; }; + 24EEE5A91F25529900B3C705 /* cancel@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F0614A111EDEE65000F5DC9A /* cancel@2x.png */; }; + 24EEE5AA1F25529C00B3C705 /* cancel.png in Resources */ = {isa = PBXBuildFile; fileRef = F0614A101EDEE65000F5DC9A /* cancel.png */; }; + 24EEE5AE1F25ED3600B3C705 /* SharePresentingViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 24EEE5AC1F25ED2E00B3C705 /* SharePresentingViewController.m */; }; + 24EEE5AF1F25F0F500B3C705 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F083BBEF1E7009EC00A9B29C /* Images.xcassets */; }; + 24EEE5B31F2607AB00B3C705 /* RoomsListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 24EEE5B11F25FF0400B3C705 /* RoomsListViewController.m */; }; + 24EEE5B41F2607C000B3C705 /* SegmentedViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F083BC4E1E7009EC00A9B29C /* SegmentedViewController.m */; }; + 24EEE5B51F2607C500B3C705 /* SegmentedViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F083BC4F1E7009EC00A9B29C /* SegmentedViewController.xib */; }; 3205ED7D1E976C8A003D65FA /* DirectoryServerPickerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3205ED7C1E976C8A003D65FA /* DirectoryServerPickerViewController.m */; }; 3205ED841E97725E003D65FA /* DirectoryServerTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 3205ED821E97725E003D65FA /* DirectoryServerTableViewCell.m */; }; 3205ED851E97725E003D65FA /* DirectoryServerTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 3205ED831E97725E003D65FA /* DirectoryServerTableViewCell.xib */; }; @@ -519,9 +532,13 @@ 24CBEC4E1F0EAD310093EABB /* RiotShareExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = RiotShareExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; }; 24CBEC501F0EAD310093EABB /* ShareViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ShareViewController.h; sourceTree = ""; }; 24CBEC511F0EAD310093EABB /* ShareViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ShareViewController.m; sourceTree = ""; }; - 24CBEC541F0EAD310093EABB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/MainInterface.storyboard; sourceTree = ""; }; 24CBEC561F0EAD310093EABB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 24CBEC5E1F0EB15D0093EABB /* Riot Share Extension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "Riot Share Extension.entitlements"; sourceTree = ""; }; + 24EEE5A51F24DD5500B3C705 /* ShareViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ShareViewController.xib; sourceTree = ""; }; + 24EEE5AB1F25ED2E00B3C705 /* SharePresentingViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SharePresentingViewController.h; sourceTree = ""; }; + 24EEE5AC1F25ED2E00B3C705 /* SharePresentingViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SharePresentingViewController.m; sourceTree = ""; }; + 24EEE5B01F25FF0400B3C705 /* RoomsListViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RoomsListViewController.h; sourceTree = ""; }; + 24EEE5B11F25FF0400B3C705 /* RoomsListViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RoomsListViewController.m; sourceTree = ""; }; 3205ED7B1E976C8A003D65FA /* DirectoryServerPickerViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DirectoryServerPickerViewController.h; sourceTree = ""; }; 3205ED7C1E976C8A003D65FA /* DirectoryServerPickerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DirectoryServerPickerViewController.m; sourceTree = ""; }; 3205ED811E97725E003D65FA /* DirectoryServerTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DirectoryServerTableViewCell.h; sourceTree = ""; }; @@ -1157,9 +1174,13 @@ isa = PBXGroup; children = ( 24CBEC5E1F0EB15D0093EABB /* Riot Share Extension.entitlements */, + 24EEE5AB1F25ED2E00B3C705 /* SharePresentingViewController.h */, + 24EEE5AC1F25ED2E00B3C705 /* SharePresentingViewController.m */, 24CBEC501F0EAD310093EABB /* ShareViewController.h */, 24CBEC511F0EAD310093EABB /* ShareViewController.m */, - 24CBEC531F0EAD310093EABB /* MainInterface.storyboard */, + 24EEE5A51F24DD5500B3C705 /* ShareViewController.xib */, + 24EEE5B01F25FF0400B3C705 /* RoomsListViewController.h */, + 24EEE5B11F25FF0400B3C705 /* RoomsListViewController.m */, 24CBEC561F0EAD310093EABB /* Info.plist */, ); path = "Riot Share Extension"; @@ -2194,7 +2215,13 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 24CBEC551F0EAD310093EABB /* MainInterface.storyboard in Resources */, + 24EEE5B51F2607C500B3C705 /* SegmentedViewController.xib in Resources */, + 24EEE5A91F25529900B3C705 /* cancel@2x.png in Resources */, + 24EEE5A71F24E03400B3C705 /* ShareViewController.xib in Resources */, + 24EEE5A81F25529600B3C705 /* cancel@3x.png in Resources */, + 24EEE5AF1F25F0F500B3C705 /* Images.xcassets in Resources */, + 24EEE5AA1F25529C00B3C705 /* cancel.png in Resources */, + 24EEE5A41F24C06E00B3C705 /* Vector.strings in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2631,7 +2658,14 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 24EEE5A01F23A08900B3C705 /* RoomTableViewCell.m in Sources */, + 24EEE5A31F23A8C300B3C705 /* AvatarGenerator.m in Sources */, 24CBEC521F0EAD310093EABB /* ShareViewController.m in Sources */, + 24EEE5B31F2607AB00B3C705 /* RoomsListViewController.m in Sources */, + 24EEE5A11F23A09A00B3C705 /* RiotDesignValues.m in Sources */, + 24EEE5A21F23A8B400B3C705 /* MXRoom+Riot.m in Sources */, + 24EEE5AE1F25ED3600B3C705 /* SharePresentingViewController.m in Sources */, + 24EEE5B41F2607C000B3C705 /* SegmentedViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2797,14 +2831,6 @@ /* End PBXTargetDependency section */ /* Begin PBXVariantGroup section */ - 24CBEC531F0EAD310093EABB /* MainInterface.storyboard */ = { - isa = PBXVariantGroup; - children = ( - 24CBEC541F0EAD310093EABB /* Base */, - ); - name = MainInterface.storyboard; - sourceTree = ""; - }; 325E1C131E8D03950018D91E /* LaunchScreen.storyboard */ = { isa = PBXVariantGroup; children = ( @@ -2877,6 +2903,7 @@ baseConfigurationReference = 12AA0005C8B3D8D8162584C5 /* Pods-RiotShareExtension.debug.xcconfig */; buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; @@ -2887,7 +2914,7 @@ INFOPLIST_FILE = "Riot Share Extension/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "im.vector.app.Riot-Share-Extension"; + PRODUCT_BUNDLE_IDENTIFIER = im.vector.app.share.extension; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; }; @@ -2898,6 +2925,7 @@ baseConfigurationReference = 765F5104DB3EC39713DEB3A4 /* Pods-RiotShareExtension.release.xcconfig */; buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; @@ -2909,7 +2937,7 @@ INFOPLIST_FILE = "Riot Share Extension/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = "im.vector.app.Riot-Share-Extension"; + PRODUCT_BUNDLE_IDENTIFIER = im.vector.app.share.extension; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; }; diff --git a/Riot/ViewController/SegmentedViewController.h b/Riot/ViewController/SegmentedViewController.h index 01abbc020..b870f188c 100644 --- a/Riot/ViewController/SegmentedViewController.h +++ b/Riot/ViewController/SegmentedViewController.h @@ -20,7 +20,7 @@ limitations under the License. #import "UIViewController+RiotSearch.h" /** - This view controller manages several uiviewcontrollers like UISegmentedControlled manages uiTableView + This view controller manages several uiviewcontrollers like UISegmentedController manages uiTableView except that the managed items are custom UIViewControllers. It uses a Vector design. */ diff --git a/Riot/ViewController/SegmentedViewController.m b/Riot/ViewController/SegmentedViewController.m index f203a094b..bd698fdd3 100644 --- a/Riot/ViewController/SegmentedViewController.m +++ b/Riot/ViewController/SegmentedViewController.m @@ -17,7 +17,9 @@ #import "SegmentedViewController.h" -#import "AppDelegate.h" +#import "RiotDesignValues.h" +//#import "RageShakeManager.h" +//#import "AppDelegate.h" @interface SegmentedViewController () { @@ -121,7 +123,7 @@ // Setup `MXKViewControllerHandling` properties self.defaultBarTintColor = kRiotNavBarTintColor; self.enableBarTintColorStatusChange = NO; - self.rageShakeManager = [RageShakeManager sharedManager]; + //self.rageShakeManager = [RageShakeManager sharedManager]; } - (void)viewDidLoad From 28b1d036dc9c58ed8f86682df7bc0ec6db4140a6 Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Tue, 25 Jul 2017 02:08:41 +0400 Subject: [PATCH 007/102] Ability to send the photo attachments --- .../RoomsListViewController.h | 2 + .../RoomsListViewController.m | 73 ++++++++++++++++++- Riot Share Extension/ShareViewController.m | 29 ++++++-- 3 files changed, 95 insertions(+), 9 deletions(-) diff --git a/Riot Share Extension/RoomsListViewController.h b/Riot Share Extension/RoomsListViewController.h index 69f88465b..cc15061ae 100644 --- a/Riot Share Extension/RoomsListViewController.h +++ b/Riot Share Extension/RoomsListViewController.h @@ -19,6 +19,8 @@ @interface RoomsListViewController : UIViewController ++ (instancetype)listViewControllerWithContext:(NSExtensionContext *)context; + - (void)updateWithRooms:(NSArray *)rooms; @end diff --git a/Riot Share Extension/RoomsListViewController.m b/Riot Share Extension/RoomsListViewController.m index e3216c2e0..fcaa430dc 100644 --- a/Riot Share Extension/RoomsListViewController.m +++ b/Riot Share Extension/RoomsListViewController.m @@ -16,14 +16,17 @@ #import "RoomsListViewController.h" #import "RoomTableViewCell.h" +@import MobileCoreServices; @interface RoomsListViewController () +@property (nonatomic) NSExtensionContext *shareExtensionContext; @property (nonatomic) NSArray *rooms; @property (nonatomic) UITableView *mainTableView; @end + @implementation RoomsListViewController #pragma mark - Lifecycle @@ -36,6 +39,13 @@ #pragma mark - Public ++ (instancetype)listViewControllerWithContext:(NSExtensionContext *)context +{ + RoomsListViewController *listViewController = [[self class] new]; + listViewController.shareExtensionContext = context; + return listViewController; +} + - (void)updateWithRooms:(NSArray *)rooms { self.rooms = rooms; @@ -64,6 +74,55 @@ centerYConstraint.active = YES; } +#pragma mark - Private + +- (void)sendToRoom:(MXRoom *)room +{ + NSString *UTTypeImage = (__bridge NSString *)kUTTypeImage; + NSString *UTTypeVideo = (__bridge NSString *)kUTTypeVideo; + + for (NSExtensionItem *item in self.shareExtensionContext.inputItems) + { + for (NSItemProvider *itemProvider in item.attachments) + { + + if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeImage]) + { + NSString *mimeType; + if ([itemProvider hasItemConformingToTypeIdentifier:(__bridge NSString *)kUTTypeJPEG]) + { + mimeType = @"image/jpeg"; + } + else if ([itemProvider hasItemConformingToTypeIdentifier:(__bridge NSString *)kUTTypePNG]) + { + mimeType = @"image/png"; + } + [itemProvider loadItemForTypeIdentifier:UTTypeImage options:nil completionHandler:^(NSData *imageData, NSError * _Null_unspecified error) + { + //send the image + UIImage *image = [[UIImage alloc] initWithData:imageData]; + [room sendImage:imageData withImageSize:image.size mimeType:mimeType andThumbnail:image localEcho:nil success:^(NSString *eventId) + { + [self.shareExtensionContext completeRequestReturningItems:@[item] completionHandler:nil]; + } + failure:^(NSError *error) + { + + }]; + }]; + } + else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeVideo]) + { + [itemProvider loadItemForTypeIdentifier:UTTypeVideo options:nil completionHandler:^(NSData *videoItem, NSError * _Null_unspecified error) + { + //send the video + }]; + } + + } + } +} + #pragma mark - UITableViewDataSource - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView @@ -99,7 +158,19 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { - NSLog(@"%@", self.rooms[indexPath.row]); + [tableView deselectRowAtIndexPath:indexPath animated:YES]; + + UIAlertController *alertController = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Send to %@", self.rooms[indexPath.row].riotDisplayname] message:nil preferredStyle:UIAlertControllerStyleAlert]; + + UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"cancel", @"Vector", nil) style:UIAlertActionStyleCancel handler:nil]; + [alertController addAction:cancelAction]; + + UIAlertAction *sendAction = [UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"send", @"Vector", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { + [self sendToRoom:self.rooms[indexPath.row]]; + }]; + [alertController addAction:sendAction]; + + [self presentViewController:alertController animated:YES completion:nil]; } @end diff --git a/Riot Share Extension/ShareViewController.m b/Riot Share Extension/ShareViewController.m index 41a7491c2..3f16ce4d2 100644 --- a/Riot Share Extension/ShareViewController.m +++ b/Riot Share Extension/ShareViewController.m @@ -84,9 +84,9 @@ self.tittleLabel.text = @"Send to"; self.segmentedViewController = [SegmentedViewController segmentedViewController]; - NSArray *titles = @[@"v1", @"v2"]; - NSArray *vcs = @[[RoomsListViewController new], [RoomsListViewController new]]; - [self.segmentedViewController initWithTitles:titles viewControllers:vcs defaultSelected:0]; + NSArray *titles = @[NSLocalizedStringFromTable(@"title_rooms", @"Vector", nil) , NSLocalizedStringFromTable(@"title_people", @"Vector", nil)]; + NSArray *viewControllers = @[[RoomsListViewController listViewControllerWithContext:self.shareExtensionContext], [RoomsListViewController listViewControllerWithContext:self.shareExtensionContext]]; + [self.segmentedViewController initWithTitles:titles viewControllers:viewControllers defaultSelected:0]; [self addChildViewController:self.segmentedViewController]; [self.contentView addSubview:self.segmentedViewController.view]; @@ -106,7 +106,7 @@ - (void)cancelSharing { [self dismissViewControllerAnimated:YES completion:^{ - NSError *error = [NSError errorWithDomain:@"cancel" code:4201 userInfo:nil]; + NSError *error = [NSError errorWithDomain:@"MXUserCancelErrorDomain" code:4201 userInfo:nil]; [self.shareExtensionContext cancelRequestWithError:error]; }]; } @@ -120,10 +120,23 @@ self.rooms = self.mainSession.rooms; if (self.rooms.count) { - //update the tab controllers - [((RoomsListViewController *)self.segmentedViewController.viewControllers[0]) updateWithRooms:self.rooms]; - [((RoomsListViewController *)self.segmentedViewController.viewControllers[1]) updateWithRooms:self.rooms]; - NSLog(@"THE ARRAY IS HERE --- \n%@", self.rooms); + + NSMutableArray *directRooms = [NSMutableArray array]; + NSMutableArray *rooms = [NSMutableArray array]; + for (MXRoom *room in self.rooms) + { + if (room.isDirect) + { + [directRooms addObject:room]; + } + else + { + [rooms addObject:room]; + } + } + + [((RoomsListViewController *)self.segmentedViewController.viewControllers[0]) updateWithRooms:rooms]; + [((RoomsListViewController *)self.segmentedViewController.viewControllers[1]) updateWithRooms:directRooms]; } } } From 1d5a21719e29839282989d8395ae9ed82025fdf4 Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Thu, 27 Jul 2017 19:41:59 +0400 Subject: [PATCH 008/102] Changed the app group to group.org.matrix --- Podfile | 5 +++++ Riot Share Extension/Riot Share Extension.entitlements | 2 +- Riot Share Extension/ShareViewController.m | 1 - Riot/Riot.entitlements | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Podfile b/Podfile index 5cac1961e..ea9bb5988 100644 --- a/Podfile +++ b/Podfile @@ -55,6 +55,11 @@ pod 'Realm', '~> 2.8.1' pod 'MatrixSDK', :path => '../matrix-ios-sdk/MatrixSDK.podspec' pod 'MatrixKit/AppExtension', :path => '../matrix-ios-kit/MatrixKit.podspec' +# Remove warnings from "bad" pods +pod 'OLMKit', :inhibit_warnings => true +pod 'cmark', :inhibit_warnings => true +pod 'DTCoreText', :inhibit_warnings => true + end diff --git a/Riot Share Extension/Riot Share Extension.entitlements b/Riot Share Extension/Riot Share Extension.entitlements index 7dd58ac09..95ba9ff62 100644 --- a/Riot Share Extension/Riot Share Extension.entitlements +++ b/Riot Share Extension/Riot Share Extension.entitlements @@ -4,7 +4,7 @@ com.apple.security.application-groups - group.org.matrix.riot + group.org.matrix diff --git a/Riot Share Extension/ShareViewController.m b/Riot Share Extension/ShareViewController.m index 3f16ce4d2..58ee61d84 100644 --- a/Riot Share Extension/ShareViewController.m +++ b/Riot Share Extension/ShareViewController.m @@ -120,7 +120,6 @@ self.rooms = self.mainSession.rooms; if (self.rooms.count) { - NSMutableArray *directRooms = [NSMutableArray array]; NSMutableArray *rooms = [NSMutableArray array]; for (MXRoom *room in self.rooms) diff --git a/Riot/Riot.entitlements b/Riot/Riot.entitlements index e9e76f7b2..fe7295f52 100644 --- a/Riot/Riot.entitlements +++ b/Riot/Riot.entitlements @@ -13,7 +13,7 @@ com.apple.security.application-groups - group.org.matrix.riot + group.org.matrix From a3b99944968ebc199dd5f0aa1d4da83908dc6f48 Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Fri, 28 Jul 2017 21:47:38 +0400 Subject: [PATCH 009/102] Added the ability to share text, and URLs --- .../RoomsListViewController.m | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/Riot Share Extension/RoomsListViewController.m b/Riot Share Extension/RoomsListViewController.m index fcaa430dc..0a94fb236 100644 --- a/Riot Share Extension/RoomsListViewController.m +++ b/Riot Share Extension/RoomsListViewController.m @@ -78,6 +78,8 @@ - (void)sendToRoom:(MXRoom *)room { + NSString *UTTypeText = (__bridge NSString *)kUTTypeText; + NSString *UTTypeURL = (__bridge NSString *)kUTTypeURL; NSString *UTTypeImage = (__bridge NSString *)kUTTypeImage; NSString *UTTypeVideo = (__bridge NSString *)kUTTypeVideo; @@ -85,8 +87,27 @@ { for (NSItemProvider *itemProvider in item.attachments) { - - if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeImage]) + if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeText]) + { + [itemProvider loadItemForTypeIdentifier:UTTypeText options:nil completionHandler:^(NSString *text, NSError * _Null_unspecified error) { + [room sendTextMessage:text success:^(NSString *eventId) { + [self.shareExtensionContext completeRequestReturningItems:@[item] completionHandler:nil]; + } failure:^(NSError *error) { + //TODO: handle failure + }]; + }]; + } + else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeURL]) + { + [itemProvider loadItemForTypeIdentifier:UTTypeURL options:nil completionHandler:^(NSURL *url, NSError * _Null_unspecified error) { + [room sendTextMessage:url.absoluteString success:^(NSString *eventId) { + [self.shareExtensionContext completeRequestReturningItems:@[item] completionHandler:nil]; + } failure:^(NSError *error) { + //TODO: handle failure + }]; + }]; + } + else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeImage]) { NSString *mimeType; if ([itemProvider hasItemConformingToTypeIdentifier:(__bridge NSString *)kUTTypeJPEG]) @@ -107,7 +128,7 @@ } failure:^(NSError *error) { - + //TODO: handle failure }]; }]; } @@ -115,7 +136,13 @@ { [itemProvider loadItemForTypeIdentifier:UTTypeVideo options:nil completionHandler:^(NSData *videoItem, NSError * _Null_unspecified error) { - //send the video + //TODO: send the video + [room sendVideo:nil withThumbnail:nil localEcho:nil success:^(NSString *eventId) { + + } failure:^(NSError *error) { + //TODO: handle failure + }]; + }]; } From 43ed4ee2b5e517b4ee25d508c89350d928a557b6 Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Sun, 30 Jul 2017 21:29:38 +0400 Subject: [PATCH 010/102] Localized the extension, added fallback view to handle logged out state, finalized NSExtensionActivationRule --- Podfile.lock | 2 +- Riot Share Extension/FallbackViewController.h | 21 +++++ Riot Share Extension/FallbackViewController.m | 42 +++++++++ .../FallbackViewController.xib | 63 +++++++++++++ Riot Share Extension/Info.plist | 11 ++- .../RoomsListViewController.h | 2 +- .../RoomsListViewController.m | 69 +++++++++++--- .../SharePresentingViewController.m | 3 +- Riot Share Extension/ShareViewController.m | 91 ++++++++++++------- Riot.xcodeproj/project.pbxproj | 16 +++- Riot/Assets/en.lproj/Vector.strings | 3 + 11 files changed, 269 insertions(+), 54 deletions(-) create mode 100644 Riot Share Extension/FallbackViewController.h create mode 100644 Riot Share Extension/FallbackViewController.m create mode 100644 Riot Share Extension/FallbackViewController.xib diff --git a/Podfile.lock b/Podfile.lock index dd93dddc6..8334d6629 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -111,6 +111,6 @@ SPEC CHECKSUMS: Realm: 3601ef091c8c499a31101d8563b991e75546cdce WebRTC: 1e9a85bf75509eec44be6478c64e9de65ac82332 -PODFILE CHECKSUM: bfbfe09d771c6904f7ec20e0cae2e99614b6a52c +PODFILE CHECKSUM: 21c5c225b8ddea3d9b74c14358eb4e2466c130aa COCOAPODS: 1.2.1 diff --git a/Riot Share Extension/FallbackViewController.h b/Riot Share Extension/FallbackViewController.h new file mode 100644 index 000000000..ddee2a064 --- /dev/null +++ b/Riot Share Extension/FallbackViewController.h @@ -0,0 +1,21 @@ +/* + Copyright 2017 Aram Sargsyan + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#import + +@interface FallbackViewController : MXKViewController + +@end diff --git a/Riot Share Extension/FallbackViewController.m b/Riot Share Extension/FallbackViewController.m new file mode 100644 index 000000000..80edc4207 --- /dev/null +++ b/Riot Share Extension/FallbackViewController.m @@ -0,0 +1,42 @@ +/* + Copyright 2017 Aram Sargsyan + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#import "FallbackViewController.h" +#import "RiotDesignValues.h" + +@interface FallbackViewController () + +@property (weak, nonatomic) IBOutlet UILabel *titleLabel; + +@end + +@implementation FallbackViewController + +- (void)viewDidLoad +{ + [super viewDidLoad]; + + self.titleLabel.textColor = kRiotTextColorGray; + self.titleLabel.text = NSLocalizedStringFromTable(@"auth_share_extension_prompt", @"Vector", nil); +} + +- (void)didReceiveMemoryWarning +{ + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +@end diff --git a/Riot Share Extension/FallbackViewController.xib b/Riot Share Extension/FallbackViewController.xib new file mode 100644 index 000000000..3dfc5aab2 --- /dev/null +++ b/Riot Share Extension/FallbackViewController.xib @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Riot Share Extension/Info.plist b/Riot Share Extension/Info.plist index 80e0c0df7..9bec3398f 100644 --- a/Riot Share Extension/Info.plist +++ b/Riot Share Extension/Info.plist @@ -27,7 +27,16 @@ NSExtensionAttributes NSExtensionActivationRule - TRUEPREDICATE + + NSExtensionActivationSupportsMovieWithMaxCount + 1 + NSExtensionActivationSupportsImageWithMaxCount + 3 + NSExtensionActivationSupportsWebURLWithMaxCount + 1 + NSExtensionActivationSupportsText + + NSExtensionPointIdentifier com.apple.share-services diff --git a/Riot Share Extension/RoomsListViewController.h b/Riot Share Extension/RoomsListViewController.h index cc15061ae..0b4f01b08 100644 --- a/Riot Share Extension/RoomsListViewController.h +++ b/Riot Share Extension/RoomsListViewController.h @@ -19,7 +19,7 @@ @interface RoomsListViewController : UIViewController -+ (instancetype)listViewControllerWithContext:(NSExtensionContext *)context; ++ (instancetype)listViewControllerWithContext:(NSExtensionContext *)context failureBlock:(void(^)())failureBlock; - (void)updateWithRooms:(NSArray *)rooms; diff --git a/Riot Share Extension/RoomsListViewController.m b/Riot Share Extension/RoomsListViewController.m index 0a94fb236..4abae61eb 100644 --- a/Riot Share Extension/RoomsListViewController.m +++ b/Riot Share Extension/RoomsListViewController.m @@ -16,11 +16,14 @@ #import "RoomsListViewController.h" #import "RoomTableViewCell.h" +#import "NSBundle+MatrixKit.h" @import MobileCoreServices; + @interface RoomsListViewController () @property (nonatomic) NSExtensionContext *shareExtensionContext; +@property (copy) void (^failureBlock)(); @property (nonatomic) NSArray *rooms; @property (nonatomic) UITableView *mainTableView; @@ -39,10 +42,11 @@ #pragma mark - Public -+ (instancetype)listViewControllerWithContext:(NSExtensionContext *)context ++ (instancetype)listViewControllerWithContext:(NSExtensionContext *)context failureBlock:(void(^)())failureBlock { RoomsListViewController *listViewController = [[self class] new]; listViewController.shareExtensionContext = context; + listViewController.failureBlock = failureBlock; return listViewController; } @@ -90,20 +94,32 @@ if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeText]) { [itemProvider loadItemForTypeIdentifier:UTTypeText options:nil completionHandler:^(NSString *text, NSError * _Null_unspecified error) { + if (!text) + { + [self showFailureAlert]; + return; + } [room sendTextMessage:text success:^(NSString *eventId) { [self.shareExtensionContext completeRequestReturningItems:@[item] completionHandler:nil]; } failure:^(NSError *error) { - //TODO: handle failure + NSLog(@"[RoomsListViewController] sendTextMessage failed."); + [self showFailureAlert]; }]; }]; } else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeURL]) { [itemProvider loadItemForTypeIdentifier:UTTypeURL options:nil completionHandler:^(NSURL *url, NSError * _Null_unspecified error) { + if (!url) + { + [self showFailureAlert]; + return; + } [room sendTextMessage:url.absoluteString success:^(NSString *eventId) { [self.shareExtensionContext completeRequestReturningItems:@[item] completionHandler:nil]; } failure:^(NSError *error) { - //TODO: handle failure + NSLog(@"[RoomsListViewController] sendTextMessage failed."); + [self showFailureAlert]; }]; }]; } @@ -120,6 +136,11 @@ } [itemProvider loadItemForTypeIdentifier:UTTypeImage options:nil completionHandler:^(NSData *imageData, NSError * _Null_unspecified error) { + if (!imageData) + { + [self showFailureAlert]; + return; + } //send the image UIImage *image = [[UIImage alloc] initWithData:imageData]; [room sendImage:imageData withImageSize:image.size mimeType:mimeType andThumbnail:image localEcho:nil success:^(NSString *eventId) @@ -128,28 +149,50 @@ } failure:^(NSError *error) { - //TODO: handle failure + NSLog(@"[RoomsListViewController] sendImage failed."); + [self showFailureAlert]; }]; }]; } else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeVideo]) { - [itemProvider loadItemForTypeIdentifier:UTTypeVideo options:nil completionHandler:^(NSData *videoItem, NSError * _Null_unspecified error) + [itemProvider loadItemForTypeIdentifier:UTTypeVideo options:nil completionHandler:^(NSURL *videoLocalUrl, NSError * _Null_unspecified error) { - //TODO: send the video - [room sendVideo:nil withThumbnail:nil localEcho:nil success:^(NSString *eventId) { - + if (!videoLocalUrl) + { + [self showFailureAlert]; + return; + } + [room sendVideo:videoLocalUrl withThumbnail:nil localEcho:nil success:^(NSString *eventId) { + [self.shareExtensionContext completeRequestReturningItems:@[item] completionHandler:nil]; } failure:^(NSError *error) { - //TODO: handle failure + NSLog(@"[RoomsListViewController] sendVideo failed."); + [self showFailureAlert]; }]; }]; } - } } } +- (void)showFailureAlert +{ + UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedStringFromTable(@"room_event_failed_to_send", @"Vector", nil) message:nil preferredStyle:UIAlertControllerStyleAlert]; + UIAlertAction *okAction = [UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"ok"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { + if (self.failureBlock) + { + self.failureBlock(); + } + else + { + [self.shareExtensionContext cancelRequestWithError:[NSError errorWithDomain:@"MXUserFailureErrorDomain" code:500 userInfo:nil]]; + } + }]; + [alertController addAction:okAction]; + [self presentViewController:alertController animated:YES completion:nil]; +} + #pragma mark - UITableViewDataSource - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView @@ -187,12 +230,12 @@ { [tableView deselectRowAtIndexPath:indexPath animated:YES]; - UIAlertController *alertController = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"Send to %@", self.rooms[indexPath.row].riotDisplayname] message:nil preferredStyle:UIAlertControllerStyleAlert]; + UIAlertController *alertController = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:NSLocalizedStringFromTable(@"send_to", @"Vector", nil), self.rooms[indexPath.row].riotDisplayname] message:nil preferredStyle:UIAlertControllerStyleAlert]; - UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"cancel", @"Vector", nil) style:UIAlertActionStyleCancel handler:nil]; + UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"] style:UIAlertActionStyleCancel handler:nil]; [alertController addAction:cancelAction]; - UIAlertAction *sendAction = [UIAlertAction actionWithTitle:NSLocalizedStringFromTable(@"send", @"Vector", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { + UIAlertAction *sendAction = [UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"send"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { [self sendToRoom:self.rooms[indexPath.row]]; }]; [alertController addAction:sendAction]; diff --git a/Riot Share Extension/SharePresentingViewController.m b/Riot Share Extension/SharePresentingViewController.m index 6a1aa756a..0ede49b4e 100644 --- a/Riot Share Extension/SharePresentingViewController.m +++ b/Riot Share Extension/SharePresentingViewController.m @@ -38,7 +38,8 @@ [self presentViewController:shareViewController animated:YES completion:nil]; } -- (void)didReceiveMemoryWarning { +- (void)didReceiveMemoryWarning +{ [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } diff --git a/Riot Share Extension/ShareViewController.m b/Riot Share Extension/ShareViewController.m index 58ee61d84..a2edb832f 100644 --- a/Riot Share Extension/ShareViewController.m +++ b/Riot Share Extension/ShareViewController.m @@ -15,9 +15,9 @@ */ #import "ShareViewController.h" -#import "RoomTableViewCell.h" -#import "RoomsListViewController.h" #import "SegmentedViewController.h" +#import "RoomsListViewController.h" +#import "FallbackViewController.h" @interface ShareViewController () @@ -70,7 +70,7 @@ [accountManager prepareSessionForActiveAccounts]; // Resume all existing matrix sessions - NSArray *mxAccounts = accountManager.activeAccounts; + NSArray *mxAccounts;// = accountManager.activeAccounts; for (MXKAccount *account in mxAccounts) { [account resume]; @@ -81,32 +81,76 @@ - (void)configureViews { self.masterContainerView.layer.cornerRadius = 7; - self.tittleLabel.text = @"Send to"; + if (self.mainSession) + { + self.tittleLabel.text = [NSString stringWithFormat:NSLocalizedStringFromTable(@"send_to", @"Vector", nil), @""]; + [self configureSegmentedViewController]; + } + else + { + NSDictionary *infoDictionary = [NSBundle mainBundle].infoDictionary; + NSString *bundleDisplayName = [infoDictionary objectForKey:@"CFBundleDisplayName"]; + self.tittleLabel.text = bundleDisplayName; + [self configureFallbackViewController]; + } +} + +- (void)configureSegmentedViewController +{ self.segmentedViewController = [SegmentedViewController segmentedViewController]; + NSArray *titles = @[NSLocalizedStringFromTable(@"title_rooms", @"Vector", nil) , NSLocalizedStringFromTable(@"title_people", @"Vector", nil)]; - NSArray *viewControllers = @[[RoomsListViewController listViewControllerWithContext:self.shareExtensionContext], [RoomsListViewController listViewControllerWithContext:self.shareExtensionContext]]; + + void (^failureBlock)() = ^void() { + [self finishSharingCanceled:NO]; + }; + NSArray *viewControllers = @[[RoomsListViewController listViewControllerWithContext:self.shareExtensionContext failureBlock:failureBlock], [RoomsListViewController listViewControllerWithContext:self.shareExtensionContext failureBlock:failureBlock]]; + [self.segmentedViewController initWithTitles:titles viewControllers:viewControllers defaultSelected:0]; [self addChildViewController:self.segmentedViewController]; [self.contentView addSubview:self.segmentedViewController.view]; [self.segmentedViewController didMoveToParentViewController:self]; - self.segmentedViewController.view.translatesAutoresizingMaskIntoConstraints = NO; - NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:self.segmentedViewController.view attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeWidth multiplier:1 constant:0]; + [self autoPinSubviewEdges:self.segmentedViewController.view toSuperviewEdges:self.contentView]; +} + +- (void)configureFallbackViewController +{ + FallbackViewController *fallbackVC = [FallbackViewController new]; + [self addChildViewController:fallbackVC]; + [self.contentView addSubview:fallbackVC.view]; + [fallbackVC didMoveToParentViewController:self]; + + [self autoPinSubviewEdges:fallbackVC.view toSuperviewEdges:self.contentView]; +} + +- (void)autoPinSubviewEdges:(UIView *)subview toSuperviewEdges:(UIView *)superview +{ + subview.translatesAutoresizingMaskIntoConstraints = NO; + NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:subview attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:superview attribute:NSLayoutAttributeWidth multiplier:1 constant:0]; widthConstraint.active = YES; - NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:self.segmentedViewController.view attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeHeight multiplier:1 constant:0]; + NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:subview attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:superview attribute:NSLayoutAttributeHeight multiplier:1 constant:0]; heightConstraint.active = YES; - NSLayoutConstraint *centerXConstraint = [NSLayoutConstraint constraintWithItem:self.segmentedViewController.view attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]; + NSLayoutConstraint *centerXConstraint = [NSLayoutConstraint constraintWithItem:subview attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:superview attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]; centerXConstraint.active = YES; - NSLayoutConstraint *centerYConstraint = [NSLayoutConstraint constraintWithItem:self.segmentedViewController.view attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]; + NSLayoutConstraint *centerYConstraint = [NSLayoutConstraint constraintWithItem:subview attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:superview attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]; centerYConstraint.active = YES; } -- (void)cancelSharing +- (void)finishSharingCanceled:(BOOL)canceled { [self dismissViewControllerAnimated:YES completion:^{ - NSError *error = [NSError errorWithDomain:@"MXUserCancelErrorDomain" code:4201 userInfo:nil]; + NSError *error; + if (canceled) + { + error = [NSError errorWithDomain:@"MXUserCancelErrorDomain" code:4201 userInfo:nil]; + } + else + { + error = [NSError errorWithDomain:@"MXUserFailureErrorDomain" code:500 userInfo:nil]; + } [self.shareExtensionContext cancelRequestWithError:error]; }]; } @@ -144,29 +188,8 @@ - (IBAction)close:(UIButton *)sender { - [self cancelSharing]; + [self finishSharingCanceled:YES]; } -/*#pragma mark - SLComposeServiceViewController - -- (BOOL)isContentValid -{ - // Do validation of contentText and/or NSExtensionContext attachments here - return YES; -} - -- (void)didSelectPost -{ - // This is called after the user selects Post. Do the upload of contentText and/or NSExtensionContext attachments. - - // Inform the host that we're done, so it un-blocks its UI. Note: Alternatively you could call super's -didSelectPost, which will similarly complete the extension context. - [self.extensionContext completeRequestReturningItems:@[] completionHandler:nil]; -} - -- (NSArray *)configurationItems -{ - // To add configuration options via table cells at the bottom of the sheet, return an array of SLComposeSheetConfigurationItem here. - return @[]; -}*/ @end diff --git a/Riot.xcodeproj/project.pbxproj b/Riot.xcodeproj/project.pbxproj index 478ec675b..8bd14750f 100644 --- a/Riot.xcodeproj/project.pbxproj +++ b/Riot.xcodeproj/project.pbxproj @@ -8,6 +8,9 @@ /* Begin PBXBuildFile section */ 05D592A32FF1D1877B89F73C /* libPods-Riot.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD9D0BDE9232898950554DD5 /* libPods-Riot.a */; }; + 2466B73C1F2DFA3000AE27B0 /* FallbackViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2466B7381F2DF78B00AE27B0 /* FallbackViewController.m */; }; + 2466B73D1F2DFA3900AE27B0 /* FallbackViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2466B7391F2DF78B00AE27B0 /* FallbackViewController.xib */; }; + 2466B73E1F2DFAC100AE27B0 /* animatedLogo-4.png in Resources */ = {isa = PBXBuildFile; fileRef = F083BB201E7009EC00A9B29C /* animatedLogo-4.png */; }; 24B5103E1EFA7083004C6AD2 /* ReadReceiptsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 24B5103D1EFA7083004C6AD2 /* ReadReceiptsViewController.m */; }; 24B510401EFA88CC004C6AD2 /* ReadReceiptsViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 24B5103F1EFA88CC004C6AD2 /* ReadReceiptsViewController.xib */; }; 24CBEC521F0EAD310093EABB /* ShareViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 24CBEC511F0EAD310093EABB /* ShareViewController.m */; }; @@ -52,7 +55,6 @@ 32FD0A3D1EB0CD9B0072B066 /* BugReportViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 32FD0A3B1EB0CD9B0072B066 /* BugReportViewController.m */; }; 32FD0A3E1EB0CD9B0072B066 /* BugReportViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 32FD0A3C1EB0CD9B0072B066 /* BugReportViewController.xib */; }; A27ECCE3FC4971745D2CB78D /* libPods-RiotShareExtension.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7246451C668D6782166E22EC /* libPods-RiotShareExtension.a */; }; - E2EAC1A4FBD6FE5228584591 /* libPods-Riot.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 7D8737F782E108CFD6908691 /* libPods-Riot.a */; }; F0131DE51F2200D600CBF707 /* RiotSplitViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F0131DE41F2200D600CBF707 /* RiotSplitViewController.m */; }; F02C1A861E8EB04C0045A404 /* PeopleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F02C1A841E8EB04C0045A404 /* PeopleViewController.m */; }; F05BD79E1E7AEBF800C69941 /* UnifiedSearchViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F05BD79D1E7AEBF800C69941 /* UnifiedSearchViewController.m */; }; @@ -529,6 +531,9 @@ /* Begin PBXFileReference section */ 12AA0005C8B3D8D8162584C5 /* Pods-RiotShareExtension.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RiotShareExtension.debug.xcconfig"; path = "Pods/Target Support Files/Pods-RiotShareExtension/Pods-RiotShareExtension.debug.xcconfig"; sourceTree = ""; }; + 2466B7371F2DF78B00AE27B0 /* FallbackViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FallbackViewController.h; sourceTree = ""; }; + 2466B7381F2DF78B00AE27B0 /* FallbackViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FallbackViewController.m; sourceTree = ""; }; + 2466B7391F2DF78B00AE27B0 /* FallbackViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = FallbackViewController.xib; sourceTree = ""; }; 24B5103C1EFA7083004C6AD2 /* ReadReceiptsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReadReceiptsViewController.h; sourceTree = ""; }; 24B5103D1EFA7083004C6AD2 /* ReadReceiptsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ReadReceiptsViewController.m; sourceTree = ""; }; 24B5103F1EFA88CC004C6AD2 /* ReadReceiptsViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ReadReceiptsViewController.xib; sourceTree = ""; }; @@ -582,7 +587,6 @@ 765F5104DB3EC39713DEB3A4 /* Pods-RiotShareExtension.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RiotShareExtension.release.xcconfig"; path = "Pods/Target Support Files/Pods-RiotShareExtension/Pods-RiotShareExtension.release.xcconfig"; sourceTree = ""; }; 839BB91240D350D5607D55BA /* Pods-Riot.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Riot.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Riot/Pods-Riot.debug.xcconfig"; sourceTree = ""; }; C195C53961EA28E6900AEB68 /* Pods-Riot.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Riot.release.xcconfig"; path = "Pods/Target Support Files/Pods-Riot/Pods-Riot.release.xcconfig"; sourceTree = ""; }; - 7D8737F782E108CFD6908691 /* libPods-Riot.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Riot.a"; sourceTree = BUILT_PRODUCTS_DIR; }; F0131DE31F2200D600CBF707 /* RiotSplitViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RiotSplitViewController.h; sourceTree = ""; }; F0131DE41F2200D600CBF707 /* RiotSplitViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RiotSplitViewController.m; sourceTree = ""; }; F02C1A831E8EB04C0045A404 /* PeopleViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PeopleViewController.h; sourceTree = ""; }; @@ -1182,6 +1186,7 @@ isa = PBXGroup; children = ( 24CBEC5E1F0EB15D0093EABB /* Riot Share Extension.entitlements */, + 24CBEC561F0EAD310093EABB /* Info.plist */, 24EEE5AB1F25ED2E00B3C705 /* SharePresentingViewController.h */, 24EEE5AC1F25ED2E00B3C705 /* SharePresentingViewController.m */, 24CBEC501F0EAD310093EABB /* ShareViewController.h */, @@ -1189,7 +1194,9 @@ 24EEE5A51F24DD5500B3C705 /* ShareViewController.xib */, 24EEE5B01F25FF0400B3C705 /* RoomsListViewController.h */, 24EEE5B11F25FF0400B3C705 /* RoomsListViewController.m */, - 24CBEC561F0EAD310093EABB /* Info.plist */, + 2466B7371F2DF78B00AE27B0 /* FallbackViewController.h */, + 2466B7381F2DF78B00AE27B0 /* FallbackViewController.m */, + 2466B7391F2DF78B00AE27B0 /* FallbackViewController.xib */, ); path = "Riot Share Extension"; sourceTree = ""; @@ -2229,8 +2236,10 @@ files = ( 24EEE5B51F2607C500B3C705 /* SegmentedViewController.xib in Resources */, 24EEE5A91F25529900B3C705 /* cancel@2x.png in Resources */, + 2466B73D1F2DFA3900AE27B0 /* FallbackViewController.xib in Resources */, 24EEE5A71F24E03400B3C705 /* ShareViewController.xib in Resources */, 24EEE5A81F25529600B3C705 /* cancel@3x.png in Resources */, + 2466B73E1F2DFAC100AE27B0 /* animatedLogo-4.png in Resources */, 24EEE5AF1F25F0F500B3C705 /* Images.xcassets in Resources */, 24EEE5AA1F25529C00B3C705 /* cancel.png in Resources */, 24EEE5A41F24C06E00B3C705 /* Vector.strings in Resources */, @@ -2678,6 +2687,7 @@ 24EEE5A21F23A8B400B3C705 /* MXRoom+Riot.m in Sources */, 24EEE5AE1F25ED3600B3C705 /* SharePresentingViewController.m in Sources */, 24EEE5B41F2607C000B3C705 /* SegmentedViewController.m in Sources */, + 2466B73C1F2DFA3000AE27B0 /* FallbackViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Riot/Assets/en.lproj/Vector.strings b/Riot/Assets/en.lproj/Vector.strings index 9091840e6..b420c72aa 100644 --- a/Riot/Assets/en.lproj/Vector.strings +++ b/Riot/Assets/en.lproj/Vector.strings @@ -49,6 +49,7 @@ "later" = "Later"; "rename" = "Rename"; "collapse" = "collapse"; +"send_to" = "Send to %@"; // Authentication "auth_login" = "Log in"; @@ -102,6 +103,7 @@ "auth_reset_password_error_not_found" = "Your email address does not appear to be associated with a Matrix ID on this Homeserver."; "auth_reset_password_success_message" = "Your password has been reset.\n\nYou have been logged out of all devices and will no longer receive push notifications. To re-enable notifications, re-log in on each device."; "auth_add_email_and_phone_warning" = "Registration with email and phone number at once is not supported yet until the api exists. Only the phone number will be taken into account. You may add your email to your profile in settings."; +"auth_share_extension_prompt" = "Login in the main app to share content"; // Chat creation "room_creation_title" = "New Chat"; @@ -249,6 +251,7 @@ "room_event_action_cancel_download" = "Cancel Download"; "room_event_action_view_encryption" = "Encryption Information"; "room_warning_about_encryption" = "End-to-end encryption is in beta and may not be reliable.\n\nYou should not yet trust it to secure data.\n\nDevices will not yet be able to decrypt history from before they joined the room.\n\nEncrypted messages will not be visible on clients that do not yet implement encryption."; +"room_event_failed_to_send" = "Failed to send"; // Unknown devices "unknown_devices_alert_title" = "Room contains unknown devices"; From 9f7b5752851b8e55a0b64b95aa25bb1998bc330a Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Mon, 31 Jul 2017 19:03:38 +0400 Subject: [PATCH 011/102] Removing podfile.lock changes from PR --- Podfile.lock | 33 +++------------------------------ 1 file changed, 3 insertions(+), 30 deletions(-) diff --git a/Podfile.lock b/Podfile.lock index 8334d6629..34664183d 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -26,11 +26,6 @@ PODS: - DTFoundation/DTAnimatedGIF (~> 1.7.5) - DTFoundation/DTHTMLParser (~> 1.7.5) - DTFoundation/UIKit (~> 1.7.5) - - DTCoreText/Extension (1.6.20): - - DTFoundation/Core (~> 1.7.5) - - DTFoundation/DTAnimatedGIF (~> 1.7.5) - - DTFoundation/DTHTMLParser (~> 1.7.5) - - DTFoundation/UIKit (~> 1.7.5) - DTFoundation/Core (1.7.12) - DTFoundation/DTAnimatedGIF (1.7.12) - DTFoundation/DTHTMLParser (1.7.12): @@ -45,20 +40,6 @@ PODS: - HPGrowingTextView (1.1) - libPhoneNumber-iOS (0.9.10) - MatrixKit (0.5.2): - - cmark (~> 0.24.1) - - DTCoreText (~> 1.6.17) - - HPGrowingTextView (~> 1.1) - - libPhoneNumber-iOS (~> 0.9.10) - - MatrixKit/Core (= 0.5.2) - - MatrixSDK (= 0.8.2) - - MatrixKit/AppExtension (0.5.2): - - cmark (~> 0.24.1) - - DTCoreText (~> 1.6.17) - - DTCoreText/Extension - - HPGrowingTextView (~> 1.1) - - libPhoneNumber-iOS (~> 0.9.10) - - MatrixSDK (= 0.8.2) - - MatrixKit/Core (0.5.2): - cmark (~> 0.24.1) - DTCoreText (~> 1.6.17) - HPGrowingTextView (~> 1.1) @@ -82,19 +63,11 @@ DEPENDENCIES: - DTCoreText - GBDeviceInfo (~> 4.3.0) - GoogleAnalytics - - MatrixKit (from `../matrix-ios-kit/MatrixKit.podspec`) - - MatrixKit/AppExtension (from `../matrix-ios-kit/MatrixKit.podspec`) - - MatrixSDK (from `../matrix-ios-sdk/MatrixSDK.podspec`) + - MatrixKit (= 0.5.2) - OLMKit - Realm (~> 2.8.1) - WebRTC (= 58.17.16937) -EXTERNAL SOURCES: - MatrixKit: - :path: ../matrix-ios-kit/MatrixKit.podspec - MatrixSDK: - :path: ../matrix-ios-sdk/MatrixSDK.podspec - SPEC CHECKSUMS: AFNetworking: 5e0e199f73d8626b11e79750991f5d173d1f8b67 cmark: ec0275215b504780287b6fca360224e384368af8 @@ -105,12 +78,12 @@ SPEC CHECKSUMS: GZIP: f8beb59597f651e6970a45b816508a9c6d700b77 HPGrowingTextView: 88a716d97fb853bcb08a4a08e4727da17efc9b19 libPhoneNumber-iOS: f721ae4d5854bce60934f9fb9b0b28e8e68913cb - MatrixKit: c922a006e0b7610e5ee4cbb28ab6357da105cdb1 + MatrixKit: daad23e5724d8f26a44a322f4d259a26b614ddc6 MatrixSDK: 1f9b5fa6334485c431884d2d2ea9ac5f65557528 OLMKit: b9d8c0ffee9ea8c45bc0aaa9afb47f93fba7efbd Realm: 3601ef091c8c499a31101d8563b991e75546cdce WebRTC: 1e9a85bf75509eec44be6478c64e9de65ac82332 -PODFILE CHECKSUM: 21c5c225b8ddea3d9b74c14358eb4e2466c130aa +PODFILE CHECKSUM: ba9311a74b4af32f75db5053d87c9f7181a42d17 COCOAPODS: 1.2.1 From 91b11f881b634ae24d0be6e9a5f9aff510a2fd59 Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Mon, 31 Jul 2017 19:26:06 +0400 Subject: [PATCH 012/102] Review changes --- Podfile | 15 +++- Riot.xcodeproj/project.pbxproj | 87 ++++++++++--------- Riot/ViewController/SegmentedViewController.m | 3 - .../FallbackViewController.h | 0 .../FallbackViewController.m | 0 .../FallbackViewController.xib | 0 .../Info.plist | 0 .../RiotShareExtension.entitlements | 0 .../RoomsListViewController.h | 0 .../RoomsListViewController.m | 27 +++++- .../SharePresentingViewController.h | 0 .../SharePresentingViewController.m | 0 .../ShareViewController.h | 0 .../ShareViewController.m | 2 +- .../ShareViewController.xib | 0 15 files changed, 81 insertions(+), 53 deletions(-) rename {Riot Share Extension => RiotShareExtension}/FallbackViewController.h (100%) rename {Riot Share Extension => RiotShareExtension}/FallbackViewController.m (100%) rename {Riot Share Extension => RiotShareExtension}/FallbackViewController.xib (100%) rename {Riot Share Extension => RiotShareExtension}/Info.plist (100%) rename Riot Share Extension/Riot Share Extension.entitlements => RiotShareExtension/RiotShareExtension.entitlements (100%) rename {Riot Share Extension => RiotShareExtension}/RoomsListViewController.h (100%) rename {Riot Share Extension => RiotShareExtension}/RoomsListViewController.m (87%) rename {Riot Share Extension => RiotShareExtension}/SharePresentingViewController.h (100%) rename {Riot Share Extension => RiotShareExtension}/SharePresentingViewController.m (100%) rename {Riot Share Extension => RiotShareExtension}/ShareViewController.h (100%) rename {Riot Share Extension => RiotShareExtension}/ShareViewController.m (99%) rename {Riot Share Extension => RiotShareExtension}/ShareViewController.xib (100%) diff --git a/Podfile b/Podfile index ea9bb5988..3c16abf00 100644 --- a/Podfile +++ b/Podfile @@ -8,9 +8,9 @@ target "Riot" do # Different flavours of pods to MatrixKit # The tagged version on which this version of Riot has been built -#pod 'MatrixKit', '0.5.2' +pod 'MatrixKit', '0.5.2' -# The lastest release available on the CocoaPods repository +# The lastest release available on the CocoaPods repository #pod 'MatrixKit' # The develop branch version @@ -19,8 +19,8 @@ target "Riot" do # The one used for developing both MatrixSDK and MatrixKit # Note that MatrixSDK must be cloned into a folder called matrix-ios-sdk next to the MatrixKit folder -pod 'MatrixKit', :path => '../matrix-ios-kit/MatrixKit.podspec' -pod 'MatrixSDK', :path => '../matrix-ios-sdk/MatrixSDK.podspec' +#pod 'MatrixKit', :path => '../matrix-ios-kit/MatrixKit.podspec' +#pod 'MatrixSDK', :path => '../matrix-ios-sdk/MatrixSDK.podspec' pod 'GBDeviceInfo', '~> 4.3.0' @@ -55,6 +55,13 @@ pod 'Realm', '~> 2.8.1' pod 'MatrixSDK', :path => '../matrix-ios-sdk/MatrixSDK.podspec' pod 'MatrixKit/AppExtension', :path => '../matrix-ios-kit/MatrixKit.podspec' +# The lastest release available on the CocoaPods repository +#pod 'MatrixKit' + +# The develop branch version +#pod 'MatrixSDK', :git => 'https://github.com/matrix-org/matrix-ios-sdk.git', :branch => 'develop' +#pod 'MatrixKit', :git => 'https://github.com/matrix-org/matrix-ios-kit.git', :branch => 'develop' + # Remove warnings from "bad" pods pod 'OLMKit', :inhibit_warnings => true pod 'cmark', :inhibit_warnings => true diff --git a/Riot.xcodeproj/project.pbxproj b/Riot.xcodeproj/project.pbxproj index 20c21ea25..2dc65fff9 100644 --- a/Riot.xcodeproj/project.pbxproj +++ b/Riot.xcodeproj/project.pbxproj @@ -8,25 +8,26 @@ /* Begin PBXBuildFile section */ 05D592A32FF1D1877B89F73C /* libPods-Riot.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD9D0BDE9232898950554DD5 /* libPods-Riot.a */; }; - 2466B73C1F2DFA3000AE27B0 /* FallbackViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2466B7381F2DF78B00AE27B0 /* FallbackViewController.m */; }; - 2466B73D1F2DFA3900AE27B0 /* FallbackViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2466B7391F2DF78B00AE27B0 /* FallbackViewController.xib */; }; 2466B73E1F2DFAC100AE27B0 /* animatedLogo-4.png in Resources */ = {isa = PBXBuildFile; fileRef = F083BB201E7009EC00A9B29C /* animatedLogo-4.png */; }; + 2466B75E1F2F80B800AE27B0 /* FallbackViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2466B7531F2F80B800AE27B0 /* FallbackViewController.m */; }; + 2466B75F1F2F80B800AE27B0 /* FallbackViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2466B7541F2F80B800AE27B0 /* FallbackViewController.xib */; }; + 2466B7601F2F80B800AE27B0 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 2466B7551F2F80B800AE27B0 /* Info.plist */; }; + 2466B7611F2F80B800AE27B0 /* RoomsListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2466B7581F2F80B800AE27B0 /* RoomsListViewController.m */; }; + 2466B7621F2F80B800AE27B0 /* SharePresentingViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2466B75A1F2F80B800AE27B0 /* SharePresentingViewController.m */; }; + 2466B7631F2F80B800AE27B0 /* ShareViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2466B75C1F2F80B800AE27B0 /* ShareViewController.m */; }; + 2466B7641F2F80B800AE27B0 /* ShareViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2466B75D1F2F80B800AE27B0 /* ShareViewController.xib */; }; 24B5103E1EFA7083004C6AD2 /* ReadReceiptsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 24B5103D1EFA7083004C6AD2 /* ReadReceiptsViewController.m */; }; 24B510401EFA88CC004C6AD2 /* ReadReceiptsViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 24B5103F1EFA88CC004C6AD2 /* ReadReceiptsViewController.xib */; }; - 24CBEC521F0EAD310093EABB /* ShareViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 24CBEC511F0EAD310093EABB /* ShareViewController.m */; }; 24CBEC591F0EAD310093EABB /* RiotShareExtension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 24CBEC4E1F0EAD310093EABB /* RiotShareExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 24EEE5A01F23A08900B3C705 /* RoomTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F083BCED1E7009EC00A9B29C /* RoomTableViewCell.m */; }; 24EEE5A11F23A09A00B3C705 /* RiotDesignValues.m in Sources */ = {isa = PBXBuildFile; fileRef = F083BC171E7009EC00A9B29C /* RiotDesignValues.m */; }; 24EEE5A21F23A8B400B3C705 /* MXRoom+Riot.m in Sources */ = {isa = PBXBuildFile; fileRef = F083BBE81E7009EC00A9B29C /* MXRoom+Riot.m */; }; 24EEE5A31F23A8C300B3C705 /* AvatarGenerator.m in Sources */ = {isa = PBXBuildFile; fileRef = F083BC111E7009EC00A9B29C /* AvatarGenerator.m */; }; - 24EEE5A41F24C06E00B3C705 /* Vector.strings in Resources */ = {isa = PBXBuildFile; fileRef = F083BB131E7009EC00A9B29C /* Vector.strings */; }; - 24EEE5A71F24E03400B3C705 /* ShareViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 24EEE5A51F24DD5500B3C705 /* ShareViewController.xib */; }; + 24EEE5A41F24C06E00B3C705 /* (null) in Resources */ = {isa = PBXBuildFile; }; 24EEE5A81F25529600B3C705 /* cancel@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = F0614A121EDEE65000F5DC9A /* cancel@3x.png */; }; 24EEE5A91F25529900B3C705 /* cancel@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F0614A111EDEE65000F5DC9A /* cancel@2x.png */; }; 24EEE5AA1F25529C00B3C705 /* cancel.png in Resources */ = {isa = PBXBuildFile; fileRef = F0614A101EDEE65000F5DC9A /* cancel.png */; }; - 24EEE5AE1F25ED3600B3C705 /* SharePresentingViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 24EEE5AC1F25ED2E00B3C705 /* SharePresentingViewController.m */; }; 24EEE5AF1F25F0F500B3C705 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F083BBEF1E7009EC00A9B29C /* Images.xcassets */; }; - 24EEE5B31F2607AB00B3C705 /* RoomsListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 24EEE5B11F25FF0400B3C705 /* RoomsListViewController.m */; }; 24EEE5B41F2607C000B3C705 /* SegmentedViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F083BC4E1E7009EC00A9B29C /* SegmentedViewController.m */; }; 24EEE5B51F2607C500B3C705 /* SegmentedViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F083BC4F1E7009EC00A9B29C /* SegmentedViewController.xib */; }; 3205ED7D1E976C8A003D65FA /* DirectoryServerPickerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 3205ED7C1E976C8A003D65FA /* DirectoryServerPickerViewController.m */; }; @@ -537,22 +538,22 @@ /* Begin PBXFileReference section */ 12AA0005C8B3D8D8162584C5 /* Pods-RiotShareExtension.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RiotShareExtension.debug.xcconfig"; path = "Pods/Target Support Files/Pods-RiotShareExtension/Pods-RiotShareExtension.debug.xcconfig"; sourceTree = ""; }; - 2466B7371F2DF78B00AE27B0 /* FallbackViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FallbackViewController.h; sourceTree = ""; }; - 2466B7381F2DF78B00AE27B0 /* FallbackViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FallbackViewController.m; sourceTree = ""; }; - 2466B7391F2DF78B00AE27B0 /* FallbackViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = FallbackViewController.xib; sourceTree = ""; }; + 2466B7521F2F80B800AE27B0 /* FallbackViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FallbackViewController.h; path = RiotShareExtension/FallbackViewController.h; sourceTree = SOURCE_ROOT; }; + 2466B7531F2F80B800AE27B0 /* FallbackViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FallbackViewController.m; path = RiotShareExtension/FallbackViewController.m; sourceTree = SOURCE_ROOT; }; + 2466B7541F2F80B800AE27B0 /* FallbackViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = FallbackViewController.xib; path = RiotShareExtension/FallbackViewController.xib; sourceTree = SOURCE_ROOT; }; + 2466B7551F2F80B800AE27B0 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = RiotShareExtension/Info.plist; sourceTree = SOURCE_ROOT; }; + 2466B7561F2F80B800AE27B0 /* RiotShareExtension.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; name = RiotShareExtension.entitlements; path = RiotShareExtension/RiotShareExtension.entitlements; sourceTree = SOURCE_ROOT; }; + 2466B7571F2F80B800AE27B0 /* RoomsListViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RoomsListViewController.h; path = RiotShareExtension/RoomsListViewController.h; sourceTree = SOURCE_ROOT; }; + 2466B7581F2F80B800AE27B0 /* RoomsListViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RoomsListViewController.m; path = RiotShareExtension/RoomsListViewController.m; sourceTree = SOURCE_ROOT; }; + 2466B7591F2F80B800AE27B0 /* SharePresentingViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SharePresentingViewController.h; path = RiotShareExtension/SharePresentingViewController.h; sourceTree = SOURCE_ROOT; }; + 2466B75A1F2F80B800AE27B0 /* SharePresentingViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SharePresentingViewController.m; path = RiotShareExtension/SharePresentingViewController.m; sourceTree = SOURCE_ROOT; }; + 2466B75B1F2F80B800AE27B0 /* ShareViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ShareViewController.h; path = RiotShareExtension/ShareViewController.h; sourceTree = SOURCE_ROOT; }; + 2466B75C1F2F80B800AE27B0 /* ShareViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ShareViewController.m; path = RiotShareExtension/ShareViewController.m; sourceTree = SOURCE_ROOT; }; + 2466B75D1F2F80B800AE27B0 /* ShareViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = ShareViewController.xib; path = RiotShareExtension/ShareViewController.xib; sourceTree = SOURCE_ROOT; }; 24B5103C1EFA7083004C6AD2 /* ReadReceiptsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReadReceiptsViewController.h; sourceTree = ""; }; 24B5103D1EFA7083004C6AD2 /* ReadReceiptsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ReadReceiptsViewController.m; sourceTree = ""; }; 24B5103F1EFA88CC004C6AD2 /* ReadReceiptsViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ReadReceiptsViewController.xib; sourceTree = ""; }; 24CBEC4E1F0EAD310093EABB /* RiotShareExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = RiotShareExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; }; - 24CBEC501F0EAD310093EABB /* ShareViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ShareViewController.h; sourceTree = ""; }; - 24CBEC511F0EAD310093EABB /* ShareViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ShareViewController.m; sourceTree = ""; }; - 24CBEC561F0EAD310093EABB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 24CBEC5E1F0EB15D0093EABB /* Riot Share Extension.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = "Riot Share Extension.entitlements"; sourceTree = ""; }; - 24EEE5A51F24DD5500B3C705 /* ShareViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ShareViewController.xib; sourceTree = ""; }; - 24EEE5AB1F25ED2E00B3C705 /* SharePresentingViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SharePresentingViewController.h; sourceTree = ""; }; - 24EEE5AC1F25ED2E00B3C705 /* SharePresentingViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SharePresentingViewController.m; sourceTree = ""; }; - 24EEE5B01F25FF0400B3C705 /* RoomsListViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RoomsListViewController.h; sourceTree = ""; }; - 24EEE5B11F25FF0400B3C705 /* RoomsListViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RoomsListViewController.m; sourceTree = ""; }; 3205ED7B1E976C8A003D65FA /* DirectoryServerPickerViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DirectoryServerPickerViewController.h; sourceTree = ""; }; 3205ED7C1E976C8A003D65FA /* DirectoryServerPickerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DirectoryServerPickerViewController.m; sourceTree = ""; }; 3205ED811E97725E003D65FA /* DirectoryServerTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DirectoryServerTableViewCell.h; sourceTree = ""; }; @@ -1194,22 +1195,23 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 24CBEC4F1F0EAD310093EABB /* Riot Share Extension */ = { + 24CBEC4F1F0EAD310093EABB /* RiotShareExtension */ = { isa = PBXGroup; children = ( - 24CBEC5E1F0EB15D0093EABB /* Riot Share Extension.entitlements */, - 24CBEC561F0EAD310093EABB /* Info.plist */, - 24EEE5AB1F25ED2E00B3C705 /* SharePresentingViewController.h */, - 24EEE5AC1F25ED2E00B3C705 /* SharePresentingViewController.m */, - 24CBEC501F0EAD310093EABB /* ShareViewController.h */, - 24CBEC511F0EAD310093EABB /* ShareViewController.m */, - 24EEE5A51F24DD5500B3C705 /* ShareViewController.xib */, - 24EEE5B01F25FF0400B3C705 /* RoomsListViewController.h */, - 24EEE5B11F25FF0400B3C705 /* RoomsListViewController.m */, - 2466B7371F2DF78B00AE27B0 /* FallbackViewController.h */, - 2466B7381F2DF78B00AE27B0 /* FallbackViewController.m */, - 2466B7391F2DF78B00AE27B0 /* FallbackViewController.xib */, + 2466B7551F2F80B800AE27B0 /* Info.plist */, + 2466B7561F2F80B800AE27B0 /* RiotShareExtension.entitlements */, + 2466B7591F2F80B800AE27B0 /* SharePresentingViewController.h */, + 2466B75A1F2F80B800AE27B0 /* SharePresentingViewController.m */, + 2466B75B1F2F80B800AE27B0 /* ShareViewController.h */, + 2466B75C1F2F80B800AE27B0 /* ShareViewController.m */, + 2466B75D1F2F80B800AE27B0 /* ShareViewController.xib */, + 2466B7571F2F80B800AE27B0 /* RoomsListViewController.h */, + 2466B7581F2F80B800AE27B0 /* RoomsListViewController.m */, + 2466B7521F2F80B800AE27B0 /* FallbackViewController.h */, + 2466B7531F2F80B800AE27B0 /* FallbackViewController.m */, + 2466B7541F2F80B800AE27B0 /* FallbackViewController.xib */, ); + name = RiotShareExtension; path = "Riot Share Extension"; sourceTree = ""; }; @@ -2132,7 +2134,7 @@ children = ( F083BB081E7009EC00A9B29C /* Riot */, F083BB021E7005FD00A9B29C /* RiotTests */, - 24CBEC4F1F0EAD310093EABB /* Riot Share Extension */, + 24CBEC4F1F0EAD310093EABB /* RiotShareExtension */, F094A9A31B78D8F000B1FBBF /* Products */, 7471DF3720D498384A068DA7 /* Pods */, 5FC42FA41F5186AFFB6A2404 /* Frameworks */, @@ -2280,13 +2282,11 @@ files = ( 24EEE5B51F2607C500B3C705 /* SegmentedViewController.xib in Resources */, 24EEE5A91F25529900B3C705 /* cancel@2x.png in Resources */, - 2466B73D1F2DFA3900AE27B0 /* FallbackViewController.xib in Resources */, - 24EEE5A71F24E03400B3C705 /* ShareViewController.xib in Resources */, 24EEE5A81F25529600B3C705 /* cancel@3x.png in Resources */, 2466B73E1F2DFAC100AE27B0 /* animatedLogo-4.png in Resources */, 24EEE5AF1F25F0F500B3C705 /* Images.xcassets in Resources */, 24EEE5AA1F25529C00B3C705 /* cancel.png in Resources */, - 24EEE5A41F24C06E00B3C705 /* Vector.strings in Resources */, + 24EEE5A41F24C06E00B3C705 /* (null) in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2641,6 +2641,9 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 2466B7601F2F80B800AE27B0 /* Info.plist in Resources */, + 2466B7641F2F80B800AE27B0 /* ShareViewController.xib in Resources */, + 2466B75F1F2F80B800AE27B0 /* FallbackViewController.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2731,13 +2734,9 @@ files = ( 24EEE5A01F23A08900B3C705 /* RoomTableViewCell.m in Sources */, 24EEE5A31F23A8C300B3C705 /* AvatarGenerator.m in Sources */, - 24CBEC521F0EAD310093EABB /* ShareViewController.m in Sources */, - 24EEE5B31F2607AB00B3C705 /* RoomsListViewController.m in Sources */, 24EEE5A11F23A09A00B3C705 /* RiotDesignValues.m in Sources */, 24EEE5A21F23A8B400B3C705 /* MXRoom+Riot.m in Sources */, - 24EEE5AE1F25ED3600B3C705 /* SharePresentingViewController.m in Sources */, 24EEE5B41F2607C000B3C705 /* SegmentedViewController.m in Sources */, - 2466B73C1F2DFA3000AE27B0 /* FallbackViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2885,7 +2884,11 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 2466B75E1F2F80B800AE27B0 /* FallbackViewController.m in Sources */, F083BEA51E70356E00A9B29C /* RiotTests.m in Sources */, + 2466B7611F2F80B800AE27B0 /* RoomsListViewController.m in Sources */, + 2466B7631F2F80B800AE27B0 /* ShareViewController.m in Sources */, + 2466B7621F2F80B800AE27B0 /* SharePresentingViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -3029,7 +3032,7 @@ CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - CODE_SIGN_ENTITLEMENTS = "Riot Share Extension/Riot Share Extension.entitlements"; + CODE_SIGN_ENTITLEMENTS = RiotShareExtension/RiotShareExtension.entitlements; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = 7J4U792NQT; ENABLE_BITCODE = NO; @@ -3051,7 +3054,7 @@ CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - CODE_SIGN_ENTITLEMENTS = "Riot Share Extension/Riot Share Extension.entitlements"; + CODE_SIGN_ENTITLEMENTS = RiotShareExtension/RiotShareExtension.entitlements; COPY_PHASE_STRIP = NO; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = 7J4U792NQT; diff --git a/Riot/ViewController/SegmentedViewController.m b/Riot/ViewController/SegmentedViewController.m index 5245a13dd..31d89753a 100644 --- a/Riot/ViewController/SegmentedViewController.m +++ b/Riot/ViewController/SegmentedViewController.m @@ -18,8 +18,6 @@ #import "SegmentedViewController.h" #import "RiotDesignValues.h" -//#import "RageShakeManager.h" -//#import "AppDelegate.h" @interface SegmentedViewController () { @@ -131,7 +129,6 @@ // Setup `MXKViewControllerHandling` properties self.enableBarTintColorStatusChange = NO; - //self.rageShakeManager = [RageShakeManager sharedManager]; } - (void)viewDidLoad diff --git a/Riot Share Extension/FallbackViewController.h b/RiotShareExtension/FallbackViewController.h similarity index 100% rename from Riot Share Extension/FallbackViewController.h rename to RiotShareExtension/FallbackViewController.h diff --git a/Riot Share Extension/FallbackViewController.m b/RiotShareExtension/FallbackViewController.m similarity index 100% rename from Riot Share Extension/FallbackViewController.m rename to RiotShareExtension/FallbackViewController.m diff --git a/Riot Share Extension/FallbackViewController.xib b/RiotShareExtension/FallbackViewController.xib similarity index 100% rename from Riot Share Extension/FallbackViewController.xib rename to RiotShareExtension/FallbackViewController.xib diff --git a/Riot Share Extension/Info.plist b/RiotShareExtension/Info.plist similarity index 100% rename from Riot Share Extension/Info.plist rename to RiotShareExtension/Info.plist diff --git a/Riot Share Extension/Riot Share Extension.entitlements b/RiotShareExtension/RiotShareExtension.entitlements similarity index 100% rename from Riot Share Extension/Riot Share Extension.entitlements rename to RiotShareExtension/RiotShareExtension.entitlements diff --git a/Riot Share Extension/RoomsListViewController.h b/RiotShareExtension/RoomsListViewController.h similarity index 100% rename from Riot Share Extension/RoomsListViewController.h rename to RiotShareExtension/RoomsListViewController.h diff --git a/Riot Share Extension/RoomsListViewController.m b/RiotShareExtension/RoomsListViewController.m similarity index 87% rename from Riot Share Extension/RoomsListViewController.m rename to RiotShareExtension/RoomsListViewController.m index 4abae61eb..474eeb766 100644 --- a/Riot Share Extension/RoomsListViewController.m +++ b/RiotShareExtension/RoomsListViewController.m @@ -141,9 +141,19 @@ [self showFailureAlert]; return; } - //send the image + //Send the image UIImage *image = [[UIImage alloc] initWithData:imageData]; - [room sendImage:imageData withImageSize:image.size mimeType:mimeType andThumbnail:image localEcho:nil success:^(NSString *eventId) + UIImage *thumbnail = nil; + // Thumbnail is useful only in case of encrypted room + if (room.state.isEncrypted) + { + thumbnail = [MXKTools reduceImage:image toFitInSize:CGSizeMake(800, 600)]; + if (thumbnail == image) + { + thumbnail = nil; + } + } + [room sendImage:imageData withImageSize:image.size mimeType:mimeType andThumbnail:thumbnail localEcho:nil success:^(NSString *eventId) { [self.shareExtensionContext completeRequestReturningItems:@[item] completionHandler:nil]; } @@ -163,7 +173,18 @@ [self showFailureAlert]; return; } - [room sendVideo:videoLocalUrl withThumbnail:nil localEcho:nil success:^(NSString *eventId) { + + // Retrieve the video frame at 1 sec to define the video thumbnail + AVURLAsset *urlAsset = [[AVURLAsset alloc] initWithURL:videoLocalUrl options:nil]; + AVAssetImageGenerator *assetImageGenerator = [AVAssetImageGenerator assetImageGeneratorWithAsset:urlAsset]; + assetImageGenerator.appliesPreferredTrackTransform = YES; + CMTime time = CMTimeMake(1, 1); + CGImageRef imageRef = [assetImageGenerator copyCGImageAtTime:time actualTime:NULL error:nil]; + // Finalize video attachment + UIImage *videoThumbnail = [[UIImage alloc] initWithCGImage:imageRef]; + CFRelease(imageRef); + + [room sendVideo:videoLocalUrl withThumbnail:videoThumbnail localEcho:nil success:^(NSString *eventId) { [self.shareExtensionContext completeRequestReturningItems:@[item] completionHandler:nil]; } failure:^(NSError *error) { NSLog(@"[RoomsListViewController] sendVideo failed."); diff --git a/Riot Share Extension/SharePresentingViewController.h b/RiotShareExtension/SharePresentingViewController.h similarity index 100% rename from Riot Share Extension/SharePresentingViewController.h rename to RiotShareExtension/SharePresentingViewController.h diff --git a/Riot Share Extension/SharePresentingViewController.m b/RiotShareExtension/SharePresentingViewController.m similarity index 100% rename from Riot Share Extension/SharePresentingViewController.m rename to RiotShareExtension/SharePresentingViewController.m diff --git a/Riot Share Extension/ShareViewController.h b/RiotShareExtension/ShareViewController.h similarity index 100% rename from Riot Share Extension/ShareViewController.h rename to RiotShareExtension/ShareViewController.h diff --git a/Riot Share Extension/ShareViewController.m b/RiotShareExtension/ShareViewController.m similarity index 99% rename from Riot Share Extension/ShareViewController.m rename to RiotShareExtension/ShareViewController.m index a2edb832f..8c18b34f9 100644 --- a/Riot Share Extension/ShareViewController.m +++ b/RiotShareExtension/ShareViewController.m @@ -70,7 +70,7 @@ [accountManager prepareSessionForActiveAccounts]; // Resume all existing matrix sessions - NSArray *mxAccounts;// = accountManager.activeAccounts; + NSArray *mxAccounts = accountManager.activeAccounts; for (MXKAccount *account in mxAccounts) { [account resume]; diff --git a/Riot Share Extension/ShareViewController.xib b/RiotShareExtension/ShareViewController.xib similarity index 100% rename from Riot Share Extension/ShareViewController.xib rename to RiotShareExtension/ShareViewController.xib From 097c78081d9abff01bbc93e5dd7e9dac47adfb49 Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Tue, 1 Aug 2017 01:34:59 +0400 Subject: [PATCH 013/102] Podfile modifications --- Podfile | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Podfile b/Podfile index 3c16abf00..e7962b6ac 100644 --- a/Podfile +++ b/Podfile @@ -52,15 +52,20 @@ pod 'OLMKit' #pod 'OLMKit', :path => '../olm/OLMKit.podspec' pod 'Realm', '~> 2.8.1' -pod 'MatrixSDK', :path => '../matrix-ios-sdk/MatrixSDK.podspec' -pod 'MatrixKit/AppExtension', :path => '../matrix-ios-kit/MatrixKit.podspec' +# The tagged version on which this version of Riot has been built +pod 'MatrixKit', '0.5.2' # The lastest release available on the CocoaPods repository -#pod 'MatrixKit' +#pod 'MatrixKit/AppExtension' # The develop branch version #pod 'MatrixSDK', :git => 'https://github.com/matrix-org/matrix-ios-sdk.git', :branch => 'develop' -#pod 'MatrixKit', :git => 'https://github.com/matrix-org/matrix-ios-kit.git', :branch => 'develop' +#pod 'MatrixKit/AppExtension', :git => 'https://github.com/matrix-org/matrix-ios-kit.git', :branch => 'develop' + +# The one used for developing both MatrixSDK and MatrixKit +# Note that MatrixSDK must be cloned into a folder called matrix-ios-sdk next to the MatrixKit folder +#pod 'MatrixSDK', :path => '../matrix-ios-sdk/MatrixSDK.podspec' +#pod 'MatrixKit/AppExtension', :path => '../matrix-ios-kit/MatrixKit.podspec' # Remove warnings from "bad" pods pod 'OLMKit', :inhibit_warnings => true From af178c7f0a8f9f7c06b0994a041d632fc9ff804a Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Thu, 3 Aug 2017 15:09:36 +0400 Subject: [PATCH 014/102] Converting non jpeg or png image types to jpeg before sending --- RiotShareExtension/RoomsListViewController.m | 25 +++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/RiotShareExtension/RoomsListViewController.m b/RiotShareExtension/RoomsListViewController.m index 474eeb766..ef75cbab7 100644 --- a/RiotShareExtension/RoomsListViewController.m +++ b/RiotShareExtension/RoomsListViewController.m @@ -125,15 +125,6 @@ } else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeImage]) { - NSString *mimeType; - if ([itemProvider hasItemConformingToTypeIdentifier:(__bridge NSString *)kUTTypeJPEG]) - { - mimeType = @"image/jpeg"; - } - else if ([itemProvider hasItemConformingToTypeIdentifier:(__bridge NSString *)kUTTypePNG]) - { - mimeType = @"image/png"; - } [itemProvider loadItemForTypeIdentifier:UTTypeImage options:nil completionHandler:^(NSData *imageData, NSError * _Null_unspecified error) { if (!imageData) @@ -143,6 +134,22 @@ } //Send the image UIImage *image = [[UIImage alloc] initWithData:imageData]; + + NSString *mimeType; + if ([itemProvider hasItemConformingToTypeIdentifier:(__bridge NSString *)kUTTypePNG]) + { + mimeType = @"image/png"; + } + else if ([itemProvider hasItemConformingToTypeIdentifier:(__bridge NSString *)kUTTypeJPEG]) + { + mimeType = @"image/jpeg"; + } + else + { + image = [[UIImage alloc] initWithData:UIImageJPEGRepresentation(image, 1.0)]; + mimeType = @"image/jpeg"; + } + UIImage *thumbnail = nil; // Thumbnail is useful only in case of encrypted room if (room.state.isEncrypted) From df3f63d908aa13983b1ff7e5756d4d63d48e36c8 Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Sun, 6 Aug 2017 18:24:35 +0400 Subject: [PATCH 015/102] Project file fixes --- Riot.xcodeproj/project.pbxproj | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/Riot.xcodeproj/project.pbxproj b/Riot.xcodeproj/project.pbxproj index 2dc65fff9..310328bd7 100644 --- a/Riot.xcodeproj/project.pbxproj +++ b/Riot.xcodeproj/project.pbxproj @@ -8,14 +8,15 @@ /* Begin PBXBuildFile section */ 05D592A32FF1D1877B89F73C /* libPods-Riot.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD9D0BDE9232898950554DD5 /* libPods-Riot.a */; }; + 243517981F375B6800D0683E /* FallbackViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2466B7531F2F80B800AE27B0 /* FallbackViewController.m */; }; + 243517991F375B7100D0683E /* FallbackViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2466B7541F2F80B800AE27B0 /* FallbackViewController.xib */; }; + 2435179A1F375B8A00D0683E /* ShareViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2466B75C1F2F80B800AE27B0 /* ShareViewController.m */; }; + 2435179B1F375B8F00D0683E /* SharePresentingViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2466B75A1F2F80B800AE27B0 /* SharePresentingViewController.m */; }; + 2435179C1F375B9400D0683E /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 2466B7551F2F80B800AE27B0 /* Info.plist */; }; + 2435179D1F375BA100D0683E /* ShareViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2466B75D1F2F80B800AE27B0 /* ShareViewController.xib */; }; + 2435179E1F375BA600D0683E /* RoomsListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2466B7581F2F80B800AE27B0 /* RoomsListViewController.m */; }; + 2435179F1F375C0F00D0683E /* Vector.strings in Resources */ = {isa = PBXBuildFile; fileRef = 327382C01F276AED00356143 /* Vector.strings */; }; 2466B73E1F2DFAC100AE27B0 /* animatedLogo-4.png in Resources */ = {isa = PBXBuildFile; fileRef = F083BB201E7009EC00A9B29C /* animatedLogo-4.png */; }; - 2466B75E1F2F80B800AE27B0 /* FallbackViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2466B7531F2F80B800AE27B0 /* FallbackViewController.m */; }; - 2466B75F1F2F80B800AE27B0 /* FallbackViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2466B7541F2F80B800AE27B0 /* FallbackViewController.xib */; }; - 2466B7601F2F80B800AE27B0 /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 2466B7551F2F80B800AE27B0 /* Info.plist */; }; - 2466B7611F2F80B800AE27B0 /* RoomsListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2466B7581F2F80B800AE27B0 /* RoomsListViewController.m */; }; - 2466B7621F2F80B800AE27B0 /* SharePresentingViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2466B75A1F2F80B800AE27B0 /* SharePresentingViewController.m */; }; - 2466B7631F2F80B800AE27B0 /* ShareViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2466B75C1F2F80B800AE27B0 /* ShareViewController.m */; }; - 2466B7641F2F80B800AE27B0 /* ShareViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2466B75D1F2F80B800AE27B0 /* ShareViewController.xib */; }; 24B5103E1EFA7083004C6AD2 /* ReadReceiptsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 24B5103D1EFA7083004C6AD2 /* ReadReceiptsViewController.m */; }; 24B510401EFA88CC004C6AD2 /* ReadReceiptsViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 24B5103F1EFA88CC004C6AD2 /* ReadReceiptsViewController.xib */; }; 24CBEC591F0EAD310093EABB /* RiotShareExtension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 24CBEC4E1F0EAD310093EABB /* RiotShareExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; @@ -2280,10 +2281,14 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 2435179D1F375BA100D0683E /* ShareViewController.xib in Resources */, 24EEE5B51F2607C500B3C705 /* SegmentedViewController.xib in Resources */, 24EEE5A91F25529900B3C705 /* cancel@2x.png in Resources */, + 2435179C1F375B9400D0683E /* Info.plist in Resources */, + 243517991F375B7100D0683E /* FallbackViewController.xib in Resources */, 24EEE5A81F25529600B3C705 /* cancel@3x.png in Resources */, 2466B73E1F2DFAC100AE27B0 /* animatedLogo-4.png in Resources */, + 2435179F1F375C0F00D0683E /* Vector.strings in Resources */, 24EEE5AF1F25F0F500B3C705 /* Images.xcassets in Resources */, 24EEE5AA1F25529C00B3C705 /* cancel.png in Resources */, 24EEE5A41F24C06E00B3C705 /* (null) in Resources */, @@ -2641,9 +2646,6 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 2466B7601F2F80B800AE27B0 /* Info.plist in Resources */, - 2466B7641F2F80B800AE27B0 /* ShareViewController.xib in Resources */, - 2466B75F1F2F80B800AE27B0 /* FallbackViewController.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2734,7 +2736,11 @@ files = ( 24EEE5A01F23A08900B3C705 /* RoomTableViewCell.m in Sources */, 24EEE5A31F23A8C300B3C705 /* AvatarGenerator.m in Sources */, + 2435179E1F375BA600D0683E /* RoomsListViewController.m in Sources */, + 243517981F375B6800D0683E /* FallbackViewController.m in Sources */, + 2435179B1F375B8F00D0683E /* SharePresentingViewController.m in Sources */, 24EEE5A11F23A09A00B3C705 /* RiotDesignValues.m in Sources */, + 2435179A1F375B8A00D0683E /* ShareViewController.m in Sources */, 24EEE5A21F23A8B400B3C705 /* MXRoom+Riot.m in Sources */, 24EEE5B41F2607C000B3C705 /* SegmentedViewController.m in Sources */, ); @@ -2884,11 +2890,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 2466B75E1F2F80B800AE27B0 /* FallbackViewController.m in Sources */, F083BEA51E70356E00A9B29C /* RiotTests.m in Sources */, - 2466B7611F2F80B800AE27B0 /* RoomsListViewController.m in Sources */, - 2466B7631F2F80B800AE27B0 /* ShareViewController.m in Sources */, - 2466B7621F2F80B800AE27B0 /* SharePresentingViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -3036,7 +3038,7 @@ DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = 7J4U792NQT; ENABLE_BITCODE = NO; - INFOPLIST_FILE = "Riot Share Extension/Info.plist"; + INFOPLIST_FILE = RiotShareExtension/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = im.vector.app.share.extension; @@ -3059,7 +3061,7 @@ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = 7J4U792NQT; ENABLE_BITCODE = NO; - INFOPLIST_FILE = "Riot Share Extension/Info.plist"; + INFOPLIST_FILE = RiotShareExtension/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = im.vector.app.share.extension; From 89592fd34cb95da080f706bd91b430e494cc20ea Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Fri, 11 Aug 2017 02:38:47 +0400 Subject: [PATCH 016/102] Reworked the Share Extension to use a subclass of MXKRecentsDataSource to show content, solved the room order issue, as well introduced a new class ShareExtensionManager responsible for Sharing content and communicating with the system to terminate the extension with the appropriate exit code when needed. --- Podfile | 12 +- Riot.xcodeproj/project.pbxproj | 94 ++++-- Riot/Views/RoomList/RoomTableViewCell.h | 2 +- .../Model/ShareExtensionManager.h | 24 ++ .../Model/ShareExtensionManager.m | 186 ++++++++++++ .../Model/ShareRecentsDataSource.h | 21 ++ .../Model/ShareRecentsDataSource.m | 128 ++++++++ RiotShareExtension/RoomsListViewController.m | 274 ------------------ RiotShareExtension/ViewController/.DS_Store | Bin 0 -> 6148 bytes .../FallbackViewController.h | 0 .../FallbackViewController.m | 0 .../FallbackViewController.xib | 0 .../RoomsListViewController.h | 7 +- .../ViewController/RoomsListViewController.m | 152 ++++++++++ .../SharePresentingViewController.h | 0 .../SharePresentingViewController.m | 4 +- .../ShareViewController.h | 2 - .../ShareViewController.m | 56 +--- .../ShareViewController.xib | 0 19 files changed, 602 insertions(+), 360 deletions(-) create mode 100644 RiotShareExtension/Model/ShareExtensionManager.h create mode 100644 RiotShareExtension/Model/ShareExtensionManager.m create mode 100644 RiotShareExtension/Model/ShareRecentsDataSource.h create mode 100644 RiotShareExtension/Model/ShareRecentsDataSource.m delete mode 100644 RiotShareExtension/RoomsListViewController.m create mode 100644 RiotShareExtension/ViewController/.DS_Store rename RiotShareExtension/{ => ViewController}/FallbackViewController.h (100%) rename RiotShareExtension/{ => ViewController}/FallbackViewController.m (100%) rename RiotShareExtension/{ => ViewController}/FallbackViewController.xib (100%) rename RiotShareExtension/{ => ViewController}/RoomsListViewController.h (72%) create mode 100644 RiotShareExtension/ViewController/RoomsListViewController.m rename RiotShareExtension/{ => ViewController}/SharePresentingViewController.h (100%) rename RiotShareExtension/{ => ViewController}/SharePresentingViewController.m (91%) rename RiotShareExtension/{ => ViewController}/ShareViewController.h (91%) rename RiotShareExtension/{ => ViewController}/ShareViewController.m (76%) rename RiotShareExtension/{ => ViewController}/ShareViewController.xib (100%) diff --git a/Podfile b/Podfile index dca685cba..d3fdf13a5 100644 --- a/Podfile +++ b/Podfile @@ -8,7 +8,7 @@ target "Riot" do # Different flavours of pods to MatrixKit # The tagged version on which this version of Riot has been built -pod 'MatrixKit', '0.6.0' +#pod 'MatrixKit', '0.6.0' # The lastest release available on the CocoaPods repository #pod 'MatrixKit' @@ -19,8 +19,8 @@ pod 'MatrixKit', '0.6.0' # The one used for developing both MatrixSDK and MatrixKit # Note that MatrixSDK must be cloned into a folder called matrix-ios-sdk next to the MatrixKit folder -#pod 'MatrixKit', :path => '../matrix-ios-kit/MatrixKit.podspec' -#pod 'MatrixSDK', :path => '../matrix-ios-sdk/MatrixSDK.podspec' +pod 'MatrixKit', :path => '../matrix-ios-kit/MatrixKit.podspec' +pod 'MatrixSDK', :path => '../matrix-ios-sdk/MatrixSDK.podspec' pod 'GBDeviceInfo', '~> 4.3.0' @@ -53,7 +53,7 @@ pod 'OLMKit' pod 'Realm', '~> 2.8.1' # The tagged version on which this version of Riot has been built -pod 'MatrixKit', '0.5.2' +#pod 'MatrixKit', '0.5.2' # The lastest release available on the CocoaPods repository #pod 'MatrixKit/AppExtension' @@ -64,8 +64,8 @@ pod 'MatrixKit', '0.5.2' # The one used for developing both MatrixSDK and MatrixKit # Note that MatrixSDK must be cloned into a folder called matrix-ios-sdk next to the MatrixKit folder -#pod 'MatrixSDK', :path => '../matrix-ios-sdk/MatrixSDK.podspec' -#pod 'MatrixKit/AppExtension', :path => '../matrix-ios-kit/MatrixKit.podspec' +pod 'MatrixSDK', :path => '../matrix-ios-sdk/MatrixSDK.podspec' +pod 'MatrixKit/AppExtension', :path => '../matrix-ios-kit/MatrixKit.podspec' # Remove warnings from "bad" pods pod 'OLMKit', :inhibit_warnings => true diff --git a/Riot.xcodeproj/project.pbxproj b/Riot.xcodeproj/project.pbxproj index 310328bd7..03e34af48 100644 --- a/Riot.xcodeproj/project.pbxproj +++ b/Riot.xcodeproj/project.pbxproj @@ -8,18 +8,20 @@ /* Begin PBXBuildFile section */ 05D592A32FF1D1877B89F73C /* libPods-Riot.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FD9D0BDE9232898950554DD5 /* libPods-Riot.a */; }; - 243517981F375B6800D0683E /* FallbackViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2466B7531F2F80B800AE27B0 /* FallbackViewController.m */; }; - 243517991F375B7100D0683E /* FallbackViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2466B7541F2F80B800AE27B0 /* FallbackViewController.xib */; }; - 2435179A1F375B8A00D0683E /* ShareViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2466B75C1F2F80B800AE27B0 /* ShareViewController.m */; }; - 2435179B1F375B8F00D0683E /* SharePresentingViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2466B75A1F2F80B800AE27B0 /* SharePresentingViewController.m */; }; 2435179C1F375B9400D0683E /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 2466B7551F2F80B800AE27B0 /* Info.plist */; }; - 2435179D1F375BA100D0683E /* ShareViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2466B75D1F2F80B800AE27B0 /* ShareViewController.xib */; }; - 2435179E1F375BA600D0683E /* RoomsListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2466B7581F2F80B800AE27B0 /* RoomsListViewController.m */; }; 2435179F1F375C0F00D0683E /* Vector.strings in Resources */ = {isa = PBXBuildFile; fileRef = 327382C01F276AED00356143 /* Vector.strings */; }; + 245FC3ED1F3D079A00603C6A /* ShareExtensionManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 245FC3EB1F3CAF9800603C6A /* ShareExtensionManager.m */; }; 2466B73E1F2DFAC100AE27B0 /* animatedLogo-4.png in Resources */ = {isa = PBXBuildFile; fileRef = F083BB201E7009EC00A9B29C /* animatedLogo-4.png */; }; 24B5103E1EFA7083004C6AD2 /* ReadReceiptsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 24B5103D1EFA7083004C6AD2 /* ReadReceiptsViewController.m */; }; 24B510401EFA88CC004C6AD2 /* ReadReceiptsViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 24B5103F1EFA88CC004C6AD2 /* ReadReceiptsViewController.xib */; }; 24CBEC591F0EAD310093EABB /* RiotShareExtension.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 24CBEC4E1F0EAD310093EABB /* RiotShareExtension.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; + 24D6B3581F3C90D300FC7A71 /* ShareRecentsDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 24D6B3571F3C90D300FC7A71 /* ShareRecentsDataSource.m */; }; + 24D6B3591F3CA02900FC7A71 /* SharePresentingViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 24D6B34B1F3C8F8A00FC7A71 /* SharePresentingViewController.m */; }; + 24D6B35A1F3CA02C00FC7A71 /* ShareViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 24D6B34D1F3C8F8A00FC7A71 /* ShareViewController.m */; }; + 24D6B35B1F3CA03300FC7A71 /* ShareViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 24D6B34E1F3C8F8A00FC7A71 /* ShareViewController.xib */; }; + 24D6B35C1F3CA03600FC7A71 /* RoomsListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 24D6B3491F3C8F8A00FC7A71 /* RoomsListViewController.m */; }; + 24D6B35D1F3CA03A00FC7A71 /* FallbackViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 24D6B3461F3C8F8A00FC7A71 /* FallbackViewController.m */; }; + 24D6B35E1F3CA03E00FC7A71 /* FallbackViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 24D6B3471F3C8F8A00FC7A71 /* FallbackViewController.xib */; }; 24EEE5A01F23A08900B3C705 /* RoomTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F083BCED1E7009EC00A9B29C /* RoomTableViewCell.m */; }; 24EEE5A11F23A09A00B3C705 /* RiotDesignValues.m in Sources */ = {isa = PBXBuildFile; fileRef = F083BC171E7009EC00A9B29C /* RiotDesignValues.m */; }; 24EEE5A21F23A8B400B3C705 /* MXRoom+Riot.m in Sources */ = {isa = PBXBuildFile; fileRef = F083BBE81E7009EC00A9B29C /* MXRoom+Riot.m */; }; @@ -539,22 +541,26 @@ /* Begin PBXFileReference section */ 12AA0005C8B3D8D8162584C5 /* Pods-RiotShareExtension.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RiotShareExtension.debug.xcconfig"; path = "Pods/Target Support Files/Pods-RiotShareExtension/Pods-RiotShareExtension.debug.xcconfig"; sourceTree = ""; }; - 2466B7521F2F80B800AE27B0 /* FallbackViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FallbackViewController.h; path = RiotShareExtension/FallbackViewController.h; sourceTree = SOURCE_ROOT; }; - 2466B7531F2F80B800AE27B0 /* FallbackViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FallbackViewController.m; path = RiotShareExtension/FallbackViewController.m; sourceTree = SOURCE_ROOT; }; - 2466B7541F2F80B800AE27B0 /* FallbackViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = FallbackViewController.xib; path = RiotShareExtension/FallbackViewController.xib; sourceTree = SOURCE_ROOT; }; + 245FC3EA1F3CAF9800603C6A /* ShareExtensionManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShareExtensionManager.h; sourceTree = ""; }; + 245FC3EB1F3CAF9800603C6A /* ShareExtensionManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ShareExtensionManager.m; sourceTree = ""; }; 2466B7551F2F80B800AE27B0 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = RiotShareExtension/Info.plist; sourceTree = SOURCE_ROOT; }; 2466B7561F2F80B800AE27B0 /* RiotShareExtension.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; name = RiotShareExtension.entitlements; path = RiotShareExtension/RiotShareExtension.entitlements; sourceTree = SOURCE_ROOT; }; - 2466B7571F2F80B800AE27B0 /* RoomsListViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RoomsListViewController.h; path = RiotShareExtension/RoomsListViewController.h; sourceTree = SOURCE_ROOT; }; - 2466B7581F2F80B800AE27B0 /* RoomsListViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = RoomsListViewController.m; path = RiotShareExtension/RoomsListViewController.m; sourceTree = SOURCE_ROOT; }; - 2466B7591F2F80B800AE27B0 /* SharePresentingViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SharePresentingViewController.h; path = RiotShareExtension/SharePresentingViewController.h; sourceTree = SOURCE_ROOT; }; - 2466B75A1F2F80B800AE27B0 /* SharePresentingViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SharePresentingViewController.m; path = RiotShareExtension/SharePresentingViewController.m; sourceTree = SOURCE_ROOT; }; - 2466B75B1F2F80B800AE27B0 /* ShareViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ShareViewController.h; path = RiotShareExtension/ShareViewController.h; sourceTree = SOURCE_ROOT; }; - 2466B75C1F2F80B800AE27B0 /* ShareViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ShareViewController.m; path = RiotShareExtension/ShareViewController.m; sourceTree = SOURCE_ROOT; }; - 2466B75D1F2F80B800AE27B0 /* ShareViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = ShareViewController.xib; path = RiotShareExtension/ShareViewController.xib; sourceTree = SOURCE_ROOT; }; 24B5103C1EFA7083004C6AD2 /* ReadReceiptsViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReadReceiptsViewController.h; sourceTree = ""; }; 24B5103D1EFA7083004C6AD2 /* ReadReceiptsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ReadReceiptsViewController.m; sourceTree = ""; }; 24B5103F1EFA88CC004C6AD2 /* ReadReceiptsViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ReadReceiptsViewController.xib; sourceTree = ""; }; 24CBEC4E1F0EAD310093EABB /* RiotShareExtension.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = RiotShareExtension.appex; sourceTree = BUILT_PRODUCTS_DIR; }; + 24D6B3451F3C8F8A00FC7A71 /* FallbackViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FallbackViewController.h; sourceTree = ""; }; + 24D6B3461F3C8F8A00FC7A71 /* FallbackViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FallbackViewController.m; sourceTree = ""; }; + 24D6B3471F3C8F8A00FC7A71 /* FallbackViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = FallbackViewController.xib; sourceTree = ""; }; + 24D6B3481F3C8F8A00FC7A71 /* RoomsListViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RoomsListViewController.h; sourceTree = ""; }; + 24D6B3491F3C8F8A00FC7A71 /* RoomsListViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RoomsListViewController.m; sourceTree = ""; }; + 24D6B34A1F3C8F8A00FC7A71 /* SharePresentingViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SharePresentingViewController.h; sourceTree = ""; }; + 24D6B34B1F3C8F8A00FC7A71 /* SharePresentingViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SharePresentingViewController.m; sourceTree = ""; }; + 24D6B34C1F3C8F8A00FC7A71 /* ShareViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShareViewController.h; sourceTree = ""; }; + 24D6B34D1F3C8F8A00FC7A71 /* ShareViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ShareViewController.m; sourceTree = ""; }; + 24D6B34E1F3C8F8A00FC7A71 /* ShareViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ShareViewController.xib; sourceTree = ""; }; + 24D6B3561F3C90D300FC7A71 /* ShareRecentsDataSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShareRecentsDataSource.h; sourceTree = ""; }; + 24D6B3571F3C90D300FC7A71 /* ShareRecentsDataSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ShareRecentsDataSource.m; sourceTree = ""; }; 3205ED7B1E976C8A003D65FA /* DirectoryServerPickerViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DirectoryServerPickerViewController.h; sourceTree = ""; }; 3205ED7C1E976C8A003D65FA /* DirectoryServerPickerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DirectoryServerPickerViewController.m; sourceTree = ""; }; 3205ED811E97725E003D65FA /* DirectoryServerTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DirectoryServerTableViewCell.h; sourceTree = ""; }; @@ -1201,21 +1207,43 @@ children = ( 2466B7551F2F80B800AE27B0 /* Info.plist */, 2466B7561F2F80B800AE27B0 /* RiotShareExtension.entitlements */, - 2466B7591F2F80B800AE27B0 /* SharePresentingViewController.h */, - 2466B75A1F2F80B800AE27B0 /* SharePresentingViewController.m */, - 2466B75B1F2F80B800AE27B0 /* ShareViewController.h */, - 2466B75C1F2F80B800AE27B0 /* ShareViewController.m */, - 2466B75D1F2F80B800AE27B0 /* ShareViewController.xib */, - 2466B7571F2F80B800AE27B0 /* RoomsListViewController.h */, - 2466B7581F2F80B800AE27B0 /* RoomsListViewController.m */, - 2466B7521F2F80B800AE27B0 /* FallbackViewController.h */, - 2466B7531F2F80B800AE27B0 /* FallbackViewController.m */, - 2466B7541F2F80B800AE27B0 /* FallbackViewController.xib */, + 24D6B3441F3C8F8A00FC7A71 /* ViewController */, + 24D6B3551F3C8FCC00FC7A71 /* Model */, ); name = RiotShareExtension; path = "Riot Share Extension"; sourceTree = ""; }; + 24D6B3441F3C8F8A00FC7A71 /* ViewController */ = { + isa = PBXGroup; + children = ( + 24D6B34A1F3C8F8A00FC7A71 /* SharePresentingViewController.h */, + 24D6B34B1F3C8F8A00FC7A71 /* SharePresentingViewController.m */, + 24D6B34C1F3C8F8A00FC7A71 /* ShareViewController.h */, + 24D6B34D1F3C8F8A00FC7A71 /* ShareViewController.m */, + 24D6B34E1F3C8F8A00FC7A71 /* ShareViewController.xib */, + 24D6B3481F3C8F8A00FC7A71 /* RoomsListViewController.h */, + 24D6B3491F3C8F8A00FC7A71 /* RoomsListViewController.m */, + 24D6B3451F3C8F8A00FC7A71 /* FallbackViewController.h */, + 24D6B3461F3C8F8A00FC7A71 /* FallbackViewController.m */, + 24D6B3471F3C8F8A00FC7A71 /* FallbackViewController.xib */, + ); + name = ViewController; + path = RiotShareExtension/ViewController; + sourceTree = SOURCE_ROOT; + }; + 24D6B3551F3C8FCC00FC7A71 /* Model */ = { + isa = PBXGroup; + children = ( + 245FC3EA1F3CAF9800603C6A /* ShareExtensionManager.h */, + 245FC3EB1F3CAF9800603C6A /* ShareExtensionManager.m */, + 24D6B3561F3C90D300FC7A71 /* ShareRecentsDataSource.h */, + 24D6B3571F3C90D300FC7A71 /* ShareRecentsDataSource.m */, + ); + name = Model; + path = RiotShareExtension/Model; + sourceTree = SOURCE_ROOT; + }; 3205ED801E97725E003D65FA /* Directory */ = { isa = PBXGroup; children = ( @@ -2281,16 +2309,16 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 2435179D1F375BA100D0683E /* ShareViewController.xib in Resources */, + 24D6B35B1F3CA03300FC7A71 /* ShareViewController.xib in Resources */, 24EEE5B51F2607C500B3C705 /* SegmentedViewController.xib in Resources */, 24EEE5A91F25529900B3C705 /* cancel@2x.png in Resources */, 2435179C1F375B9400D0683E /* Info.plist in Resources */, - 243517991F375B7100D0683E /* FallbackViewController.xib in Resources */, 24EEE5A81F25529600B3C705 /* cancel@3x.png in Resources */, 2466B73E1F2DFAC100AE27B0 /* animatedLogo-4.png in Resources */, 2435179F1F375C0F00D0683E /* Vector.strings in Resources */, 24EEE5AF1F25F0F500B3C705 /* Images.xcassets in Resources */, 24EEE5AA1F25529C00B3C705 /* cancel.png in Resources */, + 24D6B35E1F3CA03E00FC7A71 /* FallbackViewController.xib in Resources */, 24EEE5A41F24C06E00B3C705 /* (null) in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -2735,13 +2763,15 @@ buildActionMask = 2147483647; files = ( 24EEE5A01F23A08900B3C705 /* RoomTableViewCell.m in Sources */, + 24D6B3581F3C90D300FC7A71 /* ShareRecentsDataSource.m in Sources */, + 24D6B35C1F3CA03600FC7A71 /* RoomsListViewController.m in Sources */, + 24D6B35A1F3CA02C00FC7A71 /* ShareViewController.m in Sources */, + 24D6B3591F3CA02900FC7A71 /* SharePresentingViewController.m in Sources */, 24EEE5A31F23A8C300B3C705 /* AvatarGenerator.m in Sources */, - 2435179E1F375BA600D0683E /* RoomsListViewController.m in Sources */, - 243517981F375B6800D0683E /* FallbackViewController.m in Sources */, - 2435179B1F375B8F00D0683E /* SharePresentingViewController.m in Sources */, + 24D6B35D1F3CA03A00FC7A71 /* FallbackViewController.m in Sources */, 24EEE5A11F23A09A00B3C705 /* RiotDesignValues.m in Sources */, - 2435179A1F375B8A00D0683E /* ShareViewController.m in Sources */, 24EEE5A21F23A8B400B3C705 /* MXRoom+Riot.m in Sources */, + 245FC3ED1F3D079A00603C6A /* ShareExtensionManager.m in Sources */, 24EEE5B41F2607C000B3C705 /* SegmentedViewController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/Riot/Views/RoomList/RoomTableViewCell.h b/Riot/Views/RoomList/RoomTableViewCell.h index 22ff46cc0..92d5cf2cb 100644 --- a/Riot/Views/RoomList/RoomTableViewCell.h +++ b/Riot/Views/RoomList/RoomTableViewCell.h @@ -29,7 +29,7 @@ /** Update the information displayed by the cell. - @param rooom the room to render. + @param room the room to render. */ - (void)render:(MXRoom *)room; diff --git a/RiotShareExtension/Model/ShareExtensionManager.h b/RiotShareExtension/Model/ShareExtensionManager.h new file mode 100644 index 000000000..230e55238 --- /dev/null +++ b/RiotShareExtension/Model/ShareExtensionManager.h @@ -0,0 +1,24 @@ +// +// ShareExtensionManager.h +// Riot +// +// Created by Aram Sargsyan on 8/10/17. +// Copyright © 2017 matrix.org. All rights reserved. +// + +#import +#import + +@interface ShareExtensionManager : NSObject + +@property NSExtensionContext *shareExtensionContext; + ++ (instancetype)sharedManager; + +- (void)sendContentToRoom:(MXRoom *)room failureBlock:(void(^)())failureBlock; + +- (void)cancelSharing; + +- (void)cancelSharingWithFailure; + +@end diff --git a/RiotShareExtension/Model/ShareExtensionManager.m b/RiotShareExtension/Model/ShareExtensionManager.m new file mode 100644 index 000000000..e392397eb --- /dev/null +++ b/RiotShareExtension/Model/ShareExtensionManager.m @@ -0,0 +1,186 @@ +// +// ShareExtensionManager.m +// Riot +// +// Created by Aram Sargsyan on 8/10/17. +// Copyright © 2017 matrix.org. All rights reserved. +// + +#import "ShareExtensionManager.h" +@import MobileCoreServices; + + +@implementation ShareExtensionManager + +#pragma mark - Lifecycle + ++ (instancetype)sharedManager +{ + static ShareExtensionManager *sharedInstance = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + sharedInstance = [[self alloc] init]; + }); + return sharedInstance; +} + +- (void)sendContentToRoom:(MXRoom *)room failureBlock:(void(^)())failureBlock +{ + NSString *UTTypeText = (__bridge NSString *)kUTTypeText; + NSString *UTTypeURL = (__bridge NSString *)kUTTypeURL; + NSString *UTTypeImage = (__bridge NSString *)kUTTypeImage; + NSString *UTTypeVideo = (__bridge NSString *)kUTTypeVideo; + + for (NSExtensionItem *item in self.shareExtensionContext.inputItems) + { + for (NSItemProvider *itemProvider in item.attachments) + { + if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeText]) + { + [itemProvider loadItemForTypeIdentifier:UTTypeText options:nil completionHandler:^(NSString *text, NSError * _Null_unspecified error) { + if (!text) + { + if (failureBlock) + { + failureBlock(); + } + return; + } + [room sendTextMessage:text success:^(NSString *eventId) { + [self.shareExtensionContext completeRequestReturningItems:@[item] completionHandler:nil]; + } failure:^(NSError *error) { + NSLog(@"[ShareExtensionManager] sendTextMessage failed."); + if (failureBlock) + { + failureBlock(); + } + }]; + }]; + } + else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeURL]) + { + [itemProvider loadItemForTypeIdentifier:UTTypeURL options:nil completionHandler:^(NSURL *url, NSError * _Null_unspecified error) { + if (!url) + { + if (failureBlock) + { + failureBlock(); + } + return; + } + [room sendTextMessage:url.absoluteString success:^(NSString *eventId) { + [self.shareExtensionContext completeRequestReturningItems:@[item] completionHandler:nil]; + } failure:^(NSError *error) { + NSLog(@"[ShareExtensionManager] sendTextMessage failed."); + if (failureBlock) + { + failureBlock(); + } + }]; + }]; + } + else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeImage]) + { + [itemProvider loadItemForTypeIdentifier:UTTypeImage options:nil completionHandler:^(NSData *imageData, NSError * _Null_unspecified error) + { + if (!imageData) + { + if (failureBlock) + { + failureBlock(); + } + return; + } + //Send the image + UIImage *image = [[UIImage alloc] initWithData:imageData]; + + NSString *mimeType; + if ([itemProvider hasItemConformingToTypeIdentifier:(__bridge NSString *)kUTTypePNG]) + { + mimeType = @"image/png"; + } + else if ([itemProvider hasItemConformingToTypeIdentifier:(__bridge NSString *)kUTTypeJPEG]) + { + mimeType = @"image/jpeg"; + } + else + { + image = [[UIImage alloc] initWithData:UIImageJPEGRepresentation(image, 1.0)]; + mimeType = @"image/jpeg"; + } + + UIImage *thumbnail = nil; + // Thumbnail is useful only in case of encrypted room + if (room.state.isEncrypted) + { + thumbnail = [MXKTools reduceImage:image toFitInSize:CGSizeMake(800, 600)]; + if (thumbnail == image) + { + thumbnail = nil; + } + } + [room sendImage:imageData withImageSize:image.size mimeType:mimeType andThumbnail:thumbnail localEcho:nil success:^(NSString *eventId) + { + [self.shareExtensionContext completeRequestReturningItems:@[item] completionHandler:nil]; + } + failure:^(NSError *error) + { + NSLog(@"[ShareExtensionManager] sendImage failed."); + if (failureBlock) + { + failureBlock(); + } + }]; + }]; + } + else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeVideo]) + { + [itemProvider loadItemForTypeIdentifier:UTTypeVideo options:nil completionHandler:^(NSURL *videoLocalUrl, NSError * _Null_unspecified error) + { + if (!videoLocalUrl) + { + if (failureBlock) + { + failureBlock(); + } + return; + } + + // Retrieve the video frame at 1 sec to define the video thumbnail + AVURLAsset *urlAsset = [[AVURLAsset alloc] initWithURL:videoLocalUrl options:nil]; + AVAssetImageGenerator *assetImageGenerator = [AVAssetImageGenerator assetImageGeneratorWithAsset:urlAsset]; + assetImageGenerator.appliesPreferredTrackTransform = YES; + CMTime time = CMTimeMake(1, 1); + CGImageRef imageRef = [assetImageGenerator copyCGImageAtTime:time actualTime:NULL error:nil]; + // Finalize video attachment + UIImage *videoThumbnail = [[UIImage alloc] initWithCGImage:imageRef]; + CFRelease(imageRef); + + [room sendVideo:videoLocalUrl withThumbnail:videoThumbnail localEcho:nil success:^(NSString *eventId) { + [self.shareExtensionContext completeRequestReturningItems:@[item] completionHandler:nil]; + } failure:^(NSError *error) { + NSLog(@"[ShareExtensionManager] sendVideo failed."); + if (failureBlock) + { + failureBlock(); + } + }]; + + }]; + } + } + } +} + +- (void)cancelSharing +{ + [self.shareExtensionContext cancelRequestWithError:[NSError errorWithDomain:@"MXUserCancelErrorDomain" code:4201 userInfo:nil]]; +} + +- (void)cancelSharingWithFailure +{ + [self.shareExtensionContext cancelRequestWithError:[NSError errorWithDomain:@"MXFailureErrorDomain" code:500 userInfo:nil]]; +} + + +@end diff --git a/RiotShareExtension/Model/ShareRecentsDataSource.h b/RiotShareExtension/Model/ShareRecentsDataSource.h new file mode 100644 index 000000000..5e878f4c5 --- /dev/null +++ b/RiotShareExtension/Model/ShareRecentsDataSource.h @@ -0,0 +1,21 @@ +// +// ShareRecentsDataSource.h +// Riot +// +// Created by Aram Sargsyan on 8/10/17. +// Copyright © 2017 matrix.org. All rights reserved. +// + +#import + +typedef NS_ENUM(NSInteger, ShareRecentsDataSourceMode) +{ + RecentsDataSourceModePeople, + RecentsDataSourceModeRooms +}; + +@interface ShareRecentsDataSource : MXKRecentsDataSource + +- (instancetype)initWithMatrixSession:(MXSession *)mxSession dataSourceMode:(ShareRecentsDataSourceMode)dataSourceMode; + +@end diff --git a/RiotShareExtension/Model/ShareRecentsDataSource.m b/RiotShareExtension/Model/ShareRecentsDataSource.m new file mode 100644 index 000000000..fc4a4f1f4 --- /dev/null +++ b/RiotShareExtension/Model/ShareRecentsDataSource.m @@ -0,0 +1,128 @@ +// +// ShareRecentsDataSource.m +// Riot +// +// Created by Aram Sargsyan on 8/10/17. +// Copyright © 2017 matrix.org. All rights reserved. +// + +#import "ShareRecentsDataSource.h" +#import "RoomTableViewCell.h" + +@interface ShareRecentsDataSource () + +@property (nonatomic, readwrite) ShareRecentsDataSourceMode dataSourceMode; + +@property NSMutableArray *recentRooms; +@property NSMutableArray *recentPeople; + +@end + +@implementation ShareRecentsDataSource + +- (instancetype)initWithMatrixSession:(MXSession *)mxSession dataSourceMode:(ShareRecentsDataSourceMode)dataSourceMode +{ + self = [super initWithMatrixSession:mxSession]; + if (self) + { + _recentRooms = [NSMutableArray array]; + _recentPeople = [NSMutableArray array]; + self.dataSourceMode = dataSourceMode; + } + return self; +} + +#pragma mark - Private + +- (void)updateArrays +{ + [self.recentPeople removeAllObjects]; + [self.recentRooms removeAllObjects]; + + MXKSessionRecentsDataSource *recentsDataSource = displayedRecentsDataSourceArray.firstObject; + NSInteger count = recentsDataSource.numberOfCells; + + for (int index = 0; index < count; index++) + { + id cellData = [recentsDataSource cellDataAtIndex:index]; + MXRoom* room = cellData.roomSummary.room; + + if (self.dataSourceMode == RecentsDataSourceModePeople) + { + if (room.isDirect) + { + [self.recentPeople addObject:cellData]; + } + } + else if (self.dataSourceMode == RecentsDataSourceModeRooms) + { + if (!room.isDirect) + { + [self.recentRooms addObject:cellData]; + } + } + } +} + +#pragma mark - MXKRecentsDataSource + +- (id)cellDataAtIndexPath:(NSIndexPath *)indexPath +{ + id cellData = nil; + + if (self.dataSourceMode == RecentsDataSourceModePeople) + { + cellData = self.recentPeople[indexPath.row]; + } + else + { + cellData = self.recentRooms[indexPath.row]; + } + + return cellData; +} + +- (void)dataSource:(MXKDataSource*)dataSource didCellChange:(id)changes +{ + [super dataSource:dataSource didCellChange:changes]; + [self updateArrays]; + + [self.delegate dataSource:self didCellChange:changes]; +} + +#pragma mark - UITableViewDataSource + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView +{ + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section +{ + if (self.dataSourceMode == RecentsDataSourceModePeople) + { + return self.recentPeople.count; + } + else + { + return self.recentRooms.count; + } +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath +{ + RoomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[RoomTableViewCell defaultReuseIdentifier]]; + + MXRoom *room = [self cellDataAtIndexPath:indexPath].roomSummary.room; + + [cell render:room]; + + if (!room.summary.displayname.length && !cell.titleLabel.text.length) + { + cell.titleLabel.text = NSLocalizedStringFromTable(@"room_displayname_no_title", @"Vector", nil); + } + + return cell; +} + +@end diff --git a/RiotShareExtension/RoomsListViewController.m b/RiotShareExtension/RoomsListViewController.m deleted file mode 100644 index ef75cbab7..000000000 --- a/RiotShareExtension/RoomsListViewController.m +++ /dev/null @@ -1,274 +0,0 @@ -/* - Copyright 2017 Aram Sargsyan - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - */ - -#import "RoomsListViewController.h" -#import "RoomTableViewCell.h" -#import "NSBundle+MatrixKit.h" -@import MobileCoreServices; - - -@interface RoomsListViewController () - -@property (nonatomic) NSExtensionContext *shareExtensionContext; -@property (copy) void (^failureBlock)(); -@property (nonatomic) NSArray *rooms; -@property (nonatomic) UITableView *mainTableView; - -@end - - -@implementation RoomsListViewController - -#pragma mark - Lifecycle - -- (void)viewDidLoad -{ - [super viewDidLoad]; - [self configureTableView]; -} - -#pragma mark - Public - -+ (instancetype)listViewControllerWithContext:(NSExtensionContext *)context failureBlock:(void(^)())failureBlock -{ - RoomsListViewController *listViewController = [[self class] new]; - listViewController.shareExtensionContext = context; - listViewController.failureBlock = failureBlock; - return listViewController; -} - -- (void)updateWithRooms:(NSArray *)rooms -{ - self.rooms = rooms; - [self.mainTableView reloadData]; -} - -#pragma mark - Views - -- (void)configureTableView -{ - self.mainTableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain]; - self.mainTableView.dataSource = self; - self.mainTableView.delegate = self; - [self.mainTableView registerNib:[RoomTableViewCell nib] forCellReuseIdentifier:[RoomTableViewCell defaultReuseIdentifier]]; - - [self.view addSubview:self.mainTableView]; - self.mainTableView.translatesAutoresizingMaskIntoConstraints = NO; - self.view.translatesAutoresizingMaskIntoConstraints = NO; - NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:self.mainTableView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeWidth multiplier:1 constant:0]; - widthConstraint.active = YES; - NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:self.mainTableView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeHeight multiplier:1 constant:0]; - heightConstraint.active = YES; - NSLayoutConstraint *centerXConstraint = [NSLayoutConstraint constraintWithItem:self.mainTableView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]; - centerXConstraint.active = YES; - NSLayoutConstraint *centerYConstraint = [NSLayoutConstraint constraintWithItem:self.mainTableView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]; - centerYConstraint.active = YES; -} - -#pragma mark - Private - -- (void)sendToRoom:(MXRoom *)room -{ - NSString *UTTypeText = (__bridge NSString *)kUTTypeText; - NSString *UTTypeURL = (__bridge NSString *)kUTTypeURL; - NSString *UTTypeImage = (__bridge NSString *)kUTTypeImage; - NSString *UTTypeVideo = (__bridge NSString *)kUTTypeVideo; - - for (NSExtensionItem *item in self.shareExtensionContext.inputItems) - { - for (NSItemProvider *itemProvider in item.attachments) - { - if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeText]) - { - [itemProvider loadItemForTypeIdentifier:UTTypeText options:nil completionHandler:^(NSString *text, NSError * _Null_unspecified error) { - if (!text) - { - [self showFailureAlert]; - return; - } - [room sendTextMessage:text success:^(NSString *eventId) { - [self.shareExtensionContext completeRequestReturningItems:@[item] completionHandler:nil]; - } failure:^(NSError *error) { - NSLog(@"[RoomsListViewController] sendTextMessage failed."); - [self showFailureAlert]; - }]; - }]; - } - else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeURL]) - { - [itemProvider loadItemForTypeIdentifier:UTTypeURL options:nil completionHandler:^(NSURL *url, NSError * _Null_unspecified error) { - if (!url) - { - [self showFailureAlert]; - return; - } - [room sendTextMessage:url.absoluteString success:^(NSString *eventId) { - [self.shareExtensionContext completeRequestReturningItems:@[item] completionHandler:nil]; - } failure:^(NSError *error) { - NSLog(@"[RoomsListViewController] sendTextMessage failed."); - [self showFailureAlert]; - }]; - }]; - } - else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeImage]) - { - [itemProvider loadItemForTypeIdentifier:UTTypeImage options:nil completionHandler:^(NSData *imageData, NSError * _Null_unspecified error) - { - if (!imageData) - { - [self showFailureAlert]; - return; - } - //Send the image - UIImage *image = [[UIImage alloc] initWithData:imageData]; - - NSString *mimeType; - if ([itemProvider hasItemConformingToTypeIdentifier:(__bridge NSString *)kUTTypePNG]) - { - mimeType = @"image/png"; - } - else if ([itemProvider hasItemConformingToTypeIdentifier:(__bridge NSString *)kUTTypeJPEG]) - { - mimeType = @"image/jpeg"; - } - else - { - image = [[UIImage alloc] initWithData:UIImageJPEGRepresentation(image, 1.0)]; - mimeType = @"image/jpeg"; - } - - UIImage *thumbnail = nil; - // Thumbnail is useful only in case of encrypted room - if (room.state.isEncrypted) - { - thumbnail = [MXKTools reduceImage:image toFitInSize:CGSizeMake(800, 600)]; - if (thumbnail == image) - { - thumbnail = nil; - } - } - [room sendImage:imageData withImageSize:image.size mimeType:mimeType andThumbnail:thumbnail localEcho:nil success:^(NSString *eventId) - { - [self.shareExtensionContext completeRequestReturningItems:@[item] completionHandler:nil]; - } - failure:^(NSError *error) - { - NSLog(@"[RoomsListViewController] sendImage failed."); - [self showFailureAlert]; - }]; - }]; - } - else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeVideo]) - { - [itemProvider loadItemForTypeIdentifier:UTTypeVideo options:nil completionHandler:^(NSURL *videoLocalUrl, NSError * _Null_unspecified error) - { - if (!videoLocalUrl) - { - [self showFailureAlert]; - return; - } - - // Retrieve the video frame at 1 sec to define the video thumbnail - AVURLAsset *urlAsset = [[AVURLAsset alloc] initWithURL:videoLocalUrl options:nil]; - AVAssetImageGenerator *assetImageGenerator = [AVAssetImageGenerator assetImageGeneratorWithAsset:urlAsset]; - assetImageGenerator.appliesPreferredTrackTransform = YES; - CMTime time = CMTimeMake(1, 1); - CGImageRef imageRef = [assetImageGenerator copyCGImageAtTime:time actualTime:NULL error:nil]; - // Finalize video attachment - UIImage *videoThumbnail = [[UIImage alloc] initWithCGImage:imageRef]; - CFRelease(imageRef); - - [room sendVideo:videoLocalUrl withThumbnail:videoThumbnail localEcho:nil success:^(NSString *eventId) { - [self.shareExtensionContext completeRequestReturningItems:@[item] completionHandler:nil]; - } failure:^(NSError *error) { - NSLog(@"[RoomsListViewController] sendVideo failed."); - [self showFailureAlert]; - }]; - - }]; - } - } - } -} - -- (void)showFailureAlert -{ - UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedStringFromTable(@"room_event_failed_to_send", @"Vector", nil) message:nil preferredStyle:UIAlertControllerStyleAlert]; - UIAlertAction *okAction = [UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"ok"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { - if (self.failureBlock) - { - self.failureBlock(); - } - else - { - [self.shareExtensionContext cancelRequestWithError:[NSError errorWithDomain:@"MXUserFailureErrorDomain" code:500 userInfo:nil]]; - } - }]; - [alertController addAction:okAction]; - [self presentViewController:alertController animated:YES completion:nil]; -} - -#pragma mark - UITableViewDataSource - -- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView -{ - return 1; -} - -- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section -{ - return self.rooms.count; -} - -- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath -{ - RoomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[RoomTableViewCell defaultReuseIdentifier]]; - MXRoom *room = self.rooms[indexPath.row]; - - [cell render:room]; - if (!room.summary.displayname.length && !cell.titleLabel.text.length) - { - cell.titleLabel.text = NSLocalizedStringFromTable(@"room_displayname_no_title", @"Vector", nil); - } - - return cell; -} - -#pragma mark - UITableViewDelegate - -- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath -{ - return [RoomTableViewCell cellHeight]; -} - -- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath -{ - [tableView deselectRowAtIndexPath:indexPath animated:YES]; - - UIAlertController *alertController = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:NSLocalizedStringFromTable(@"send_to", @"Vector", nil), self.rooms[indexPath.row].riotDisplayname] message:nil preferredStyle:UIAlertControllerStyleAlert]; - - UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"] style:UIAlertActionStyleCancel handler:nil]; - [alertController addAction:cancelAction]; - - UIAlertAction *sendAction = [UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"send"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { - [self sendToRoom:self.rooms[indexPath.row]]; - }]; - [alertController addAction:sendAction]; - - [self presentViewController:alertController animated:YES completion:nil]; -} - -@end diff --git a/RiotShareExtension/ViewController/.DS_Store b/RiotShareExtension/ViewController/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..2535820cd938362acc8c8e59f36bdbbdecad7565 GIT binary patch literal 6148 zcmeHK!Ab)$5PhRP6utB!tzO)tC&9CqrB*@kAQn99)?$mT3$3EZz4#CQg5T!{=$jYOZ0Gqa}4Kt zTZJ)T4E#0*bnUiq#C1F3ue^Tyc)$U2+~N)sqPF*0+Qr~_l=rexp3zq~j(zIRn-i9* z#~VlSUZQwg7036;-6xxkDa|P6CeApg9Aivz!v0gvQg^MTXDv_Pju_2bUZaTH=wiUk zOgO4jXQwP_K8Cc{)yC_x^jyl)_o7E*hvuvteWNt?YP@Quz7{DOlgm&!Qgi7sE&2y( zcFNKC_{W83wn}~7qgi9X7%&Dt7|{J8p(>^U3y*H=pmA3KVvW^KSk_Mh^+^Jz0Sk|8 zp@?@SdRGZo4Ds%)PeQ*mVByibL&D`l!kZ=BP{h5R@e|h_l6o|23>X8m46ORchMxb2 zpWpvyo$SdNFb4h=15)dBJ8e!WoUL<{)3Y|AUQkuEU*XZY(1hdI74#@>QJt_Y(E>3I TSa@U Za4Q7miA7$Vj@H5rp literal 0 HcmV?d00001 diff --git a/RiotShareExtension/FallbackViewController.h b/RiotShareExtension/ViewController/FallbackViewController.h similarity index 100% rename from RiotShareExtension/FallbackViewController.h rename to RiotShareExtension/ViewController/FallbackViewController.h diff --git a/RiotShareExtension/FallbackViewController.m b/RiotShareExtension/ViewController/FallbackViewController.m similarity index 100% rename from RiotShareExtension/FallbackViewController.m rename to RiotShareExtension/ViewController/FallbackViewController.m diff --git a/RiotShareExtension/FallbackViewController.xib b/RiotShareExtension/ViewController/FallbackViewController.xib similarity index 100% rename from RiotShareExtension/FallbackViewController.xib rename to RiotShareExtension/ViewController/FallbackViewController.xib diff --git a/RiotShareExtension/RoomsListViewController.h b/RiotShareExtension/ViewController/RoomsListViewController.h similarity index 72% rename from RiotShareExtension/RoomsListViewController.h rename to RiotShareExtension/ViewController/RoomsListViewController.h index 0b4f01b08..6054a1ddf 100644 --- a/RiotShareExtension/RoomsListViewController.h +++ b/RiotShareExtension/ViewController/RoomsListViewController.h @@ -16,11 +16,10 @@ #import #import "MXRoom+Riot.h" +#import "ShareRecentsDataSource.h" -@interface RoomsListViewController : UIViewController +@interface RoomsListViewController : UIViewController -+ (instancetype)listViewControllerWithContext:(NSExtensionContext *)context failureBlock:(void(^)())failureBlock; - -- (void)updateWithRooms:(NSArray *)rooms; ++ (instancetype)listViewControllerWithDataSource:(ShareRecentsDataSource *)dataSource failureBlock:(void(^)())failureBlock; @end diff --git a/RiotShareExtension/ViewController/RoomsListViewController.m b/RiotShareExtension/ViewController/RoomsListViewController.m new file mode 100644 index 000000000..b2f957900 --- /dev/null +++ b/RiotShareExtension/ViewController/RoomsListViewController.m @@ -0,0 +1,152 @@ +/* + Copyright 2017 Aram Sargsyan + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#import "RoomsListViewController.h" +#import "RoomTableViewCell.h" +#import "NSBundle+MatrixKit.h" +#import "ShareExtensionManager.h" + + +@interface RoomsListViewController () + +@property (nonatomic) ShareRecentsDataSource *dataSource; +@property (copy) void (^failureBlock)(); + +@property (nonatomic) UITableView *mainTableView; + +@end + + +@implementation RoomsListViewController + +#pragma mark - Lifecycle + +- (void)viewDidLoad +{ + [super viewDidLoad]; + [self configureTableView]; +} + +#pragma mark - Public + ++ (instancetype)listViewControllerWithDataSource:(ShareRecentsDataSource *)dataSource failureBlock:(void(^)())failureBlock +{ + RoomsListViewController *listViewController = [[self class] new]; + listViewController.dataSource = dataSource; + listViewController.failureBlock = failureBlock; + return listViewController; +} + +#pragma mark - Views + +- (void)configureTableView +{ + self.mainTableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain]; + self.mainTableView.dataSource = self.dataSource; + self.mainTableView.delegate = self; + [self.mainTableView registerNib:[RoomTableViewCell nib] forCellReuseIdentifier:[RoomTableViewCell defaultReuseIdentifier]]; + + [self.view addSubview:self.mainTableView]; + self.mainTableView.translatesAutoresizingMaskIntoConstraints = NO; + self.view.translatesAutoresizingMaskIntoConstraints = NO; + NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:self.mainTableView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeWidth multiplier:1 constant:0]; + widthConstraint.active = YES; + NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:self.mainTableView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeHeight multiplier:1 constant:0]; + heightConstraint.active = YES; + NSLayoutConstraint *centerXConstraint = [NSLayoutConstraint constraintWithItem:self.mainTableView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]; + centerXConstraint.active = YES; + NSLayoutConstraint *centerYConstraint = [NSLayoutConstraint constraintWithItem:self.mainTableView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]; + centerYConstraint.active = YES; +} + +#pragma mark - Private + +- (void)showFailureAlert +{ + UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedStringFromTable(@"room_event_failed_to_send", @"Vector", nil) message:nil preferredStyle:UIAlertControllerStyleAlert]; + UIAlertAction *okAction = [UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"ok"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { + if (self.failureBlock) + { + self.failureBlock(); + [[ShareExtensionManager sharedManager] cancelSharing]; + } + }]; + [alertController addAction:okAction]; + [self presentViewController:alertController animated:YES completion:nil]; +} + +#pragma mark - UITableViewDelegate + +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath +{ + return [RoomTableViewCell cellHeight]; +} + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath +{ + [tableView deselectRowAtIndexPath:indexPath animated:YES]; + + NSString *receipantName = [self.dataSource getRoomAtIndexPath:indexPath].riotDisplayname; + if (!receipantName.length) + { + receipantName = NSLocalizedStringFromTable(@"room_displayname_no_title", @"Vector", nil); + } + + UIAlertController *alertController = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:NSLocalizedStringFromTable(@"send_to", @"Vector", nil), receipantName] message:nil preferredStyle:UIAlertControllerStyleAlert]; + + UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"] style:UIAlertActionStyleCancel handler:nil]; + [alertController addAction:cancelAction]; + + UIAlertAction *sendAction = [UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"send"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { + MXRoom *selectedRoom = [self.dataSource getRoomAtIndexPath:indexPath]; + [[ShareExtensionManager sharedManager] sendContentToRoom:selectedRoom failureBlock:^{ + [self showFailureAlert]; + }]; + }]; + [alertController addAction:sendAction]; + + [self presentViewController:alertController animated:YES completion:nil]; +} + +#pragma mark - MXKDataSourceDelegate + +- (void)dataSource:(MXKDataSource*)dataSource didCellChange:(id)changes +{ + if (dataSource == self.dataSource) + { + [self.mainTableView reloadData]; + } +} + +- (Class)cellViewClassForCellData:(MXKCellData*)cellData +{ + if ([cellData isKindOfClass:[MXKRecentCellData class]]) + { + return [RoomTableViewCell class]; + } + return nil; +} + +- (NSString *)cellReuseIdentifierForCellData:(MXKCellData*)cellData +{ + if ([cellData isKindOfClass:[MXKRecentCellData class]]) + { + return [RoomTableViewCell defaultReuseIdentifier]; + } + return nil; +} + +@end diff --git a/RiotShareExtension/SharePresentingViewController.h b/RiotShareExtension/ViewController/SharePresentingViewController.h similarity index 100% rename from RiotShareExtension/SharePresentingViewController.h rename to RiotShareExtension/ViewController/SharePresentingViewController.h diff --git a/RiotShareExtension/SharePresentingViewController.m b/RiotShareExtension/ViewController/SharePresentingViewController.m similarity index 91% rename from RiotShareExtension/SharePresentingViewController.m rename to RiotShareExtension/ViewController/SharePresentingViewController.m index 0ede49b4e..3125425d7 100644 --- a/RiotShareExtension/SharePresentingViewController.m +++ b/RiotShareExtension/ViewController/SharePresentingViewController.m @@ -16,6 +16,7 @@ #import "SharePresentingViewController.h" #import "ShareViewController.h" +#import "ShareExtensionManager.h" @interface SharePresentingViewController () @@ -27,8 +28,9 @@ { [super viewDidLoad]; + [ShareExtensionManager sharedManager].shareExtensionContext = self.extensionContext; + ShareViewController *shareViewController = [[ShareViewController alloc] init]; - shareViewController.shareExtensionContext = self.extensionContext; shareViewController.providesPresentationContextTransitionStyle = YES; shareViewController.definesPresentationContext = YES; diff --git a/RiotShareExtension/ShareViewController.h b/RiotShareExtension/ViewController/ShareViewController.h similarity index 91% rename from RiotShareExtension/ShareViewController.h rename to RiotShareExtension/ViewController/ShareViewController.h index a3d464ee1..a7ce75c4d 100644 --- a/RiotShareExtension/ShareViewController.h +++ b/RiotShareExtension/ViewController/ShareViewController.h @@ -20,6 +20,4 @@ @interface ShareViewController : MXKViewController -@property (nonatomic) NSExtensionContext *shareExtensionContext; - @end diff --git a/RiotShareExtension/ShareViewController.m b/RiotShareExtension/ViewController/ShareViewController.m similarity index 76% rename from RiotShareExtension/ShareViewController.m rename to RiotShareExtension/ViewController/ShareViewController.m index 8c18b34f9..8e3439bea 100644 --- a/RiotShareExtension/ShareViewController.m +++ b/RiotShareExtension/ViewController/ShareViewController.m @@ -18,12 +18,16 @@ #import "SegmentedViewController.h" #import "RoomsListViewController.h" #import "FallbackViewController.h" +#import "ShareRecentsDataSource.h" +#import "ShareExtensionManager.h" @interface ShareViewController () @property (nonatomic) NSArray *rooms; +@property (nonatomic) MXKRecentsDataSource *recentsDataSource; + @property (weak, nonatomic) IBOutlet UIView *masterContainerView; @property (weak, nonatomic) IBOutlet UILabel *tittleLabel; @property (weak, nonatomic) IBOutlet UIView *contentView; @@ -103,11 +107,18 @@ NSArray *titles = @[NSLocalizedStringFromTable(@"title_rooms", @"Vector", nil) , NSLocalizedStringFromTable(@"title_people", @"Vector", nil)]; void (^failureBlock)() = ^void() { - [self finishSharingCanceled:NO]; + [[ShareExtensionManager sharedManager] cancelSharingWithFailure]; }; - NSArray *viewControllers = @[[RoomsListViewController listViewControllerWithContext:self.shareExtensionContext failureBlock:failureBlock], [RoomsListViewController listViewControllerWithContext:self.shareExtensionContext failureBlock:failureBlock]]; - [self.segmentedViewController initWithTitles:titles viewControllers:viewControllers defaultSelected:0]; + ShareRecentsDataSource *roomsDataSource = [[ShareRecentsDataSource alloc] initWithMatrixSession:self.mainSession dataSourceMode:RecentsDataSourceModeRooms]; + RoomsListViewController *roomsViewController = [RoomsListViewController listViewControllerWithDataSource:roomsDataSource failureBlock:failureBlock]; + roomsDataSource.delegate = roomsViewController; + + ShareRecentsDataSource *peopleDataSource = [[ShareRecentsDataSource alloc] initWithMatrixSession:self.mainSession dataSourceMode:RecentsDataSourceModePeople]; + RoomsListViewController *peopleViewController = [RoomsListViewController listViewControllerWithDataSource:peopleDataSource failureBlock:failureBlock]; + peopleDataSource.delegate = peopleViewController; + + [self.segmentedViewController initWithTitles:titles viewControllers:@[roomsViewController, peopleViewController] defaultSelected:0]; [self addChildViewController:self.segmentedViewController]; [self.contentView addSubview:self.segmentedViewController.view]; @@ -139,48 +150,13 @@ centerYConstraint.active = YES; } -- (void)finishSharingCanceled:(BOOL)canceled -{ - [self dismissViewControllerAnimated:YES completion:^{ - NSError *error; - if (canceled) - { - error = [NSError errorWithDomain:@"MXUserCancelErrorDomain" code:4201 userInfo:nil]; - } - else - { - error = [NSError errorWithDomain:@"MXUserFailureErrorDomain" code:500 userInfo:nil]; - } - [self.shareExtensionContext cancelRequestWithError:error]; - }]; -} - #pragma mark - Notifications - (void)onSessionSync:(NSNotification *)notification { if ([notification.object isEqual:self.mainSession] && !self.rooms.count) { - self.rooms = self.mainSession.rooms; - if (self.rooms.count) - { - NSMutableArray *directRooms = [NSMutableArray array]; - NSMutableArray *rooms = [NSMutableArray array]; - for (MXRoom *room in self.rooms) - { - if (room.isDirect) - { - [directRooms addObject:room]; - } - else - { - [rooms addObject:room]; - } - } - - [((RoomsListViewController *)self.segmentedViewController.viewControllers[0]) updateWithRooms:rooms]; - [((RoomsListViewController *)self.segmentedViewController.viewControllers[1]) updateWithRooms:directRooms]; - } + self.recentsDataSource = [[MXKRecentsDataSource alloc] initWithMatrixSession:self.mainSession]; } } @@ -188,7 +164,7 @@ - (IBAction)close:(UIButton *)sender { - [self finishSharingCanceled:YES]; + [[ShareExtensionManager sharedManager] cancelSharing]; } diff --git a/RiotShareExtension/ShareViewController.xib b/RiotShareExtension/ViewController/ShareViewController.xib similarity index 100% rename from RiotShareExtension/ShareViewController.xib rename to RiotShareExtension/ViewController/ShareViewController.xib From ef2e38b63fc833e5d11ec0ee8844948b99f786a1 Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Fri, 11 Aug 2017 20:33:50 +0400 Subject: [PATCH 017/102] Added search functionality for rooms and people, fixed bug of dismmisal --- Riot.xcodeproj/project.pbxproj | 2 + .../Model/ShareRecentsDataSource.m | 12 ++++- .../ViewController/RoomsListViewController.m | 51 +++++++++++++++++-- .../SharePresentingViewController.m | 5 ++ .../ViewController/ShareViewController.m | 8 ++- 5 files changed, 71 insertions(+), 7 deletions(-) diff --git a/Riot.xcodeproj/project.pbxproj b/Riot.xcodeproj/project.pbxproj index 03e34af48..75fcaabb4 100644 --- a/Riot.xcodeproj/project.pbxproj +++ b/Riot.xcodeproj/project.pbxproj @@ -11,6 +11,7 @@ 2435179C1F375B9400D0683E /* Info.plist in Resources */ = {isa = PBXBuildFile; fileRef = 2466B7551F2F80B800AE27B0 /* Info.plist */; }; 2435179F1F375C0F00D0683E /* Vector.strings in Resources */ = {isa = PBXBuildFile; fileRef = 327382C01F276AED00356143 /* Vector.strings */; }; 245FC3ED1F3D079A00603C6A /* ShareExtensionManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 245FC3EB1F3CAF9800603C6A /* ShareExtensionManager.m */; }; + 245FC3EF1F3DD30800603C6A /* RecentCellData.m in Sources */ = {isa = PBXBuildFile; fileRef = F083BC071E7009EC00A9B29C /* RecentCellData.m */; }; 2466B73E1F2DFAC100AE27B0 /* animatedLogo-4.png in Resources */ = {isa = PBXBuildFile; fileRef = F083BB201E7009EC00A9B29C /* animatedLogo-4.png */; }; 24B5103E1EFA7083004C6AD2 /* ReadReceiptsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 24B5103D1EFA7083004C6AD2 /* ReadReceiptsViewController.m */; }; 24B510401EFA88CC004C6AD2 /* ReadReceiptsViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 24B5103F1EFA88CC004C6AD2 /* ReadReceiptsViewController.xib */; }; @@ -2764,6 +2765,7 @@ files = ( 24EEE5A01F23A08900B3C705 /* RoomTableViewCell.m in Sources */, 24D6B3581F3C90D300FC7A71 /* ShareRecentsDataSource.m in Sources */, + 245FC3EF1F3DD30800603C6A /* RecentCellData.m in Sources */, 24D6B35C1F3CA03600FC7A71 /* RoomsListViewController.m in Sources */, 24D6B35A1F3CA02C00FC7A71 /* ShareViewController.m in Sources */, 24D6B3591F3CA02900FC7A71 /* SharePresentingViewController.m in Sources */, diff --git a/RiotShareExtension/Model/ShareRecentsDataSource.m b/RiotShareExtension/Model/ShareRecentsDataSource.m index fc4a4f1f4..609332cd0 100644 --- a/RiotShareExtension/Model/ShareRecentsDataSource.m +++ b/RiotShareExtension/Model/ShareRecentsDataSource.m @@ -8,6 +8,7 @@ #import "ShareRecentsDataSource.h" #import "RoomTableViewCell.h" +#import "RecentCellData.h" @interface ShareRecentsDataSource () @@ -25,13 +26,14 @@ self = [super initWithMatrixSession:mxSession]; if (self) { + self.dataSourceMode = dataSourceMode; _recentRooms = [NSMutableArray array]; _recentPeople = [NSMutableArray array]; - self.dataSourceMode = dataSourceMode; } return self; } + #pragma mark - Private - (void)updateArrays @@ -66,6 +68,11 @@ #pragma mark - MXKRecentsDataSource +- (Class)cellDataClassForCellIdentifier:(NSString *)identifier +{ + return RecentCellData.class; +} + - (id)cellDataAtIndexPath:(NSIndexPath *)indexPath { id cellData = nil; @@ -85,8 +92,8 @@ - (void)dataSource:(MXKDataSource*)dataSource didCellChange:(id)changes { [super dataSource:dataSource didCellChange:changes]; - [self updateArrays]; + [self updateArrays]; [self.delegate dataSource:self didCellChange:changes]; } @@ -125,4 +132,5 @@ return cell; } + @end diff --git a/RiotShareExtension/ViewController/RoomsListViewController.m b/RiotShareExtension/ViewController/RoomsListViewController.m index b2f957900..512c597b7 100644 --- a/RiotShareExtension/ViewController/RoomsListViewController.m +++ b/RiotShareExtension/ViewController/RoomsListViewController.m @@ -18,14 +18,17 @@ #import "RoomTableViewCell.h" #import "NSBundle+MatrixKit.h" #import "ShareExtensionManager.h" +#import "RecentCellData.h" +#import "RiotDesignValues.h" -@interface RoomsListViewController () +@interface RoomsListViewController () @property (nonatomic) ShareRecentsDataSource *dataSource; @property (copy) void (^failureBlock)(); @property (nonatomic) UITableView *mainTableView; +@property (nonatomic) UISearchBar *searchBar; @end @@ -38,6 +41,7 @@ { [super viewDidLoad]; [self configureTableView]; + [self configureSearchBar]; } #pragma mark - Public @@ -70,6 +74,23 @@ centerXConstraint.active = YES; NSLayoutConstraint *centerYConstraint = [NSLayoutConstraint constraintWithItem:self.mainTableView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]; centerYConstraint.active = YES; + + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + [self.dataSource searchWithPatterns:nil]; + }); +} + +- (void)configureSearchBar +{ + self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, 44.0)]; + self.searchBar.searchBarStyle = UISearchBarStyleMinimal; + self.searchBar.placeholder = NSLocalizedStringFromTable(@"search_default_placeholder", @"Vector", nil); + self.searchBar.tintColor = kRiotColorGreen; + self.searchBar.showsCancelButton = YES; + + self.searchBar.delegate = self; + + self.mainTableView.tableHeaderView = self.searchBar; } #pragma mark - Private @@ -81,7 +102,6 @@ if (self.failureBlock) { self.failureBlock(); - [[ShareExtensionManager sharedManager] cancelSharing]; } }]; [alertController addAction:okAction]; @@ -133,7 +153,7 @@ - (Class)cellViewClassForCellData:(MXKCellData*)cellData { - if ([cellData isKindOfClass:[MXKRecentCellData class]]) + if ([cellData isKindOfClass:[RecentCellData class]]) { return [RoomTableViewCell class]; } @@ -149,4 +169,29 @@ return nil; } +#pragma mark - UISearchBarDelegate + +- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText +{ + if (searchText.length) + { + [self.dataSource searchWithPatterns:@[searchText]]; + } + else + { + [self.dataSource searchWithPatterns:nil]; + } +} + +- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar +{ + [searchBar resignFirstResponder]; +} + +- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar +{ + [searchBar resignFirstResponder]; + [self.dataSource searchWithPatterns:nil]; +} + @end diff --git a/RiotShareExtension/ViewController/SharePresentingViewController.m b/RiotShareExtension/ViewController/SharePresentingViewController.m index 3125425d7..081c328b7 100644 --- a/RiotShareExtension/ViewController/SharePresentingViewController.m +++ b/RiotShareExtension/ViewController/SharePresentingViewController.m @@ -30,6 +30,11 @@ [ShareExtensionManager sharedManager].shareExtensionContext = self.extensionContext; + [self presentShareViewController]; +} + +- (void)presentShareViewController +{ ShareViewController *shareViewController = [[ShareViewController alloc] init]; shareViewController.providesPresentationContextTransitionStyle = YES; diff --git a/RiotShareExtension/ViewController/ShareViewController.m b/RiotShareExtension/ViewController/ShareViewController.m index 8e3439bea..b4fd9fe3d 100644 --- a/RiotShareExtension/ViewController/ShareViewController.m +++ b/RiotShareExtension/ViewController/ShareViewController.m @@ -107,7 +107,9 @@ NSArray *titles = @[NSLocalizedStringFromTable(@"title_rooms", @"Vector", nil) , NSLocalizedStringFromTable(@"title_people", @"Vector", nil)]; void (^failureBlock)() = ^void() { - [[ShareExtensionManager sharedManager] cancelSharingWithFailure]; + [self dismissViewControllerAnimated:YES completion:^{ + [[ShareExtensionManager sharedManager] cancelSharingWithFailure]; + }]; }; ShareRecentsDataSource *roomsDataSource = [[ShareRecentsDataSource alloc] initWithMatrixSession:self.mainSession dataSourceMode:RecentsDataSourceModeRooms]; @@ -164,7 +166,9 @@ - (IBAction)close:(UIButton *)sender { - [[ShareExtensionManager sharedManager] cancelSharing]; + [self dismissViewControllerAnimated:YES completion:^{ + [[ShareExtensionManager sharedManager] cancelSharing]; + }]; } From 12dfc437aeefe581a3ecd13bce7808810ec4afff Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Mon, 14 Aug 2017 15:25:02 +0400 Subject: [PATCH 018/102] Share Extension manager improvements --- .../Model/ShareExtensionManager.m | 265 ++++++++++-------- 1 file changed, 153 insertions(+), 112 deletions(-) diff --git a/RiotShareExtension/Model/ShareExtensionManager.m b/RiotShareExtension/Model/ShareExtensionManager.m index e392397eb..cdb7b4dd0 100644 --- a/RiotShareExtension/Model/ShareExtensionManager.m +++ b/RiotShareExtension/Model/ShareExtensionManager.m @@ -24,148 +24,58 @@ return sharedInstance; } +#pragma mark - Public + - (void)sendContentToRoom:(MXRoom *)room failureBlock:(void(^)())failureBlock { NSString *UTTypeText = (__bridge NSString *)kUTTypeText; NSString *UTTypeURL = (__bridge NSString *)kUTTypeURL; NSString *UTTypeImage = (__bridge NSString *)kUTTypeImage; NSString *UTTypeVideo = (__bridge NSString *)kUTTypeVideo; + NSString *UTTypeFileUrl = (__bridge NSString *)kUTTypeFileURL; + NSString *UTTypeMovie = (__bridge NSString *)kUTTypeMovie; for (NSExtensionItem *item in self.shareExtensionContext.inputItems) { for (NSItemProvider *itemProvider in item.attachments) { - if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeText]) + if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeFileUrl]) + { + [itemProvider loadItemForTypeIdentifier:UTTypeFileUrl options:nil completionHandler:^(NSURL *fileUrl, NSError * _Null_unspecified error) { + [self sendFileWithUrl:fileUrl toRoom:room extensionItem:item failureBlock:failureBlock]; + }]; + } + else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeText]) { [itemProvider loadItemForTypeIdentifier:UTTypeText options:nil completionHandler:^(NSString *text, NSError * _Null_unspecified error) { - if (!text) - { - if (failureBlock) - { - failureBlock(); - } - return; - } - [room sendTextMessage:text success:^(NSString *eventId) { - [self.shareExtensionContext completeRequestReturningItems:@[item] completionHandler:nil]; - } failure:^(NSError *error) { - NSLog(@"[ShareExtensionManager] sendTextMessage failed."); - if (failureBlock) - { - failureBlock(); - } - }]; + [self sendText:text toRoom:room extensionItem:item failureBlock:failureBlock]; }]; } else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeURL]) { [itemProvider loadItemForTypeIdentifier:UTTypeURL options:nil completionHandler:^(NSURL *url, NSError * _Null_unspecified error) { - if (!url) - { - if (failureBlock) - { - failureBlock(); - } - return; - } - [room sendTextMessage:url.absoluteString success:^(NSString *eventId) { - [self.shareExtensionContext completeRequestReturningItems:@[item] completionHandler:nil]; - } failure:^(NSError *error) { - NSLog(@"[ShareExtensionManager] sendTextMessage failed."); - if (failureBlock) - { - failureBlock(); - } - }]; + [self sendText:url.absoluteString toRoom:room extensionItem:item failureBlock:failureBlock]; }]; } else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeImage]) { [itemProvider loadItemForTypeIdentifier:UTTypeImage options:nil completionHandler:^(NSData *imageData, NSError * _Null_unspecified error) { - if (!imageData) - { - if (failureBlock) - { - failureBlock(); - } - return; - } - //Send the image - UIImage *image = [[UIImage alloc] initWithData:imageData]; - - NSString *mimeType; - if ([itemProvider hasItemConformingToTypeIdentifier:(__bridge NSString *)kUTTypePNG]) - { - mimeType = @"image/png"; - } - else if ([itemProvider hasItemConformingToTypeIdentifier:(__bridge NSString *)kUTTypeJPEG]) - { - mimeType = @"image/jpeg"; - } - else - { - image = [[UIImage alloc] initWithData:UIImageJPEGRepresentation(image, 1.0)]; - mimeType = @"image/jpeg"; - } - - UIImage *thumbnail = nil; - // Thumbnail is useful only in case of encrypted room - if (room.state.isEncrypted) - { - thumbnail = [MXKTools reduceImage:image toFitInSize:CGSizeMake(800, 600)]; - if (thumbnail == image) - { - thumbnail = nil; - } - } - [room sendImage:imageData withImageSize:image.size mimeType:mimeType andThumbnail:thumbnail localEcho:nil success:^(NSString *eventId) - { - [self.shareExtensionContext completeRequestReturningItems:@[item] completionHandler:nil]; - } - failure:^(NSError *error) - { - NSLog(@"[ShareExtensionManager] sendImage failed."); - if (failureBlock) - { - failureBlock(); - } - }]; + [self sendImage:imageData withProvider:itemProvider toRoom:room extensionItem:item failureBlock:failureBlock]; }]; } else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeVideo]) { [itemProvider loadItemForTypeIdentifier:UTTypeVideo options:nil completionHandler:^(NSURL *videoLocalUrl, NSError * _Null_unspecified error) { - if (!videoLocalUrl) - { - if (failureBlock) - { - failureBlock(); - } - return; - } - - // Retrieve the video frame at 1 sec to define the video thumbnail - AVURLAsset *urlAsset = [[AVURLAsset alloc] initWithURL:videoLocalUrl options:nil]; - AVAssetImageGenerator *assetImageGenerator = [AVAssetImageGenerator assetImageGeneratorWithAsset:urlAsset]; - assetImageGenerator.appliesPreferredTrackTransform = YES; - CMTime time = CMTimeMake(1, 1); - CGImageRef imageRef = [assetImageGenerator copyCGImageAtTime:time actualTime:NULL error:nil]; - // Finalize video attachment - UIImage *videoThumbnail = [[UIImage alloc] initWithCGImage:imageRef]; - CFRelease(imageRef); - - [room sendVideo:videoLocalUrl withThumbnail:videoThumbnail localEcho:nil success:^(NSString *eventId) { - [self.shareExtensionContext completeRequestReturningItems:@[item] completionHandler:nil]; - } failure:^(NSError *error) { - NSLog(@"[ShareExtensionManager] sendVideo failed."); - if (failureBlock) - { - failureBlock(); - } - }]; - + [self sendVideo:videoLocalUrl toRoom:room extensionItem:item failureBlock:failureBlock]; + }]; + } + else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeMovie]) + { + [itemProvider loadItemForTypeIdentifier:UTTypeMovie options:nil completionHandler:^(NSURL *videoLocalUrl, NSError * _Null_unspecified error) + { + [self sendVideo:videoLocalUrl toRoom:room extensionItem:item failureBlock:failureBlock]; }]; } } @@ -182,5 +92,136 @@ [self.shareExtensionContext cancelRequestWithError:[NSError errorWithDomain:@"MXFailureErrorDomain" code:500 userInfo:nil]]; } +#pragma mark - Sharing + +- (void)sendText:(NSString *)text toRoom:(MXRoom *)room extensionItem:(NSExtensionItem *)extensionItem failureBlock:(void(^)())failureBlock +{ + if (!text) + { + NSLog(@"[ShareExtensionManager] loadItemForTypeIdentifier: failed."); + if (failureBlock) + { + failureBlock(); + } + return; + } + [room sendTextMessage:text success:^(NSString *eventId) { + [self.shareExtensionContext completeRequestReturningItems:@[extensionItem] completionHandler:nil]; + } failure:^(NSError *error) { + NSLog(@"[ShareExtensionManager] sendTextMessage failed."); + if (failureBlock) + { + failureBlock(); + } + }]; +} + +- (void)sendFileWithUrl:(NSURL *)fileUrl toRoom:(MXRoom *)room extensionItem:(NSExtensionItem *)extensionItem failureBlock:(void(^)())failureBlock +{ + if (!fileUrl) + { + NSLog(@"[ShareExtensionManager] loadItemForTypeIdentifier: failed."); + if (failureBlock) + { + failureBlock(); + } + return; + } + NSString *mimeType = [fileUrl pathExtension]; + [room sendFile:fileUrl mimeType:mimeType localEcho:nil success:^(NSString *eventId) { + [self.shareExtensionContext completeRequestReturningItems:@[extensionItem] completionHandler:nil]; + } failure:^(NSError *error) { + NSLog(@"[ShareExtensionManager] sendFile failed."); + if (failureBlock) + { + failureBlock(); + } + }]; +} + +- (void)sendImage:(NSData *)imageData withProvider:(NSItemProvider*)itemProvider toRoom:(MXRoom *)room extensionItem:(NSExtensionItem *)extensionItem failureBlock:(void(^)())failureBlock +{ + if (!imageData) + { + NSLog(@"[ShareExtensionManager] loadItemForTypeIdentifier: failed."); + if (failureBlock) + { + failureBlock(); + } + return; + } + //Send the image + UIImage *image = [[UIImage alloc] initWithData:imageData]; + + NSString *mimeType; + if ([itemProvider hasItemConformingToTypeIdentifier:(__bridge NSString *)kUTTypePNG]) + { + mimeType = @"image/png"; + } + else if ([itemProvider hasItemConformingToTypeIdentifier:(__bridge NSString *)kUTTypeJPEG]) + { + mimeType = @"image/jpeg"; + } + else + { + image = [[UIImage alloc] initWithData:UIImageJPEGRepresentation(image, 1.0)]; + mimeType = @"image/jpeg"; + } + + UIImage *thumbnail = nil; + // Thumbnail is useful only in case of encrypted room + if (room.state.isEncrypted) + { + thumbnail = [MXKTools reduceImage:image toFitInSize:CGSizeMake(800, 600)]; + if (thumbnail == image) + { + thumbnail = nil; + } + } + + [room sendImage:imageData withImageSize:image.size mimeType:mimeType andThumbnail:thumbnail localEcho:nil success:^(NSString *eventId) { + [self.shareExtensionContext completeRequestReturningItems:@[extensionItem] completionHandler:nil]; + } failure:^(NSError *error) { + NSLog(@"[ShareExtensionManager] sendImage failed."); + if (failureBlock) + { + failureBlock(); + } + }]; +} + +- (void)sendVideo:(NSURL *)videoLocalUrl toRoom:(MXRoom *)room extensionItem:(NSExtensionItem *)extensionItem failureBlock:(void(^)())failureBlock +{ + if (!videoLocalUrl) + { + NSLog(@"[ShareExtensionManager] loadItemForTypeIdentifier: failed."); + if (failureBlock) + { + failureBlock(); + } + return; + } + + // Retrieve the video frame at 1 sec to define the video thumbnail + AVURLAsset *urlAsset = [[AVURLAsset alloc] initWithURL:videoLocalUrl options:nil]; + AVAssetImageGenerator *assetImageGenerator = [AVAssetImageGenerator assetImageGeneratorWithAsset:urlAsset]; + assetImageGenerator.appliesPreferredTrackTransform = YES; + CMTime time = CMTimeMake(1, 1); + CGImageRef imageRef = [assetImageGenerator copyCGImageAtTime:time actualTime:NULL error:nil]; + // Finalize video attachment + UIImage *videoThumbnail = [[UIImage alloc] initWithCGImage:imageRef]; + CFRelease(imageRef); + + [room sendVideo:videoLocalUrl withThumbnail:videoThumbnail localEcho:nil success:^(NSString *eventId) { + [self.shareExtensionContext completeRequestReturningItems:@[extensionItem] completionHandler:nil]; + } failure:^(NSError *error) { + NSLog(@"[ShareExtensionManager] sendVideo failed."); + if (failureBlock) + { + failureBlock(); + } + }]; +} + @end From 58508430b08d1392a7fb3a284c79fff98d36dea9 Mon Sep 17 00:00:00 2001 From: Giom Foret Date: Wed, 16 Aug 2017 10:42:29 +0200 Subject: [PATCH 019/102] Update MatrixKit version in RiotShareExtension target --- Podfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Podfile b/Podfile index dca685cba..5dcb91d2a 100644 --- a/Podfile +++ b/Podfile @@ -53,7 +53,7 @@ pod 'OLMKit' pod 'Realm', '~> 2.8.1' # The tagged version on which this version of Riot has been built -pod 'MatrixKit', '0.5.2' +pod 'MatrixKit', '0.6.0' # The lastest release available on the CocoaPods repository #pod 'MatrixKit/AppExtension' From f8e48d7d683d64cd4ba95295efcdf6b270994735 Mon Sep 17 00:00:00 2001 From: Giom Foret Date: Wed, 16 Aug 2017 18:24:07 +0200 Subject: [PATCH 020/102] Apply the actual application group: "group.im.vector" --- Riot/AppDelegate.m | 5 +++-- Riot/Riot.entitlements | 2 +- RiotShareExtension/RiotShareExtension.entitlements | 2 +- RiotShareExtension/ShareViewController.m | 3 +++ 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Riot/AppDelegate.m b/Riot/AppDelegate.m index b29c573b3..7d823b5c7 100644 --- a/Riot/AppDelegate.m +++ b/Riot/AppDelegate.m @@ -1607,8 +1607,9 @@ NSString *const kAppDelegateNetworkStatusDidChangeNotification = @"kAppDelegateN }]; - // Observe settings changes - [[MXKAppSettings standardAppSettings] addObserver:self forKeyPath:@"showAllEventsInRoomHistory" options:0 context:nil]; + // Apply the application group name, and add observer on settings changes. + [MXKAppSettings standardAppSettings].applicationGroup = @"group.im.vector"; + [[MXKAppSettings standardAppSettings] addObserver:self forKeyPath:@"showAllEventsInRoomHistory" options:0 context:nil]; // Prepare account manager MXKAccountManager *accountManager = [MXKAccountManager sharedManager]; diff --git a/Riot/Riot.entitlements b/Riot/Riot.entitlements index fe7295f52..bb2281e16 100644 --- a/Riot/Riot.entitlements +++ b/Riot/Riot.entitlements @@ -13,7 +13,7 @@ com.apple.security.application-groups - group.org.matrix + group.im.vector diff --git a/RiotShareExtension/RiotShareExtension.entitlements b/RiotShareExtension/RiotShareExtension.entitlements index 95ba9ff62..e540aaaec 100644 --- a/RiotShareExtension/RiotShareExtension.entitlements +++ b/RiotShareExtension/RiotShareExtension.entitlements @@ -4,7 +4,7 @@ com.apple.security.application-groups - group.org.matrix + group.im.vector diff --git a/RiotShareExtension/ShareViewController.m b/RiotShareExtension/ShareViewController.m index 8c18b34f9..cb5c573ed 100644 --- a/RiotShareExtension/ShareViewController.m +++ b/RiotShareExtension/ShareViewController.m @@ -59,6 +59,9 @@ - (void)prepareSession { + // Apply the application group + [MXKAppSettings standardAppSettings].applicationGroup = @"group.im.vector"; + // Prepare account manager MXKAccountManager *accountManager = [MXKAccountManager sharedManager]; From bbe5a7f82b94105f76d07b6e12b7fd2738e7b042 Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Thu, 17 Aug 2017 00:01:54 +0400 Subject: [PATCH 021/102] Loading HUD usage in the extension, Image resoulution alertController introduced --- Riot/Assets/en.lproj/Vector.strings | 1 + RiotShareExtension/Info.plist | 2 +- .../Model/ShareExtensionManager.h | 22 +- .../Model/ShareExtensionManager.m | 198 +++++++++++++++++- .../ViewController/RoomsListViewController.m | 78 ++++--- 5 files changed, 270 insertions(+), 31 deletions(-) diff --git a/Riot/Assets/en.lproj/Vector.strings b/Riot/Assets/en.lproj/Vector.strings index 7b900ed35..1b5775bc8 100644 --- a/Riot/Assets/en.lproj/Vector.strings +++ b/Riot/Assets/en.lproj/Vector.strings @@ -50,6 +50,7 @@ "rename" = "Rename"; "collapse" = "collapse"; "send_to" = "Send to %@"; +"sending" = "Sending"; // Authentication "auth_login" = "Log in"; diff --git a/RiotShareExtension/Info.plist b/RiotShareExtension/Info.plist index 9bec3398f..251562e64 100644 --- a/RiotShareExtension/Info.plist +++ b/RiotShareExtension/Info.plist @@ -31,7 +31,7 @@ NSExtensionActivationSupportsMovieWithMaxCount 1 NSExtensionActivationSupportsImageWithMaxCount - 3 + 1 NSExtensionActivationSupportsWebURLWithMaxCount 1 NSExtensionActivationSupportsText diff --git a/RiotShareExtension/Model/ShareExtensionManager.h b/RiotShareExtension/Model/ShareExtensionManager.h index 230e55238..3af693a91 100644 --- a/RiotShareExtension/Model/ShareExtensionManager.h +++ b/RiotShareExtension/Model/ShareExtensionManager.h @@ -9,16 +9,36 @@ #import #import +@class ShareExtensionManager; + +@protocol ShareExtensionManagerDelegate + +@required + +- (void)shareExtensionManager:(ShareExtensionManager *)extensionManager showImageCompressionPrompt:(UIAlertController *)compressionPrompt; + +@optional + +- (void)shareExtensionManager:(ShareExtensionManager *)extensionManager mediaUploadProgress:(CGFloat)progress; + +@end + @interface ShareExtensionManager : NSObject -@property NSExtensionContext *shareExtensionContext; +@property (nonatomic) NSExtensionContext *shareExtensionContext; + +@property (nonatomic) id delegate; + (instancetype)sharedManager; - (void)sendContentToRoom:(MXRoom *)room failureBlock:(void(^)())failureBlock; +- (BOOL)hasImageTypeContent; + - (void)cancelSharing; - (void)cancelSharingWithFailure; +- (UIAlertController *)compressionPromptForImage:(UIImage *)image shareBlock:(nonnull void(^)())shareBlock; + @end diff --git a/RiotShareExtension/Model/ShareExtensionManager.m b/RiotShareExtension/Model/ShareExtensionManager.m index cdb7b4dd0..95c60e640 100644 --- a/RiotShareExtension/Model/ShareExtensionManager.m +++ b/RiotShareExtension/Model/ShareExtensionManager.m @@ -7,8 +7,24 @@ // #import "ShareExtensionManager.h" +#import "MXKPieChartHUD.h" @import MobileCoreServices; +typedef NS_ENUM(NSInteger, ImageCompressionMode) +{ + ImageCompressionModeNone, + ImageCompressionModeSmall, + ImageCompressionModeMedium, + ImageCompressionModeLarge +}; + +@interface ShareExtensionManager () + +@property ImageCompressionMode imageCompressionMode; +@property CGFloat actualLargeSize; + +@end + @implementation ShareExtensionManager @@ -20,6 +36,7 @@ static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ sharedInstance = [[self alloc] init]; + [[NSNotificationCenter defaultCenter] addObserver:sharedInstance selector:@selector(onMediaUploadProgress:) name:kMXMediaUploadProgressNotification object:nil]; }); return sharedInstance; } @@ -35,6 +52,7 @@ NSString *UTTypeFileUrl = (__bridge NSString *)kUTTypeFileURL; NSString *UTTypeMovie = (__bridge NSString *)kUTTypeMovie; + for (NSExtensionItem *item in self.shareExtensionContext.inputItems) { for (NSItemProvider *itemProvider in item.attachments) @@ -61,7 +79,11 @@ { [itemProvider loadItemForTypeIdentifier:UTTypeImage options:nil completionHandler:^(NSData *imageData, NSError * _Null_unspecified error) { - [self sendImage:imageData withProvider:itemProvider toRoom:room extensionItem:item failureBlock:failureBlock]; + UIImage *image = [[UIImage alloc] initWithData:imageData]; + UIAlertController *compressionPrompt = [self compressionPromptForImage:image shareBlock:^{ + [self sendImage:imageData withProvider:itemProvider toRoom:room extensionItem:item failureBlock:failureBlock]; + }]; + [self.delegate shareExtensionManager:self showImageCompressionPrompt:compressionPrompt]; }]; } else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeVideo]) @@ -82,6 +104,21 @@ } } +- (BOOL)hasImageTypeContent +{ + for (NSExtensionItem *item in self.shareExtensionContext.inputItems) + { + for (NSItemProvider *itemProvider in item.attachments) + { + if ([itemProvider hasItemConformingToTypeIdentifier:(__bridge NSString *)kUTTypeImage]) + { + return YES; + } + } + } + return NO; +} + - (void)cancelSharing { [self.shareExtensionContext cancelRequestWithError:[NSError errorWithDomain:@"MXUserCancelErrorDomain" code:4201 userInfo:nil]]; @@ -92,6 +129,152 @@ [self.shareExtensionContext cancelRequestWithError:[NSError errorWithDomain:@"MXFailureErrorDomain" code:500 userInfo:nil]]; } +- (UIAlertController *)compressionPromptForImage:(UIImage *)image shareBlock:(nonnull void(^)())shareBlock +{ + UIAlertController *compressionPrompt; + + // Get availabe sizes for this image + MXKImageCompressionSizes compressionSizes = [MXKTools availableCompressionSizesForImage:image]; + + // Apply the compression mode + if (compressionSizes.small.fileSize || compressionSizes.medium.fileSize || compressionSizes.large.fileSize) + { + __weak typeof(self) weakSelf = self; + + compressionPrompt = [UIAlertController alertControllerWithTitle:[NSBundle mxk_localizedStringForKey:@"attachment_size_prompt"] message:nil preferredStyle:UIAlertControllerStyleActionSheet]; + + if (compressionSizes.small.fileSize) + { + NSString *resolution = [NSString stringWithFormat:@"%@ (%d x %d)", [MXTools fileSizeToString:compressionSizes.small.fileSize round:NO], (int)compressionSizes.small.imageSize.width, (int)compressionSizes.small.imageSize.height]; + + NSString *title = [NSString stringWithFormat:[NSBundle mxk_localizedStringForKey:@"attachment_small"], resolution]; + + [compressionPrompt addAction:[UIAlertAction actionWithTitle:title + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { + + if (weakSelf) + { + typeof(self) self = weakSelf; + + // Send the small image + self.imageCompressionMode = ImageCompressionModeSmall; + if (shareBlock) + { + shareBlock(); + } + + [compressionPrompt dismissViewControllerAnimated:YES completion:nil]; + } + + }]]; + } + + if (compressionSizes.medium.fileSize) + { + NSString *resolution = [NSString stringWithFormat:@"%@ (%d x %d)", [MXTools fileSizeToString:compressionSizes.medium.fileSize round:NO], (int)compressionSizes.medium.imageSize.width, (int)compressionSizes.medium.imageSize.height]; + + NSString *title = [NSString stringWithFormat:[NSBundle mxk_localizedStringForKey:@"attachment_medium"], resolution]; + + [compressionPrompt addAction:[UIAlertAction actionWithTitle:title + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { + + if (weakSelf) + { + typeof(self) self = weakSelf; + + // Send the medium image + self.imageCompressionMode = ImageCompressionModeMedium; + if (shareBlock) + { + shareBlock(); + } + + [compressionPrompt dismissViewControllerAnimated:YES completion:nil]; + } + + }]]; + } + + if (compressionSizes.large.fileSize) + { + NSString *resolution = [NSString stringWithFormat:@"%@ (%d x %d)", [MXTools fileSizeToString:compressionSizes.large.fileSize round:NO], (int)compressionSizes.large.imageSize.width, (int)compressionSizes.large.imageSize.height]; + + NSString *title = [NSString stringWithFormat:[NSBundle mxk_localizedStringForKey:@"attachment_large"], resolution]; + + [compressionPrompt addAction:[UIAlertAction actionWithTitle:title + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { + + if (weakSelf) + { + typeof(self) self = weakSelf; + + // Send the large image + self.imageCompressionMode = ImageCompressionModeLarge; + self.actualLargeSize = compressionSizes.actualLargeSize; + if (shareBlock) + { + shareBlock(); + } + + [compressionPrompt dismissViewControllerAnimated:YES completion:nil]; + } + + }]]; + } + + NSString *resolution = [NSString stringWithFormat:@"%@ (%d x %d)", [MXTools fileSizeToString:compressionSizes.original.fileSize round:NO], (int)compressionSizes.original.imageSize.width, (int)compressionSizes.original.imageSize.height]; + + NSString *title = [NSString stringWithFormat:[NSBundle mxk_localizedStringForKey:@"attachment_original"], resolution]; + + [compressionPrompt addAction:[UIAlertAction actionWithTitle:title + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { + + if (weakSelf) + { + typeof(self) self = weakSelf; + + self.imageCompressionMode = ImageCompressionModeNone; + if (shareBlock) + { + shareBlock(); + } + + [compressionPrompt dismissViewControllerAnimated:YES completion:nil]; + } + + }]]; + + [compressionPrompt addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"] + style:UIAlertActionStyleDefault + handler:^(UIAlertAction * action) { + + if (weakSelf) + { + [compressionPrompt dismissViewControllerAnimated:YES completion:nil]; + } + + }]]; + + + } + + return compressionPrompt; +} + +#pragma mark - Notifications + +- (void)onMediaUploadProgress:(NSNotification *)notification +{ + if ([self.delegate respondsToSelector:@selector(shareExtensionManager:mediaUploadProgress:)]) + { + [self.delegate shareExtensionManager:self mediaUploadProgress:((NSNumber *)notification.userInfo[kMXMediaLoaderProgressValueKey]).floatValue]; + } +} + #pragma mark - Sharing - (void)sendText:(NSString *)text toRoom:(MXRoom *)room extensionItem:(NSExtensionItem *)extensionItem failureBlock:(void(^)())failureBlock @@ -153,6 +336,19 @@ //Send the image UIImage *image = [[UIImage alloc] initWithData:imageData]; + if (self.imageCompressionMode == ImageCompressionModeSmall) + { + image = [MXKTools reduceImage:image toFitInSize:CGSizeMake(MXKTOOLS_SMALL_IMAGE_SIZE, MXKTOOLS_SMALL_IMAGE_SIZE)]; + } + else if (self.imageCompressionMode == ImageCompressionModeMedium) + { + image = [MXKTools reduceImage:image toFitInSize:CGSizeMake(MXKTOOLS_MEDIUM_IMAGE_SIZE, MXKTOOLS_MEDIUM_IMAGE_SIZE)]; + } + else if (self.imageCompressionMode == ImageCompressionModeLarge) + { + image = [MXKTools reduceImage:image toFitInSize:CGSizeMake(self.actualLargeSize, self.actualLargeSize)]; + } + NSString *mimeType; if ([itemProvider hasItemConformingToTypeIdentifier:(__bridge NSString *)kUTTypePNG]) { diff --git a/RiotShareExtension/ViewController/RoomsListViewController.m b/RiotShareExtension/ViewController/RoomsListViewController.m index 512c597b7..e2ee6cb13 100644 --- a/RiotShareExtension/ViewController/RoomsListViewController.m +++ b/RiotShareExtension/ViewController/RoomsListViewController.m @@ -20,15 +20,19 @@ #import "ShareExtensionManager.h" #import "RecentCellData.h" #import "RiotDesignValues.h" +#import "MXKPieChartView.h" +#import "MXKPieChartHUD.h" -@interface RoomsListViewController () + +@interface RoomsListViewController () @property (nonatomic) ShareRecentsDataSource *dataSource; @property (copy) void (^failureBlock)(); @property (nonatomic) UITableView *mainTableView; @property (nonatomic) UISearchBar *searchBar; +@property (nonatomic) MXKPieChartHUD *hudView; @end @@ -67,17 +71,11 @@ self.mainTableView.translatesAutoresizingMaskIntoConstraints = NO; self.view.translatesAutoresizingMaskIntoConstraints = NO; NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:self.mainTableView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeWidth multiplier:1 constant:0]; - widthConstraint.active = YES; NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:self.mainTableView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeHeight multiplier:1 constant:0]; - heightConstraint.active = YES; NSLayoutConstraint *centerXConstraint = [NSLayoutConstraint constraintWithItem:self.mainTableView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]; - centerXConstraint.active = YES; NSLayoutConstraint *centerYConstraint = [NSLayoutConstraint constraintWithItem:self.mainTableView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]; - centerYConstraint.active = YES; - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ - [self.dataSource searchWithPatterns:nil]; - }); + [NSLayoutConstraint activateConstraints:@[widthConstraint, heightConstraint, centerXConstraint, centerYConstraint]]; } - (void)configureSearchBar @@ -95,6 +93,35 @@ #pragma mark - Private +- (void)showShareAlertForRoomPath:(NSIndexPath *)indexPath +{ + NSString *receipantName = [self.dataSource getRoomAtIndexPath:indexPath].riotDisplayname; + if (!receipantName.length) + { + receipantName = NSLocalizedStringFromTable(@"room_displayname_no_title", @"Vector", nil); + } + + UIAlertController *alertController = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:NSLocalizedStringFromTable(@"send_to", @"Vector", nil), receipantName] message:nil preferredStyle:UIAlertControllerStyleAlert]; + + UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"] style:UIAlertActionStyleCancel handler:nil]; + [alertController addAction:cancelAction]; + + UIAlertAction *sendAction = [UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"send"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { + MXRoom *selectedRoom = [self.dataSource getRoomAtIndexPath:indexPath]; + + self.hudView = [MXKPieChartHUD showLoadingHudOnView:self.view WithMessage:NSLocalizedStringFromTable(@"sending", @"Vector", nil)]; + [ShareExtensionManager sharedManager].delegate = self; + self.parentViewController.view.userInteractionEnabled = NO; + + [[ShareExtensionManager sharedManager] sendContentToRoom:selectedRoom failureBlock:^{ + [self showFailureAlert]; + }]; + }]; + [alertController addAction:sendAction]; + + [self presentViewController:alertController animated:YES completion:nil]; +} + - (void)showFailureAlert { UIAlertController *alertController = [UIAlertController alertControllerWithTitle:NSLocalizedStringFromTable(@"room_event_failed_to_send", @"Vector", nil) message:nil preferredStyle:UIAlertControllerStyleAlert]; @@ -119,26 +146,7 @@ { [tableView deselectRowAtIndexPath:indexPath animated:YES]; - NSString *receipantName = [self.dataSource getRoomAtIndexPath:indexPath].riotDisplayname; - if (!receipantName.length) - { - receipantName = NSLocalizedStringFromTable(@"room_displayname_no_title", @"Vector", nil); - } - - UIAlertController *alertController = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:NSLocalizedStringFromTable(@"send_to", @"Vector", nil), receipantName] message:nil preferredStyle:UIAlertControllerStyleAlert]; - - UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"cancel"] style:UIAlertActionStyleCancel handler:nil]; - [alertController addAction:cancelAction]; - - UIAlertAction *sendAction = [UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"send"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { - MXRoom *selectedRoom = [self.dataSource getRoomAtIndexPath:indexPath]; - [[ShareExtensionManager sharedManager] sendContentToRoom:selectedRoom failureBlock:^{ - [self showFailureAlert]; - }]; - }]; - [alertController addAction:sendAction]; - - [self presentViewController:alertController animated:YES completion:nil]; + [self showShareAlertForRoomPath:indexPath]; } #pragma mark - MXKDataSourceDelegate @@ -194,4 +202,18 @@ [self.dataSource searchWithPatterns:nil]; } +#pragma mark - ShareExtensionManagerDelegate + +- (void)shareExtensionManager:(ShareExtensionManager *)extensionManager showImageCompressionPrompt:(UIAlertController *)compressionPrompt +{ + [compressionPrompt popoverPresentationController].sourceView = self.view; + [compressionPrompt popoverPresentationController].sourceRect = self.view.frame; + [self presentViewController:compressionPrompt animated:YES completion:nil]; +} + +- (void)shareExtensionManager:(ShareExtensionManager *)extensionManager mediaUploadProgress:(CGFloat)progress +{ + [self.hudView setProgress:progress]; +} + @end From e34e0544a35017b5a480766cbe9fa4829aa28351 Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Thu, 17 Aug 2017 19:28:08 +0400 Subject: [PATCH 022/102] Fixed retain cycles, changed color constant --- .../Model/ShareExtensionManager.h | 22 ++-- .../Model/ShareExtensionManager.m | 101 ++++++++++++++---- .../Model/ShareRecentsDataSource.h | 22 ++-- .../Model/ShareRecentsDataSource.m | 22 ++-- .../ViewController/FallbackViewController.m | 2 +- 5 files changed, 126 insertions(+), 43 deletions(-) diff --git a/RiotShareExtension/Model/ShareExtensionManager.h b/RiotShareExtension/Model/ShareExtensionManager.h index 3af693a91..f9145c9a2 100644 --- a/RiotShareExtension/Model/ShareExtensionManager.h +++ b/RiotShareExtension/Model/ShareExtensionManager.h @@ -1,10 +1,18 @@ -// -// ShareExtensionManager.h -// Riot -// -// Created by Aram Sargsyan on 8/10/17. -// Copyright © 2017 matrix.org. All rights reserved. -// +/* + Copyright 2017 Aram Sargsyan + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ #import #import diff --git a/RiotShareExtension/Model/ShareExtensionManager.m b/RiotShareExtension/Model/ShareExtensionManager.m index 95c60e640..566d3859e 100644 --- a/RiotShareExtension/Model/ShareExtensionManager.m +++ b/RiotShareExtension/Model/ShareExtensionManager.m @@ -1,10 +1,18 @@ -// -// ShareExtensionManager.m -// Riot -// -// Created by Aram Sargsyan on 8/10/17. -// Copyright © 2017 matrix.org. All rights reserved. -// +/* + Copyright 2017 Aram Sargsyan + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ #import "ShareExtensionManager.h" #import "MXKPieChartHUD.h" @@ -52,6 +60,7 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode) NSString *UTTypeFileUrl = (__bridge NSString *)kUTTypeFileURL; NSString *UTTypeMovie = (__bridge NSString *)kUTTypeMovie; + __weak typeof(self) weakSelf = self; for (NSExtensionItem *item in self.shareExtensionContext.inputItems) { @@ -60,44 +69,68 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode) if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeFileUrl]) { [itemProvider loadItemForTypeIdentifier:UTTypeFileUrl options:nil completionHandler:^(NSURL *fileUrl, NSError * _Null_unspecified error) { - [self sendFileWithUrl:fileUrl toRoom:room extensionItem:item failureBlock:failureBlock]; + if (weakSelf) + { + typeof(self) self = weakSelf; + [self sendFileWithUrl:fileUrl toRoom:room extensionItem:item failureBlock:failureBlock]; + } }]; } else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeText]) { [itemProvider loadItemForTypeIdentifier:UTTypeText options:nil completionHandler:^(NSString *text, NSError * _Null_unspecified error) { - [self sendText:text toRoom:room extensionItem:item failureBlock:failureBlock]; + if (weakSelf) + { + typeof(self) self = weakSelf; + [self sendText:text toRoom:room extensionItem:item failureBlock:failureBlock]; + } }]; } else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeURL]) { [itemProvider loadItemForTypeIdentifier:UTTypeURL options:nil completionHandler:^(NSURL *url, NSError * _Null_unspecified error) { - [self sendText:url.absoluteString toRoom:room extensionItem:item failureBlock:failureBlock]; + if (weakSelf) + { + typeof(self) self = weakSelf; + [self sendText:url.absoluteString toRoom:room extensionItem:item failureBlock:failureBlock]; + } }]; } else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeImage]) { [itemProvider loadItemForTypeIdentifier:UTTypeImage options:nil completionHandler:^(NSData *imageData, NSError * _Null_unspecified error) { - UIImage *image = [[UIImage alloc] initWithData:imageData]; - UIAlertController *compressionPrompt = [self compressionPromptForImage:image shareBlock:^{ - [self sendImage:imageData withProvider:itemProvider toRoom:room extensionItem:item failureBlock:failureBlock]; - }]; - [self.delegate shareExtensionManager:self showImageCompressionPrompt:compressionPrompt]; + if (weakSelf) + { + typeof(self) self = weakSelf; + UIImage *image = [[UIImage alloc] initWithData:imageData]; + UIAlertController *compressionPrompt = [self compressionPromptForImage:image shareBlock:^{ + [self sendImage:imageData withProvider:itemProvider toRoom:room extensionItem:item failureBlock:failureBlock]; + }]; + [self.delegate shareExtensionManager:self showImageCompressionPrompt:compressionPrompt]; + } }]; } else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeVideo]) { [itemProvider loadItemForTypeIdentifier:UTTypeVideo options:nil completionHandler:^(NSURL *videoLocalUrl, NSError * _Null_unspecified error) { - [self sendVideo:videoLocalUrl toRoom:room extensionItem:item failureBlock:failureBlock]; + if (weakSelf) + { + typeof(self) self = weakSelf; + [self sendVideo:videoLocalUrl toRoom:room extensionItem:item failureBlock:failureBlock]; + } }]; } else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeMovie]) { [itemProvider loadItemForTypeIdentifier:UTTypeMovie options:nil completionHandler:^(NSURL *videoLocalUrl, NSError * _Null_unspecified error) { - [self sendVideo:videoLocalUrl toRoom:room extensionItem:item failureBlock:failureBlock]; + if (weakSelf) + { + typeof(self) self = weakSelf; + [self sendVideo:videoLocalUrl toRoom:room extensionItem:item failureBlock:failureBlock]; + } }]; } } @@ -288,8 +321,15 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode) } return; } + + __weak typeof(self) weakSelf = self; + [room sendTextMessage:text success:^(NSString *eventId) { - [self.shareExtensionContext completeRequestReturningItems:@[extensionItem] completionHandler:nil]; + if (weakSelf) + { + typeof(self) self = weakSelf; + [self.shareExtensionContext completeRequestReturningItems:@[extensionItem] completionHandler:nil]; + } } failure:^(NSError *error) { NSLog(@"[ShareExtensionManager] sendTextMessage failed."); if (failureBlock) @@ -311,8 +351,15 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode) return; } NSString *mimeType = [fileUrl pathExtension]; + + __weak typeof(self) weakSelf = self; + [room sendFile:fileUrl mimeType:mimeType localEcho:nil success:^(NSString *eventId) { - [self.shareExtensionContext completeRequestReturningItems:@[extensionItem] completionHandler:nil]; + if (weakSelf) + { + typeof(self) self = weakSelf; + [self.shareExtensionContext completeRequestReturningItems:@[extensionItem] completionHandler:nil]; + } } failure:^(NSError *error) { NSLog(@"[ShareExtensionManager] sendFile failed."); if (failureBlock) @@ -375,8 +422,14 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode) } } + __weak typeof(self) weakSelf = self; + [room sendImage:imageData withImageSize:image.size mimeType:mimeType andThumbnail:thumbnail localEcho:nil success:^(NSString *eventId) { - [self.shareExtensionContext completeRequestReturningItems:@[extensionItem] completionHandler:nil]; + if (weakSelf) + { + typeof(self) self = weakSelf; + [self.shareExtensionContext completeRequestReturningItems:@[extensionItem] completionHandler:nil]; + } } failure:^(NSError *error) { NSLog(@"[ShareExtensionManager] sendImage failed."); if (failureBlock) @@ -408,8 +461,14 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode) UIImage *videoThumbnail = [[UIImage alloc] initWithCGImage:imageRef]; CFRelease(imageRef); + __weak typeof(self) weakSelf = self; + [room sendVideo:videoLocalUrl withThumbnail:videoThumbnail localEcho:nil success:^(NSString *eventId) { - [self.shareExtensionContext completeRequestReturningItems:@[extensionItem] completionHandler:nil]; + if (weakSelf) + { + typeof(self) self = weakSelf; + [self.shareExtensionContext completeRequestReturningItems:@[extensionItem] completionHandler:nil]; + } } failure:^(NSError *error) { NSLog(@"[ShareExtensionManager] sendVideo failed."); if (failureBlock) diff --git a/RiotShareExtension/Model/ShareRecentsDataSource.h b/RiotShareExtension/Model/ShareRecentsDataSource.h index 5e878f4c5..e25d3d26d 100644 --- a/RiotShareExtension/Model/ShareRecentsDataSource.h +++ b/RiotShareExtension/Model/ShareRecentsDataSource.h @@ -1,10 +1,18 @@ -// -// ShareRecentsDataSource.h -// Riot -// -// Created by Aram Sargsyan on 8/10/17. -// Copyright © 2017 matrix.org. All rights reserved. -// +/* + Copyright 2017 Aram Sargsyan + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ #import diff --git a/RiotShareExtension/Model/ShareRecentsDataSource.m b/RiotShareExtension/Model/ShareRecentsDataSource.m index 609332cd0..727fb929f 100644 --- a/RiotShareExtension/Model/ShareRecentsDataSource.m +++ b/RiotShareExtension/Model/ShareRecentsDataSource.m @@ -1,10 +1,18 @@ -// -// ShareRecentsDataSource.m -// Riot -// -// Created by Aram Sargsyan on 8/10/17. -// Copyright © 2017 matrix.org. All rights reserved. -// +/* + Copyright 2017 Aram Sargsyan + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ #import "ShareRecentsDataSource.h" #import "RoomTableViewCell.h" diff --git a/RiotShareExtension/ViewController/FallbackViewController.m b/RiotShareExtension/ViewController/FallbackViewController.m index 80edc4207..479e97f5e 100644 --- a/RiotShareExtension/ViewController/FallbackViewController.m +++ b/RiotShareExtension/ViewController/FallbackViewController.m @@ -29,7 +29,7 @@ { [super viewDidLoad]; - self.titleLabel.textColor = kRiotTextColorGray; + self.titleLabel.textColor = kRiotSecondaryTextColor; self.titleLabel.text = NSLocalizedStringFromTable(@"auth_share_extension_prompt", @"Vector", nil); } From e1162f2affb83796d59c4773c182c4974a02955e Mon Sep 17 00:00:00 2001 From: Giom Foret Date: Thu, 17 Aug 2017 18:06:46 +0200 Subject: [PATCH 023/102] Remove unwanted binary file --- RiotShareExtension/ViewController/.DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 RiotShareExtension/ViewController/.DS_Store diff --git a/RiotShareExtension/ViewController/.DS_Store b/RiotShareExtension/ViewController/.DS_Store deleted file mode 100644 index 2535820cd938362acc8c8e59f36bdbbdecad7565..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHK!Ab)$5PhRP6utB!tzO)tC&9CqrB*@kAQn99)?$mT3$3EZz4#CQg5T!{=$jYOZ0Gqa}4Kt zTZJ)T4E#0*bnUiq#C1F3ue^Tyc)$U2+~N)sqPF*0+Qr~_l=rexp3zq~j(zIRn-i9* z#~VlSUZQwg7036;-6xxkDa|P6CeApg9Aivz!v0gvQg^MTXDv_Pju_2bUZaTH=wiUk zOgO4jXQwP_K8Cc{)yC_x^jyl)_o7E*hvuvteWNt?YP@Quz7{DOlgm&!Qgi7sE&2y( zcFNKC_{W83wn}~7qgi9X7%&Dt7|{J8p(>^U3y*H=pmA3KVvW^KSk_Mh^+^Jz0Sk|8 zp@?@SdRGZo4Ds%)PeQ*mVByibL&D`l!kZ=BP{h5R@e|h_l6o|23>X8m46ORchMxb2 zpWpvyo$SdNFb4h=15)dBJ8e!WoUL<{)3Y|AUQkuEU*XZY(1hdI74#@>QJt_Y(E>3I TSa@U Za4Q7miA7$Vj@H5rp From ca2b519f40c55af91d93fbfe7665aa0e63441c04 Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Fri, 18 Aug 2017 02:27:56 +0400 Subject: [PATCH 024/102] Added comments describing ShareExtensionManager public functionality + small method renaming --- .../Model/ShareExtensionManager.h | 47 +++++++++++++++++-- .../Model/ShareExtensionManager.m | 16 ++++--- .../ViewController/ShareViewController.m | 4 +- 3 files changed, 53 insertions(+), 14 deletions(-) diff --git a/RiotShareExtension/Model/ShareExtensionManager.h b/RiotShareExtension/Model/ShareExtensionManager.h index f9145c9a2..854738ddf 100644 --- a/RiotShareExtension/Model/ShareExtensionManager.h +++ b/RiotShareExtension/Model/ShareExtensionManager.h @@ -19,34 +19,71 @@ @class ShareExtensionManager; +/** + The protocol for the manager's delegate + */ @protocol ShareExtensionManagerDelegate @required +/** + Called when an image is going to be shared to show a compression prompt + @param extensionManager the ShareExtensionManager object that called the method + @param compressionPrompt the prompt that was prepared for the image which is going to be shared + */ - (void)shareExtensionManager:(ShareExtensionManager *)extensionManager showImageCompressionPrompt:(UIAlertController *)compressionPrompt; @optional +/** + Called when the progress of the uploading media changes + @param extensionManager the ShareExtensionManager object that called the method + @param progress the current progress + */ - (void)shareExtensionManager:(ShareExtensionManager *)extensionManager mediaUploadProgress:(CGFloat)progress; @end + +/** + A class used to share content from the extension + */ + @interface ShareExtensionManager : NSObject +/** + The share extension context that represents a user's sharing request, also stores the content to be shared + */ @property (nonatomic) NSExtensionContext *shareExtensionContext; +/** + A delegate used to notify about needed UI changes when sharing + */ @property (nonatomic) id delegate; +/** + The singleton instance + */ + (instancetype)sharedManager; +/** + Send the content that the user has chosen to a room + @param room the room to send the content to + @param failureBlock the code to be executed when sharing has failed for whatever reason + note: there is no "successBlock" parameter because when the sharing succeds, the extension needs to close itself + */ - (void)sendContentToRoom:(MXRoom *)room failureBlock:(void(^)())failureBlock; +/** + Checks if there is an image in the user chosen content + @return YES if there is, NO otherwise + */ - (BOOL)hasImageTypeContent; -- (void)cancelSharing; - -- (void)cancelSharingWithFailure; - -- (UIAlertController *)compressionPromptForImage:(UIImage *)image shareBlock:(nonnull void(^)())shareBlock; +/** + Terminate the extension and return to the app that started it + @param canceled YES if the user chose to cancel the sharing, NO otherwise + */ +- (void)terminateExtensionCanceled:(BOOL)canceled; @end diff --git a/RiotShareExtension/Model/ShareExtensionManager.m b/RiotShareExtension/Model/ShareExtensionManager.m index 566d3859e..47c1bff4a 100644 --- a/RiotShareExtension/Model/ShareExtensionManager.m +++ b/RiotShareExtension/Model/ShareExtensionManager.m @@ -152,14 +152,16 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode) return NO; } -- (void)cancelSharing +- (void)terminateExtensionCanceled:(BOOL)canceled { - [self.shareExtensionContext cancelRequestWithError:[NSError errorWithDomain:@"MXUserCancelErrorDomain" code:4201 userInfo:nil]]; -} - -- (void)cancelSharingWithFailure -{ - [self.shareExtensionContext cancelRequestWithError:[NSError errorWithDomain:@"MXFailureErrorDomain" code:500 userInfo:nil]]; + if (canceled) + { + [self.shareExtensionContext cancelRequestWithError:[NSError errorWithDomain:@"MXUserCancelErrorDomain" code:4201 userInfo:nil]]; + } + else + { + [self.shareExtensionContext cancelRequestWithError:[NSError errorWithDomain:@"MXFailureErrorDomain" code:500 userInfo:nil]]; + } } - (UIAlertController *)compressionPromptForImage:(UIImage *)image shareBlock:(nonnull void(^)())shareBlock diff --git a/RiotShareExtension/ViewController/ShareViewController.m b/RiotShareExtension/ViewController/ShareViewController.m index b4fd9fe3d..ce35cddf5 100644 --- a/RiotShareExtension/ViewController/ShareViewController.m +++ b/RiotShareExtension/ViewController/ShareViewController.m @@ -108,7 +108,7 @@ void (^failureBlock)() = ^void() { [self dismissViewControllerAnimated:YES completion:^{ - [[ShareExtensionManager sharedManager] cancelSharingWithFailure]; + [[ShareExtensionManager sharedManager] terminateExtensionCanceled:NO]; }]; }; @@ -167,7 +167,7 @@ - (IBAction)close:(UIButton *)sender { [self dismissViewControllerAnimated:YES completion:^{ - [[ShareExtensionManager sharedManager] cancelSharing]; + [[ShareExtensionManager sharedManager] terminateExtensionCanceled:YES]; }]; } From 272092ff6b66deba0d4321100c4c56e27484e7b4 Mon Sep 17 00:00:00 2001 From: Giom Foret Date: Fri, 18 Aug 2017 09:40:37 +0200 Subject: [PATCH 025/102] Apply the app group name in app extension (merge https://github.com/vector-im/riot-ios/pull/1440) --- RiotShareExtension/ViewController/ShareViewController.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/RiotShareExtension/ViewController/ShareViewController.m b/RiotShareExtension/ViewController/ShareViewController.m index ce35cddf5..b8d694c67 100644 --- a/RiotShareExtension/ViewController/ShareViewController.m +++ b/RiotShareExtension/ViewController/ShareViewController.m @@ -63,6 +63,9 @@ - (void)prepareSession { + // Apply the application group + [MXKAppSettings standardAppSettings].applicationGroup = @"group.im.vector"; + // Prepare account manager MXKAccountManager *accountManager = [MXKAccountManager sharedManager]; From 701135d7fcfa4bb9e56c650eb3f9e3814d45aaa9 Mon Sep 17 00:00:00 2001 From: manuroe Date: Fri, 18 Aug 2017 17:19:13 +0200 Subject: [PATCH 026/102] Language: Enable Russian --- Riot.xcodeproj/project.pbxproj | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Riot.xcodeproj/project.pbxproj b/Riot.xcodeproj/project.pbxproj index 17f963f01..c7079c110 100644 --- a/Riot.xcodeproj/project.pbxproj +++ b/Riot.xcodeproj/project.pbxproj @@ -38,6 +38,8 @@ 327382C21F276AED00356143 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 327382BC1F276AED00356143 /* InfoPlist.strings */; }; 327382C31F276AED00356143 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 327382BE1F276AED00356143 /* Localizable.strings */; }; 327382C41F276AED00356143 /* Vector.strings in Resources */ = {isa = PBXBuildFile; fileRef = 327382C01F276AED00356143 /* Vector.strings */; }; + 32918EA91F473BDB0076CA16 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 32918EA51F473BDB0076CA16 /* Localizable.strings */; }; + 32918EAA1F473BDB0076CA16 /* Vector.strings in Resources */ = {isa = PBXBuildFile; fileRef = 32918EA71F473BDB0076CA16 /* Vector.strings */; }; 32AE61E41F0A971B007255F4 /* RoomMembershipBubbleCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 32AE61E21F0A971B007255F4 /* RoomMembershipBubbleCell.m */; }; 32AE61E51F0A971B007255F4 /* RoomMembershipBubbleCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 32AE61E31F0A971B007255F4 /* RoomMembershipBubbleCell.xib */; }; 32AE61E91F0CE099007255F4 /* RoomMembershipWithPaginationTitleBubbleCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 32AE61E71F0CE099007255F4 /* RoomMembershipWithPaginationTitleBubbleCell.m */; }; @@ -563,6 +565,8 @@ 327382BD1F276AED00356143 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = InfoPlist.strings; sourceTree = ""; }; 327382BF1F276AED00356143 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = Localizable.strings; sourceTree = ""; }; 327382C11F276AED00356143 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = Vector.strings; sourceTree = ""; }; + 32918EA61F473BDB0076CA16 /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = Localizable.strings; sourceTree = ""; }; + 32918EA81F473BDB0076CA16 /* ru */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = ru; path = Vector.strings; sourceTree = ""; }; 32AE61E11F0A971B007255F4 /* RoomMembershipBubbleCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RoomMembershipBubbleCell.h; sourceTree = ""; }; 32AE61E21F0A971B007255F4 /* RoomMembershipBubbleCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RoomMembershipBubbleCell.m; sourceTree = ""; }; 32AE61E31F0A971B007255F4 /* RoomMembershipBubbleCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = RoomMembershipBubbleCell.xib; sourceTree = ""; }; @@ -1253,6 +1257,15 @@ path = en.lproj; sourceTree = ""; }; + 32918EA41F473BDB0076CA16 /* ru.lproj */ = { + isa = PBXGroup; + children = ( + 32918EA51F473BDB0076CA16 /* Localizable.strings */, + 32918EA71F473BDB0076CA16 /* Vector.strings */, + ); + path = ru.lproj; + sourceTree = ""; + }; 32AE61EB1F0D2183007255F4 /* nl.lproj */ = { isa = PBXGroup; children = ( @@ -1331,6 +1344,7 @@ F083BB0E1E7009EC00A9B29C /* Assets */ = { isa = PBXGroup; children = ( + 32918EA41F473BDB0076CA16 /* ru.lproj */, 327382A71F276AD200356143 /* de.lproj */, 327382BB1F276AED00356143 /* en.lproj */, 327382AE1F276AD200356143 /* fr.lproj */, @@ -2242,6 +2256,7 @@ nl, de, fr, + ru, ); mainGroup = F094A9991B78D8F000B1FBBF; productRefGroup = F094A9A31B78D8F000B1FBBF /* Products */; @@ -2284,6 +2299,7 @@ F083BD441E7009ED00A9B29C /* call_speaker_on_icon@3x.png in Resources */, F0614A0F1EDDCCE700F5DC9A /* jump_to_unread@3x.png in Resources */, F083BE511E7009ED00A9B29C /* RoomOutgoingEncryptedTextMsgBubbleCell.xib in Resources */, + 32918EA91F473BDB0076CA16 /* Localizable.strings in Resources */, F083BDAE1E7009ED00A9B29C /* plus_icon@2x.png in Resources */, F0E05A401EA0F9EB004B83FB /* tab_people@2x.png in Resources */, F083BD5A1E7009ED00A9B29C /* chevron@2x.png in Resources */, @@ -2381,6 +2397,7 @@ F083BD811E7009ED00A9B29C /* favourite@2x.png in Resources */, F0A4A1681EF7CB66003630DB /* members_list_icon@2x.png in Resources */, F083BD9F1E7009ED00A9B29C /* mod_icon@2x.png in Resources */, + 32918EAA1F473BDB0076CA16 /* Vector.strings in Resources */, F083BD801E7009ED00A9B29C /* favourite.png in Resources */, F083BD4B1E7009ED00A9B29C /* camera_capture.png in Resources */, F083BD841E7009ED00A9B29C /* favouriteOff@2x.png in Resources */, @@ -2909,6 +2926,22 @@ name = Vector.strings; sourceTree = ""; }; + 32918EA51F473BDB0076CA16 /* Localizable.strings */ = { + isa = PBXVariantGroup; + children = ( + 32918EA61F473BDB0076CA16 /* ru */, + ); + name = Localizable.strings; + sourceTree = ""; + }; + 32918EA71F473BDB0076CA16 /* Vector.strings */ = { + isa = PBXVariantGroup; + children = ( + 32918EA81F473BDB0076CA16 /* ru */, + ); + name = Vector.strings; + sourceTree = ""; + }; 32AE61EC1F0D2183007255F4 /* InfoPlist.strings */ = { isa = PBXVariantGroup; children = ( From 34eb2630e6bee8b71cef120840e5c432bb3e76f5 Mon Sep 17 00:00:00 2001 From: Giom Foret Date: Fri, 18 Aug 2017 17:30:38 +0200 Subject: [PATCH 027/102] Bug Fix - App extension: handle correctly the account change. Only the first enabled account is considered FTM. --- .../ViewController/ShareViewController.m | 114 +++++++++++++----- 1 file changed, 84 insertions(+), 30 deletions(-) diff --git a/RiotShareExtension/ViewController/ShareViewController.m b/RiotShareExtension/ViewController/ShareViewController.m index b8d694c67..84168b9a1 100644 --- a/RiotShareExtension/ViewController/ShareViewController.m +++ b/RiotShareExtension/ViewController/ShareViewController.m @@ -24,9 +24,11 @@ @interface ShareViewController () -@property (nonatomic) NSArray *rooms; +// The current user account +@property (nonatomic) MXKAccount *userAccount; +@property (nonatomic) id removedAccountObserver; -@property (nonatomic) MXKRecentsDataSource *recentsDataSource; +@property (nonatomic) NSArray *rooms; @property (weak, nonatomic) IBOutlet UIView *masterContainerView; @property (weak, nonatomic) IBOutlet UILabel *tittleLabel; @@ -47,16 +49,35 @@ [super viewDidLoad]; [self prepareSession]; - [self configureViews]; - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onSessionSync:) name:kMXSessionDidSyncNotification object:nil]; + [self configureViews]; +} + +- (void)viewWillAppear:(BOOL)animated +{ + [super viewWillAppear:animated]; + + // Add observer to handle removed accounts + self.removedAccountObserver = [[NSNotificationCenter defaultCenter] addObserverForName:kMXKAccountManagerDidRemoveAccountNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notif) { + + [self checkUserAccount]; + }]; + + [self checkUserAccount]; } - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; - [[NSNotificationCenter defaultCenter] removeObserver:self]; + // Remove listener + if (self.removedAccountObserver) + { + [[NSNotificationCenter defaultCenter] removeObserver:self.removedAccountObserver]; + self.removedAccountObserver = nil; + } + + [self.userAccount pauseInBackgroundTask]; } #pragma mark - Private @@ -66,22 +87,50 @@ // Apply the application group [MXKAppSettings standardAppSettings].applicationGroup = @"group.im.vector"; - // Prepare account manager - MXKAccountManager *accountManager = [MXKAccountManager sharedManager]; - - // Use MXFileStore as MXStore to permanently store events. - accountManager.storeClass = [MXFileStore class]; - - // Start a matrix session for each enabled accounts. - NSLog(@"[AppDelegate] initMatrixSessions: prepareSessionForActiveAccounts"); - [accountManager prepareSessionForActiveAccounts]; - - // Resume all existing matrix sessions - NSArray *mxAccounts = accountManager.activeAccounts; - for (MXKAccount *account in mxAccounts) + // We consider for now the first enabled account. + // TODO: Handle multiple accounts + self.userAccount = [MXKAccountManager sharedManager].activeAccounts.firstObject; + if (self.userAccount) { - [account resume]; - [self addMatrixSession:account.mxSession]; + NSLog(@"[ShareViewController] openSession for %@ account", self.userAccount.mxCredentials.userId); + // Use MXFileStore as MXStore to permanently store events. + [self.userAccount openSessionWithStore:[[MXFileStore alloc] init]]; + + [self addMatrixSession:self.userAccount.mxSession]; + } +} + +- (void)checkUserAccount +{ + // Force account manager to reload account from the local storage. + [[MXKAccountManager sharedManager] forceReloadAccounts]; + + if (self.userAccount) + { + // Check whether the used account is still the first active one + MXKAccount *firstAccount = [MXKAccountManager sharedManager].activeAccounts.firstObject; + + // Compare the access token + if (!firstAccount || ![self.userAccount.mxCredentials.accessToken isEqualToString:firstAccount.mxCredentials.accessToken]) + { + // Remove this account + [self removeMatrixSession:self.userAccount.mxSession]; + [self.userAccount closeSession:YES]; + self.userAccount = nil; + } + } + + if (self.userAccount) + { + // Resume the matrix session + [self.userAccount resume]; + } + else + { + // Prepare a new session if a new account is available. + [self prepareSession]; + + [self configureViews]; } } @@ -89,6 +138,21 @@ { self.masterContainerView.layer.cornerRadius = 7; + // Empty the content view + NSArray *subviews = self.contentView.subviews; + for (UIView *subview in subviews) + { + [subview removeFromSuperview]; + } + + // Release the current segmented view controller if any + if (self.segmentedViewController) + { + // TODO: release correctly all the existing data source and view controllers... + [self.segmentedViewController destroy]; + self.segmentedViewController = nil; + } + if (self.mainSession) { self.tittleLabel.text = [NSString stringWithFormat:NSLocalizedStringFromTable(@"send_to", @"Vector", nil), @""]; @@ -155,16 +219,6 @@ centerYConstraint.active = YES; } -#pragma mark - Notifications - -- (void)onSessionSync:(NSNotification *)notification -{ - if ([notification.object isEqual:self.mainSession] && !self.rooms.count) - { - self.recentsDataSource = [[MXKRecentsDataSource alloc] initWithMatrixSession:self.mainSession]; - } -} - #pragma mark - Actions - (IBAction)close:(UIButton *)sender From b1ae853be4542b75638cdcb39d6840390174f6d7 Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Mon, 21 Aug 2017 01:39:08 +0400 Subject: [PATCH 028/102] Introduced new ShareExtensionDelegate method didStartSendingToRoom to notify the viewController when the request is initiated to only then show the loading hud, block interaction with the view, etc --- RiotShareExtension/Model/ShareExtensionManager.h | 2 ++ RiotShareExtension/Model/ShareExtensionManager.m | 16 +++++++++++++++- .../ViewController/RoomsListViewController.m | 9 +++++++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/RiotShareExtension/Model/ShareExtensionManager.h b/RiotShareExtension/Model/ShareExtensionManager.h index 854738ddf..7f1c740b7 100644 --- a/RiotShareExtension/Model/ShareExtensionManager.h +++ b/RiotShareExtension/Model/ShareExtensionManager.h @@ -35,6 +35,8 @@ @optional +- (void)shareExtensionManager:(ShareExtensionManager *)extensionManager didStartSendingContentToRoom:(MXRoom *)room; + /** Called when the progress of the uploading media changes @param extensionManager the ShareExtensionManager object that called the method diff --git a/RiotShareExtension/Model/ShareExtensionManager.m b/RiotShareExtension/Model/ShareExtensionManager.m index 47c1bff4a..47303e86c 100644 --- a/RiotShareExtension/Model/ShareExtensionManager.m +++ b/RiotShareExtension/Model/ShareExtensionManager.m @@ -164,7 +164,9 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode) } } -- (UIAlertController *)compressionPromptForImage:(UIImage *)image shareBlock:(nonnull void(^)())shareBlock +#pragma mark - Private + +- (UIAlertController *)compressionPromptForImage:(UIImage *)image shareBlock:(void(^)())shareBlock { UIAlertController *compressionPrompt; @@ -300,6 +302,14 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode) return compressionPrompt; } +- (void)didStartSendingToRoom:(MXRoom *)room +{ + if ([self.delegate respondsToSelector:@selector(shareExtensionManager:didStartSendingContentToRoom:)]) + { + [self.delegate shareExtensionManager:self didStartSendingContentToRoom:room]; + } +} + #pragma mark - Notifications - (void)onMediaUploadProgress:(NSNotification *)notification @@ -314,6 +324,7 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode) - (void)sendText:(NSString *)text toRoom:(MXRoom *)room extensionItem:(NSExtensionItem *)extensionItem failureBlock:(void(^)())failureBlock { + [self didStartSendingToRoom:room]; if (!text) { NSLog(@"[ShareExtensionManager] loadItemForTypeIdentifier: failed."); @@ -343,6 +354,7 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode) - (void)sendFileWithUrl:(NSURL *)fileUrl toRoom:(MXRoom *)room extensionItem:(NSExtensionItem *)extensionItem failureBlock:(void(^)())failureBlock { + [self didStartSendingToRoom:room]; if (!fileUrl) { NSLog(@"[ShareExtensionManager] loadItemForTypeIdentifier: failed."); @@ -373,6 +385,7 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode) - (void)sendImage:(NSData *)imageData withProvider:(NSItemProvider*)itemProvider toRoom:(MXRoom *)room extensionItem:(NSExtensionItem *)extensionItem failureBlock:(void(^)())failureBlock { + [self didStartSendingToRoom:room]; if (!imageData) { NSLog(@"[ShareExtensionManager] loadItemForTypeIdentifier: failed."); @@ -443,6 +456,7 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode) - (void)sendVideo:(NSURL *)videoLocalUrl toRoom:(MXRoom *)room extensionItem:(NSExtensionItem *)extensionItem failureBlock:(void(^)())failureBlock { + [self didStartSendingToRoom:room]; if (!videoLocalUrl) { NSLog(@"[ShareExtensionManager] loadItemForTypeIdentifier: failed."); diff --git a/RiotShareExtension/ViewController/RoomsListViewController.m b/RiotShareExtension/ViewController/RoomsListViewController.m index e2ee6cb13..8ef221f4b 100644 --- a/RiotShareExtension/ViewController/RoomsListViewController.m +++ b/RiotShareExtension/ViewController/RoomsListViewController.m @@ -109,9 +109,7 @@ UIAlertAction *sendAction = [UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"send"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { MXRoom *selectedRoom = [self.dataSource getRoomAtIndexPath:indexPath]; - self.hudView = [MXKPieChartHUD showLoadingHudOnView:self.view WithMessage:NSLocalizedStringFromTable(@"sending", @"Vector", nil)]; [ShareExtensionManager sharedManager].delegate = self; - self.parentViewController.view.userInteractionEnabled = NO; [[ShareExtensionManager sharedManager] sendContentToRoom:selectedRoom failureBlock:^{ [self showFailureAlert]; @@ -211,6 +209,13 @@ [self presentViewController:compressionPrompt animated:YES completion:nil]; } +- (void)shareExtensionManager:(ShareExtensionManager *)extensionManager didStartSendingContentToRoom:(MXRoom *)room +{ + self.parentViewController.view.userInteractionEnabled = NO; + self.hudView = [MXKPieChartHUD showLoadingHudOnView:self.view WithMessage:NSLocalizedStringFromTable(@"sending", @"Vector", nil)]; + [self.hudView setProgress:0.0]; +} + - (void)shareExtensionManager:(ShareExtensionManager *)extensionManager mediaUploadProgress:(CGFloat)progress { [self.hudView setProgress:progress]; From d246fc56042fa955a54448fa0693f9ff719c4a64 Mon Sep 17 00:00:00 2001 From: Giom Foret Date: Mon, 21 Aug 2017 14:07:49 +0200 Subject: [PATCH 029/102] RoomsListViewController should inherit from MXKRecentListViewController. - to release correctly the resources - to reuse data source handling mechanism ... --- Riot.xcodeproj/project.pbxproj | 4 + .../ViewController/RoomsListViewController.h | 4 +- .../ViewController/RoomsListViewController.m | 169 ++++++++++++------ .../RoomsListViewController.xib | 53 ++++++ .../ViewController/ShareViewController.m | 12 +- 5 files changed, 176 insertions(+), 66 deletions(-) create mode 100644 RiotShareExtension/ViewController/RoomsListViewController.xib diff --git a/Riot.xcodeproj/project.pbxproj b/Riot.xcodeproj/project.pbxproj index 9e55e9d36..7c11cde6a 100644 --- a/Riot.xcodeproj/project.pbxproj +++ b/Riot.xcodeproj/project.pbxproj @@ -481,6 +481,7 @@ F0B4CBAC1F41F090008E99C5 /* EncryptionInfoView.xib in Resources */ = {isa = PBXBuildFile; fileRef = F0B4CBAB1F41F090008E99C5 /* EncryptionInfoView.xib */; }; F0B4CBB11F4215E3008E99C5 /* EventDetailsView.m in Sources */ = {isa = PBXBuildFile; fileRef = F0B4CBAF1F4215E3008E99C5 /* EventDetailsView.m */; }; F0B4CBB21F4215E3008E99C5 /* EventDetailsView.xib in Resources */ = {isa = PBXBuildFile; fileRef = F0B4CBB01F4215E3008E99C5 /* EventDetailsView.xib */; }; + F0B7A8B11F475783006E27D2 /* RoomsListViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F0B7A8AF1F4756A5006E27D2 /* RoomsListViewController.xib */; }; F0D869EB1EC455A100BB0A2B /* create_direct_chat.png in Resources */ = {isa = PBXBuildFile; fileRef = F0D869E81EC455A100BB0A2B /* create_direct_chat.png */; }; F0D869EC1EC455A100BB0A2B /* create_direct_chat@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F0D869E91EC455A100BB0A2B /* create_direct_chat@2x.png */; }; F0D869ED1EC455A100BB0A2B /* create_direct_chat@3x.png in Resources */ = {isa = PBXBuildFile; fileRef = F0D869EA1EC455A100BB0A2B /* create_direct_chat@3x.png */; }; @@ -1152,6 +1153,7 @@ F0B4CBAE1F4215E3008E99C5 /* EventDetailsView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EventDetailsView.h; sourceTree = ""; }; F0B4CBAF1F4215E3008E99C5 /* EventDetailsView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EventDetailsView.m; sourceTree = ""; }; F0B4CBB01F4215E3008E99C5 /* EventDetailsView.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = EventDetailsView.xib; sourceTree = ""; }; + F0B7A8AF1F4756A5006E27D2 /* RoomsListViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = RoomsListViewController.xib; sourceTree = ""; }; F0D869E81EC455A100BB0A2B /* create_direct_chat.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = create_direct_chat.png; sourceTree = ""; }; F0D869E91EC455A100BB0A2B /* create_direct_chat@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "create_direct_chat@2x.png"; sourceTree = ""; }; F0D869EA1EC455A100BB0A2B /* create_direct_chat@3x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "create_direct_chat@3x.png"; sourceTree = ""; }; @@ -1240,6 +1242,7 @@ 24D6B34E1F3C8F8A00FC7A71 /* ShareViewController.xib */, 24D6B3481F3C8F8A00FC7A71 /* RoomsListViewController.h */, 24D6B3491F3C8F8A00FC7A71 /* RoomsListViewController.m */, + F0B7A8AF1F4756A5006E27D2 /* RoomsListViewController.xib */, 24D6B3451F3C8F8A00FC7A71 /* FallbackViewController.h */, 24D6B3461F3C8F8A00FC7A71 /* FallbackViewController.m */, 24D6B3471F3C8F8A00FC7A71 /* FallbackViewController.xib */, @@ -2345,6 +2348,7 @@ 24D6B35B1F3CA03300FC7A71 /* ShareViewController.xib in Resources */, 24EEE5B51F2607C500B3C705 /* SegmentedViewController.xib in Resources */, 24EEE5A91F25529900B3C705 /* cancel@2x.png in Resources */, + F0B7A8B11F475783006E27D2 /* RoomsListViewController.xib in Resources */, 2435179C1F375B9400D0683E /* Info.plist in Resources */, 24EEE5A81F25529600B3C705 /* cancel@3x.png in Resources */, 2466B73E1F2DFAC100AE27B0 /* animatedLogo-4.png in Resources */, diff --git a/RiotShareExtension/ViewController/RoomsListViewController.h b/RiotShareExtension/ViewController/RoomsListViewController.h index 6054a1ddf..9a87e86a9 100644 --- a/RiotShareExtension/ViewController/RoomsListViewController.h +++ b/RiotShareExtension/ViewController/RoomsListViewController.h @@ -18,8 +18,8 @@ #import "MXRoom+Riot.h" #import "ShareRecentsDataSource.h" -@interface RoomsListViewController : UIViewController +@interface RoomsListViewController : MXKRecentListViewController -+ (instancetype)listViewControllerWithDataSource:(ShareRecentsDataSource *)dataSource failureBlock:(void(^)())failureBlock; +@property (copy) void (^failureBlock)(); @end diff --git a/RiotShareExtension/ViewController/RoomsListViewController.m b/RiotShareExtension/ViewController/RoomsListViewController.m index e2ee6cb13..ed489553f 100644 --- a/RiotShareExtension/ViewController/RoomsListViewController.m +++ b/RiotShareExtension/ViewController/RoomsListViewController.m @@ -25,70 +25,104 @@ -@interface RoomsListViewController () +@interface RoomsListViewController () -@property (nonatomic) ShareRecentsDataSource *dataSource; -@property (copy) void (^failureBlock)(); - -@property (nonatomic) UITableView *mainTableView; -@property (nonatomic) UISearchBar *searchBar; @property (nonatomic) MXKPieChartHUD *hudView; +// The fake search bar displayed at the top of the recents table. We switch on the actual search bar (self.recentsSearchBar) +// when the user selects it. +@property (nonatomic) UISearchBar *tableSearchBar; + @end @implementation RoomsListViewController +#pragma mark - Class methods + ++ (UINib *)nib +{ + return [UINib nibWithNibName:NSStringFromClass([RoomsListViewController class]) + bundle:[NSBundle bundleForClass:[RoomsListViewController class]]]; +} + ++ (instancetype)recentListViewController +{ + return [[[self class] alloc] initWithNibName:NSStringFromClass([RoomsListViewController class]) + bundle:[NSBundle bundleForClass:[RoomsListViewController class]]]; +} + +- (void)finalizeInit +{ + [super finalizeInit]; + + self.enableBarButtonSearch = NO; + + // Create the fake search bar + _tableSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 600, 44)]; + _tableSearchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth; + _tableSearchBar.showsCancelButton = NO; + _tableSearchBar.placeholder = NSLocalizedStringFromTable(@"search_default_placeholder", @"Vector", nil); + _tableSearchBar.delegate = self; +} + #pragma mark - Lifecycle - (void)viewDidLoad { [super viewDidLoad]; - [self configureTableView]; + + [self.recentsTableView registerNib:[RoomTableViewCell nib] forCellReuseIdentifier:[RoomTableViewCell defaultReuseIdentifier]]; + [self configureSearchBar]; } -#pragma mark - Public - -+ (instancetype)listViewControllerWithDataSource:(ShareRecentsDataSource *)dataSource failureBlock:(void(^)())failureBlock +- (void)destroy { - RoomsListViewController *listViewController = [[self class] new]; - listViewController.dataSource = dataSource; - listViewController.failureBlock = failureBlock; - return listViewController; + // Release the room data source + [self.dataSource destroy]; + + [super destroy]; } #pragma mark - Views -- (void)configureTableView -{ - self.mainTableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain]; - self.mainTableView.dataSource = self.dataSource; - self.mainTableView.delegate = self; - [self.mainTableView registerNib:[RoomTableViewCell nib] forCellReuseIdentifier:[RoomTableViewCell defaultReuseIdentifier]]; - - [self.view addSubview:self.mainTableView]; - self.mainTableView.translatesAutoresizingMaskIntoConstraints = NO; - self.view.translatesAutoresizingMaskIntoConstraints = NO; - NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:self.mainTableView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeWidth multiplier:1 constant:0]; - NSLayoutConstraint *heightConstraint = [NSLayoutConstraint constraintWithItem:self.mainTableView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeHeight multiplier:1 constant:0]; - NSLayoutConstraint *centerXConstraint = [NSLayoutConstraint constraintWithItem:self.mainTableView attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]; - NSLayoutConstraint *centerYConstraint = [NSLayoutConstraint constraintWithItem:self.mainTableView attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1 constant:0]; - - [NSLayoutConstraint activateConstraints:@[widthConstraint, heightConstraint, centerXConstraint, centerYConstraint]]; -} - - (void)configureSearchBar { - self.searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, 44.0)]; - self.searchBar.searchBarStyle = UISearchBarStyleMinimal; - self.searchBar.placeholder = NSLocalizedStringFromTable(@"search_default_placeholder", @"Vector", nil); - self.searchBar.tintColor = kRiotColorGreen; - self.searchBar.showsCancelButton = YES; + self.recentsSearchBar.autocapitalizationType = UITextAutocapitalizationTypeNone; - self.searchBar.delegate = self; + self.recentsSearchBar.searchBarStyle = UISearchBarStyleMinimal; + self.recentsSearchBar.placeholder = NSLocalizedStringFromTable(@"search_default_placeholder", @"Vector", nil); + self.recentsSearchBar.tintColor = kRiotColorGreen; - self.mainTableView.tableHeaderView = self.searchBar; + _tableSearchBar.tintColor = self.recentsSearchBar.tintColor; +} + +#pragma mark - Override MXKRecentListViewController + +- (void)refreshRecentsTable +{ + [super refreshRecentsTable]; + + // Check conditions to display the fake search bar into the table header + if (self.recentsSearchBar.isHidden && self.recentsTableView.tableHeaderView == nil) + { + // Add the search bar by hiding it by default. + self.recentsTableView.tableHeaderView = _tableSearchBar; + self.recentsTableView.contentOffset = CGPointMake(0, self.recentsTableView.contentOffset.y + _tableSearchBar.frame.size.height); + } +} + +- (void)hideSearchBar:(BOOL)hidden +{ + [super hideSearchBar:hidden]; + + if (!hidden) + { + // Remove the fake table header view if any + self.recentsTableView.tableHeaderView = nil; + self.recentsTableView.contentInset = UIEdgeInsetsZero; + } } #pragma mark - Private @@ -151,14 +185,6 @@ #pragma mark - MXKDataSourceDelegate -- (void)dataSource:(MXKDataSource*)dataSource didCellChange:(id)changes -{ - if (dataSource == self.dataSource) - { - [self.mainTableView reloadData]; - } -} - - (Class)cellViewClassForCellData:(MXKCellData*)cellData { if ([cellData isKindOfClass:[RecentCellData class]]) @@ -179,27 +205,52 @@ #pragma mark - UISearchBarDelegate -- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText +- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar { - if (searchText.length) + if (searchBar == _tableSearchBar) { - [self.dataSource searchWithPatterns:@[searchText]]; - } - else - { - [self.dataSource searchWithPatterns:nil]; + [self hideSearchBar:NO]; + [self.recentsSearchBar becomeFirstResponder]; + return NO; } + + return YES; } -- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar +- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar { - [searchBar resignFirstResponder]; + dispatch_async(dispatch_get_main_queue(), ^{ + + [self.recentsSearchBar setShowsCancelButton:YES animated:NO]; + + }); } -- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar +- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar { - [searchBar resignFirstResponder]; - [self.dataSource searchWithPatterns:nil]; + [self.recentsSearchBar setShowsCancelButton:NO animated:NO]; +} + +#pragma mark - UIScrollViewDelegate + +- (void)scrollViewDidScroll:(UIScrollView *)scrollView +{ + [super scrollViewDidScroll:scrollView]; + + if (scrollView == self.recentsTableView) + { + if (!self.recentsSearchBar.isHidden) + { + if (!self.recentsSearchBar.text.length && (scrollView.contentOffset.y + scrollView.contentInset.top > self.recentsSearchBar.frame.size.height)) + { + // Hide the search bar + [self hideSearchBar:YES]; + + // Refresh display + [self refreshRecentsTable]; + } + } + } } #pragma mark - ShareExtensionManagerDelegate diff --git a/RiotShareExtension/ViewController/RoomsListViewController.xib b/RiotShareExtension/ViewController/RoomsListViewController.xib new file mode 100644 index 000000000..441694c1f --- /dev/null +++ b/RiotShareExtension/ViewController/RoomsListViewController.xib @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/RiotShareExtension/ViewController/ShareViewController.m b/RiotShareExtension/ViewController/ShareViewController.m index 84168b9a1..b85408af6 100644 --- a/RiotShareExtension/ViewController/ShareViewController.m +++ b/RiotShareExtension/ViewController/ShareViewController.m @@ -148,7 +148,7 @@ // Release the current segmented view controller if any if (self.segmentedViewController) { - // TODO: release correctly all the existing data source and view controllers... + // Release correctly all the existing data source and view controllers. [self.segmentedViewController destroy]; self.segmentedViewController = nil; } @@ -180,12 +180,14 @@ }; ShareRecentsDataSource *roomsDataSource = [[ShareRecentsDataSource alloc] initWithMatrixSession:self.mainSession dataSourceMode:RecentsDataSourceModeRooms]; - RoomsListViewController *roomsViewController = [RoomsListViewController listViewControllerWithDataSource:roomsDataSource failureBlock:failureBlock]; - roomsDataSource.delegate = roomsViewController; + RoomsListViewController *roomsViewController = [RoomsListViewController recentListViewController]; + roomsViewController.failureBlock = failureBlock; + [roomsViewController displayList:roomsDataSource]; ShareRecentsDataSource *peopleDataSource = [[ShareRecentsDataSource alloc] initWithMatrixSession:self.mainSession dataSourceMode:RecentsDataSourceModePeople]; - RoomsListViewController *peopleViewController = [RoomsListViewController listViewControllerWithDataSource:peopleDataSource failureBlock:failureBlock]; - peopleDataSource.delegate = peopleViewController; + RoomsListViewController *peopleViewController = [RoomsListViewController recentListViewController]; + peopleViewController.failureBlock = failureBlock; + [peopleViewController displayList:peopleDataSource]; [self.segmentedViewController initWithTitles:titles viewControllers:@[roomsViewController, peopleViewController] defaultSelected:0]; From 8666014f2cf09dd72fc1541ffafd2c1d4c2fc623 Mon Sep 17 00:00:00 2001 From: Giom Foret Date: Mon, 21 Aug 2017 15:28:58 +0200 Subject: [PATCH 030/102] Bug Fix - Make sure the uploaded image orientation is up --- .../Model/ShareExtensionManager.m | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/RiotShareExtension/Model/ShareExtensionManager.m b/RiotShareExtension/Model/ShareExtensionManager.m index 47c1bff4a..367f0ef0b 100644 --- a/RiotShareExtension/Model/ShareExtensionManager.m +++ b/RiotShareExtension/Model/ShareExtensionManager.m @@ -382,9 +382,18 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode) } return; } - //Send the image + + // Prepare the image + BOOL rotated = NO; UIImage *image = [[UIImage alloc] initWithData:imageData]; + // Make sure the uploaded image orientation is up + if (image.imageOrientation != UIImageOrientationUp) + { + image = [MXKTools forceImageOrientationUp:image]; + rotated = YES; + } + if (self.imageCompressionMode == ImageCompressionModeSmall) { image = [MXKTools reduceImage:image toFitInSize:CGSizeMake(MXKTOOLS_SMALL_IMAGE_SIZE, MXKTOOLS_SMALL_IMAGE_SIZE)]; @@ -402,14 +411,27 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode) if ([itemProvider hasItemConformingToTypeIdentifier:(__bridge NSString *)kUTTypePNG]) { mimeType = @"image/png"; + + if (rotated) + { + // Update imageData + imageData = UIImagePNGRepresentation(image); + } } else if ([itemProvider hasItemConformingToTypeIdentifier:(__bridge NSString *)kUTTypeJPEG]) { mimeType = @"image/jpeg"; + + if (rotated) + { + // Update imageData + imageData = UIImageJPEGRepresentation(image, 1.0); + } } else { - image = [[UIImage alloc] initWithData:UIImageJPEGRepresentation(image, 1.0)]; + imageData = UIImageJPEGRepresentation(image, 1.0); + image = [[UIImage alloc] initWithData:imageData]; mimeType = @"image/jpeg"; } From 9ce814873f561d33d2c197a087dc04a2bf204d8b Mon Sep 17 00:00:00 2001 From: Aram Sargsyan Date: Mon, 21 Aug 2017 18:45:16 +0400 Subject: [PATCH 031/102] Sending the file with it's actual fiename, changes temporary search bar stykle to match the real one's style, showing only joined rooms for sharing --- RiotShareExtension/Model/ShareExtensionManager.m | 2 +- RiotShareExtension/Model/ShareRecentsDataSource.m | 4 ++-- .../ViewController/RoomsListViewController.m | 1 + .../ViewController/RoomsListViewController.xib | 7 ++++--- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/RiotShareExtension/Model/ShareExtensionManager.m b/RiotShareExtension/Model/ShareExtensionManager.m index 47303e86c..37f11b977 100644 --- a/RiotShareExtension/Model/ShareExtensionManager.m +++ b/RiotShareExtension/Model/ShareExtensionManager.m @@ -380,7 +380,7 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode) { failureBlock(); } - }]; + } keepActualFilename:YES]; } - (void)sendImage:(NSData *)imageData withProvider:(NSItemProvider*)itemProvider toRoom:(MXRoom *)room extensionItem:(NSExtensionItem *)extensionItem failureBlock:(void(^)())failureBlock diff --git a/RiotShareExtension/Model/ShareRecentsDataSource.m b/RiotShareExtension/Model/ShareRecentsDataSource.m index 727fb929f..4df22655c 100644 --- a/RiotShareExtension/Model/ShareRecentsDataSource.m +++ b/RiotShareExtension/Model/ShareRecentsDataSource.m @@ -59,14 +59,14 @@ if (self.dataSourceMode == RecentsDataSourceModePeople) { - if (room.isDirect) + if (room.isDirect && room.state.membership == MXMembershipJoin) { [self.recentPeople addObject:cellData]; } } else if (self.dataSourceMode == RecentsDataSourceModeRooms) { - if (!room.isDirect) + if (!room.isDirect && room.state.membership == MXMembershipJoin) { [self.recentRooms addObject:cellData]; } diff --git a/RiotShareExtension/ViewController/RoomsListViewController.m b/RiotShareExtension/ViewController/RoomsListViewController.m index a5ab5ad59..709277a09 100644 --- a/RiotShareExtension/ViewController/RoomsListViewController.m +++ b/RiotShareExtension/ViewController/RoomsListViewController.m @@ -62,6 +62,7 @@ _tableSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 600, 44)]; _tableSearchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth; _tableSearchBar.showsCancelButton = NO; + _tableSearchBar.searchBarStyle = UISearchBarStyleMinimal; _tableSearchBar.placeholder = NSLocalizedStringFromTable(@"search_default_placeholder", @"Vector", nil); _tableSearchBar.delegate = self; } diff --git a/RiotShareExtension/ViewController/RoomsListViewController.xib b/RiotShareExtension/ViewController/RoomsListViewController.xib index 441694c1f..630d940a3 100644 --- a/RiotShareExtension/ViewController/RoomsListViewController.xib +++ b/RiotShareExtension/ViewController/RoomsListViewController.xib @@ -1,10 +1,11 @@ - + - + + @@ -23,7 +24,7 @@ - + From 0c5218fa59c536599b359a2ad34b38df31b7f34e Mon Sep 17 00:00:00 2001 From: Giom Foret Date: Mon, 21 Aug 2017 18:09:07 +0200 Subject: [PATCH 032/102] App extension: enlarge the close button --- .../ViewController/ShareViewController.xib | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/RiotShareExtension/ViewController/ShareViewController.xib b/RiotShareExtension/ViewController/ShareViewController.xib index ab0444174..879dde935 100644 --- a/RiotShareExtension/ViewController/ShareViewController.xib +++ b/RiotShareExtension/ViewController/ShareViewController.xib @@ -1,11 +1,12 @@ - + - + + @@ -39,9 +40,10 @@