Skip to content

Commit

Permalink
UI Work, minor bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
EverythingSolution committed Oct 4, 2010
1 parent 250f049 commit c446574
Show file tree
Hide file tree
Showing 30 changed files with 3,773 additions and 160 deletions.
4 changes: 2 additions & 2 deletions ADModel-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSMainNibFile</key>
<string>MainWindow_iPhone</string>
<string>MainWindow~iPhone</string>
<key>NSMainNibFile~ipad</key>
<string>MainWindow_iPad</string>
<string>MainWindow~iPad</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
Expand Down
120 changes: 95 additions & 25 deletions ADModel.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions ADModel_Prefix.pch
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "UtilityFunctions.h"
#import "GUIFunctions.h"
#endif
6 changes: 5 additions & 1 deletion Classes/DataModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ typedef enum {
kBadServerURLCode,
kUnavailableURLCode,
kPutCreateURL,
kPutNoContentURL,
} OperationCodes;

#import <Foundation/Foundation.h>
Expand Down Expand Up @@ -77,14 +78,17 @@ typedef enum {
- (void)putNoContentURL;

- (NSString *)generateConnectionID;
- (NSString *)logNSURLError:(int)errorCode;
- (NSString *)stringForNSURLError:(int)errorCode;

@end

@protocol DataModelDelegate
- (void)error:(NSError *)error operationCode:(NSInteger)code;
@optional
- (void)podcastFeed:(NSArray *)feedItems;
- (void)twitterSearchFeed:(NSArray *)tweets;
- (void)twitterUserFeed:(NSArray *)tweets;
- (void)postPrint:(NSString *)result;
- (void)putCreate:(NSString *)response;
- (void)putNoContent:(NSString *)response;
@end
69 changes: 55 additions & 14 deletions Classes/DataModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,10 @@ - (void)putCreateURL
op.parseType = NoParse;
op.instanceCode = kPutCreateURL;
op.URI = @"/ESModelAPI/Put/Created/index.php";
op.headerDict = [NSDictionary dictionaryWithObjectsAndKeys:
@"Header_Value_One", @"Header_Field_One",
@"Header_Value_Two", @"Header_Field_Two", nil];
op.bodyDataArray = [NSArray arrayWithObject:[@"Put Test String Encoded As Data\n" dataUsingEncoding:NSUTF8StringEncoding]];
// op.headerDict = [NSDictionary dictionaryWithObjectsAndKeys:
// @"Header_Value_One", @"Header_Field_One",
// @"Header_Value_Two", @"Header_Field_Two", nil];
op.bodyDataArray = [NSArray arrayWithObject:[@"Put Test String\n" dataUsingEncoding:NSUTF8StringEncoding]];
//op.connectionID = [self generateConnectionID];
if (connected)
[operationQueue addOperation:op];
Expand All @@ -299,7 +299,7 @@ - (void)putNoContentURL
op.delegate = self;
op.requestType = PUT;
op.parseType = NoParse;
op.instanceCode = kPutCreateURL;
op.instanceCode = kPutNoContentURL;
op.URI = @"/ESModelAPI/Put/NoContent/index.php";
op.headerDict = [NSDictionary dictionaryWithObjectsAndKeys:
@"Header_Value_One", @"Header_Field_One",
Expand All @@ -316,7 +316,7 @@ - (NSString *)generateConnectionID
{
return [NSString stringWithFormat:@"%f", CFAbsoluteTimeGetCurrent()];
}
- (NSString *)logNSURLError:(int)errorCode
- (NSString *)stringForNSURLError:(int)errorCode
{
switch (errorCode) {
case NSURLErrorUnknown:
Expand Down Expand Up @@ -550,12 +550,13 @@ - (void)networkOperationDidComplete:(NetworkOperation *)operation withResult:(id
statusCode,
headers,
value);
NSMutableArray * dlgts;
NSArray * dlgts;
NSString * resultString;
switch (operation.instanceCode) {
case kPodcastFeedCode:
NSParameterAssert([result isKindOfClass:[NSArray class]]);
NSParameterAssert(([(NSArray *)result count] > 0));
dlgts = [[NSMutableArray alloc] initWithArray:delegates];
dlgts = [[NSArray alloc] initWithArray:delegates];
for (id delegate in dlgts)
{
if ([delegate respondsToSelector:@selector(podcastFeed:)])
Expand All @@ -571,7 +572,7 @@ - (void)networkOperationDidComplete:(NetworkOperation *)operation withResult:(id
// Also in a real app I would hold onto the refresh url instead of
// making new queries each time
NSArray * results = [(NSDictionary *)result objectForKey:@"results"];
dlgts = [[NSMutableArray alloc] initWithArray:delegates];
dlgts = [[NSArray alloc] initWithArray:delegates];
for (id delegate in dlgts)
{
if ([delegate respondsToSelector:@selector(twitterSearchFeed:)])
Expand All @@ -587,7 +588,7 @@ - (void)networkOperationDidComplete:(NetworkOperation *)operation withResult:(id
// Also in a real app I would hold onto the refresh url instead of
// making new queries each time
// Also in a real I would need to check for users set to priavte (result would be nil)
dlgts = [[NSMutableArray alloc] initWithArray:delegates];
dlgts = [[NSArray alloc] initWithArray:delegates];
for (id delegate in dlgts)
{
if ([delegate respondsToSelector:@selector(twitterUserFeed:)])
Expand All @@ -597,16 +598,50 @@ - (void)networkOperationDidComplete:(NetworkOperation *)operation withResult:(id
break;
case kPostPrintCode:
NSParameterAssert([result isKindOfClass:[NSArray class]]);
NSString * resultString = [NSString stringWithFormat:@"%@", result];
resultString = [NSString stringWithFormat:@"%@", result];
NSParameterAssert((resultString != nil));
dlgts = [[NSMutableArray alloc] initWithArray:delegates];
dlgts = [[NSArray alloc] initWithArray:delegates];
for (id delegate in dlgts)
{
if ([delegate respondsToSelector:@selector(postPrint:)])
[delegate postPrint:resultString];
}
CleanRelease(dlgts);
break;
case kPutCreateURL:
NSParameterAssert([result isKindOfClass:[NSData class]]);
NSParameterAssert(([(NSHTTPURLResponse *)operation.response statusCode] == 201));
resultString = [[[NSString alloc] initWithData:(NSData *)result encoding:NSUTF8StringEncoding] autorelease];
NSParameterAssert((resultString != nil));
dlgts = [[NSArray alloc] initWithArray:delegates];
for (id delegate in dlgts)
{
if ([delegate respondsToSelector:@selector(putCreate:)])
[delegate putCreate:resultString];
}
CleanRelease(dlgts);
break;
case kPutNoContentURL:
NSParameterAssert([result isKindOfClass:[NSData class]]);
NSParameterAssert(([(NSData *)result length] == 0));
NSInteger statusCode = 0;
NSDictionary * headers = nil;
if ([operation.response isKindOfClass:[NSHTTPURLResponse class]])
{
statusCode = [(NSHTTPURLResponse *)operation.response statusCode];
headers = [(NSHTTPURLResponse *)operation.response allHeaderFields];
}
resultString = [NSString stringWithFormat:@"Response Status Code: %d\nHeaders: %@",
statusCode,
headers];
dlgts = [[NSArray alloc] initWithArray:delegates];
for (id delegate in dlgts)
{
if ([delegate respondsToSelector:@selector(putNoContent:)])
[delegate putNoContent:resultString];
}
CleanRelease(dlgts);
break;
default:
break;
}
Expand All @@ -623,8 +658,14 @@ - (void)networkOperationDidFail:(NetworkOperation *)operation withError:(NSError
operation.URI,
error,
statusCode,
[self logNSURLError:error.code]);
// Report error
[self stringForNSURLError:error.code]);
NSArray * dlgts = [[NSArray alloc] initWithArray:delegates];
for (id delegate in dlgts)
{
if ([delegate respondsToSelector:@selector(error:operationCode:)])
[delegate error:error operationCode:operation.instanceCode];
}
CleanRelease(dlgts);
}
/******************************************************************************/
#pragma mark -
Expand Down
32 changes: 26 additions & 6 deletions Classes/MainWindow_iPad.xib → Classes/MainWindow~iPad.xib
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
</object>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
<integer value="3"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
Expand Down Expand Up @@ -77,12 +76,16 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="IBUIViewController" id="924972615">
<object class="IBUINavigationItem" key="IBUINavigationItem" id="1046310561">
<reference key="IBUINavigationBar"/>
<string key="IBUITitle">Root View Controller</string>
<string key="IBUITitle">Asynchronous Data Model</string>
<object class="IBUIBarButtonItem" key="IBUIBackBarButtonItem" id="929167298">
<string key="IBUITitle">Back</string>
<string key="targetRuntimeIdentifier">IBIPadFramework</string>
<int key="IBUIStyle">1</int>
</object>
<string key="targetRuntimeIdentifier">IBIPadFramework</string>
</object>
<reference key="IBUIParentViewController" ref="897686312"/>
<string key="IBUINibName">RootView_iPad</string>
<string key="IBUINibName">RootView~iPad</string>
<object class="IBUISimulatedOrientationMetrics" key="IBUISimulatedOrientationMetrics">
<int key="interfaceOrientation">1</int>
</object>
Expand Down Expand Up @@ -172,13 +175,22 @@
<object class="IBObjectRecord">
<int key="objectID">6</int>
<reference key="object" ref="1046310561"/>
<object class="NSMutableArray" key="children">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="929167298"/>
</object>
<reference key="parent" ref="924972615"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">8</int>
<reference key="object" ref="891484457"/>
<reference key="parent" ref="0"/>
</object>
<object class="IBObjectRecord">
<int key="objectID">11</int>
<reference key="object" ref="929167298"/>
<reference key="parent" ref="1046310561"/>
</object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
Expand Down Expand Up @@ -228,7 +240,7 @@
</object>
</object>
<nil key="sourceID"/>
<int key="maxID">10</int>
<int key="maxID">11</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
Expand Down Expand Up @@ -274,8 +286,16 @@
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">RootViewController</string>
<string key="className">ModelViewController</string>
<string key="superclassName">UIViewController</string>
<object class="IBClassDescriptionSource" key="sourceIdentifier">
<string key="majorKey">IBProjectSource</string>
<string key="minorKey">Classes/ModelViewController.h</string>
</object>
</object>
<object class="IBPartialClassDescription">
<string key="className">RootViewController</string>
<string key="superclassName">ModelViewController</string>
<object class="NSMutableDictionary" key="actions">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSArray" key="dict.sortedKeys">
Expand Down
17 changes: 13 additions & 4 deletions Classes/ModelTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ - (void)viewDidUnload
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
// if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
return YES;
else
return ((toInterfaceOrientation == UIInterfaceOrientationPortrait) ||
(toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown));
// else
// return ((toInterfaceOrientation == UIInterfaceOrientationPortrait) ||
// (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown));
}
/******************************************************************************/
#pragma mark -
Expand Down Expand Up @@ -113,6 +113,15 @@ - (void)reloadTableView
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

}
/******************************************************************************/
#pragma mark -
#pragma mark Data Model Delegate
#pragma mark -
/******************************************************************************/
- (void)error:(NSError *)error operationCode:(NSInteger)code
{

}

@end
Expand Down
18 changes: 13 additions & 5 deletions Classes/ModelViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ - (void)viewDidUnload
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
// if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
return YES;
else
return ((toInterfaceOrientation == UIInterfaceOrientationPortrait) ||
(toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown));
// else
// return ((toInterfaceOrientation == UIInterfaceOrientationPortrait) ||
// (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown));
}
/******************************************************************************/
#pragma mark -
Expand All @@ -80,6 +80,14 @@ - (void)dealloc
CleanRelease(activityIndicator);
[super dealloc];
}

/******************************************************************************/
#pragma mark -
#pragma mark Data Model Delegate
#pragma mark -
/******************************************************************************/
- (void)error:(NSError *)error operationCode:(NSInteger)code
{

}

@end
29 changes: 23 additions & 6 deletions Classes/PodcastTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,9 @@ @implementation PodcastTableViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.title = @"Podcast";
[model podcastFeed];
}
- (void)podcastFeed:(NSArray *)feedItems
{
self.items = feedItems;
[self reloadTableView];
[self.activityIndicator stopAnimating];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
Expand All @@ -42,6 +37,28 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
cell.textLabel.text = [[self.items objectAtIndex:indexPath.row] objectForKey:@"title"];
return cell;
}
/******************************************************************************/
#pragma mark -
#pragma mark Data Model Delegate
#pragma mark -
/******************************************************************************/
- (void)error:(NSError *)error operationCode:(NSInteger)code
{
if (code == kPodcastFeedCode)
{
BasicAlert(@"Error",
error.domain,
nil,
@"OK",
nil);
}
}
- (void)podcastFeed:(NSArray *)feedItems
{
self.items = feedItems;
[self reloadTableView];
[self.activityIndicator stopAnimating];
}

@end

Loading

0 comments on commit c446574

Please sign in to comment.