Squeegy / latest-chatty

OLD CODE - DO NOT USE

This URL has Read+Write access

latest-chatty / Classes / RootViewController.m
c6ade158 » Squeegy 2008-08-01 Initial commit 1 //
2 // RootViewController.m
3 // LatestChatty
4 //
5 // Created by Alex Wayne on 7/31/08.
6 // Copyright __MyCompanyName__ 2008. All rights reserved.
7 //
8
9 #import "RootViewController.h"
10 #import "LatestChattyAppDelegate.h"
11
12
13 @implementation RootViewController
14
15
16 - (void)viewDidLoad {
17 // Refresh button
0f555d5c » Squeegy 2008-08-12 Loading indicators are no l... 18 UIBarButtonItem *refreshButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh
19 target:self
20 action:@selector(refresh:)];
be515b6c » Squeegy 2008-08-11 Refresh button on the root ... 21 self.navigationItem.leftBarButtonItem = refreshButton;
22
c6ade158 » Squeegy 2008-08-01 Initial commit 23
24 // Compose button
25 UIBarButtonItem *composeItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose
26 target:self
27 action:@selector(compose:)];
28 self.navigationItem.rightBarButtonItem = composeItem;
29 [composeItem release];
6a593468 » Squeegy 2008-08-11 Show loading spinner when a... 30
31 // Fetch feed
32 [self refresh:nil];
c6ade158 » Squeegy 2008-08-01 Initial commit 33 }
34
35
36 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
37 return 1;
38 }
39
40
41 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
69e888bc » Squeegy 2008-08-06 Added pagination to root th... 42 if ([feed hasMorePages]) {
43 return [[feed posts] count] + 1;
44 } else {
45 return [[feed posts] count];
46 }
c6ade158 » Squeegy 2008-08-01 Initial commit 47 }
48
49
68f781cb » Squeegy 2008-08-14 root view controller is now... 50 - (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
51 NSLog(@"asked for cell!");
2dad3431 » Squeegy 2008-08-09 * Fixed that api_server was... 52 RootPostCellView *cell;
69e888bc » Squeegy 2008-08-06 Added pagination to root th... 53 if (indexPath.row < [[feed posts] count]) {
2dad3431 » Squeegy 2008-08-09 * Fixed that api_server was... 54 Post *post = [[feed posts] objectAtIndex:indexPath.row];
55
56 cell = (RootPostCellView *)[tableView dequeueReusableCellWithIdentifier:@"rootPostCell"];
57 if (cell == nil) {
58 cell = [[RootPostCellView alloc] initForPost];
59 }
60
61 [cell updateWithPost:post];
69e888bc » Squeegy 2008-08-06 Added pagination to root th... 62 } else {
63 cell = [[RootPostCellView alloc] initLoadMore];
64 }
2dad3431 » Squeegy 2008-08-09 * Fixed that api_server was... 65
66 cell.striped = (indexPath.row % 2 == 1);
67 return (UITableViewCell *)cell;
c6ade158 » Squeegy 2008-08-01 Initial commit 68 }
69
70
68f781cb » Squeegy 2008-08-14 root view controller is now... 71 - (void)tableView:(UITableView *)aTableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
3988116f » Squeegy 2008-08-12 Asynchronous thread loading... 72 // Tapped a post cell
69e888bc » Squeegy 2008-08-06 Added pagination to root th... 73 if (indexPath.row < [[feed posts] count]) {
ae9179b6 » Squeegy 2008-08-07 * New icon, again, without ... 74 RootPostCellView *cell = (RootPostCellView *)[tableView cellForRowAtIndexPath:indexPath];
3988116f » Squeegy 2008-08-12 Asynchronous thread loading... 75 [cell setLoading:YES];
76 Post *rootPost = [[feed posts] objectAtIndex:indexPath.row];
77 [[Post alloc] initWithThreadId:rootPost.postId delegate:self];
78
79 // Tapped the load more cell
69e888bc » Squeegy 2008-08-06 Added pagination to root th... 80 } else {
ae9179b6 » Squeegy 2008-08-07 * New icon, again, without ... 81 RootPostCellView *cell = (RootPostCellView *)[tableView cellForRowAtIndexPath:indexPath];
3988116f » Squeegy 2008-08-12 Asynchronous thread loading... 82 [cell setLoading:YES];
69e888bc » Squeegy 2008-08-06 Added pagination to root th... 83 [feed loadNextPage];
84 }
c0281ada » Squeegy 2008-08-12 Utilize the status bar netw... 85
86 [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
c6ade158 » Squeegy 2008-08-01 Initial commit 87 }
88
ae9179b6 » Squeegy 2008-08-07 * New icon, again, without ... 89 - (void)feedDidFinishLoading {
68f781cb » Squeegy 2008-08-14 root view controller is now... 90 [tableView reloadData];
ae9179b6 » Squeegy 2008-08-07 * New icon, again, without ... 91 if (feed.lastPageLoaded == 1) {
68f781cb » Squeegy 2008-08-14 root view controller is now... 92 [tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
ae9179b6 » Squeegy 2008-08-07 * New icon, again, without ... 93 }
68f781cb » Squeegy 2008-08-14 root view controller is now... 94 [tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:YES];
be515b6c » Squeegy 2008-08-11 Refresh button on the root ... 95
a9483f02 » Squeegy 2008-08-14 Root view now shows the sto... 96 self.title = [feed storyName];
c0281ada » Squeegy 2008-08-12 Utilize the status bar netw... 97
98 [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
ae9179b6 » Squeegy 2008-08-07 * New icon, again, without ... 99 }
c6ade158 » Squeegy 2008-08-01 Initial commit 100
f25dbb73 » Squeegy 2008-08-12 Some tweaks to not crash af... 101 - (void)didFinishLoadingThread:(Post *)post {
3988116f » Squeegy 2008-08-12 Asynchronous thread loading... 102 // create the detail view controller
103 DetailViewController *detailViewController = [[DetailViewController alloc] initWithStoryId:feed.storyId rootPost:post];
104
105 // Push the detail view controller onto the navigation stack
106 [[self navigationController] pushViewController:detailViewController animated:YES];
107 [detailViewController release];
108
109 // Remove loading status from tapped cell
68f781cb » Squeegy 2008-08-14 root view controller is now... 110 [(RootPostCellView *)[tableView cellForRowAtIndexPath:[tableView indexPathForSelectedRow]] setLoading:NO];
c0281ada » Squeegy 2008-08-12 Utilize the status bar netw... 111
112 [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
3988116f » Squeegy 2008-08-12 Asynchronous thread loading... 113 }
114
c6ade158 » Squeegy 2008-08-01 Initial commit 115 /*
116 Override if you support editing the list
117 - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
118
119 if (editingStyle == UITableViewCellEditingStyleDelete) {
120 // Delete the row from the data source
121 [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
122 }
123 if (editingStyle == UITableViewCellEditingStyleInsert) {
124 // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
125 }
126 }
127 */
128
129
130 /*
131 Override if you support conditional editing of the list
132 - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
133 // Return NO if you do not want the specified item to be editable.
134 return YES;
135 }
136 */
137
138
139 /*
140 Override if you support rearranging the list
141 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
142 }
143 */
144
145
146 /*
147 Override if you support conditional rearranging of the list
148 - (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
149 // Return NO if you do not want the item to be re-orderable.
150 return YES;
151 }
152 */
153
154
155 - (void)viewWillAppear:(BOOL)animated {
156 [super viewWillAppear:animated];
68f781cb » Squeegy 2008-08-14 root view controller is now... 157 [tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:YES];
c6ade158 » Squeegy 2008-08-01 Initial commit 158 }
159
160 - (void)viewDidAppear:(BOOL)animated {
161 [super viewDidAppear:animated];
162 }
163
164 - (void)viewWillDisappear:(BOOL)animated {
165 }
166
167 - (void)viewDidDisappear:(BOOL)animated {
168 }
169
170
171 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
c15195ee » Squeegy 2008-08-02 Disabled landscape for now. 172 return (interfaceOrientation == UIInterfaceOrientationPortrait);
c6ade158 » Squeegy 2008-08-01 Initial commit 173 return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
174 }
175
176
177 - (void)didReceiveMemoryWarning {
178 [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
179 // Release anything that's not essential, such as cached data
180 }
181
182
183 - (void)dealloc {
0f555d5c » Squeegy 2008-08-12 Loading indicators are no l... 184 [feed release];
c6ade158 » Squeegy 2008-08-01 Initial commit 185 [super dealloc];
186 }
187
188
189
190
191
192
193 - (void)refresh:(id)sender {
194 [feed release];
ae9179b6 » Squeegy 2008-08-07 * New icon, again, without ... 195 feed = [[Feed alloc] initWithLatestChattyAndDelegate:self];
c0281ada » Squeegy 2008-08-12 Utilize the status bar netw... 196 [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
c6ade158 » Squeegy 2008-08-01 Initial commit 197 }
198
199 - (IBAction)compose:(id)sender {
14c35411 » Squeegy 2008-08-02 Added compose views. 200 ComposeViewController *composeViewController = [[ComposeViewController alloc] initWithStoryId:feed.storyId];
201 [[self navigationController] pushViewController:composeViewController animated:YES];
202 [composeViewController release];
c6ade158 » Squeegy 2008-08-01 Initial commit 203 }
204
205
206 @end
207