From eff5d2d1e5aac98b334fed39d4aee5ad51c8d710 Mon Sep 17 00:00:00 2001 From: Robert Panzer Date: Thu, 20 Jun 2013 23:18:06 +0200 Subject: [PATCH] Allow to watch/unwatch own repos --- Github To Go/RPWatchRepoActivity.m | 2 +- Github To Go/RepositoryStorage.m | 4 +- Github To Go/UIRepositoryRootViewController.m | 64 +++++++++---------- 3 files changed, 33 insertions(+), 37 deletions(-) diff --git a/Github To Go/RPWatchRepoActivity.m b/Github To Go/RPWatchRepoActivity.m index 60099a5..9cdefbd 100644 --- a/Github To Go/RPWatchRepoActivity.m +++ b/Github To Go/RPWatchRepoActivity.m @@ -53,7 +53,7 @@ -(NSString *)activityType { } -(BOOL)canPerformWithActivityItems:(NSArray *)activityItems { - return ![[RepositoryStorage sharedStorage] repositoryIsOwned:self.repository]; + return YES; } -(void)prepareWithActivityItems:(NSArray *)activityItems { diff --git a/Github To Go/RepositoryStorage.m b/Github To Go/RepositoryStorage.m index 56887d7..4eea557 100644 --- a/Github To Go/RepositoryStorage.m +++ b/Github To Go/RepositoryStorage.m @@ -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]; diff --git a/Github To Go/UIRepositoryRootViewController.m b/Github To Go/UIRepositoryRootViewController.m index a91c201..d647a27 100644 --- a/Github To Go/UIRepositoryRootViewController.m +++ b/Github To Go/UIRepositoryRootViewController.m @@ -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]; - } - }); - }]; - }]; - } + }]; } }