diff --git a/TimeCrumbs/Custom Cells/LogItemTableViewCell.swift b/TimeCrumbs/Custom Cells/LogItemTableViewCell.swift index 6b3711d..9f98059 100644 --- a/TimeCrumbs/Custom Cells/LogItemTableViewCell.swift +++ b/TimeCrumbs/Custom Cells/LogItemTableViewCell.swift @@ -40,7 +40,9 @@ class LogItemTableViewCell: UITableViewCell { dateLabel.text = format(date: date) } - if let taskName = task.name?.trimmingCharacters(in: .whitespacesAndNewlines), + if task.isActive { + taskNameLabel.text = "In Progress" + } else if let taskName = task.name?.trimmingCharacters(in: .whitespacesAndNewlines), taskName.isEmpty == false { taskNameLabel.text = task.name } else { diff --git a/TimeCrumbs/Custom Cells/ProjectCollectionViewCell.swift b/TimeCrumbs/Custom Cells/ProjectCollectionViewCell.swift index 7ff79ab..1bd98d9 100644 --- a/TimeCrumbs/Custom Cells/ProjectCollectionViewCell.swift +++ b/TimeCrumbs/Custom Cells/ProjectCollectionViewCell.swift @@ -7,6 +7,7 @@ // import UIKit +import CoreData protocol ProjectCollectionViewCellDelegate: class { func logTimeButtonTapped(cell: ProjectCollectionViewCell) @@ -82,15 +83,26 @@ class ProjectCollectionViewCell: UICollectionViewCell { } private func setupViews() { - projectLabel.text = project?.name - if let projectColorName = project?.color, + guard let project = project else { return } + + projectLabel.text = project.name + if let projectColorName = project.color, let projectColor = UIColor(named: projectColorName) { projectColorView.backgroundColor = projectColor logTimeButton.tintColor = projectColor startButton.tintColor = projectColor } - + + let request: NSFetchRequest = Task.fetchRequest() + request.predicate = NSPredicate(format: "(project = %@) AND (isActive = YES)", project) + if let startedTasks = try? project.managedObjectContext?.fetch(request), + startedTasks.count > 0 { + + startLabel.text = "RESUME" + } else { + startLabel.text = "START" + } } } diff --git a/TimeCrumbs/Custom Cells/ProjectDetailTableViewCell.swift b/TimeCrumbs/Custom Cells/ProjectDetailTableViewCell.swift index 25b6216..6b28a2d 100644 --- a/TimeCrumbs/Custom Cells/ProjectDetailTableViewCell.swift +++ b/TimeCrumbs/Custom Cells/ProjectDetailTableViewCell.swift @@ -22,7 +22,9 @@ class ProjectDetailTableViewCell: UITableViewCell { func update(with task: Task) { let taskDuration = format(duration: task.duration) - if let taskName = task.name?.trimmingCharacters(in: .whitespacesAndNewlines), + if task.isActive { + taskNameLabel.text = "In Progress" + } else if let taskName = task.name?.trimmingCharacters(in: .whitespacesAndNewlines), taskName.isEmpty == false { taskNameLabel.text = task.name } else { diff --git a/TimeCrumbs/View Controllers/LogTableViewController.swift b/TimeCrumbs/View Controllers/LogTableViewController.swift index c081cf4..912ccc7 100644 --- a/TimeCrumbs/View Controllers/LogTableViewController.swift +++ b/TimeCrumbs/View Controllers/LogTableViewController.swift @@ -62,6 +62,15 @@ class LogTableViewController: UITableViewController { return cell } + override func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle { + if let task = fetchedResultsController?.object(at: indexPath) { + if task.isActive { + return .none + } + } + return .delete + } + override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { if editingStyle == .delete { if let task = fetchedResultsController?.object(at: indexPath) { diff --git a/TimeCrumbs/View Controllers/ProjectDetailTableViewController.swift b/TimeCrumbs/View Controllers/ProjectDetailTableViewController.swift index 621e19f..4e7091a 100644 --- a/TimeCrumbs/View Controllers/ProjectDetailTableViewController.swift +++ b/TimeCrumbs/View Controllers/ProjectDetailTableViewController.swift @@ -79,6 +79,15 @@ class ProjectDetailTableViewController: UITableViewController { return cell } + + override func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle { + if let task = fetchedResultsController?.object(at: indexPath) { + if task.isActive { + return .none + } + } + return .delete + } override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { if editingStyle == .delete { @@ -96,7 +105,18 @@ class ProjectDetailTableViewController: UITableViewController { } } + override func tableView(_ tableView: UITableView, willSelectRowAt indexPath: IndexPath) -> IndexPath? { + guard let task = fetchedResultsController?.object(at: indexPath) else { return nil } + + if task.isActive { + return nil + } + + return indexPath + } + // MARK: - Navigation + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if segue.identifier == "toEditProject" { guard let destination = segue.destination as? AddProjectViewController,