Permalink
Browse files

Open source release of App Store version 2.1

 	modified:   WhiteHouseApp.xcodeproj/project.pbxproj
 	modified:   WhiteHouseApp/AppConfig.plist
 	modified:   WhiteHouseApp/WHAppDelegate.h
 	modified:   WhiteHouseApp/WHAppDelegate.m
 	modified:   WhiteHouseApp/WHArticleViewController.m
 	modified:   WhiteHouseApp/WHBlogViewController.m
 	modified:   WhiteHouseApp/WHFavoritesViewController.m
 	modified:   WhiteHouseApp/WHFeed.m
 	modified:   WhiteHouseApp/WHFeedCache.h
 	modified:   WhiteHouseApp/WHFeedCache.m
 	modified:   WhiteHouseApp/WHLiveController.h
 	modified:   WhiteHouseApp/WHLiveController.m
 	modified:   WhiteHouseApp/WHLiveFeedViewController.m
 	modified:   WhiteHouseApp/WHPhotoGalleryViewController.m
 	modified:   WhiteHouseApp/WHPhotoViewController.m
 	modified:   WhiteHouseApp/WHReaderPanelView.m
 	modified:   WhiteHouseApp/WHReaderViewController.m
 	modified:   WhiteHouseApp/WHRemoteFile.m
 	modified:   WhiteHouseApp/WHRevealViewController.m
 	modified:   WhiteHouseApp/WHRootMenuViewController.m
 	modified:   WhiteHouseApp/WHThumbnailView.m
 	modified:   WhiteHouseApp/WHTrendyView.h
 	modified:   WhiteHouseApp/WHTrendyView.m
 	modified:   WhiteHouseApp/WHYouTubePlayerViewController.m
 	modified:   WhiteHouseApp/WhiteHouseApp-Info.plist
 	modified:   WhiteHouseApp/WhiteHouseApp-Prefix.pch
 	new file:   WhiteHouseApp/noise800.png
 	new file:   WhiteHouseApp/vignette.png
  • Loading branch information...
1 parent edf77d9 commit d27bea6ace89332b752adccf7dc63afa8ffde739 Bryan Hirsch committed Oct 19, 2012

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -34,5 +34,7 @@
<string>//p | //div[not(starts-with(@class, &apos;field&apos;))]</string>
<key>ArticleBaseURL</key>
<string>http://www.example.com/</string>
+ <key>LiveFeedUpdateFrequency</key>
+ <integer>60</integer>
</dict>
</plist>
@@ -32,6 +32,7 @@
#import <UIKit/UIKit.h>
+#import "Facebook.h"
#import "WHRootMenuViewController.h"
#import "WHLiveBarController.h"
#import "WHRevealViewController.h"
@@ -179,7 +179,8 @@ - (WHRootMenuViewController *)loadMenu
viewController = self.liveSectionViewController;
liveSectionMenuIndex = currentIndex;
- self.liveController = [[WHLiveController alloc] initWithFeed:feed];
+ NSInteger freq = [AppConfig(@"LiveFeedUpdateFrequency") integerValue];
+ self.liveController = [[WHLiveController alloc] initWithFeed:feed updateFrequency:freq];
self.liveBarController = [[WHLiveBarController alloc] init];
}
@@ -271,11 +272,9 @@ - (void)application:(UIApplication *)application didRegisterForRemoteNotificatio
UATagTypeLanguage |
UATagTypeCountry |
UATagTypeDeviceType)];
-
- // and specify the new version of the app, so we can send appropriate notifications
+ // specify the new version of the app, so we can send appropriate notifications
NSArray *tags = [baseTags arrayByAddingObject:@"app_v2"];
[UAPush shared].tags = tags;
-
[[UAPush shared] registerDeviceToken:deviceToken];
}
@@ -398,7 +397,7 @@ - (void)initFacebook
return;
}
- NSString *fbID = AppConfig(@"FacebookAppID");
+ NSString *fbID = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"FacebookAppID"];
if (fbID) {
// facebook
self.facebook = [[Facebook alloc] initWithAppId:fbID andDelegate:self];
@@ -411,6 +410,8 @@ - (void)initFacebook
self.facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}
+ self.facebook.sessionDelegate = self;
+
[self.facebook authorize:nil];
}
@@ -210,11 +210,4 @@ - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)
return YES;
}
-
-- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
-{
- DebugLog(@"web view rotation...?");
- return toInterfaceOrientation == UIInterfaceOrientationPortrait || UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
-}
-
@end
@@ -154,7 +154,7 @@ - (NSURL *)thumbnailURLForItem:(WHFeedItem *)item
- (CGSize)sizeForTitleText:(NSString *)text
{
- CGFloat titleWidth = self.view.bounds.size.width - (CELL_PADDING + CELL_PADDING_RIGHT);
+ CGFloat titleWidth = self.tableView.bounds.size.width - (CELL_PADDING + CELL_PADDING_RIGHT);
return [text sizeWithFont:[WHStyle headingFontWithSize:TITLE_FONT_SIZE] constrainedToSize:CGSizeMake(titleWidth, 1000) lineBreakMode:UILineBreakModeWordWrap];
}
@@ -220,12 +220,12 @@ - (UITableViewCell *)createMediaCell
[imageView sizeToFit];
imageView.tag = TAG_IMAGE;
imageView.contentMode = UIViewContentModeScaleAspectFill;
+ imageView.clipsToBounds = YES;
imageView.delegate = self;
cell.backgroundView = imageView;
CGRect barFrame = CGRectMake(0, PHOTO_V_PADDING + PHOTO_HEIGHT - ROW_HEIGHT, 320, ROW_HEIGHT);
UIView *blackBar = [[UIView alloc] initWithFrame:barFrame];
- blackBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
blackBar.tag = TAG_LABEL_CONTAINER;
blackBar.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.75];
[cell.contentView addSubview:blackBar];
@@ -234,7 +234,7 @@ - (UITableViewCell *)createMediaCell
cell.selectedBackgroundView.backgroundColor = [UIColor colorWithHue:(211.0 / 360.0) saturation:0.99 brightness:0.93 alpha:0.8];
DTCustomColoredAccessory *arrow = [DTCustomColoredAccessory accessoryWithColor:[UIColor whiteColor]];
- arrow.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleRightMargin;
+ arrow.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin;
CGRect arrowFrame = arrow.frame;
arrowFrame.origin = CGPointMake(297, 30);
arrow.frame = arrowFrame;
@@ -318,7 +318,7 @@ - (void)configureMediaCell:(UITableViewCell *)cell forFeedItem:(WHFeedItem *)ite
UIView *labelContaier = [cell viewWithTag:TAG_LABEL_CONTAINER];
CGFloat containerHeight = TITLE_Y + titleSize.height + CELL_PADDING;
- labelContaier.frame = CGRectMake(0, PHOTO_ROW_HEIGHT - containerHeight, 320, containerHeight);
+ labelContaier.frame = CGRectMake(0, PHOTO_ROW_HEIGHT - containerHeight, cell.contentView.bounds.size.width, containerHeight);
UILabel *dateView = (UILabel *)[cell viewWithTag:TAG_DATE];
dateView.text = RelativeDateString(item.pubDate);
@@ -345,6 +345,7 @@ - (void)configureCell:(UITableViewCell *)cell forFeedItem:(WHFeedItem *)item
UILabel *titleLabel = (UILabel *)[cell viewWithTag:TAG_TITLE];
CGSize titleSize = [self sizeForTitleText:item.title];
titleLabel.frame = CGRectMake(CELL_PADDING, TITLE_Y, titleSize.width, titleSize.height);
+ titleLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
titleLabel.text = item.title;
UILabel *dateView = (UILabel *)[cell viewWithTag:TAG_DATE];
@@ -401,10 +402,16 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
}
-- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
+- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
- DebugLog(@"blog view should rotate?");
- return toInterfaceOrientation == UIInterfaceOrientationPortrait;
+ [self.tableView reloadData];
+}
+
+
+- (void)viewWillAppear:(BOOL)animated
+{
+ [super viewWillAppear:animated];
+ [self.tableView reloadData];
}
@@ -33,6 +33,7 @@
#import "WHFavoritesViewController.h"
#import "UIViewController+WHFeedItemPresentation.h"
+#import "WHPhotoViewController.h"
#import "WHFeedCollection.h"
#import "WHTrendyView.h"
#import "WHFeedCache.h"
@@ -59,6 +60,7 @@ - (void)reloadFavorites
NSMutableDictionary *favoritesDict = [NSMutableDictionary dictionary];
for (WHFeed *feed in feeds) {
NSSet *favorites = [feed favorites];
+ DebugLog(@"Feed %@ has %i favorites", feed.feedURL, favorites.count);
if ([favorites count]) {
[feedsWithFavorites addObject:feed];
[favoritesDict setObject:favorites forKey:feed.feedURL];
@@ -90,14 +92,15 @@ - (void)viewDidLoad
self.tableView = tableView;
WHTrendyView *zeroState = [[WHTrendyView alloc] initWithFrame:self.view.bounds];
- zeroState.startColor = [UIColor colorWithWhite:0.7 alpha:1.0];
- zeroState.endColor = [UIColor colorWithWhite:1.0 alpha:1.0];
+ zeroState.backgroundColor = [UIColor whiteColor];
+ zeroState.autoresizingMask = UIViewAutoresizingFlexibleDimensions;
[self.view addSubview:zeroState];
self.zeroStateView = zeroState;
UIImageView *messageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"favorites-zero-state"]];
messageView.center = zeroState.center;
messageView.frame = CGRectOffset(messageView.frame, 0, 0.5);
+ messageView.autoresizingMask = UIViewAutoresizingFlexibleMargins;
[zeroState addSubview:messageView];
DebugLog(@"view bounds = %@", NSStringFromCGRect(self.view.bounds));
@@ -128,12 +131,6 @@ - (void)viewWillAppear:(BOOL)animated
}
-- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
-{
- return (interfaceOrientation == UIInterfaceOrientationPortrait);
-}
-
-
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
@@ -216,7 +213,18 @@ - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
WHFeedItem *item = [self favoriteForRowAtIndexPath:indexPath];
- [self displayFeedItem:item];
+ if (item.mediaContents.count) {
+ // handle the image selection here
+ WHPhotoViewController *photoView = [[WHPhotoViewController alloc] initWithNibName:nil bundle:nil];
+ photoView.feedItems = [self favesForSection:indexPath.section];
+ [self.navigationController pushViewController:photoView animated:YES];
+ [photoView.photoAlbumView moveToPageAtIndex:[photoView.feedItems indexOfObject:item] animated:NO];
+ photoView.toolbarIsTranslucent = YES;
+ photoView.hidesChromeWhenScrolling = YES;
+ photoView.chromeCanBeHidden = YES;
+ } else {
+ [self displayFeedItem:item];
+ }
}
View
@@ -33,21 +33,29 @@
#import "WHFeed.h"
#import "WHFeedCache.h"
+#import "WHRemoteFile.h"
NSString* const WHFeedChangedNotification = @"WHFeedChangedNotification";
+
+@interface WHFeed ()
+@property (nonatomic, strong) WHRemoteFile *cache;
+@end
+
@implementation WHFeed
@synthesize feedURL = _feedURL;
@synthesize items = _items;
@synthesize title;
@synthesize isDatabaseBacked;
@synthesize lastUpdatedDate;
+@synthesize cache = _cache;
- (id)initWithFeedURL:(NSURL *)feedURL
{
if ((self = [super init])) {
self.feedURL = feedURL;
+ self.cache = [[WHRemoteFile alloc] initWithBundleResource:nil ofType:nil remoteURL:self.feedURL];
_queue = dispatch_queue_create("gov.eop.wh.feed_loading", NULL);
}
@@ -63,55 +71,44 @@ - (void)notify
}
+- (NSSet *)parseFeedData:(NSData *)data
+{
+ NSMutableSet *items = [NSMutableSet set];
+ WHFeedParser *parser = [[WHFeedParser alloc] initWithFeedData:data];
+ [parser parse: ^(WHFeedItem *item) {
+ item.feedURL = self.feedURL;
+ [items addObject:item];
+ }];
+ return items;
+}
+
+
- (void)internalFetch
{
- if (self.isDatabaseBacked && self.items == nil) {
- NSSet *databaseItems = [[WHFeedCache sharedCache] cachedItemsForURL:self.feedURL];
- if ([databaseItems count])
- {
- self.items = databaseItems;
+ if (self.items == nil && self.isDatabaseBacked) {
+ DebugLog(@"%@ Loading local cache", self.feedURL);
+ self.items = [self parseFeedData:[self.cache data]];
+ if (self.items.count) {
+ DebugLog(@"%@ Had %i cached items", self.feedURL, self.items.count);
[self notify];
}
}
- NSData *feedData = [NSData dataWithContentsOfURL:self.feedURL];
- if (feedData) {
- NSMutableDictionary *itemsByGUID = [NSMutableDictionary dictionaryWithCapacity:self.items.count];
- for (WHFeedItem *item in self.items) {
- [itemsByGUID setObject:item forKey:item.guid];
- }
-
- WHFeedParser *parser = [[WHFeedParser alloc] initWithFeedData:feedData];
-
- // parse with block callback
- [parser parse: ^(WHFeedItem *item) {
- WHFeedItem *existingItem = [itemsByGUID objectForKey:item.guid];
- if (![existingItem isEqualToFeedItem:item]) {
- item.feedURL = self.feedURL;
-
- if (existingItem) {
- // make sure to maintain this when items are replaced
- item.isFavorited = existingItem.isFavorited;
- }
-
- [[WHFeedCache sharedCache] saveFeedItem:item];
- [itemsByGUID setObject:item forKey:item.guid];
- }
- }];
-
- self.items = [NSSet setWithArray:[itemsByGUID allValues]];
+ DebugLog(@"Updating from URL");
+ [self.cache updateWithValidator:^BOOL(NSData *remoteData) {
+ DebugLog(@"%@ Got feed data (%i bytes)", self.feedURL, remoteData.length);
+ self.items = [self parseFeedData:remoteData];
+ self.lastUpdatedDate = [NSDate date];
[self notify];
- }
+ return self.isDatabaseBacked;
+ }];
}
- (void)fetch
{
- self.lastUpdatedDate = [NSDate date];
dispatch_async(_queue, ^{
- NINetworkActivityTaskDidStart();
[self internalFetch];
- NINetworkActivityTaskDidFinish();
});
}
@@ -55,11 +55,6 @@
*/
+ (WHFeedCache *)sharedCache;
-/**
- * Return all feed items for the given URL (blocking)
- */
-- (NSSet *)cachedItemsForURL:(NSURL *)feedURL;
-
- (NSSet *)favoritedItemsForURL:(NSURL *)feedURL;
/**
Oops, something went wrong.

0 comments on commit d27bea6

Please sign in to comment.