Skip to content

Commit 48c1f94

Browse files
Alfredo UribeAlfredo Uribe
authored andcommitted
separated page controller to own class
started adding fade removal on first and last two pages new feed item is broken Need to talk to Joey about animating better
1 parent 608fe73 commit 48c1f94

8 files changed

Lines changed: 146 additions & 65 deletions

File tree

EasyReader.xcodeproj/project.pbxproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
2751F4E218DA0D3000339C96 /* CSFeedItemCollectionViewDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 2751F4DD18DA0D3000339C96 /* CSFeedItemCollectionViewDataSource.m */; };
2222
2751F4E318DA0D3000339C96 /* CSFeedItemCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 2751F4DF18DA0D3000339C96 /* CSFeedItemCell.m */; };
2323
2751F4E418DA0D3000339C96 /* CSFeedItemCollectionView.m in Sources */ = {isa = PBXBuildFile; fileRef = 2751F4E118DA0D3000339C96 /* CSFeedItemCollectionView.m */; };
24+
8E685AA718DC733B00309270 /* CSCollectionPageControl.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E685AA618DC733B00309270 /* CSCollectionPageControl.m */; };
25+
8E685AA818DC733B00309270 /* CSCollectionPageControl.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E685AA618DC733B00309270 /* CSCollectionPageControl.m */; };
26+
8E685AA918DC733B00309270 /* CSCollectionPageControl.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E685AA618DC733B00309270 /* CSCollectionPageControl.m */; };
2427
8E7F403218D3596C00A6FED6 /* CSResponsiveApiRequestor.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E7F403118D3596C00A6FED6 /* CSResponsiveApiRequestor.m */; };
2528
8E7F81F018D0BF8500BC50C2 /* CSBaseObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 8E7F81EF18D0BF8500BC50C2 /* CSBaseObject.m */; };
2629
9D140BF5171F68E000CDD319 /* button_add@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 9D140BF4171F68E000CDD319 /* button_add@2x.png */; };
@@ -248,6 +251,8 @@
248251
2751F4E118DA0D3000339C96 /* CSFeedItemCollectionView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CSFeedItemCollectionView.m; sourceTree = "<group>"; };
249252
5CECD14CAE964A1994399D15 /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = SOURCE_ROOT; };
250253
8E1CE42418D0F5A00090028E /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; };
254+
8E685AA518DC733B00309270 /* CSCollectionPageControl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CSCollectionPageControl.h; path = EasyReader/Application/Controls/CSCollectionPageControl.h; sourceTree = SOURCE_ROOT; };
255+
8E685AA618DC733B00309270 /* CSCollectionPageControl.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CSCollectionPageControl.m; path = EasyReader/Application/Controls/CSCollectionPageControl.m; sourceTree = SOURCE_ROOT; };
251256
8E7F403018D3596C00A6FED6 /* CSResponsiveApiRequestor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CSResponsiveApiRequestor.h; path = Api/CSResponsiveApiRequestor.h; sourceTree = "<group>"; };
252257
8E7F403118D3596C00A6FED6 /* CSResponsiveApiRequestor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CSResponsiveApiRequestor.m; path = Api/CSResponsiveApiRequestor.m; sourceTree = "<group>"; };
253258
8E7F81EE18D0BF8500BC50C2 /* CSBaseObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSBaseObject.h; sourceTree = "<group>"; };
@@ -428,6 +433,15 @@
428433
name = Api;
429434
sourceTree = "<group>";
430435
};
436+
8E685AA418DC724000309270 /* Controls */ = {
437+
isa = PBXGroup;
438+
children = (
439+
8E685AA518DC733B00309270 /* CSCollectionPageControl.h */,
440+
8E685AA618DC733B00309270 /* CSCollectionPageControl.m */,
441+
);
442+
name = Controls;
443+
sourceTree = "<group>";
444+
};
431445
9D16D30A18DA2E49001E9C38 /* Application */ = {
432446
isa = PBXGroup;
433447
children = (
@@ -667,6 +681,7 @@
667681
9DAC1717170A043200383722 /* Application */ = {
668682
isa = PBXGroup;
669683
children = (
684+
8E685AA418DC724000309270 /* Controls */,
670685
2751F4D118DA02C100339C96 /* Categories */,
671686
2767394818CFA6AC00110C33 /* Api */,
672687
9DAC1718170A043200383722 /* AppDelegates */,
@@ -1106,6 +1121,7 @@
11061121
9D79270F18DA1D0300E1D3E1 /* NSObject+CSReflectionAdditions.m in Sources */,
11071122
9D79271018DA1D0300E1D3E1 /* CSBaseObject.m in Sources */,
11081123
9D79271118DA1D0300E1D3E1 /* CSFeedItemCell.m in Sources */,
1124+
8E685AA818DC733B00309270 /* CSCollectionPageControl.m in Sources */,
11091125
9D79271218DA1D0300E1D3E1 /* CSRootViewController.m in Sources */,
11101126
9D79271318DA1D0300E1D3E1 /* FeedItem.m in Sources */,
11111127
9D79271418DA1D0300E1D3E1 /* User.m in Sources */,
@@ -1140,6 +1156,7 @@
11401156
9D79275318DA1D3800E1D3E1 /* NSObject+CSReflectionAdditions.m in Sources */,
11411157
9D79275418DA1D3800E1D3E1 /* CSBaseObject.m in Sources */,
11421158
9D79275518DA1D3800E1D3E1 /* CSFeedItemCell.m in Sources */,
1159+
8E685AA918DC733B00309270 /* CSCollectionPageControl.m in Sources */,
11431160
9D79275618DA1D3800E1D3E1 /* CSRootViewController.m in Sources */,
11441161
9D79275718DA1D3800E1D3E1 /* FeedItem.m in Sources */,
11451162
9D79275818DA1D3800E1D3E1 /* User.m in Sources */,
@@ -1183,6 +1200,7 @@
11831200
2751F4D718DA02C100339C96 /* NSObject+CSReflectionAdditions.m in Sources */,
11841201
8E7F81F018D0BF8500BC50C2 /* CSBaseObject.m in Sources */,
11851202
2751F4E318DA0D3000339C96 /* CSFeedItemCell.m in Sources */,
1203+
8E685AA718DC733B00309270 /* CSCollectionPageControl.m in Sources */,
11861204
9D8C6C5D170CA12500B18012 /* CSRootViewController.m in Sources */,
11871205
0DE51FF418CF911000454E51 /* FeedItem.m in Sources */,
11881206
0DE51FF518CF911000454E51 /* User.m in Sources */,

EasyReader/Application/Api/CSFakedDataRequestor.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ - (NSDictionary *) feedItemsResponse
155155
if ( self.requestCounter == 1 ){
156156
subarrayRange = NSMakeRange(0,6);
157157
} else {
158-
if( [items count] > self.requestCounter*2 ){
159-
subarrayRange = NSMakeRange(self.requestCounter*2,2);
158+
if( [items count] > (self.requestCounter+1)*2 ){
159+
subarrayRange = NSMakeRange((self.requestCounter+1)*2,2);
160160
} else {
161161
subarrayRange = NSMakeRange(8,2);
162162
}

EasyReader/Application/Api/CSFeedItemUpdater.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ - (void) start
3232
[myInvocation setTarget:self];
3333
[myInvocation setSelector:@selector(requestFiveMinutesOfFeedItems:)];
3434

35-
int interval = 20 * 1;
35+
int interval = 30 * 1;
3636
[NSTimer scheduledTimerWithTimeInterval:interval invocation:myInvocation repeats:YES];
3737
}
3838

EasyReader/Application/Controllers/Home/CSHomeViewController.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88

99
#import <UIKit/UIKit.h>
1010
#import "CSBaseViewController.h"
11+
#import "CSCollectionPageControl.h"
1112

1213
@class User;
1314

1415
@interface CSHomeViewController : CSBaseViewController<UICollectionViewDelegate,UIScrollViewDelegate>
1516

1617
@property (weak, nonatomic) IBOutlet UIScrollView *verticalScrollView;
1718
@property (strong, nonatomic) IBOutlet UIButton *button_leftMenu;
18-
@property (strong, nonatomic) IBOutlet UIPageControl *pageControl_itemIndicator;
19+
@property (strong, nonatomic) IBOutlet CSCollectionPageControl *pageControl_itemIndicator;
1920
@property (nonatomic, strong) UIWebView *feedItemWebView;
2021
@property (nonatomic, strong) NSMutableSet *feedItems;
2122
@property User* currentUser;

EasyReader/Application/Controllers/Home/CSHomeViewController.m

Lines changed: 14 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
#import "User.h"
1818

1919
@interface CSHomeViewController (){
20-
CSFeedItemCollectionViewDataSource *feedCollectionViewDataSource;
21-
FeedItem *currentFeedItem;
22-
NSString *currentURL;
20+
CSFeedItemCollectionViewDataSource *feedCollectionViewDataSource;
21+
FeedItem *currentFeedItem;
22+
NSString *currentURL;
2323
}
2424

2525
/// The collection view which holds the individual feed items
@@ -32,8 +32,9 @@ @implementation CSHomeViewController
3232

3333
- (void)viewDidLoad
3434
{
35-
_feedItems = [[NSMutableSet alloc] init];
3635
[super viewDidLoad];
36+
_feedItems = [[NSMutableSet alloc] init];
37+
[_pageControl_itemIndicator setUpFadesOnView:[_pageControl_itemIndicator superview]];
3738
[self setUpCollectionView];
3839
[self setUpWebView];
3940
[self setupFeedItemObserver];
@@ -68,7 +69,7 @@ - (void) setupFeedItemObserver
6869
_feedItems = [(CSFeedItemCollectionViewDataSource *)_collectionView_feedItems.dataSource feedItems];
6970

7071
if(!new) {
71-
NSLog(@"startup?");
72+
NSLog(@"There are no feeds here");
7273
} else {
7374
NSMutableArray *addedFeedItems = [[new allObjects] mutableCopy];
7475
NSMutableArray *removedFeedItems = [[old allObjects] mutableCopy];
@@ -84,7 +85,7 @@ - (void) setupFeedItemObserver
8485
[_feedItems addObject:item];
8586
}
8687

87-
//Add call to button on custom page controller
88+
[_pageControl_itemIndicator.button_newItem setHidden:NO];
8889
}
8990

9091
//redraw the collection with the changes to the feed items
@@ -94,7 +95,8 @@ - (void) setupFeedItemObserver
9495

9596
if(currentFeedItem){
9697
[self scrollToCurrentFeedItem];
97-
[self setPageControllerPageAtIndex:[feedCollectionViewDataSource.sortedFeedItems indexOfObject:currentFeedItem]];
98+
[_pageControl_itemIndicator setPageControllerPageAtIndex:[feedCollectionViewDataSource.sortedFeedItems indexOfObject:currentFeedItem]
99+
forCollection:_feedItems];
98100
}
99101
}
100102
insertionBlock:nil
@@ -106,6 +108,7 @@ - (void) setupFeedItemObserver
106108
removalBlock:nil
107109
replacementBlock:nil
108110
];
111+
NSLog(@"observer added");
109112
}
110113

111114
// Sets up collection view on controller start up
@@ -122,51 +125,16 @@ - (void)setUpCollectionView
122125
self.collectionView_feedItems.dataSource = feedCollectionViewDataSource;
123126
self.collectionView_feedItems.delegate = self;
124127

125-
self.collectionView_feedItems.pagingEnabled = YES;
126-
self.pageControl_itemIndicator.currentPage = 0;
127-
128-
UIButton *dot = [UIButton buttonWithType:UIButtonTypeInfoLight];
129-
dot.frame = CGRectMake(10,(self.pageControl_itemIndicator.frame.size.height/2)-5, 12, 12);
130-
131-
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(newItemButton:)];
132-
[dot addGestureRecognizer:singleTap];
133-
134-
UIView *leftFade = [[UIView alloc] init];
135-
leftFade.frame = CGRectMake(90, 10, 70, 20);
136-
leftFade.backgroundColor = [UIColor blackColor];
137-
138-
CAGradientLayer *leftLayer = [CAGradientLayer layer];
139-
leftLayer.frame = leftFade.bounds;
140-
leftLayer.colors = [NSArray arrayWithObjects:(id)[UIColor whiteColor].CGColor, (id)[UIColor clearColor].CGColor, nil];
141-
leftLayer.startPoint = CGPointMake(0.0f, 1.0f);
142-
leftLayer.endPoint = CGPointMake(1.0f, 1.0f);
143-
leftFade.layer.mask = leftLayer;
144-
145-
UIView *rightFade = [[UIView alloc] init];
146-
rightFade.frame = CGRectMake(160, 10, 70, 20);
147-
rightFade.backgroundColor = [UIColor blackColor];
148128

149-
CAGradientLayer *rightLayer = [CAGradientLayer layer];
150-
rightLayer.frame = rightFade.bounds;
151-
rightLayer.colors = [NSArray arrayWithObjects:(id)[UIColor whiteColor].CGColor, (id)[UIColor clearColor].CGColor, nil];
152-
rightLayer.startPoint = CGPointMake(1.0f, 1.0f);
153-
rightLayer.endPoint = CGPointMake(0.0f, 1.0f);
154-
rightFade.layer.mask = rightLayer;
155-
156-
157-
[self.pageControl_itemIndicator addSubview:dot];
158-
UIView *pageControllerMask = [self.pageControl_itemIndicator superview];
159-
[pageControllerMask addSubview:leftFade];
160-
[pageControllerMask addSubview:rightFade];
161129
}
162130

163131
-(void)newItemButton:(id)sender
164132
{
165133
currentFeedItem = [feedCollectionViewDataSource.sortedFeedItems firstObject];
166134
[self scrollToCurrentFeedItem];
167135
self.collectionCellGoingTo = 0;
168-
[self setPageControllerPageAtIndex:[feedCollectionViewDataSource.sortedFeedItems indexOfObject:currentFeedItem]];
169-
[sender setHidden:YES];
136+
[_pageControl_itemIndicator setPageControllerPageAtIndex:[feedCollectionViewDataSource.sortedFeedItems indexOfObject:currentFeedItem]
137+
forCollection:_feedItems];
170138
}
171139

172140
#pragma mark - IBActions
@@ -239,22 +207,8 @@ - (void)scrollToCurrentFeedItem
239207
- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
240208
{
241209
int newIndex = indexPath.row+((indexPath.row-self.collectionCellGoingTo)*-1);
242-
[self setPageControllerPageAtIndex:newIndex];
243-
}
244-
245-
- (void)setPageControllerPageAtIndex:(int)index
246-
{
247-
if ([_feedItems count] < 6){
248-
_pageControl_itemIndicator.currentPage = index;
249-
} else {
250-
if( index < 3 ){
251-
_pageControl_itemIndicator.currentPage = index;
252-
} else if(index > ([_feedItems count]-3) ){
253-
_pageControl_itemIndicator.currentPage = 5-([_feedItems count]-index);
254-
} else {
255-
_pageControl_itemIndicator.currentPage = 2;
256-
}
257-
}
210+
[_pageControl_itemIndicator setPageControllerPageAtIndex:newIndex
211+
forCollection:_feedItems];
258212
}
259213

260214
- (void)loadFeedItemWebView
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// CSCollectionPageControl.h
3+
// EasyReader
4+
//
5+
// Created by Alfredo Uribe on 3/21/14.
6+
// Copyright (c) 2014 Cloudspace. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@interface CSCollectionPageControl : UIPageControl
12+
13+
@property UIButton *button_newItem;
14+
@property UIView *view_maskLayer;
15+
@property UIView *view_leftFade;
16+
@property UIView *view_rightFade;
17+
18+
- (void)setPageControllerPageAtIndex:(int)index forCollection:(NSSet*)collection;
19+
-(void)setUpFadesOnView:(UIView*)mask;
20+
21+
@end
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
//
2+
// CSCollectionPageControl.m
3+
// EasyReader
4+
//
5+
// Created by Alfredo Uribe on 3/21/14.
6+
// Copyright (c) 2014 Cloudspace. All rights reserved.
7+
//
8+
9+
#import "CSCollectionPageControl.h"
10+
11+
@implementation CSCollectionPageControl
12+
13+
- (id)initWithCoder:(NSCoder *)aDecoder
14+
{
15+
self = [super initWithCoder:aDecoder];
16+
if (self) {
17+
UIButton *dot = [UIButton buttonWithType:UIButtonTypeInfoLight];
18+
dot.frame = CGRectMake(10,(self.frame.size.height/2)-5, 12, 12);
19+
20+
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(newItemButton:)];
21+
[dot addGestureRecognizer:singleTap];
22+
23+
[self addSubview:dot];
24+
}
25+
return self;
26+
}
27+
28+
-(void)setUpFadesOnView:(UIView*)mask
29+
{
30+
_view_maskLayer = [[UIView alloc] init];
31+
_view_leftFade = [[UIView alloc] init];
32+
_view_leftFade.frame = CGRectMake(110, 10, 30, 20);
33+
_view_leftFade.backgroundColor = [UIColor blackColor];
34+
35+
CAGradientLayer *leftLayer = [CAGradientLayer layer];
36+
leftLayer.frame = _view_leftFade.bounds;
37+
leftLayer.colors = [NSArray arrayWithObjects:(id)[UIColor whiteColor].CGColor, (id)[UIColor clearColor].CGColor, nil];
38+
leftLayer.startPoint = CGPointMake(0.0f, 1.0f);
39+
leftLayer.endPoint = CGPointMake(1.0f, 1.0f);
40+
_view_leftFade.layer.mask = leftLayer;
41+
42+
_view_rightFade = [[UIView alloc] init];
43+
_view_rightFade.frame = CGRectMake(160, 10, 50, 20);
44+
_view_rightFade.backgroundColor = [UIColor blackColor];
45+
46+
CAGradientLayer *rightLayer = [CAGradientLayer layer];
47+
rightLayer.frame = _view_rightFade.bounds;
48+
rightLayer.colors = [NSArray arrayWithObjects:(id)[UIColor whiteColor].CGColor, (id)[UIColor clearColor].CGColor, nil];
49+
rightLayer.startPoint = CGPointMake(1.0f, 1.0f);
50+
rightLayer.endPoint = CGPointMake(0.0f, 1.0f);
51+
_view_rightFade.layer.mask = rightLayer;
52+
53+
[_view_maskLayer addSubview:_view_leftFade];
54+
[_view_maskLayer addSubview:_view_rightFade];
55+
[mask addSubview:_view_maskLayer];
56+
NSLog(@"added?");
57+
}
58+
59+
- (void)setPageControllerPageAtIndex:(int)index forCollection:(NSSet*)collection
60+
{
61+
if ([collection count] < 6){
62+
self.currentPage = index;
63+
} else {
64+
if( index <= 2 ){
65+
self.currentPage = index;
66+
[_view_leftFade setHidden:YES];
67+
} else if(index > ([collection count]-3) ){
68+
self.currentPage = 5-([collection count]-index);
69+
[_view_rightFade setHidden:YES];
70+
} else {
71+
self.currentPage = 2;
72+
[_view_leftFade setHidden:NO];
73+
[_view_rightFade setHidden:NO];
74+
}
75+
}
76+
}
77+
78+
/*
79+
// Only override drawRect: if you perform custom drawing.
80+
// An empty implementation adversely affects performance during animation.
81+
- (void)drawRect:(CGRect)rect
82+
{
83+
// Drawing code
84+
}
85+
*/
86+
87+
@end

EasyReader/Application/Views/Main_iPhone.storyboard

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
<rect key="frame" x="0.0" y="531" width="320" height="284"/>
137137
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
138138
<subviews>
139-
<pageControl opaque="NO" contentMode="scaleToFill" ambiguous="YES" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" numberOfPages="5" translatesAutoresizingMaskIntoConstraints="NO" id="vdW-Yb-aAb">
139+
<pageControl opaque="NO" contentMode="scaleToFill" ambiguous="YES" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" numberOfPages="3" translatesAutoresizingMaskIntoConstraints="NO" id="vdW-Yb-aAb" customClass="CSCollectionPageControl">
140140
<rect key="frame" x="0.0" y="0.0" width="320" height="37"/>
141141
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
142142
<color key="backgroundColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>

0 commit comments

Comments
 (0)