From c19e7e6a4b9c58b19a5e9b61d3914466091c0ce7 Mon Sep 17 00:00:00 2001 From: Roy Yang Date: Wed, 8 Aug 2012 19:31:33 -0700 Subject: [PATCH] adding in popover for actionsheet --- media/ios/Classes/FeedDetailViewController.m | 50 ++++++++++++++++++-- media/ios/Classes/ProfileBadge.h | 2 +- media/ios/Classes/ProfileBadge.m | 37 ++++++++++++++- media/ios/storyDetailView.css | 5 +- 4 files changed, 87 insertions(+), 7 deletions(-) diff --git a/media/ios/Classes/FeedDetailViewController.m b/media/ios/Classes/FeedDetailViewController.m index dceff9fc3..db0a95e29 100644 --- a/media/ios/Classes/FeedDetailViewController.m +++ b/media/ios/Classes/FeedDetailViewController.m @@ -28,6 +28,12 @@ #define kMarkReadActionSheet 1; #define kSettingsActionSheet 2; +@interface FeedDetailViewController () + +@property (nonatomic) UIActionSheet* actionSheet_; // add this line + +@end + @implementation FeedDetailViewController @synthesize popoverController; @@ -39,6 +45,7 @@ @synthesize pageFetching; @synthesize pageFinished; @synthesize intelligenceControl; +@synthesize actionSheet_; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { @@ -117,11 +124,18 @@ [super viewWillAppear:animated]; if ((appDelegate.isSocialRiverView || appDelegate.isRiverView || appDelegate.isSocialView) || - [appDelegate.activeFolder isEqualToString:@"Everything"]) { + [appDelegate.activeFolder isEqualToString:@"ALL STORIES"]) { settingsButton.enabled = NO; } else { settingsButton.enabled = YES; } + + if (appDelegate.isSocialRiverView || + [appDelegate.activeFolder isEqualToString:@"ALL STORIES"]) { + feedMarkReadButton.enabled = NO; + } else { + feedMarkReadButton.enabled = YES; + } if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) { [self.storyTitlesTable reloadData]; @@ -876,6 +890,13 @@ } - (IBAction)doOpenMarkReadActionSheet:(id)sender { + // already displaying action sheet? + if (self.actionSheet_) { + [self.actionSheet_ dismissWithClickedButtonIndex:-1 animated:YES]; + self.actionSheet_ = nil; + return; + } + // Individual sites just get marked as read, no action sheet needed. if (!appDelegate.isRiverView) { [self markFeedsReadWithAllStories:YES]; @@ -892,6 +913,8 @@ destructiveButtonTitle:nil otherButtonTitles:nil]; + self.actionSheet_ = options; + int visibleUnreadCount = appDelegate.visibleUnreadCount; int totalUnreadCount = [appDelegate unreadCount]; NSArray *buttonTitles = nil; @@ -924,7 +947,11 @@ options.cancelButtonIndex = [options addButtonWithTitle:@"Cancel"]; options.tag = kMarkReadActionSheet; - [options showInView:self.view]; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + [options showFromBarButtonItem:self.feedMarkReadButton animated:YES]; + } else { + [options showInView:self.view]; + } } - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { @@ -964,7 +991,18 @@ } } +- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex { + // just set to nil + actionSheet_ = nil; +} + - (IBAction)doOpenSettingsActionSheet { + // already displaying action sheet? + if (self.actionSheet_) { + [self.actionSheet_ dismissWithClickedButtonIndex:-1 animated:YES]; + self.actionSheet_ = nil; + return; + } NSString *title = appDelegate.isRiverView ? appDelegate.activeFolder : [appDelegate.activeFeed objectForKey:@"feed_title"]; @@ -975,6 +1013,8 @@ destructiveButtonTitle:nil otherButtonTitles:nil]; + self.actionSheet_ = options; + if (![title isEqualToString:@"Everything"]) { NSString *deleteText = [NSString stringWithFormat:@"Delete %@", appDelegate.isRiverView ? @@ -993,7 +1033,11 @@ options.cancelButtonIndex = [options addButtonWithTitle:@"Cancel"]; options.tag = kSettingsActionSheet; - [options showInView:self.view]; + if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { + [options showFromBarButtonItem:self.settingsButton animated:YES]; + } else { + [options showInView:self.view]; + } } - (void)confirmDeleteSite { diff --git a/media/ios/Classes/ProfileBadge.h b/media/ios/Classes/ProfileBadge.h index 83c4c5ccc..644d5bc10 100644 --- a/media/ios/Classes/ProfileBadge.h +++ b/media/ios/Classes/ProfileBadge.h @@ -37,7 +37,7 @@ @property ( nonatomic) NSDictionary *activeProfile; -- (void)refreshWithProfile:(NSDictionary *)profile showStats:(BOOL)showStats withWidth:(int)width; +- (void)refreshWithProfile:(NSDictionary *)profile showStats:(BOOL)showStats withWidth:(int)newWidth; - (IBAction)doFollowButton:(id)sender; - (void)finishFollowing:(ASIHTTPRequest *)request; diff --git a/media/ios/Classes/ProfileBadge.m b/media/ios/Classes/ProfileBadge.m index 19dd3b4ed..d33f9c7c3 100644 --- a/media/ios/Classes/ProfileBadge.m +++ b/media/ios/Classes/ProfileBadge.m @@ -16,6 +16,11 @@ #define kTopBadgeHeight 125 #define kTopBadgeTextXCoordinate 100 +@interface ProfileBadge () + @property (readwrite) int moduleWidth; + +@end + @implementation ProfileBadge @synthesize appDelegate; @@ -27,6 +32,7 @@ @synthesize followButton; @synthesize activeProfile; @synthesize activityIndicator; +@synthesize moduleWidth; - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { @@ -59,7 +65,18 @@ [super layoutSubviews]; } -- (void)refreshWithProfile:(NSDictionary *)profile showStats:(BOOL)showStats withWidth:(int)width { +- (void)refreshWithProfile:(NSDictionary *)profile showStats:(BOOL)showStats withWidth:(int)newWidth { + int width; + + if (newWidth) { + width = newWidth; + self.moduleWidth = newWidth; + } else { + width = self.moduleWidth; + for (UIView *subview in [self.contentView subviews]) { + [subview removeFromSuperview]; + } + } self.appDelegate = (NewsBlurAppDelegate *)[[UIApplication sharedApplication] delegate]; self.activeProfile = profile; int yCoordinatePointer = 0; @@ -314,6 +331,15 @@ [self.followButton setTitle:@"Following" forState:UIControlStateNormal]; [appDelegate reloadFeedsView:NO]; + + NSMutableDictionary *newProfile = [self.activeProfile mutableCopy]; + NSNumber *count = [newProfile objectForKey:@"follower_count"]; + int value = [count intValue]; + count = [NSNumber numberWithInt:value + 1]; + + [newProfile setObject:count forKey:@"follower_count"]; + [newProfile setObject:[NSNumber numberWithInt:1] forKey:@"followed_by_you"]; + [self refreshWithProfile:newProfile showStats:YES withWidth:0]; } @@ -335,6 +361,15 @@ NSLog(@"results %@", results); [self.followButton setTitle:@"Follow" forState:UIControlStateNormal]; [appDelegate reloadFeedsView:NO]; + + NSMutableDictionary *newProfile = [self.activeProfile mutableCopy]; + NSNumber *count = [newProfile objectForKey:@"follower_count"]; + int value = [count intValue]; + count = [NSNumber numberWithInt:value - 1]; + + [newProfile setObject:count forKey:@"follower_count"]; + [newProfile setObject:[NSNumber numberWithInt:0] forKey:@"followed_by_you"]; + [self refreshWithProfile:newProfile showStats:YES withWidth:0]; } - (void)requestFailed:(ASIHTTPRequest *)request diff --git a/media/ios/storyDetailView.css b/media/ios/storyDetailView.css index 015ac7401..f88f06de8 100644 --- a/media/ios/storyDetailView.css +++ b/media/ios/storyDetailView.css @@ -454,14 +454,14 @@ a.NB-show-profile { } .NB-button.NB-share-button div { - padding: 8px 40px 8px 14px; + padding: 8px 0px 8px; border-radius: 5px; text-align: center; background: -webkit-gradient( linear, left top, left bottom, from(#42aaff), to(#003366)); - padding-left: 40px; + box-shadow: inset 0 0 1px 1px rgba(255, 255, 255, 1) } .NB-button.NB-share-button div span { @@ -470,6 +470,7 @@ a.NB-show-profile { display: inline-block; height: 16px; margin-bottom: -2px; + margin-left: -23px; } .NB-iphone .NB-button .NB-story-comment-like-button-wrapper,