merge view

This commit is contained in:
Danmei Chen 2018-06-14 17:37:15 +02:00
parent cdf2e45403
commit 88341280b6
6 changed files with 220 additions and 251 deletions

View file

@ -220,7 +220,7 @@ static UICompositeViewDescription *compositeDescription = nil;
NSDictionary *dict = [defaults valueForKey:@"img"];
NSDictionary *dictWeb = [defaults valueForKey:@"web"];
NSDictionary *dictFile = [defaults valueForKey:@"file"];
NSDictionary *dictFile = [defaults valueForKey:@"mov"];
NSDictionary *dictText = [defaults valueForKey:@"text"];
if (dict) {
//share photo
@ -247,7 +247,7 @@ static UICompositeViewDescription *compositeDescription = nil;
NSData *data = dictFile[@"nsData"];
[self confirmShare:data url:[NSURL fileURLWithPath:dictFile[@"url"]]];
[self sendContentText:dictFile[@"name"]];
[defaults removeObjectForKey:@"file"];
[defaults removeObjectForKey:@"mov"];
}else if(dictText) {
//share text
[self sendContentText:dictText[@"name"]];
@ -370,7 +370,7 @@ static UICompositeViewDescription *compositeDescription = nil;
DTActionSheet *sheet = [[DTActionSheet alloc] initWithTitle:NSLocalizedString(@"", nil)];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[sheet addButtonWithTitle:@"send to him"
[sheet addButtonWithTitle:@"send to this friend"
block:^() {
[self startFileUpload:data withUrl:url];
}];
@ -856,7 +856,6 @@ void on_chat_room_conference_left(LinphoneChatRoom *cr, const LinphoneEventLog *
- (void)openResults:(NSString *) filePath
{
//TODO: if file exist
// Open the controller.
_documentInteractionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:filePath]];
_documentInteractionController.delegate = self;

View file

@ -19,7 +19,7 @@
<outlet property="cancelButton" destination="6dl-Nz-rdv" id="ygz-nv-omC"/>
<outlet property="contactDateLabel" destination="JyR-RQ-uwF" id="Tc4-9t-i5V"/>
<outlet property="downloadButton" destination="N75-gL-R6t" id="EgN-Ab-Ded"/>
<outlet property="fileName" destination="Dqi-dR-naZ" id="yvz-fI-THr"/>
<outlet property="fileName" destination="Dho-UV-6Ev" id="Iro-II-w8a"/>
<outlet property="fileTransferProgress" destination="USm-wC-GvG" id="POt-YD-NCG"/>
<outlet property="finalImage" destination="gzv-K4-5OL" id="YIw-kM-Ld6"/>
<outlet property="imageGestureRecognizer" destination="aDF-hC-ddO" id="2jh-Rr-eKk"/>
@ -27,8 +27,8 @@
<outlet property="imdmIcon" destination="LPj-VT-0fH" id="yYh-pv-EJs"/>
<outlet property="imdmLabel" destination="44j-me-Iqi" id="m5R-Dm-V8g"/>
<outlet property="messageImageView" destination="yMW-cT-bpU" id="MNr-F2-abQ"/>
<outlet property="openRecognizer" destination="9ss-Qo-Kkt" id="sJZ-Fa-wFh"/>
<outlet property="playButton" destination="Mna-y7-VAE" id="aOC-UN-xLJ"/>
<outlet property="openRecognizer" destination="NYA-II-xYn" id="pVM-vD-4Rg"/>
<outlet property="playButton" destination="cvc-tl-Pcf" id="eKJ-2T-LUl"/>
<outlet property="resendRecognizer" destination="5ZI-Ip-lGl" id="G2r-On-6mV"/>
<outlet property="statusInProgressSpinner" destination="Eab-ND-ix3" id="UuC-eY-MSf"/>
<outlet property="totalView" destination="8I3-n2-0kS" id="aa8-j9-saW"/>
@ -72,11 +72,11 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxX="YES" heightSizable="YES" flexibleMaxY="YES"/>
<gestureRecognizers/>
</imageView>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="Label" textAlignment="center" lineBreakMode="middleTruncation" adjustsFontSizeToFit="NO" id="Dqi-dR-naZ" userLabel="fileName">
<rect key="frame" x="9" y="18" width="229" height="40"/>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" text="Label" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Dho-UV-6Ev" userLabel="fileName">
<rect key="frame" x="0.0" y="0.0" width="200" height="50"/>
<autoresizingMask key="autoresizingMask"/>
<color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<fontDescription key="fontDescription" type="system" pointSize="10"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
@ -113,25 +113,9 @@
<action selector="onCancelClick:" destination="-1" eventType="touchUpInside" id="D9y-vf-I4Y"/>
</connections>
</button>
<button opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="Mna-y7-VAE" userLabel="playButton" customClass="UIRoundBorderedButton">
<rect key="frame" x="66" y="5" width="115" height="27"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMinY="YES"/>
<accessibility key="accessibilityConfiguration" label="PLAY"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<state key="normal" title="PLAY" backgroundImage="color_I.png">
<color key="titleColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</state>
<state key="highlighted" backgroundImage="color_M.png"/>
<connections>
<action selector="onPlayClick:" destination="-1" eventType="touchUpInside" id="72M-jV-kHF"/>
</connections>
</button>
</subviews>
</view>
</subviews>
<connections>
<outletCollection property="gestureRecognizers" destination="9ss-Qo-Kkt" appends="YES" id="fEu-Vc-75u"/>
</connections>
</view>
<view contentMode="scaleToFill" misplaced="YES" id="VYJ-RC-Jmg">
<rect key="frame" x="8" y="55" width="349" height="213"/>
@ -142,9 +126,23 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<gestureRecognizers/>
</imageView>
<button opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="cvc-tl-Pcf" userLabel="playButton" customClass="UIRoundBorderedButton">
<rect key="frame" x="125" y="93" width="50" height="25"/>
<autoresizingMask key="autoresizingMask"/>
<accessibility key="accessibilityConfiguration" label="Cancel"/>
<fontDescription key="fontDescription" type="system" pointSize="15"/>
<state key="normal" title="PLAY" backgroundImage="color_I.png">
<color key="titleColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</state>
<state key="highlighted" backgroundImage="color_M.png"/>
<connections>
<action selector="onPlayClick:" destination="-1" eventType="touchUpInside" id="B4y-PJ-4tO"/>
</connections>
</button>
</subviews>
<connections>
<outletCollection property="gestureRecognizers" destination="aDF-hC-ddO" appends="YES" id="lKJ-ra-dwR"/>
<outletCollection property="gestureRecognizers" destination="NYA-II-xYn" appends="YES" id="fK6-ld-zOX"/>
</connections>
</view>
<imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="color_A.png" id="6dA-3U-OPW" userLabel="bottomBarColor">
@ -193,9 +191,9 @@
<action selector="onImageClick:" destination="-1" id="feN-LT-89b"/>
</connections>
</tapGestureRecognizer>
<tapGestureRecognizer id="9ss-Qo-Kkt" userLabel="openClick">
<tapGestureRecognizer id="NYA-II-xYn" userLabel="openClick">
<connections>
<action selector="onOpenClick:" destination="-1" id="JSH-cf-C7G"/>
<action selector="onOpenClick:" destination="-1" id="XaJ-Or-uQQ"/>
</connections>
</tapGestureRecognizer>
</objects>

View file

@ -29,7 +29,7 @@
@implementation UIChatBubblePhotoCell {
FileTransferDelegate *_ftd;
CGSize imageSize, bubbleSize;
CGSize imageSize, bubbleSize, videoDefaultSize;
int actualAvailableWidth;
ChatConversationTableView *chatTableView;
//CGImageRef displayedImage;
@ -55,6 +55,7 @@
[self addSubview:sub];
chatTableView = VIEW(ChatConversationView).tableController;
actualAvailableWidth = chatTableView.tableView.frame.size.width;
videoDefaultSize = CGSizeMake(320, 240);
}
return self;
}
@ -80,7 +81,6 @@
if (amessage) {
const LinphoneContent *c = linphone_chat_message_get_file_transfer_information(amessage);
if (c) {
const char *name = linphone_content_get_name(c);
for (FileTransferDelegate *aftd in [LinphoneManager.instance fileTransferDelegates]) {
if (linphone_chat_message_get_file_transfer_information(aftd.message) &&
@ -98,12 +98,7 @@
[super setChatMessage:amessage];
}
- (void) loadAsset:(ALAsset*) asset {
UIImage *thumb = [[UIImage alloc] initWithCGImage:[asset thumbnail]];
ALAssetRepresentation *representation = [asset defaultRepresentation];
imageSize = [UIChatBubbleTextCell getMediaMessageSizefromOriginalSize:[representation dimensions] withWidth:chatTableView.tableView.frame.size.width];
CGImageRef tmpImg = [self cropImageFromRepresentation:representation];
UIImage *image = [[UIImage alloc] initWithCGImage:tmpImg];
- (void) loadImageAsset:(ALAsset*) asset thumb:(UIImage *)thumb image:(UIImage *)image {
dispatch_async(dispatch_get_main_queue(), ^{
[_finalImage setImage:image];
[_messageImageView setImage:thumb];
@ -111,16 +106,23 @@
[_messageImageView stopLoading];
_messageImageView.hidden = YES;
_imageGestureRecognizer.enabled = YES;
//_cancelButton.hidden = _fileTransferProgress.hidden = _downloadButton.hidden = YES;
_finalImage.hidden = NO;
});
}
- (void) loadAsset:(ALAsset*) asset {
UIImage *thumb = [[UIImage alloc] initWithCGImage:[asset thumbnail]];
ALAssetRepresentation *representation = [asset defaultRepresentation];
imageSize = [UIChatBubbleTextCell getMediaMessageSizefromOriginalSize:[representation dimensions] withWidth:chatTableView.tableView.frame.size.width];
CGImageRef tmpImg = [self cropImageFromRepresentation:representation];
UIImage *image = [[UIImage alloc] initWithCGImage:tmpImg];
[self loadImageAsset:nil thumb:thumb image:image];
}
- (void) loadVideoAsset: (AVAsset *) asset {
// Calculate a time for the snapshot - I'm using the half way mark.
CMTime duration = [asset duration];
CMTime snapshot = CMTimeMake(duration.value / 2, duration.timescale);
// Create a generator and copy image at the time.
// I'm not capturing the actual time or an error.
AVAssetImageGenerator *generator =
@ -129,22 +131,28 @@
actualTime:nil
error:nil];
// Make a UIImage and release the CGImage.
UIImage *image = [UIImage imageWithCGImage:imageRef];
UIImage *thumb = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
dispatch_async(dispatch_get_main_queue(), ^{
[_messageImageView setImage:image];
[_messageImageView stopLoading];
_messageImageView.hidden = NO;
});
UIGraphicsBeginImageContext(videoDefaultSize);
[thumb drawInRect:CGRectMake(0, 0, videoDefaultSize.width, videoDefaultSize.height)];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[self loadImageAsset:nil thumb:thumb image:image];
// put the play button in the top
CGRect newFrame = _playButton.frame;
newFrame.origin.x = _finalImage.frame.origin.x/2;
newFrame.origin.y = _finalImage.frame.origin.y/2;
_playButton.frame = newFrame;
}
- (void) loadFileAsset {
dispatch_async(dispatch_get_main_queue(), ^{
CGRect newFrame = _totalView.frame;
newFrame.origin.x = newFrame.origin.y = 0;
_fileName.frame = newFrame;
_fileName.hidden = NO;
_imageGestureRecognizer.enabled = NO;
_openRecognizer.enabled = YES;
});
}
@ -155,7 +163,6 @@
}
[super update];
LinphoneChatMessageState state = linphone_chat_message_get_state(self.message);
const char *url = linphone_chat_message_get_external_body_url(self.message);
BOOL is_external =
(url && (strstr(url, "http") == url)) || linphone_chat_message_get_file_transfer_information(self.message);
@ -165,21 +172,25 @@
BOOL fullScreenImage = NO;
assert(is_external || localImage || localVideo || localFile);
if (localImage) {
// image is being saved on device - just wait for it
if ([localImage isEqualToString:@"saving..."]) {
if (!(localImage || localVideo || localFile)) {
_playButton.hidden = YES;
_fileName.hidden = YES;
_messageImageView.hidden = _cancelButton.hidden = (_ftd.message == nil);
_downloadButton.hidden = !_cancelButton.hidden;
_fileTransferProgress.hidden = NO;
} else {
// file is being saved on device - just wait for it
if ([localImage isEqualToString:@"saving..."] || [localVideo isEqualToString:@"saving..."] || [localFile isEqualToString:@"saving..."]) {
_cancelButton.hidden = _fileTransferProgress.hidden = _downloadButton.hidden = _playButton.hidden = _fileName.hidden = YES;
fullScreenImage = YES;
} else {
if (localImage) {
// we did not load the image yet, so start doing so
if (_messageImageView.image == nil) {
NSURL *imageUrl = [NSURL URLWithString:localImage];
[_messageImageView startLoading];
__block LinphoneChatMessage *achat = self.message;
[LinphoneManager.instance.photoLibrary assetForURL:imageUrl
resultBlock:^(ALAsset *asset) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, (unsigned long)NULL),
^(void) {
[LinphoneManager.instance.photoLibrary assetForURL:imageUrl resultBlock:^(ALAsset *asset) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, (unsigned long)NULL), ^(void) {
if (achat != self.message) // Avoid glitch and scrolling
return;
@ -203,11 +214,26 @@
}];
}
});
}
failureBlock:^(NSError *error) {
} failureBlock:^(NSError *error) {
LOGE(@"Can't read image");
}];
}
} else if (localVideo) {
if (_messageImageView.image == nil) {
[_messageImageView startLoading];
// read video from Documents
NSString *filePath = [LinphoneManager documentFile:localVideo];
NSURL *url = [NSURL fileURLWithPath:filePath];
AVAsset *asset = [AVAsset assetWithURL:url];
if (asset)
[self loadVideoAsset:asset];
}
} else if (localFile) {
NSString *text = [NSString stringWithFormat:@"📎 %@",localFile];
_fileName.text = text;
[self loadFileAsset];
}
// we are uploading the image
if (_ftd.message != nil) {
_cancelButton.hidden = NO;
@ -216,71 +242,13 @@
_playButton.hidden = YES;
_fileName.hidden = YES;
} else {
_cancelButton.hidden = _fileTransferProgress.hidden = _downloadButton.hidden = _playButton.hidden = _fileName.hidden = YES;
_cancelButton.hidden = _fileTransferProgress.hidden = _downloadButton.hidden = YES;
fullScreenImage = YES;
_playButton.hidden = localVideo ? NO : YES;
_fileName.hidden = localFile ? NO : YES;
}
}
// we must download the image: either it has already started (show cancel button) or not yet (show download
// button)
} else if(localVideo) {
if ([localVideo isEqualToString:@"saving..."]) {
_cancelButton.hidden = _fileTransferProgress.hidden = _downloadButton.hidden = _playButton.hidden = _fileName.hidden = YES;
fullScreenImage = YES;
} else {
if (_messageImageView.image == nil) {
[_messageImageView startLoading];
NSURL *url = [NSURL fileURLWithPath:localVideo];
AVAsset *asset = [AVAsset assetWithURL:url];
if (asset)
[self loadVideoAsset:asset];
//TODO fail
else return;
}
// we did not load the video yet, so start doing so
// we are uploading the video
if (_ftd.message != nil && state != LinphoneChatMessageStateNotDelivered && state != LinphoneChatMessageStateDisplayed) {
_cancelButton.hidden = NO;
_fileTransferProgress.hidden = NO;
_downloadButton.hidden = YES;
_playButton.hidden = YES;
_fileName.hidden = YES;
} else {
_cancelButton.hidden = _fileTransferProgress.hidden = _downloadButton.hidden = _fileName.hidden = YES;
_playButton.hidden = NO;
fullScreenImage = YES;
}
}
} else if(localFile){
if ([localFile isEqualToString:@"saving..."]) {
_cancelButton.hidden = _fileTransferProgress.hidden = _downloadButton.hidden = _playButton.hidden = _fileName.hidden = YES;
fullScreenImage = YES;
} else {
if (_ftd.message != nil && state != LinphoneChatMessageStateNotDelivered && state != LinphoneChatMessageStateDisplayed) {
_cancelButton.hidden = NO;
_fileTransferProgress.hidden = NO;
_downloadButton.hidden = YES;
_playButton.hidden = YES;
_fileName.hidden = YES;
} else {
NSString *text = [[NSURL fileURLWithPath:localFile] lastPathComponent];
_fileName.text = text;
_cancelButton.hidden = _fileTransferProgress.hidden = _downloadButton.hidden =
_playButton.hidden = YES;
fullScreenImage = YES;
[self loadFileAsset];
_openRecognizer.enabled = YES;
}
}
}else{
_playButton.hidden = _fileName.hidden = YES;
_messageImageView.hidden = _cancelButton.hidden = (_ftd.message == nil);
_downloadButton.hidden = !_cancelButton.hidden;
_fileTransferProgress.hidden = NO;
}
// resize image so that it take the full bubble space available
CGRect newFrame = _totalView.frame;
newFrame.origin.x = newFrame.origin.y = 0;
@ -290,6 +258,15 @@
_messageImageView.frame = newFrame;
}
- (void)fileErrorBlock {
DTActionSheet *sheet = [[DTActionSheet alloc] initWithTitle:NSLocalizedString(@"Can't open this file", nil)];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[sheet addCancelButtonWithTitle:NSLocalizedString(@"OK", nil) block:nil];
dispatch_async(dispatch_get_main_queue(), ^{
[sheet showInView:PhoneMainView.instance.view];
});
});
}
- (IBAction)onDownloadClick:(id)event {
[_ftd cancel];
@ -304,28 +281,32 @@
- (IBAction)onPlayClick:(id)sender {
NSString *localVideo = [LinphoneManager getMessageAppDataForKey:@"localvideo" inMessage:self.message];
NSString *filePath = [LinphoneManager documentFile:localVideo];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL * fileURL= [[NSURL alloc] initFileURLWithPath:localVideo];
if ([fileManager fileExistsAtPath:filePath]) {
// create a player view controller
AVPlayer *player = [AVPlayer playerWithURL:fileURL];
AVPlayer *player = [AVPlayer playerWithURL:[[NSURL alloc] initFileURLWithPath:filePath]];
AVPlayerViewController *controller = [[AVPlayerViewController alloc] init];
[PhoneMainView.instance presentViewController:controller animated:YES completion:nil];
controller.player = player;
[player play];
_cancelButton.hidden = YES;
_downloadButton.hidden = YES;
_playButton.hidden = NO;
_fileTransferProgress.hidden = YES;
} else {
[self fileErrorBlock];
}
}
- (IBAction)onOpenClick:(id)event {
NSString *localFile = [LinphoneManager getMessageAppDataForKey:@"localfile" inMessage:self.message];
NSString *filePath = [LinphoneManager documentFile:localFile];
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:filePath]) {
ChatConversationView *view = VIEW(ChatConversationView);
[view openResults:localFile];
[view openResults:filePath];
} else {
[self fileErrorBlock];
}
}

View file

@ -234,6 +234,7 @@
NSNumber *uploadQuality =[LinphoneManager getMessageAppDataForKey:@"uploadQuality" inMessage:_message];
NSString *localVideo = [LinphoneManager getMessageAppDataForKey:@"localvideo" inMessage:_message];
NSString *localFile = [LinphoneManager getMessageAppDataForKey:@"localfile" inMessage:_message];
NSString *fileName = localVideo ? localVideo : localFile;
NSURL *imageUrl = [NSURL URLWithString:localImage];
[self onDelete];
if(localImage){
@ -248,12 +249,10 @@
failureBlock:^(NSError *error) {
LOGE(@"Can't read image");
}];
} else if(localVideo) {
[_chatRoomDelegate startFileUpload:[NSData dataWithContentsOfFile:localVideo] withUrl:[NSURL URLWithString:localVideo]];
} else {
[_chatRoomDelegate startFileUpload:[NSData dataWithContentsOfFile:localFile] withUrl:[NSURL URLWithString:localFile]];
} else if(fileName) {
NSString *filePath = [LinphoneManager documentFile:fileName];
[_chatRoomDelegate startFileUpload:[NSData dataWithContentsOfFile:filePath] withUrl:[NSURL URLWithString:filePath]];
}
} else {
[self onDelete];
double delayInSeconds = 0.4;
@ -319,6 +318,7 @@ static const CGFloat CELL_MESSAGE_Y_MARGIN = 52; // 44;
+ (CGSize)ViewHeightForMessage:(LinphoneChatMessage *)chat withWidth:(int)width {
NSString *messageText = [UIChatBubbleTextCell TextMessageForChat:chat];
static UIFont *messageFont = nil;
if (!messageFont) {
UIChatBubbleTextCell *cell =
[[UIChatBubbleTextCell alloc] initWithIdentifier:NSStringFromClass(UIChatBubbleTextCell.class)];
@ -335,6 +335,16 @@ static const CGFloat CELL_MESSAGE_Y_MARGIN = 52; // 44;
font:messageFont];
} else {
NSString *localImage = [LinphoneManager getMessageAppDataForKey:@"localimage" inMessage:chat];
NSString *localFile = [LinphoneManager getMessageAppDataForKey:@"localfile" inMessage:chat];
NSString *localVideo = [LinphoneManager getMessageAppDataForKey:@"localvideo" inMessage:chat];
if(localFile) {
CGSize fileSize = CGSizeMake(200, 50);
size = [self getMediaMessageSizefromOriginalSize:fileSize withWidth:width];
} else if (localVideo) {
CGSize videoSize = CGSizeMake(320, 240);
size = [self getMediaMessageSizefromOriginalSize:videoSize withWidth:width];
} else {
NSURL *imageUrl = [NSURL URLWithString:localImage];
__block CGSize originalImageSize = CGSizeMake(0, 0);
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
@ -353,8 +363,10 @@ static const CGFloat CELL_MESSAGE_Y_MARGIN = 52; // 44;
size = [self getMediaMessageSizefromOriginalSize:originalImageSize withWidth:width];
//This fixes the image being too small. I think the issue comes form the fact that the display is retina. This should probably be changed in the future.
}
size.height += CELL_MESSAGE_X_MARGIN;
}
size.width = MAX(size.width + CELL_MESSAGE_X_MARGIN, CELL_MIN_WIDTH);
size.height = MAX(size.height + CELL_MESSAGE_Y_MARGIN, CELL_MIN_HEIGHT);
return size;

View file

@ -116,12 +116,9 @@ static void linphone_iphone_file_transfer_recv(LinphoneChatMessage *message, con
} else {
[[LinphoneManager.instance fileTransferDelegates] removeObject:thiz];
NSString *key = @"localvideo";
NSString *key = [fileType isEqualToString:@"file"] ? @"localfile" : @"localvideo";
NSString *name =[NSString stringWithUTF8String:linphone_content_get_name(content)];
if([fileType isEqualToString:@"file"]){
key = @"localfile";
}
[LinphoneManager setValueInMessageAppData:@"saving..." forKey:key inMessage:message];
//write file to path
@ -131,7 +128,7 @@ static void linphone_iphone_file_transfer_recv(LinphoneChatMessage *message, con
contents:thiz.data
attributes:nil];
[LinphoneManager setValueInMessageAppData:filePath forKey:key inMessage:message];
[LinphoneManager setValueInMessageAppData:name forKey:key inMessage:message];
[NSNotificationCenter.defaultCenter
postNotificationName:kLinphoneFileTransferRecvUpdate
@ -199,56 +196,14 @@ static LinphoneBuffer *linphone_iphone_file_transfer_send(LinphoneChatMessage *m
return NULL;
}
- (void)upload:(UIImage *)image withURL:(NSURL *)url forChatRoom:(LinphoneChatRoom *)chatRoom withQuality:(float)quality {
[LinphoneManager.instance.fileTransferDelegates addObject:self];
LinphoneContent *content = linphone_core_create_content(linphone_chat_room_get_core(chatRoom));
_data = [NSMutableData dataWithData:UIImageJPEGRepresentation(image, quality)];
linphone_content_set_type(content, "image");
linphone_content_set_subtype(content, "jpeg");
linphone_content_set_name(
content, [[NSString stringWithFormat:@"%li-%f.jpg", (long)image.hash, [NSDate timeIntervalSinceReferenceDate]]
UTF8String]);
linphone_content_set_size(content, _data.length);
_message = linphone_chat_room_create_file_transfer_message(chatRoom, content);
linphone_content_unref(content);
linphone_chat_message_cbs_set_file_transfer_send(linphone_chat_message_get_callbacks(_message),
linphone_iphone_file_transfer_send);
if (url) {
// internal url is saved in the appdata for display and later save
[LinphoneManager setValueInMessageAppData:[url absoluteString] forKey:@"localimage" inMessage:_message];
[LinphoneManager setValueInMessageAppData:[NSNumber numberWithFloat:quality] forKey:@"uploadQuality" inMessage:_message];
}
LOGI(@"%p Uploading content from message %p", self, _message);
linphone_chat_room_send_chat_message(chatRoom, _message);
if (linphone_core_lime_enabled(LC) == LinphoneLimeMandatory && !linphone_chat_room_lime_available(chatRoom)) {
[LinphoneManager.instance alertLIME:chatRoom];
}
}
- (void)uploadFile:(NSData *)data forChatRoom:(LinphoneChatRoom *)chatRoom withUrl:(NSURL *)url {
- (void)uploadData:(NSData *)data forChatRoom:(LinphoneChatRoom *)chatRoom type:(NSString *)type subtype:(NSString *)subtype name:(NSString *)name key:(NSString *)key keyData:(NSString *)keyData qualityData:(NSNumber *)qualityData {
[LinphoneManager.instance.fileTransferDelegates addObject:self];
LinphoneContent *content = linphone_core_create_content(linphone_chat_room_get_core(chatRoom));
_data = [NSMutableData dataWithData:data];
NSString *filePath = [LinphoneManager documentFile:[url lastPathComponent]];
[[NSFileManager defaultManager] createFileAtPath:filePath
contents:_data
attributes:nil];
NSString *key = @"localvideo";
if(![[url pathExtension]isEqualToString:@"MOV"]) {
linphone_content_set_type(content, "file");
key = @"localfile";
}
linphone_content_set_name(content, [[url lastPathComponent] UTF8String]);
linphone_content_set_type(content, [type UTF8String]);
linphone_content_set_subtype(content, [subtype UTF8String]);
linphone_content_set_name(content, [name UTF8String]);
linphone_content_set_size(content, _data.length);
_message = linphone_chat_room_create_file_transfer_message(chatRoom, content);
@ -257,7 +212,9 @@ static LinphoneBuffer *linphone_iphone_file_transfer_send(LinphoneChatMessage *m
linphone_chat_message_cbs_set_file_transfer_send(linphone_chat_message_get_callbacks(_message),
linphone_iphone_file_transfer_send);
[LinphoneManager setValueInMessageAppData:filePath forKey:key inMessage:_message];
// internal url is saved in the appdata for display and later save
[LinphoneManager setValueInMessageAppData:keyData forKey:key inMessage:_message];
[LinphoneManager setValueInMessageAppData:qualityData forKey:@"uploadQuality" inMessage:_message];
LOGI(@"%p Uploading content from message %p", self, _message);
linphone_chat_room_send_chat_message(chatRoom, _message);
@ -267,6 +224,28 @@ static LinphoneBuffer *linphone_iphone_file_transfer_send(LinphoneChatMessage *m
}
}
- (void)upload:(UIImage *)image withURL:(NSURL *)url forChatRoom:(LinphoneChatRoom *)chatRoom withQuality:(float)quality {
NSString *name = [NSString stringWithFormat:@"%li-%f.jpg", (long)image.hash, [NSDate timeIntervalSinceReferenceDate]];
if (url)
[self uploadData:UIImageJPEGRepresentation(image, quality) forChatRoom:chatRoom type:@"image" subtype:@"jpeg" name:name key:@"localimage" keyData:[url absoluteString] qualityData:[NSNumber numberWithFloat:quality]];
else
[self uploadData:UIImageJPEGRepresentation(image, quality) forChatRoom:chatRoom type:@"image" subtype:@"jpeg" name:name key:@"localimage" keyData:nil qualityData:nil];
}
- (void)uploadFile:(NSData *)data forChatRoom:(LinphoneChatRoom *)chatRoom withUrl:(NSURL *)url {
NSString *name = [url lastPathComponent];
//save file to Documents
NSString *filePath = [LinphoneManager documentFile:name];
[[NSFileManager defaultManager] createFileAtPath:filePath
contents:[NSMutableData dataWithData:data]
attributes:nil];
if ([[url pathExtension]isEqualToString:@"MOV"])
[self uploadData:data forChatRoom:chatRoom type:nil subtype:nil name:name key:@"localvideo" keyData:name qualityData:nil];
else
[self uploadData:data forChatRoom:chatRoom type:@"file" subtype:nil name:name key:@"localfile" keyData:name qualityData:nil];
}
- (BOOL)download:(LinphoneChatMessage *)message {

View file

@ -32,7 +32,7 @@ static NSString* groupName = @"group.belledonne-communications.linphone";
} else if ([provider hasItemConformingToTypeIdentifier:@"public.url"]) {
[self loadItem:provider typeIdentifier:@"public.url" defaults:defaults key:@"web"];
} else if ([provider hasItemConformingToTypeIdentifier:@"public.movie"]) {
[self loadItem:provider typeIdentifier:@"public.movie" defaults:defaults key:@"file"];
[self loadItem:provider typeIdentifier:@"public.movie" defaults:defaults key:@"mov"];
} else if ([provider hasItemConformingToTypeIdentifier:@"public.plain-text"]) {
[self loadItem:provider typeIdentifier:@"public.plain-text" defaults:defaults key:@"text"];
} else if ([provider hasItemConformingToTypeIdentifier:@"com.adobe.pdf"]) {