Permalink
Browse files

use observer pattern to check 'repo starring'

  • Loading branch information...
1 parent bce7c98 commit 71fc9ace23d10f0c9d1b44fa09acee024cb1138b @trivektor committed Apr 3, 2013
View
2 AppConfig.plist
@@ -4,6 +4,8 @@
<dict>
<key>GitosHost</key>
<string>http://thawing-crag-8872.herokuapp.com</string>
+ <key>GithubHost</key>
+ <string>https://github.com</string>
<key>GithubApiHost</key>
<string>https://api.github.com</string>
<key>GithubRawHost</key>
View
19 Gitos-iPad.xcodeproj/project.pbxproj
@@ -285,6 +285,7 @@
B574CF3716FFAAA00077D353 /* sunburst.css in Resources */ = {isa = PBXBuildFile; fileRef = B574CF3316FFAAA00077D353 /* sunburst.css */; };
B574CF3916FFB28C0077D353 /* doxy.css in Resources */ = {isa = PBXBuildFile; fileRef = B574CF3816FFB28C0077D353 /* doxy.css */; };
B57E39AA16FE5CBB006C2BD1 /* YRDropdownView.m in Sources */ = {isa = PBXBuildFile; fileRef = B57E39A916FE5CBB006C2BD1 /* YRDropdownView.m */; };
+ B5836C90170BFCA40012CC61 /* AppHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = B5836C8F170BFCA40012CC61 /* AppHelper.m */; };
B5BC452116BA5E3F00434848 /* prettify.js in Resources */ = {isa = PBXBuildFile; fileRef = B5BC451C16BA5DFD00434848 /* prettify.js */; };
B5BC452516BCEE7100434848 /* MasterViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B5BC452316BCEE7000434848 /* MasterViewController.m */; };
B5BC452616BCEE7100434848 /* MasterViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = B5BC452416BCEE7000434848 /* MasterViewController.xib */; };
@@ -685,6 +686,8 @@
B574CF3816FFB28C0077D353 /* doxy.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; path = doxy.css; sourceTree = "<group>"; };
B57E39A816FE5CBB006C2BD1 /* YRDropdownView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = YRDropdownView.h; sourceTree = "<group>"; };
B57E39A916FE5CBB006C2BD1 /* YRDropdownView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = YRDropdownView.m; sourceTree = "<group>"; };
+ B5836C8E170BFCA40012CC61 /* AppHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppHelper.h; sourceTree = "<group>"; };
+ B5836C8F170BFCA40012CC61 /* AppHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppHelper.m; sourceTree = "<group>"; };
B5BC451C16BA5DFD00434848 /* prettify.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = prettify.js; sourceTree = "<group>"; };
B5BC452216BCEE6F00434848 /* MasterViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MasterViewController.h; sourceTree = "<group>"; };
B5BC452316BCEE7000434848 /* MasterViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MasterViewController.m; sourceTree = "<group>"; };
@@ -963,6 +966,7 @@
B55D90A616B7AA27009CB90F /* Gitos-iPad */ = {
isa = PBXGroup;
children = (
+ B5836C8D170BFC870012CC61 /* Helpers */,
B5BC451A16BA5DFC00434848 /* Html */,
B516539916B7C1AA003F0DFA /* Images */,
B55D90AF16B7AA27009CB90F /* AppDelegate.h */,
@@ -1243,6 +1247,15 @@
path = YRDropdownView;
sourceTree = "<group>";
};
+ B5836C8D170BFC870012CC61 /* Helpers */ = {
+ isa = PBXGroup;
+ children = (
+ B5836C8E170BFCA40012CC61 /* AppHelper.h */,
+ B5836C8F170BFCA40012CC61 /* AppHelper.m */,
+ );
+ name = Helpers;
+ sourceTree = "<group>";
+ };
B5BC451A16BA5DFC00434848 /* Html */ = {
isa = PBXGroup;
children = (
@@ -1300,6 +1313,11 @@
hasScannedForEncodings = 0;
knownRegions = (
en,
+ da,
+ "es-ES",
+ es,
+ "zh-Hans",
+ "zh-Hant",
);
mainGroup = B55D908F16B7AA27009CB90F;
productRefGroup = B55D909B16B7AA27009CB90F /* Products */;
@@ -1606,6 +1624,7 @@
B57E39AA16FE5CBB006C2BD1 /* YRDropdownView.m in Sources */,
B569D0D216FE6F0F002216DD /* Authorization.m in Sources */,
B569D0D516FE7923002216DD /* GitosConstants.m in Sources */,
+ B5836C90170BFCA40012CC61 /* AppHelper.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
BIN ...deproj/project.xcworkspace/xcuserdata/trivuong.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
View
13 Gitos-iPad.xcodeproj/xcuserdata/trivuong.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist
@@ -81,6 +81,19 @@
landmarkName = "-displayEvent"
landmarkType = "5">
</FileBreakpoint>
+ <FileBreakpoint
+ shouldBeEnabled = "No"
+ ignoreCount = "0"
+ continueAfterRunningActions = "No"
+ filePath = "Gitos-iPad/Classes/Repo.m"
+ timestampString = "386665151.002083"
+ startingColumnNumber = "9223372036854775807"
+ endingColumnNumber = "9223372036854775807"
+ startingLineNumber = "198"
+ endingLineNumber = "198"
+ landmarkName = "-checkStar"
+ landmarkType = "5">
+ </FileBreakpoint>
</FileBreakpoints>
<ExceptionBreakpoints>
<ExceptionBreakpoint
View
3 Gitos-iPad/Classes/Repo.h
@@ -23,6 +23,7 @@
- (NSString *)getLanguage;
- (NSString *)getBranchesUrl;
- (NSString *)getTreeUrl;
+- (NSString *)getStarredUrl;
- (NSInteger)getSize;
- (NSString *)getPushedAt;
- (NSString *)getDescription;
@@ -36,5 +37,7 @@
- (NSString *)convertToRelativeDate:(NSString *)originalDateString;
- (NSString *)getOwner;
- (BOOL)isForked;
+- (NSString *)getGithubUrl;
+- (void)checkStar;
@end
View
47 Gitos-iPad/Classes/Repo.m
@@ -162,4 +162,51 @@ - (BOOL)isForked
return [[self.data valueForKey:@"fork"] integerValue] == 1;
}
+- (NSString *)getSubscriptionUrl
+{
+ NSString *githubApiHost = [AppConfig getConfigValue:@"GithubApiHost"];
+ return [githubApiHost stringByAppendingFormat:@"/user/subscriptions/%@", [self getFullName]];
+}
+
+- (NSString *)getStarredUrl
+{
+ NSString *githubApiHost = [AppConfig getConfigValue:@"GithubApiHost"];
+ return [githubApiHost stringByAppendingFormat:@"/user/starred/%@", [self getFullName]];
+}
+
+- (NSString *)getGithubUrl
+{
+ NSString *githubHost = [AppConfig getConfigValue:@"GithubHost"];
+ return [githubHost stringByAppendingFormat:@"/%@", [self getFullName]];
+}
+
+- (void)checkStar
+{
+ NSURL *starredUrl = [NSURL URLWithString:[self getStarredUrl]];
+
+ AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:starredUrl];
+
+ NSMutableURLRequest *getRequest = [httpClient requestWithMethod:@"GET" path:starredUrl.absoluteString parameters:[AppHelper getAccessTokenParams]];
+
+ AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:getRequest];
+
+ [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
+ NSNumber *statusCode = [NSNumber numberWithInt:operation.response.statusCode];
+
+ NSDictionary *userInfo = [NSDictionary dictionaryWithObject:statusCode forKey:@"Code"];
+
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"StarChecked" object:self userInfo:userInfo];
+ }
+ failure:^(AFHTTPRequestOperation *operation, NSError *error) {
+ NSNumber *statusCode = [NSNumber numberWithInt:operation.response.statusCode];
+
+ NSDictionary *userInfo = [NSDictionary dictionaryWithObject:statusCode forKey:@"Code"];
+
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"StarChecked" object:self userInfo:userInfo];
+ }];
+
+ [operation start];
+}
+
+
@end
View
2 Gitos-iPad/Controllers/LoginViewController.m
@@ -118,6 +118,8 @@ - (void)authenticate
[SSKeychain setPassword:token forService:@"access_token" account:account];
[SSKeychain setPassword:authorizationId forService:@"authorization_id" account:account];
+ [SSKeychain setPassword:username forService:@"username" account:account];
+ [SSKeychain setPassword:password forService:@"password" account:account];
[AppInitialization run:self.view.window];
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
View
7 Gitos-iPad/Controllers/RepoViewController.h
@@ -8,22 +8,23 @@
#import "Repo.h"
-@interface RepoViewController : UIViewController
-<UITableViewDataSource, UITableViewDelegate>
+@interface RepoViewController : UIViewController <UITableViewDataSource, UITableViewDelegate, UIActionSheetDelegate>
@property (nonatomic, weak) IBOutlet UITableView *detailsTable;
@property (nonatomic, weak) IBOutlet UITableView *branchesTable;
@property (nonatomic, weak) IBOutlet UIScrollView *repoScrollView;
-@property (nonatomic, strong) NSString *accessToken;
@property (nonatomic, strong) Repo *repo;
@property (nonatomic, strong) NSMutableArray *repoBranches;
@property (nonatomic, strong) MBProgressHUD *hud;
+@property (nonatomic, strong) UIActionSheet *actionOptions;
- (void)performHouseKeepingTasks;
- (void)registerNib;
- (UITableViewCell *)cellForDetailsTableAtIndexPath:(NSIndexPath *)indexPath;
- (UITableViewCell *)cellForBranchesTableAtIndexPath:(NSIndexPath *)indexPath;
- (void)getRepoBranches;
- (void)adjustFrameHeight;
+- (void)prepareActionOptionsForStatus:(NSNotification *)notification;
+- (void)showAvailableActions;
@end
View
45 Gitos-iPad/Controllers/RepoViewController.m
@@ -27,7 +27,6 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
if (self) {
// Custom initialization
self.repoBranches = [[NSMutableArray alloc] initWithCapacity:0];
- self.accessToken = [SSKeychain passwordForService:@"access_token" account:@"gitos"];
}
return self;
}
@@ -38,8 +37,8 @@ - (void)viewDidLoad
// Do any additional setup after loading the view from its nib.
[self.navigationItem setTitle:[self.repo getName]];
[self performHouseKeepingTasks];
- //[self adjustFrameHeight];
[self getRepoBranches];
+ [self.repo checkStar];
}
- (void)adjustFrameHeight
@@ -66,6 +65,8 @@ - (void)performHouseKeepingTasks
hud.mode = MBProgressHUDAnimationFade;
hud.labelText = LOADING_MESSAGE;
[self registerNib];
+
+ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(prepareActionOptionsForStatus:) name:@"StarChecked" object:nil];
}
- (void)registerNib
@@ -175,13 +176,8 @@ - (void)getRepoBranches
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:branchesUrl];
- NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
- self.accessToken, @"access_token",
- @"bearer", @"token_type",
- nil];
-
- NSMutableURLRequest *getRequest = [httpClient requestWithMethod:@"GET" path:branchesUrl.absoluteString parameters:params];
-
+ NSMutableURLRequest *getRequest = [httpClient requestWithMethod:@"GET" path:branchesUrl.absoluteString parameters:[AppHelper getAccessTokenParams]];
+
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:getRequest];
[operation setCompletionBlockWithSuccess:
@@ -209,4 +205,35 @@ - (void)getRepoBranches
[operation start];
}
+- (void)prepareActionOptionsForStatus:(NSNotification *)notification
+{
+ int statusCode = [[notification.userInfo valueForKey:@"Code"] intValue];
+
+ if (statusCode == 204) {
+ self.actionOptions = [[UIActionSheet alloc] initWithTitle:@"Actions" delegate:self cancelButtonTitle:@"" destructiveButtonTitle:nil otherButtonTitles:@"Unstar", @"View on Github", nil];
+ } else if (statusCode == 404) {
+ self.actionOptions = [[UIActionSheet alloc] initWithTitle:@"Actions" delegate:self cancelButtonTitle:@"" destructiveButtonTitle:nil otherButtonTitles:@"Star", @"View on Github", nil];
+ }
+
+ UIBarButtonItem *actionsButton = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStyleBordered target:self action:@selector(showAvailableActions)];
+ actionsButton.image = [UIImage imageNamed:@"211-action.png"];
+ self.navigationItem.rightBarButtonItem = actionsButton;
+}
+
+- (void)showAvailableActions
+{
+ [self.actionOptions showInView:[UIApplication sharedApplication].keyWindow];
+}
+
+- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
+{
+ if (buttonIndex == 0) {
+
+ } else if (buttonIndex == 1) {
+ WebsiteViewController *websiteController = [[WebsiteViewController alloc] init];
+ websiteController.requestedUrl = [self.repo getGithubUrl];
+ [self.navigationController pushViewController:websiteController animated:YES];
+ }
+}
+
@end
View
1 Gitos-iPad/Gitos-iPad-Prefix.pch
@@ -30,4 +30,5 @@
#import "Issue.h"
#import "Comment.h"
#import "YRDropdownView.h"
+ #import "AppHelper.h"
#endif

0 comments on commit 71fc9ac

Please sign in to comment.