diff --git a/Classes/Base.lproj/CallView.xib b/Classes/Base.lproj/CallView.xib index b7d1a4f6d..57a9894c9 100644 --- a/Classes/Base.lproj/CallView.xib +++ b/Classes/Base.lproj/CallView.xib @@ -9,6 +9,7 @@ + @@ -116,7 +117,7 @@ - + diff --git a/Classes/Base.lproj/ChatConversationView.xib b/Classes/Base.lproj/ChatConversationView.xib index b2f230e20..b68877f92 100644 --- a/Classes/Base.lproj/ChatConversationView.xib +++ b/Classes/Base.lproj/ChatConversationView.xib @@ -8,12 +8,10 @@ - - @@ -40,7 +38,7 @@ + + - - - - - + + @@ -195,9 +178,7 @@ - - @@ -207,6 +188,7 @@ + diff --git a/Classes/Base.lproj/ChatsListView.xib b/Classes/Base.lproj/ChatsListView.xib index 670dd6185..62551e36b 100644 --- a/Classes/Base.lproj/ChatsListView.xib +++ b/Classes/Base.lproj/ChatsListView.xib @@ -7,7 +7,12 @@ + + + + + @@ -45,7 +50,7 @@ - + - - - - + diff --git a/Classes/Base.lproj/ContactDetailsView.xib b/Classes/Base.lproj/ContactDetailsView.xib index d0314cc69..d1994bd9b 100644 --- a/Classes/Base.lproj/ContactDetailsView.xib +++ b/Classes/Base.lproj/ContactDetailsView.xib @@ -1,7 +1,6 @@ - diff --git a/Classes/Base.lproj/HistoryListView.xib b/Classes/Base.lproj/HistoryListView.xib index ed6452d3f..d3678cab2 100644 --- a/Classes/Base.lproj/HistoryListView.xib +++ b/Classes/Base.lproj/HistoryListView.xib @@ -1,7 +1,6 @@ - diff --git a/Classes/CallView.h b/Classes/CallView.h index 62ebb7418..389f62d2d 100644 --- a/Classes/CallView.h +++ b/Classes/CallView.h @@ -51,6 +51,8 @@ @property(nonatomic, strong) IBOutlet UICamSwitch *videoCameraSwitch; @property(nonatomic, strong) IBOutlet UIActivityIndicatorView *videoWaitingForFirstImage; +@property(weak, nonatomic) IBOutlet UIView *callView; + @property(nonatomic, strong) IBOutlet UIPauseButton *pauseButton; @property(nonatomic, strong) IBOutlet UIButton *optionsConferenceButton; @property(nonatomic, strong) IBOutlet UIVideoButton *videoButton; diff --git a/Classes/ChatConversationTableView.h b/Classes/ChatConversationTableView.h index 54c7a4731..a0f5b3f19 100644 --- a/Classes/ChatConversationTableView.h +++ b/Classes/ChatConversationTableView.h @@ -41,6 +41,4 @@ - (void)updateChatEntry:(LinphoneChatMessage *)chat; - (void)setChatRoom:(LinphoneChatRoom *)room; -+ (CGSize)viewSize:(LinphoneChatMessage *)message width:(int)width; - @end diff --git a/Classes/ChatConversationTableView.m b/Classes/ChatConversationTableView.m index cc2cd11bb..bd550a8eb 100644 --- a/Classes/ChatConversationTableView.m +++ b/Classes/ChatConversationTableView.m @@ -23,15 +23,6 @@ #import "UIChatBubblePhotoCell.h" #import "PhoneMainView.h" -static const CGFloat CELL_MIN_HEIGHT = 50.0f; -static const CGFloat CELL_MIN_WIDTH = 150.0f; -static const CGFloat CELL_MESSAGE_X_MARGIN = 26.0f + 10.0f; -static const CGFloat CELL_MESSAGE_Y_MARGIN = 36.0f; -static const CGFloat CELL_FONT_SIZE = 17.0f; -static const CGFloat CELL_IMAGE_HEIGHT = 100.0f; -static const CGFloat CELL_IMAGE_WIDTH = 100.0f; -static UIFont *CELL_FONT = nil; - @implementation ChatConversationTableView @synthesize chatRoomDelegate; @@ -223,47 +214,9 @@ static UIFont *CELL_FONT = nil; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { - LinphoneChatMessage *message = ms_list_nth_data(messageList, (int)[indexPath row]); - return [self.class viewSize:message width:[self.view frame].size.width].height; + UIChatBubbleTextCell *cell = (UIChatBubbleTextCell *)[self tableView:tableView cellForRowAtIndexPath:indexPath]; + return [cell viewSizeWithWidth:self.view.frame.size.width].height; } -#pragma mark - Cell dimension - -+ (CGSize)viewSize:(LinphoneChatMessage *)message width:(int)width { - CGSize messageSize; - const char *url = linphone_chat_message_get_external_body_url(message); - if (url == nil && linphone_chat_message_get_file_transfer_information(message) == NULL) { - NSString *text = [UIChatBubbleTextCell TextMessageForChat:message]; - if (CELL_FONT == nil) { - CELL_FONT = [UIFont systemFontOfSize:CELL_FONT_SIZE]; - } -#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000 - if (UIDevice.currentDevice.systemVersion.doubleValue >= 7) { - messageSize = - [text boundingRectWithSize:CGSizeMake(width - CELL_MESSAGE_X_MARGIN, CGFLOAT_MAX) - options:(NSStringDrawingUsesLineFragmentOrigin | - NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesFontLeading) - attributes:@{ - NSFontAttributeName : CELL_FONT - } context:nil] - .size; - } else -#endif - { - messageSize = [text sizeWithFont:CELL_FONT - constrainedToSize:CGSizeMake(width - CELL_MESSAGE_X_MARGIN, 10000.0f) - lineBreakMode:NSLineBreakByTruncatingTail]; - } - } else { - messageSize = CGSizeMake(CELL_IMAGE_WIDTH, CELL_IMAGE_HEIGHT); - } - messageSize.height += CELL_MESSAGE_Y_MARGIN; - if (messageSize.height < CELL_MIN_HEIGHT) - messageSize.height = CELL_MIN_HEIGHT; - messageSize.width += CELL_MESSAGE_X_MARGIN; - if (messageSize.width < CELL_MIN_WIDTH) - messageSize.width = CELL_MIN_WIDTH; - return messageSize; -} @end diff --git a/Classes/ChatsListView.h b/Classes/ChatsListView.h index eeb08f3ce..e3a11b6d0 100644 --- a/Classes/ChatsListView.h +++ b/Classes/ChatsListView.h @@ -28,10 +28,15 @@ } @property(nonatomic, strong) IBOutlet ChatsListTableView *tableController; -@property(nonatomic, strong) IBOutlet UIToggleButton *editButton; +@property(nonatomic, strong) IBOutlet UIButton *editButton; @property(nonatomic, strong) IBOutlet UITextField *addressField; +@property(weak, nonatomic) IBOutlet UIButton *toggleSelectionButton; +@property(weak, nonatomic) IBOutlet UIButton *backButton; +@property(weak, nonatomic) IBOutlet UIButton *addButton; +@property(weak, nonatomic) IBOutlet UIButton *deleteButton; - (IBAction)onAddClick:(id)event; -- (IBAction)onEditClick:(id)event; +- (IBAction)onEditToggle:(id)event; +- (IBAction)onSelectionToggle:(id)sender; @end diff --git a/Classes/ChatsListView.m b/Classes/ChatsListView.m index c8d26bc1f..b2007f321 100644 --- a/Classes/ChatsListView.m +++ b/Classes/ChatsListView.m @@ -22,10 +22,6 @@ @implementation ChatsListView -@synthesize tableController; -@synthesize editButton; -@synthesize addressField; - #pragma mark - Lifecycle Functions - (id)init { @@ -40,9 +36,7 @@ selector:@selector(textReceivedEvent:) name:kLinphoneMessageReceived object:nil]; - if ([tableController isEditing]) - [tableController setEditing:FALSE animated:FALSE]; - [editButton setOff]; + [self setEditing:NO]; } - (void)viewWillDisappear:(BOOL)animated { @@ -54,7 +48,7 @@ #pragma mark - Event Functions - (void)textReceivedEvent:(NSNotification *)notif { - [tableController loadData]; + [_tableController loadData]; } #pragma mark - UICompositeViewDelegate Functions @@ -82,7 +76,7 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)startChatRoom { // Push ChatRoom LinphoneChatRoom *room = - linphone_core_get_chat_room_from_uri([LinphoneManager getLc], [addressField.text UTF8String]); + linphone_core_get_chat_room_from_uri([LinphoneManager getLc], [_addressField.text UTF8String]); if (room != nil) { ChatConversationView *view = VIEW(ChatConversationView); [PhoneMainView.instance changeCurrentView:view.compositeViewDescription push:TRUE]; @@ -95,10 +89,11 @@ static UICompositeViewDescription *compositeDescription = nil; otherButtonTitles:nil]; [alert show]; } - addressField.text = @""; + _addressField.text = @""; } + - (IBAction)onAddClick:(id)event { - if ([[addressField text] length] == 0) { // if no address is manually set, lauch address book + if (_addressField.text.length == 0) { // if no address is manually set, lauch address book [ContactSelection setSelectionMode:ContactSelectionModeMessage]; [ContactSelection setAddAddress:nil]; [ContactSelection setSipFilter:[LinphoneManager instance].contactFilter]; @@ -110,15 +105,24 @@ static UICompositeViewDescription *compositeDescription = nil; } } -- (IBAction)onEditClick:(id)event { - [tableController setEditing:![tableController isEditing] animated:TRUE]; +- (void)setEditing:(BOOL)editing { + [_tableController setEditing:editing animated:TRUE]; + _toggleSelectionButton.hidden = _backButton.hidden = _deleteButton.hidden = !editing; + _addButton.hidden = _editButton.hidden = editing; +} + +- (IBAction)onEditToggle:(id)event { + [self setEditing:!_tableController.isEditing]; +} + +- (IBAction)onSelectionToggle:(id)sender { } #pragma mark - UITextFieldDelegate Functions - (BOOL)textFieldShouldReturn:(UITextField *)textField { - [addressField resignFirstResponder]; - if ([[addressField text] length] > 0) + [_addressField resignFirstResponder]; + if (_addressField.text.length > 0) [self startChatRoom]; return YES; } diff --git a/Classes/LinphoneUI/Base.lproj/UIChatCell.xib b/Classes/LinphoneUI/Base.lproj/UIChatCell.xib index 060319461..aa702af7d 100644 --- a/Classes/LinphoneUI/Base.lproj/UIChatCell.xib +++ b/Classes/LinphoneUI/Base.lproj/UIChatCell.xib @@ -1,6 +1,7 @@ + @@ -22,14 +23,6 @@ - - - + + diff --git a/Classes/LinphoneUI/UIChatBubbleTextCell.h b/Classes/LinphoneUI/UIChatBubbleTextCell.h index cf8532c6f..0ade096ee 100644 --- a/Classes/LinphoneUI/UIChatBubbleTextCell.h +++ b/Classes/LinphoneUI/UIChatBubbleTextCell.h @@ -34,6 +34,9 @@ @property(nonatomic, weak) IBOutlet UIButton *deleteButton; @property(weak, nonatomic) IBOutlet UIImageView *bottomBarColor; @property(nonatomic, strong) id chatRoomDelegate; +@property(strong, nonatomic) IBOutlet UIView *bubbleView; + +- (CGSize)viewSizeWithWidth:(int)width; - (void)setChatMessage:(LinphoneChatMessage *)message; diff --git a/Classes/LinphoneUI/UIChatBubbleTextCell.m b/Classes/LinphoneUI/UIChatBubbleTextCell.m index 8e5dd5516..34acaac6a 100644 --- a/Classes/LinphoneUI/UIChatBubbleTextCell.m +++ b/Classes/LinphoneUI/UIChatBubbleTextCell.m @@ -32,21 +32,14 @@ - (id)initWithIdentifier:(NSString *)identifier { if ((self = [super initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]) != nil) { - NSArray *arrayOfViews = [[NSBundle mainBundle] loadNibNamed:@"UIChatBubbleTextCell" owner:self options:nil]; - [self.contentView addSubview:[arrayOfViews objectAtIndex:arrayOfViews.count - 1]]; - -#if 0 - // shift message box, otherwise it will collide with the bubble - CGRect messageCoords = _messageText.frame; - messageCoords.origin.x += 2; - messageCoords.origin.y += 2; - messageCoords.size.width -= 5; - - _messageText.frame = messageCoords; - _messageText.allowSelectAll = TRUE; -#endif + NSArray *arrayOfViews = + [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self.class) owner:self options:nil]; + // resize cell to match .nib size. It is needed when resized the cell to + // correctly adapt its height too + UIView *sub = ((UIView *)[arrayOfViews objectAtIndex:arrayOfViews.count - 1]); + [self setFrame:CGRectMake(0, 0, sub.frame.size.width, sub.frame.size.height)]; + [self addSubview:sub]; } - return self; } @@ -98,7 +91,7 @@ NSAttributedString *attr_text = [[NSAttributedString alloc] initWithString:self.textMessage attributes:@{ - NSFontAttributeName : [UIFont systemFontOfSize:17.0], + NSFontAttributeName : _messageText.font, NSForegroundColorAttributeName : [UIColor darkGrayColor] }]; _messageText.attributedText = attr_text; @@ -110,7 +103,7 @@ LinphoneChatMessageState state = linphone_chat_message_get_state(message); BOOL outgoing = linphone_chat_message_is_outgoing(message); - _backgroundColor.image = _bottomBarColor.image = [UIImage imageNamed:outgoing ? @"color_A" : @"color_F"]; + // _backgroundColor.image = _bottomBarColor.image = [UIImage imageNamed:outgoing ? @"color_A" : @"color_F"]; if (!outgoing) { _statusImage.accessibilityValue = @"incoming"; @@ -156,20 +149,6 @@ } } -#pragma mark - View Functions - -- (void)layoutSubviews { - [super layoutSubviews]; - if (message != nil) { - BOOL is_outgoing = linphone_chat_message_is_outgoing(message); - CGRect newFrame; - newFrame.size = [ChatConversationTableView viewSize:message width:self.frame.size.width]; - newFrame.origin.y = 0.0f; - newFrame.origin.x = is_outgoing ? self.contentView.frame.size.width - newFrame.size.width : 0; - self.contentView.frame = self.frame = newFrame; - } -} - #pragma mark - Action Functions - (IBAction)onDeleteClick:(id)event { @@ -224,4 +203,65 @@ static void message_status(LinphoneChatMessage *msg, LinphoneChatMessageState st [thiz update]; } +#pragma mark - Bubble size computing + +- (CGSize)viewSizeWithWidth:(int)width { + static const CGFloat TEXT_MIN_HEIGHT = 50.0f; + static const CGFloat TEXT_MIN_WIDTH = 150.0f; + static const CGFloat MARGIN_WIDTH = 47 + 10; + static const CGFloat MARGIN_HEIGHT = 12 + 10; + static const CGFloat IMAGE_HEIGHT = 100.0f; // TODO: move that in bubblephpto + static const CGFloat IMAGE_WIDTH = 100.0f; + + CGSize messageSize; + int messageAvailableWidth = width - MARGIN_WIDTH; + + const char *url = linphone_chat_message_get_external_body_url(message); + if (url == nil && linphone_chat_message_get_file_transfer_information(message) == NULL) { + NSString *text = [UIChatBubbleTextCell TextMessageForChat:message]; + +#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000 + if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 7) { + messageSize = + [text boundingRectWithSize:CGSizeMake(messageAvailableWidth, CGFLOAT_MAX) + options:(NSStringDrawingUsesLineFragmentOrigin | + NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesFontLeading) + attributes:@{ + NSFontAttributeName : _messageText.font + } context:nil] + .size; + } else +#endif + { + messageSize = [text sizeWithFont:_messageText.font + constrainedToSize:CGSizeMake(messageAvailableWidth, 10000.0f) + lineBreakMode:NSLineBreakByTruncatingTail]; + } + } else { + messageSize = CGSizeMake(IMAGE_WIDTH, IMAGE_HEIGHT); + } + + messageSize.width = MAX(TEXT_MIN_WIDTH, messageSize.width); + messageSize.height = MAX(TEXT_MIN_HEIGHT, messageSize.height); + + CGSize bubbleSize = messageSize; + bubbleSize.width += MARGIN_WIDTH; + bubbleSize.height += MARGIN_HEIGHT; + + LOGE(@"%d %fx%f for %@", width, bubbleSize.width, bubbleSize.height, + [UIChatBubbleTextCell TextMessageForChat:message]); + return bubbleSize; +} + +- (void)layoutSubviews { + [super layoutSubviews]; + if (message != nil) { + BOOL is_outgoing = linphone_chat_message_is_outgoing(message); + CGRect bubbleFrame = _bubbleView.frame; + bubbleFrame.size = [self viewSizeWithWidth:self.frame.size.width]; + bubbleFrame.origin.x = is_outgoing ? self.frame.size.width - bubbleFrame.size.width : 0; + _bubbleView.frame = bubbleFrame; + } +} + @end diff --git a/Classes/LinphoneUI/UIChatBubbleTextCell.xib b/Classes/LinphoneUI/UIChatBubbleTextCell.xib index 37fadc4dd..0a40f32df 100644 --- a/Classes/LinphoneUI/UIChatBubbleTextCell.xib +++ b/Classes/LinphoneUI/UIChatBubbleTextCell.xib @@ -10,6 +10,7 @@ + @@ -21,63 +22,73 @@ - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + static const CGFloat CELL_MESSAGE_WIDTH_MARGIN = 26.0f + 10.0f + 48; +static const CGFloat CELL_MESSAGE_HEIGHT_MARGIN = 10.0f + 10; +static const CGFloat CELL_IMAGE_HEIGHT = 100.0f; +static const CGFloat CELL_IMAGE_WIDTH = 100.0f; + + + + + + + + + + + + + + - diff --git a/Classes/LinphoneUI/UIChatCell.m b/Classes/LinphoneUI/UIChatCell.m index 7b4ea2f2d..e5c8e9285 100644 --- a/Classes/LinphoneUI/UIChatCell.m +++ b/Classes/LinphoneUI/UIChatCell.m @@ -114,6 +114,7 @@ [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:0.3]; } + [super setEditing:editing animated:animated]; if (editing) { [deleteButton setAlpha:1.0f]; } else { diff --git a/Classes/Utils/Utils.m b/Classes/Utils/Utils.m index de32a40a6..cddd607eb 100644 --- a/Classes/Utils/Utils.m +++ b/Classes/Utils/Utils.m @@ -353,7 +353,12 @@ void linphone_iphone_log_handler(int lev, const char *fmt, va_list args) { } + (void)setDisplayNameLabel:(UILabel *)label forAddress:(const LinphoneAddress *)addr { - label.text = [FastAddressBook displayNameForAddress:addr]; + ABRecordRef contact = [FastAddressBook getContactWithLinphoneAddress:addr]; + if (contact) { + [ContactDisplay setDisplayNameLabel:label forContact:contact]; + } else { + label.text = [FastAddressBook displayNameForAddress:addr]; + } } @end