Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions EasyReader/Application/Controllers/Home/EZRHomeViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
/// Displays website that hosts article
@property (nonatomic, strong) EZRNestableWebView *webView_feedItem;

/// The up indicator displayed over the web view to assist in navigating to the top of the page
@property (nonatomic, strong) UIImageView *upIndicatorView;


# pragma mark - Properties

Expand All @@ -60,9 +63,20 @@
* @param feedItem The feed item to
*/
- (void) loadURLForFeedItem:(FeedItem *)feedItem;

/**
* Resets the content of the web view
*/
- (void)resetWebView;

/**
* Hides the scroll up indicator
*/
- (void)hideUpInidicator;

/**
* Shows the scroll up indicator
*/
- (void)showUpInidicator;

@end
77 changes: 43 additions & 34 deletions EasyReader/Application/Controllers/Home/EZRHomeViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ @interface EZRHomeViewController()
/// The social sharing toolbar
@property (nonatomic, weak) IBOutlet CLDSocialShareToolbar *socialShareToolbar;

/// The up indicator displayed over the web view to assist in navigating to the top of the page
@property (nonatomic, strong) UIImageView *upIndicatorView;

@end


Expand Down Expand Up @@ -90,11 +87,43 @@ @implementation EZRHomeViewController
Feed *lastSelectedFeed;
}

#pragma mark - Public Methods

- (void)loadURLForFeedItem:(FeedItem *)feedItem
{
NSURL *url = [NSURL URLWithString:feedItem.url];
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30.0];

[self.webView_feedItem loadRequest:request];
}

- (void)resetWebView
{
[self.webView_feedItem stopLoading];

NSString *blankHTML = @"<html><head></head><body style=\"background-color: #000000;\"></body></html>";
[self.webView_feedItem loadHTMLString:blankHTML
baseURL:nil];
}

- (void)hideUpInidicator {
[UIView animateWithDuration:0.5f animations:^{
[self.upIndicatorView setAlpha:0.0f];
}];
}

- (void)showUpInidicator {
[UIView animateWithDuration:0.5f animations:^{
[self.upIndicatorView setAlpha:1.0f];
}];
}

- (FeedItem *)currentFeedItem
{
return self.collectionView_feedItems.currentFeedItem;
}


#pragma mark - UIViewController Methods

/**
Expand Down Expand Up @@ -263,12 +292,7 @@ -(void)setUpWebView
[self.upIndicatorView addGestureRecognizer:tapRecognizer];
}

/**
* Scrolls the main containing scroll view to the top (animated)
*/
- (void) scrollToTop {
[self.scrollView_vertical setContentOffset:CGPointMake(0,0) animated:YES];
}



#pragma mark - Observations
Expand Down Expand Up @@ -328,7 +352,7 @@ - (void) visibleFeedItemsDidChange:(EZRCurrentFeedsProvider *)currentFeedService
}


#pragma mark - IBActions
#pragma mark - Actions

// Receives left menu link click
- (IBAction)buttonLeftMenu_touchUpInside_goToMenu:(id)sender {
Expand Down Expand Up @@ -356,6 +380,15 @@ - (void)scrollToFeedItem:(FeedItem *)feedItem
[_collectionView_feedItems scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];
}

/**
* Scrolls the main containing scroll view to the top (animated)
*/
- (void) scrollToTop {
[self.scrollView_vertical setContentOffset:CGPointMake(0,0) animated:YES];
}

#pragma mark - Prefetching

/**
* Fetches the current feed item image, then prefetches after
*/
Expand Down Expand Up @@ -388,33 +421,9 @@ - (void)prefetchImagesNearIndex:(NSInteger)currentPageIndex count:(NSInteger)cou
NSArray *itemsToPrefetch = [self.currentFeedsProvider.visibleFeedItems subarrayWithRange:fetchRange];

[[EZRFeedImageService shared] prefetchImagesForFeedItems:itemsToPrefetch];

}

/**
* Loads the url for the new feed item in the web view
*
* @param feedItem The feed item to
*/
- (void) loadURLForFeedItem:(FeedItem *)feedItem
{
NSURL *url = [NSURL URLWithString:feedItem.url];
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30.0];

[self.webView_feedItem loadRequest:request];
}

/**
* Resets the content of the web view
*/
- (void)resetWebView
{
[self.webView_feedItem stopLoading];

NSString *blankHTML = @"<html><head></head><body style=\"background-color: #000000;\"></body></html>";
[self.webView_feedItem loadHTMLString:blankHTML
baseURL:nil];
}

@end

Expand Down
39 changes: 38 additions & 1 deletion EasyReader/Application/Controllers/Home/EZRHomeWebViewDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,17 @@

@implementation EZRHomeWebViewDelegate
{
/// The home view controller
EZRHomeViewController *controller;


/// The bar progress view
NJKWebViewProgressView *progressView;

/// Is the page currently being dragged
BOOL dragging;

/// The staring point of the current drag
CGPoint dragStart;
}

- (instancetype)initWithController:(EZRHomeViewController *)homeController
Expand All @@ -29,6 +37,12 @@ - (instancetype)initWithController:(EZRHomeViewController *)homeController
return self;
}


#pragma mark - NJKWebViewProgressDelegate methods

/**
* Adds the progress view object if it doesn't exist, update the progress
*/
- (void)webViewProgress:(NJKWebViewProgress *)webViewProgress updateProgress:(float)progress
{
if (!progressView) {
Expand All @@ -39,4 +53,27 @@ - (void)webViewProgress:(NJKWebViewProgress *)webViewProgress updateProgress:(fl
[progressView setProgress:progress animated:NO];
}


#pragma mark - UIScrollViewDelegate methods

/**
* Only allows the scroll-up indicator to be visible on the top 5% of the page or when the user is scrolling up
*/
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView.contentOffset.y > dragStart.y && scrollView.contentOffset.y > scrollView.contentSize.height*.05) {
[controller hideUpInidicator];
} else {
[controller showUpInidicator];
}
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
dragging = YES;
dragStart = scrollView.contentOffset;
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
dragging = NO;
}

@end