Skip to content

Commit

Permalink
Add UI of TodoList
Browse files Browse the repository at this point in the history
  • Loading branch information
JK0369 committed Apr 29, 2021
1 parent 48df5c4 commit 36284dd
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 2 deletions.
12 changes: 12 additions & 0 deletions TodoList.xcodeproj/project.pbxproj
Expand Up @@ -31,6 +31,7 @@
E0B34A6A263AD08500C72855 /* TodoListBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0B34A66263AD08500C72855 /* TodoListBuilder.swift */; };
E0B34A6B263AD08500C72855 /* TodoListInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0B34A67263AD08500C72855 /* TodoListInteractor.swift */; };
E0B34A6D263AD17500C72855 /* LoggedInComponent+TodoList.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0B34A6C263AD17500C72855 /* LoggedInComponent+TodoList.swift */; };
E0B34A70263AE4F900C72855 /* UserDefaultManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0B34A6F263AE4F900C72855 /* UserDefaultManager.swift */; };
E0F04ECD263A84DA009A07B2 /* RootComponent+LoggedIn.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0F04ECC263A84DA009A07B2 /* RootComponent+LoggedIn.swift */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -63,6 +64,7 @@
E0B34A66263AD08500C72855 /* TodoListBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TodoListBuilder.swift; sourceTree = "<group>"; };
E0B34A67263AD08500C72855 /* TodoListInteractor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TodoListInteractor.swift; sourceTree = "<group>"; };
E0B34A6C263AD17500C72855 /* LoggedInComponent+TodoList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "LoggedInComponent+TodoList.swift"; sourceTree = "<group>"; };
E0B34A6F263AE4F900C72855 /* UserDefaultManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaultManager.swift; sourceTree = "<group>"; };
E0F04ECC263A84DA009A07B2 /* RootComponent+LoggedIn.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RootComponent+LoggedIn.swift"; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -127,6 +129,7 @@
E0868D9826397BCC003D9D87 /* TodoList */ = {
isa = PBXGroup;
children = (
E0B34A6E263AE4EF00C72855 /* Utils */,
E0B34A63263AD07800C72855 /* TodoList */,
E0840A18263A83DB00D04DF2 /* LoggedIn */,
E0868DBB263982D5003D9D87 /* LoggedOut */,
Expand Down Expand Up @@ -185,6 +188,14 @@
path = TodoList;
sourceTree = "<group>";
};
E0B34A6E263AE4EF00C72855 /* Utils */ = {
isa = PBXGroup;
children = (
E0B34A6F263AE4F900C72855 /* UserDefaultManager.swift */,
);
path = Utils;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -300,6 +311,7 @@
files = (
E0868D9E26397BCC003D9D87 /* ViewController.swift in Sources */,
E0B34A6A263AD08500C72855 /* TodoListBuilder.swift in Sources */,
E0B34A70263AE4F900C72855 /* UserDefaultManager.swift in Sources */,
E0B34A6D263AD17500C72855 /* LoggedInComponent+TodoList.swift in Sources */,
E0868DC4263985BD003D9D87 /* LoggedOutBuilder.swift in Sources */,
E0840A1C263A83F100D04DF2 /* LoggedInRouter.swift in Sources */,
Expand Down
87 changes: 85 additions & 2 deletions TodoList/TodoList/TodoListViewController.swift
Expand Up @@ -8,8 +8,9 @@
import RIBs
import RxSwift
import UIKit
import SnapKit

protocol TodoListPresentableListener: class {
protocol TodoListPresentableListener: AnyObject {
// TODO: Declare properties and methods that the view controller can invoke to perform
// business logic, such as signIn(). This protocol is implemented by the corresponding
// interactor class.
Expand All @@ -18,17 +19,99 @@ protocol TodoListPresentableListener: class {
final class TodoListViewController: UIViewController, TodoListPresentable, TodoListViewControllable {

weak var listener: TodoListPresentableListener?
var data = [String]()

init(email: String, password: String) {
self.email = email
self.password = password
super.init()
super.init(nibName: nil, bundle: nil)
}

required init?(coder aDecoder: NSCoder) {
fatalError("IB is not supported")
}

override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
setupTableView()
loadData()
}

// MARK: - Private

private lazy var emailLabel: UILabel = {
let label = UILabel()
label.text = email
view.addSubview(label)
return label
}()

private lazy var addButton: UIButton = {
let button = UIButton()
button.setImage(UIImage(systemName: "plus"), for: .normal)
view.addSubview(button)
return button
}()

private lazy var topContainerView: UIView = {
let view = UIView()
self.view.addSubview(view)
view.backgroundColor = .lightGray

view.snp.makeConstraints { (make) in
make.top.equalTo(self.view.snp.top)
make.leading.trailing.equalTo(self.view)
make.height.equalTo(50)
}

emailLabel.snp.makeConstraints { (make) in
make.centerY.centerX.equalTo(view)
}

addButton.snp.makeConstraints { (make) in
make.centerY.equalTo(view)
make.trailing.equalTo(view.snp.trailing).inset(12)
}

return view
}()

private lazy var tableView: UITableView = {
let tableView = UITableView()
view.addSubview(tableView)
tableView.snp.makeConstraints { (make) in
make.top.equalTo(topContainerView.snp.bottom)
make.leading.bottom.trailing.equalTo(self.view)
}
return tableView
}()

private let email: String
private let password: String
}

extension TodoListViewController {
func setupTableView() {
tableView.dataSource = self
tableView.delegate = self
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "tableViewCell")
}

func loadData() {
let data = UserDefaultManager.todoList
self.data = data
}
}

extension TodoListViewController: UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "tableViewCell")! as UITableViewCell
cell.textLabel?.text = data[indexPath.row]
return cell
}
}
33 changes: 33 additions & 0 deletions TodoList/Utils/UserDefaultManager.swift
@@ -0,0 +1,33 @@
//
// UserDefaultManager.swift
// TodoList
//
// Created by 김종권 on 2021/04/29.
//

import Foundation

@propertyWrapper
fileprivate struct UserDefaultWrapper<E> {
private let key: String
private let defaultValue: E

init(key: String, defaultValue: E) {
self.key = key
self.defaultValue = defaultValue
}

var wrappedValue: E {
get {
return UserDefaults.standard.object(forKey: key) as? E ?? defaultValue
}
set {
UserDefaults.standard.set(newValue, forKey: key)
}
}
}

struct UserDefaultManager {
@UserDefaultWrapper(key: "todoList", defaultValue: [String]())
static var todoList
}

0 comments on commit 36284dd

Please sign in to comment.