Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Commit

Permalink
Merge branch 'drag-refresh-example' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
diederich committed Feb 13, 2011
2 parents fd16b96 + ee2ca45 commit d1af7c1
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 5 deletions.
7 changes: 7 additions & 0 deletions samples/TTCatalog/Classes/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#import "TableTestController.h"
#import "TableWithBannerController.h"
#import "TableWithShadowController.h"
#import "TableDragRefreshController.h"
#import "SearchTestController.h"
#import "MessageTestController.h"
#import "ActivityTestController.h"
Expand Down Expand Up @@ -103,6 +104,12 @@ - (void)applicationDidFinishLaunching:(UIApplication*)application {
selector: nil
transition: 0];

[map from: @"tt://tableDragRefresh"
parent: @"tt://catalog"
toViewController: [TableDragRefreshController class]
selector: nil
transition: 0];

[map from: @"tt://composerTest"
parent: @"tt://catalog"
toViewController: [MessageTestController class]
Expand Down
1 change: 1 addition & 0 deletions samples/TTCatalog/Classes/CatalogController.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ - (void)createModel {
[TTTableTextItem itemWithText:@"Web Images in Table" URL:@"tt://imageTest2"],
[TTTableTextItem itemWithText:@"Table With Banner" URL:@"tt://tableWithBanner"],
[TTTableTextItem itemWithText:@"Table With Shadow" URL:@"tt://tableWithShadow"],
[TTTableTextItem itemWithText:@"Table With Drag Refresh" URL:@"tt://tableDragRefresh"],

@"Models",
[TTTableTextItem itemWithText:@"Model Search" URL:@"tt://searchTest"],
Expand Down
9 changes: 8 additions & 1 deletion samples/TTCatalog/Classes/MockDataSource.h
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
#import <Three20/Three20.h>

/*
* a searchable model which can be configured with a
* loading and/or search time
*/
@interface MockAddressBook : NSObject <TTModel> {
NSMutableArray* _delegates;
NSMutableArray* _names;
NSArray* _allNames;
NSTimer* _fakeSearchTimer;
NSTimeInterval _fakeSearchDuration;
NSTimer* _fakeLoadingTimer;
NSTimeInterval _fakeLoadingDuration;
}

@property(nonatomic,retain) NSArray* names;
@property(nonatomic) NSTimeInterval fakeSearchDuration;
@property(nonatomic) NSTimeInterval fakeLoadingDuration;

+ (NSMutableArray*)fakeNames;

- (id)initWithNames:(NSArray*)names;

- (void)loadNames;

- (void)search:(NSString*)text;

@end
Expand Down
37 changes: 33 additions & 4 deletions samples/TTCatalog/Classes/MockDataSource.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@

#import "MockDataSource.h"

@interface MockAddressBook ()
- (void) loadNames;
@end

///////////////////////////////////////////////////////////////////////////////////////////////////

@implementation MockAddressBook

@synthesize names = _names, fakeSearchDuration = _fakeSearchDuration;
@synthesize names = _names, fakeSearchDuration = _fakeSearchDuration, fakeLoadingDuration = _fakeLoadingDuration;

///////////////////////////////////////////////////////////////////////////////////////////////////
// class public
Expand Down Expand Up @@ -356,6 +360,7 @@ - (id)initWithNames:(NSArray*)names {

- (void)dealloc {
TT_INVALIDATE_TIMER(_fakeSearchTimer);
TT_INVALIDATE_TIMER(_fakeLoadingTimer)
TT_RELEASE_SAFELY(_delegates);
TT_RELEASE_SAFELY(_allNames);
TT_RELEASE_SAFELY(_names);
Expand Down Expand Up @@ -385,14 +390,32 @@ - (BOOL)isLoaded {
}

- (BOOL)isLoading {
return !!_fakeSearchTimer;
return !!_fakeSearchTimer || !!_fakeLoadingTimer;
}

- (BOOL)isEmpty {
return !_names.count;
}

- (void) fakeLoadingReady {
_fakeLoadingTimer = nil;

[self loadNames];

[_delegates perform:@selector(modelDidFinishLoad:) withObject:self];
}

- (void)load:(TTURLRequestCachePolicy)cachePolicy more:(BOOL)more {
[_delegates perform:@selector(modelDidStartLoad:) withObject:self];
if (_fakeLoadingDuration) {
TT_INVALIDATE_TIMER(_fakeLoadingTimer);
_fakeLoadingTimer = [NSTimer scheduledTimerWithTimeInterval:_fakeLoadingDuration target:self
selector:@selector(fakeLoadingReady) userInfo:nil repeats:NO];
[_delegates perform:@selector(modelDidStartLoad:) withObject:self];
} else {
[self loadNames];
[_delegates perform:@selector(modelDidFinishLoad:) withObject:self];
}
}

- (void)invalidate:(BOOL)erase {
Expand All @@ -402,6 +425,9 @@ - (void)cancel {
if (_fakeSearchTimer) {
TT_INVALIDATE_TIMER(_fakeSearchTimer);
[_delegates perform:@selector(modelDidCancelLoad:) withObject:self];
} else if(_fakeLoadingTimer) {
TT_INVALIDATE_TIMER(_fakeLoadingTimer);
[_delegates perform:@selector(modelDidCancelLoad:) withObject:self];
}
}

Expand All @@ -416,6 +442,7 @@ - (void)loadNames {
- (void)search:(NSString*)text {
[self cancel];

TT_RELEASE_SAFELY(_names);
if (text.length) {
if (_fakeSearchDuration) {
TT_INVALIDATE_TIMER(_fakeSearchTimer);
Expand All @@ -427,7 +454,6 @@ - (void)search:(NSString*)text {
[_delegates perform:@selector(modelDidFinishLoad:) withObject:self];
}
} else {
TT_RELEASE_SAFELY(_names);
[_delegates perform:@selector(modelDidChange:) withObject:self];
}
}
Expand All @@ -446,7 +472,6 @@ @implementation MockDataSource
- (id)init {
if (self = [super init]) {
_addressBook = [[MockAddressBook alloc] initWithNames:[MockAddressBook fakeNames]];
[_addressBook loadNames];
self.model = _addressBook;
}
return self;
Expand Down Expand Up @@ -492,6 +517,10 @@ - (void)tableViewDidLoadModel:(UITableView*)tableView {
}
}

- (id<TTModel>)model {
return _addressBook;
}

@end

///////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
5 changes: 5 additions & 0 deletions samples/TTCatalog/Classes/TableDragRefreshController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#import <Three20/Three20.h>

@interface TableDragRefreshController : TTTableViewController

@end
39 changes: 39 additions & 0 deletions samples/TTCatalog/Classes/TableDragRefreshController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

#import "TableDragRefreshController.h"
#import "MockDataSource.h"

@implementation TableDragRefreshController

///////////////////////////////////////////////////////////////////////////////////////////////////
// private

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
}
return self;
}

///////////////////////////////////////////////////////////////////////////////////////////////////
// UIViewController

- (void)loadView {
[super loadView];
}

- (void) createModel {
MockDataSource *ds = [[MockDataSource alloc] init];
ds.addressBook.fakeLoadingDuration = 1.0;
self.dataSource = ds;
[ds release];
}

- (id<TTTableViewDelegate>) createDelegate {

TTTableViewDragRefreshDelegate *delegate = [[TTTableViewDragRefreshDelegate alloc] initWithController:self];

return [delegate autorelease];
}

@end

16 changes: 16 additions & 0 deletions samples/TTCatalog/TTCatalog.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@
BEF199230F818E720010D36E /* StyledTextTestController.m in Sources */ = {isa = PBXBuildFile; fileRef = BEF199210F818E720010D36E /* StyledTextTestController.m */; };
BEF6EC370F280CB300CF4096 /* ScrollViewTestController.m in Sources */ = {isa = PBXBuildFile; fileRef = BEF6EC360F280CB300CF4096 /* ScrollViewTestController.m */; };
E46662FE127F91A4001A0F20 /* TableWithBannerController.m in Sources */ = {isa = PBXBuildFile; fileRef = E46662FD127F91A4001A0F20 /* TableWithBannerController.m */; };
E4D1D1D61306D2670090AE0C /* TableDragRefreshController.m in Sources */ = {isa = PBXBuildFile; fileRef = E4D1D1D51306D2670090AE0C /* TableDragRefreshController.m */; };
E4D1D1D71306D2670090AE0C /* TableDragRefreshController.m in Sources */ = {isa = PBXBuildFile; fileRef = E4D1D1D51306D2670090AE0C /* TableDragRefreshController.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -490,6 +492,8 @@
BEF6EC360F280CB300CF4096 /* ScrollViewTestController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ScrollViewTestController.m; sourceTree = "<group>"; };
E46662FC127F91A4001A0F20 /* TableWithBannerController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TableWithBannerController.h; sourceTree = "<group>"; };
E46662FD127F91A4001A0F20 /* TableWithBannerController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TableWithBannerController.m; sourceTree = "<group>"; };
E4D1D1D41306D2670090AE0C /* TableDragRefreshController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TableDragRefreshController.h; sourceTree = "<group>"; };
E4D1D1D51306D2670090AE0C /* TableDragRefreshController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TableDragRefreshController.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -753,6 +757,15 @@
name = "Table with Banner";
sourceTree = "<group>";
};
E4D1D1C41306D12D0090AE0C /* Table Drag Refresh */ = {
isa = PBXGroup;
children = (
E4D1D1D41306D2670090AE0C /* TableDragRefreshController.h */,
E4D1D1D51306D2670090AE0C /* TableDragRefreshController.m */,
);
name = "Table Drag Refresh";
sourceTree = "<group>";
};
EA1080F1101B37E90098AAC2 /* Photos */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -931,6 +944,7 @@
EA108169101B3A3A0098AAC2 /* Web Images in Table */,
E46662F9127F916C001A0F20 /* Table with Banner */,
6E002564116A6CF900D1F0CB /* Table With Shadow */,
E4D1D1C41306D12D0090AE0C /* Table Drag Refresh */,
);
name = Tables;
sourceTree = "<group>";
Expand Down Expand Up @@ -1354,6 +1368,7 @@
6E002567116A6D1A00D1F0CB /* TableWithShadowController.m in Sources */,
E46662FE127F91A4001A0F20 /* TableWithBannerController.m in Sources */,
666E183012944D23001C1D97 /* SplitCatalogController.m in Sources */,
E4D1D1D61306D2670090AE0C /* TableDragRefreshController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -1387,6 +1402,7 @@
664DFEE212663122004C20C2 /* TableWithShadowController.m in Sources */,
664B27F612846A220008D569 /* TableWithBannerController.m in Sources */,
666E183112944D23001C1D97 /* SplitCatalogController.m in Sources */,
E4D1D1D71306D2670090AE0C /* TableDragRefreshController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down

0 comments on commit d1af7c1

Please sign in to comment.