From 2e98a334a19bca920d5f41e72a82477dae16c9ac Mon Sep 17 00:00:00 2001 From: Samuel Clay Date: Wed, 26 Oct 2011 09:40:04 -0700 Subject: [PATCH] Adding favicon_fade for gradient river of news in iphone app. --- apps/rss_feeds/models.py | 13 ++++++++++++ media/iphone/Classes/FeedDetailTableCell.xib | 18 ++++++++--------- .../iphone/Classes/FeedDetailViewController.m | 20 +++++++++++-------- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/apps/rss_feeds/models.py b/apps/rss_feeds/models.py index 338661df3..d55b5be11 100644 --- a/apps/rss_feeds/models.py +++ b/apps/rss_feeds/models.py @@ -77,8 +77,10 @@ class Feed(models.Model): 'updated_seconds_ago': seconds_timesince(self.last_update), 'subs': self.num_subscribers, 'favicon_color': self.favicon_color, + 'favicon_fade': self.favicon_fade(), 'favicon_fetching': bool(not (self.favicon_not_found or self.favicon_color)) } + print self.favicon_color, self.favicon_fade() if include_favicon: try: @@ -354,6 +356,17 @@ class Feed(models.Model): self.save_feed_stories_last_month(verbose) # self.save_feed_story_history_statistics() + def favicon_fade(self): + color = self.favicon_color + if color: + splitter = lambda s, p: [s[i:i+p] for i in range(0, len(s), p)] + red, green, blue = splitter(color[:6], 2) + fade_red = hex(max(int(red, 16) - 60, 0))[2:].zfill(2) + fade_green = hex(max(int(green, 16) - 60, 0))[2:].zfill(2) + fade_blue = hex(max(int(blue, 16) - 60, 0))[2:].zfill(2) + return "%s%s%s" % (fade_red, fade_green, fade_blue) + + def save_feed_stories_last_month(self, verbose=False): month_ago = datetime.datetime.utcnow() - datetime.timedelta(days=30) stories_last_month = MStory.objects(story_feed_id=self.pk, diff --git a/media/iphone/Classes/FeedDetailTableCell.xib b/media/iphone/Classes/FeedDetailTableCell.xib index 53fe27e2e..a1366c3cf 100644 --- a/media/iphone/Classes/FeedDetailTableCell.xib +++ b/media/iphone/Classes/FeedDetailTableCell.xib @@ -208,7 +208,7 @@ 292 - {{172, 65}, {119, 15}} + {{172, 61}, {119, 15}} @@ -238,7 +238,7 @@ 292 - {{20, 28}, {271, 34}} + {{20, 24}, {271, 34}} @@ -267,7 +267,7 @@ 292 - {{43, 2}, {248, 21}} + {{43, -1}, {248, 21}} @@ -308,7 +308,7 @@ 292 - {{20, 65}, {150, 15}} + {{20, 61}, {150, 15}} @@ -335,7 +335,7 @@ 292 - {{2, 37}, {16, 16}} + {{2, 33}, {16, 16}} @@ -346,7 +346,7 @@ 292 - {{21, 5}, {16, 16}} + {{21, 2}, {16, 16}} @@ -355,7 +355,7 @@ IBCocoaTouchFramework - {300, 84} + {300, 91} @@ -367,7 +367,7 @@ IBCocoaTouchFramework - {320, 85} + {320, 92} @@ -377,7 +377,7 @@ 1 RiverFeedDetailCellIdentifier - + diff --git a/media/iphone/Classes/FeedDetailViewController.m b/media/iphone/Classes/FeedDetailViewController.m index 4cb94a67e..051eb9e0e 100644 --- a/media/iphone/Classes/FeedDetailViewController.m +++ b/media/iphone/Classes/FeedDetailViewController.m @@ -20,7 +20,7 @@ #import "Utilities.h" #define kTableViewRowHeight 65; -#define kTableViewRiverRowHeight 85; +#define kTableViewRiverRowHeight 81; @implementation FeedDetailViewController @@ -439,18 +439,22 @@ cell.feedFavicon.image = [Utilities getImage:feedIdStr]; CAGradientLayer *gradient = [CAGradientLayer layer]; - gradient.frame = CGRectMake(0, 0, cell.frame.size.width, 27); + gradient.frame = CGRectMake(0, 0, cell.frame.size.width, 21); unsigned int color = 0; + unsigned int colorFade = 0; NSString *favicon_color = [feed objectForKey:@"favicon_color"]; if ([favicon_color class] == [NSNull class]) { favicon_color = @"505050"; } - NSString *red = [favicon_color substringFrom:0 to:2]; - NSString *green = [favicon_color substringFrom:2 to:4]; - NSString *blue = [favicon_color substringFrom:4 to:6]; + NSString *favicon_fade = [feed objectForKey:@"favicon_fade"]; + if ([favicon_fade class] == [NSNull class]) { + favicon_fade = @"303030"; + } NSScanner *scanner = [NSScanner scannerWithString:favicon_color]; [scanner scanHexInt:&color]; - gradient.colors = [NSArray arrayWithObjects:(id)[UIColorFromRGB(color) CGColor], (id)[[UIColor blackColor] CGColor], nil]; + NSScanner *scannerFade = [NSScanner scannerWithString:favicon_fade]; + [scannerFade scanHexInt:&colorFade]; + gradient.colors = [NSArray arrayWithObjects:(id)[UIColorFromRGB(color) CGColor], (id)[UIColorFromRGB(colorFade) CGColor], nil]; if (isStoryRead) { gradient.opacity = .15; } @@ -466,7 +470,7 @@ cell.storyDate.textColor = [UIColor colorWithRed:0.14f green:0.18f blue:0.42f alpha:1.0]; cell.storyDate.font = [UIFont fontWithName:@"Helvetica-Bold" size:10]; cell.storyUnreadIndicator.alpha = 1; - cell.feedTitle.textColor = [UIColor colorWithRed:0.58f green:0.58f blue:0.58f alpha:1.0]; + cell.feedTitle.textColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1.0]; cell.feedTitle.font = [UIFont fontWithName:@"Helvetica-Bold" size:11]; cell.feedFavicon.alpha = 1; @@ -479,7 +483,7 @@ cell.storyDate.textColor = [UIColor colorWithRed:0.14f green:0.18f blue:0.42f alpha:0.5]; cell.storyDate.font = [UIFont fontWithName:@"Helvetica" size:10]; cell.storyUnreadIndicator.alpha = 0.15f; - cell.feedTitle.textColor = [UIColor colorWithRed:0.4f green:0.4f blue:0.4f alpha:0.7]; + cell.feedTitle.textColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1]; cell.feedTitle.font = [UIFont fontWithName:@"Helvetica" size:11]; cell.feedFavicon.alpha = 0.5f; }