mirror of
https://github.com/viq/NewsBlur.git
synced 2025-09-18 21:43:31 +00:00
adding share and keyboard logic
This commit is contained in:
parent
ce1a110449
commit
326a1f590f
7 changed files with 113 additions and 122 deletions
|
@ -23,8 +23,11 @@
|
|||
|
||||
- (void)transitionToFeedDetail;
|
||||
- (void)transitionFromFeedDetail;
|
||||
- (void)transitionToShareView;
|
||||
- (void)transitionFromShareView;
|
||||
|
||||
- (void)dragStoryToolbar:(int)yCoordinate;
|
||||
- (void)showUserProfilePopover:(id)sender;
|
||||
- (void)slideUpKeyboard;
|
||||
|
||||
@end
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#define NB_DEFAULT_MASTER_WIDTH 270
|
||||
#define NB_DEFAULT_STORY_TITLE_HEIGHT 1024 - 591
|
||||
#define NB_DEFAULT_SLIDER_INTERVAL 0.4
|
||||
#define NB_DEFAULT_SHARE_HEIGHT 120
|
||||
|
||||
@interface NBContainerViewController ()
|
||||
|
||||
|
@ -30,6 +31,7 @@
|
|||
@property (nonatomic, strong) UIView *storyTitlesStub;
|
||||
@property (readwrite) int storyTitlesYCoordinate;
|
||||
@property (readwrite) BOOL storyTitlesOnLeft;
|
||||
@property (readwrite) BOOL isSharingStory;
|
||||
@property (nonatomic, strong) UIPopoverController *popoverController;
|
||||
|
||||
@property (readwrite) BOOL feedDetailIsVisible;
|
||||
|
@ -51,6 +53,7 @@
|
|||
@synthesize storyTitlesOnLeft;
|
||||
@synthesize popoverController;
|
||||
@synthesize storyTitlesStub;
|
||||
@synthesize isSharingStory;
|
||||
|
||||
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
|
||||
{
|
||||
|
@ -69,7 +72,8 @@
|
|||
[super viewDidLoad];
|
||||
// Do any additional setup after loading the view.
|
||||
|
||||
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShowOrHide:) name:UIKeyboardWillShowNotification object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShowOrHide:) name:UIKeyboardWillHideNotification object:nil];
|
||||
|
||||
self.view.backgroundColor = [UIColor blackColor];
|
||||
|
||||
|
@ -78,6 +82,7 @@
|
|||
self.dashboardViewController = appDelegate.dashboardViewController;
|
||||
self.feedDetailViewController = appDelegate.feedDetailViewController;
|
||||
self.storyDetailViewController = appDelegate.storyDetailViewController;
|
||||
self.shareViewController = appDelegate.shareViewController;
|
||||
|
||||
// adding dashboardViewController
|
||||
[self addChildViewController:self.dashboardViewController];
|
||||
|
@ -128,6 +133,10 @@
|
|||
[super viewDidAppear:animated];
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
}
|
||||
|
||||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
||||
return YES;
|
||||
}
|
||||
|
@ -374,6 +383,40 @@
|
|||
}
|
||||
}
|
||||
|
||||
- (void)transitionToShareView {
|
||||
if (isSharingStory) {
|
||||
return;
|
||||
} else {
|
||||
CGRect vb = [self.view bounds];
|
||||
self.isSharingStory = YES;
|
||||
|
||||
// adding feedDetailViewController
|
||||
[self addChildViewController:self.shareViewController];
|
||||
[self.view addSubview:self.shareViewController.view];
|
||||
[self.shareViewController didMoveToParentViewController:self];
|
||||
|
||||
self.shareViewController.view.frame = CGRectMake(self.storyNavigationController.view.frame.origin.x, vb.size.height, self.storyDetailViewController.view.frame.size.width, NB_DEFAULT_SHARE_HEIGHT);
|
||||
[self performSelector:@selector(slideUpKeyboard) withObject:self afterDelay:.350];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)transitionFromShareView {
|
||||
if (!isSharingStory) {
|
||||
return;
|
||||
} else {
|
||||
CGRect vb = [self.view bounds];
|
||||
self.isSharingStory = NO;
|
||||
[UIView animateWithDuration:NB_DEFAULT_SLIDER_INTERVAL delay:0 options:UIViewAnimationOptionCurveLinear animations:^{
|
||||
self.shareViewController.view.frame = CGRectMake(self.storyNavigationController.view.frame.origin.x, vb.size.height, self.storyDetailViewController.view.frame.size.width, NB_DEFAULT_SHARE_HEIGHT);
|
||||
} completion:^(BOOL finished) {
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)slideUpKeyboard {
|
||||
[self.shareViewController.commentField becomeFirstResponder];
|
||||
}
|
||||
|
||||
- (void)dragStoryToolbar:(int)yCoordinate {
|
||||
|
||||
CGRect vb = [self.view bounds];
|
||||
|
@ -416,4 +459,52 @@
|
|||
}
|
||||
}
|
||||
|
||||
-(void)keyboardWillShowOrHide:(NSNotification*)notification {
|
||||
NSDictionary *userInfo = notification.userInfo;
|
||||
NSTimeInterval duration = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
|
||||
UIViewAnimationCurve curve = [[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue];
|
||||
|
||||
CGRect vb = [self.view bounds];
|
||||
CGRect keyboardFrame = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
|
||||
CGRect shareViewFrame = self.shareViewController.view.frame;
|
||||
CGRect storyDetailViewFrame = self.storyNavigationController.view.frame;
|
||||
|
||||
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
|
||||
|
||||
if ([notification.name isEqualToString:@"UIKeyboardWillShowNotification"]) {
|
||||
if (UIInterfaceOrientationIsPortrait(orientation)) {
|
||||
shareViewFrame.origin.y = vb.size.height - NB_DEFAULT_SHARE_HEIGHT - keyboardFrame.size.height;
|
||||
storyDetailViewFrame.size.height = vb.size.height - NB_DEFAULT_SHARE_HEIGHT - keyboardFrame.size.height + 44;
|
||||
} else {
|
||||
shareViewFrame.origin.y = vb.size.height - NB_DEFAULT_SHARE_HEIGHT - keyboardFrame.size.width;
|
||||
storyDetailViewFrame.size.height = vb.size.height - NB_DEFAULT_SHARE_HEIGHT - keyboardFrame.size.width + 44;
|
||||
}
|
||||
} else {
|
||||
if (UIInterfaceOrientationIsPortrait(orientation)) {
|
||||
shareViewFrame.origin.y = vb.size.height - NB_DEFAULT_SHARE_HEIGHT - keyboardFrame.size.height;
|
||||
storyDetailViewFrame.size.height = vb.size.height - NB_DEFAULT_SHARE_HEIGHT - keyboardFrame.size.height + 44;
|
||||
} else {
|
||||
shareViewFrame.origin.y = vb.size.height - NB_DEFAULT_SHARE_HEIGHT;
|
||||
storyDetailViewFrame.size.height = vb.size.height - NB_DEFAULT_SHARE_HEIGHT + 44;
|
||||
}
|
||||
}
|
||||
|
||||
if ([notification.name isEqualToString:@"UIKeyboardWillHideNotification"]) {
|
||||
self.storyNavigationController.view.frame = storyDetailViewFrame;
|
||||
}
|
||||
|
||||
[UIView animateWithDuration:duration
|
||||
delay:0
|
||||
options:UIViewAnimationOptionBeginFromCurrentState | curve
|
||||
animations:^{
|
||||
self.shareViewController.view.frame = shareViewFrame;
|
||||
|
||||
} completion:^(BOOL finished) {
|
||||
if ([notification.name isEqualToString:@"UIKeyboardWillShowNotification"]) {
|
||||
self.storyNavigationController.view.frame = storyDetailViewFrame;
|
||||
[self.storyDetailViewController scrolltoBottom];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
@end
|
|
@ -72,7 +72,6 @@
|
|||
NSString * activeUserProfileId;
|
||||
BOOL isRiverView;
|
||||
BOOL isSocialView;
|
||||
BOOL isShowingShare;
|
||||
BOOL popoverHasFeedView;
|
||||
BOOL inFeedDetail;
|
||||
BOOL inFindingStoryMode;
|
||||
|
@ -139,7 +138,6 @@
|
|||
@property (nonatomic, readwrite) BOOL isSocialView;
|
||||
@property (nonatomic, readwrite) BOOL inFindingStoryMode;
|
||||
@property (nonatomic) NSString *tryFeedStoryId;
|
||||
@property (nonatomic, readwrite) BOOL isShowingShare;
|
||||
@property (nonatomic, readwrite) BOOL popoverHasFeedView;
|
||||
@property (nonatomic, readwrite) BOOL inFeedDetail;
|
||||
@property (readwrite) NSDictionary * activeFeed;
|
||||
|
@ -195,7 +193,6 @@
|
|||
- (void)loadStoryDetailView;
|
||||
- (void)adjustStoryDetailWebView;
|
||||
- (void)calibrateStoryTitles;
|
||||
- (void)adjustShareModal;
|
||||
- (void)reloadFeedsView:(BOOL)showLoader;
|
||||
- (void)hideNavigationBar:(BOOL)animated;
|
||||
- (void)showNavigationBar:(BOOL)animated;
|
||||
|
|
|
@ -62,7 +62,6 @@
|
|||
@synthesize activeUserProfileId;
|
||||
@synthesize isRiverView;
|
||||
@synthesize isSocialView;
|
||||
@synthesize isShowingShare;
|
||||
@synthesize inFindingStoryMode;
|
||||
@synthesize tryFeedStoryId;
|
||||
@synthesize popoverHasFeedView;
|
||||
|
@ -245,55 +244,16 @@
|
|||
setUserId:(NSString *)userId
|
||||
setUsername:(NSString *)username
|
||||
setCommentIndex:(NSString *)commentIndex {
|
||||
self.isShowingShare = YES;
|
||||
|
||||
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
||||
// // add shareViewController to storyDetail
|
||||
// [self.storyDetailContainerViewController.view addSubview:self.shareViewController.view];
|
||||
// [self.shareViewController setSiteInfo:type setUserId:userId setUsername:username setCommentIndex:commentIndex];
|
||||
//
|
||||
//
|
||||
// self.shareViewController.view.frame = CGRectMake(0,
|
||||
// self.storyDetailContainerViewController.view.frame.size.height,
|
||||
// self.storyDetailContainerViewController.view.frame.size.width,
|
||||
// 0);
|
||||
//
|
||||
// int newShareYCoordinate = self.storyDetailContainerViewController.view.frame.size.height - SHARE_MODAL_HEIGHT;
|
||||
// int newStoryHeight = self.storyDetailContainerViewController.view.frame.size.height - SHARE_MODAL_HEIGHT + 44;
|
||||
//
|
||||
// [UIView animateWithDuration:0.35 animations:^{
|
||||
// self.shareViewController.view.frame = CGRectMake(0,
|
||||
// newShareYCoordinate,
|
||||
// self.storyDetailContainerViewController.view.frame.size.width,
|
||||
// SHARE_MODAL_HEIGHT);
|
||||
// self.storyDetailViewController.view.frame = CGRectMake(0,
|
||||
// 0,
|
||||
// self.storyDetailContainerViewController.view.frame.size.width,
|
||||
// newStoryHeight);
|
||||
// } completion:^(BOOL finished) {
|
||||
// [self.shareViewController.commentField becomeFirstResponder];
|
||||
// }];
|
||||
[self.shareViewController setSiteInfo:type setUserId:userId setUsername:username setCommentIndex:commentIndex];
|
||||
[self.masterContainerViewController transitionToShareView];
|
||||
} else {
|
||||
[self.navigationController presentModalViewController:self.shareViewController animated:YES];
|
||||
[self.shareViewController setSiteInfo:type setUserId:userId setUsername:username setCommentIndex:commentIndex];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)adjustShareModal {
|
||||
if (self.isShowingShare) {
|
||||
int newShareYCoordinate = storyDetailViewController.view.frame.size.height - SHARE_MODAL_HEIGHT;
|
||||
int newStoryHeight = storyDetailViewController.view.frame.size.height - SHARE_MODAL_HEIGHT;
|
||||
shareViewController.view.frame = CGRectMake(0,
|
||||
newShareYCoordinate,
|
||||
storyDetailViewController.view.frame.size.width,
|
||||
SHARE_MODAL_HEIGHT);
|
||||
storyDetailViewController.webView.frame = CGRectMake(0,
|
||||
0,
|
||||
storyDetailViewController.view.frame.size.width,
|
||||
newStoryHeight);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)hideShareView:(BOOL)resetComment {
|
||||
if (resetComment) {
|
||||
self.shareViewController.commentField.text = @"";
|
||||
|
@ -301,21 +261,8 @@
|
|||
|
||||
[self.shareViewController.commentField resignFirstResponder];
|
||||
|
||||
self.isShowingShare = NO;
|
||||
|
||||
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
||||
// [UIView animateWithDuration:0.35 animations:^{
|
||||
// shareViewController.view.frame = CGRectMake(0,
|
||||
// storyDetailContainerViewController.view.frame.size.height,
|
||||
// storyDetailContainerViewController.view.frame.size.width,
|
||||
// 0);
|
||||
// storyDetailViewController.view.frame = CGRectMake(0,
|
||||
// 0,
|
||||
// storyDetailContainerViewController.view.frame.size.width,
|
||||
// storyDetailContainerViewController.view.frame.size.height);
|
||||
// } completion:^(BOOL finished) {
|
||||
// [shareViewController.view removeFromSuperview];
|
||||
// }];
|
||||
[self.masterContainerViewController transitionFromShareView];
|
||||
} else {
|
||||
[self.navigationController dismissModalViewControllerAnimated:YES];
|
||||
}
|
||||
|
@ -537,8 +484,6 @@
|
|||
}
|
||||
|
||||
- (void)adjustStoryDetailWebView {
|
||||
[self adjustShareModal];
|
||||
|
||||
// UIView *titleLabel = [self makeFeedTitle:self.activeFeed];
|
||||
// if (storyDetailViewController.navigationItem){
|
||||
// storyDetailViewController.navigationItem.titleView = titleLabel;
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#import <UIKit/UIKit.h>
|
||||
#import "NewsBlurAppDelegate.h"
|
||||
|
||||
@interface ShareViewController : UIViewController <ASIHTTPRequestDelegate> {
|
||||
@interface ShareViewController : UIViewController <ASIHTTPRequestDelegate, UITextViewDelegate> {
|
||||
NewsBlurAppDelegate *appDelegate;
|
||||
int activeCommentIndex;
|
||||
}
|
||||
|
@ -31,6 +31,6 @@
|
|||
- (void)finishAddComment:(ASIHTTPRequest *)request;
|
||||
- (void)finishAddReply:(ASIHTTPRequest *)request;
|
||||
- (void)requestFailed:(ASIHTTPRequest *)request;- (void)replaceStory:(NSDictionary *)newStory;
|
||||
- (NSString *) stringByStrippingHTML:(NSString *)s;
|
||||
- (NSString *)stringByStrippingHTML:(NSString *)s;
|
||||
|
||||
@end
|
||||
|
|
|
@ -70,21 +70,15 @@
|
|||
}
|
||||
|
||||
- (void)viewDidAppear:(BOOL)animated {
|
||||
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShowOrHide:) name:UIKeyboardWillShowNotification object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShowOrHide:) name:UIKeyboardWillHideNotification object:nil];
|
||||
} else {
|
||||
[self.commentField becomeFirstResponder];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
// if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
||||
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShowOrHide:) name:UIKeyboardWillShowNotification object:nil];
|
||||
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShowOrHide:) name:UIKeyboardWillHideNotification object:nil];
|
||||
// } else {
|
||||
// [self.commentField becomeFirstResponder];
|
||||
// }
|
||||
}
|
||||
|
||||
- (IBAction)doCancelButton:(id)sender {
|
||||
NSLog(@"do cancel buttom?");
|
||||
[commentField resignFirstResponder];
|
||||
[appDelegate hideShareView:NO];
|
||||
}
|
||||
|
||||
|
@ -110,8 +104,6 @@
|
|||
}
|
||||
|
||||
- (void)setSiteInfo:(NSString *)type setUserId:(NSString *)userId setUsername:(NSString *)username setCommentIndex:(NSString *)commentIndex {
|
||||
|
||||
|
||||
if ([type isEqualToString: @"edit-reply"]) {
|
||||
[submitButton setTitle:@"Save"];
|
||||
facebookButton.hidden = YES;
|
||||
|
@ -178,6 +170,8 @@
|
|||
[request setPostValue:feedIdStr forKey:@"feed_id"];
|
||||
[request setPostValue:storyIdStr forKey:@"story_id"];
|
||||
|
||||
|
||||
|
||||
NSString *comments = commentField.text;
|
||||
if ([comments length]) {
|
||||
[request setPostValue:comments forKey:@"comments"];
|
||||
|
@ -318,51 +312,12 @@
|
|||
[appDelegate refreshComments];
|
||||
}
|
||||
|
||||
-(void)keyboardWillShowOrHide:(NSNotification*)notification {
|
||||
NSDictionary *userInfo = notification.userInfo;
|
||||
NSTimeInterval duration = [[userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
|
||||
UIViewAnimationCurve curve = [[userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue];
|
||||
|
||||
// CGRect keyboardFrame = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
|
||||
|
||||
CGRect shareViewFrame = self.view.frame;
|
||||
CGRect storyDetailViewFrame = appDelegate.storyDetailViewController.webView.frame;
|
||||
|
||||
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
|
||||
|
||||
if ([notification.name isEqualToString:@"UIKeyboardWillShowNotification"]) {
|
||||
if (UIInterfaceOrientationIsPortrait(orientation)) {
|
||||
shareViewFrame.origin.y = 576;
|
||||
storyDetailViewFrame.size.height = 576;
|
||||
} else {
|
||||
shareViewFrame.origin.y = 232;
|
||||
storyDetailViewFrame.size.height = 232;
|
||||
}
|
||||
} else {
|
||||
if (UIInterfaceOrientationIsPortrait(orientation)) {
|
||||
shareViewFrame.origin.y = 840;
|
||||
storyDetailViewFrame.size.height = 840;
|
||||
} else {
|
||||
shareViewFrame.origin.y = 584;
|
||||
storyDetailViewFrame.size.height = 584;
|
||||
}
|
||||
}
|
||||
|
||||
[UIView animateWithDuration:duration
|
||||
delay:0
|
||||
options:UIViewAnimationOptionBeginFromCurrentState | curve
|
||||
animations:^{
|
||||
self.view.frame = shareViewFrame;
|
||||
appDelegate.storyDetailViewController.webView.frame = storyDetailViewFrame;
|
||||
} completion:^(BOOL finished) {
|
||||
[appDelegate.storyDetailViewController scrolltoBottom];
|
||||
|
||||
}];
|
||||
- (BOOL)canBecomeFirstResponder {
|
||||
return YES;
|
||||
}
|
||||
|
||||
-(NSString *)stringByStrippingHTML:(NSString *)s {
|
||||
- (NSString *)stringByStrippingHTML:(NSString *)s {
|
||||
NSRange r;
|
||||
|
||||
while ((r = [s rangeOfString:@"<[^>]+>" options:NSRegularExpressionSearch]).location != NSNotFound)
|
||||
s = [s stringByReplacingCharactersInRange:r withString:@""];
|
||||
return s;
|
||||
|
|
|
@ -180,7 +180,7 @@
|
|||
}
|
||||
|
||||
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
|
||||
[appDelegate.shareViewController.commentField resignFirstResponder];
|
||||
// [appDelegate.shareViewController.commentField resignFirstResponder];
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue