diff --git a/RedmineMobile/RedmineMobile.xcodeproj/project.pbxproj b/RedmineMobile/RedmineMobile.xcodeproj/project.pbxproj index 5cbe6cc..2e1709a 100644 --- a/RedmineMobile/RedmineMobile.xcodeproj/project.pbxproj +++ b/RedmineMobile/RedmineMobile.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ 2B9968B01794FC0A0086F115 /* OZLProjectCreateViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2B9968AE1794FC0A0086F115 /* OZLProjectCreateViewController.xib */; }; 2B9968B417951A5C0086F115 /* OZLIssueCreateViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 2B9968B217951A5C0086F115 /* OZLIssueCreateViewController.m */; }; 2B9968B517951A5C0086F115 /* OZLIssueCreateViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2B9968B317951A5C0086F115 /* OZLIssueCreateViewController.xib */; }; + 2BCCA0541795312E00FA8B1A /* OZLConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 2BCCA0531795312E00FA8B1A /* OZLConstants.m */; }; 2BCF880C1793A26A006FC859 /* MBProgressHUD.m in Sources */ = {isa = PBXBuildFile; fileRef = 2BCF880B1793A26A006FC859 /* MBProgressHUD.m */; }; 2BCF88101793ABA0006FC859 /* Reachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 2BCF880F1793ABA0006FC859 /* Reachability.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; 2BCF88121793CB4F006FC859 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2BCF88111793CB4F006FC859 /* CFNetwork.framework */; }; @@ -68,6 +69,8 @@ 2B9968B117951A5C0086F115 /* OZLIssueCreateViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OZLIssueCreateViewController.h; path = ViewControllers/OZLIssueCreateViewController.h; sourceTree = ""; }; 2B9968B217951A5C0086F115 /* OZLIssueCreateViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OZLIssueCreateViewController.m; path = ViewControllers/OZLIssueCreateViewController.m; sourceTree = ""; }; 2B9968B317951A5C0086F115 /* OZLIssueCreateViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; name = OZLIssueCreateViewController.xib; path = ViewControllers/OZLIssueCreateViewController.xib; sourceTree = ""; }; + 2BCCA0521795312E00FA8B1A /* OZLConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = OZLConstants.h; path = Models/OZLConstants.h; sourceTree = ""; }; + 2BCCA0531795312E00FA8B1A /* OZLConstants.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OZLConstants.m; path = Models/OZLConstants.m; sourceTree = ""; }; 2BCF880A1793A26A006FC859 /* MBProgressHUD.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MBProgressHUD.h; sourceTree = ""; }; 2BCF880B1793A26A006FC859 /* MBProgressHUD.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MBProgressHUD.m; sourceTree = ""; }; 2BCF880E1793ABA0006FC859 /* Reachability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Reachability.h; sourceTree = ""; }; @@ -361,6 +364,8 @@ D5DB80B917930C830081662A /* OZLNetworkBase.m */, D5DB80BB17930ECD0081662A /* OZLSingleton.h */, D5DB80BC17930ECD0081662A /* OZLSingleton.m */, + 2BCCA0521795312E00FA8B1A /* OZLConstants.h */, + 2BCCA0531795312E00FA8B1A /* OZLConstants.m */, ); name = Utils; sourceTree = ""; @@ -493,6 +498,7 @@ 2B9968AB1794F71B0086F115 /* OZLModelIssueCategory.m in Sources */, 2B9968AF1794FC0A0086F115 /* OZLProjectCreateViewController.m in Sources */, 2B9968B417951A5C0086F115 /* OZLIssueCreateViewController.m in Sources */, + 2BCCA0541795312E00FA8B1A /* OZLConstants.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/RedmineMobile/RedmineMobile/Models/OZLConstants.h b/RedmineMobile/RedmineMobile/Models/OZLConstants.h new file mode 100644 index 0000000..3fe8559 --- /dev/null +++ b/RedmineMobile/RedmineMobile/Models/OZLConstants.h @@ -0,0 +1,15 @@ +// +// OZLConstants.h +// RedmineMobile +// +// Created by lizhijie on 7/16/13. +// Copyright (c) 2013 Lee Zhijie. All rights reserved. +// + +#import + +extern const NSString* NOTIFICATION_REDMINE_ACCOUNT_CHANGED; + +@interface OZLConstants : NSObject + +@end diff --git a/RedmineMobile/RedmineMobile/Models/OZLConstants.m b/RedmineMobile/RedmineMobile/Models/OZLConstants.m new file mode 100644 index 0000000..cdd3873 --- /dev/null +++ b/RedmineMobile/RedmineMobile/Models/OZLConstants.m @@ -0,0 +1,16 @@ +// +// OZLConstants.m +// RedmineMobile +// +// Created by lizhijie on 7/16/13. +// Copyright (c) 2013 Lee Zhijie. All rights reserved. +// + +#import "OZLConstants.h" + +const NSString* NOTIFICATION_REDMINE_ACCOUNT_CHANGED = @"NOTIFICATION_REDMINE_ACCOUNT_CHANGED"; + + +@implementation OZLConstants + +@end diff --git a/RedmineMobile/RedmineMobile/OZLAppDelegate.m b/RedmineMobile/RedmineMobile/OZLAppDelegate.m index 055353a..c95fefd 100644 --- a/RedmineMobile/RedmineMobile/OZLAppDelegate.m +++ b/RedmineMobile/RedmineMobile/OZLAppDelegate.m @@ -62,6 +62,18 @@ */ OZLProjectListViewController* projectList = [[OZLProjectListViewController alloc] initWithNibName:@"OZLProjectListViewController" bundle:nil]; _navigationController = [[UINavigationController alloc] initWithRootViewController:projectList]; + + int lastProjectID = [[OZLSingleton sharedInstance] lastProjectID]; + if (lastProjectID < 0) { + + }else { + OZLProjectViewController* projectview = [[OZLProjectViewController alloc] initWithNibName:@"OZLProjectViewController" bundle:nil]; + OZLModelProject* data = [[OZLModelProject alloc] init]; + data.index = lastProjectID; + [projectview setProjectData:data]; + [_navigationController pushViewController:projectview animated:NO]; + } + self.window.rootViewController = _navigationController; self.window.backgroundColor = [UIColor whiteColor]; @@ -100,7 +112,6 @@ return PPRevealSideDirectionLeft ; } - - (void)applicationWillResignActive:(UIApplication *)application { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. diff --git a/RedmineMobile/RedmineMobile/Utils/OZLNetwork.m b/RedmineMobile/RedmineMobile/Utils/OZLNetwork.m index 58d98f2..6c92909 100644 --- a/RedmineMobile/RedmineMobile/Utils/OZLNetwork.m +++ b/RedmineMobile/RedmineMobile/Utils/OZLNetwork.m @@ -30,6 +30,7 @@ #import "OZLNetworkBase.h" #import "AFHTTPRequestOperation.h" #import "JSONKit.h" +#import "OZLSingleton.h" @implementation OZLNetwork @@ -38,7 +39,14 @@ +(void)getProjectListWithParams:(NSDictionary*)params andBlock:(void (^)(NSArray *result, NSError *error))block; { NSString* path = @"/projects.json"; - [[OZLNetworkBase sharedClient] getPath:path parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) { + NSMutableDictionary* paramsDic = [[NSMutableDictionary alloc] initWithDictionary:params]; + NSString* accessKey = [[OZLSingleton sharedInstance] redmineUserKey]; + if (accessKey.length > 0) { + [paramsDic setObject:accessKey forKey:@"key"]; + } + + [[OZLNetworkBase sharedClient] setAuthorizationHeader]; + [[OZLNetworkBase sharedClient] getPath:path parameters:paramsDic success:^(AFHTTPRequestOperation *operation, id responseObject) { if (block) { NSLog(@"the repsonse:%@",responseObject); @@ -63,7 +71,13 @@ +(void)getDetailForProject:(int)projectid withParams:(NSDictionary*)params andBlock:(void (^)(OZLModelProject *result, NSError *error))block { NSString* path = [NSString stringWithFormat:@"/projects/%d.json",projectid]; - [[OZLNetworkBase sharedClient] getPath:path parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) { + NSMutableDictionary* paramsDic = [[NSMutableDictionary alloc] initWithDictionary:params]; + NSString* accessKey = [[OZLSingleton sharedInstance] redmineUserKey]; + if (accessKey.length > 0) { + [paramsDic setObject:accessKey forKey:@"key"]; + } + + [[OZLNetworkBase sharedClient] getPath:path parameters:paramsDic success:^(AFHTTPRequestOperation *operation, id responseObject) { if (block) { NSLog(@"the repsonse:%@",responseObject); @@ -82,6 +96,7 @@ }]; } + +(void)createProject:(OZLModelProject*)projectData withParams:(NSDictionary*)params andBlock:(void (^)(BOOL success, NSError *error))block { NSString* path = @"/projects.json"; @@ -90,6 +105,11 @@ NSMutableDictionary* projectDic = [projectData toParametersDic]; [projectDic addEntriesFromDictionary:params]; + NSString* accessKey = [[OZLSingleton sharedInstance] redmineUserKey]; + if (accessKey.length > 0) { + [projectDic setObject:accessKey forKey:@"key"]; + } + [[OZLNetworkBase sharedClient] postPath:path parameters:projectDic success:^(AFHTTPRequestOperation *operation, id responseObject) { if (block) { @@ -106,6 +126,7 @@ }]; } + +(void)updateProject:(OZLModelProject*)projectData withParams:(NSDictionary*)params andBlock:(void (^)(BOOL success, NSError *error))block { NSString* path = [NSString stringWithFormat:@"/projects/%d.json",projectData.index]; @@ -113,7 +134,12 @@ //project info NSMutableDictionary* projectDic = [projectData toParametersDic]; [projectDic addEntriesFromDictionary:params]; - + + NSString* accessKey = [[OZLSingleton sharedInstance] redmineUserKey]; + if (accessKey.length > 0) { + [projectDic setObject:accessKey forKey:@"key"]; + } + [[OZLNetworkBase sharedClient] putPath:path parameters:projectDic success:^(AFHTTPRequestOperation *operation, id responseObject) { if (block) { @@ -124,7 +150,6 @@ } failure:^(AFHTTPRequestOperation *operation, NSError *error) { - if (block) { block(NO, error); } @@ -132,11 +157,17 @@ }]; } + +(void)deleteProject:(int)projectid withParams:(NSDictionary*)params andBlock:(void (^)(BOOL success, NSError *error))block { NSString* path = [NSString stringWithFormat:@"/projects/%d.json",projectid]; + NSMutableDictionary* paramsDic = [[NSMutableDictionary alloc] initWithDictionary:params]; + NSString* accessKey = [[OZLSingleton sharedInstance] redmineUserKey]; + if (accessKey.length > 0) { + [paramsDic setObject:accessKey forKey:@"key"]; + } - [[OZLNetworkBase sharedClient] deletePath:path parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) { + [[OZLNetworkBase sharedClient] deletePath:path parameters:paramsDic success:^(AFHTTPRequestOperation *operation, id responseObject) { if (block) { NSLog(@"the repsonse:%@",responseObject); @@ -146,7 +177,6 @@ } failure:^(AFHTTPRequestOperation *operation, NSError *error) { - if (block) { block(NO, error); } @@ -160,10 +190,14 @@ +(void)getIssueListForProject:(int)projectid withParams:(NSDictionary*)params andBlock:(void (^)(NSArray *result, NSError *error))block { NSString* path = [NSString stringWithFormat:@"/issues.json"]; - NSMutableDictionary* dic = [[NSMutableDictionary alloc] initWithDictionary:params]; - [dic setObject:[NSNumber numberWithInt:projectid] forKey:@"project_id"]; - - [[OZLNetworkBase sharedClient] getPath:path parameters:dic success:^(AFHTTPRequestOperation *operation, id responseObject) { + NSMutableDictionary* paramsDic = [[NSMutableDictionary alloc] initWithDictionary:params]; + [paramsDic setObject:[NSNumber numberWithInt:projectid] forKey:@"project_id"]; + NSString* accessKey = [[OZLSingleton sharedInstance] redmineUserKey]; + if (accessKey.length > 0) { + [paramsDic setObject:accessKey forKey:@"key"]; + } + + [[OZLNetworkBase sharedClient] getPath:path parameters:paramsDic success:^(AFHTTPRequestOperation *operation, id responseObject) { if (block) { NSLog(@"the repsonse:%@",responseObject); @@ -189,7 +223,14 @@ +(void)getDetailFoIssue:(int)issueid withParams:(NSDictionary*)params andBlock:(void (^)(OZLModelIssue *result, NSError *error))block { NSString* path = [NSString stringWithFormat:@"/issues/%d.json",issueid]; - [[OZLNetworkBase sharedClient] getPath:path parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) { + + NSMutableDictionary* paramsDic = [[NSMutableDictionary alloc] initWithDictionary:params]; + NSString* accessKey = [[OZLSingleton sharedInstance] redmineUserKey]; + if (accessKey.length > 0) { + [paramsDic setObject:accessKey forKey:@"key"]; + } + + [[OZLNetworkBase sharedClient] getPath:path parameters:paramsDic success:^(AFHTTPRequestOperation *operation, id responseObject) { if (block) { NSLog(@"the repsonse:%@",responseObject); @@ -218,6 +259,11 @@ NSMutableDictionary* paramsDic = [[NSMutableDictionary alloc] initWithDictionary:params]; [paramsDic addEntriesFromDictionary:[issueData toParametersDic]]; + NSString* accessKey = [[OZLSingleton sharedInstance] redmineUserKey]; + if (accessKey.length > 0) { + [paramsDic setObject:accessKey forKey:@"key"]; + } + [[OZLNetworkBase sharedClient] postPath:path parameters:paramsDic success:^(AFHTTPRequestOperation *operation, id responseObject) { if (block) { @@ -241,7 +287,12 @@ //project info NSMutableDictionary* paramsDic = [[NSMutableDictionary alloc] initWithDictionary:params]; [paramsDic addEntriesFromDictionary:[issueData toParametersDic]]; - + + NSString* accessKey = [[OZLSingleton sharedInstance] redmineUserKey]; + if (accessKey.length > 0) { + [paramsDic setObject:accessKey forKey:@"key"]; + } + [[OZLNetworkBase sharedClient] putPath:path parameters:paramsDic success:^(AFHTTPRequestOperation *operation, id responseObject) { if (block) { @@ -263,7 +314,13 @@ { NSString* path = [NSString stringWithFormat:@"/issues/%d.json",issueid]; - [[OZLNetworkBase sharedClient] deletePath:path parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) { + NSMutableDictionary* paramsDic = [[NSMutableDictionary alloc] initWithDictionary:params]; + NSString* accessKey = [[OZLSingleton sharedInstance] redmineUserKey]; + if (accessKey.length > 0) { + [paramsDic setObject:accessKey forKey:@"key"]; + } + + [[OZLNetworkBase sharedClient] deletePath:path parameters:paramsDic success:^(AFHTTPRequestOperation *operation, id responseObject) { if (block) { NSLog(@"the repsonse:%@",responseObject); diff --git a/RedmineMobile/RedmineMobile/Utils/OZLNetworkBase.h b/RedmineMobile/RedmineMobile/Utils/OZLNetworkBase.h index 9268754..1ac5d48 100644 --- a/RedmineMobile/RedmineMobile/Utils/OZLNetworkBase.h +++ b/RedmineMobile/RedmineMobile/Utils/OZLNetworkBase.h @@ -32,5 +32,6 @@ @interface OZLNetworkBase : AFHTTPClient +(OZLNetworkBase *)sharedClient; +-(void)setAuthorizationHeader; @end diff --git a/RedmineMobile/RedmineMobile/Utils/OZLNetworkBase.m b/RedmineMobile/RedmineMobile/Utils/OZLNetworkBase.m index 8a3cf26..4317eb2 100644 --- a/RedmineMobile/RedmineMobile/Utils/OZLNetworkBase.m +++ b/RedmineMobile/RedmineMobile/Utils/OZLNetworkBase.m @@ -29,17 +29,17 @@ #import "OZLNetworkBase.h" #import "AFJSONRequestOperation.h" #import "OZLSingleton.h" - +#import "OZLConstants.h" @implementation OZLNetworkBase +static OZLNetworkBase *_sharedClient = nil; +(OZLNetworkBase *)sharedClient { - static OZLNetworkBase *_sharedClient = nil; if (_sharedClient == nil) { _sharedClient = [[OZLNetworkBase alloc] initWithBaseURL:[NSURL URLWithString:[[OZLSingleton sharedInstance] redmineHomeURL]]]; - + }; return _sharedClient; @@ -55,8 +55,29 @@ // Accept HTTP Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1 [self setDefaultHeader:@"Accept" value:@"application/json"]; - + + NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; + [center addObserver:self selector:@selector(accountChanged) name:NOTIFICATION_REDMINE_ACCOUNT_CHANGED object:nil]; + + [self setAuthorizationHeader]; return self; } +-(void)setAuthorizationHeader +{ + + [self clearAuthorizationHeader]; + NSString* username = [[OZLSingleton sharedInstance] redmineUserName]; + NSString* password = [[OZLSingleton sharedInstance] redminePassword]; + [self setAuthorizationHeaderWithUsername:username password:password]; + +} + +-(void)accountChanged +{ + _sharedClient = nil; + + NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; + [center removeObserver:self]; +} @end diff --git a/RedmineMobile/RedmineMobile/Utils/OZLSingleton.h b/RedmineMobile/RedmineMobile/Utils/OZLSingleton.h index 2ac8a1b..9bd229d 100644 --- a/RedmineMobile/RedmineMobile/Utils/OZLSingleton.h +++ b/RedmineMobile/RedmineMobile/Utils/OZLSingleton.h @@ -35,6 +35,8 @@ //network @property(nonatomic,strong) NSString* redmineHomeURL; @property(nonatomic,strong) NSString* redmineUserKey; +@property(nonatomic,strong) NSString* redmineUserName; +@property(nonatomic,strong) NSString* redminePassword; //app status @property(nonatomic) int lastProjectID;// last viewed project id diff --git a/RedmineMobile/RedmineMobile/Utils/OZLSingleton.m b/RedmineMobile/RedmineMobile/Utils/OZLSingleton.m index 4c81dac..24562f2 100644 --- a/RedmineMobile/RedmineMobile/Utils/OZLSingleton.m +++ b/RedmineMobile/RedmineMobile/Utils/OZLSingleton.m @@ -27,13 +27,15 @@ // THE SOFTWARE. #import "OZLSingleton.h" +#import "OZLConstants.h" @implementation OZLSingleton NSString* USER_DEFUALTS_REDMINE_HOME_URL = @"USER_DEFUALTS_REDMINE_HOME_URL"; NSString* USER_DEFUALTS_REDMINE_USER_KEY = @"USER_DEFUALTS_REDMINE_USER_KEY"; NSString* USER_DEFUALTS_LAST_PROJECT_ID = @"USER_DEFUALTS_LAST_PROJECT_ID"; - +NSString* USER_DEFUALTS_REDMINE_USER_NAME = @"USER_DEFUALTS_REDMINE_USER_NAME"; +NSString* USER_DEFUALTS_REDMINE_PASSWORD = @"USER_DEFUALTS_REDMINE_PASSWORD"; static OZLSingleton* sharedInstance = nil; +(OZLSingleton*) sharedInstance @@ -46,6 +48,8 @@ static OZLSingleton* sharedInstance = nil; @"http://demo.redmine.org/",USER_DEFUALTS_REDMINE_HOME_URL, @"",USER_DEFUALTS_REDMINE_USER_KEY, [NSNumber numberWithInt:-1],USER_DEFUALTS_LAST_PROJECT_ID, + @"",USER_DEFUALTS_REDMINE_USER_NAME, + @"",USER_DEFUALTS_REDMINE_PASSWORD, nil]; [defaults registerDefaults:dic]; } @@ -62,6 +66,7 @@ static OZLSingleton* sharedInstance = nil; NSUserDefaults* userdefaults = [NSUserDefaults standardUserDefaults]; [userdefaults setObject:redmineHomeURL forKey:USER_DEFUALTS_REDMINE_HOME_URL]; [userdefaults synchronize]; + } -(NSString*)redmineUserKey { @@ -86,4 +91,29 @@ static OZLSingleton* sharedInstance = nil; [userdefaults synchronize]; } +-(NSString*)redmineUserName +{ + NSUserDefaults* userdefaults = [NSUserDefaults standardUserDefaults]; + return [userdefaults objectForKey:USER_DEFUALTS_REDMINE_USER_NAME]; +} + +-(void)setRedmineUserName:(NSString *)redmineUserName +{ + NSUserDefaults* userdefaults = [NSUserDefaults standardUserDefaults]; + [userdefaults setObject:redmineUserName forKey:USER_DEFUALTS_REDMINE_USER_NAME]; + [userdefaults synchronize]; +} + +-(NSString*)redminePassword +{ + NSUserDefaults* userdefaults = [NSUserDefaults standardUserDefaults]; + return [userdefaults objectForKey:USER_DEFUALTS_REDMINE_PASSWORD]; +} + +-(void)setRedminePassword:(NSString *)redminePassword +{ + NSUserDefaults* userdefaults = [NSUserDefaults standardUserDefaults]; + [userdefaults setObject:redminePassword forKey:USER_DEFUALTS_REDMINE_PASSWORD]; + [userdefaults synchronize]; +} @end diff --git a/RedmineMobile/RedmineMobile/ViewControllers/OZLAccountViewController.h b/RedmineMobile/RedmineMobile/ViewControllers/OZLAccountViewController.h index 410b0c4..d08e086 100644 --- a/RedmineMobile/RedmineMobile/ViewControllers/OZLAccountViewController.h +++ b/RedmineMobile/RedmineMobile/ViewControllers/OZLAccountViewController.h @@ -32,6 +32,10 @@ @property (strong, nonatomic) IBOutlet UITextField *redmineHomeURL; @property (strong, nonatomic) IBOutlet UITextField *redmineUserKey; + +@property (weak, nonatomic) IBOutlet UITextField *username; +@property (weak, nonatomic) IBOutlet UITextField *password; + - (IBAction)onOk:(id)sender; @end diff --git a/RedmineMobile/RedmineMobile/ViewControllers/OZLAccountViewController.m b/RedmineMobile/RedmineMobile/ViewControllers/OZLAccountViewController.m index 66cf454..75386b8 100644 --- a/RedmineMobile/RedmineMobile/ViewControllers/OZLAccountViewController.m +++ b/RedmineMobile/RedmineMobile/ViewControllers/OZLAccountViewController.m @@ -30,6 +30,7 @@ #import "PPRevealSideViewController.h" #import "OZLProjectListViewController.h" #import "OZLSingleton.h" +#import "OZLConstants.h" #import "OZLNetwork.h" @interface OZLAccountViewController (){ @@ -59,8 +60,17 @@ _redmineHomeURL.text = [[OZLSingleton sharedInstance] redmineHomeURL]; _redmineUserKey.text = [[OZLSingleton sharedInstance] redmineUserKey]; + _username.text = [[OZLSingleton sharedInstance] redmineUserName]; + _password.text = [[OZLSingleton sharedInstance] redminePassword]; + + UITapGestureRecognizer* tapper = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(backgroundTapped)]; + [self.view addGestureRecognizer:tapper]; } +-(void)backgroundTapped +{ + [self.view endEditing:YES]; +} - (void) preloadLeft { OZLProjectListViewController *c = [[OZLProjectListViewController alloc] initWithNibName:@"OZLProjectListViewController" bundle:nil]; @@ -106,11 +116,19 @@ - (void)viewDidUnload { [self setRedmineHomeURL:nil]; [self setRedmineUserKey:nil]; + [self setUsername:nil]; + [self setPassword:nil]; [super viewDidUnload]; } - (IBAction)onOk:(id)sender { [[OZLSingleton sharedInstance] setRedmineUserKey:_redmineUserKey.text]; [[OZLSingleton sharedInstance] setRedmineHomeURL:_redmineHomeURL.text]; + [[OZLSingleton sharedInstance] setRedmineUserName:_username.text]; + [[OZLSingleton sharedInstance] setRedminePassword:_password.text]; + [[OZLSingleton sharedInstance] setLastProjectID:-1]; + + NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; + [center postNotificationName:NOTIFICATION_REDMINE_ACCOUNT_CHANGED object:nil]; [self showProjectList]; } diff --git a/RedmineMobile/RedmineMobile/ViewControllers/OZLAccountViewController.xib b/RedmineMobile/RedmineMobile/ViewControllers/OZLAccountViewController.xib index b302a51..88390e5 100644 --- a/RedmineMobile/RedmineMobile/ViewControllers/OZLAccountViewController.xib +++ b/RedmineMobile/RedmineMobile/ViewControllers/OZLAccountViewController.xib @@ -2,10 +2,10 @@ 1552 - 12E55 + 11G63 3084 - 1187.39 - 626.00 + 1138.51 + 569.00 com.apple.InterfaceBuilder.IBCocoaTouchPlugin 2083 @@ -14,6 +14,7 @@ IBProxyObject IBUIButton IBUILabel + IBUIScrollView IBUITextField IBUIView @@ -37,155 +38,271 @@ 274 - + - 292 - {{20, 49}, {280, 30}} - - - _NS:9 - NO - YES - IBCocoaTouchFramework - 0 - - 3 - - 3 - MAA - - 2 + 274 + + + + 292 + {{20, 49}, {280, 30}} + + + + _NS:9 + NO + YES + IBCocoaTouchFramework + 0 + + 3 + + 3 + MAA + + 2 + + + YES + 17 + + IBCocoaTouchFramework + + + 1 + 14 + + + Helvetica + 14 + 16 + - - YES - 17 - - IBCocoaTouchFramework - - - 1 - 14 - - - Helvetica - 14 - 16 - - - - - 292 - {{20, 20}, {42, 21}} + + + 292 + {{20, 20}, {42, 21}} + + + + _NS:9 + NO + YES + 7 + NO + IBCocoaTouchFramework + url: + + 1 + MCAwIDAAA + darkTextColor + + + 0 + + 1 + 17 + + + Helvetica + 17 + 16 + + NO + + + + -2147483356 + {{20, 454}, {280, 30}} + + + + _NS:9 + NO + YES + IBCocoaTouchFramework + 0 + + 3 + + 3 + MAA + + + YES + 17 + + IBCocoaTouchFramework + + + + + + + -2147483356 + {{20, 425}, {42, 21}} + + + + _NS:9 + NO + YES + 7 + NO + IBCocoaTouchFramework + key: + + + 0 + + + NO + + + + 292 + {{20, 241}, {280, 44}} + + + _NS:9 + NO + IBCocoaTouchFramework + 0 + 0 + 1 + OK + + 3 + MQA + + + 1 + MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA + + + 3 + MC41AA + + + 2 + 15 + + + Helvetica-Bold + 15 + 16 + + + + + 292 + {{20, 116}, {280, 30}} + + + + _NS:9 + NO + YES + IBCocoaTouchFramework + 0 + + 3 + + 3 + MAA + + + YES + 17 + + IBCocoaTouchFramework + + + + + + + 292 + {{20, 87}, {102, 21}} + + + + _NS:9 + NO + YES + 7 + NO + IBCocoaTouchFramework + username: + + + 0 + + + NO + + + + 292 + {{20, 183}, {280, 30}} + + + + _NS:9 + NO + YES + IBCocoaTouchFramework + 0 + + 3 + + 3 + MAA + + + YES + 17 + + YES + IBCocoaTouchFramework + + + + + + + 292 + {{20, 154}, {102, 21}} + + + + _NS:9 + NO + YES + 7 + NO + IBCocoaTouchFramework + password: + + + 0 + + + NO + + + {320, 504} - + _NS:9 - NO YES - 7 - NO + YES IBCocoaTouchFramework - url: - - 1 - MCAwIDAAA - darkTextColor - - - 0 - - 1 - 17 - - - Helvetica - 17 - 16 - - NO - - - - 292 - {{20, 116}, {280, 30}} - - - _NS:9 - NO - YES - IBCocoaTouchFramework - 0 - - 3 - - 3 - MAA - - - YES - 17 - - IBCocoaTouchFramework - - - - - - - 292 - {{20, 87}, {42, 21}} - - - _NS:9 - NO - YES - 7 - NO - IBCocoaTouchFramework - key: - - - 0 - - - NO - - - - 292 - {{20, 154}, {280, 44}} - - _NS:9 - NO - IBCocoaTouchFramework - 0 - 0 - 1 - OK - - 3 - MQA - - - 1 - MC4xOTYwNzg0MzQ2IDAuMzA5ODAzOTMyOSAwLjUyMTU2ODY1NgA - - - 3 - MC41AA - - - 2 - 15 - - - Helvetica-Bold - 15 - 16 - {{0, 64}, {320, 504}} + 3 @@ -226,6 +343,14 @@ 3 + + + username + + + + 16 + redmineHomeURL @@ -242,6 +367,14 @@ 10 + + + password + + + + 17 + onOk: @@ -264,11 +397,7 @@ 1 - - - - - + @@ -283,30 +412,66 @@ + + 18 + + + + + + + + + + + + + + 4 - + 5 - + 6 - + 7 - + 8 - + + + + 12 + + + + + 13 + + + + + 14 + + + + + 15 + + @@ -316,6 +481,11 @@ UIResponder com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin + com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin com.apple.InterfaceBuilder.IBCocoaTouchPlugin @@ -326,9 +496,55 @@ - 11 + 30 + + + + + OZLAccountViewController + UIViewController + + onOk: + id + + + onOk: + + onOk: + id + + + + UITextField + UITextField + UITextField + UITextField + + + + password + UITextField + + + redmineHomeURL + UITextField + + + redmineUserKey + UITextField + + + username + UITextField + + + + IBProjectSource + ./Classes/OZLAccountViewController.h + + + - 0 IBCocoaTouchFramework YES diff --git a/RedmineMobile/RedmineMobile/ViewControllers/OZLProjectListViewController.m b/RedmineMobile/RedmineMobile/ViewControllers/OZLProjectListViewController.m index f743cf7..69014ac 100644 --- a/RedmineMobile/RedmineMobile/ViewControllers/OZLProjectListViewController.m +++ b/RedmineMobile/RedmineMobile/ViewControllers/OZLProjectListViewController.m @@ -34,6 +34,7 @@ #import "OZLNetwork.h" #import "OZLModelProject.h" #import "MBProgressHUD.h" +#import "OZLSingleton.h" @interface OZLProjectListViewController (){ NSMutableArray* _projectList; @@ -67,6 +68,8 @@ [self.navigationItem setLeftBarButtonItem:accountBtn]; [self.navigationItem setTitle:@"Projects"]; + + [[OZLSingleton sharedInstance] setLastProjectID:-1]; } -(void) viewWillAppear:(BOOL)animated diff --git a/RedmineMobile/RedmineMobile/ViewControllers/OZLProjectViewController.m b/RedmineMobile/RedmineMobile/ViewControllers/OZLProjectViewController.m index a1ebddf..79a5eab 100644 --- a/RedmineMobile/RedmineMobile/ViewControllers/OZLProjectViewController.m +++ b/RedmineMobile/RedmineMobile/ViewControllers/OZLProjectViewController.m @@ -34,6 +34,7 @@ #import "OZLProjectDetailViewController.h" #import "OZLIssueDetailViewController.h" #import "OZLIssueCreateViewController.h" +#import "OZLSingleton.h" @interface OZLProjectViewController () { @@ -71,6 +72,8 @@ _HUD.labelText = @"Loading..."; [self reloadData]; + + [[OZLSingleton sharedInstance] setLastProjectID:_projectData.index]; } -(void) reloadData