Skip to content

Commit

Permalink
Update SVPullToRefresh
Browse files Browse the repository at this point in the history
  • Loading branch information
anqqa committed Oct 27, 2012
1 parent b9e3166 commit 680f5d0
Show file tree
Hide file tree
Showing 9 changed files with 979 additions and 30 deletions.
37 changes: 22 additions & 15 deletions klubitus.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
E92F881E15E975BA0007D673 /* FlyerBackViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E92F881D15E975BA0007D673 /* FlyerBackViewController.m */; };
E993F1F3163C078A000D453B /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E993F1F2163C078A000D453B /* SystemConfiguration.framework */; };
E993F1F5163C09D8000D453B /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = E993F1F4163C09D8000D453B /* Default-568h@2x.png */; };
E993F1FC163C0DA1000D453B /* UIScrollView+SVInfiniteScrolling.m in Sources */ = {isa = PBXBuildFile; fileRef = E993F1F9163C0DA1000D453B /* UIScrollView+SVInfiniteScrolling.m */; };
E993F1FD163C0DA1000D453B /* UIScrollView+SVPullToRefresh.m in Sources */ = {isa = PBXBuildFile; fileRef = E993F1FB163C0DA1000D453B /* UIScrollView+SVPullToRefresh.m */; };
E9945B6A15E13E7B00EACAC6 /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E9945B6915E13E7B00EACAC6 /* UIKit.framework */; };
E9945B6C15E13E7B00EACAC6 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E9945B6B15E13E7B00EACAC6 /* Foundation.framework */; };
E9945B6E15E13E7B00EACAC6 /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E9945B6D15E13E7B00EACAC6 /* CoreGraphics.framework */; };
Expand All @@ -25,7 +27,6 @@
E9945B9815E1424200EACAC6 /* Default.png in Resources */ = {isa = PBXBuildFile; fileRef = E9945B9715E1424200EACAC6 /* Default.png */; };
E9945B9A15E1424700EACAC6 /* Default@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = E9945B9915E1424700EACAC6 /* Default@2x.png */; };
E9945B9C15E3E39E00EACAC6 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E9945B9B15E3E39E00EACAC6 /* QuartzCore.framework */; };
E9945BA015E3E57F00EACAC6 /* SVPullToRefresh.m in Sources */ = {isa = PBXBuildFile; fileRef = E9945B9F15E3E57F00EACAC6 /* SVPullToRefresh.m */; };
E9945BA315E4025800EACAC6 /* logo.png in Resources */ = {isa = PBXBuildFile; fileRef = E9945BA115E4025800EACAC6 /* logo.png */; };
E9945BA415E4025800EACAC6 /* logo@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = E9945BA215E4025800EACAC6 /* logo@2x.png */; };
E9945BBB15E4165B00EACAC6 /* AFHTTPClient.m in Sources */ = {isa = PBXBuildFile; fileRef = E9945BA715E4165B00EACAC6 /* AFHTTPClient.m */; };
Expand Down Expand Up @@ -55,6 +56,11 @@
E92F881D15E975BA0007D673 /* FlyerBackViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FlyerBackViewController.m; sourceTree = "<group>"; };
E993F1F2163C078A000D453B /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; };
E993F1F4163C09D8000D453B /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = "<group>"; };
E993F1F7163C0DA1000D453B /* SVPullToRefresh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVPullToRefresh.h; sourceTree = "<group>"; };
E993F1F8163C0DA1000D453B /* UIScrollView+SVInfiniteScrolling.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIScrollView+SVInfiniteScrolling.h"; sourceTree = "<group>"; };
E993F1F9163C0DA1000D453B /* UIScrollView+SVInfiniteScrolling.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIScrollView+SVInfiniteScrolling.m"; sourceTree = "<group>"; };
E993F1FA163C0DA1000D453B /* UIScrollView+SVPullToRefresh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIScrollView+SVPullToRefresh.h"; sourceTree = "<group>"; };
E993F1FB163C0DA1000D453B /* UIScrollView+SVPullToRefresh.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIScrollView+SVPullToRefresh.m"; sourceTree = "<group>"; };
E9945B6515E13E7B00EACAC6 /* klubitus.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = klubitus.app; sourceTree = BUILT_PRODUCTS_DIR; };
E9945B6915E13E7B00EACAC6 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
E9945B6B15E13E7B00EACAC6 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
Expand All @@ -75,8 +81,6 @@
E9945B9715E1424200EACAC6 /* Default.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = Default.png; sourceTree = "<group>"; };
E9945B9915E1424700EACAC6 /* Default@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default@2x.png"; sourceTree = "<group>"; };
E9945B9B15E3E39E00EACAC6 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
E9945B9E15E3E57F00EACAC6 /* SVPullToRefresh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SVPullToRefresh.h; sourceTree = "<group>"; };
E9945B9F15E3E57F00EACAC6 /* SVPullToRefresh.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SVPullToRefresh.m; sourceTree = "<group>"; };
E9945BA115E4025800EACAC6 /* logo.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = logo.png; sourceTree = "<group>"; };
E9945BA215E4025800EACAC6 /* logo@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "logo@2x.png"; sourceTree = "<group>"; };
E9945BA615E4165B00EACAC6 /* AFHTTPClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AFHTTPClient.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -128,6 +132,18 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
E993F1F6163C0DA1000D453B /* SVPullToRefresh */ = {
isa = PBXGroup;
children = (
E993F1F7163C0DA1000D453B /* SVPullToRefresh.h */,
E993F1F8163C0DA1000D453B /* UIScrollView+SVInfiniteScrolling.h */,
E993F1F9163C0DA1000D453B /* UIScrollView+SVInfiniteScrolling.m */,
E993F1FA163C0DA1000D453B /* UIScrollView+SVPullToRefresh.h */,
E993F1FB163C0DA1000D453B /* UIScrollView+SVPullToRefresh.m */,
);
path = SVPullToRefresh;
sourceTree = "<group>";
};
E9945B5A15E13E7B00EACAC6 = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -215,16 +231,6 @@
name = GFX;
sourceTree = "<group>";
};
E9945B9D15E3E57F00EACAC6 /* SVPullToRefresh */ = {
isa = PBXGroup;
children = (
E9945B9E15E3E57F00EACAC6 /* SVPullToRefresh.h */,
E9945B9F15E3E57F00EACAC6 /* SVPullToRefresh.m */,
);
name = SVPullToRefresh;
path = ../SVPullToRefresh;
sourceTree = "<group>";
};
E9945BA515E4165B00EACAC6 /* AFNetworking */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -255,8 +261,8 @@
E9945BC915E907B200EACAC6 /* Helpers */ = {
isa = PBXGroup;
children = (
E993F1F6163C0DA1000D453B /* SVPullToRefresh */,
E9945BCA15E907E100EACAC6 /* IOSBoilerplate */,
E9945B9D15E3E57F00EACAC6 /* SVPullToRefresh */,
E9945BA515E4165B00EACAC6 /* AFNetworking */,
);
name = Helpers;
Expand Down Expand Up @@ -374,7 +380,6 @@
E9945B7A15E13E7C00EACAC6 /* AppDelegate.m in Sources */,
E9945B8015E13E7C00EACAC6 /* MasterViewController.m in Sources */,
E9945B8315E13E7C00EACAC6 /* DetailViewController.m in Sources */,
E9945BA015E3E57F00EACAC6 /* SVPullToRefresh.m in Sources */,
E9945BBB15E4165B00EACAC6 /* AFHTTPClient.m in Sources */,
E9945BBC15E4165B00EACAC6 /* AFHTTPRequestOperation.m in Sources */,
E9945BBD15E4165B00EACAC6 /* AFImageRequestOperation.m in Sources */,
Expand All @@ -387,6 +392,8 @@
E9945BCD15E907E100EACAC6 /* DictionaryHelper.m in Sources */,
E92F881A15E93FFE0007D673 /* FlyerViewController.m in Sources */,
E92F881E15E975BA0007D673 /* FlyerBackViewController.m in Sources */,
E993F1FC163C0DA1000D453B /* UIScrollView+SVInfiniteScrolling.m in Sources */,
E993F1FD163C0DA1000D453B /* UIScrollView+SVPullToRefresh.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
27 changes: 12 additions & 15 deletions klubitus/MasterViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,16 @@ - (void)viewDidLoad {
self.lastDay = self.firstDay = [self timeToDate:[NSDate date]];

// Initialize infinite scroller and pull to refresh, with initial refresh in other direction..
self.tableView.pullToRefreshView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
self.tableView.infiniteScrollingView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
__block MasterViewController *blocksafeSelf = self;
[self.tableView addInfiniteScrollingWithActionHandler:^{
[blocksafeSelf fetchEventsWithOrder:@"asc"];
}];
[self.tableView addPullToRefreshWithActionHandler:^{
[blocksafeSelf fetchEventsWithOrder:@"desc"];
}];
[self.tableView.pullToRefreshView triggerRefresh];

// [self fetchEventsWithOrder:@"asc"];
self.tableView.pullToRefreshView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
self.tableView.infiniteScrollingView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
[self.tableView triggerInfiniteScrolling];
}


Expand Down Expand Up @@ -111,12 +109,6 @@ - (NSDate *)timeToDate:(NSDate *)inputDate {
Load events with JSON.
*/
- (void)fetchEventsWithOrder:(NSString *)inputOrder {

// Kludge to always order first request descending because we are triggering refresh onViewLoad
if ([self.lastDay isEqualToDate:self.firstDay]) {
inputOrder = @"asc";
}

NSDate *fromDate = ([inputOrder isEqualToString:@"asc"]) ? self.lastDay : self.firstDay;
int from = [fromDate timeIntervalSince1970];
NSString *APIBasePath = @"http://api.klubitus.org/v1/events/browse?field=all&limit=1w&order=%@&from=%d";
Expand Down Expand Up @@ -164,13 +156,18 @@ - (void)fetchEventsWithOrder:(NSString *)inputOrder {
self.lastDay = [self timeToDate:[self.lastDay dateByAddingTimeInterval:(60 * 60 * 25)]];

// Refresh table and jump to new section if needed
[self.tableView reloadData];

if ([inputOrder isEqualToString:@"desc"]) {

NSIndexPath *tempPath = [NSIndexPath indexPathForRow:0 inSection:newSections];
[self.tableView scrollToRowAtIndexPath:tempPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
}
[self.tableView.pullToRefreshView stopAnimating];
[self.tableView reloadData];
[self.tableView scrollToRowAtIndexPath:tempPath atScrollPosition:UITableViewScrollPositionTop animated:NO];
} else {
[self.tableView reloadData];
[self.tableView.infiniteScrollingView stopAnimating];
}

[self.tableView.pullToRefreshView stopAnimating];

} failure:nil];

Expand Down
15 changes: 15 additions & 0 deletions klubitus/SVPullToRefresh/SVPullToRefresh.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// SVPullToRefresh.h
// SVPullToRefreshDemo
//
// Created by Sam Vermette on 23.04.12.
// Copyright (c) 2012 samvermette.com. All rights reserved.
//
// https://github.com/samvermette/SVPullToRefresh
//

// this header file is provided for backwards compatibility and will be removed in the future
// here's how you should import SVPullToRefresh now:

#import "UIScrollView+SVPullToRefresh.h"
#import "UIScrollView+SVInfiniteScrolling.h"
44 changes: 44 additions & 0 deletions klubitus/SVPullToRefresh/UIScrollView+SVInfiniteScrolling.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// UIScrollView+SVInfiniteScrolling.h
//
// Created by Sam Vermette on 23.04.12.
// Copyright (c) 2012 samvermette.com. All rights reserved.
//
// https://github.com/samvermette/SVPullToRefresh
//

#import <UIKit/UIKit.h>

@class SVInfiniteScrollingView;

@interface UIScrollView (SVInfiniteScrolling)

- (void)addInfiniteScrollingWithActionHandler:(void (^)(void))actionHandler;
- (void)triggerInfiniteScrolling;

@property (nonatomic, strong, readonly) SVInfiniteScrollingView *infiniteScrollingView;
@property (nonatomic, assign) BOOL showsInfiniteScrolling;

@end


enum {
SVInfiniteScrollingStateStopped = 0,
SVInfiniteScrollingStateTriggered,
SVInfiniteScrollingStateLoading,
SVInfiniteScrollingStateAll = 10
};

typedef NSUInteger SVInfiniteScrollingState;

@interface SVInfiniteScrollingView : UIView

@property (nonatomic, readwrite) UIActivityIndicatorViewStyle activityIndicatorViewStyle;
@property (nonatomic, readonly) SVInfiniteScrollingState state;

- (void)setCustomView:(UIView *)view forState:(SVInfiniteScrollingState)state;

- (void)startAnimating;
- (void)stopAnimating;

@end
Loading

0 comments on commit 680f5d0

Please sign in to comment.