Skip to content

Commit

Permalink
Restructure app
Browse files Browse the repository at this point in the history
  • Loading branch information
brung committed Feb 25, 2015
1 parent ecdf107 commit e722b3a
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 194 deletions.
10 changes: 0 additions & 10 deletions unnamed.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@
B8C291CF1A930BDD000F2143 /* unnamedTests.m in Sources */ = {isa = PBXBuildFile; fileRef = B8C291CE1A930BDD000F2143 /* unnamedTests.m */; };
B8C704AA1A97065600243C3B /* DetailQuestionCell.m in Sources */ = {isa = PBXBuildFile; fileRef = B8C704A81A97065600243C3B /* DetailQuestionCell.m */; };
B8C704AB1A97065600243C3B /* DetailQuestionCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B8C704A91A97065600243C3B /* DetailQuestionCell.xib */; };
E25DBF061A9489530074D48B /* TabBarMenuViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E25DBF041A9489530074D48B /* TabBarMenuViewController.m */; };
E25DBF071A9489530074D48B /* TabBarMenuViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = E25DBF051A9489530074D48B /* TabBarMenuViewController.xib */; };
E25DBF0B1A948D870074D48B /* ProfileViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E25DBF091A948D870074D48B /* ProfileViewController.m */; };
E25DBF0C1A948D870074D48B /* ProfileViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = E25DBF0A1A948D870074D48B /* ProfileViewController.xib */; };
E2C6FF1E1A96C178005AEDA9 /* ProfileCell.m in Sources */ = {isa = PBXBuildFile; fileRef = E2C6FF1C1A96C178005AEDA9 /* ProfileCell.m */; };
Expand Down Expand Up @@ -165,9 +163,6 @@
B8C704A71A97065600243C3B /* DetailQuestionCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DetailQuestionCell.h; sourceTree = "<group>"; };
B8C704A81A97065600243C3B /* DetailQuestionCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DetailQuestionCell.m; sourceTree = "<group>"; };
B8C704A91A97065600243C3B /* DetailQuestionCell.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = DetailQuestionCell.xib; sourceTree = "<group>"; };
E25DBF031A9489530074D48B /* TabBarMenuViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TabBarMenuViewController.h; sourceTree = "<group>"; };
E25DBF041A9489530074D48B /* TabBarMenuViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TabBarMenuViewController.m; sourceTree = "<group>"; };
E25DBF051A9489530074D48B /* TabBarMenuViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = TabBarMenuViewController.xib; sourceTree = "<group>"; };
E25DBF081A948D870074D48B /* ProfileViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ProfileViewController.h; sourceTree = "<group>"; };
E25DBF091A948D870074D48B /* ProfileViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ProfileViewController.m; sourceTree = "<group>"; };
E25DBF0A1A948D870074D48B /* ProfileViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = ProfileViewController.xib; sourceTree = "<group>"; };
Expand Down Expand Up @@ -355,9 +350,6 @@
B87C15B61A93113400191823 /* LoginViewController.h */,
B87C15B71A93113400191823 /* LoginViewController.m */,
B87C15B81A93113400191823 /* LoginViewController.xib */,
E25DBF031A9489530074D48B /* TabBarMenuViewController.h */,
E25DBF041A9489530074D48B /* TabBarMenuViewController.m */,
E25DBF051A9489530074D48B /* TabBarMenuViewController.xib */,
E25DBF081A948D870074D48B /* ProfileViewController.h */,
E25DBF091A948D870074D48B /* ProfileViewController.m */,
E25DBF0A1A948D870074D48B /* ProfileViewController.xib */,
Expand Down Expand Up @@ -480,7 +472,6 @@
B82956BD1A9C553200D0ECFD /* CameraViewController.xib in Resources */,
B8C704AB1A97065600243C3B /* DetailQuestionCell.xib in Resources */,
3E2BB7E11A94FF0000E78B3A /* AppNavigationController.xib in Resources */,
E25DBF071A9489530074D48B /* TabBarMenuViewController.xib in Resources */,
E2C6FF1F1A96C178005AEDA9 /* ProfileCell.xib in Resources */,
B8C291C31A930BDD000F2143 /* LaunchScreen.xib in Resources */,
3E58B4D61A984C3900AA14D4 /* AnswerView.xib in Resources */,
Expand Down Expand Up @@ -571,7 +562,6 @@
B8BA93EB1A9464C7003BD476 /* Question.m in Sources */,
3E58B4CF1A98300C00AA14D4 /* AnswerCollectionView.m in Sources */,
3EC3AEE11A9AB22100E0DCCB /* UIColor+AppColor.m in Sources */,
E25DBF061A9489530074D48B /* TabBarMenuViewController.m in Sources */,
B827A9EE1A98287B00AB43CE /* GrayBarButtonItem.m in Sources */,
3E4B80A01A9C42FB004F5D78 /* CommentView.m in Sources */,
B8C0DBDC1A95138C0023BC39 /* ComposeAnswerCell.m in Sources */,
Expand Down
5 changes: 0 additions & 5 deletions unnamed/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@
//

#import <UIKit/UIKit.h>
#import "TabBarMenuViewController.h"

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

+ (TabBarMenuViewController *)tabBarMenuViewController;

@end

30 changes: 1 addition & 29 deletions unnamed/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
#import <Parse/Parse.h>
#import <ParseFacebookUtils/PFFacebookUtils.h>
#import "User.h"
#import "TabBarMenuViewController.h"
#import "ComposeViewController.h"
#import "ProfileViewController.h"
#import "AppNavigationController.h"
#import "UIColor+AppColor.h"

Expand All @@ -28,26 +25,6 @@ @interface AppDelegate ()

@implementation AppDelegate

+ (TabBarMenuViewController *)tabBarMenuViewController {
static TabBarMenuViewController *instance = nil;

instance = [[TabBarMenuViewController alloc] init];

AppNavigationController * vc1 = [[AppNavigationController alloc] initWithRootViewController:[[HomeViewController alloc] init]];
AppNavigationController * vc2 = [[AppNavigationController alloc] initWithRootViewController:[[ComposeViewController alloc] init]];
ProfileViewController *pvc = [[ProfileViewController alloc] init];
pvc.user = [User currentUser];
AppNavigationController * vc3 = [[AppNavigationController alloc] initWithRootViewController:pvc];


//adding sub view controllers
NSArray* controllers = [NSArray arrayWithObjects:vc1, vc2, vc3, nil];
instance.viewControllers = controllers;
//instance.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

return instance;
}

- (void) showFBSessionState{
//Debugging purpose to see whether
//check this url for details: https://developers.facebook.com/docs/facebook-login/ios/sessions
Expand Down Expand Up @@ -91,11 +68,6 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(

User *user = [User currentUser];
if (user) {

NSLog(@"User name %@", user.name);
NSLog(@"User image %@", user.profileImageUrl);
NSLog(@"User id %@", user.objectId);

[self showFBSessionState];

if (FBSession.activeSession.state == FBSessionStateCreatedTokenLoaded) {
Expand All @@ -119,7 +91,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
self.window.rootViewController = [[LoginViewController alloc] init];
self.window.backgroundColor = [UIColor whiteColor];
}else{
self.window.rootViewController = [AppDelegate tabBarMenuViewController];
self.window.rootViewController = [[AppNavigationController alloc] initWithRootViewController:[[HomeViewController alloc] init]];
}

[self.window makeKeyAndVisible];
Expand Down
49 changes: 26 additions & 23 deletions unnamed/ComposeViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = @"Create";
self.tabBarItem.image = [UIImage imageNamed:@"Poll Topic"];
GrayBarButtonItem *submitButton = [[GrayBarButtonItem alloc] initWithTitle:@"Submit" style:UIBarButtonItemStylePlain target:self action:@selector(onSubmitButton)];
self.navigationItem.rightBarButtonItem = submitButton;
}
self.view.backgroundColor = [UIColor appBgColor];
return self;
Expand All @@ -61,10 +62,8 @@ - (void)viewDidLoad {
self.questionText.layer.masksToBounds = YES;

// Button
GrayBarButtonItem *cancelButton = [[GrayBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStylePlain target:self action:@selector(onCancelButton)];
self.navigationItem.leftBarButtonItem = cancelButton;
GrayBarButtonItem *submitButton = [[GrayBarButtonItem alloc] initWithTitle:@"Submit" style:UIBarButtonItemStylePlain target:self action:@selector(onSubmitButton)];
self.navigationItem.rightBarButtonItem = submitButton;
// GrayBarButtonItem *cancelButton = [[GrayBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStylePlain target:self action:@selector(onCancelButton)];
// self.navigationItem.leftBarButtonItem = cancelButton;

self.answerSegControl.alpha = 0;

Expand Down Expand Up @@ -217,27 +216,11 @@ - (void)onSubmitButton {

if (self.isShowingTextAnswers) {
[ParseClient saveTextSurvey:survey withCompletion:^(BOOL succeeded, NSError *error) {
if (succeeded) {
NSDictionary *dict = [NSDictionary dictionaryWithObject:survey forKey:@"survey"];
[[NSNotificationCenter defaultCenter] postNotificationName:UserDidPostNewSurveyNotification object:nil userInfo:dict];
[self resetForm];
[self.tabBarController setSelectedIndex:0];
} else {
[[[UIAlertView alloc] initWithTitle:@"Save Failed" message:@"Unable to save at this time. Please try again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
}
self.isUpdating = NO;
[self onPostSurvey:survey completionStatus:succeeded error:error];
}];
} else {
[ParseClient savePhotoSurvey:survey withCompletion:^(BOOL succeeded, NSError *error) {
if (succeeded) {
NSDictionary *dict = [NSDictionary dictionaryWithObject:survey forKey:@"survey"];
[[NSNotificationCenter defaultCenter] postNotificationName:UserDidPostNewSurveyNotification object:nil userInfo:dict];
[self resetForm];
[self.tabBarController setSelectedIndex:0];
} else {
[[[UIAlertView alloc] initWithTitle:@"Save Failed" message:@"Unable to save at this time. Please try again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
}
self.isUpdating = NO;
[self onPostSurvey:survey completionStatus:succeeded error:error];
}];

}
Expand All @@ -247,8 +230,28 @@ - (void)onSubmitButton {
}
}

- (void)onPostSurvey:(Survey *)survey completionStatus:(BOOL) succeeded error:(NSError *)error {
if (succeeded) {
[self onSuccessfulPostSurvey:survey];
} else {
[self onErrorPost];
}
self.isUpdating = NO;
}

- (void)onSuccessfulPostSurvey:(Survey *)survey {
NSDictionary *dict = [NSDictionary dictionaryWithObject:survey forKey:@"survey"];
[[NSNotificationCenter defaultCenter] postNotificationName:UserDidPostNewSurveyNotification object:nil userInfo:dict];
[self onCancelButton];
}

- (void)onErrorPost {
[[[UIAlertView alloc] initWithTitle:@"Save Failed" message:@"Unable to save at this time. Please try again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
}

- (void)onCancelButton {
[self resetForm];
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
}

- (void)resetForm {
Expand Down
4 changes: 2 additions & 2 deletions unnamed/HomeProfileAnimation.m
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,12 @@ - (id )animationControllerForDismissedController:(UIViewController *)dismissed {
- (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC {
self.navController = navigationController;
if (operation == UINavigationControllerOperationPush) {
if ([toVC isKindOfClass:[ProfileViewController class]] && [fromVC isKindOfClass:[HomeViewController class]]) {
if ([toVC isKindOfClass:[ProfileViewController class]] && [fromVC isKindOfClass:[HomeViewController class]] && self.selectedCell) {
self.isPresenting = YES;
return self;
}
} else if (operation == UINavigationControllerOperationPop) {
if ([fromVC isKindOfClass:[ProfileViewController class]] && [toVC isKindOfClass:[HomeViewController class]]) {
if ([fromVC isKindOfClass:[ProfileViewController class]] && [toVC isKindOfClass:[HomeViewController class]] && self.selectedCell) {
self.isPresenting = NO;
return self;
}
Expand Down
40 changes: 29 additions & 11 deletions unnamed/HomeViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#import "HomeViewController.h"
#import "SurveyViewController.h"
#import "ProfileViewController.h"
#import "ComposeViewController.h"
#import "SurveyViewCell.h"
#import "PhotoAnswerCell.h"
#import "ParseClient.h"
Expand Down Expand Up @@ -65,6 +66,10 @@ - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
if (self) {
self.title = @"Home";
self.tabBarItem.image = [UIImage imageNamed:@"Home"];
UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"User Male"] style:UIBarButtonItemStylePlain target:self action:@selector(onProfileTap)];
self.navigationItem.leftBarButtonItem = leftBarButtonItem;
UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Poll Topic"] style:UIBarButtonItemStylePlain target:self action:@selector(onCreateTap)];
self.navigationItem.rightBarButtonItem = rightBarButtonItem;
}
return self;
}
Expand Down Expand Up @@ -113,6 +118,10 @@ - (void)viewWillAppear:(BOOL)animated {
}
}

- (void)viewDidAppear:(BOOL)animated {
self.transitionAnimation.selectedCell = nil;
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
Expand Down Expand Up @@ -231,21 +240,17 @@ - (void)configureCell:(UITableViewCell *)pCell forRowAtIndexPath:(NSIndexPath *)

#pragma mark - SurveyViewCellDelegate methods
- (void)surveyViewCell:(SurveyViewCell *)cell didClickOnUser:(User *)user {
if ([user.objectId isEqualToString:[User currentUser].objectId]) {
[self.tabBarController setSelectedIndex:2];
} else {
ProfileViewController *vc = [[ProfileViewController alloc] init];
vc.user = user;
vc.view.frame = self.view.frame;
self.transitionAnimation.selectedCell = cell;
[self.navigationController pushViewController:vc animated:YES];
}
[self clickedOnCell:cell userPhoto:user];
}

#pragma mark - PhotoAnswerCellDelegate methods
- (void)photoAnswerCell:(PhotoAnswerCell *)cell didClickOnUser:(User *)user{
if ([user.objectId isEqualToString:[User currentUser].objectId]) {
[self.tabBarController setSelectedIndex:2];
[self clickedOnCell:cell userPhoto:user];
}

- (void)clickedOnCell:(UITableViewCell *)cell userPhoto:(User *)user {
if ([user isEqualUser:[User currentUser]]) {
[self onProfileTap];
} else {
ProfileViewController *vc = [[ProfileViewController alloc] init];
vc.user = user;
Expand All @@ -267,6 +272,19 @@ - (void)onNewPost:(NSNotification *)notification {
}
}

- (void)onProfileTap {
ProfileViewController *vc = [[ProfileViewController alloc] init];
vc.user = [User currentUser];
vc.view.frame = self.view.frame;
self.transitionAnimation.selectedCell = nil;
[self.navigationController pushViewController:vc animated:YES];
}

- (void)onCreateTap{
ComposeViewController *vc = [[ComposeViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
}

- (void)onUpdatePost {
[self.tableView reloadData];
}
Expand Down
4 changes: 3 additions & 1 deletion unnamed/LoginViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#import <Parse/Parse.h>
#import <ParseFacebookUtils/PFFacebookUtils.h>
#import "AppDelegate.h"
#import "AppNavigationController.h"
#import "HomeViewController.h"

@interface LoginViewController () <FBLoginViewDelegate>

Expand Down Expand Up @@ -72,7 +74,7 @@ - (void)didReceiveMemoryWarning {
#pragma mark - Private methods

- (void)presentLoggedInViewController {
[self presentViewController:[AppDelegate tabBarMenuViewController] animated:YES completion:nil];
[self presentViewController:[[AppNavigationController alloc] initWithRootViewController:[[HomeViewController alloc] init]] animated:YES completion:nil];
}

- (IBAction)onLoginButton:(id)sender {
Expand Down
10 changes: 6 additions & 4 deletions unnamed/ParseClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ @implementation ParseClient
//}

+ (void)getUser:(User *)user surveysComplete:(BOOL)complete onPage:(NSInteger)page withCompletion:(void(^)(NSArray *surveys, NSError *error))completion {
if (!user) {
if (!user || !user.parseUser) {
completion([NSArray array], [[NSError alloc] initWithDomain:@"No user found" code:909 userInfo:nil]);
return;
}
PFQuery *userQuery = [PFUser query];
[userQuery whereKey:@"objectId" equalTo:user.objectId];
PFQuery *query = [Question query];
[query orderByDescending:@"createdAt"];
[query whereKey:@"user" matchesQuery:userQuery];
[query whereKey:@"user" equalTo:user.parseUser];
[query includeKey:@"user"];
[query includeKey:@"questionPhotos"];
[query whereKey:@"complete" equalTo:@(complete)];
Expand Down Expand Up @@ -207,6 +206,9 @@ + (void)savePhotoSurvey:(Survey *)survey withCompletion:(void(^)(BOOL succeeded,
completion(NO, error);
}
}];
} else {
completion([NSArray array], [[NSError alloc] initWithDomain:@"Not enough valid answers for question" code:500 userInfo:nil]);
return;
}
}

Expand Down
Loading

0 comments on commit e722b3a

Please sign in to comment.