Skip to content

Commit

Permalink
Code!
Browse files Browse the repository at this point in the history
  • Loading branch information
brianantonelli committed Jul 4, 2012
1 parent b1770d2 commit 013eab7
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 25 deletions.
8 changes: 8 additions & 0 deletions FishCount.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
373110E8153E386600FB43C8 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 373110E7153E386600FB43C8 /* QuartzCore.framework */; };
37311100153E38B900FB43C8 /* libRestKit.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 373110F5153E387800FB43C8 /* libRestKit.a */; };
37311104153E3AE000FB43C8 /* Visit.m in Sources */ = {isa = PBXBuildFile; fileRef = 37311103153E3AE000FB43C8 /* Visit.m */; };
377A39DA15A40396000BD5FC /* checkmark.png in Resources */ = {isa = PBXBuildFile; fileRef = 377A39D815A40396000BD5FC /* checkmark.png */; };
377A39DB15A40396000BD5FC /* checkmark@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 377A39D915A40396000BD5FC /* checkmark@2x.png */; };
377BE1B1159CFCE10020E6F6 /* DetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 377BE1B0159CFCE10020E6F6 /* DetailViewController.m */; };
377BE1B2159CFCE10020E6F6 /* DetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 377BE1B0159CFCE10020E6F6 /* DetailViewController.m */; };
379DA49E154269710081D42F /* ScheduleViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 379DA49D154269710081D42F /* ScheduleViewController.m */; };
Expand Down Expand Up @@ -192,6 +194,8 @@
37311103153E3AE000FB43C8 /* Visit.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Visit.m; sourceTree = "<group>"; };
37311126153E473F00FB43C8 /* FishCount copy-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = "FishCount copy-Info.plist"; path = "/Users/monkeymojo/Dev/FishCount/FishCount copy-Info.plist"; sourceTree = "<absolute>"; };
37311127153E475600FB43C8 /* visits.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = visits.json; sourceTree = "<group>"; };
377A39D815A40396000BD5FC /* checkmark.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = checkmark.png; sourceTree = "<group>"; };
377A39D915A40396000BD5FC /* checkmark@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "checkmark@2x.png"; sourceTree = "<group>"; };
377BE1AF159CFCE10020E6F6 /* DetailViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DetailViewController.h; sourceTree = "<group>"; };
377BE1B0159CFCE10020E6F6 /* DetailViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DetailViewController.m; sourceTree = "<group>"; };
379DA49C154269710081D42F /* ScheduleViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScheduleViewController.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -393,6 +397,8 @@
37B9A20415A2AD8800B0C0EF /* buttons */ = {
isa = PBXGroup;
children = (
377A39D815A40396000BD5FC /* checkmark.png */,
377A39D915A40396000BD5FC /* checkmark@2x.png */,
37B9A20515A2AD8800B0C0EF /* blackButton.png */,
37B9A20615A2AD8800B0C0EF /* blackButton@2x.png */,
37B9A20715A2AD8800B0C0EF /* blackButtonHighlight.png */,
Expand Down Expand Up @@ -595,6 +601,8 @@
37B9A23C15A2AD8800B0C0EF /* whiteButton@2x.png in Resources */,
37B9A23D15A2AD8800B0C0EF /* whiteButtonHighlight.png in Resources */,
37B9A23E15A2AD8800B0C0EF /* whiteButtonHighlight@2x.png in Resources */,
377A39DA15A40396000BD5FC /* checkmark.png in Resources */,
377A39DB15A40396000BD5FC /* checkmark@2x.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@
<Bucket
type = "1"
version = "1.0">
<SymbolicBreakpoints>
<SymbolicBreakpoint
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = ""
moduleName = "">
</SymbolicBreakpoint>
</SymbolicBreakpoints>
<ExceptionBreakpoints>
<ExceptionBreakpoint
shouldBeEnabled = "Yes"
Expand Down
10 changes: 10 additions & 0 deletions FishCount/DetailViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
//#import "VisitFormDataSource.h"
#import "VisitorCounterViewController.h"

@protocol DetailViewControllerDelegate <NSObject>

@required

- (void)didSave;

@end

typedef enum {
kStateCounty,
kTypeProgram,
Expand Down Expand Up @@ -49,6 +57,7 @@ typedef enum {
NSArray *payments;
NSArray *types;
NSArray *programs;
id<DetailViewControllerDelegate> __weak delegate;
}

-(IBAction) didClickScheduleButton:(id) sender;
Expand All @@ -71,4 +80,5 @@ typedef enum {
@property(nonatomic, strong) NSArray *programs;
@property(nonatomic, strong) NSArray *types;
@property(nonatomic, strong) NSArray *payments;
@property(nonatomic, weak) id<DetailViewControllerDelegate> delegate;
@end
18 changes: 8 additions & 10 deletions FishCount/DetailViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import <RestKit/RestKit.h>
#import "ScheduleViewController.h"
#import "Visit.h"
#import "MasterViewController.h"

#define GEORGIA_INDEX 13;

Expand All @@ -28,19 +29,11 @@ @implementation DetailViewController
counties = _counties,
programs = _programs,
types = _types,
payments = _payments;
payments = _payments,
delegate;


-(IBAction) didClickScheduleButton:(id) sender{
// ScheduleFormDataSource *ds = [[ScheduleFormDataSource alloc] initWithModel:visit];
// ScheduleViewController *schedule = [[ScheduleViewController alloc] initWithNibName:nil bundle:nil formDataSource:ds];
// schedule.delegate = self;
//
// UINavigationController *ctrl = [[UINavigationController alloc] initWithRootViewController:schedule];
// ctrl.modalPresentationStyle = UIModalPresentationFormSheet;
//
// [self presentModalViewController:ctrl animated:YES];

[self performSegueWithIdentifier:@"scheduleSegue" sender:self];
}

Expand All @@ -65,6 +58,7 @@ -(IBAction) didClickSaveButton:(id) sender{
[alert setDelegate:self];
[alert addButtonWithTitle:@"No"];
[alert addButtonWithTitle:@"Yes"];
[self.view endEditing:TRUE];
[alert show];
}

Expand Down Expand Up @@ -443,12 +437,16 @@ - (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger

if(err != nil){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"There was an error saving to the local database. Please try again." delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil];
[self.view endEditing:TRUE];
[alert show];

NSLog(@"Error saving to store! %@", [err description]);
}
else {
NSLog(@"Successfully saved to store!");
if(self.delegate != nil){
[self.delegate didSave];
}
}

[_visit flagAsDirty:NO];
Expand Down
5 changes: 3 additions & 2 deletions FishCount/MasterViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@

#import <UIKit/UIKit.h>
#import <RestKit/RestKit.h>
#import "DetailViewController.h"

@class Visit;
@class DetailViewController;

typedef enum {
kAlertTypeLoad,
kAlertTypeSync,
kAlertTypeDirty
} AlertType;

@interface MasterViewController : UITableViewController <RKObjectLoaderDelegate, UIAlertViewDelegate>{
@interface MasterViewController : UITableViewController <RKObjectLoaderDelegate, UIAlertViewDelegate,DetailViewControllerDelegate>{
NSArray *visits;
NSIndexPath *lastSelectedIndex;
AlertType alertType;
BOOL saving;
}

-(void) loadObjectsFromDataStore;
Expand Down
39 changes: 35 additions & 4 deletions FishCount/MasterViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ -(void) loadObjectsFromWebPrompt{
[alert setDelegate:self];
[alert addButtonWithTitle:@"No"];
[alert addButtonWithTitle:@"Yes"];
[self.view endEditing:TRUE];
[alert show];
}

Expand All @@ -61,6 +62,7 @@ -(void) loadObjectsFromWeb{
}

-(void) syncObjectsToWeb{
saving = YES;
BOOL needsSync = NO;
for (Visit *aVisit in self.visits) {
if([aVisit.updateDatabase boolValue]){
Expand All @@ -70,8 +72,12 @@ -(void) syncObjectsToWeb{
}
}

if(!needsSync){
if(needsSync){
[self loadObjectsFromWeb];
}
else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"You haven't saved any records so there's nothing to sync." message:nil delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[self.view endEditing:TRUE];
[alert show];
}
}
Expand All @@ -80,16 +86,23 @@ -(void) syncObjectsToWeb{
#pragma mark RKObjectLoaderDelegate methods

- (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects {
self.visits = objects;
[self.tableView reloadData];
if(!saving){
self.visits = objects;
[self.tableView reloadData];
}
else{
NSLog(@"we be savin");
saving = NO;
}
}

- (void)objectLoader:(RKObjectLoader*)objectLoader didFailWithError:(NSError*)error {
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Error"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[self.view endEditing:TRUE];
[alert show];
NSLog(@"objectLoader error: %@", error);
}

Expand Down Expand Up @@ -139,6 +152,7 @@ - (void)viewDidLoad
self.navigationItem.rightBarButtonItem = syncToWebButton;

self.detailViewController = (DetailViewController *)[[self.splitViewController.viewControllers lastObject] topViewController];
self.detailViewController.delegate = self;

[self loadObjectsFromDataStore];
}
Expand Down Expand Up @@ -183,6 +197,14 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N

Visit *visit = [visits objectAtIndex:indexPath.row];
cell.textLabel.text = visit.school;
NSLog(@"----cellForRowAtIndexPath");
if([visit.updateDatabase boolValue]){
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"checkmark.png"]];
cell.accessoryView = imgView;
}
else{
cell.accessoryView = nil;
}

return cell;
}
Expand All @@ -200,6 +222,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
[alert setDelegate:self];
[alert addButtonWithTitle:@"No"];
[alert addButtonWithTitle:@"Yes"];
[self.view endEditing:TRUE];
[alert show];
}
else{
Expand All @@ -208,4 +231,12 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
}
}

#pragma mark -
#pragma mark DetailViewControllerDelegate

-(void) didSave{
NSLog(@"sizaved");
[self.tableView reloadData];
}

@end
Binary file added buttons/checkmark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added buttons/checkmark@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 013eab7

Please sign in to comment.