From 19d028687160970be6d8fc64f2507f9f4f90dc5a Mon Sep 17 00:00:00 2001 From: Nightonke Date: Fri, 17 Mar 2017 17:47:06 +0800 Subject: [PATCH] For issue #12: 1. Fixed 2 dangerous null-exception. 2. Prevent the need-login-view being visible when contribution chart is drawn. --- VHGithubNotifier/Info.plist | 4 ++-- .../Model/Manager/VHGithubNotifierManager+Profile.m | 13 +++++++++---- .../CNUserNotificationBannerController.m | 6 +++--- VHGithubNotifier/VC/VHProfileVC.m | 2 ++ 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/VHGithubNotifier/Info.plist b/VHGithubNotifier/Info.plist index 98daacf..9f3ec44 100644 --- a/VHGithubNotifier/Info.plist +++ b/VHGithubNotifier/Info.plist @@ -19,9 +19,9 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.0.2.1 + 1.0.2.2 CFBundleVersion - 1021 + 1022 LSMinimumSystemVersion $(MACOSX_DEPLOYMENT_TARGET) LSUIElement diff --git a/VHGithubNotifier/Model/Manager/VHGithubNotifierManager+Profile.m b/VHGithubNotifier/Model/Manager/VHGithubNotifierManager+Profile.m index d3081e0..7c6ec53 100644 --- a/VHGithubNotifier/Model/Manager/VHGithubNotifierManager+Profile.m +++ b/VHGithubNotifier/Model/Manager/VHGithubNotifierManager+Profile.m @@ -108,10 +108,15 @@ - (NSString *)yearContributionsTimeString NSLocale *enUSPOSIXLocale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"]; [dateFormatter setLocale:enUSPOSIXLocale]; [dateFormatter setDateFormat:@"MMM d, yyyy"]; - NSMutableString *timeString = [NSMutableString string]; - [timeString appendString:[dateFormatter stringFromDate:[contributionBlocks firstObject].date]]; - [timeString appendString:@" — "]; - [timeString appendString:[dateFormatter stringFromDate:[contributionBlocks lastObject].date]]; + NSMutableString *timeString = [NSMutableString stringWithFormat:@""]; + NSString *firstContributionDate = [dateFormatter stringFromDate:[contributionBlocks firstObject].date]; + NSString *lastContributionDate = [dateFormatter stringFromDate:[contributionBlocks lastObject].date]; + if (firstContributionDate && lastContributionDate) + { + [timeString appendString:[dateFormatter stringFromDate:[contributionBlocks firstObject].date]]; + [timeString appendString:@" — "]; + [timeString appendString:[dateFormatter stringFromDate:[contributionBlocks lastObject].date]]; + } return [timeString copy]; } diff --git a/VHGithubNotifier/Utils/CNUserNotification/CNUserNotificationBannerController.m b/VHGithubNotifier/Utils/CNUserNotification/CNUserNotificationBannerController.m index e45a31f..9737b78 100755 --- a/VHGithubNotifier/Utils/CNUserNotification/CNUserNotificationBannerController.m +++ b/VHGithubNotifier/Utils/CNUserNotification/CNUserNotificationBannerController.m @@ -312,15 +312,15 @@ - (void)configureNotificationBannerImage { - (void)configureNotificationBannerTexts { self.title = [self labelWithidentifier:@"titleLabel" - attributedTextValue:[[NSAttributedString alloc] initWithString:_userNotification.title attributes:titleAttributes] + attributedTextValue:[[NSAttributedString alloc] initWithString:AVOID_NIL_STRING(_userNotification.title) attributes:titleAttributes] superView:[[self window] contentView]]; self.subtitle = [self labelWithidentifier:@"subtitleLabel" - attributedTextValue:[[NSAttributedString alloc] initWithString:_userNotification.subtitle attributes:subtitleAttributes] + attributedTextValue:[[NSAttributedString alloc] initWithString:AVOID_NIL_STRING(_userNotification.subtitle) attributes:subtitleAttributes] superView:[[self window] contentView]]; self.informativeText = [self labelWithidentifier:@"informativeTextLabel" - attributedTextValue:[[NSAttributedString alloc] initWithString:_userNotification.informativeText attributes:informativeTextAttributes] + attributedTextValue:[[NSAttributedString alloc] initWithString:AVOID_NIL_STRING(_userNotification.informativeText) attributes:informativeTextAttributes] superView:[[self window] contentView]]; switch (_informativeTextLineBreakMode) { case NSLineBreakByClipping: diff --git a/VHGithubNotifier/VC/VHProfileVC.m b/VHGithubNotifier/VC/VHProfileVC.m index 21be2ec..a15fbf5 100644 --- a/VHGithubNotifier/VC/VHProfileVC.m +++ b/VHGithubNotifier/VC/VHProfileVC.m @@ -132,6 +132,7 @@ - (void)onNotifyLoginCookieGotFailed:(NSNotification *)notification - (void)onNotifyContributionBlocksLoadedSuccessfully:(NSNotification *)notification { self.stateView.state = VHStateViewStateTypeLoadSuccessfully; + self.needLoginView.hidden = YES; self.contributionChart.hidden = NO; [self.contributionChart setNeedsDisplay:YES]; [self updateContributionLabels]; @@ -150,6 +151,7 @@ - (void)onNotifyProfileLoadedSuccessfully:(NSNotification *)notificatio - (void)onNotifyContributionChartChanged:(NSNotification *)notification { + self.needLoginView.hidden = YES; [self.contributionChart setNeedsDisplay:YES]; }