From 50f8b106235cf549b1758af9a9bd3de6ca3a8097 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Mon, 14 Sep 2015 16:10:40 +0200 Subject: [PATCH] use confirmation popup when deleting a contact --- Classes/Base.lproj/ContactDetailsView.xib | 34 ++++++++------- Classes/ContactDetailsDelegate.h | 1 - Classes/ContactDetailsView.h | 1 + Classes/ContactDetailsView.m | 14 +++++-- Classes/HistoryDetailsView.h | 2 - Classes/HistoryDetailsView.m | 46 +++++++++------------ Classes/LinphoneUI/UIConfirmationDialog.h | 4 ++ Classes/LinphoneUI/UIConfirmationDialog.m | 3 ++ Classes/LinphoneUI/UIConfirmationDialog.xib | 26 ++++++------ Classes/LinphoneUI/UIHistoryCell.m | 12 ++---- Classes/LinphoneUI/UIRoundBorderedButton.m | 1 + linphone.xcodeproj/project.pbxproj | 6 +-- 12 files changed, 77 insertions(+), 73 deletions(-) diff --git a/Classes/Base.lproj/ContactDetailsView.xib b/Classes/Base.lproj/ContactDetailsView.xib index 9d32ab529..d0314cc69 100644 --- a/Classes/Base.lproj/ContactDetailsView.xib +++ b/Classes/Base.lproj/ContactDetailsView.xib @@ -44,21 +44,7 @@ - - + @@ -105,6 +106,7 @@ + diff --git a/Classes/ContactDetailsDelegate.h b/Classes/ContactDetailsDelegate.h index c251079ee..c1043f25e 100644 --- a/Classes/ContactDetailsDelegate.h +++ b/Classes/ContactDetailsDelegate.h @@ -19,7 +19,6 @@ @protocol ContactDetailsDelegate -- (void)onRemove:(id)event; - (void)onModification:(id)event; @end \ No newline at end of file diff --git a/Classes/ContactDetailsView.h b/Classes/ContactDetailsView.h index 0592bb8cf..f0c96e5f3 100644 --- a/Classes/ContactDetailsView.h +++ b/Classes/ContactDetailsView.h @@ -38,6 +38,7 @@ - (IBAction)onBackClick:(id)event; - (IBAction)onCancelClick:(id)event; - (IBAction)onEditClick:(id)event; +- (IBAction)onDeleteClick:(id)sender; - (void)newContact; - (void)newContact:(NSString *)address; diff --git a/Classes/ContactDetailsView.m b/Classes/ContactDetailsView.m index 30ffc7e3b..4d5384b3a 100644 --- a/Classes/ContactDetailsView.m +++ b/Classes/ContactDetailsView.m @@ -266,10 +266,16 @@ static UICompositeViewDescription *compositeDescription = nil; } } -- (void)onRemove:(id)event { - [self disableEdit:FALSE]; - [self removeContact]; - [PhoneMainView.instance popCurrentView]; +- (IBAction)onDeleteClick:(id)sender { + NSString *msg = [NSString + stringWithFormat:NSLocalizedString(@"Are you sure that you want to delete your contact %@?", nil), @"toto"]; + [UIConfirmationDialog ShowWithMessage:msg + onCancelClick:nil + onConfirmationClick:^() { + [self disableEdit:FALSE]; + [self removeContact]; + [PhoneMainView.instance popCurrentView]; + }]; } - (void)onModification:(id)event { diff --git a/Classes/HistoryDetailsView.h b/Classes/HistoryDetailsView.h index 92b9fe5a1..80bfa7095 100644 --- a/Classes/HistoryDetailsView.h +++ b/Classes/HistoryDetailsView.h @@ -25,7 +25,6 @@ #import "HistoryDetailsTableView.h" @interface HistoryDetailsView : UIViewController { @private - ABRecordRef contact; LinphoneCallLog *callLog; NSDateFormatter *dateFormatter; } @@ -35,7 +34,6 @@ @property(nonatomic, strong) IBOutlet UIButton *addContactButton; @property(nonatomic, copy, setter=setCallLogId:) NSString *callLogId; @property(weak, nonatomic) IBOutlet UIView *headerView; -@property(weak, nonatomic) IBOutlet UITableView *callsTableView; @property(strong, nonatomic) IBOutlet HistoryDetailsTableView *tableView; - (IBAction)onBackClick:(id)event; diff --git a/Classes/HistoryDetailsView.m b/Classes/HistoryDetailsView.m index 7521868c8..3e9fc76a0 100644 --- a/Classes/HistoryDetailsView.m +++ b/Classes/HistoryDetailsView.m @@ -159,12 +159,10 @@ static UICompositeViewDescription *compositeDescription = nil; } LinphoneAddress *addr = linphone_call_log_get_remote_address(callLog); - // this address should NEVER be NULL: if this assert is broken, the bug is elsewhere. - assert(addr != NULL); - - [ContactDisplay setDisplayNameLabel:_contactLabel forAddress:addr]; - _avatarImage.image = - [FastAddressBook getContactImage:[FastAddressBook getContactWithLinphoneAddress:addr] thumbnail:NO]; + ABRecordRef contact = [FastAddressBook getContactWithLinphoneAddress:addr]; + _addContactButton.hidden = (contact != nil); + [ContactDisplay setDisplayNameLabel:_contactLabel forContact:contact]; + _avatarImage.image = [FastAddressBook getContactImage:contact thumbnail:NO]; char *addrURI = linphone_address_as_string_uri_only(addr); _addressLabel.text = [NSString stringWithUTF8String:addrURI]; ms_free(addrURI); @@ -177,30 +175,26 @@ static UICompositeViewDescription *compositeDescription = nil; } - (IBAction)onContactClick:(id)event { - if (contact) { - ContactDetailsView *view = VIEW(ContactDetailsView); - [PhoneMainView.instance changeCurrentView:view.compositeViewDescription push:TRUE]; - [ContactSelection setSelectionMode:ContactSelectionModeNone]; - [view setContact:contact]; - } + LinphoneAddress *addr = linphone_call_log_get_remote_address(callLog); + ABRecordRef contact = [FastAddressBook getContactWithLinphoneAddress:addr]; + ContactDetailsView *view = VIEW(ContactDetailsView); + [PhoneMainView.instance changeCurrentView:view.compositeViewDescription push:TRUE]; + [ContactSelection setSelectionMode:ContactSelectionModeNone]; + [view setContact:contact]; } - (IBAction)onAddContactClick:(id)event { - LinphoneAddress *addr; + LinphoneAddress *addr = linphone_call_log_get_remote_address(callLog); + char *lAddress = linphone_address_as_string_uri_only(addr); + if (lAddress != NULL) { + [ContactSelection setAddAddress:[NSString stringWithUTF8String:lAddress]]; + [ContactSelection setSelectionMode:ContactSelectionModeEdit]; - addr = linphone_call_log_get_remote_address(callLog); - if (addr != NULL) { - char *lAddress = linphone_address_as_string_uri_only(addr); - if (lAddress != NULL) { - [ContactSelection setAddAddress:[NSString stringWithUTF8String:lAddress]]; - [ContactSelection setSelectionMode:ContactSelectionModeEdit]; - - [ContactSelection setSipFilter:nil]; - [ContactSelection enableEmailFilter:FALSE]; - [ContactSelection setNameOrEmailFilter:nil]; - [PhoneMainView.instance changeCurrentView:ContactsListView.compositeViewDescription push:TRUE]; - ms_free(lAddress); - } + [ContactSelection setSipFilter:nil]; + [ContactSelection enableEmailFilter:FALSE]; + [ContactSelection setNameOrEmailFilter:nil]; + [PhoneMainView.instance changeCurrentView:ContactsListView.compositeViewDescription push:TRUE]; + ms_free(lAddress); } } diff --git a/Classes/LinphoneUI/UIConfirmationDialog.h b/Classes/LinphoneUI/UIConfirmationDialog.h index 12c8f0175..42729ab46 100644 --- a/Classes/LinphoneUI/UIConfirmationDialog.h +++ b/Classes/LinphoneUI/UIConfirmationDialog.h @@ -6,6 +6,8 @@ // // +#include "UIRoundBorderedButton.h" + typedef void (^UIConfirmationBlock)(void); @interface UIConfirmationDialog : UIViewController { @@ -18,6 +20,8 @@ typedef void (^UIConfirmationBlock)(void); onCancelClick:(UIConfirmationBlock)onCancel onConfirmationClick:(UIConfirmationBlock)onConfirm; +@property(weak, nonatomic) IBOutlet UIRoundBorderedButton *cancelButton; +@property(weak, nonatomic) IBOutlet UIRoundBorderedButton *confirmationButton; @property(weak, nonatomic) IBOutlet UILabel *titleLabel; - (IBAction)onCancelClick:(id)sender; - (IBAction)onConfirmationClick:(id)sender; diff --git a/Classes/LinphoneUI/UIConfirmationDialog.m b/Classes/LinphoneUI/UIConfirmationDialog.m index 0700b3d7e..b6251eb47 100644 --- a/Classes/LinphoneUI/UIConfirmationDialog.m +++ b/Classes/LinphoneUI/UIConfirmationDialog.m @@ -24,6 +24,9 @@ dialog->onConfirmCb = onConfirm; [dialog.titleLabel setText:message]; + dialog.confirmationButton.layer.borderColor = + [[UIColor colorWithPatternImage:[UIImage imageNamed:@"color_A"]] CGColor]; + dialog.cancelButton.layer.borderColor = [[UIColor colorWithPatternImage:[UIImage imageNamed:@"color_F"]] CGColor]; } - (IBAction)onCancelClick:(id)sender { diff --git a/Classes/LinphoneUI/UIConfirmationDialog.xib b/Classes/LinphoneUI/UIConfirmationDialog.xib index 3f0fc6d10..eaeccaa3a 100644 --- a/Classes/LinphoneUI/UIConfirmationDialog.xib +++ b/Classes/LinphoneUI/UIConfirmationDialog.xib @@ -7,6 +7,8 @@ + + @@ -17,7 +19,7 @@ - + - + diff --git a/Classes/LinphoneUI/UIHistoryCell.m b/Classes/LinphoneUI/UIHistoryCell.m index b2487e00a..1b85f9976 100644 --- a/Classes/LinphoneUI/UIHistoryCell.m +++ b/Classes/LinphoneUI/UIHistoryCell.m @@ -37,7 +37,6 @@ if ([arrayOfViews count] >= 1) { [self.contentView addSubview:[arrayOfViews objectAtIndex:0]]; } - callLog = NULL; } return self; @@ -47,6 +46,7 @@ - (void)setCallLog:(LinphoneCallLog *)acallLog { callLog = acallLog; + [self update]; } @@ -74,16 +74,10 @@ #pragma mark - - (NSString *)accessibilityValue { - // TODO: localize? BOOL incoming = linphone_call_log_get_dir(callLog) == LinphoneCallIncoming; BOOL missed = linphone_call_log_get_status(callLog) == LinphoneCallMissed; - - NSString *call_type = @"Outgoing"; - if (incoming) { - call_type = missed ? @"Missed" : @"Incoming"; - } - - return [NSString stringWithFormat:@"%@ from %@", call_type, displayNameLabel.text]; + NSString *call_type = incoming ? (missed ? @"Missed" : @"Incoming") : @"Outgoing"; + return [NSString stringWithFormat:@"%@ call from %@", call_type, displayNameLabel.text]; } - (void)update { diff --git a/Classes/LinphoneUI/UIRoundBorderedButton.m b/Classes/LinphoneUI/UIRoundBorderedButton.m index e3891a86c..4c2781bbc 100644 --- a/Classes/LinphoneUI/UIRoundBorderedButton.m +++ b/Classes/LinphoneUI/UIRoundBorderedButton.m @@ -16,6 +16,7 @@ self.layer.borderWidth = .8; self.layer.borderColor = [[UIColor blackColor] CGColor]; self.layer.cornerRadius = 4.f; + self.layer.masksToBounds = YES; // capitalize title (should be already done though) UIControlState states[] = {UIControlStateNormal, UIControlStateHighlighted, UIControlStateSelected, diff --git a/linphone.xcodeproj/project.pbxproj b/linphone.xcodeproj/project.pbxproj index 7bd596b68..286dbb26e 100755 --- a/linphone.xcodeproj/project.pbxproj +++ b/linphone.xcodeproj/project.pbxproj @@ -1415,6 +1415,9 @@ D3211BAD159C4EF00098460B /* UIConferenceHeader.h */, D3211BAE159C4EF00098460B /* UIConferenceHeader.m */, D38187F315FE354000C3EDCA /* UIConferenceHeader.xib */, + 63701DDD1BA32039006A9AE3 /* UIConfirmationDialog.h */, + 63701DDE1BA32039006A9AE3 /* UIConfirmationDialog.m */, + 63701DD51BA31DA1006A9AE3 /* UIConfirmationDialog.xib */, D3A55FBA15877E5E003FD403 /* UIContactCell.h */, D3A55FBB15877E5E003FD403 /* UIContactCell.m */, F088488D19FF8C41007FFCF3 /* UIContactCell.xib */, @@ -1457,9 +1460,6 @@ D32460E5159D9AAD00BA7F3A /* UITransparentView.m */, 340751E5150F38FC00B89C47 /* UIVideoButton.h */, 340751E6150F38FD00B89C47 /* UIVideoButton.m */, - 63701DD51BA31DA1006A9AE3 /* UIConfirmationDialog.xib */, - 63701DDD1BA32039006A9AE3 /* UIConfirmationDialog.h */, - 63701DDE1BA32039006A9AE3 /* UIConfirmationDialog.m */, ); path = LinphoneUI; sourceTree = "";