Skip to content

Commit 41e9942

Browse files
author
Joey Lorich
committed
Fix merge conflicts
2 parents de64671 + b129c63 commit 41e9942

3 files changed

Lines changed: 135 additions & 74 deletions

File tree

EasyReader/Application/Controllers/Home/CSHomeViewController.h

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,64 @@
77
//
88

99
#import <UIKit/UIKit.h>
10-
#import "CSBaseViewController.h"
10+
11+
// Controls
1112
#import "CSCollectionPageControl.h"
13+
#import "CSFeedItemCollectionView.h"
14+
15+
// View Controllers
16+
#import "CSBaseViewController.h"
1217
#import "CSFeedItemCollectionViewDataSource.h"
1318

1419
@class User;
1520

21+
/**
22+
* The home view controller for the application
23+
*/
1624
@interface CSHomeViewController : CSBaseViewController<UICollectionViewDelegate,UIScrollViewDelegate>
1725

26+
27+
# pragma mark - IBOutlet
28+
29+
/// Vertical scroll view holding collection view and webviews
1830
@property (weak, nonatomic) IBOutlet UIScrollView *verticalScrollView;
31+
32+
/// Button to go to left menu
1933
@property (strong, nonatomic) IBOutlet UIButton *button_leftMenu;
34+
35+
/// Feed position indicator
2036
@property (strong, nonatomic) IBOutlet CSCollectionPageControl *pageControl_itemIndicator;
37+
38+
/// The collection view which holds the individual feed items
39+
@property (strong, nonatomic) IBOutlet CSFeedItemCollectionView *collectionView_feedItems;
40+
41+
42+
# pragma mark - Properties
43+
44+
/// Displays website that hosts article
2145
@property (nonatomic, strong) UIWebView *feedItemWebView;
46+
47+
/// Feed items on user
2248
@property (nonatomic, strong) NSMutableSet *feedItems;
2349

50+
/// Current User
2451
@property (nonatomic, retain) User* currentUser;
52+
53+
/// Data source for Collection view
2554
@property CSFeedItemCollectionViewDataSource *feedCollectionViewDataSource;
55+
56+
/// Feed Item currently visible
2657
@property FeedItem *currentFeedItem;
58+
59+
/// Integer id for the Collection cell that user is scrolling to
2760
@property NSInteger collectionCellGoingTo;
2861

62+
63+
# pragma mark - Methods
64+
65+
/**
66+
* Scrolls through collection view to display whatever item is set to currentItem
67+
*/
2968
- (void)scrollToCurrentFeedItem;
3069

3170
@end

EasyReader/Application/Controllers/Home/CSHomeViewController.m

Lines changed: 92 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -7,49 +7,50 @@
77
//
88

99
#import "CSHomeViewController.h"
10+
11+
// Pods
1012
#import <Block-KVO/MTKObserving.h>
11-
#import "CSFeedItemCollectionView.h"
12-
#import "CSFeedItemCollectionViewDataSource.h"
13-
#import "FeedItem.h"
1413
#import "MFSideMenu.h"
15-
#import "CSFeedItemCell.h"
14+
15+
// Models
16+
#import "FeedItem.h"
1617
#import "Feed.h"
1718
#import "User.h"
1819
#import <AFNetworking/UIImageView+AFNetworking.h>
1920

2021

21-
@interface CSHomeViewController (){
22+
#import "CSFeedItemCell.h"
23+
24+
@interface CSHomeViewController ()
25+
{
2226
NSString *currentURL;
2327
}
24-
25-
/// The collection view which holds the individual feed items
26-
@property (nonatomic, weak) IBOutlet CSFeedItemCollectionView *collectionView_feedItems;
27-
2828
@end
2929

30-
3130
@implementation CSHomeViewController
3231

32+
/**
33+
* Set up data sctructures, controller views, add observers
34+
*/
3335
- (void)viewDidLoad
3436
{
3537
[super viewDidLoad];
3638
_feedItems = [[NSMutableSet alloc] init];
39+
3740
[_pageControl_itemIndicator setUpFadesOnView:[_pageControl_itemIndicator superview]];
3841
_pageControl_itemIndicator.controller_owner = self;
3942

40-
self.currentUser = [User current];
43+
self.currentUser = [User current];
4144

45+
[self setUpVerticalScrollView];
4246
[self setUpCollectionView];
4347
[self setUpWebView];
4448
[self setupFeedItemObserver];
45-
// Do any additional setup after loading the view.
46-
}
47-
48-
- (void)viewDidLayoutSubviews
49-
{
50-
[self setUpVerticalScrollView];
5149
}
5250

51+
/**
52+
* Assigns observers for feeds and feed items, puts page controller at start
53+
*/
5354
- (void) setupFeedItemObserver
5455
{
5556
[self observeRelationship:@keypath(self.currentUser.feeds)
@@ -112,11 +113,32 @@ - (void) setupFeedItemObserver
112113
removalBlock:nil
113114
replacementBlock:nil
114115
];
115-
116-
NSLog(@"observer added");
117116
}
118117

119-
// Sets up collection view on controller start up
118+
#pragma mark - IBActions
119+
120+
// Receives left menu link click
121+
- (IBAction)buttonLeftMenu_touchUpInside_goToMenu:(id)sender {
122+
[[self rootViewController] toggleLeftSideMenuCompletion:^{}];
123+
}
124+
125+
126+
/**
127+
* Sets up vertical scroll view on controller start up
128+
*/
129+
-(void)setUpVerticalScrollView{
130+
// Set contentSize to be twice the height of the scrollview
131+
NSInteger width = self.verticalScrollView.frame.size.width;
132+
NSInteger height = self.verticalScrollView.frame.size.height;
133+
self.verticalScrollView.contentSize = CGSizeMake(width, height*2);
134+
135+
self.verticalScrollView.pagingEnabled =YES;
136+
self.verticalScrollView.delegate = self;
137+
}
138+
139+
/**
140+
* Sets up collection view on controller start up
141+
*/
120142
- (void)setUpCollectionView
121143
{
122144
// NSArray *feedItems = [FeedItem MR_findAll];
@@ -129,18 +151,26 @@ - (void)setUpCollectionView
129151

130152
self.collectionView_feedItems.dataSource = _feedCollectionViewDataSource;
131153
self.collectionView_feedItems.delegate = self;
132-
133-
134154
}
135155

136-
#pragma mark - IBActions
137-
138-
// Receives left menu link click
139-
- (IBAction)buttonLeftMenu_touchUpInside_goToMenu:(id)sender {
140-
[[self rootViewController] toggleLeftSideMenuCompletion:^{}];
156+
/**
157+
* Sets up collection view on controller start up
158+
*/
159+
-(void)setUpWebView
160+
{
161+
// Create a new webview and place it below the collectionView
162+
self.feedItemWebView = [[UIWebView alloc] init];
163+
NSInteger width = self.verticalScrollView.frame.size.width;
164+
NSInteger height = self.verticalScrollView.frame.size.height;
165+
self.feedItemWebView.frame= CGRectMake(0, height, width, height*2);
166+
167+
// Add it to the bottom of the scrollView
168+
[self.verticalScrollView addSubview:self.feedItemWebView];
141169
}
142170

143-
171+
/**
172+
* Sets up collection cell to given feed item data
173+
*/
144174
- (configureFeedItemCell)configureFeedItem
145175
{
146176
return ^void(CSFeedItemCell *cell, FeedItem *feedItem) {
@@ -153,35 +183,49 @@ - (configureFeedItemCell)configureFeedItem
153183
};
154184
}
155185

156-
-(void)setUpVerticalScrollView{
157-
// Set contentSize to be twice the height of the scrollview
158-
NSInteger width = self.verticalScrollView.frame.size.width;
159-
NSInteger height = self.verticalScrollView.frame.size.height;
160-
self.verticalScrollView.contentSize = CGSizeMake(width, height*2);
186+
- (void)loadFeedItemWebView
187+
{
188+
// Check if this is a new url
189+
if(currentURL != self.collectionView_feedItems.currentFeedItem.url){
190+
// update the current url
191+
currentURL = self.collectionView_feedItems.currentFeedItem.url;
161192

162-
self.verticalScrollView.pagingEnabled =YES;
163-
self.verticalScrollView.delegate = self;
193+
// load the url in the webView
194+
NSURL *url = [NSURL URLWithString:currentURL];
195+
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
196+
[self.feedItemWebView loadRequest:requestObj];
197+
}
164198
}
165199

166-
-(void)setUpWebView
200+
# pragma mark - ScrollView methods
201+
202+
/**
203+
* Scroll to the currentFeedItem when the feedItems update
204+
*/
205+
- (void)scrollToCurrentFeedItem
167206
{
168-
// Create a new webview and place it below the collectionView
169-
self.feedItemWebView = [[UIWebView alloc] init];
170-
NSInteger width = self.verticalScrollView.frame.size.width;
171-
NSInteger height = self.verticalScrollView.frame.size.height;
172-
self.feedItemWebView.frame= CGRectMake(0, height, width, height*2);
173-
174-
// Add it to the bottom of the scrollView
175-
[self.verticalScrollView addSubview:self.feedItemWebView];
207+
NSUInteger index = [_feedCollectionViewDataSource.sortedFeedItems indexOfObject:_currentFeedItem];
208+
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:0];
209+
[_collectionView_feedItems scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];
176210
}
177211

212+
# pragma mark - ScrollView Delegate methods
213+
214+
/**
215+
* Scroll view delegate method for dragging view up into webview
216+
*/
178217
- (void)scrollViewWillBeginDragging:(UIScrollView *)sender {
179218
// If we are scrolling in the scrollView only not a subclass
180219
if([sender isMemberOfClass:[UIScrollView class]]) {
181220
[self loadFeedItemWebView];
182221
}
183222
}
184223

224+
# pragma mark - CollectionView Delegate methods
225+
226+
/**
227+
* Collection view delegate method for updating current feed item webview url
228+
*/
185229
- (void)scrollViewDidEndDecelerating:(UIScrollView *)sender {
186230
// If we are scrolling in the collectionView only
187231
if([sender isMemberOfClass:[CSFeedItemCollectionView class]]) {
@@ -193,15 +237,10 @@ - (void)scrollViewDidEndDecelerating:(UIScrollView *)sender {
193237
}
194238
}
195239

196-
// Scroll to the currentFeedItem when the feedItems update
197-
- (void)scrollToCurrentFeedItem
198-
{
199-
NSUInteger index = [_feedCollectionViewDataSource.sortedFeedItems indexOfObject:_currentFeedItem];
200-
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:0];
201-
[_collectionView_feedItems scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];
202-
}
203-
204-
240+
/**
241+
* Collection view delegate method for when a cell ends display
242+
* Sets page control indicator
243+
*/
205244
- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
206245
{
207246
NSInteger newIndex = indexPath.row+((indexPath.row-self.collectionCellGoingTo)*-1);
@@ -210,24 +249,4 @@ - (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(
210249
forCollection:_feedItems];
211250
}
212251

213-
- (void)loadFeedItemWebView
214-
{
215-
// Check if this is a new url
216-
if(currentURL != self.collectionView_feedItems.currentFeedItem.url){
217-
// update the current url
218-
currentURL = self.collectionView_feedItems.currentFeedItem.url;
219-
220-
// load the url in the webView
221-
NSURL *url = [NSURL URLWithString:currentURL];
222-
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
223-
[self.feedItemWebView loadRequest:requestObj];
224-
}
225-
}
226-
227-
- (void)didReceiveMemoryWarning
228-
{
229-
[super didReceiveMemoryWarning];
230-
// Dispose of any resources that can be recreated.
231-
}
232-
233252
@end

EasyReader/Application/Controls/CSCollectionPageControl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
#import <UIKit/UIKit.h>
1010
@class CSHomeViewController;
1111

12+
/**
13+
* Page control for multiple
14+
*/
1215
@interface CSCollectionPageControl : UIPageControl
1316

1417
@property CSHomeViewController *controller_owner;

0 commit comments

Comments
 (0)