Finished the drawing of custom feed cells, which now include feed title, feed favicon, correct sizings and clipping for unread count pills, and section headers. Gorgeous!

This commit is contained in:
Samuel Clay 2011-08-12 10:12:30 -07:00
parent 597bf495da
commit 73b4af2faa
8 changed files with 105 additions and 69 deletions

View file

@ -313,7 +313,7 @@ def load_single_feed(request, feed_id):
if usersub:
userstories_db = MUserStory.objects(user_id=user.pk,
feed_id=feed.pk,
read_date__gte=usersub.mark_read_date)
read_date__gte=usersub.mark_read_date).only('story')
starred_stories = MStarredStory.objects(user_id=user.pk, story_feed_id=feed_id).only('story_guid', 'starred_date')
starred_stories = dict([(story.story_guid, story.starred_date) for story in starred_stories])

View file

@ -204,7 +204,7 @@
}
- (int)visibleUnreadCount {
return 0;
}
- (void)addStories:(NSArray *)stories {

View file

@ -16,6 +16,11 @@
#define kTableViewRowHeight 40;
#define UIColorFromRGB(rgbValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
@implementation NewsBlurViewController
@synthesize appDelegate;
@ -137,7 +142,7 @@
- (void)fetchFeedList {
NSURL *urlFeedList = [NSURL URLWithString:[NSString
stringWithFormat:@"http://nb.local.host:8000/reader/feeds?flat=true"]];
stringWithFormat:@"http://www.newsblur.com/reader/feeds?flat=true"]];
responseData = [[NSMutableData data] retain];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL: urlFeedList];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
@ -316,14 +321,14 @@
id feedId = [feeds objectAtIndex:location];
NSString *feedIdStr = [NSString stringWithFormat:@"%@",feedId];
NSDictionary *feed = [self.dictFeeds objectForKey:feedIdStr];
cell.feedTitle.text = [feed objectForKey:@"feed_title"];
cell.feedTitle = [feed objectForKey:@"feed_title"];
NSString *favicon = [feed objectForKey:@"favicon"];
if ((NSNull *)favicon != [NSNull null] && [favicon length] > 0) {
NSData *imageData = [NSData dataWithBase64EncodedString:favicon];
cell.feedFavicon.image = [UIImage imageWithData:imageData];
cell.feedFavicon = [UIImage imageWithData:imageData];
} else {
cell.feedFavicon.image = [UIImage imageNamed:@"world.png"];
cell.feedFavicon = [UIImage imageNamed:@"world.png"];
}
cell.positiveCount = [[feed objectForKey:@"ps"] intValue];
@ -334,7 +339,8 @@
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *folderName = [self.dictFoldersArray objectAtIndex:indexPath.section];
NSArray *feeds = [self.dictFolders objectForKey:folderName];
NSArray *activeFolderFeeds = [self.activeFeedLocations objectForKey:folderName];
@ -349,10 +355,57 @@
[appDelegate loadFeedDetailView];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- (CGFloat)tableView:(UITableView *)tableView
heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return kTableViewRowHeight;
}
- (UIView *)tableView:(UITableView *)tableView
viewForHeaderInSection:(NSInteger)section {
// create the parent view that will hold header Label
UIView* customView = [[[UIView alloc]
initWithFrame:CGRectMake(0.0, 0.0,
tableView.bounds.size.width, 21.0)]
autorelease];
UIView *borderBottom = [[[UIView alloc]
initWithFrame:CGRectMake(0.0, 20.0,
tableView.bounds.size.width, 1.0)]
autorelease];
borderBottom.backgroundColor = [UIColorFromRGB(0xB7BDC6) colorWithAlphaComponent:0.5];
borderBottom.opaque = NO;
[customView addSubview:borderBottom];
UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
customView.backgroundColor = [UIColorFromRGB(0xD7DDE6)
colorWithAlphaComponent:0.8];
customView.opaque = NO;
headerLabel.backgroundColor = [UIColor clearColor];
headerLabel.opaque = NO;
headerLabel.textColor = [UIColor colorWithRed:0.3 green:0.3 blue:0.3 alpha:1.0];
headerLabel.highlightedTextColor = [UIColor whiteColor];
headerLabel.font = [UIFont boldSystemFontOfSize:11];
headerLabel.frame = CGRectMake(26.0, 1.0, 286.0, 20.0);
headerLabel.text = [[self.dictFoldersArray objectAtIndex:section] uppercaseString];
headerLabel.shadowColor = [UIColor colorWithRed:.94 green:0.94 blue:0.97 alpha:1.0];
headerLabel.shadowOffset = CGSizeMake(1.0, 1.0);
[customView addSubview:headerLabel];
[headerLabel release];
UIImage *folderImage = [UIImage imageNamed:@"folder.png"];
UIImageView *folderImageView = [[UIImageView alloc] initWithImage:folderImage];
folderImageView.frame = CGRectMake(10.0, 2.0, 16.0, 16.0);
[customView addSubview:folderImageView];
[folderImageView release];
return customView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 21;
}
- (NSString *)showUnreadCount:(NSDictionary *)feed {
NSString *imgCssString = [NSString stringWithFormat:@"<style>"
"body {"
@ -513,7 +566,7 @@
- (void)loadFavicons {
NSString *urlString = @"http://nb.local.host:8000/reader/favicons";
NSString *urlString = @"http://www.newsblur.com/reader/favicons";
NSURL *url = [NSURL URLWithString:urlString];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
@ -534,6 +587,7 @@
[self.dictFeeds setValue:feed forKey:feed_id];
}
[results release];
[self.feedTitlesTable reloadData];
}

View file

@ -11,8 +11,8 @@
@interface FeedTableCell : ABTableViewCell {
UILabel *feedTitle;
UIImageView *feedFavicon;
NSString *feedTitle;
UIImage *feedFavicon;
int _positiveCount;
int _neutralCount;
int _negativeCount;
@ -21,8 +21,8 @@
NSString *_negativeCountStr;
}
@property (nonatomic, retain) IBOutlet UILabel *feedTitle;
@property (nonatomic, retain) IBOutlet UIImageView *feedFavicon;
@property (nonatomic, retain) NSString *feedTitle;
@property (nonatomic, retain) UIImage *feedFavicon;
@property (assign, nonatomic) int positiveCount;
@property (assign, nonatomic) int neutralCount;
@property (assign, nonatomic) int negativeCount;

View file

@ -23,6 +23,7 @@ static UIColor *positiveBackgroundColor = nil;
static UIColor *neutralBackgroundColor = nil;
static UIColor *negativeBackgroundColor = nil;
static CGFloat *psColors = nil;
@implementation FeedTableCell
@synthesize feedTitle;
@ -48,16 +49,16 @@ static CGFloat *psColors = nil;
positiveBackgroundColor = [ps retain];
neutralBackgroundColor = [nt retain];
negativeBackgroundColor = [ng retain];
UIColor *psGrad = UIColorFromRGB(0x559F4D);
// UIColor *psGrad = UIColorFromRGB(0x559F4D);
// UIColor *ntGrad = UIColorFromRGB(0xE4AB00);
// UIColor *ngGrad = UIColorFromRGB(0x9B181B);
const CGFloat* psTop = CGColorGetComponents(ps.CGColor);
const CGFloat* psBot = CGColorGetComponents(psGrad.CGColor);
CGFloat psGradient[] = {
psTop[0], psTop[1], psTop[2], psTop[3],
psBot[0], psBot[1], psBot[2], psBot[3]
};
psColors = psGradient;
// const CGFloat* psTop = CGColorGetComponents(ps.CGColor);
// const CGFloat* psBot = CGColorGetComponents(psGrad.CGColor);
// CGFloat psGradient[] = {
// psTop[0], psTop[1], psTop[2], psTop[3],
// psBot[0], psBot[1], psBot[2], psBot[3]
// };
// psColors = psGradient;
}
}
@ -118,8 +119,7 @@ static CGFloat *psColors = nil;
CGContextRef context = UIGraphicsGetCurrentContext();
UIColor *backgroundColor = self.selected || self.highlighted ? [UIColor clearColor] : [UIColor whiteColor];
UIColor *textColor = self.selected || self.highlighted ? [UIColor whiteColor] : [UIColor blackColor];
UIColor *backgroundColor = self.selected || self.highlighted ? [UIColor colorWithRed:0.15 green:0.55 blue:0.95 alpha:1.0] : [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1.0];
[backgroundColor set];
CGContextFillRect(context, r);
@ -129,25 +129,25 @@ static CGFloat *psColors = nil;
rect.size.width -= 25;
int psWidth = _positiveCount == 0 ? 0 : _positiveCount < 10 ?
14 : _positiveCount < 100 ? 20 : 26;
12 : _positiveCount < 100 ? 20 : 26;
int ntWidth = _neutralCount == 0 ? 0 : _neutralCount < 10 ?
14 : _neutralCount < 100 ? 20 : 26;
12 : _neutralCount < 100 ? 20 : 26;
int ngWidth = _negativeCount == 0 ? 0 : _negativeCount < 10 ?
14 : _negativeCount < 100 ? 20 : 26;
12 : _negativeCount < 100 ? 20 : 26;
int psOffset = _positiveCount == 0 ? 0 : _positiveCount < 10 ?
-6 : _positiveCount < 100 ? 0 : 6;
-8 : _positiveCount < 100 ? 0 : 6;
int ntOffset = _neutralCount == 0 ? 0 : _neutralCount < 10 ?
-6 : _neutralCount < 100 ? 0 : 6;
-8 : _neutralCount < 100 ? 0 : 6;
int ngOffset = _negativeCount == 0 ? 0 : _negativeCount < 10 ?
-6 : _negativeCount < 100 ? 0 : 6;
-8 : _negativeCount < 100 ? 0 : 6;
int psPadding = _positiveCount == 0 ? 0 : 2;
int ntPadding = _neutralCount == 0 ? 0 : 2;
if(_positiveCount > 0){
[positiveBackgroundColor set];
CGRect rr = CGRectMake(rect.size.width + rect.origin.x - psOffset, 8, psWidth, 18);
CGRect rr = CGRectMake(rect.size.width + rect.origin.x - psOffset, 10, psWidth, 18);
[UIView drawLinearGradientInRect:rr colors:psColors];
[UIView drawRoundRectangleInRect:rr withRadius:5];
@ -155,35 +155,42 @@ static CGFloat *psColors = nil;
CGSize size = [_positiveCountStr sizeWithFont:indicatorFont];
float x_pos = (rr.size.width - size.width) / 2;
float y_pos = (rr.size.height - size.height) /2;
float y_pos = (rr.size.height - size.height) / 2;
[_positiveCountStr drawAtPoint:CGPointMake(rr.origin.x + x_pos, rr.origin.y + y_pos) withFont:indicatorFont];
}
if(_neutralCount > 0){
[neutralBackgroundColor set];
CGRect rr = CGRectMake(rect.size.width + rect.origin.x - psWidth - psPadding - ntOffset, 8, ntWidth, 18);
CGRect rr = CGRectMake(rect.size.width + rect.origin.x - psWidth - psPadding - ntOffset, 10, ntWidth, 18);
[UIView drawRoundRectangleInRect:rr withRadius:5];
// [UIView drawLinearGradientInRect:rr colors:ntColors];
[indicatorBlackColor set];
CGSize size = [_neutralCountStr sizeWithFont:indicatorFont];
float x_pos = (rr.size.width - size.width) / 2;
float y_pos = (rr.size.height - size.height) /2;
float y_pos = (rr.size.height - size.height) / 2;
[_neutralCountStr drawAtPoint:CGPointMake(rr.origin.x + x_pos, rr.origin.y + y_pos) withFont:indicatorFont];
}
if(_negativeCount > 0){
[negativeBackgroundColor set];
CGRect rr = CGRectMake(rect.size.width + rect.origin.x - psWidth - psPadding - ntWidth - ntPadding - ngOffset, 8, ngWidth, 18);
CGRect rr = CGRectMake(rect.size.width + rect.origin.x - psWidth - psPadding - ntWidth - ntPadding - ngOffset, 10, ngWidth, 18);
[UIView drawRoundRectangleInRect:rr withRadius:5];
// [UIView drawLinearGradientInRect:rr colors:ngColors];
[indicatorWhiteColor set];
CGSize size = [_negativeCountStr sizeWithFont:indicatorFont];
float x_pos = (rr.size.width - size.width) / 2;
float y_pos = (rr.size.height - size.height) /2;
float y_pos = (rr.size.height - size.height) / 2;
[_negativeCountStr drawAtPoint:CGPointMake(rr.origin.x + x_pos, rr.origin.y + y_pos) withFont:indicatorFont];
}
UIColor *textColor = self.selected || self.highlighted ? [UIColor whiteColor] : [UIColor blackColor];
[textColor set];
[feedTitle drawInRect:CGRectMake(36.0, 12.0, rect.size.width - psWidth - psPadding - ntWidth - ntPadding - ngWidth - 10, 20.0) withFont:[UIFont boldSystemFontOfSize:13.0] lineBreakMode:UILineBreakModeTailTruncation alignment:UITextAlignmentLeft];
[self.feedFavicon drawInRect:CGRectMake(14.0, 12.0, 16.0, 16.0)];
}

View file

@ -64,6 +64,7 @@
FF79E11D13EB756A0095C852 /* arrow.png in Resources */ = {isa = PBXBuildFile; fileRef = FF79E11913EB756A0095C852 /* arrow.png */; };
FF79E11E13EB756A0095C852 /* arrow@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = FF79E11A13EB756A0095C852 /* arrow@2x.png */; };
FF79E11F13EB756A0095C852 /* PullToRefreshView.m in Sources */ = {isa = PBXBuildFile; fileRef = FF79E11C13EB756A0095C852 /* PullToRefreshView.m */; };
FF7DB4C413F58486008176BF /* folder.png in Resources */ = {isa = PBXBuildFile; fileRef = FF7DB4C313F58486008176BF /* folder.png */; };
FFCE7AE813D49165009A98F6 /* FeedTableCell.m in Sources */ = {isa = PBXBuildFile; fileRef = FFCE7AE613D49165009A98F6 /* FeedTableCell.m */; };
FFCE7AE913D49165009A98F6 /* FeedTableCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = FFCE7AE713D49165009A98F6 /* FeedTableCell.xib */; };
/* End PBXBuildFile section */
@ -164,6 +165,7 @@
FF79E11A13EB756A0095C852 /* arrow@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "arrow@2x.png"; sourceTree = "<group>"; };
FF79E11B13EB756A0095C852 /* PullToRefreshView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PullToRefreshView.h; sourceTree = "<group>"; };
FF79E11C13EB756A0095C852 /* PullToRefreshView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PullToRefreshView.m; sourceTree = "<group>"; };
FF7DB4C313F58486008176BF /* folder.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = folder.png; sourceTree = "<group>"; };
FFCE7AE513D49165009A98F6 /* FeedTableCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FeedTableCell.h; path = ../NewsBlur.xcodeproj/FeedTableCell.h; sourceTree = "<group>"; };
FFCE7AE613D49165009A98F6 /* FeedTableCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FeedTableCell.m; path = ../NewsBlur.xcodeproj/FeedTableCell.m; sourceTree = "<group>"; };
FFCE7AE713D49165009A98F6 /* FeedTableCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = FeedTableCell.xib; path = ../NewsBlur.xcodeproj/FeedTableCell.xib; sourceTree = "<group>"; };
@ -266,6 +268,7 @@
29B97317FDCFA39411CA2CEA /* Resources */ = {
isa = PBXGroup;
children = (
FF7DB4C313F58486008176BF /* folder.png */,
FF79E11913EB756A0095C852 /* arrow.png */,
FF79E11A13EB756A0095C852 /* arrow@2x.png */,
FF435EDD13E9B04E0083043F /* world.png */,
@ -431,6 +434,7 @@
FF435EDE13E9B04E0083043F /* world.png in Resources */,
FF79E11D13EB756A0095C852 /* arrow.png in Resources */,
FF79E11E13EB756A0095C852 /* arrow@2x.png in Resources */,
FF7DB4C413F58486008176BF /* folder.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View file

@ -53,48 +53,19 @@
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="895374018"/>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">10</int>
<object class="NSImage" key="NSImage">
<int key="NSImageFlags">549453824</int>
<string key="NSSize">{84, 1}</string>
<object class="NSMutableArray" key="NSReps">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray">
<bool key="EncodedWithXMLCoder">YES</bool>
<integer value="0"/>
<object class="NSBitmapImageRep">
<object class="NSData" key="NSTIFFRepresentation">
<bytes key="NS.bytes">TU0AKgAAAVjFzNT/xczU/8XM1P/FzNT/xczS/8vS2P/L0tj/xczU/8XM1P/FzNT/xczU/8XM0v/L0tj/
y9LY/8XM1P/FzNT/xczU/8XM1P/FzNL/y9LY/8vS2P/FzNT/xczU/8XM1P/FzNT/xczS/8vS2P/L0tj/
xczU/8XM1P/FzNT/xczU/8XM0v/L0tj/y9LY/8XM1P/FzNT/xczU/8XM1P/FzNL/y9LY/8vS2P/FzNT/
xczU/8XM1P/FzNT/xczS/8vS2P/L0tj/xczU/8XM1P/FzNT/xczU/8XM0v/L0tj/y9LY/8XM1P/FzNT/
xczU/8XM1P/FzNL/y9LY/8vS2P/FzNT/xczU/8XM1P/FzNT/xczS/8vS2P/L0tj/xczU/8XM1P/FzNT/
xczU/8XM0v/L0tj/y9LY/8XM1P/FzNT/xczU/8XM1P/FzNL/y9LY/8vS2P8ADQEAAAMAAAABAFQAAAEB
AAMAAAABAAEAAAECAAMAAAAEAAAB+gEDAAMAAAABAAEAAAEGAAMAAAABAAIAAAERAAQAAAABAAAACAES
AAMAAAABAAEAAAEVAAMAAAABAAQAAAEWAAMAAAABAAEAAAEXAAQAAAABAAABUAEcAAMAAAABAAEAAAFS
AAMAAAABAAEAAAFTAAMAAAAEAAACAgAAAAAACAAIAAgACAABAAEAAQABA</bytes>
</object>
</object>
</object>
</object>
<object class="NSColor" key="NSColor">
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MCAwAA</bytes>
</object>
</object>
<string key="IBUIColorCocoaTouchKeyPath">groupTableViewBackgroundColor</string>
<int key="NSColorSpace">3</int>
<bytes key="NSWhite">MQA</bytes>
</object>
<bool key="IBUIClipsSubviews">YES</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<bool key="IBUIShowsHorizontalScrollIndicator">NO</bool>
<bool key="IBUIBouncesZoom">NO</bool>
<int key="IBUIStyle">1</int>
<int key="IBUISeparatorStyle">1</int>
<int key="IBUISectionIndexMinimumDisplayRowCount">0</int>
<bool key="IBUIShowsSelectionImmediatelyOnTouchBegin">YES</bool>
<float key="IBUIRowHeight">44</float>
<float key="IBUISectionHeaderHeight">10</float>
<float key="IBUISectionFooterHeight">10</float>
<float key="IBUISectionHeaderHeight">22</float>
<float key="IBUISectionFooterHeight">22</float>
</object>
<object class="IBUIToolbar" id="895374018">
<reference key="NSNextResponder" ref="774585933"/>

BIN
media/iphone/folder.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 521 B