Permalink
Browse files

initial commits view

  • Loading branch information...
1 parent 3a62f73 commit 125dfdebc5cc9689b66e4bea116c3aaf93c858dc @sschroed committed Feb 25, 2009
View
@@ -0,0 +1,50 @@
+//
+// Commit.h
+// git-phone
+//
+// Created by Sam Schroeder on 2/7/09.
+// Copyright 2009 Proton Microsystems, LLC. All rights reserved.
+//
+//
+//{
+// "commits": [
+// {
+// "message": "Updated readme with DQMultipartForm information",
+// "parents": [{"id": "97638b6d7e2f657c1b9debdb9798ccb8e44ef0ed"}],
+// "url": "http://github.com/sschroed/mini-mallows/commit/cb106e80912c140fbb4fc26448f370c0b154a999",
+//
+// "author": {
+// "name": "Vladimir Pouzanov",
+// "email": "farcaller@gmail.com"
+// },
+//
+// "id": "cb106e80912c140fbb4fc26448f370c0b154a999",
+// "committed_date": "2008-12-24T06:43:15-08:00",
+// "authored_date": "2008-12-24T06:43:15-08:00",
+// "tree": "47b3669803f1ddc73d0f9222fe8729ad4661cab0",
+//
+// "committer": {
+// "name": "Vladimir Pouzanov",
+// "email": "farcaller@gmail.com"
+// }
+// }
+// ]
+//}
+
+
+@interface Commit : NSObject {
+ NSString *commitID;
+ NSString *message;
+ NSString *url;
+ NSString *authorName;
+ NSString *authorEmail;
+}
+
+@property (nonatomic, retain) NSString *commitID;
+@property (nonatomic, retain) NSString *message;
+@property (nonatomic, retain) NSString *url;
+@property (nonatomic, retain) NSString *authorName;
+@property (nonatomic, retain) NSString *authorEmail;
+
+
+@end
View
@@ -0,0 +1,63 @@
+//
+// Commit.m
+// git-phone
+//
+// Created by Sam Schroeder on 2/7/09.
+// Copyright 2009 Proton Microsystems, LLC. All rights reserved.
+//
+
+#import "Commit.h"
+
+@implementation Commit
+
+@synthesize commitID;
+@synthesize message;
+@synthesize url;
+@synthesize authorName;
+@synthesize authorEmail;
+
++ (NSString *)indexURLwithRepository:(NSString *)repository {
+
+ return [NSString stringWithFormat:@"%@/%@/%@/commits/master",
+ [[Config instance] baseAPIURL],
+ [[Config instance] gitHubUserName],
+ repository];
+}
+
+//TODO: this needs to be thought out better. Maybe loaded on the repo.
++ (NSArray *)loadAllfromRepository:(NSString *)repository {
+
+ NSMutableArray *commitsArray = [[[NSMutableArray alloc] init] autorelease];
+ NSString *resultJSON = [Connector postToURL:[self indexURLwithRepository:repository]];
+
+ NSMutableArray *commits = [[[NSMutableArray alloc] init] autorelease];
+
+ commits = [[resultJSON JSONValue] valueForKey:@"commits"];
+
+ for (NSDictionary *commit in commits) {
+ Commit *tempCommit = [[[Commit alloc] init] autorelease];
+
+ [tempCommit setCommitID:[commit valueForKey:@"id"]];
+ [tempCommit setMessage:[commit valueForKey:@"message"]];
+ [tempCommit setUrl:[commit valueForKey:@"url"]];
+ [tempCommit setAuthorName:[[commit valueForKey:@"author"] valueForKey:@"name"]];
+ [tempCommit setAuthorEmail:[[commit valueForKey:@"author"] valueForKey:@"email"]];
+
+ DevLog2(@"Loaded Commit: %@", [tempCommit commitID]);
+
+ [commitsArray addObject:tempCommit];
+ }
+ return commitsArray;
+}
+
+- (void) dealloc {
+ [commitID release];
+ [message release];
+ [url release];
+ [authorName release];
+ [authorEmail release];
+ [super dealloc];
+}
+
+
+@end
@@ -0,0 +1,18 @@
+//
+// RepoCommitsViewController.h
+// git-phone
+//
+// Created by Sam Schroeder on 2/7/09.
+// Copyright 2009 Proton Microsystems, LLC. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+
+@interface RepoCommitsViewController : UITableViewController {
+ NSArray *repoCommits;
+}
+
+@property (nonatomic, retain) NSArray *repoCommits;
+
+@end
@@ -0,0 +1,88 @@
+//
+// RepoCommitsViewController.m
+// git-phone
+//
+// Created by Sam Schroeder on 2/7/09.
+// Copyright 2009 Proton Microsystems, LLC. All rights reserved.
+//
+
+#import "RepoCommitsViewController.h"
+#import "Commit.h"
+
+
+@implementation RepoCommitsViewController
+
+@synthesize repoCommits;
+
+/*
+- (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];
+ self.title = @"Recent Commits";
+}
+
+
+- (void)viewWillAppear:(BOOL)animated {
+ [super viewWillAppear: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 [repoCommits count];
+}
+
+
+// Customize the appearance of table view cells.
+- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
+
+ static NSString *CellIdentifier = @"CommitCell";
+
+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
+ if (cell == nil) {
+ cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
+ }
+
+ // Set up the cell...
+ cell.text = [(Commit *)[repoCommits objectAtIndex:[indexPath row]] message];
+
+ 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 {
+ [repoCommits release];
+ [super dealloc];
+}
+
+
+@end
+
@@ -7,6 +7,7 @@
//
#import "RepositoriesViewController.h"
+#import "RepoCommitsViewController.h"
@implementation RepositoriesViewController
@@ -50,6 +51,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
+ cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
// Set up the cell...
@@ -59,10 +61,16 @@ - (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];
+ RepoCommitsViewController *repoCommitsViewController = [[[RepoCommitsViewController alloc] initWithNibName:@"RepoCommitsView" bundle:nil] autorelease];
+ Repository *repository = [repositories objectAtIndex:[indexPath row]];
+
+ [repoCommitsViewController.repoCommits release];
+ [repository.commits release];
+ [repository loadCommits];
+ repoCommitsViewController.repoCommits = repository.commits;
+
+ [self.navigationController pushViewController:repoCommitsViewController animated:YES];
+ [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
View
@@ -9,13 +9,19 @@
@interface Repository : NSObject {
NSString *name;
+ NSString *owner;
NSNumber *privateRepo;
+ NSMutableArray *commits;
}
@property (nonatomic, retain) NSString *name;
+@property (nonatomic, retain) NSString *owner;
@property (nonatomic, retain) NSNumber *privateRepo;
+@property (nonatomic, retain) NSMutableArray *commits;
+ (NSString *)indexURL;
+ (void)loadAll;
+- (NSString *)commitsURL;
+- (void)loadCommits;
@end
View
@@ -8,12 +8,15 @@
#import "Repository.h"
#import "Connector.h"
+#import "Commit.h"
@implementation Repository
@synthesize name;
+@synthesize owner;
@synthesize privateRepo;
+@synthesize commits;
+ (NSString *)indexURL {
@@ -22,8 +25,15 @@ + (NSString *)indexURL {
[[Config instance] gitHubUserName]];
}
+- (NSString *)commitsURL {
+ // http://github.com/api/v1/json/caged/gitnub/commits/master
+ return [NSString stringWithFormat:@"%@/%@/%@/commits/master",
+ [[Config instance] baseAPIURL],
+ [self owner],
+ [self name]];
+}
+
+ (void)loadAll {
-
NSString *resultJSON = [Connector postToURL:[self indexURL]];
NSMutableArray *publicRepoArray = [[[NSMutableArray alloc] init] autorelease];
@@ -36,6 +46,7 @@ + (void)loadAll {
for (NSDictionary *repository in repositories) {
Repository *tempRepo = [[[Repository alloc] init] autorelease];
[tempRepo setName:[repository valueForKey:@"name"]];
+ [tempRepo setOwner:[repository valueForKey:@"owner"]];
[tempRepo setPrivateRepo:[DataParser readInt:[repository valueForKey:@"private"]]];
DevLog2(@"Loaded Repo: %@", [tempRepo name]);
@@ -51,9 +62,35 @@ + (void)loadAll {
[[Config instance] setPrivateRepositories:privateRepoArray];
}
+- (void)loadCommits {
+ NSString *resultJSON = [Connector postToURL:[self commitsURL]];
+
+ NSMutableArray *commitsArray = [[[NSMutableArray alloc] init] autorelease];
+ NSMutableArray *repoCommits = [[[NSMutableArray alloc] init] autorelease];
+
+ repoCommits = [[resultJSON JSONValue] valueForKey:@"commits"];
+
+ for (NSDictionary *commit in repoCommits) {
+ Commit *tempCommit = [[[Commit alloc] init] autorelease];
+ [tempCommit setCommitID:[commit valueForKey:@"id"]];
+ [tempCommit setMessage:[commit valueForKey:@"message"]];
+ [tempCommit setUrl:[commit valueForKey:@"url"]];
+ [tempCommit setAuthorName:[[commit valueForKey:@"author"] valueForKey:@"name"]];
+ [tempCommit setAuthorEmail:[[commit valueForKey:@"author"] valueForKey:@"email"]];
+
+ DevLog2(@"Loaded Commit: %@", [tempCommit message]);
+
+ [commitsArray addObject:tempCommit];
+ }
+
+ [self setCommits:commitsArray];
+}
+
- (void) dealloc {
[name release];
+ [owner release];
[privateRepo release];
+ [commits release];
[super dealloc];
}
@@ -28,7 +28,7 @@ - (void)didReceiveMemoryWarning {
#pragma mark Table view methods
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- return 3;
+ return 4;
}
@@ -50,6 +50,10 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
rows = 1;
break;
}
+ case 3: {
+ rows = 1;
+ break;
+ }
}
return rows;
}
@@ -92,10 +96,20 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
break;
}
case 2: {
+ switch(indexPath.row) {
+ case 0: {
+ cell.text = @"Search";
+ cell.image = [UIImage imageNamed:@"octocat_small.png"];
+ break;
+ }
+ }
+ break;
+ }
+ case 3: {
switch(indexPath.row) {
case 0: {
cell.text = @"About GitHub GitPhone";
- cell.image = [UIImage imageNamed:@"gravatar.png"];
+ cell.image = [UIImage imageNamed:@"octocat_small.png"];
break;
}
}
Oops, something went wrong.

0 comments on commit 125dfde

Please sign in to comment.