Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds custom field support to iOS app. #48

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
25 changes: 16 additions & 9 deletions Classes/Common/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ @implementation AppDelegate
@synthesize window;
@synthesize navigationController;
@synthesize deploymentTableViewController;
@synthesize incidentTabViewController;
@synthesize incidentDetailsViewController;
@synthesize incidentTabViewController;
@synthesize incidentDetailsViewController;
@synthesize checkinTabViewController;
@synthesize splitViewController;
@synthesize categorySelectViewController;
Expand All @@ -64,7 +64,7 @@ - (void)pushDetailsViewController:(BaseViewController *)viewController animated:
[detailNavigationController pushViewController:viewController animated:animated];
}
else {
[self.navigationController pushViewController:viewController animated:animated];
[self.navigationController pushViewController:viewController animated:animated];
}
}

Expand Down Expand Up @@ -97,7 +97,7 @@ - (void)setDetailsViewController:(BaseViewController *)viewController animated:(
[detailNavigationController pushViewController:viewController animated:animated];
self.splitViewController.viewControllers = [NSArray arrayWithObjects:masterNavigationController, detailNavigationController, nil];
[viewController viewWasPushed];
}
}
}
else {
[self.navigationController pushViewController:viewController animated:animated];
Expand Down Expand Up @@ -130,6 +130,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

NSString *mapURL = [[Settings sharedSettings] mapURL];
//NSString *mapURL = @"http://uh.kunjan.net"; //[[Settings sharedSettings] mapURL];
DLog(@"MapURL: %@", mapURL);

NSString *mapName = [[Settings sharedSettings] mapName];
Expand All @@ -140,7 +141,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

NavigationController *masterNavigationController = [[[NavigationController alloc] init] autorelease];
masterNavigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
masterNavigationController.navigationBar.tintColor = [[Settings sharedSettings] navBarTintColor];
masterNavigationController.navigationBar.tintColor = [[Settings sharedSettings] navBarTintColor];

NavigationController *detailNavigationController = [[[NavigationController alloc] init] autorelease];
detailNavigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
Expand All @@ -149,7 +150,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
if ([Device isIPad]) {
self.splitViewController.viewControllers = [NSArray arrayWithObjects:masterNavigationController, detailNavigationController, nil];
self.navigationController = detailNavigationController;
}
}
else {
self.navigationController = masterNavigationController;
}
Expand All @@ -165,10 +166,13 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[[Ushahidi sharedUshahidi] addDeployment:deployment];
[[Ushahidi sharedUshahidi] loadDeployment:deployment];
[[Ushahidi sharedUshahidi] getVersionOfDeployment:deployment forDelegate:self];


}
else {
self.splashViewController.shouldDismissOnAppear = YES;
[[Ushahidi sharedUshahidi] loadDeployment:deployment];
[[Ushahidi sharedUshahidi] loadDeployment:deployment];

if (deployment.supportsCheckins) {
self.checkinTabViewController.deployment = deployment;
if ([Device isIPad]) {
Expand Down Expand Up @@ -198,6 +202,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
Deployment *deployment = [[Ushahidi sharedUshahidi] getDeploymentWithUrl:lastDeployment];
if (deployment != nil) {
[[Ushahidi sharedUshahidi] loadDeployment:deployment];


if (deployment.supportsCheckins) {
[masterNavigationController pushViewController:self.deploymentTableViewController animated:NO];
self.checkinTabViewController.deployment = deployment;
Expand Down Expand Up @@ -225,6 +231,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
}
}
else {

[masterNavigationController pushViewController:self.deploymentTableViewController animated:NO];
if ([Device isIPad]) {
[self setDetailsViewController:self.incidentTabViewController animated:NO];
Expand All @@ -236,14 +243,14 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[masterNavigationController pushViewController:self.deploymentTableViewController animated:NO];
if ([Device isIPad]) {
[self setDetailsViewController:self.incidentTabViewController animated:NO];
}
}
}
self.splashViewController.modalPresentationStyle = UIModalPresentationFullScreen;
self.splashViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
if ([Device isIPad]) {
[self.window addSubview:self.splitViewController.view];
[self.splitViewController presentModalViewController:self.splashViewController animated:NO];
}
}
else {
[self.window addSubview:self.navigationController.view];
[self.navigationController presentModalViewController:self.splashViewController animated:NO];
Expand Down
5 changes: 5 additions & 0 deletions Classes/Common/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@

BOOL showReportNewsURL;
BOOL isWhiteLabel;

NSArray *incidentCustomFieldsArray;
BOOL hasIncidentCustomFields;
}

@property(nonatomic, retain) NSString *email;
Expand Down Expand Up @@ -132,6 +135,8 @@
@property(nonatomic, assign) BOOL showReportVideosURL;
@property(nonatomic, readonly) BOOL isWhiteLabel;

@property(nonatomic,retain) NSArray *incidentCustomFieldsArray;

+ (Settings *) sharedSettings;

- (void) save;
Expand Down
41 changes: 35 additions & 6 deletions Classes/Common/Settings.m
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ @implementation Settings
@synthesize firstName;
@synthesize lastName;
@synthesize lastDeployment;
@synthesize lastIncident;
@synthesize lastIncident;
@synthesize downloadMaps;
@synthesize becomeDiscrete;
@synthesize resizePhotos;
Expand Down Expand Up @@ -83,6 +83,7 @@ @implementation Settings
@synthesize youtubeDeveloperKey;
@synthesize youtubeLogin;
@synthesize youtubePassword;
@synthesize incidentCustomFieldsArray;

- (id) init {
if ((self = [super init])) {
Expand Down Expand Up @@ -121,8 +122,19 @@ - (void) loadUserDefaults {
self.twitterUserSecret = [userDefaults stringForKey:@"twitterUserSecret"];

self.youtubeDeveloperKey = [userDefaults stringForKey:@"USHYoutubeDeveloperKey"];
self.youtubeLogin = [userDefaults stringForKey:@"USHYoutubeUsername"];
self.youtubeLogin = [userDefaults stringForKey:@"USHYoutubeUsername"];
self.youtubePassword = [userDefaults stringForKey:@"USHYoutubePassword"];


if ([userDefaults objectForKey:@"incidentCustomFields"] != nil) {

NSData *data = [userDefaults objectForKey:@"incidentCustomFields"];
self.incidentCustomFieldsArray = [[NSArray alloc] initWithArray:[NSKeyedUnarchiver unarchiveObjectWithData:data]];
}
else {
self.incidentCustomFieldsArray = nil;
}

}

- (void) loadInfoDictionary {
Expand Down Expand Up @@ -152,12 +164,12 @@ - (void) loadInfoDictionary {

self.twitterApiKey = [infoDictionary stringForKey:@"USHTwitterApiKey"];
self.twitterApiSecret = [infoDictionary stringForKey:@"USHTwitterApiSecret"];

self.bitlyApiLogin = [infoDictionary stringForKey:@"USHBitlyApiLogin"];
self.bitlyApiKey = [infoDictionary stringForKey:@"USHBitlyApiKey"];

self.youtubeDeveloperKey = [infoDictionary stringForKey:@"USHYoutubeDeveloperKey"];
self.youtubeLogin = [infoDictionary stringForKey:@"USHYoutubeUsername"];
self.youtubeLogin = [infoDictionary stringForKey:@"USHYoutubeUsername"];
self.youtubePassword = [infoDictionary stringForKey:@"USHYoutubePassword"];

if ([infoDictionary objectForKey:@"USHReportNewsURL"] != nil) {
Expand Down Expand Up @@ -209,6 +221,8 @@ - (void)dealloc {

[bitlyApiLogin release];
[bitlyApiKey release];

[incidentCustomFieldsArray release];
[super dealloc];
}

Expand All @@ -231,7 +245,15 @@ - (void) save {
[[NSUserDefaults standardUserDefaults] setObject:self.twitterPassword forKey:@"twitterPassword"];
[[NSUserDefaults standardUserDefaults] setObject:self.twitterUserKey forKey:@"twitterUserKey"];
[[NSUserDefaults standardUserDefaults] setObject:self.twitterUserSecret forKey:@"twitterUserSecret"];



NSArray* tmpCustomFieldArray = [[NSArray alloc] initWithArray:self.incidentCustomFieldsArray];

NSArray *arr = tmpCustomFieldArray;
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:arr];

[[NSUserDefaults standardUserDefaults] setObject:data forKey:@"incidentCustomFields"];

[[NSUserDefaults standardUserDefaults] synchronize];
}

Expand All @@ -253,11 +275,18 @@ - (BOOL) hasMapURL {

- (BOOL) isWhiteLabel {
return [NSString isNilOrEmpty:self.mapName] == NO ||
[NSString isNilOrEmpty:self.mapURL] == NO;
[NSString isNilOrEmpty:self.mapURL] == NO;
}

- (BOOL) hasYoutubeCredentials {
return self.youtubeDeveloperKey && self.youtubeLogin && self.youtubePassword;
}

- (BOOL) hasIncidentCustomFields {
if((self.incidentCustomFieldsArray != nil) && ([self.incidentCustomFieldsArray count]>0)){
return YES;
}
return NO;
}

@end
2 changes: 2 additions & 0 deletions Classes/Common/Ushahidi.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@
- (NSArray *) getIncidentsPending;
- (NSArray *) getIncidentsForDelegate:(id<UshahidiDelegate>)delegate;

- (NSArray *) getIncidentCustomFieldsForDelegate:(id<UshahidiDelegate>)delegate;

- (NSURL *) getUrlForIncident:(Incident *)incident;

- (void) downloadPhoto:(Photo *)photo forIncident:(Incident *)incident forDelegate:(id<UshahidiDelegate>)delegate;
Expand Down
Loading