Fixed retain cycles, changed color constant

This commit is contained in:
Aram Sargsyan 2017-08-17 19:28:08 +04:00
parent 07a0c9f982
commit 37bd161f1d
5 changed files with 126 additions and 43 deletions

View file

@ -1,10 +1,18 @@
// /*
// ShareExtensionManager.h Copyright 2017 Aram Sargsyan
// Riot
// Licensed under the Apache License, Version 2.0 (the "License");
// Created by Aram Sargsyan on 8/10/17. you may not use this file except in compliance with the License.
// Copyright © 2017 matrix.org. All rights reserved. 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 <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import <MatrixKit/MatrixKit.h> #import <MatrixKit/MatrixKit.h>

View file

@ -1,10 +1,18 @@
// /*
// ShareExtensionManager.m Copyright 2017 Aram Sargsyan
// Riot
// Licensed under the Apache License, Version 2.0 (the "License");
// Created by Aram Sargsyan on 8/10/17. you may not use this file except in compliance with the License.
// Copyright © 2017 matrix.org. All rights reserved. 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 "ShareExtensionManager.h"
#import "MXKPieChartHUD.h" #import "MXKPieChartHUD.h"
@ -52,6 +60,7 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
NSString *UTTypeFileUrl = (__bridge NSString *)kUTTypeFileURL; NSString *UTTypeFileUrl = (__bridge NSString *)kUTTypeFileURL;
NSString *UTTypeMovie = (__bridge NSString *)kUTTypeMovie; NSString *UTTypeMovie = (__bridge NSString *)kUTTypeMovie;
__weak typeof(self) weakSelf = self;
for (NSExtensionItem *item in self.shareExtensionContext.inputItems) for (NSExtensionItem *item in self.shareExtensionContext.inputItems)
{ {
@ -60,44 +69,68 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeFileUrl]) if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeFileUrl])
{ {
[itemProvider loadItemForTypeIdentifier:UTTypeFileUrl options:nil completionHandler:^(NSURL *fileUrl, NSError * _Null_unspecified error) { [itemProvider loadItemForTypeIdentifier:UTTypeFileUrl options:nil completionHandler:^(NSURL *fileUrl, NSError * _Null_unspecified error) {
if (weakSelf)
{
typeof(self) self = weakSelf;
[self sendFileWithUrl:fileUrl toRoom:room extensionItem:item failureBlock:failureBlock]; [self sendFileWithUrl:fileUrl toRoom:room extensionItem:item failureBlock:failureBlock];
}
}]; }];
} }
else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeText]) else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeText])
{ {
[itemProvider loadItemForTypeIdentifier:UTTypeText options:nil completionHandler:^(NSString *text, NSError * _Null_unspecified error) { [itemProvider loadItemForTypeIdentifier:UTTypeText options:nil completionHandler:^(NSString *text, NSError * _Null_unspecified error) {
if (weakSelf)
{
typeof(self) self = weakSelf;
[self sendText:text toRoom:room extensionItem:item failureBlock:failureBlock]; [self sendText:text toRoom:room extensionItem:item failureBlock:failureBlock];
}
}]; }];
} }
else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeURL]) else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeURL])
{ {
[itemProvider loadItemForTypeIdentifier:UTTypeURL options:nil completionHandler:^(NSURL *url, NSError * _Null_unspecified error) { [itemProvider loadItemForTypeIdentifier:UTTypeURL options:nil completionHandler:^(NSURL *url, NSError * _Null_unspecified error) {
if (weakSelf)
{
typeof(self) self = weakSelf;
[self sendText:url.absoluteString toRoom:room extensionItem:item failureBlock:failureBlock]; [self sendText:url.absoluteString toRoom:room extensionItem:item failureBlock:failureBlock];
}
}]; }];
} }
else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeImage]) else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeImage])
{ {
[itemProvider loadItemForTypeIdentifier:UTTypeImage options:nil completionHandler:^(NSData *imageData, NSError * _Null_unspecified error) [itemProvider loadItemForTypeIdentifier:UTTypeImage options:nil completionHandler:^(NSData *imageData, NSError * _Null_unspecified error)
{ {
if (weakSelf)
{
typeof(self) self = weakSelf;
UIImage *image = [[UIImage alloc] initWithData:imageData]; UIImage *image = [[UIImage alloc] initWithData:imageData];
UIAlertController *compressionPrompt = [self compressionPromptForImage:image shareBlock:^{ UIAlertController *compressionPrompt = [self compressionPromptForImage:image shareBlock:^{
[self sendImage:imageData withProvider:itemProvider toRoom:room extensionItem:item failureBlock:failureBlock]; [self sendImage:imageData withProvider:itemProvider toRoom:room extensionItem:item failureBlock:failureBlock];
}]; }];
[self.delegate shareExtensionManager:self showImageCompressionPrompt:compressionPrompt]; [self.delegate shareExtensionManager:self showImageCompressionPrompt:compressionPrompt];
}
}]; }];
} }
else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeVideo]) else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeVideo])
{ {
[itemProvider loadItemForTypeIdentifier:UTTypeVideo options:nil completionHandler:^(NSURL *videoLocalUrl, NSError * _Null_unspecified error) [itemProvider loadItemForTypeIdentifier:UTTypeVideo options:nil completionHandler:^(NSURL *videoLocalUrl, NSError * _Null_unspecified error)
{ {
if (weakSelf)
{
typeof(self) self = weakSelf;
[self sendVideo:videoLocalUrl toRoom:room extensionItem:item failureBlock:failureBlock]; [self sendVideo:videoLocalUrl toRoom:room extensionItem:item failureBlock:failureBlock];
}
}]; }];
} }
else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeMovie]) else if ([itemProvider hasItemConformingToTypeIdentifier:UTTypeMovie])
{ {
[itemProvider loadItemForTypeIdentifier:UTTypeMovie options:nil completionHandler:^(NSURL *videoLocalUrl, NSError * _Null_unspecified error) [itemProvider loadItemForTypeIdentifier:UTTypeMovie options:nil completionHandler:^(NSURL *videoLocalUrl, NSError * _Null_unspecified error)
{ {
if (weakSelf)
{
typeof(self) self = weakSelf;
[self sendVideo:videoLocalUrl toRoom:room extensionItem:item failureBlock:failureBlock]; [self sendVideo:videoLocalUrl toRoom:room extensionItem:item failureBlock:failureBlock];
}
}]; }];
} }
} }
@ -288,8 +321,15 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
} }
return; return;
} }
__weak typeof(self) weakSelf = self;
[room sendTextMessage:text success:^(NSString *eventId) { [room sendTextMessage:text success:^(NSString *eventId) {
if (weakSelf)
{
typeof(self) self = weakSelf;
[self.shareExtensionContext completeRequestReturningItems:@[extensionItem] completionHandler:nil]; [self.shareExtensionContext completeRequestReturningItems:@[extensionItem] completionHandler:nil];
}
} failure:^(NSError *error) { } failure:^(NSError *error) {
NSLog(@"[ShareExtensionManager] sendTextMessage failed."); NSLog(@"[ShareExtensionManager] sendTextMessage failed.");
if (failureBlock) if (failureBlock)
@ -311,8 +351,15 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
return; return;
} }
NSString *mimeType = [fileUrl pathExtension]; NSString *mimeType = [fileUrl pathExtension];
__weak typeof(self) weakSelf = self;
[room sendFile:fileUrl mimeType:mimeType localEcho:nil success:^(NSString *eventId) { [room sendFile:fileUrl mimeType:mimeType localEcho:nil success:^(NSString *eventId) {
if (weakSelf)
{
typeof(self) self = weakSelf;
[self.shareExtensionContext completeRequestReturningItems:@[extensionItem] completionHandler:nil]; [self.shareExtensionContext completeRequestReturningItems:@[extensionItem] completionHandler:nil];
}
} failure:^(NSError *error) { } failure:^(NSError *error) {
NSLog(@"[ShareExtensionManager] sendFile failed."); NSLog(@"[ShareExtensionManager] sendFile failed.");
if (failureBlock) 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) { [room sendImage:imageData withImageSize:image.size mimeType:mimeType andThumbnail:thumbnail localEcho:nil success:^(NSString *eventId) {
if (weakSelf)
{
typeof(self) self = weakSelf;
[self.shareExtensionContext completeRequestReturningItems:@[extensionItem] completionHandler:nil]; [self.shareExtensionContext completeRequestReturningItems:@[extensionItem] completionHandler:nil];
}
} failure:^(NSError *error) { } failure:^(NSError *error) {
NSLog(@"[ShareExtensionManager] sendImage failed."); NSLog(@"[ShareExtensionManager] sendImage failed.");
if (failureBlock) if (failureBlock)
@ -408,8 +461,14 @@ typedef NS_ENUM(NSInteger, ImageCompressionMode)
UIImage *videoThumbnail = [[UIImage alloc] initWithCGImage:imageRef]; UIImage *videoThumbnail = [[UIImage alloc] initWithCGImage:imageRef];
CFRelease(imageRef); CFRelease(imageRef);
__weak typeof(self) weakSelf = self;
[room sendVideo:videoLocalUrl withThumbnail:videoThumbnail localEcho:nil success:^(NSString *eventId) { [room sendVideo:videoLocalUrl withThumbnail:videoThumbnail localEcho:nil success:^(NSString *eventId) {
if (weakSelf)
{
typeof(self) self = weakSelf;
[self.shareExtensionContext completeRequestReturningItems:@[extensionItem] completionHandler:nil]; [self.shareExtensionContext completeRequestReturningItems:@[extensionItem] completionHandler:nil];
}
} failure:^(NSError *error) { } failure:^(NSError *error) {
NSLog(@"[ShareExtensionManager] sendVideo failed."); NSLog(@"[ShareExtensionManager] sendVideo failed.");
if (failureBlock) if (failureBlock)

View file

@ -1,10 +1,18 @@
// /*
// ShareRecentsDataSource.h Copyright 2017 Aram Sargsyan
// Riot
// Licensed under the Apache License, Version 2.0 (the "License");
// Created by Aram Sargsyan on 8/10/17. you may not use this file except in compliance with the License.
// Copyright © 2017 matrix.org. All rights reserved. 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 <MatrixKit/MatrixKit.h> #import <MatrixKit/MatrixKit.h>

View file

@ -1,10 +1,18 @@
// /*
// ShareRecentsDataSource.m Copyright 2017 Aram Sargsyan
// Riot
// Licensed under the Apache License, Version 2.0 (the "License");
// Created by Aram Sargsyan on 8/10/17. you may not use this file except in compliance with the License.
// Copyright © 2017 matrix.org. All rights reserved. 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 "ShareRecentsDataSource.h"
#import "RoomTableViewCell.h" #import "RoomTableViewCell.h"

View file

@ -29,7 +29,7 @@
{ {
[super viewDidLoad]; [super viewDidLoad];
self.titleLabel.textColor = kRiotTextColorGray; self.titleLabel.textColor = kRiotSecondaryTextColor;
self.titleLabel.text = NSLocalizedStringFromTable(@"auth_share_extension_prompt", @"Vector", nil); self.titleLabel.text = NSLocalizedStringFromTable(@"auth_share_extension_prompt", @"Vector", nil);
} }