From 828917bef937434973f0261d3b21eeb1ab9d6a84 Mon Sep 17 00:00:00 2001 From: Gautier Pelloux-Prayer Date: Mon, 26 Oct 2015 14:58:24 +0100 Subject: [PATCH] UI: change date formatting, still work to do --- Classes/Base.lproj/ContactDetailsView.xib | 13 +++++----- Classes/CallView.m | 5 +++- Classes/ChatConversationView.h | 1 - Classes/ChatConversationView.m | 1 - Classes/ContactDetailsView.h | 1 + Classes/ContactDetailsView.m | 1 - Classes/HistoryDetailsTableView.m | 7 +++--- Classes/HistoryDetailsView.h | 1 - Classes/HistoryDetailsView.m | 28 +++------------------ Classes/HistoryListTableView.m | 4 +-- Classes/LinphoneUI/UICallConferenceCell.m | 2 +- Classes/LinphoneUI/UICallPausedCell.m | 2 +- Classes/LinphoneUI/UIChatBubbleTextCell.m | 2 +- Classes/LinphoneUI/UIChatCell.m | 2 +- Classes/LinphoneUI/UIContactDetailsCell.xib | 1 + Classes/Utils/Utils.h | 4 +-- Classes/Utils/Utils.m | 24 +++--------------- 17 files changed, 31 insertions(+), 68 deletions(-) diff --git a/Classes/Base.lproj/ContactDetailsView.xib b/Classes/Base.lproj/ContactDetailsView.xib index f3be92f07..b3337a10a 100644 --- a/Classes/Base.lproj/ContactDetailsView.xib +++ b/Classes/Base.lproj/ContactDetailsView.xib @@ -1,5 +1,5 @@ - + @@ -10,6 +10,7 @@ + @@ -108,21 +109,21 @@ - + - + - + @@ -167,8 +168,8 @@ - - + + diff --git a/Classes/CallView.m b/Classes/CallView.m index 8ca8e96fc..5c0b0de98 100644 --- a/Classes/CallView.m +++ b/Classes/CallView.m @@ -439,7 +439,10 @@ static void hideSpinner(LinphoneCall *call, void *user_data) { #pragma mark - UI modification - (void)callDurationUpdate { - _durationLabel.text = [LinphoneUtils durationForCall:linphone_core_get_current_call([LinphoneManager getLc])]; + int duration = linphone_core_get_current_call([LinphoneManager getLc]) + ? linphone_call_get_duration(linphone_core_get_current_call([LinphoneManager getLc])) + : 0; + _durationLabel.text = [LinphoneUtils durationToString:duration]; } - (void)onCurrentCallChange { diff --git a/Classes/ChatConversationView.h b/Classes/ChatConversationView.h index bad77336e..096178688 100644 --- a/Classes/ChatConversationView.h +++ b/Classes/ChatConversationView.h @@ -42,7 +42,6 @@ @property(weak, nonatomic) IBOutlet UITextView *messageField; @property(nonatomic, strong) IBOutlet UIButton *sendButton; @property(nonatomic, strong) IBOutlet UILabel *addressLabel; -@property(nonatomic, strong) IBOutlet UIRoundedImageView *avatarImage; @property(nonatomic, strong) IBOutlet UIView *headerView; @property(nonatomic, strong) IBOutlet UIView *chatView; @property(nonatomic, strong) IBOutlet UIView *messageView; diff --git a/Classes/ChatConversationView.m b/Classes/ChatConversationView.m index 560aab54e..c827ebf6a 100644 --- a/Classes/ChatConversationView.m +++ b/Classes/ChatConversationView.m @@ -200,7 +200,6 @@ static UICompositeViewDescription *compositeDescription = nil; } [ContactDisplay setDisplayNameLabel:_addressLabel forAddress:addr]; _addressLabel.accessibilityValue = _addressLabel.text; - [_avatarImage setImage:[FastAddressBook imageForAddress:addr thumbnail:YES] bordered:NO withRoundedRadius:YES]; } static void message_status(LinphoneChatMessage *msg, LinphoneChatMessageState state, void *ud) { diff --git a/Classes/ContactDetailsView.h b/Classes/ContactDetailsView.h index 24593e564..af2ae2d52 100644 --- a/Classes/ContactDetailsView.h +++ b/Classes/ContactDetailsView.h @@ -39,6 +39,7 @@ @property(nonatomic, strong) IBOutlet UIButton *cancelButton; @property(weak, nonatomic) IBOutlet UIRoundedImageView *avatarImage; @property(weak, nonatomic) IBOutlet UILabel *nameLabel; +@property(weak, nonatomic) IBOutlet UIToggleButton *deleteButton; - (IBAction)onBackClick:(id)event; - (IBAction)onCancelClick:(id)event; diff --git a/Classes/ContactDetailsView.m b/Classes/ContactDetailsView.m index 1bb1af116..e339501ef 100644 --- a/Classes/ContactDetailsView.m +++ b/Classes/ContactDetailsView.m @@ -210,7 +210,6 @@ static UICompositeViewDescription *compositeDescription = nil; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:1.0]; } - [_tableController setEditing:editing animated:animated]; if (editing) { [_editButton setOn]; diff --git a/Classes/HistoryDetailsTableView.m b/Classes/HistoryDetailsTableView.m index 98cfc9be4..54e7593de 100644 --- a/Classes/HistoryDetailsTableView.m +++ b/Classes/HistoryDetailsTableView.m @@ -65,9 +65,10 @@ time_t callTime = linphone_call_log_get_start_date(log); cell.textLabel.textAlignment = NSTextAlignmentCenter; [cell.textLabel - setText:[NSString stringWithFormat:@"%@ - %d sec", - [LinphoneUtils timeToString:callTime withStyle:NSDateFormatterMediumStyle], - duration]]; + setText:[NSString stringWithFormat:@"%@ - %@", [LinphoneUtils timeToString:callTime + withFormat:NSLocalizedString( + @"yyyy/MM/dd '-' HH'h'mm", nil)], + [LinphoneUtils durationToString:duration]]]; BOOL outgoing = (linphone_call_log_get_dir(log) == LinphoneCallOutgoing); if (linphone_call_log_get_status(log) == LinphoneCallMissed) { diff --git a/Classes/HistoryDetailsView.h b/Classes/HistoryDetailsView.h index ccbf2964a..78d849367 100644 --- a/Classes/HistoryDetailsView.h +++ b/Classes/HistoryDetailsView.h @@ -28,7 +28,6 @@ @interface HistoryDetailsView : UIViewController { @private LinphoneCallLog *callLog; - NSDateFormatter *dateFormatter; } @property(weak, nonatomic) IBOutlet UILabel *contactLabel; @property(nonatomic, strong) IBOutlet UIRoundedImageView *avatarImage; diff --git a/Classes/HistoryDetailsView.m b/Classes/HistoryDetailsView.m index 2a50f7db7..a358b3c8b 100644 --- a/Classes/HistoryDetailsView.m +++ b/Classes/HistoryDetailsView.m @@ -21,26 +21,7 @@ #import "PhoneMainView.h" #import "FastAddressBook.h" -@implementation HistoryDetailsView { -} - -#pragma mark - LifeCycle Functions - -- (id)init { - self = [super initWithNibName:NSStringFromClass(self.class) bundle:[NSBundle mainBundle]]; - if (self != nil) { - dateFormatter = [[NSDateFormatter alloc] init]; - [dateFormatter setTimeStyle:NSDateFormatterMediumStyle]; - [dateFormatter setDateStyle:NSDateFormatterMediumStyle]; - NSLocale *locale = [NSLocale currentLocale]; - [dateFormatter setLocale:locale]; - } - return self; -} - -- (void)dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; -} +@implementation HistoryDetailsView #pragma mark - UICompositeViewDelegate Functions @@ -97,10 +78,7 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; - - [[NSNotificationCenter defaultCenter] removeObserver:self name:kLinphoneAddressBookUpdate object:nil]; - - [[NSNotificationCenter defaultCenter] removeObserver:self name:kLinphoneCoreUpdate object:nil]; + [[NSNotificationCenter defaultCenter] removeObserver:self]; } #pragma mark - Event Functions @@ -162,7 +140,7 @@ static UICompositeViewDescription *compositeDescription = nil; ABRecordRef contact = [FastAddressBook getContactWithAddress:addr]; _addContactButton.hidden = (contact != nil); [ContactDisplay setDisplayNameLabel:_contactLabel forAddress:addr]; - [_avatarImage setImage:[FastAddressBook imageForContact:contact thumbnail:NO] bordered:YES withRoundedRadius:YES]; + [_avatarImage setImage:[FastAddressBook imageForContact:contact thumbnail:NO] bordered:NO withRoundedRadius:YES]; char *addrURI = linphone_address_as_string_uri_only(addr); _addressLabel.text = [NSString stringWithUTF8String:addrURI]; ms_free(addrURI); diff --git a/Classes/HistoryListTableView.m b/Classes/HistoryListTableView.m index da03fd7c6..f2e7e20fc 100644 --- a/Classes/HistoryListTableView.m +++ b/Classes/HistoryListTableView.m @@ -158,8 +158,8 @@ } else if ([eventDate isEqualToDate:[currentDate dateByAddingTimeInterval:-3600 * 24]]) { tempLabel.text = NSLocalizedString(@"YESTERDAY", nil); } else { - tempLabel.text = - [LinphoneUtils timeToString:eventDate.timeIntervalSince1970 withStyle:NSDateFormatterMediumStyle]; + tempLabel.text = [LinphoneUtils timeToString:eventDate.timeIntervalSince1970 + withFormat:NSLocalizedString(@"yyyy/MM/dd", nil)]; } tempLabel.textAlignment = NSTextAlignmentCenter; tempLabel.font = [UIFont boldSystemFontOfSize:17]; diff --git a/Classes/LinphoneUI/UICallConferenceCell.m b/Classes/LinphoneUI/UICallConferenceCell.m index fc8ef5d7a..0caf2588d 100644 --- a/Classes/LinphoneUI/UICallConferenceCell.m +++ b/Classes/LinphoneUI/UICallConferenceCell.m @@ -39,7 +39,7 @@ [_avatarImage setImage:[FastAddressBook imageForAddress:addr thumbnail:YES] bordered:NO withRoundedRadius:YES]; - _durationLabel.text = [LinphoneUtils durationForCall:linphone_core_get_current_call([LinphoneManager getLc])]; + _durationLabel.text = [LinphoneUtils durationToString:linphone_call_get_duration(call)]; } - (IBAction)onKickClick:(id)sender { diff --git a/Classes/LinphoneUI/UICallPausedCell.m b/Classes/LinphoneUI/UICallPausedCell.m index ffee7a46d..04e7c86a7 100644 --- a/Classes/LinphoneUI/UICallPausedCell.m +++ b/Classes/LinphoneUI/UICallPausedCell.m @@ -41,7 +41,7 @@ [_avatarImage setImage:[FastAddressBook imageForAddress:addr thumbnail:NO] bordered:YES withRoundedRadius:YES]; - _durationLabel.text = [LinphoneUtils durationForCall:linphone_core_get_current_call([LinphoneManager getLc])]; + _durationLabel.text = [LinphoneUtils durationToString:linphone_call_get_duration(call)]; } @end diff --git a/Classes/LinphoneUI/UIChatBubbleTextCell.m b/Classes/LinphoneUI/UIChatBubbleTextCell.m index 553e77616..bad58ed90 100644 --- a/Classes/LinphoneUI/UIChatBubbleTextCell.m +++ b/Classes/LinphoneUI/UIChatBubbleTextCell.m @@ -100,7 +100,7 @@ // Date _contactDateLabel.text = [NSString stringWithFormat:@"%@ - %@", [LinphoneUtils timeToString:linphone_chat_message_get_time(_message) - withStyle:NSDateFormatterShortStyle], + withFormat:NSLocalizedString(@"yyyy/MM/dd '-' HH'h'mm", nil)], [FastAddressBook displayNameForAddress:linphone_chat_message_get_peer_address(_message)]]; LinphoneChatMessageState state = linphone_chat_message_get_state(_message); diff --git a/Classes/LinphoneUI/UIChatCell.m b/Classes/LinphoneUI/UIChatCell.m index 6b2a6e421..fd6078b77 100644 --- a/Classes/LinphoneUI/UIChatCell.m +++ b/Classes/LinphoneUI/UIChatCell.m @@ -87,7 +87,7 @@ } _chatLatestTimeLabel.text = [LinphoneUtils timeToString:linphone_chat_message_get_time(last_message) - withStyle:NSDateFormatterShortStyle]; + withFormat:NSLocalizedString(@"MM/dd", nil)]; _chatLatestTimeLabel.hidden = NO; } else { _chatContentLabel.text = nil; diff --git a/Classes/LinphoneUI/UIContactDetailsCell.xib b/Classes/LinphoneUI/UIContactDetailsCell.xib index 6eaf6bd09..bd2a5358e 100644 --- a/Classes/LinphoneUI/UIContactDetailsCell.xib +++ b/Classes/LinphoneUI/UIContactDetailsCell.xib @@ -9,6 +9,7 @@ + diff --git a/Classes/Utils/Utils.h b/Classes/Utils/Utils.h index 6c7241fd4..f6722a4e4 100644 --- a/Classes/Utils/Utils.h +++ b/Classes/Utils/Utils.h @@ -36,12 +36,12 @@ void linphone_iphone_log_handler(int lev, const char *fmt, va_list args); + (void)buttonMultiViewApplyAttributes:(NSDictionary*)attributes button:(UIButton*)button; + (NSString *)deviceName; -+ (NSString *)timeToString:(time_t)time withStyle:(NSDateFormatterStyle)style; ++ (NSString *)timeToString:(time_t)time withFormat:(NSString *)format; + (BOOL)hasAvatar; + (void)setSelfAvatar:(UIImageView *)avatar; -+ (NSString *)durationForCall:(LinphoneCall *)call; ++ (NSString *)durationToString:(int)duration; @end diff --git a/Classes/Utils/Utils.m b/Classes/Utils/Utils.m index 0ae5b2365..85af5ae97 100644 --- a/Classes/Utils/Utils.m +++ b/Classes/Utils/Utils.m @@ -105,8 +105,7 @@ void linphone_iphone_log_handler(int lev, const char *fmt, va_list args) { } } -+ (NSString *)durationForCall:(LinphoneCall *)call { - int duration = call ? linphone_call_get_duration(call) : 0; ++ (NSString *)durationToString:(int)duration { NSMutableString *result = [[NSMutableString alloc] init]; if (duration / 3600 > 0) { [result appendString:[NSString stringWithFormat:@"%02i:", duration / 3600]]; @@ -115,28 +114,11 @@ void linphone_iphone_log_handler(int lev, const char *fmt, va_list args) { return [result stringByAppendingString:[NSString stringWithFormat:@"%02i:%02i", (duration / 60), (duration % 60)]]; } -+ (NSString *)timeToString:(time_t)time withStyle:(NSDateFormatterStyle)style { ++ (NSString *)timeToString:(time_t)time withFormat:(NSString *)format { NSDate *todayDate = [[NSDate alloc] init]; NSDate *messageDate = (time == 0) ? todayDate : [NSDate dateWithTimeIntervalSince1970:time]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; - - [dateFormatter setDateStyle:style]; - - if (style == NSDateFormatterShortStyle) { - // UGLY but single line code! - BOOL sameDay = - [[dateFormatter stringFromDate:todayDate] isEqualToString:[dateFormatter stringFromDate:messageDate]]; - if (sameDay) { - [dateFormatter setDateStyle:NSDateFormatterNoStyle]; - [dateFormatter setTimeStyle:style]; - } else { - [dateFormatter setTimeStyle:NSDateFormatterNoStyle]; - } - } else { - [dateFormatter setTimeStyle:style]; - } - NSLocale *locale = [NSLocale currentLocale]; - [dateFormatter setLocale:locale]; + [dateFormatter setDateFormat:format]; return [dateFormatter stringFromDate:messageDate]; }