Skip to content

Commit

Permalink
Clean up iPhone / iPad sample
Browse files Browse the repository at this point in the history
Dismiss auth dialog
  • Loading branch information
pokeb committed Jun 26, 2010
1 parent aea86b9 commit 1247da7
Show file tree
Hide file tree
Showing 11 changed files with 215 additions and 164 deletions.
1 change: 1 addition & 0 deletions Classes/ASIAuthenticationDialog.m
Expand Up @@ -357,6 +357,7 @@ - (void)loginWithCredentialsFromDialog:(id)sender
[requestsNeedingAuthentication removeObject:theRequest];
}
[self performSelector:@selector(presentNextDialog) withObject:nil afterDelay:1];
[self dismiss];
}

#pragma mark table view data source
Expand Down
2 changes: 1 addition & 1 deletion Classes/ASIHTTPRequest.m
Expand Up @@ -24,7 +24,7 @@

// Automatically set on build

NSString *ASIHTTPRequestVersion = @"v1.6.2-68 2010-06-25";
NSString *ASIHTTPRequestVersion = @"v1.6.2-69 2010-06-26";

NSString* const NetworkRequestErrorDomain = @"ASIHTTPRequestErrorDomain";

Expand Down
68 changes: 37 additions & 31 deletions iPhone Sample/AuthenticationViewController.m
Expand Up @@ -135,48 +135,54 @@ - (UIView *)tableView:(UITableView *)theTableView viewForHeaderInSection:(NSInte

- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
if ([indexPath section] == 0) {
cell = [InfoCell cellWithDescription:intro];
} else if ([indexPath section] == 1) {
cell = [tableView dequeueReusableCellWithIdentifier:@"ToggleCell"];
if (!cell) {
cell = [ToggleCell cell];
}
} else {
cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];
if (!cell) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCell"] autorelease];
}
}
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

int tablePadding = 40;
int tableWidth = [tableView frame].size.width;
if (tableWidth > 480) { // iPad
tablePadding = 110;
}

switch ([indexPath section]) {
case 1:
switch ([indexPath row]) {
case 0:
[[cell textLabel] setText:@"Use Keychain"];
useKeychain = [(ToggleCell *)cell toggle];
break;
case 1:
[[cell textLabel] setText:@"Use Built-In Dialog"];
useBuiltInDialog = [(ToggleCell *)cell toggle];
break;

UITableViewCell *cell;
if ([indexPath section] == 0) {

cell = [tableView dequeueReusableCellWithIdentifier:@"InfoCell"];
if (!cell) {
cell = [InfoCell cell];
}
[[cell textLabel] setText:intro];
[cell layoutSubviews];

} else if ([indexPath section] == 1) {
cell = [tableView dequeueReusableCellWithIdentifier:@"ToggleCell"];
if (!cell) {
cell = [ToggleCell cell];
if ([indexPath row] == 0) {
[[cell textLabel] setText:@"Use Keychain"];
useKeychain = [(ToggleCell *)cell toggle];
} else {
[[cell textLabel] setText:@"Use Built-In Dialog"];
useBuiltInDialog = [(ToggleCell *)cell toggle];
}
break;
case 2:
responseField = [[[UITextView alloc] initWithFrame:CGRectMake(5,5,tableWidth-tablePadding,150)] autorelease];
}

} else if ([indexPath section] == 2) {

cell = [tableView dequeueReusableCellWithIdentifier:@"Response"];
if (!cell) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Response"] autorelease];

responseField = [[[UITextView alloc] initWithFrame:CGRectZero] autorelease];
[responseField setBackgroundColor:[UIColor clearColor]];
[responseField setText:@"Secret information will appear here if authentication succeeds"];
[[cell contentView] addSubview:responseField];
break;
}
[responseField setFrame:CGRectMake(5,5,tableWidth-tablePadding,150)];


}
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];


return cell;
}

Expand Down
2 changes: 1 addition & 1 deletion iPhone Sample/InfoCell.h
Expand Up @@ -12,6 +12,6 @@
@interface InfoCell : UITableViewCell {

}
+ (id)cellWithDescription:(NSString *)description;
+ (id)cell;
+ (NSUInteger)neededHeightForDescription:(NSString *)description withTableWidth:(NSUInteger)tableWidth;
@end
4 changes: 1 addition & 3 deletions iPhone Sample/InfoCell.m
Expand Up @@ -11,7 +11,7 @@

@implementation InfoCell

+ (id)cellWithDescription:(NSString *)description
+ (id)cell
{
InfoCell *cell = [[[InfoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"InfoCell"] autorelease];
if ([[UIScreen mainScreen] bounds].size.width > 480) { // iPad
Expand All @@ -21,8 +21,6 @@ + (id)cellWithDescription:(NSString *)description
}
[[cell textLabel] setLineBreakMode:UILineBreakModeWordWrap];
[[cell textLabel] setNumberOfLines:0];
[[cell textLabel] setText:description];
[[cell textLabel] sizeToFit];

if ([[UIScreen mainScreen] bounds].size.width > 480) { // iPad
UIImageView *imageView = [[[UIImageView alloc] initWithFrame:CGRectMake(10,10,48,48)] autorelease];
Expand Down
3 changes: 3 additions & 0 deletions iPhone Sample/QueueViewController.h
Expand Up @@ -22,6 +22,9 @@
UIProgressView *imageProgressIndicator1;
UIProgressView *imageProgressIndicator2;
UIProgressView *imageProgressIndicator3;
UILabel *imageLabel1;
UILabel *imageLabel2;
UILabel *imageLabel3;
BOOL failed;

}
Expand Down
155 changes: 91 additions & 64 deletions iPhone Sample/QueueViewController.m
Expand Up @@ -80,6 +80,7 @@ - (void)imageFetchFailed:(ASIHTTPRequest *)request
}

- (void)dealloc {
[progressIndicator release];
[networkQueue reset];
[networkQueue release];
[super dealloc];
Expand Down Expand Up @@ -115,7 +116,11 @@ - (UIView *)tableView:(UITableView *)theTableView viewForHeaderInSection:(NSInte
[goButton addTarget:self action:@selector(fetchThreeImages:) forControlEvents:UIControlEventTouchUpInside];
[view addSubview:goButton];

progressIndicator = [[[UIProgressView alloc] initWithFrame:CGRectMake((tablePadding/2)-10,20,200,10)] autorelease];
if (!progressIndicator) {
progressIndicator = [[UIProgressView alloc] initWithFrame:CGRectMake((tablePadding/2)-10,20,200,10)];
} else {
[progressIndicator setFrame:CGRectMake((tablePadding/2)-10,20,200,10)];
}
[view addSubview:progressIndicator];

return view;
Expand All @@ -125,88 +130,110 @@ - (UIView *)tableView:(UITableView *)theTableView viewForHeaderInSection:(NSInte

- (UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
int tablePadding = 40;
int tableWidth = [tableView frame].size.width;
if (tableWidth > 480) { // iPad
tablePadding = 110;
}

UITableViewCell *cell;
if ([indexPath section] == 0) {
cell = [InfoCell cellWithDescription:intro];
cell = [tableView dequeueReusableCellWithIdentifier:@"InfoCell"];
if (!cell) {
cell = [InfoCell cell];
}
[[cell textLabel] setText:intro];
[cell layoutSubviews];

} else if ([indexPath section] == 1) {
cell = [tableView dequeueReusableCellWithIdentifier:@"ToggleCell"];
if (!cell) {
cell = [ToggleCell cell];
}
} else {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MyCell"] autorelease];
}
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

int tablePadding = 40;
int tableWidth = [tableView frame].size.width;
if (tableWidth > 480) { // iPad
tablePadding = 110;
}

if ([indexPath section] == 1) {
[[cell textLabel] setText:@"Show Accurate Progress"];
accurateProgress = [(ToggleCell *)cell toggle];
} else if ([indexPath section] == 2) {

NSUInteger imageWidth = (tableWidth-tablePadding-20)/3;
NSUInteger imageHeight = imageWidth*0.66;
} else {

imageView1 = [[[UIImageView alloc] initWithFrame:CGRectMake(tablePadding/2,10,imageWidth,imageHeight)] autorelease];
[imageView1 setBackgroundColor:[UIColor grayColor]];
[cell addSubview:imageView1];
cell = [tableView dequeueReusableCellWithIdentifier:@"ImagesCell"];

imageProgressIndicator1 = [[[UIProgressView alloc] initWithFrame:CGRectMake(tablePadding/2,15+imageHeight,imageWidth,20)] autorelease];
[cell addSubview:imageProgressIndicator1];

UILabel *label = [[[UILabel alloc] initWithFrame:CGRectMake(tablePadding/2,25+imageHeight,imageWidth,20)] autorelease];
if (tableWidth > 480) {
[label setText:@"This image is 15KB in size"];
} else {
[label setText:@"Img size: 15KB"];
if (!cell) {

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ImagesCell"] autorelease];

imageView1 = [[[UIImageView alloc] initWithFrame:CGRectZero] autorelease];
[imageView1 setBackgroundColor:[UIColor grayColor]];
[cell addSubview:imageView1];

imageProgressIndicator1 = [[[UIProgressView alloc] initWithFrame:CGRectZero] autorelease];
[cell addSubview:imageProgressIndicator1];

imageLabel1 = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
if (tableWidth > 480) {
[imageLabel1 setText:@"This image is 15KB in size"];
} else {
[imageLabel1 setText:@"Img size: 15KB"];
}
[imageLabel1 setTextAlignment:UITextAlignmentCenter];
[imageLabel1 setFont:[UIFont systemFontOfSize:11]];
[imageLabel1 setBackgroundColor:[UIColor clearColor]];
[cell addSubview:imageLabel1];

imageView2 = [[[UIImageView alloc] initWithFrame:CGRectZero] autorelease];
[imageView2 setBackgroundColor:[UIColor grayColor]];
[cell addSubview:imageView2];

imageProgressIndicator2 = [[[UIProgressView alloc] initWithFrame:CGRectZero] autorelease];
[cell addSubview:imageProgressIndicator2];

imageLabel2 = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
if (tableWidth > 480) {
[imageLabel2 setText:@"This image is 176KB in size"];
} else {
[imageLabel2 setText:@"Img size: 176KB"];
}
[imageLabel2 setTextAlignment:UITextAlignmentCenter];
[imageLabel2 setFont:[UIFont systemFontOfSize:11]];
[imageLabel2 setBackgroundColor:[UIColor clearColor]];
[cell addSubview:imageLabel2];

imageView3 = [[[UIImageView alloc] initWithFrame:CGRectZero] autorelease];
[imageView3 setBackgroundColor:[UIColor grayColor]];
[cell addSubview:imageView3];

imageProgressIndicator3 = [[[UIProgressView alloc] initWithFrame:CGRectZero] autorelease];
[cell addSubview:imageProgressIndicator3];

imageLabel3 = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
if (tableWidth > 480) {
[imageLabel3 setText:@"This image is 1.4MB in size"];
} else {
[imageLabel3 setText:@"Img size: 1.4MB"];
}
[imageLabel3 setTextAlignment:UITextAlignmentCenter];
[imageLabel3 setFont:[UIFont systemFontOfSize:11]];
[imageLabel3 setBackgroundColor:[UIColor clearColor]];
[cell addSubview:imageLabel3];

}
[label setTextAlignment:UITextAlignmentCenter];
[label setFont:[UIFont systemFontOfSize:11]];
[label setBackgroundColor:[UIColor clearColor]];
[cell addSubview:label];

imageView2 = [[[UIImageView alloc] initWithFrame:CGRectMake((tablePadding/2)+imageWidth+10,10,imageWidth,imageHeight)] autorelease];
[imageView2 setBackgroundColor:[UIColor grayColor]];
[cell addSubview:imageView2];
NSUInteger imageWidth = (tableWidth-tablePadding-20)/3;
NSUInteger imageHeight = imageWidth*0.66;

imageProgressIndicator2 = [[[UIProgressView alloc] initWithFrame:CGRectMake((tablePadding/2)+imageWidth+10,15+imageHeight,imageWidth,20)] autorelease];
[cell addSubview:imageProgressIndicator2];

label = [[[UILabel alloc] initWithFrame:CGRectMake(tablePadding/2+imageWidth+10,25+imageHeight,imageWidth,20)] autorelease];
if (tableWidth > 480) {
[label setText:@"This image is 176KB in size"];
} else {
[label setText:@"Img size: 176KB"];
}
[label setTextAlignment:UITextAlignmentCenter];
[label setFont:[UIFont systemFontOfSize:11]];
[label setBackgroundColor:[UIColor clearColor]];
[cell addSubview:label];
[imageView1 setFrame:CGRectMake(tablePadding/2,10,imageWidth,imageHeight)];
[imageProgressIndicator1 setFrame:CGRectMake(tablePadding/2,15+imageHeight,imageWidth,20)];
[imageLabel1 setFrame:CGRectMake(tablePadding/2,25+imageHeight,imageWidth,20)];

imageView3 = [[[UIImageView alloc] initWithFrame:CGRectMake((tablePadding/2)+(imageWidth*2)+20,10,imageWidth,imageHeight)] autorelease];
[imageView3 setBackgroundColor:[UIColor grayColor]];
[cell addSubview:imageView3];
[imageView2 setFrame:CGRectMake((tablePadding/2)+imageWidth+10,10,imageWidth,imageHeight)];
[imageProgressIndicator2 setFrame:CGRectMake((tablePadding/2)+imageWidth+10,15+imageHeight,imageWidth,20)];
[imageLabel2 setFrame:CGRectMake(tablePadding/2+imageWidth+10,25+imageHeight,imageWidth,20)];

imageProgressIndicator3 = [[[UIProgressView alloc] initWithFrame:CGRectMake((tablePadding/2)+(imageWidth*2)+20,15+imageHeight,imageWidth,20)] autorelease];
[cell addSubview:imageProgressIndicator3];

label = [[[UILabel alloc] initWithFrame:CGRectMake(tablePadding/2+(imageWidth*2)+20,25+imageHeight,imageWidth,20)] autorelease];
if (tableWidth > 480) {
[label setText:@"This image is 1.4MB in size"];
} else {
[label setText:@"Img size: 1.4MB"];
}
[label setTextAlignment:UITextAlignmentCenter];
[label setFont:[UIFont systemFontOfSize:11]];
[label setBackgroundColor:[UIColor clearColor]];
[cell addSubview:label];

[imageView3 setFrame:CGRectMake((tablePadding/2)+(imageWidth*2)+20,10,imageWidth,imageHeight)];
[imageProgressIndicator3 setFrame:CGRectMake((tablePadding/2)+(imageWidth*2)+20,15+imageHeight,imageWidth,20)];
[imageLabel3 setFrame:CGRectMake(tablePadding/2+(imageWidth*2)+20,25+imageHeight,imageWidth,20)];
}
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
return cell;
}

Expand Down
1 change: 1 addition & 0 deletions iPhone Sample/SynchronousViewController.h
Expand Up @@ -14,6 +14,7 @@
ASIHTTPRequest *request;
UITextField *urlField;
UITextView *responseField;
UIButton *goButton;

}
- (IBAction)simpleURLFetch:(id)sender;
Expand Down

0 comments on commit 1247da7

Please sign in to comment.