Skip to content

Commit

Permalink
ChatConversation: optimize conversation loading and fix UI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bagage committed Nov 16, 2015
1 parent 94bdcd7 commit 50f0a56
Show file tree
Hide file tree
Showing 12 changed files with 147 additions and 129 deletions.
2 changes: 1 addition & 1 deletion Classes/Base.lproj/ChatConversationView.xib
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
<rect key="frame" x="0.0" y="0.0" width="75" height="66"/>
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" heightSizable="YES" flexibleMaxY="YES"/>
<animations/>
<accessibility key="accessibilityConfiguration" label="Delete all"/>
<accessibility key="accessibilityConfiguration" label="Cancel"/>
<inset key="titleEdgeInsets" minX="0.0" minY="18" maxX="0.0" maxY="0.0"/>
<state key="normal" image="cancel_edit_default.png">
<color key="titleShadowColor" white="0.5" alpha="1" colorSpace="calibratedWhite"/>
Expand Down
7 changes: 5 additions & 2 deletions Classes/ChatConversationTableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell = [[NSClassFromString(kCellId) alloc] initWithIdentifier:kCellId];
}
[cell setChatMessage:chat];
if (chat) {
[cell update];
}
[cell setChatRoomDelegate:_chatRoomDelegate];
[super accessoryForCell:cell atPath:indexPath];
return cell;
Expand All @@ -204,8 +207,8 @@ - (void)tableView:(UITableView *)tableView
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
UIChatBubbleTextCell *cell = (UIChatBubbleTextCell *)[self tableView:tableView cellForRowAtIndexPath:indexPath];
return [cell viewSizeWithWidth:self.view.frame.size.width].height;
LinphoneChatMessage *chat = ms_list_nth_data(messageList, (int)[indexPath row]);
return [UIChatBubbleTextCell ViewSizeForMessage:chat withWidth:self.view.frame.size.width].height;
}


Expand Down
4 changes: 2 additions & 2 deletions Classes/ContactDetailsTableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ typedef enum _ContactSections {
ContactSections_None = 0, // first section is empty because we cannot set header for first section
ContactSections_First_Name,
ContactSections_Last_Name,
ContactSections_Number,
ContactSections_Sip,
ContactSections_Number,
ContactSections_Email,
ContactSections_MAX
} ContactSections_e;
} ContactSections;

@interface ContactDetailsTableView : UITableViewController <UITextFieldDelegate> {
@private
Expand Down
79 changes: 37 additions & 42 deletions Classes/ContactDetailsTableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ - (id)initWithData:(ABMultiValueIdentifier)aidentifier {

@implementation ContactDetailsTableView

static const ContactSections_e contactSections[ContactSections_MAX] = {
ContactSections_None, ContactSections_First_Name, ContactSections_Last_Name,
ContactSections_Sip, ContactSections_Number, ContactSections_Email};

@synthesize contactDetailsDelegate;
@synthesize contact;

Expand Down Expand Up @@ -102,11 +98,11 @@ - (void)updateModification {
}

- (NSMutableArray *)getSectionData:(NSInteger)section {
if (contactSections[section] == ContactSections_Number) {
if (section == ContactSections_Number) {
return [dataCache objectAtIndex:0];
} else if (contactSections[section] == ContactSections_Sip) {
} else if (section == ContactSections_Sip) {
return [dataCache objectAtIndex:1];
} else if (contactSections[section] == ContactSections_Email) {
} else if (section == ContactSections_Email) {
if ([[LinphoneManager instance] lpConfigBoolForKey:@"show_contacts_emails_preference"] == true) {
return [dataCache objectAtIndex:2];
} else {
Expand All @@ -116,7 +112,7 @@ - (NSMutableArray *)getSectionData:(NSInteger)section {
return nil;
}

- (ABPropertyID)propertyIDForSection:(ContactSections_e)section {
- (ABPropertyID)propertyIDForSection:(ContactSections)section {
switch (section) {
case ContactSections_First_Name:
return kABPersonFirstNameProperty;
Expand Down Expand Up @@ -313,7 +309,7 @@ - (void)addEntry:(UITableView *)tableview section:(NSInteger)section animated:(B
NSUInteger count = [sectionArray count];
CFErrorRef error = NULL;
bool added = TRUE;
if (contactSections[section] == ContactSections_Number) {
if (section == ContactSections_Number) {
ABMultiValueIdentifier identifier;
ABMultiValueRef lcMap = ABRecordCopyValue(contact, kABPersonPhoneProperty);
ABMutableMultiValueRef lMap;
Expand All @@ -336,7 +332,7 @@ - (void)addEntry:(UITableView *)tableview section:(NSInteger)section animated:(B
LOGI(@"Can't add entry: %@", [(__bridge NSError *)error localizedDescription]);
}
CFRelease(lMap);
} else if (contactSections[section] == ContactSections_Sip) {
} else if (section == ContactSections_Sip) {
Entry *entry = [self setOrCreateSipContactEntry:nil withValue:value];
if (entry) {
[sectionArray addObject:entry];
Expand All @@ -345,7 +341,7 @@ - (void)addEntry:(UITableView *)tableview section:(NSInteger)section animated:(B
added = false;
LOGE(@"Can't add entry for value: %@", value);
}
} else if (contactSections[section] == ContactSections_Email) {
} else if (section == ContactSections_Email) {
ABMultiValueIdentifier identifier;
ABMultiValueRef lcMap = ABRecordCopyValue(contact, kABPersonEmailProperty);
ABMutableMultiValueRef lMap;
Expand Down Expand Up @@ -392,7 +388,7 @@ - (void)removeEmptyEntry:(UITableView *)tableview section:(NSInteger)section ani
if (row >= 0) {
Entry *entry = [sectionDict objectAtIndex:row];

ABPropertyID property = [self propertyIDForSection:contactSections[section]];
ABPropertyID property = [self propertyIDForSection:(ContactSections)section];
if (property != kABInvalidPropertyType) {
ABMultiValueRef lMap = ABRecordCopyValue(contact, property);
NSInteger index = ABMultiValueGetIndexForIdentifier(lMap, [entry identifier]);
Expand Down Expand Up @@ -425,7 +421,7 @@ - (void)removeEmptyEntry:(UITableView *)tableview section:(NSInteger)section ani
- (void)removeEntry:(UITableView *)tableview path:(NSIndexPath *)indexPath animated:(BOOL)animated {
NSMutableArray *sectionArray = [self getSectionData:[indexPath section]];
Entry *entry = [sectionArray objectAtIndex:[indexPath row]];
ABPropertyID property = [self propertyIDForSection:contactSections[indexPath.section]];
ABPropertyID property = [self propertyIDForSection:(ContactSections)indexPath.section];

if (property != kABInvalidPropertyType) {
ABMultiValueRef lcMap = ABRecordCopyValue(contact, property);
Expand Down Expand Up @@ -459,22 +455,22 @@ - (void)setContact:(ABRecordRef)acontact {
}

- (void)addPhoneField:(NSString *)number {
int i = 0;
while (i < ContactSections_MAX && contactSections[i] != ContactSections_Number)
ContactSections i = 0;
while (i != ContactSections_MAX && i != ContactSections_Number)
++i;
[self addEntry:[self tableView] section:i animated:FALSE value:number];
}

- (void)addSipField:(NSString *)address {
int i = 0;
while (i < ContactSections_MAX && contactSections[i] != ContactSections_Sip)
ContactSections i = 0;
while (i != ContactSections_MAX && i != ContactSections_Sip)
++i;
[self addEntry:[self tableView] section:i animated:FALSE value:address];
}

- (void)addEmailField:(NSString *)address {
int i = 0;
while (i < ContactSections_MAX && contactSections[i] != ContactSections_Email)
ContactSections i = 0;
while (i != ContactSections_MAX && i != ContactSections_Email)
++i;
[self addEntry:[self tableView] section:i animated:FALSE value:address];
}
Expand All @@ -486,8 +482,7 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (contactSections[section] == ContactSections_First_Name ||
contactSections[section] == ContactSections_Last_Name) {
if (section == ContactSections_First_Name || section == ContactSections_Last_Name) {
return (self.tableView.isEditing) ? 1 : 0 /*no first and last name when not editting */;
} else {
return [[self getSectionData:section] count];
Expand All @@ -510,17 +505,17 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
NSString *label = [FastAddressBook localizedLabel:[labelArray objectAtIndex:0]];

[cell hideDeleteButton:NO];
if (contactSections[indexPath.section] == ContactSections_First_Name) {
if (indexPath.section == ContactSections_First_Name) {
value =
(__bridge NSString *)(ABRecordCopyValue(contact, [self propertyIDForSection:ContactSections_First_Name]));
label = nil;
[cell hideDeleteButton:YES];
} else if (contactSections[indexPath.section] == ContactSections_Last_Name) {
} else if (indexPath.section == ContactSections_Last_Name) {
value =
(__bridge NSString *)(ABRecordCopyValue(contact, [self propertyIDForSection:ContactSections_Last_Name]));
label = nil;
[cell hideDeleteButton:YES];
} else if (contactSections[[indexPath section]] == ContactSections_Number) {
} else if ([indexPath section] == ContactSections_Number) {
ABMultiValueRef lMap = ABRecordCopyValue(contact, kABPersonPhoneProperty);
NSInteger index = ABMultiValueGetIndexForIdentifier(lMap, [entry identifier]);
NSString *labelRef = CFBridgingRelease(ABMultiValueCopyLabelAtIndex(lMap, index));
Expand All @@ -532,7 +527,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
value = [FastAddressBook localizedLabel:valueRef];
}
CFRelease(lMap);
} else if (contactSections[[indexPath section]] == ContactSections_Sip) {
} else if ([indexPath section] == ContactSections_Sip) {
ABMultiValueRef lMap = ABRecordCopyValue(contact, kABPersonInstantMessageProperty);
NSInteger index = ABMultiValueGetIndexForIdentifier(lMap, [entry identifier]);

Expand All @@ -556,7 +551,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
}
CFRelease(lDict);
CFRelease(lMap);
} else if (contactSections[[indexPath section]] == ContactSections_Email) {
} else if ([indexPath section] == ContactSections_Email) {
ABMultiValueRef lMap = ABRecordCopyValue(contact, kABPersonEmailProperty);
NSInteger index = ABMultiValueGetIndexForIdentifier(lMap, [entry identifier]);
NSString *labelRef = CFBridgingRelease(ABMultiValueCopyLabelAtIndex(lMap, index));
Expand All @@ -570,11 +565,11 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
CFRelease(lMap);
}
[cell setAddress:value];
if (contactSections[[indexPath section]] == ContactSections_Number) {
if ([indexPath section] == ContactSections_Number) {
[cell.editTextfield setKeyboardType:UIKeyboardTypePhonePad];
} else if (contactSections[[indexPath section]] == ContactSections_Sip) {
} else if ([indexPath section] == ContactSections_Sip) {
[cell.editTextfield setKeyboardType:UIKeyboardTypeASCIICapable];
} else if (contactSections[[indexPath section]] == ContactSections_Email) {
} else if ([indexPath section] == ContactSections_Email) {
[cell.editTextfield setKeyboardType:UIKeyboardTypeASCIICapable];
} else {
[cell.editTextfield setKeyboardType:UIKeyboardTypeDefault];
Expand All @@ -588,7 +583,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
Entry *entry = [sectionDict objectAtIndex:[indexPath row]];
if ([self isEditing]) {
NSString *key = nil;
ABPropertyID property = [self propertyIDForSection:contactSections[indexPath.section]];
ABPropertyID property = [self propertyIDForSection:(ContactSections)indexPath.section];

if (property != kABInvalidPropertyType && property != kABPersonFirstNameProperty &&
property != kABPersonLastNameProperty) {
Expand Down Expand Up @@ -629,8 +624,8 @@ - (void)setEditing:(BOOL)editing animated:(BOOL)animated {
if (editing) {
// add phone/SIP/email entries so that the user can add new data
for (int section = 0; section < [self numberOfSectionsInTableView:[self tableView]]; ++section) {
if (contactSections[section] == ContactSections_Number || contactSections[section] == ContactSections_Sip ||
(showEmails && contactSections[section] == ContactSections_Email)) {
if (section == ContactSections_Number || section == ContactSections_Sip ||
(showEmails && section == ContactSections_Email)) {
[self addEntry:self.tableView section:section animated:animated];
}
}
Expand All @@ -639,8 +634,8 @@ - (void)setEditing:(BOOL)editing animated:(BOOL)animated {
// remove empty phone numbers
for (int section = 0; section < [self numberOfSectionsInTableView:[self tableView]]; ++section) {
// remove phony entries that were not filled by the user
if (contactSections[section] == ContactSections_Number || contactSections[section] == ContactSections_Sip ||
(showEmails && contactSections[section] == ContactSections_Email)) {
if (section == ContactSections_Number || section == ContactSections_Sip ||
(showEmails && section == ContactSections_Email)) {

[self removeEmptyEntry:self.tableView section:section animated:animated];
if ([[self getSectionData:section] count] == 0 && animated) { // the section is empty -> remove titles
Expand All @@ -665,20 +660,20 @@ - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger
NSString *text = nil;
BOOL canAddEntry = self.tableView.isEditing;
NSString *addEntryName = nil;
if (contactSections[section] == ContactSections_First_Name && self.tableView.isEditing) {
if (section == ContactSections_First_Name && self.tableView.isEditing) {
text = NSLocalizedString(@"First name", nil);
canAddEntry = NO;
} else if (contactSections[section] == ContactSections_Last_Name && self.tableView.isEditing) {
} else if (section == ContactSections_Last_Name && self.tableView.isEditing) {
text = NSLocalizedString(@"Last name", nil);
canAddEntry = NO;
} else if ([self getSectionData:section].count > 0 || self.tableView.isEditing) {
if (contactSections[section] == ContactSections_Number) {
if (section == ContactSections_Number) {
text = NSLocalizedString(@"Phone numbers", nil);
addEntryName = NSLocalizedString(@"Add new phone number", nil);
} else if (contactSections[section] == ContactSections_Sip) {
} else if (section == ContactSections_Sip) {
text = NSLocalizedString(@"SIP addresses", nil);
addEntryName = NSLocalizedString(@"Add new SIP address", nil);
} else if (contactSections[section] == ContactSections_Email &&
} else if (section == ContactSections_Email &&
[LinphoneManager.instance lpConfigBoolForKey:@"show_contacts_emails_preference"]) {
text = NSLocalizedString(@"Email addresses", nil);
addEntryName = NSLocalizedString(@"Add new email", nil);
Expand Down Expand Up @@ -780,7 +775,7 @@ - (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
NSIndexPath *path = [self.tableView indexPathForCell:cell];
NSMutableArray *sectionDict = [self getSectionData:[path section]];
Entry *entry = [sectionDict objectAtIndex:[path row]];
ContactSections_e sect = contactSections[[path section]];
ContactSections sect = (ContactSections)[path section];

ABPropertyID property = [self propertyIDForSection:sect];
NSString *value = [textField text];
Expand Down Expand Up @@ -844,8 +839,8 @@ - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSIntege
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
if (section == 0 || (!self.tableView.isEditing && (contactSections[section] == ContactSections_First_Name ||
contactSections[section] == ContactSections_Last_Name))) {
if (section == 0 || (!self.tableView.isEditing &&
(section == ContactSections_First_Name || section == ContactSections_Last_Name))) {
return 1e-5;
}
return [self tableView:tableView viewForHeaderInSection:section].frame.size.height;
Expand Down
1 change: 1 addition & 0 deletions Classes/LinphoneUI/UIChatBubblePhotoCell.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
@property(weak, nonatomic) IBOutlet UIButton *cancelButton;
@property(weak, nonatomic) IBOutlet UIView *imageSubView;
@property(weak, nonatomic) IBOutlet UIView *totalView;
@property(strong, nonatomic) IBOutlet UITapGestureRecognizer *imageGestureRecognizer;

- (void)setChatMessage:(LinphoneChatMessage *)message;
- (void)connectToFileDelegate:(FileTransferDelegate *)ftd;
Expand Down
Loading

0 comments on commit 50f0a56

Please sign in to comment.