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

#39 Adding priority for task - feature #40

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Application/To-Do.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
5BBE55C925245DBF00090F87 /* TaskDetailsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BBE55C825245DBF00090F87 /* TaskDetailsViewController.swift */; };
5BBE55CB2524623900090F87 /* TextviewBorder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5BBE55CA2524623900090F87 /* TextviewBorder.swift */; };
603B4C66252647BD00579EC6 /* ResultsTableController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 603B4C65252647BD00579EC6 /* ResultsTableController.swift */; };
60B775552528C6C300833A15 /* Priority.swift in Sources */ = {isa = PBXBuildFile; fileRef = 60B775542528C6C200833A15 /* Priority.swift */; };
AB95E033252712C4008C4E48 /* TaskCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = AB95E032252712C4008C4E48 /* TaskCell.swift */; };
/* End PBXBuildFile section */

Expand All @@ -35,6 +36,7 @@
5BBE55C825245DBF00090F87 /* TaskDetailsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaskDetailsViewController.swift; sourceTree = "<group>"; };
5BBE55CA2524623900090F87 /* TextviewBorder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextviewBorder.swift; sourceTree = "<group>"; };
603B4C65252647BD00579EC6 /* ResultsTableController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ResultsTableController.swift; sourceTree = "<group>"; };
60B775542528C6C200833A15 /* Priority.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Priority.swift; sourceTree = "<group>"; };
AB95E032252712C4008C4E48 /* TaskCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TaskCell.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -81,6 +83,7 @@
children = (
5BBE55A62523A42700090F87 /* To_Do.xcdatamodeld */,
07F46C8425277C7E007DC6AC /* SortTypes.swift */,
60B775542528C6C200833A15 /* Priority.swift */,
);
path = Model;
sourceTree = "<group>";
Expand Down Expand Up @@ -191,6 +194,7 @@
07F46C8525277C7E007DC6AC /* SortTypes.swift in Sources */,
5BBE55B72523A90A00090F87 /* TodoViewController.swift in Sources */,
5BBE559E2523A42700090F87 /* AppDelegate.swift in Sources */,
60B775552528C6C300833A15 /* Priority.swift in Sources */,
5BBE55A02523A42700090F87 /* SceneDelegate.swift in Sources */,
5BBE55A82523A42700090F87 /* To_Do.xcdatamodeld in Sources */,
5BBE55CB2524623900090F87 /* TextviewBorder.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class TaskDetailsViewController: UIViewController{
@IBOutlet weak var subTasksTextView: UITextView!
@IBOutlet weak var endDateTextField: UITextField!
@IBOutlet weak var saveButton: UIBarButtonItem!
@IBOutlet weak var prioritySegmentedControl: UISegmentedControl!

// VARIABLES
var task : Task? = nil
Expand Down Expand Up @@ -76,6 +77,7 @@ class TaskDetailsViewController: UIViewController{
task?.subTasks = subtask
task?.dueDate = endDate
task?.dueDateTimeStamp = selectedDateTimeStamp ?? 0
task?.priority = Priority.getPriorityByIndex(index: prioritySegmentedControl.selectedSegmentIndex).rawValue
return task
}

Expand All @@ -85,6 +87,8 @@ class TaskDetailsViewController: UIViewController{
taskTitleTextField.text = task.title
subTasksTextView.text = task.subTasks
endDateTextField.text = task.dueDate
let priority: Priority = Priority(rawValue: task.priority ?? "") ?? Priority.low
prioritySegmentedControl.selectedSegmentIndex = priority.getPriorityIndex()
}

// IBOUTLET for datepicker
Expand Down
5 changes: 4 additions & 1 deletion Application/To-Do/Controller/TodoViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ class TodoViewController: UITableViewController {
let task = todoList[indexPath.row]
cell.title.text = task.title
cell.subtitle.text = task.dueDate
cell.starImage.isHidden = todoList[indexPath.row].isFavourite ? false : true
/// width adjustment of starImage
cell.starImageWidthConstraint.constant = todoList[indexPath.row].isFavourite ? 32 : 0
let priority: Priority = Priority(rawValue: task.priority ?? "") ?? Priority.low
cell.priorityImage.image = priority.getImageForPriority()
return cell
}

Expand Down
34 changes: 34 additions & 0 deletions Application/To-Do/Model/Priority.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Priority.swift
// To-Do
//
// Created by Amirthy Tejeshwar on 03/10/20.
// Copyright © 2020 Aaryan Kothari. All rights reserved.
//

import UIKit

enum Priority: String, CaseIterable {
case low = "LOW"
case medium = "MEDIUM"
case high = "HIGH"

func getPriorityIndex() -> Int {
return Priority.allCases.firstIndex(of: self)!
}

func getImageForPriority() -> UIImage? {
switch self {
case .low:
return UIImage(systemName: "exclamationmark")
case .medium:
return UIImage(systemName: "exclamationmark.square")
case .high:
return UIImage(systemName: "exclamationmark.square.fill")
}
}

static func getPriorityByIndex(index: Int) -> Priority {
return index < Priority.allCases.count ? Priority.allCases[index] : .low
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="15702" systemVersion="19E287" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="15702" systemVersion="19H2" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="Label" representedClassName="Label" syncable="YES" codeGenerationType="class">
<attribute name="color" optional="YES" attributeType="String"/>
<attribute name="title" optional="YES" attributeType="String"/>
Expand All @@ -9,12 +9,13 @@
<attribute name="dueDate" optional="YES" attributeType="String"/>
<attribute name="dueDateTimeStamp" optional="YES" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES"/>
<attribute name="isFavourite" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="priority" optional="YES" attributeType="String"/>
<attribute name="subTasks" optional="YES" attributeType="String"/>
<attribute name="title" optional="YES" attributeType="String"/>
<relationship name="labels" optional="YES" toMany="YES" deletionRule="Nullify" ordered="YES" destinationEntity="Label" inverseName="relationship" inverseEntity="Label"/>
</entity>
<elements>
<element name="Label" positionX="-54" positionY="18" width="128" height="88"/>
<element name="Task" positionX="-63" positionY="-18" width="128" height="133"/>
<element name="Task" positionX="-63" positionY="-18" width="128" height="148"/>
</elements>
</model>
Loading