mirror of
https://gitlab.linphone.org/BC/public/linphone-iphone.git
synced 2026-01-29 17:29:20 +00:00
Auto layout almost done
This commit is contained in:
parent
e20ac86e6a
commit
d20ac76f2e
6 changed files with 82 additions and 101 deletions
|
|
@ -40,7 +40,6 @@
|
|||
|
||||
@property(nonatomic) LinphoneChatRoom *chatRoom;
|
||||
@property(nonatomic, strong) id<ChatConversationDelegate> chatRoomDelegate;
|
||||
@property(nonatomic) NSMutableDictionary<NSIndexPath *, NSNumber *> *photoSizesDict;
|
||||
|
||||
- (void)addEventEntry:(LinphoneEventLog *)event;
|
||||
- (void)scrollToBottom:(BOOL)animated;
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@
|
|||
|
||||
- (void)viewWillAppear:(BOOL)animated {
|
||||
[super viewWillAppear:animated];
|
||||
self.photoSizesDict = [NSMutableDictionary dictionary];
|
||||
self.tableView.accessibilityIdentifier = @"ChatRoom list";
|
||||
}
|
||||
|
||||
|
|
@ -179,15 +178,11 @@
|
|||
kCellId = NSStringFromClass(UIChatBubblePhotoCell.class);
|
||||
else
|
||||
kCellId = NSStringFromClass(UIChatBubbleTextCell.class);
|
||||
|
||||
UIChatBubbleTextCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellId];
|
||||
if (!cell) {
|
||||
cell = [[NSClassFromString(kCellId) alloc] initWithIdentifier:kCellId];
|
||||
cell.indexInTable = indexPath;
|
||||
}
|
||||
//if (linphone_chat_message_get_file_transfer_information(chat) || linphone_chat_message_get_external_body_url(chat)) {
|
||||
// UIChatBubblePhotoCell *photoCell = (UIChatBubblePhotoCell *) cell;
|
||||
// [photoCell unloadImages];
|
||||
//}
|
||||
[cell setEvent:event];
|
||||
if (chat)
|
||||
[cell update];
|
||||
|
|
@ -220,14 +215,9 @@
|
|||
if (linphone_event_log_get_type(event) == LinphoneEventLogTypeConferenceChatMessage) {
|
||||
LinphoneChatMessage *chat = linphone_event_log_get_chat_message(event);
|
||||
|
||||
if ((linphone_chat_message_get_file_transfer_information(chat) || linphone_chat_message_get_external_body_url(chat)) && [_photoSizesDict objectForKey:indexPath]) {
|
||||
return [_photoSizesDict objectForKey:indexPath].doubleValue;
|
||||
}
|
||||
|
||||
return [UIChatBubbleTextCell ViewHeightForMessage:chat withWidth:self.view.frame.size.width].height;
|
||||
} else {
|
||||
return [UIChatNotifiedEventCell height];
|
||||
}
|
||||
return [UIChatNotifiedEventCell height];
|
||||
}
|
||||
|
||||
- (void) tableView:(UITableView *)tableView deleteRowAtIndex:(NSIndexPath *)indexPath {
|
||||
|
|
|
|||
|
|
@ -85,13 +85,6 @@
|
|||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMinY="YES"/>
|
||||
<accessibility key="accessibilityConfiguration" label="Delivery failed"/>
|
||||
</imageView>
|
||||
<imageView hidden="YES" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" id="gzv-K4-5OL" userLabel="finalImage">
|
||||
<rect key="frame" x="7" y="55" width="350" height="211"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<connections>
|
||||
<outletCollection property="gestureRecognizers" destination="aDF-hC-ddO" appends="YES" id="ICw-5U-vcc"/>
|
||||
</connections>
|
||||
</imageView>
|
||||
<view contentMode="scaleToFill" misplaced="YES" id="8I3-n2-0kS" userLabel="view">
|
||||
<rect key="frame" x="39" y="55" width="298" height="190"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxX="YES" heightSizable="YES" flexibleMaxY="YES"/>
|
||||
|
|
@ -100,9 +93,6 @@
|
|||
<rect key="frame" x="0.0" y="0.0" width="298" height="122"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" flexibleMaxX="YES" heightSizable="YES" flexibleMaxY="YES"/>
|
||||
<gestureRecognizers/>
|
||||
<connections>
|
||||
<outletCollection property="gestureRecognizers" destination="aDF-hC-ddO" appends="YES" id="7kE-0j-s1g"/>
|
||||
</connections>
|
||||
</imageView>
|
||||
<view contentMode="scaleToFill" id="GmN-7v-uuO" userLabel="imageSubView">
|
||||
<rect key="frame" x="0.0" y="128" width="297" height="62"/>
|
||||
|
|
@ -141,6 +131,20 @@
|
|||
</view>
|
||||
</subviews>
|
||||
</view>
|
||||
<view contentMode="scaleToFill" misplaced="YES" id="VYJ-RC-Jmg">
|
||||
<rect key="frame" x="8" y="55" width="349" height="213"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<imageView hidden="YES" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" misplaced="YES" id="gzv-K4-5OL" userLabel="finalImage">
|
||||
<rect key="frame" x="0.0" y="0.0" width="349" height="213"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<gestureRecognizers/>
|
||||
<connections>
|
||||
<outletCollection property="gestureRecognizers" destination="aDF-hC-ddO" appends="YES" id="3P2-uH-W2N"/>
|
||||
</connections>
|
||||
</imageView>
|
||||
</subviews>
|
||||
</view>
|
||||
</subviews>
|
||||
<connections>
|
||||
<outletCollection property="gestureRecognizers" destination="5ZI-Ip-lGl" appends="YES" id="1iY-46-rRR"/>
|
||||
|
|
@ -152,16 +156,16 @@
|
|||
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
|
||||
<point key="canvasLocation" x="-73.5" y="246.5"/>
|
||||
</view>
|
||||
<tapGestureRecognizer id="aDF-hC-ddO" userLabel="imageClick">
|
||||
<connections>
|
||||
<action selector="onImageClick:" destination="-1" id="feN-LT-89b"/>
|
||||
</connections>
|
||||
</tapGestureRecognizer>
|
||||
<tapGestureRecognizer id="5ZI-Ip-lGl" userLabel="resendClick">
|
||||
<connections>
|
||||
<action selector="onResendClick:" destination="-1" id="XOF-AF-Hes"/>
|
||||
</connections>
|
||||
</tapGestureRecognizer>
|
||||
<tapGestureRecognizer id="aDF-hC-ddO" userLabel="imageClick">
|
||||
<connections>
|
||||
<action selector="onImageClick:" destination="-1" id="feN-LT-89b"/>
|
||||
</connections>
|
||||
</tapGestureRecognizer>
|
||||
</objects>
|
||||
<resources>
|
||||
<image name="avatar.png" width="259" height="259"/>
|
||||
|
|
|
|||
|
|
@ -26,10 +26,10 @@
|
|||
|
||||
@implementation UIChatBubblePhotoCell {
|
||||
FileTransferDelegate *_ftd;
|
||||
bool isAssetLoaded;
|
||||
CGSize imageSize, bubbleSize;
|
||||
int actualAvailableWidth;
|
||||
CGImageRef displayedImage;
|
||||
ChatConversationTableView *chatTableView;
|
||||
//CGImageRef displayedImage;
|
||||
}
|
||||
|
||||
#pragma mark - Lifecycle Functions
|
||||
|
|
@ -48,14 +48,11 @@
|
|||
break;
|
||||
}
|
||||
}
|
||||
// Useless
|
||||
//[self setFrame:CGRectMake(0, 0, 5, 100)];
|
||||
//self.autoresizesSubviews = TRUE;
|
||||
[self setFrame:CGRectMake(0, 0, 5, 100)];
|
||||
[self addSubview:sub];
|
||||
isAssetLoaded = FALSE;
|
||||
actualAvailableWidth = self.frame.size.width;
|
||||
[self setBubbleSize];
|
||||
LOGD(@"ZBOUB");
|
||||
//LOGD(@"ZBOUB");
|
||||
chatTableView = VIEW(ChatConversationView).tableController;
|
||||
actualAvailableWidth = chatTableView.tableView.frame.size.width;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
|
@ -67,20 +64,20 @@
|
|||
|
||||
super.event = event;
|
||||
[self setChatMessage:linphone_event_log_get_chat_message(event)];
|
||||
[VIEW(ChatConversationView).tableController.photoSizesDict setObject:@(bubbleSize.height) forKey:self.indexInTable];
|
||||
}
|
||||
|
||||
- (void)setChatMessage:(LinphoneChatMessage *)amessage {
|
||||
_imageGestureRecognizer.enabled = NO;
|
||||
_messageImageView.image = nil;
|
||||
//_finalImage.image = nil;
|
||||
//_finalImage. = TRUE;
|
||||
_finalImage.image = nil;
|
||||
_finalImage.hidden = TRUE;
|
||||
_fileTransferProgress.progress = 0;
|
||||
[self disconnectFromFileDelegate];
|
||||
|
||||
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) &&
|
||||
|
|
@ -99,26 +96,21 @@
|
|||
}
|
||||
|
||||
- (void) loadAsset:(ALAsset*) asset {
|
||||
if (isAssetLoaded) return;
|
||||
LOGD(@"BITEENBOIS");
|
||||
isAssetLoaded = TRUE;
|
||||
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];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
ALAssetRepresentation *representation = [asset defaultRepresentation];
|
||||
imageSize = [self getMediaMessageSizefromOriginalSize:[representation dimensions]];
|
||||
displayedImage = [self cropImageFromRepresentation:representation withNewSize:imageSize];
|
||||
UIImage *image = [[UIImage alloc] initWithCGImage:displayedImage];
|
||||
[self setBubbleSize];
|
||||
[_finalImage setImage:image];
|
||||
[_messageImageView setImage:thumb];
|
||||
[_messageImageView setFullImageUrl:asset];
|
||||
[_messageImageView stopLoading];
|
||||
_messageImageView.hidden = YES;
|
||||
_imageGestureRecognizer.enabled = YES;
|
||||
_cancelButton.hidden = _fileTransferProgress.hidden = _downloadButton.hidden = YES;
|
||||
//_cancelButton.hidden = _fileTransferProgress.hidden = _downloadButton.hidden = YES;
|
||||
_finalImage.hidden = NO;
|
||||
ChatConversationTableView *tableView = VIEW(ChatConversationView).tableController;
|
||||
[tableView.photoSizesDict setObject:@(bubbleSize.height) forKey:self.indexInTable];
|
||||
[tableView.tableView beginUpdates];
|
||||
[tableView.tableView endUpdates];
|
||||
LOGD(@"ZBOUB");
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -128,7 +120,6 @@
|
|||
return;
|
||||
}
|
||||
[super update];
|
||||
|
||||
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);
|
||||
|
|
@ -202,8 +193,7 @@
|
|||
if (!fullScreenImage) {
|
||||
newFrame.size.height -= _imageSubView.frame.size.height;
|
||||
}
|
||||
//newFrame.size.height *= 10;
|
||||
//_messageImageView.frame = newFrame;
|
||||
_messageImageView.frame = newFrame;
|
||||
}
|
||||
|
||||
- (IBAction)onDownloadClick:(id)event {
|
||||
|
|
@ -326,21 +316,16 @@
|
|||
return imgRef;
|
||||
}
|
||||
|
||||
|
||||
static const CGFloat CELL_MIN_HEIGHT = 60.0f;
|
||||
static const CGFloat CELL_MIN_WIDTH = 190.0f;
|
||||
static const CGFloat CELL_IMAGE_HEIGHT = 100.0f;
|
||||
static const CGFloat CELL_IMAGE_WIDTH = 100.0f;
|
||||
static const CGFloat CELL_MESSAGE_Y_MARGIN = 0; // 44;
|
||||
|
||||
- (void)layoutSubviews {
|
||||
[super layoutSubviews];
|
||||
if (!isAssetLoaded) return;
|
||||
//if (!isAssetLoaded) return;
|
||||
UITableView *tableView = VIEW(ChatConversationView).tableController.tableView;
|
||||
BOOL is_outgoing = linphone_chat_message_is_outgoing(super.message);
|
||||
CGRect bubbleFrame = super.bubbleView.frame;
|
||||
int origin_x;
|
||||
|
||||
bubbleSize = [UIChatBubbleTextCell ViewSizeForMessage:[self message] withWidth:chatTableView.tableView.frame.size.width];
|
||||
|
||||
bubbleFrame.size = bubbleSize;
|
||||
|
||||
if (tableView.isEditing) {
|
||||
|
|
@ -354,46 +339,20 @@ static const CGFloat CELL_MESSAGE_Y_MARGIN = 0; // 44;
|
|||
super.bubbleView.frame = bubbleFrame;
|
||||
}
|
||||
|
||||
- (CGSize)getMediaMessageSizefromOriginalSize:(CGSize)originalSize{
|
||||
CGSize mediaSize = CGSizeMake(0, 0);
|
||||
//CGRect screenRect = [[UIScreen mainScreen] bounds];
|
||||
if (UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation])) {
|
||||
actualAvailableWidth = actualAvailableWidth *2/3;
|
||||
}
|
||||
int height = originalSize.height;
|
||||
if (originalSize.width > actualAvailableWidth) {
|
||||
height = originalSize.height * actualAvailableWidth / originalSize.width;
|
||||
}
|
||||
mediaSize.height = MIN(height, actualAvailableWidth);
|
||||
mediaSize.width = MIN(actualAvailableWidth, originalSize.width);
|
||||
return mediaSize;
|
||||
}
|
||||
|
||||
- (CGImageRef)cropImageFromRepresentation:(ALAssetRepresentation*)rep withNewSize:(CGSize)size {
|
||||
- (CGImageRef)cropImageFromRepresentation:(ALAssetRepresentation*)rep {
|
||||
CGImageRef newImage = [rep fullResolutionImage];
|
||||
CGSize originalSize = [rep dimensions];
|
||||
// We resize in width and crop in height
|
||||
if (originalSize.width > size.width) {
|
||||
int height = originalSize.height * size.width / originalSize.width;
|
||||
newImage = [self.class resizeCGImage:newImage toWidth:size.width andHeight:height];
|
||||
if (originalSize.width > imageSize.width) {
|
||||
int height = originalSize.height * imageSize.width / originalSize.width;
|
||||
newImage = [self.class resizeCGImage:newImage toWidth:imageSize.width andHeight:height];
|
||||
originalSize.height = height;
|
||||
}
|
||||
CGRect cropRect = CGRectMake(0, 0, size.width, size.height);
|
||||
if (size.height < originalSize.height) cropRect.origin.y = (originalSize.height - size.height)/2;
|
||||
CGRect cropRect = CGRectMake(0, 0, imageSize.width, imageSize.height);
|
||||
if (imageSize.height < originalSize.height) cropRect.origin.y = (originalSize.height - imageSize.height)/2;
|
||||
newImage = CGImageCreateWithImageInRect(newImage, cropRect);
|
||||
return newImage;
|
||||
}
|
||||
|
||||
- (void) setBubbleSize {
|
||||
if (!isAssetLoaded) {
|
||||
NSString *localImage = [LinphoneManager getMessageAppDataForKey:@"localimage" inMessage:self.message];
|
||||
bubbleSize = (localImage != nil) ? CGSizeMake(CELL_IMAGE_WIDTH, CELL_IMAGE_HEIGHT) : CGSizeMake(50, 50);
|
||||
bubbleSize.height += self.avatarImage.frame.size.height + self.imdmLabel.frame.size.height + CELL_MESSAGE_Y_MARGIN;
|
||||
}
|
||||
bubbleSize = CGSizeMake(imageSize.width, imageSize.height + self.avatarImage.frame.size.height + self.imdmLabel.frame.size.height + CELL_MESSAGE_Y_MARGIN); //We add the height of the avatar so the image is not distorted
|
||||
bubbleSize.width = MAX(bubbleSize.width, CELL_MIN_WIDTH);
|
||||
bubbleSize.height = MAX(bubbleSize.height, CELL_MIN_HEIGHT);
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -40,9 +40,8 @@
|
|||
@property(weak, nonatomic) IBOutlet UIImageView *imdmIcon;
|
||||
@property(weak, nonatomic) IBOutlet UILabel *imdmLabel;
|
||||
|
||||
@property(nonatomic) NSIndexPath *indexInTable;
|
||||
|
||||
+ (CGSize)ViewSizeForMessage:(LinphoneChatMessage *)chat withWidth:(int)width;
|
||||
+ (CGSize)getMediaMessageSizefromOriginalSize:(CGSize)originalSize withWidth:(int)width;
|
||||
|
||||
- (void)setEvent:(LinphoneEventLog *)event;
|
||||
- (void)setChatMessage:(LinphoneChatMessage *)message;
|
||||
|
|
|
|||
|
|
@ -306,8 +306,6 @@ static const CGFloat CELL_MIN_HEIGHT = 60.0f;
|
|||
static const CGFloat CELL_MIN_WIDTH = 190.0f;
|
||||
static const CGFloat CELL_MESSAGE_X_MARGIN = 78 + 10.0f;
|
||||
static const CGFloat CELL_MESSAGE_Y_MARGIN = 52; // 44;
|
||||
static const CGFloat CELL_IMAGE_HEIGHT = 100.0f;
|
||||
static const CGFloat CELL_IMAGE_WIDTH = 100.0f;
|
||||
|
||||
+ (CGSize)ViewHeightForMessage:(LinphoneChatMessage *)chat withWidth:(int)width {
|
||||
NSString *messageText = [UIChatBubbleTextCell TextMessageForChat:chat];
|
||||
|
|
@ -328,7 +326,23 @@ static const CGFloat CELL_IMAGE_WIDTH = 100.0f;
|
|||
font:messageFont];
|
||||
} else {
|
||||
NSString *localImage = [LinphoneManager getMessageAppDataForKey:@"localimage" inMessage:chat];
|
||||
size = (localImage != nil) ? CGSizeMake(CELL_IMAGE_WIDTH, CELL_IMAGE_HEIGHT) : CGSizeMake(50, 50);
|
||||
NSURL *imageUrl = [NSURL URLWithString:localImage];
|
||||
__block CGSize originalImageSize = CGSizeMake(0, 0);
|
||||
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void) {
|
||||
[LinphoneManager.instance.photoLibrary assetForURL:imageUrl
|
||||
resultBlock:^(ALAsset *asset) {
|
||||
originalImageSize = [[asset defaultRepresentation] dimensions];
|
||||
dispatch_semaphore_signal(sema);
|
||||
}
|
||||
failureBlock:^(NSError *error) {
|
||||
LOGE(@"Can't read image");
|
||||
dispatch_semaphore_signal(sema);
|
||||
}];
|
||||
});
|
||||
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
|
||||
|
||||
size = [self getMediaMessageSizefromOriginalSize:originalImageSize withWidth:width];
|
||||
}
|
||||
size.width = MAX(size.width + CELL_MESSAGE_X_MARGIN, CELL_MIN_WIDTH);
|
||||
size.height = MAX(size.height + CELL_MESSAGE_Y_MARGIN, CELL_MIN_HEIGHT);
|
||||
|
|
@ -375,4 +389,20 @@ static const CGFloat CELL_IMAGE_WIDTH = 100.0f;
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
+ (CGSize)getMediaMessageSizefromOriginalSize:(CGSize)originalSize withWidth:(int)width {
|
||||
CGSize mediaSize = CGSizeMake(0, 0);
|
||||
int availableWidth = width - CELL_MESSAGE_X_MARGIN;
|
||||
if (UIDeviceOrientationIsLandscape([[UIDevice currentDevice] orientation])) {
|
||||
availableWidth = availableWidth /3;
|
||||
}
|
||||
int height = originalSize.height;
|
||||
if (originalSize.width > availableWidth) {
|
||||
height = originalSize.height * availableWidth / originalSize.width;
|
||||
}
|
||||
mediaSize.height = MIN(height, availableWidth);
|
||||
mediaSize.width = MIN(availableWidth, originalSize.width);
|
||||
return mediaSize;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue