mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-28 15:22:39 +00:00
Fixed retain cycles, changed color constant
This commit is contained in:
parent
07a0c9f982
commit
37bd161f1d
5 changed files with 126 additions and 43 deletions
|
@ -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 <Foundation/Foundation.h>
|
||||
#import <MatrixKit/MatrixKit.h>
|
||||
|
|
|
@ -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) {
|
||||
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) {
|
||||
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) {
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
if (weakSelf)
|
||||
{
|
||||
typeof(self) self = weakSelf;
|
||||
[self.shareExtensionContext completeRequestReturningItems:@[extensionItem] completionHandler:nil];
|
||||
}
|
||||
} failure:^(NSError *error) {
|
||||
NSLog(@"[ShareExtensionManager] sendVideo failed.");
|
||||
if (failureBlock)
|
||||
|
|
|
@ -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 <MatrixKit/MatrixKit.h>
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
{
|
||||
[super viewDidLoad];
|
||||
|
||||
self.titleLabel.textColor = kRiotTextColorGray;
|
||||
self.titleLabel.textColor = kRiotSecondaryTextColor;
|
||||
self.titleLabel.text = NSLocalizedStringFromTable(@"auth_share_extension_prompt", @"Vector", nil);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue