Skip to content

Commit

Permalink
GH-21 Meetup5 Improve Todo cell UI (#26)
Browse files Browse the repository at this point in the history
* GH-21 Meetup 5 Improve Todo Cell UI:
- Added completion date property to Item Model
- Added an icon for complete and incomplete state.
- Added label to display completed date
- Setup labels layout to vertical when dynamic type size is large.
- Removed autoresizing masks form xibs
- Cleaned up code and added pragma marks

* GH-21

* GH-20 Meetup5 Empty state (#25)

* GH-21 Changes:
- Moved TableView to child VC.
- Handled Keyboard
- Added Empty state
- Fixed textField placeholder Dynamic Type support
- Added Extensions to add and remove child VC's, add subview with fill constraints
- Made Navbar opaque.

* GH-20 Empty state improvements
  • Loading branch information
ivancr committed Nov 9, 2018
1 parent e6f59fc commit f2da8d2
Show file tree
Hide file tree
Showing 17 changed files with 538 additions and 115 deletions.
16 changes: 16 additions & 0 deletions TodoList.xcodeproj/project.pbxproj
Expand Up @@ -13,6 +13,10 @@
2C677E78213DDE6A00BEAF40 /* UITableViewExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C677E75213DDE6A00BEAF40 /* UITableViewExtensions.swift */; };
2C677E7A213DE3DB00BEAF40 /* TextFieldView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C677E79213DE3DB00BEAF40 /* TextFieldView.swift */; };
2C677E7C213DE3E600BEAF40 /* TextFieldView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2C677E7B213DE3E600BEAF40 /* TextFieldView.xib */; };
2C7E196B2159D6B00002ED43 /* TodoTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C7E196A2159D6B00002ED43 /* TodoTableViewController.swift */; };
2C7E196D2159DE0E0002ED43 /* UIViewControllerExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C7E196C2159DE0E0002ED43 /* UIViewControllerExtensions.swift */; };
2C7E196F2159F4DD0002ED43 /* EmptyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C7E196E2159F4DD0002ED43 /* EmptyView.swift */; };
2C7E19712159F4F70002ED43 /* EmptyView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2C7E19702159F4F70002ED43 /* EmptyView.xib */; };
A5142CCC2144ABDD002150BB /* NSObjectExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5142CCB2144ABDD002150BB /* NSObjectExtensions.swift */; };
A7E81039214B133D00E16B45 /* Todos.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7E81038214B133D00E16B45 /* Todos.swift */; };
D341523C2138AA9C0009D874 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D341523B2138AA9C0009D874 /* AppDelegate.swift */; };
Expand All @@ -29,6 +33,10 @@
2C677E75213DDE6A00BEAF40 /* UITableViewExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UITableViewExtensions.swift; sourceTree = "<group>"; };
2C677E79213DE3DB00BEAF40 /* TextFieldView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextFieldView.swift; sourceTree = "<group>"; };
2C677E7B213DE3E600BEAF40 /* TextFieldView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = TextFieldView.xib; sourceTree = "<group>"; };
2C7E196A2159D6B00002ED43 /* TodoTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TodoTableViewController.swift; sourceTree = "<group>"; };
2C7E196C2159DE0E0002ED43 /* UIViewControllerExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIViewControllerExtensions.swift; sourceTree = "<group>"; };
2C7E196E2159F4DD0002ED43 /* EmptyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EmptyView.swift; sourceTree = "<group>"; };
2C7E19702159F4F70002ED43 /* EmptyView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = EmptyView.xib; sourceTree = "<group>"; };
A5142CCB2144ABDD002150BB /* NSObjectExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NSObjectExtensions.swift; sourceTree = "<group>"; };
A7E81038214B133D00E16B45 /* Todos.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Todos.swift; sourceTree = "<group>"; };
D34152382138AA9C0009D874 /* TodoList.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TodoList.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -67,6 +75,8 @@
2C677E6F213DDE1300BEAF40 /* ItemTableViewCell.xib */,
2C677E79213DE3DB00BEAF40 /* TextFieldView.swift */,
2C677E7B213DE3E600BEAF40 /* TextFieldView.xib */,
2C7E196E2159F4DD0002ED43 /* EmptyView.swift */,
2C7E19702159F4F70002ED43 /* EmptyView.xib */,
);
path = Views;
sourceTree = "<group>";
Expand All @@ -75,6 +85,7 @@
isa = PBXGroup;
children = (
D341524D2138B1090009D874 /* TodoListViewController.swift */,
2C7E196A2159D6B00002ED43 /* TodoTableViewController.swift */,
);
path = "View Controllers";
sourceTree = "<group>";
Expand All @@ -95,6 +106,7 @@
A5142CCB2144ABDD002150BB /* NSObjectExtensions.swift */,
2C677E75213DDE6A00BEAF40 /* UITableViewExtensions.swift */,
2C677E74213DDE6A00BEAF40 /* UIViewExtensions.swift */,
2C7E196C2159DE0E0002ED43 /* UIViewControllerExtensions.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -190,6 +202,7 @@
2C677E71213DDE1300BEAF40 /* ItemTableViewCell.xib in Resources */,
2C677E7C213DE3E600BEAF40 /* TextFieldView.xib in Resources */,
D34152432138AA9D0009D874 /* Assets.xcassets in Resources */,
2C7E19712159F4F70002ED43 /* EmptyView.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -201,7 +214,10 @@
buildActionMask = 2147483647;
files = (
2C677E78213DDE6A00BEAF40 /* UITableViewExtensions.swift in Sources */,
2C7E196D2159DE0E0002ED43 /* UIViewControllerExtensions.swift in Sources */,
2C7E196B2159D6B00002ED43 /* TodoTableViewController.swift in Sources */,
2C677E7A213DE3DB00BEAF40 /* TextFieldView.swift in Sources */,
2C7E196F2159F4DD0002ED43 /* EmptyView.swift in Sources */,
2C677E70213DDE1300BEAF40 /* ItemTableViewCell.swift in Sources */,
A5142CCC2144ABDD002150BB /* NSObjectExtensions.swift in Sources */,
D341524E2138B1090009D874 /* TodoListViewController.swift in Sources */,
Expand Down
24 changes: 4 additions & 20 deletions TodoList/AppDelegate.swift
Expand Up @@ -7,34 +7,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

let navController = UINavigationController(rootViewController: TodoListViewController(style: .grouped))
let navController = UINavigationController(rootViewController: TodoListViewController())

window = UIWindow(frame: UIScreen.main.bounds)
window?.rootViewController = navController
window?.makeKeyAndVisible()
setAppearance()

return true
}

func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
completionHandler(handleShortcut(shortcutItem))
}

func handleShortcut(_ shortcutItem: UIApplicationShortcutItem ) -> Bool {
print("Handling shortcut")

var succeeded = false

if (shortcutItem.type == "io.chuva.TodoList.clear-all") {
UserDefaults.standard.set(nil, forKey: "todoList")
let navController = UINavigationController(rootViewController: TodoListViewController(style: .grouped))
window?.rootViewController = navController
window?.makeKeyAndVisible()
succeeded = true
}

return succeeded

func setAppearance() {
UINavigationBar.appearance().isTranslucent = false
}
}

27 changes: 27 additions & 0 deletions TodoList/Extensions/UIViewControllerExtensions.swift
@@ -0,0 +1,27 @@
import UIKit

extension UIViewController {

/// Adds a subview to the calling `UIViewControler` and constrains it to the edges
///
/// - Parameter subview: view to add as subview and constraint.
/// - Parameter margin: Optional margin inset to all of the edges of the subview. Defaults to 0.
func addSubViewWithFillConstraints(_ subview: UIView, margin: CGFloat = 0) {
view.addSubViewWithFillConstraints(subview, margin: margin)
}

func add(_ child: UIViewController) {
child.view.translatesAutoresizingMaskIntoConstraints = false
addChildViewController(child)
view.addSubview(child.view)
child.didMove(toParentViewController: self)
}

func remove() {
guard parent != nil else { return }

willMove(toParentViewController: nil)
removeFromParentViewController()
view.removeFromSuperview()
}
}
14 changes: 14 additions & 0 deletions TodoList/Extensions/UIViewExtensions.swift
Expand Up @@ -12,4 +12,18 @@ extension UIView {

return nibView
}

/// Adds a subview and constrains it to the edges
///
/// - Parameter subview: view to add as subview and constraint.
/// - Parameter margin: Optional margin inset to all of the edges of the subview. Defaults to 0.
func addSubViewWithFillConstraints(_ subview: UIView, margin: CGFloat = 0) {
addSubview(subview)
subview.translatesAutoresizingMaskIntoConstraints = false

subview.topAnchor.constraint(equalTo: topAnchor, constant: margin).isActive = true
subview.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -margin).isActive = true
subview.leadingAnchor.constraint(equalTo: leadingAnchor, constant: margin).isActive = true
subview.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -margin).isActive = true
}
}
4 changes: 3 additions & 1 deletion TodoList/Models/Item.swift
Expand Up @@ -2,10 +2,12 @@ import Foundation

struct Item: Codable {
let title: String
var completionDate: Date?
var isComplete: Bool

init(title: String, isComplete: Bool = false) {
init(title: String, completionDate: Date? = nil, isComplete: Bool = false) {
self.title = title
self.completionDate = completionDate
self.isComplete = isComplete
}
}
@@ -0,0 +1,16 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "completedIcon.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template",
"preserves-vector-representation" : true
}
}
Binary file not shown.
16 changes: 16 additions & 0 deletions TodoList/Resources/Assets.xcassets/todoIcon.imageset/Contents.json
@@ -0,0 +1,16 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "todoIcon.pdf"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
},
"properties" : {
"template-rendering-intent" : "template",
"preserves-vector-representation" : true
}
}
Binary file not shown.

0 comments on commit f2da8d2

Please sign in to comment.