Permalink
Browse files

starting to hook up repositories UI

  • Loading branch information...
sschroed committed Jan 28, 2009
1 parent 5d03d5b commit fec48ac3ef5418453ddaf02edea9fa606d05a2d9
@@ -55,12 +55,12 @@ - (void)textFieldDidEndEditing:(UITextField *)textField {
[self showAlert:@"Unable to authenticate using the credentials you provided." withTitle:@"Octocat FAIL"];
[userName becomeFirstResponder];
} else {
- [Repository loadAll];
[self dismissModalViewControllerAnimated:YES];
}
}
}
+//TODO: Refactor out this method
- (void)showAlert:(NSString *)message withTitle:(NSString *)title {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title
message:message
@@ -0,0 +1,19 @@
+//
+// RepositoriesViewController.h
+// git-phone
+//
+// Created by Sam Schroeder on 1/27/09.
+// Copyright 2009 Proton Microsystems, LLC. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+#import "RootViewController.h"
+
+
+@interface RepositoriesViewController : UITableViewController {
+ RootViewController *rootViewController;
+ NSArray *repositories;
+}
+@property (nonatomic, retain) RootViewController *rootViewController;
+
+@end
@@ -0,0 +1,108 @@
+//
+// RepositoriesViewController.m
+// git-phone
+//
+// Created by Sam Schroeder on 1/27/09.
+// Copyright 2009 Proton Microsystems, LLC. All rights reserved.
+//
+
+#import "RepositoriesViewController.h"
+
+
+@implementation RepositoriesViewController
+
+@synthesize rootViewController;
+
+/*
+- (id)initWithStyle:(UITableViewStyle)style {
+ // Override initWithStyle: if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
+ if (self = [super initWithStyle:style]) {
+ }
+ return self;
+}
+*/
+
+/*
+- (void)viewDidLoad {
+ [super viewDidLoad];
+
+ // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
+ // self.navigationItem.rightBarButtonItem = self.editButtonItem;
+}
+*/
+
+
+- (void)viewWillAppear:(BOOL)animated {
+ [repositories release];
+ repositories = [[[Config instance] repositories] retain];
+ [super viewWillAppear:animated];
+}
+
+/*
+- (void)viewDidAppear:(BOOL)animated {
+ [super viewDidAppear:animated];
+}
+*/
+/*
+- (void)viewWillDisappear:(BOOL)animated {
+ [super viewWillDisappear:animated];
+}
+*/
+/*
+- (void)viewDidDisappear:(BOOL)animated {
+ [super viewDidDisappear:animated];
+}
+*/
+
+
+- (void)didReceiveMemoryWarning {
+ [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
+ // Release anything that's not essential, such as cached data
+}
+
+#pragma mark Table view methods
+
+- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
+ return 1;
+}
+
+
+// Customize the number of rows in the table view.
+- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
+ return [repositories count];
+}
+
+
+// Customize the appearance of table view cells.
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
+
+ static NSString *CellIdentifier = @"RepositoryCell";
+
+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
+ if (cell == nil) {
+ cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
+ }
+
+ // Set up the cell...
+ cell.text = [(Repository *)[repositories objectAtIndex:[indexPath row]] name];
+ return cell;
+}
+
+
+- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
+ // Navigation logic may go here. Create and push another view controller.
+ // AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil];
+ // [self.navigationController pushViewController:anotherViewController];
+ // [anotherViewController release];
+}
+
+
+- (void)dealloc {
+ [repositories release];
+ [rootViewController release];
+ [super dealloc];
+}
+
+
+@end
+
@@ -8,6 +8,7 @@
#import "RootViewController.h"
#import "git_phoneAppDelegate.h"
+#import "RepositoriesViewController.h"
@implementation RootViewController
@@ -21,36 +22,6 @@ - (void)viewDidLoad {
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
-
-/*
-- (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
-}
-*/
-/*
-- (void)viewDidAppear:(BOOL)animated {
- [super viewDidAppear:animated];
-}
-*/
-/*
-- (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
-}
-*/
-/*
-- (void)viewDidDisappear:(BOOL)animated {
- [super viewDidDisappear:animated];
-}
-*/
-
-/*
-// Override to allow orientations other than the default portrait orientation.
-- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
- // Return YES for supported orientations
- return (interfaceOrientation == UIInterfaceOrientationPortrait);
-}
-*/
-
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
// Release anything that's not essential, such as cached data
@@ -104,52 +75,14 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- // Navigation logic may go here. Create and push another view controller.
- // AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil];
- // [self.navigationController pushViewController:anotherViewController];
- // [anotherViewController release];
-}
-
-
-/*
-// Override to support conditional editing of the table view.
-- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
- // Return NO if you do not want the specified item to be editable.
- return YES;
-}
-*/
-
-
-/*
-// Override to support editing the table view.
-- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
-
- if (editingStyle == UITableViewCellEditingStyleDelete) {
- // Delete the row from the data source
- [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
- }
- else if (editingStyle == UITableViewCellEditingStyleInsert) {
- // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
- }
+ RepositoriesViewController *repositoriesViewController = [[[RepositoriesViewController alloc] initWithNibName:@"RepositoriesView" bundle:nil] autorelease];
+ //repositoriesViewController.repositories = [photochecks objectAtIndex:[indexPath row]];
+ repositoriesViewController.rootViewController = self;
+ //[self.navigationController pushViewController:tableView animated:YES];
+ [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
-*/
-/*
-// Override to support rearranging the table view.
-- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
-}
-*/
-
-
-/*
-// Override to support conditional rearranging of the table view.
-- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
- // Return NO if you do not want the item to be re-orderable.
- return YES;
-}
-*/
-
- (void)dealloc {
[super dealloc];
}
@@ -17,5 +17,8 @@
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
+- (void)authenticate;
+- (void)showAlert:(NSString *)message withTitle:(NSString *)title;
+
@end
@@ -37,6 +37,10 @@ - (void)applicationDidFinishLaunching:(UIApplication *)application {
}
[self loadPreferences];
+ [self authenticate];
+
+ //LOAD MAIN APP
+ [Repository loadAll];
}
@@ -50,24 +54,40 @@ - (void) showError:(NSString *)errorMessage {
[[self window] addSubview:errorController.view];
}
+- (void) loadLoginView {
+ LoginViewController *loginViewController = [[[LoginViewController alloc] initWithNibName:@"Login" bundle:nil] autorelease];
+ [window addSubview:[loginViewController view]];
+ [navigationController presentModalViewController:loginViewController animated:YES];
+
+}
+- (void) authenticate {
+ // Check if username is set
+ if ([[Config instance] gitHubUserName] == NULL || [[Config instance] gitHubToken] == NULL) {
+ [self loadLoginView];
+ } else {
+ if (![Connector didAuthenticateUser:[[Config instance] gitHubUserName] withToken:[[Config instance] gitHubToken]]) {
+ [self showAlert:@"Unable to auto-authenticate using the credentials saved in your settings." withTitle:@"Octocat FAIL"];
+ [self loadLoginView];
+ }
+ }
+}
+
- (void) loadPreferences {
// read user prefs
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[[Config instance] setGitHubUserName:[defaults stringForKey:@"GitHubUserName"]];
[[Config instance] setGitHubToken:[defaults stringForKey:@"GitHubToken"]];
DevLog2(@"username: %@", [[Config instance] gitHubUserName]);
-
- // Check if username is set
- if ([[Config instance] gitHubUserName] == NULL || [[Config instance] gitHubToken] == NULL) {
- LoginViewController *loginViewController = [[[LoginViewController alloc] initWithNibName:@"Login" bundle:nil] autorelease];
- [window addSubview:[loginViewController view]];
- [navigationController presentModalViewController:loginViewController animated:YES];
- } else {
- //TODO: use conntector didAuthenticate User here
- [Repository loadAll];
- }
- //LOAD MAIN APP
+}
+
+- (void)showAlert:(NSString *)message withTitle:(NSString *)title {
+ UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title
+ message:message
+ delegate:nil
+ cancelButtonTitle:@"Try Again" otherButtonTitles:nil];
+ [alertView show];
+ [alertView release];
}
- (void)dealloc {
Oops, something went wrong.

0 comments on commit fec48ac

Please sign in to comment.