Permalink
Browse files

oops, large commit. webviewer finished, partially completed ResultVie…

…wController.
  • Loading branch information...
1 parent b066c49 commit a18dbaf8fcca2e60b05b44a14b226cd4f93d1324 Sahil Desai committed Oct 25, 2009
View
BIN Back.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
@@ -24,7 +24,7 @@ - (id)deserializeAsDictionary:(NSData *)inData error:(NSError **)outError;
{
if (inData == NULL || [inData length] == 0)
{
- if (*outError)
+ if (outError != NULL && *outError)
*outError = [NSError errorWithDomain:kJSONDeserializerErrorDomain code:-1 userInfo:NULL];
return(NULL);
@@ -47,7 +47,7 @@ - (id)deserialize:(NSData *)inData error:(NSError **)outError
{
if (inData == NULL || [inData length] == 0)
{
- if (*outError)
+ if (outError != NULL && *outError)
*outError = [NSError errorWithDomain:kJSONDeserializerErrorDomain code:-1 userInfo:NULL];
return(NULL);
@@ -3,26 +3,25 @@
@implementation DomainrAppDelegate
-@synthesize window;
-@synthesize navigationController;
+ @synthesize window;
+ @synthesize navigationController;
-- (void)applicationDidFinishLaunching:(UIApplication *)application {
- MainViewController *mainViewController = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
- UINavigationController *aNavigationController = [[UINavigationController alloc] initWithRootViewController:mainViewController];
- self.navigationController = aNavigationController;
- [aNavigationController release];
- [mainViewController release];
- [self.navigationController setNavigationBarHidden:YES];
-
- [window addSubview:[navigationController view]];
- [window makeKeyAndVisible];
-}
+ - (void)applicationDidFinishLaunching:(UIApplication *)application; {
+ MainViewController *mainViewController = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
+ UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:mainViewController];
+ self.navigationController = navController;
+ Release(navController);
+ Release(mainViewController);
+
+ [self.navigationController setNavigationBarHidden:YES];
+ [window addSubview:[self.navigationController view]];
+ [window makeKeyAndVisible];
+ }
-- (void)dealloc {
- [window release];
- [super dealloc];
-}
-
+ - (void)dealloc; {
+ [window release];
+ [super dealloc];
+ }
@end
@@ -1,14 +1,14 @@
#import <UIKit/UIKit.h>
#import "CJSONDeserializer.h"
+@class DomainrTableView;
@class Reachability;
@interface MainViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, UISearchBarDelegate, UINavigationBarDelegate> {
- UINavigationController *navController;
- IBOutlet UITableView *myTableView;
- IBOutlet UISearchBar *mySearchBar;
- IBOutlet UIActivityIndicatorView *activityIndicator;
- IBOutlet UIView *whiteBgView;
+ IBOutlet DomainrTableView *myTableView;
+ IBOutlet UISearchBar *mySearchBar;
+ IBOutlet UIActivityIndicatorView *activityIndicator;
+ IBOutlet UIView *whiteBgView;
NSData *jsonData;
NSURL *jsonURL;
@@ -32,8 +32,8 @@
UIAlertView *alert;
}
-@property (nonatomic, retain) UITableView *myTableView;
-@property (nonatomic, retain) UISearchBar *mySearchBar;
+@property (nonatomic, retain) DomainrTableView *myTableView;
+@property (nonatomic, retain) UISearchBar *mySearchBar;
- (void) toggleActivityIndicator:(BOOL)show;
- (void) setKeyboardState:(BOOL)show;
@@ -1,13 +1,15 @@
#import "MainViewController.h"
#import "ResultCell.h"
#import "Reachability.h"
+#import "DomainrTableView.h"
+#import "ResultViewController.h"
@implementation MainViewController
@synthesize myTableView;
@synthesize mySearchBar;
- - (void)dealloc {
+ - (void)dealloc; {
Release(myTableView);
Release(mySearchBar);
Release(activityIndicator);
@@ -40,11 +42,11 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
return self;
}
- - (void)viewDidAppear:(BOOL)animated; {
- [super viewDidAppear: animated];
+ - (void)viewWillAppear:(BOOL)animated; {
+ [super viewWillAppear: animated];
}
- - (void)viewDidLoad {
+ - (void)viewDidLoad; {
internetReach = [[Reachability reachabilityForInternetConnection] retain];
[internetReach startNotifer];
@@ -57,14 +59,20 @@ - (void)viewDidLoad {
[super viewDidLoad];
}
+ - (void)viewDidUnload; {
+ Release(internetReach);
+ [super viewDidUnload];
+ }
+
+
#pragma mark -
#pragma mark Various helpers
#pragma mark -
- - (BOOL)networkAvailable {
+ - (BOOL)networkAvailable; {
if ([internetReach currentReachabilityStatus] == NotReachable) {
- UIAlertView *networkAlert = [[UIAlertView alloc] initWithTitle:@"Network Error" message:@"Sorry, the network isn't available." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
+ UIAlertView *networkAlert = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Network Error",nil) message:NSLocalizedString(@"Sorry, the network isn't available.",nil) delegate:self cancelButtonTitle:nil otherButtonTitles:NSLocalizedString(@"OK",nil), nil];
[networkAlert show];
Release(networkAlert);
return NO;
@@ -88,6 +96,7 @@ - (void)toggleActivityIndicator:(BOOL)show; {
- (void)setKeyboardState:(BOOL)show; {
keyboardHidden = !show;
+
CGRect newFrame = [myTableView frame];
if(show) {
newFrame.size.height = UIInterfaceOrientationIsPortrait(self.interfaceOrientation) ? 460 - 44 - KEYBOARD_HEIGHT_PORTRAIT : 300 - 44 - KEYBOARD_HEIGHT_LANDSCAPE;
@@ -107,15 +116,15 @@ - (void)_showKeyboardWorkAround; {
#pragma mark UISearchBar methods
#pragma mark -
- - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar { // return NO to not become first responder
+ - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar; { // return NO to not become first responder
return YES;
}
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar; {
[self performSelector:@selector(_showKeyboardWorkAround) withObject:nil afterDelay:0.5];
}
- - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{ // called when text changes (including clear)
+ - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText; { // called when text changes (including clear)
if([searchText isEqualToString:@""]) {
[self toggleActivityIndicator:NO];
@@ -126,7 +135,7 @@ - (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText{
[self search];
}
- - (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { // called before text changes
+ - (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text; { // called before text changes
if(![self networkAvailable]) return NO;
if(([text isEqualToString:@""] && [[mySearchBar text] length] == 0)) {
@@ -141,14 +150,14 @@ - (BOOL)searchBar:(UISearchBar *)searchBar shouldChangeTextInRange:(NSRange)rang
return YES;
}
- - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { // called when keyboard search button pressed
+ - (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar; { // called when keyboard search button pressed
[self setKeyboardState:NO];
if(![self networkAvailable]) return;
[self search];
}
- - (void)search {
+ - (void)search; {
NSString *searchText = [mySearchBar text];
[self toggleActivityIndicator:YES];
@@ -163,27 +172,24 @@ - (void)search {
theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
- NSLog(@"Request submitted");
receivedData=[[NSMutableData data] retain];
- } else {
- NSLog(@"Failed to submit request");
+ }
+ else {
}
}
#pragma mark -
#pragma mark NSURLConnection methods
#pragma mark -
- - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
+ - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data; {
[receivedData appendData:data];
}
- - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
+ - (void)connectionDidFinishLoading:(NSURLConnection *)connection; {
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(_showClearButton) object:nil];
NSError *error = nil;
- jsonString = [[NSString alloc] initWithData:receivedData encoding:NSASCIIStringEncoding];
- jsonData = [jsonString dataUsingEncoding:NSUTF32BigEndianStringEncoding];
- NSDictionary *dictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error];
+ NSDictionary *dictionary = [[CJSONDeserializer deserializer] deserializeAsDictionary:receivedData error:&error];
if(results)
Release(results);
@@ -194,12 +200,13 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
newResult.domainName = [result objectForKey:@"domain"];
newResult.availability = [result objectForKey:@"availability"];
newResult.path = [result objectForKey:@"path"];
-
+ newResult.registerURL = [result objectForKey:@"register_url"];
NSMutableArray *registrars = [result objectForKey:@"registrars"];
for (NSString *registrar in registrars) {
[newResult.registrars addObject:registrar];
}
[results addObject:newResult];
+ Release(newResult);
}
[receivedData setLength:0];
@@ -209,7 +216,7 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection {
[myTableView reloadData];
loading = NO;
[self toggleActivityIndicator:NO];
- [self performSelector:@selector(_showClearButton) withObject:nil afterDelay:0];
+ [self performSelector:@selector(_showClearButton) withObject:nil afterDelay:0.1];
}
- (void)_showClearButton; {
@@ -224,7 +231,7 @@ - (void)_hideClearButton; {
#pragma mark Table view methods
#pragma mark -
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
+ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath; {
if(results == nil) return 40;
NSString *domainNameString = [[results objectAtIndexA:indexPath.row] domainName];
@@ -235,23 +242,26 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa
return aSize.height+35;
}
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
+ - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; {
return 1;
}
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
+ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; {
if(results == nil) return 0;
return [results count];
}
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
+ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; {
ResultCell *cell = (ResultCell *)[tableView cellForClass:[ResultCell class]];
[cell setResult:[results objectAtIndexA:indexPath.row]];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
return cell;
}
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
+ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath; {
+
+ ResultViewController *resultViewController = [[[ResultViewController alloc] initWithResult:[results objectAtIndexA:indexPath.row]] autorelease];
+ [self.navigationController pushViewController:resultViewController animated:YES];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
View
@@ -6,6 +6,7 @@
NSString *domainName;
NSString *availability;
NSString *path;
+ NSString *registerURL;
NSMutableArray *registrars;
int imageType;
@@ -15,9 +16,12 @@
@property (retain) NSString *domainName;
@property (retain) NSString *availability;
@property (retain) NSString *path;
+@property (retain) NSString *registerURL;
@property (retain) NSMutableArray *registrars;
@property int imageType;
@property (assign) ResultCell *resultCell;
+-(BOOL)isResolvable;
+
@end
View
@@ -2,20 +2,20 @@
@implementation Result
- @synthesize domainName, availability, path, registrars, resultCell, imageType;
+ @synthesize domainName, availability, path, registerURL, registrars, resultCell, imageType;
- (void)dealloc; {
Release(domainName);
Release(availability);
Release(registrars);
- Release(resultCell);
+ Release(registerURL);
[super dealloc];
}
- (NSMutableArray *)registrars; {
if(!registrars)
registrars = [[NSMutableArray alloc] init];
- return nil;
+ return registrars;
}
-(void)setAvailability:(NSString *)avail; {
@@ -24,35 +24,41 @@ -(void)setAvailability:(NSString *)avail; {
Release(availability);
- if([avail isEqualToString:@"available"]){
+ if([avail isEqualToString:NSLocalizedString(@"available",nil)]){
availability = [avail retain];
imageType = kAvailable;
}
- else if([avail isEqualToString:@"maybe"]) {
+ else if([avail isEqualToString:NSLocalizedString(@"maybe",nil)]) {
availability = [avail retain];
imageType = kMaybe;
}
- else if([avail isEqualToString:@"taken"]) {
+ else if([avail isEqualToString:NSLocalizedString(@"taken",nil)]) {
availability = [avail retain];
imageType = kTaken;
}
- else if([avail isEqualToString:@"tld"]) {
+ else if([avail isEqualToString:NSLocalizedString(@"tld",nil)]) {
imageType = kTLD;
- availability = [[NSString alloc] initWithString: @"top-level domain"];
+ availability = [@"top-level domain" retain];
}
- else if([avail isEqualToString:@"known"]) {
+ else if([avail isEqualToString:NSLocalizedString(@"known",nil)]) {
imageType = kTLD;
- availability = [[NSString alloc] initWithString: @"subdomain"];
+ availability = [@"subdomain" retain];
}
- else if([avail isEqualToString:@"unavailable"]) {
+ else if([avail isEqualToString:NSLocalizedString(@"unavailable",nil)]) {
availability = [avail retain];
imageType = kUnavailable;
}
else {
availability = [avail retain];
imageType = kTaken;
}
+ }
+ -(BOOL)isResolvable; {
+ if(imageType == kAvailable || imageType == kUnavailable || imageType == kTLD || imageType == kMaybe) {
+ return NO;
+ }
+ return YES;
}
@end
Oops, something went wrong.

0 comments on commit a18dbaf

Please sign in to comment.