diff --git a/Classes/ChatConversationImdnView.h b/Classes/ChatConversationImdnView.h new file mode 100644 index 000000000..9872e8ea5 --- /dev/null +++ b/Classes/ChatConversationImdnView.h @@ -0,0 +1,36 @@ +// +// ChatConversationImdnView.h +// linphone +// +// Created by REIS Benjamin on 25/04/2018. +// + +#ifndef ChatConversationImdnView_h +#define ChatConversationImdnView_h + +#import + +#import "UICompositeView.h" +#import "UIRoundBorderedButton.h" + +@interface ChatConversationImdnView : UIViewController + +@property(nonatomic) LinphoneChatMessage *msg; +@property(nonatomic) bctbx_list_t *displayedList; +@property(nonatomic) bctbx_list_t *receivedList; +@property(nonatomic) bctbx_list_t *notReceivedList; +@property(nonatomic) bctbx_list_t *errorList; + +@property (weak, nonatomic) IBOutlet UIView *msgView; +@property (weak, nonatomic) IBOutlet UIImageView *msgBackgroundColorImage; +@property (weak, nonatomic) IBOutlet UIRoundedImageView *msgAvatarImage; +@property (weak, nonatomic) IBOutlet UIImageView *msgBottomBar; +@property (weak, nonatomic) IBOutlet UILabel *msgDateLabel; +@property (weak, nonatomic) IBOutlet UITextViewNoDefine *msgText; +@property (weak, nonatomic) IBOutlet UITableView *tableView; + +- (IBAction)onBackClick:(id)sender; + +@end + +#endif /* ChatConversationImdnView_h */ diff --git a/Classes/ChatConversationImdnView.m b/Classes/ChatConversationImdnView.m new file mode 100644 index 000000000..b7d8015cb --- /dev/null +++ b/Classes/ChatConversationImdnView.m @@ -0,0 +1,233 @@ +// +// ChatConversationImdnView.m +// linphone +// +// Created by REIS Benjamin on 25/04/2018. +// + +#import + +#import "ChatConversationImdnView.h" +#import "PhoneMainView.h" +#import "UIChatBubbleTextCell.h" +#import "UIChatConversationImdnTableViewCell.h" + +@implementation ChatConversationImdnView + +static UICompositeViewDescription *compositeDescription = nil; + ++ (UICompositeViewDescription *)compositeViewDescription { + if (compositeDescription == nil) { + compositeDescription = [[UICompositeViewDescription alloc] init:self.class + statusBar:StatusBarView.class + tabBar:TabBarView.class + sideMenu:SideMenuView.class + fullscreen:false + isLeftFragment:NO + fragmentWith:ChatsListView.class]; + } + return compositeDescription; +} + +- (UICompositeViewDescription *)compositeViewDescription { + return self.class.compositeViewDescription; +} + +- (void)viewDidLoad { + [super viewDidLoad]; + _msg = NULL; +} + +- (void)viewWillAppear:(BOOL)animated { + [super viewWillAppear:animated]; + const LinphoneAddress *addr = linphone_chat_message_get_from_address(_msg); + BOOL outgoing = linphone_chat_message_is_outgoing(_msg); + + _msgDateLabel.text = [NSString stringWithFormat:@"%@ - %@", + [LinphoneUtils timeToString:linphone_chat_message_get_time(_msg) withFormat:LinphoneDateChatBubble], + [FastAddressBook displayNameForAddress:addr]]; + _msgAvatarImage.image = outgoing ? [LinphoneUtils selfAvatar] : [FastAddressBook imageForAddress:addr]; + _msgText.text = [NSString stringWithUTF8String:linphone_chat_message_get_text(_msg)]; + _msgBackgroundColorImage.image = _msgBottomBar.image = [UIImage imageNamed:(outgoing ? @"color_A.png" : @"color_D.png")]; + _msgDateLabel.textColor = [UIColor colorWithPatternImage:_msgBackgroundColorImage.image]; + [_msgView setFrame:CGRectMake(_msgView.frame.origin.x, + _msgView.frame.origin.y, + _msgView.frame.size.width, + [UIChatBubbleTextCell ViewHeightForMessage:_msg withWidth:self.view.frame.size.width].height)]; + + _tableView.delegate = self; + _tableView.dataSource = self; + [_tableView setFrame:CGRectMake(_tableView.frame.origin.x, + _msgView.frame.origin.y + _msgView.frame.size.height + 10, + _tableView.frame.size.width, + self.view.frame.size.height - (_msgView.frame.origin.y + _msgView.frame.size.height))]; + + _displayedList = linphone_chat_message_get_participants_by_imdn_state(_msg, LinphoneChatMessageStateDisplayed); + _receivedList = linphone_chat_message_get_participants_by_imdn_state(_msg, LinphoneChatMessageStateDeliveredToUser); + _notReceivedList = linphone_chat_message_get_participants_by_imdn_state(_msg, LinphoneChatMessageStateDelivered); + _errorList = linphone_chat_message_get_participants_by_imdn_state(_msg, LinphoneChatMessageStateNotDelivered); + + [_tableView reloadData]; +} + +#pragma mark - TableView + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + NSInteger numberOfSection = 0; + if (_displayedList) numberOfSection++; + if (_receivedList) numberOfSection++; + if (_notReceivedList) numberOfSection++; + if (_errorList) numberOfSection++; + return numberOfSection; +} + +- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { + return 23.0; +} + +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath { + return 44.0; +} +- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { + UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)]; + label.numberOfLines = 1; + UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 23)]; + UIImage *image = NULL; + + if (section == 0) { + if (_displayedList) { + label.text = NSLocalizedString(@"Read", nil); + label.textColor = [UIColor colorWithRed:(24 / 255.0) green:(167 / 255.0) blue:(175 / 255.0) alpha:1.0]; + image = [UIImage imageNamed:@"chat_read"]; + } else if (_receivedList) { + label.text = NSLocalizedString(@"Delivered", nil); + label.textColor = [UIColor grayColor]; + image = [UIImage imageNamed:@"chat_delivered"]; + } else if (_notReceivedList) { + label.text = NSLocalizedString(@"Sent", nil); + label.textColor = [UIColor grayColor]; + } else if (_errorList) { + label.text = NSLocalizedString(@"Error", nil); + label.textColor = [UIColor redColor]; + image = [UIImage imageNamed:@"chat_error"]; + } + } else if (section == 1) { + if (_displayedList && _receivedList) { + label.text = NSLocalizedString(@"Delivered", nil); + label.textColor = [UIColor grayColor]; + image = [UIImage imageNamed:@"chat_delivered"]; + } else if (_notReceivedList) { + label.text = NSLocalizedString(@"Sent", nil); + label.textColor = [UIColor grayColor]; + } else if (_errorList) { + label.text = NSLocalizedString(@"Error", nil); + label.textColor = [UIColor redColor]; + image = [UIImage imageNamed:@"chat_error"]; + } + } else if (section == 2) { + if (_displayedList && _receivedList && _notReceivedList) { + label.text = NSLocalizedString(@"Sent", nil); + label.textColor = [UIColor grayColor]; + } else if (_errorList) { + label.text = NSLocalizedString(@"Error", nil); + label.textColor = [UIColor redColor]; + image = [UIImage imageNamed:@"chat_error"]; + } + } else if (section == 3) { + label.text = NSLocalizedString(@"Error", nil); + label.textColor = [UIColor redColor]; + image = [UIImage imageNamed:@"chat_error"]; + } + + [view addSubview:label]; + [label sizeToFit]; + [label setCenter:view.center]; + + if (image) { + UIImageView *imageView = [[UIImageView alloc] initWithImage:image]; + [view addSubview:imageView]; + [imageView setFrame:CGRectMake(label.frame.origin.x + label.frame.size.width + 5, 2, 19, 19)]; + } + [view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"color_G.png"]]]; + return view; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + if (section == 0) { + if (_displayedList) + return bctbx_list_size(_displayedList); + else if (_receivedList) + return bctbx_list_size(_receivedList); + else if (_notReceivedList) + return bctbx_list_size(_notReceivedList); + else if (_errorList) + return bctbx_list_size(_errorList); + } else if (section == 1) { + if (_displayedList &&_receivedList) + return bctbx_list_size(_receivedList); + else if (_notReceivedList) + return bctbx_list_size(_notReceivedList); + else if (_errorList) + return bctbx_list_size(_errorList); + } else if (section == 2) { + if (_displayedList && _receivedList && _notReceivedList) + return bctbx_list_size(_notReceivedList); + else if (_errorList) + return bctbx_list_size(_errorList); + } else if (section == 3) + return bctbx_list_size(_errorList); + + return 0; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + bctbx_list_t *list = NULL; + if (indexPath.section == 0) { + if (_displayedList) + list = _displayedList; + else if (_receivedList) + list = _receivedList; + else if (_notReceivedList) + list = _notReceivedList; + else if (_errorList) + list = _errorList; + } else if (indexPath.section == 1) { + if (_displayedList &&_receivedList) + list = _receivedList; + else if (_notReceivedList) + list = _notReceivedList; + else if (_errorList) + list = _errorList; + } else if (indexPath.section == 2) { + if (_displayedList && _receivedList && _notReceivedList) + list = _notReceivedList; + else if (_errorList) + list = _errorList; + } else if (indexPath.section == 3) + list = _errorList; + + if (!list) + return nil; + + NSString *kCellId = NSStringFromClass(UIChatConversationImdnTableViewCell.class); + UIChatConversationImdnTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellId]; + if (cell == nil) { + cell = [[UIChatConversationImdnTableViewCell alloc] initWithIdentifier:kCellId]; + } + LinphoneParticipantImdnState *state = bctbx_list_nth_data(list, (int)indexPath.row); + const LinphoneParticipant *participant = linphone_participant_imdn_state_get_participant(state); + time_t time = linphone_participant_imdn_state_get_state_change_time(state); + const LinphoneAddress *addr = linphone_participant_get_address(participant); + cell.displayName.text = [FastAddressBook displayNameForAddress:addr]; + cell.avatar.image = [FastAddressBook imageForAddress:addr]; + cell.dateLabel.text = [LinphoneUtils timeToString:time withFormat:LinphoneDateChatBubble]; + cell.userInteractionEnabled = false; + + return cell; +} + +- (IBAction)onBackClick:(id)sender { + [PhoneMainView.instance popCurrentView]; +} + +@end diff --git a/Classes/ChatConversationImdnView.xib b/Classes/ChatConversationImdnView.xib new file mode 100644 index 000000000..8ecca1101 --- /dev/null +++ b/Classes/ChatConversationImdnView.xib @@ -0,0 +1,128 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Classes/ChatConversationInfoView.m b/Classes/ChatConversationInfoView.m index 4dc46ae58..1c4d42df9 100644 --- a/Classes/ChatConversationInfoView.m +++ b/Classes/ChatConversationInfoView.m @@ -126,7 +126,7 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)onCreate { bctbx_list_t *addresses = NULL; - for(NSString *addr in _contacts) { + for (NSString *addr in _contacts) { LinphoneAddress *linphoneAddress = linphone_address_new(addr.UTF8String); if (!linphoneAddress) continue; diff --git a/Classes/ChatConversationInfoView.xib b/Classes/ChatConversationInfoView.xib index 919871b67..e7ef9d66d 100644 --- a/Classes/ChatConversationInfoView.xib +++ b/Classes/ChatConversationInfoView.xib @@ -1,11 +1,11 @@ - - + + - + @@ -22,29 +22,29 @@ - + - + - + - + - + - + @@ -148,11 +148,11 @@