mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-17 02:58:07 +00:00
enable share screenshots and icloud images
This commit is contained in:
parent
9e2d313c53
commit
aace9c26e3
5 changed files with 79 additions and 43 deletions
|
|
@ -261,8 +261,14 @@ static UICompositeViewDescription *compositeDescription = nil;
|
|||
NSString *key = [[fileName componentsSeparatedByString:@"."] firstObject];
|
||||
NSMutableDictionary <NSString *, PHAsset *> * assetDict = [LinphoneUtils photoAssetsDictionary];
|
||||
if ([fileName hasSuffix:@"JPG"] || [fileName hasSuffix:@"PNG"]) {
|
||||
UIImage *image = [[UIImage alloc] initWithData:dict[@"nsData"]];
|
||||
[self chooseImageQuality:image assetId:[[assetDict objectForKey:key] localIdentifier]];
|
||||
PHAsset *phasset = [assetDict objectForKey:key];
|
||||
if (!phasset) {
|
||||
// for the images not really in the photo album
|
||||
[self confirmShare:dict[@"nsData"] url:nil fileName:fileName assetId:nil];
|
||||
} else {
|
||||
UIImage *image = [[UIImage alloc] initWithData:dict[@"nsData"]];
|
||||
[self chooseImageQuality:image assetId:[phasset localIdentifier]];
|
||||
}
|
||||
} else if ([fileName hasSuffix:@"MOV"]) {
|
||||
[self confirmShare:dict[@"nsData"] url:nil fileName:nil assetId:[[assetDict objectForKey:key] localIdentifier]];
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -107,6 +107,7 @@
|
|||
_messageImageView.hidden = YES;
|
||||
_imageGestureRecognizer.enabled = YES;
|
||||
_finalImage.hidden = NO;
|
||||
_fileView.hidden = YES;
|
||||
[self layoutSubviews];
|
||||
});
|
||||
}
|
||||
|
|
@ -189,9 +190,16 @@
|
|||
}
|
||||
}
|
||||
else if (localFile) {
|
||||
NSString *text = [NSString stringWithFormat:@"📎 %@",localFile];
|
||||
_fileName.text = text;
|
||||
[self loadFileAsset];
|
||||
if ([localFile hasSuffix:@"JPG"] || [localFile hasSuffix:@"PNG"]) {
|
||||
ChatConversationView *view = VIEW(ChatConversationView);
|
||||
NSData *data = [NSData dataWithContentsOfURL:[view getICloudFileUrl:localFile]];
|
||||
UIImage *image = [[UIImage alloc] initWithData:data];
|
||||
[self loadImageAsset:nil image:image];
|
||||
} else {
|
||||
NSString *text = [NSString stringWithFormat:@"📎 %@",localFile];
|
||||
_fileName.text = text;
|
||||
[self loadFileAsset];
|
||||
}
|
||||
}
|
||||
|
||||
// we are uploading the image
|
||||
|
|
@ -303,6 +311,19 @@
|
|||
ImageView *view = VIEW(ImageView);
|
||||
[PhoneMainView.instance changeCurrentView:view.compositeViewDescription];
|
||||
PHAsset *asset = [_messageImageView asset];
|
||||
if (!asset) {
|
||||
NSString *localFile = [LinphoneManager getMessageAppDataForKey:@"localfile" inMessage:self.message];
|
||||
if ([localFile hasSuffix:@"JPG"] || [localFile hasSuffix:@"PNG"]) {
|
||||
ChatConversationView *chatView = VIEW(ChatConversationView);
|
||||
NSData *data = [NSData dataWithContentsOfURL:[chatView getICloudFileUrl:localFile]];
|
||||
UIImage *image = [[UIImage alloc] initWithData:data];
|
||||
if (image)
|
||||
[view setImage:image];
|
||||
else
|
||||
LOGE(@"Can't read image");
|
||||
}
|
||||
return;
|
||||
}
|
||||
PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
|
||||
options.synchronous = TRUE;
|
||||
[[PHImageManager defaultManager] requestImageForAsset:asset targetSize:PHImageManagerMaximumSize contentMode:PHImageContentModeDefault options:options
|
||||
|
|
|
|||
|
|
@ -456,18 +456,29 @@ static const CGFloat CELL_MESSAGE_Y_MARGIN = 44; // 44;
|
|||
NSString *localFile = [LinphoneManager getMessageAppDataForKey:@"localfile" inMessage:chat];
|
||||
NSString *localVideo = [LinphoneManager getMessageAppDataForKey:@"localvideo" inMessage:chat];
|
||||
|
||||
CGSize textSize = CGSizeMake(0, 0);
|
||||
if (![messageText isEqualToString:@"🗻"]) {
|
||||
textSize = [self computeBoundingBox:messageText
|
||||
size:CGSizeMake(width - CELL_MESSAGE_X_MARGIN - 4, CGFLOAT_MAX)
|
||||
font:messageFont];
|
||||
size.height += textSize.height;
|
||||
}
|
||||
|
||||
if(localFile) {
|
||||
CGSize fileSize = CGSizeMake(230, 50);
|
||||
size = [self getMediaMessageSizefromOriginalSize:fileSize withWidth:width];
|
||||
} else {
|
||||
CGSize textSize = CGSizeMake(0, 0);
|
||||
if (![messageText isEqualToString:@"🗻"]) {
|
||||
textSize = [self computeBoundingBox:messageText
|
||||
size:CGSizeMake(width - CELL_MESSAGE_X_MARGIN - 4, CGFLOAT_MAX)
|
||||
font:messageFont];
|
||||
if ([localFile hasSuffix:@"JPG"] || [localFile hasSuffix:@"PNG"]) {
|
||||
ChatConversationView *view = VIEW(ChatConversationView);
|
||||
NSData *data = [NSData dataWithContentsOfURL:[view getICloudFileUrl:localFile]];
|
||||
UIImage *image = [[UIImage alloc] initWithData:data];
|
||||
size = [self getMediaMessageSizefromOriginalSize:image.size withWidth:width];
|
||||
|
||||
// add size for message text
|
||||
size.height += textSize.height;
|
||||
size.width = MAX(textSize.width, size.width);
|
||||
} else {
|
||||
CGSize fileSize = CGSizeMake(230, 50);
|
||||
size = [self getMediaMessageSizefromOriginalSize:fileSize withWidth:width];
|
||||
}
|
||||
|
||||
} else {
|
||||
if (!localImage && !localVideo) {
|
||||
//We are loading the image
|
||||
return CGSizeMake(CELL_MIN_WIDTH + CELL_MESSAGE_X_MARGIN, CELL_MIN_HEIGHT + CELL_MESSAGE_Y_MARGIN + textSize.height + 20);
|
||||
|
|
|
|||
|
|
@ -73,23 +73,6 @@
|
|||
return assetDict;
|
||||
}
|
||||
|
||||
/*+ (NSMutableDictionary <NSString *, PHAsset *> *)videoAssetsDictionary {
|
||||
NSMutableDictionary <NSString *, PHAsset *> *assetDict = [NSMutableDictionary dictionary];
|
||||
|
||||
PHFetchOptions *options = [[PHFetchOptions alloc] init];
|
||||
[options setIncludeHiddenAssets:YES];
|
||||
[options setIncludeAllBurstAssets:YES];
|
||||
|
||||
PHFetchResult *fetchRes = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeVideo options:options];
|
||||
|
||||
for (PHAsset *asset in fetchRes) {
|
||||
NSString *key = [asset valueForKey:@"filename"];
|
||||
[assetDict setObject:asset forKey:[[key componentsSeparatedByString:@"."] firstObject]];
|
||||
}
|
||||
|
||||
return assetDict;
|
||||
}*/
|
||||
|
||||
+ (NSString *)timeToString:(time_t)time withFormat:(LinphoneDateFormat)format {
|
||||
NSString *formatstr;
|
||||
NSDate *todayDate = [[NSDate alloc] init];
|
||||
|
|
|
|||
|
|
@ -42,7 +42,9 @@
|
|||
[self loadItem:provider typeIdentifier:@"com.adobe.pdf" defaults:defaults];
|
||||
} else if ([provider hasItemConformingToTypeIdentifier:@"public.png"]) {
|
||||
[self loadItem:provider typeIdentifier:@"public.png" defaults:defaults];
|
||||
} else{
|
||||
} else if ([provider hasItemConformingToTypeIdentifier:@"public.image"]) {
|
||||
[self loadItem:provider typeIdentifier:@"public.image" defaults:defaults];
|
||||
}else{
|
||||
NSLog(@"Unkown itemprovider = %@", provider);
|
||||
support = false;
|
||||
}
|
||||
|
|
@ -96,22 +98,35 @@
|
|||
[self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];
|
||||
}
|
||||
|
||||
UIResponder *responder = self;
|
||||
while (responder != nil) {
|
||||
if ([responder respondsToSelector:@selector(openURL:)]) {
|
||||
[responder performSelector:@selector(openURL:)
|
||||
withObject:[NSURL URLWithString:@"message-linphone://" ]];
|
||||
[self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];
|
||||
break;
|
||||
}
|
||||
responder = [responder nextResponder];
|
||||
}
|
||||
[defaults synchronize];
|
||||
[self respondUrl:defaults];
|
||||
} else if ([(NSObject*)item isKindOfClass:[UIImage class]]) {
|
||||
UIImage *image = (UIImage*)item;
|
||||
NSDictionary *dict = @{@"nsData" : UIImagePNGRepresentation(image),
|
||||
@"url" : [NSString stringWithFormat:@"IMAGE_%f.PNG", [[NSDate date] timeIntervalSince1970]],
|
||||
@"message" : self.contentText};
|
||||
[defaults setObject:dict forKey:@"photoData"];
|
||||
|
||||
[self respondUrl:defaults];
|
||||
} else {
|
||||
//share text
|
||||
NSLog(@"Unsupported provider = %@", provider);
|
||||
[self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)respondUrl:(NSUserDefaults *)defaults {
|
||||
UIResponder *responder = self;
|
||||
while (responder != nil) {
|
||||
if ([responder respondsToSelector:@selector(openURL:)]) {
|
||||
[responder performSelector:@selector(openURL:)
|
||||
withObject:[NSURL URLWithString:@"message-linphone://" ]];
|
||||
[self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];
|
||||
break;
|
||||
}
|
||||
responder = [responder nextResponder];
|
||||
}
|
||||
[defaults synchronize];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue