diff --git a/MarsWater/MarsWater.xcodeproj/project.pbxproj b/MarsWater/MarsWater.xcodeproj/project.pbxproj index a2f82e3..3f48698 100644 --- a/MarsWater/MarsWater.xcodeproj/project.pbxproj +++ b/MarsWater/MarsWater.xcodeproj/project.pbxproj @@ -19,6 +19,8 @@ 8DB2F6E81BC1E75500E58E65 /* List+CoreDataProperties.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DB2F6E21BC1E75500E58E65 /* List+CoreDataProperties.m */; }; 8DB2F6E91BC1E75500E58E65 /* Task.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DB2F6E41BC1E75500E58E65 /* Task.m */; }; 8DB2F6EA1BC1E75500E58E65 /* Task+CoreDataProperties.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DB2F6E61BC1E75500E58E65 /* Task+CoreDataProperties.m */; }; + ABF463FB1BC5F24C0054CE11 /* TasksTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = ABF463FA1BC5F24C0054CE11 /* TasksTableViewController.m */; settings = {ASSET_TAGS = (); }; }; + ABF463FE1BC600E70054CE11 /* TaskCreationViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = ABF463FD1BC600E70054CE11 /* TaskCreationViewController.m */; settings = {ASSET_TAGS = (); }; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -43,6 +45,10 @@ 8DB2F6E41BC1E75500E58E65 /* Task.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Task.m; sourceTree = ""; }; 8DB2F6E51BC1E75500E58E65 /* Task+CoreDataProperties.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Task+CoreDataProperties.h"; sourceTree = ""; }; 8DB2F6E61BC1E75500E58E65 /* Task+CoreDataProperties.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "Task+CoreDataProperties.m"; sourceTree = ""; }; + ABF463F91BC5F24C0054CE11 /* TasksTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TasksTableViewController.h; sourceTree = ""; }; + ABF463FA1BC5F24C0054CE11 /* TasksTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TasksTableViewController.m; sourceTree = ""; }; + ABF463FC1BC600E70054CE11 /* TaskCreationViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TaskCreationViewController.h; sourceTree = ""; }; + ABF463FD1BC600E70054CE11 /* TaskCreationViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TaskCreationViewController.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -82,6 +88,10 @@ 8DA86CD31BC1B8E4006C50BC /* ListsTableViewController.m */, 8DA86CD51BC1B904006C50BC /* ListCreationTableViewController.h */, 8DA86CD61BC1B904006C50BC /* ListCreationTableViewController.m */, + ABF463F91BC5F24C0054CE11 /* TasksTableViewController.h */, + ABF463FA1BC5F24C0054CE11 /* TasksTableViewController.m */, + ABF463FC1BC600E70054CE11 /* TaskCreationViewController.h */, + ABF463FD1BC600E70054CE11 /* TaskCreationViewController.m */, 8DA86CB01BC1AE57006C50BC /* Main.storyboard */, 8DA86CB61BC1AE57006C50BC /* Assets.xcassets */, 8DA86CB81BC1AE57006C50BC /* LaunchScreen.storyboard */, @@ -189,8 +199,10 @@ 8DA86CAC1BC1AE57006C50BC /* AppDelegate.m in Sources */, 8DB2F6EA1BC1E75500E58E65 /* Task+CoreDataProperties.m in Sources */, 8DA86CD41BC1B8E4006C50BC /* ListsTableViewController.m in Sources */, + ABF463FE1BC600E70054CE11 /* TaskCreationViewController.m in Sources */, 8DB2F6E71BC1E75500E58E65 /* List.m in Sources */, 8DB2F6E91BC1E75500E58E65 /* Task.m in Sources */, + ABF463FB1BC5F24C0054CE11 /* TasksTableViewController.m in Sources */, 8DA86CD71BC1B904006C50BC /* ListCreationTableViewController.m in Sources */, 8DA86CA91BC1AE57006C50BC /* main.m in Sources */, 8DB2F6E81BC1E75500E58E65 /* List+CoreDataProperties.m in Sources */, diff --git a/MarsWater/MarsWater.xcodeproj/project.xcworkspace/xcshareddata/MarsWater.xcscmblueprint b/MarsWater/MarsWater.xcodeproj/project.xcworkspace/xcshareddata/MarsWater.xcscmblueprint new file mode 100644 index 0000000..f8e3eb1 --- /dev/null +++ b/MarsWater/MarsWater.xcodeproj/project.xcworkspace/xcshareddata/MarsWater.xcscmblueprint @@ -0,0 +1,30 @@ +{ + "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "6DE2C1D134E7E42733C08A7A796A852DF2F0373A", + "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : { + + }, + "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { + "A3AEDD975711D11A3C07EE12753FF388EB8DBC2D" : 0, + "6DE2C1D134E7E42733C08A7A796A852DF2F0373A" : 0 + }, + "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "DF0F57E6-66E2-436C-A7A3-E0FAA1F6209B", + "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { + "A3AEDD975711D11A3C07EE12753FF388EB8DBC2D" : "", + "6DE2C1D134E7E42733C08A7A796A852DF2F0373A" : "unit-2-hw-3\/" + }, + "DVTSourceControlWorkspaceBlueprintNameKey" : "MarsWater", + "DVTSourceControlWorkspaceBlueprintVersion" : 204, + "DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "SavingForever\/MarsWater.xcodeproj", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [ + { + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/bereket6725\/unit-2-hw-3.git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "6DE2C1D134E7E42733C08A7A796A852DF2F0373A" + }, + { + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/bereket6725\/presetTimerRepo.git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "A3AEDD975711D11A3C07EE12753FF388EB8DBC2D" + } + ] +} \ No newline at end of file diff --git a/MarsWater/MarsWater/Base.lproj/Main.storyboard b/MarsWater/MarsWater/Base.lproj/Main.storyboard index 13ead89..c1ff794 100644 --- a/MarsWater/MarsWater/Base.lproj/Main.storyboard +++ b/MarsWater/MarsWater/Base.lproj/Main.storyboard @@ -41,6 +41,9 @@ + + + @@ -75,7 +78,7 @@ - + @@ -213,7 +216,97 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -232,5 +325,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/MarsWater/MarsWater/List+CoreDataProperties.h b/MarsWater/MarsWater/List+CoreDataProperties.h index 9ce8d06..ccbccbd 100644 --- a/MarsWater/MarsWater/List+CoreDataProperties.h +++ b/MarsWater/MarsWater/List+CoreDataProperties.h @@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nullable, nonatomic, retain) NSString *title; @property (nullable, nonatomic, retain) NSDate *createdAt; @property (nullable, nonatomic, retain) id color; -@property (nullable, nonatomic, retain) NSArray *task; +@property (nullable, nonatomic, retain) NSOrderedSet *task; @end diff --git a/MarsWater/MarsWater/ListCreationTableViewController.m b/MarsWater/MarsWater/ListCreationTableViewController.m index 0ecf6e9..4c6a099 100644 --- a/MarsWater/MarsWater/ListCreationTableViewController.m +++ b/MarsWater/MarsWater/ListCreationTableViewController.m @@ -10,6 +10,7 @@ #import "ListCreationTableViewController.h" #import "List.h" #import "AppDelegate.h" +#import "TasksTableViewController.h" @interface ListCreationTableViewController () @@ -60,4 +61,11 @@ - (IBAction)colorButtonTapped:(UIButton *)sender { self.list.color = sender.backgroundColor; } + +//-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ +// +// +// +//} + @end diff --git a/MarsWater/MarsWater/ListsTableViewController.h b/MarsWater/MarsWater/ListsTableViewController.h index e83a1d1..99222fd 100644 --- a/MarsWater/MarsWater/ListsTableViewController.h +++ b/MarsWater/MarsWater/ListsTableViewController.h @@ -7,7 +7,10 @@ // #import +#import "List.h" @interface ListsTableViewController : UITableViewController +@property (nonatomic) List *list; + @end diff --git a/MarsWater/MarsWater/ListsTableViewController.m b/MarsWater/MarsWater/ListsTableViewController.m index 8a2659c..dc101b6 100644 --- a/MarsWater/MarsWater/ListsTableViewController.m +++ b/MarsWater/MarsWater/ListsTableViewController.m @@ -9,7 +9,8 @@ #import #import "ListsTableViewController.h" #import "AppDelegate.h" -#import "List.h" +#import "TasksTableViewController.h" +#import "ListCreationTableViewController.h" @interface ListsTableViewController () @@ -72,5 +73,26 @@ - (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id) [self.tableView reloadData]; } + +-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ + + + if([segue.identifier isEqual: @"TasksSegueIdentifer"]){ + + UINavigationController* navigationController = segue.destinationViewController; + + TasksTableViewController* tableViewController = navigationController.childViewControllers[0]; + NSIndexPath* indexPath = [self.tableView indexPathForSelectedRow]; + self.list = self.fetchedResultsController.fetchedObjects[indexPath.row]; + + tableViewController.list = self.list; + + NSLog(@"List Passed: %@",self.list); + + } + +} + + @end diff --git a/MarsWater/MarsWater/TaskCreationViewController.h b/MarsWater/MarsWater/TaskCreationViewController.h new file mode 100644 index 0000000..c51450e --- /dev/null +++ b/MarsWater/MarsWater/TaskCreationViewController.h @@ -0,0 +1,24 @@ +// +// TaskCreationViewController.h +// MarsWater +// +// Created by Bereket on 10/7/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import +#import "AppDelegate.h" +#import "TasksTableViewController.h" +#import +#import "Task.h" +#import "List.h" + +@interface TaskCreationViewController : UIViewController + + + + +@property (strong, nonatomic) IBOutlet UITextField *addTaskTextField; +@property (nonatomic) Task* task; +@property (nonatomic) List* list; +@end diff --git a/MarsWater/MarsWater/TaskCreationViewController.m b/MarsWater/MarsWater/TaskCreationViewController.m new file mode 100644 index 0000000..3b3d36b --- /dev/null +++ b/MarsWater/MarsWater/TaskCreationViewController.m @@ -0,0 +1,107 @@ +// +// TaskCreationViewController.m +// MarsWater +// +// Created by Bereket on 10/7/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import "TaskCreationViewController.h" +//#import "AppDelegate.h" +//#import "TasksTableViewController.h" +//#import +//#import "Task.h" + + +@interface TaskCreationViewController () + +@property (nonatomic) NSMutableOrderedSet *taskList; + +@end + +@implementation TaskCreationViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + [self setupNavigationBar]; + + AppDelegate *delegate = [UIApplication sharedApplication].delegate; + + self.task = [NSEntityDescription insertNewObjectForEntityForName:@"Task" inManagedObjectContext:delegate.managedObjectContext]; + + NSLog(@"Current List 2: %@", self.list); + // Do any additional setup after loading the view. +} + + + +- (void)setupNavigationBar { + + self.navigationItem.title = @"Create new task"; + + self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancel)]; + + self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(save)]; + + // set the right button to save +} + +- (void)cancel { + [self dismissViewControllerAnimated:YES completion:nil]; +} + +- (void)save { + + self.task.taskDescription = self.addTaskTextField.text; + self.task.createdAt = [NSDate date]; // not really necessary I gues since the textLabel or detail wont show it but w/e + + self.taskList = self.list.task.mutableCopy; + + [self.taskList addObject:self.task]; + + self.list.task = self.taskList; + + NSLog(@"self.list.tasks: %@",self.list.task); + + AppDelegate *delegate = [UIApplication sharedApplication].delegate; + + [delegate.managedObjectContext save:nil]; + + [self dismissViewControllerAnimated:YES completion:nil]; + + // [self dismiss]; + + + //self.task.taskDescription = self.addTaskTextField.text; + +// self.list.title = self.titleTextField.text; +// self.list.createdAt = [NSDate date]; +// +// AppDelegate *delegate = [UIApplication sharedApplication].delegate; +// [delegate.managedObjectContext save:nil]; +// +// [self dismissViewControllerAnimated:YES completion:nil]; +} + +//- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { +// +// if ([[segue identifier]isEqualToString:@"taskCreateSegue"]){ +// +// UINavigationController *navController = segue.destinationViewController; +// TaskCreationViewController* viewController = navController.viewControllers[0]; +// NSLog(@"passing this list: %@", self.list); +// viewController.list = self.list; +// } +// +//} +/* +#pragma mark - Navigation + +// In a storyboard-based application, you will often want to do a little preparation before navigation +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { + // Get the new view controller using [segue destinationViewController]. + // Pass the selected object to the new view controller. +} +*/ + +@end diff --git a/MarsWater/MarsWater/TasksTableViewController.h b/MarsWater/MarsWater/TasksTableViewController.h new file mode 100644 index 0000000..fb63e39 --- /dev/null +++ b/MarsWater/MarsWater/TasksTableViewController.h @@ -0,0 +1,16 @@ +// +// TasksTableViewController.h +// MarsWater +// +// Created by Bereket on 10/7/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import +#import "List.h" + +@interface TasksTableViewController : UITableViewController + +@property (nonatomic) List* list; + +@end diff --git a/MarsWater/MarsWater/TasksTableViewController.m b/MarsWater/MarsWater/TasksTableViewController.m new file mode 100644 index 0000000..1260a28 --- /dev/null +++ b/MarsWater/MarsWater/TasksTableViewController.m @@ -0,0 +1,104 @@ +// +// TasksTableViewController.m +// MarsWater +// +// Created by Bereket on 10/7/15. +// Copyright © 2015 Michael Kavouras. All rights reserved. +// + +#import "TasksTableViewController.h" +#import "AppDelegate.h" +#import +#import "TaskCreationViewController.h" + + +@interface TasksTableViewController () + +@property (nonatomic) NSFetchedResultsController *fetchedResultsController; +@end + +@implementation TasksTableViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + [self setupNavigationBar]; + [self fetchResults]; + NSLog(@"Current List 1: %@", self.list); + +} +- (void) fetchResults{ + + AppDelegate *delegate = [UIApplication sharedApplication].delegate; + + // create an instance of NSFetchRequest with an entity name + NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"Task"]; + + // create a sort descriptor + NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"taskDescription" ascending:NO]; + + // set the sortDescriptors on the fetchRequest + fetchRequest.sortDescriptors = @[sort]; + + // NARROWS the search from the fetchRequest based on "list.title" + fetchRequest.predicate = [NSPredicate predicateWithFormat:@"list.title == %@", self.list.title]; + + // create a fetchedResultsController with a fetchRequest and a managedObjectContext, + self.fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:delegate.managedObjectContext sectionNameKeyPath:nil cacheName:nil]; + + self.fetchedResultsController.delegate = self; + + [self.fetchedResultsController performFetch:nil]; + + [self.tableView reloadData]; + +} +- (void)setupNavigationBar { + self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(back)]; + +} +-(void)back{ + + [self dismissViewControllerAnimated:NO completion:nil]; + +} + + +#pragma mark - Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + + return self.fetchedResultsController.fetchedObjects.count; +} + +//dont understand this method :( Is it to adjust where the Tasks/list should be? +- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath { + + [self.tableView reloadData]; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TaskCellIdentifier" forIndexPath:indexPath]; + + Task *task = self.fetchedResultsController.fetchedObjects[indexPath.row]; + cell.textLabel.text = task.taskDescription; + + return cell; +} +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { + + if ([[segue identifier]isEqualToString:@"TaskCreateSegue"]){ + + UINavigationController *navController = segue.destinationViewController; + TaskCreationViewController* viewController = navController.viewControllers[0]; + viewController.list = self.list; + + NSLog(@"passing this list: %@", self.list); + } + +} + +@end