Skip to content

Commit

Permalink
Allow to watch/unwatch own repos
Browse files Browse the repository at this point in the history
  • Loading branch information
robertpanzer committed Jun 20, 2013
1 parent 5a7ced4 commit eff5d2d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Github To Go/RPWatchRepoActivity.m
Expand Up @@ -53,7 +53,7 @@ -(NSString *)activityType {
}

-(BOOL)canPerformWithActivityItems:(NSArray *)activityItems {
return ![[RepositoryStorage sharedStorage] repositoryIsOwned:self.repository];
return YES;
}

-(void)prepareWithActivityItems:(NSArray *)activityItems {
Expand Down
4 changes: 1 addition & 3 deletions Github To Go/RepositoryStorage.m
Expand Up @@ -121,9 +121,7 @@ -(void)loadFollowedRepos {

for (NSDictionary* repoObject in data) {
Repository* repo = [[Repository alloc] initFromJSONObject:repoObject];
if (! [[[Settings sharedInstance] username] isEqualToString: repo.owner.login]) {
newRepos[repo.fullName] = repo;
}
newRepos[repo.fullName] = repo;
}
self.watchedRepositories = newRepos;
[[NSNotificationCenter defaultCenter] postNotificationName:LOADED_REPOS_NOTIFICATION object:self];
Expand Down
64 changes: 31 additions & 33 deletions Github To Go/UIRepositoryRootViewController.m
Expand Up @@ -73,40 +73,38 @@ - (id)initWithRepository:(Repository*)aRepository
title:_repository.fullName
viewController:self];
NSString *repoName = self.repository.fullName;
if (![[RepositoryStorage sharedStorage] repositoryIsOwned:self.repository]) {
if (![[RepositoryStorage sharedStorage] repositoryIsWatched:_repository]) {
[_shareUrlController addAction:WatchRepo
block:^() {
NSString* url = [NSString stringWithFormat:@"https://api.github.com/user/watched/%@", repoName];
[[NetworkProxy sharedInstance] loadStringFromURL:url verb:@"PUT" block:^(int status, NSDictionary* headerFields, id data) {
dispatch_async(dispatch_get_main_queue(), ^{
if (status == 204) {
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:WatchRepo message:NSLocalizedString(@"Repository is being watched now", @"Alert View") delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alertView show];
} else {
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:WatchRepo message:NSLocalizedString(@"Starting to watch repository failed", @"Alert view") delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alertView show];
}
});
} ];
if (![[RepositoryStorage sharedStorage] repositoryIsWatched:_repository]) {
[_shareUrlController addAction:WatchRepo
block:^() {
NSString* url = [NSString stringWithFormat:@"https://api.github.com/user/watched/%@", repoName];
[[NetworkProxy sharedInstance] loadStringFromURL:url verb:@"PUT" block:^(int status, NSDictionary* headerFields, id data) {
dispatch_async(dispatch_get_main_queue(), ^{
if (status == 204) {
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:WatchRepo message:NSLocalizedString(@"Repository is being watched now", @"Alert View") delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alertView show];
} else {
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:WatchRepo message:NSLocalizedString(@"Starting to watch repository failed", @"Alert view") delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alertView show];
}
});
} ];
}];
} else {
[_shareUrlController addAction:StopWatchingRepo
block:^() {
NSString* url = [NSString stringWithFormat:@"https://api.github.com/user/watched/%@", repoName];
[[NetworkProxy sharedInstance] loadStringFromURL:url verb:@"DELETE" block:^(int status, NSDictionary* headerFields, id data) {
dispatch_async(dispatch_get_main_queue(), ^{
if (status == 204) {
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:StopWatchingRepo message:NSLocalizedString(@"Repository is no longer watched now", @"Alert view") delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alertView show];
} else {
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:StopWatchingRepo message:NSLocalizedString(@"Stopping to watch repository failed", @"Alert view") delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alertView show];
}
});
}];
} else {
[_shareUrlController addAction:StopWatchingRepo
block:^() {
NSString* url = [NSString stringWithFormat:@"https://api.github.com/user/watched/%@", repoName];
[[NetworkProxy sharedInstance] loadStringFromURL:url verb:@"DELETE" block:^(int status, NSDictionary* headerFields, id data) {
dispatch_async(dispatch_get_main_queue(), ^{
if (status == 204) {
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:StopWatchingRepo message:NSLocalizedString(@"Repository is no longer watched now", @"Alert view") delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alertView show];
} else {
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:StopWatchingRepo message:NSLocalizedString(@"Stopping to watch repository failed", @"Alert view") delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[alertView show];
}
});
}];
}];
}
}];
}
}

Expand Down

0 comments on commit eff5d2d

Please sign in to comment.