Skip to content

Commit

Permalink
Started implementing repository watching and user following
Browse files Browse the repository at this point in the history
  • Loading branch information
dbloete committed Apr 28, 2009
1 parent e8028f9 commit 99ec888
Show file tree
Hide file tree
Showing 15 changed files with 261 additions and 47 deletions.
4 changes: 3 additions & 1 deletion Classes/GHUser.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#import "GHResource.h"


@class GravatarLoader;
@class GravatarLoader, GHRepository;

@interface GHUser : GHResource {
NSString *name;
Expand Down Expand Up @@ -37,5 +37,7 @@
- (void)loadRepositories;
- (void)loadedRepositories:(NSArray *)theRepositories;
- (void)loadedGravatar:(UIImage *)theImage;
- (BOOL)isFollowing:(GHUser *)anUser;
- (BOOL)isWatching:(GHRepository *)aRepository;

@end
12 changes: 12 additions & 0 deletions Classes/GHUser.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ - (NSString *)description {
return [NSString stringWithFormat:@"<GHUser login:'%@' name:'%@' email:'%@' company:'%@' location:'%@' blogURL:'%@'>", login, name, email, company, location, blogURL];
}

// FIXME Currently just stubbed out, see the issue:
// http://github.com/dbloete/ioctocat/issues#issue/5
- (BOOL)isFollowing:(GHUser *)anUser {
return NO;
}

// FIXME Currently just stubbed out, see the issue:
// http://github.com/dbloete/ioctocat/issues#issue/6
- (BOOL)isWatching:(GHRepository *)aRepository {
return NO;
}

#pragma mark -
#pragma mark User loading

Expand Down
6 changes: 5 additions & 1 deletion Classes/RepositoryViewController.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#import <UIKit/UIKit.h>


@class GHRepository, GHFeedEntryCell, TextCell, LabeledCell;
@class GHRepository, GHUser, GHFeedEntryCell, TextCell, LabeledCell;

@interface RepositoryViewController : UITableViewController {
@private
GHRepository *repository;
IBOutlet UIView *tableHeaderView;
IBOutlet UILabel *nameLabel;
IBOutlet UILabel *numbersLabel;
IBOutlet UIButton *watchButton;
IBOutlet UILabel *ownerLabel;
IBOutlet UILabel *websiteLabel;
IBOutlet UILabel *descriptionLabel;
Expand All @@ -21,6 +22,9 @@
IBOutlet TextCell *descriptionCell;
}

@property (nonatomic, readonly) GHUser *currentUser;

- (id)initWithRepository:(GHRepository *)theRepository;
- (IBAction)toggleWatching:(id)sender;

@end
21 changes: 21 additions & 0 deletions Classes/RepositoryViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ - (void)viewDidLoad {
(repository.isLoaded) ? [self displayRepository] : [repository loadRepository];
}

- (GHUser *)currentUser {
iOctocatAppDelegate *appDelegate = (iOctocatAppDelegate *)[[UIApplication sharedApplication] delegate];
return appDelegate.currentUser;
}

#pragma mark -
#pragma mark Actions

Expand All @@ -43,6 +48,11 @@ - (void)displayRepository {
[websiteCell setContentText:[repository.homepageURL host]];
[descriptionCell setContentText:repository.descriptionText];
if (!repository.recentCommits.isLoaded) [repository.recentCommits loadEntries];
// FIXME Watching needs to be implemented, see issue:
// http://github.com/dbloete/ioctocat/issues#issue/4
// UIImage *buttonImage = [UIImage imageNamed:([self.currentUser isWatching:repository] ? @"UnwatchButton.png" : @"WatchButton.png")];
// [watchButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
// watchButton.hidden = NO;
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:object change:change context:context {
Expand All @@ -61,6 +71,16 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:object change:change
}
}

- (IBAction)toggleWatching:(id)sender {
UIImage *buttonImage;
if ([self.currentUser isWatching:repository]) {
buttonImage = [UIImage imageNamed:@"UnwatchButton.png"];
} else {
buttonImage = [UIImage imageNamed:@"WatchButton.png"];
}
[watchButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
}

#pragma mark -
#pragma mark Table view methods

Expand Down Expand Up @@ -145,6 +165,7 @@ - (void)dealloc {
[tableHeaderView release];
[nameLabel release];
[numbersLabel release];
[watchButton release];
[ownerLabel release];
[websiteLabel release];
[descriptionLabel release];
Expand Down
4 changes: 4 additions & 0 deletions Classes/UserViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
GHUser *user;
IBOutlet UIView *tableHeaderView;
IBOutlet UIImageView *gravatarView;
IBOutlet UIButton *followButton;
IBOutlet UILabel *nameLabel;
IBOutlet UILabel *companyLabel;
IBOutlet UILabel *locationLabel;
Expand All @@ -21,6 +22,9 @@
IBOutlet LabeledCell *emailCell;
}

@property (nonatomic, readonly) GHUser *currentUser;

- (id)initWithUser:(GHUser *)theUser;
- (IBAction)toggleFollowing:(id)sender;

@end
23 changes: 23 additions & 0 deletions Classes/UserViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#import "GHRepository.h"
#import "LabeledCell.h"
#import "GravatarLoader.h"
#import "iOctocatAppDelegate.h"


@interface UserViewController ()
Expand All @@ -31,6 +32,11 @@ - (void)viewDidLoad {
self.tableView.tableHeaderView = tableHeaderView;
}

- (GHUser *)currentUser {
iOctocatAppDelegate *appDelegate = (iOctocatAppDelegate *)[[UIApplication sharedApplication] delegate];
return appDelegate.currentUser;
}

#pragma mark -
#pragma mark Actions

Expand All @@ -41,6 +47,12 @@ - (void)displayUser {
[locationCell setContentText:user.location];
[blogCell setContentText:[user.blogURL host]];
[emailCell setContentText:user.email];
// FIXME Following needs to be implemented, see issue:
// http://github.com/dbloete/ioctocat/issues#issue/3
// if ([self.currentUser isEqual:user]) return;
// UIImage *buttonImage = [UIImage imageNamed:([self.currentUser isFollowing:user] ? @"UnfollowButton.png" : @"FollowButton.png")];
// [followButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
// followButton.hidden = NO;
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:object change:change context:context {
Expand All @@ -61,6 +73,16 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:object change:change
}
}

- (IBAction)toggleFollowing:(id)sender {
UIImage *buttonImage;
if ([self.currentUser isFollowing:user]) {
buttonImage = [UIImage imageNamed:@"UnfollowButton.png"];
} else {
buttonImage = [UIImage imageNamed:@"FollowButton.png"];
}
[followButton setBackgroundImage:buttonImage forState:UIControlStateNormal];
}

#pragma mark -
#pragma mark Table view methods

Expand Down Expand Up @@ -156,6 +178,7 @@ - (void)dealloc {
[loadingUserCell release];
[loadingReposCell release];
[noPublicReposCell release];
[followButton release];
[super dealloc];
}

Expand Down
2 changes: 1 addition & 1 deletion Classes/iOctocatAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@property (nonatomic, readonly) BOOL isDataSourceAvailable;
@property (nonatomic, retain) NSMutableDictionary *users;

- (GHUser *)user;
- (GHUser *)currentUser;
- (GHUser *)userWithLogin:(NSString *)theUsername;

@end
Expand Down
3 changes: 1 addition & 2 deletions Classes/iOctocatAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ - (void)displayNoConnectionView {
[noConnectionView release];
}


- (GHUser *)user {
- (GHUser *)currentUser {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *username = [defaults valueForKey:kUsernameDefaultsKey];
return ([username isEqualToString:@""]) ? nil : [self userWithLogin:username];
Expand Down
Loading

0 comments on commit 99ec888

Please sign in to comment.