diff --git a/UniPlogger.xcodeproj/project.pbxproj b/UniPlogger.xcodeproj/project.pbxproj index d4b28e9..e7e472a 100644 --- a/UniPlogger.xcodeproj/project.pbxproj +++ b/UniPlogger.xcodeproj/project.pbxproj @@ -20,6 +20,7 @@ 4C8956832532D0630099934E /* QuestFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C8956822532D0630099934E /* QuestFactory.swift */; }; 4C8956862532E3230099934E /* QuestTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C8956852532E3230099934E /* QuestTableViewCell.swift */; }; 4CB979C42524E5BC00498E81 /* NavigationTabsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CB979C32524E5BC00498E81 /* NavigationTabsView.swift */; }; + 4CBA217B254EB1AF002BDCC3 /* QuestModels+ViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CBA217A254EB1AF002BDCC3 /* QuestModels+ViewModel.swift */; }; 4CC9C7C825231581004D873D /* QuestViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CC9C7C725231581004D873D /* QuestViewController.swift */; }; 4CC9C7CB252315D7004D873D /* QuestInteractor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CC9C7CA252315D7004D873D /* QuestInteractor.swift */; }; 4CC9C7CE252315E0004D873D /* QuestPresenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4CC9C7CD252315E0004D873D /* QuestPresenter.swift */; }; @@ -88,6 +89,7 @@ 4C8956822532D0630099934E /* QuestFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuestFactory.swift; sourceTree = ""; }; 4C8956852532E3230099934E /* QuestTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuestTableViewCell.swift; sourceTree = ""; }; 4CB979C32524E5BC00498E81 /* NavigationTabsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationTabsView.swift; sourceTree = ""; }; + 4CBA217A254EB1AF002BDCC3 /* QuestModels+ViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "QuestModels+ViewModel.swift"; sourceTree = ""; }; 4CC9C7C725231581004D873D /* QuestViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuestViewController.swift; sourceTree = ""; }; 4CC9C7CA252315D7004D873D /* QuestInteractor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuestInteractor.swift; sourceTree = ""; }; 4CC9C7CD252315E0004D873D /* QuestPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuestPresenter.swift; sourceTree = ""; }; @@ -193,6 +195,7 @@ 4CC9C7D6252315FC004D873D /* QuestWorker.swift */, 4C8956822532D0630099934E /* QuestFactory.swift */, 4CC9C7D3252315F3004D873D /* QuestModels.swift */, + 4CBA217A254EB1AF002BDCC3 /* QuestModels+ViewModel.swift */, 4C7248A82541CDE300ACB32B /* QuestList.swift */, ); path = Main; @@ -595,6 +598,7 @@ 4C7248A92541CDE300ACB32B /* QuestList.swift in Sources */, 4C7248B925455B2C00ACB32B /* QuestBaseViewController.swift in Sources */, AA7F54EC2532C1A6001C4012 /* StartCountingViewController.swift in Sources */, + 4CBA217B254EB1AF002BDCC3 /* QuestModels+ViewModel.swift in Sources */, AA7F551E2533568D001C4012 /* ShareInteractor.swift in Sources */, AA7F54F62532C1CF001C4012 /* LocationManager.swift in Sources */, AA7F54ED2532C1A6001C4012 /* PloggingInteractor.swift in Sources */, @@ -768,7 +772,7 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = ""; + DEVELOPMENT_TEAM = N23K7ZS482; INFOPLIST_FILE = UniPlogger/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", diff --git a/UniPlogger/Model/Quest.swift b/UniPlogger/Model/Quest.swift index 9dcca42..1152055 100644 --- a/UniPlogger/Model/Quest.swift +++ b/UniPlogger/Model/Quest.swift @@ -30,3 +30,14 @@ extension Quest: Hashable { return lhs.id == rhs.id } } + +extension Quest.Category: Comparable { + static func >(lhs: Quest.Category, rhs: Quest.Category) -> Bool { + switch (lhs, rhs) { + case (.training, .routine): + return true + default: + return false + } + } +} diff --git a/UniPlogger/Scene/Quest/Main/QuestInteractor.swift b/UniPlogger/Scene/Quest/Main/QuestInteractor.swift index 6c1f002..a61d4a2 100644 --- a/UniPlogger/Scene/Quest/Main/QuestInteractor.swift +++ b/UniPlogger/Scene/Quest/Main/QuestInteractor.swift @@ -21,10 +21,6 @@ protocol QuestDataStore { class QuestInteractor: QuestDataStore { private var presenter: QuestPresentationLogic private var worker: QuestWorker - private var sectionTable: [Int: Quest.Category] = [ - 0: .training, - 1: .routine - ] private(set) var questList = QuestList(quests: []) init(presenter: QuestPresentationLogic, worker: QuestWorker) { @@ -64,6 +60,7 @@ extension QuestInteractor: QuestBusinessLogic { questList = QuestList(quests: worker.fetchData()) let response = QuestModels.Response(questList: questList.quests(for: request.state)) + presenter.presentQuestList(response: response) } } diff --git a/UniPlogger/Scene/Quest/Main/QuestList.swift b/UniPlogger/Scene/Quest/Main/QuestList.swift index ca3cf47..4f4d929 100644 --- a/UniPlogger/Scene/Quest/Main/QuestList.swift +++ b/UniPlogger/Scene/Quest/Main/QuestList.swift @@ -34,7 +34,11 @@ struct QuestList { // MARK: Getter func quests(for state: State) -> [Quest] { + guard state == .done else { + return questList[state]?.sorted(by: { $0.category > $1.category }) ?? [] + } return questList[state] ?? [] + } func quest(at indexPath: IndexPath, in state: State) -> Quest? { diff --git a/UniPlogger/Scene/Quest/Main/QuestModels+ViewModel.swift b/UniPlogger/Scene/Quest/Main/QuestModels+ViewModel.swift new file mode 100644 index 0000000..d733d74 --- /dev/null +++ b/UniPlogger/Scene/Quest/Main/QuestModels+ViewModel.swift @@ -0,0 +1,83 @@ +// +// QuestModels+ViewModel.swift +// UniPlogger +// +// Created by woong on 2020/11/01. +// Copyright © 2020 손병근. All rights reserved. +// + +import UIKit + +extension QuestModels { + struct ViewModel { + + // MARK: Constants + + struct CellSize { + static let trainingHeight: CGFloat = 176 + 20 + static let routineHeight: CGFloat = 88 + 20 + } + + struct QuestViewModel { + var title: String + var content: String + var category: Quest.Category + var cellImage: UIImage? + var cellImageBackground: UIColor? + var accessoryImage: UIImage? + var backgroundColor: String + } + + // MARK: - Properties + + private var questList = [QuestViewModel]() + + // MARK: - Methods + + // MARK: Getter + + func numberOfSections() -> Int { + return 1 + } + + func numberOfQuest(in section: Int) -> Int { + guard section == 0 else { return 0 } + return questList.count + } + + func quest(at indexPath: IndexPath) -> QuestViewModel? { + guard isInRagne(for: indexPath) else { return nil } + return questList[indexPath.row] + } + + func height(at indexPath: IndexPath) -> CGFloat { + guard isInRagne(for: indexPath) else { return .zero } + return questList[indexPath.row].category == .training ? + CellSize.trainingHeight : + CellSize.routineHeight + } + + // MARK: Mutating + + mutating func append(_ viewModel: QuestViewModel) { + questList.append(viewModel) + } + + // MARK: Private + + private func isInRagne(for indexPath: IndexPath) -> Bool { + return 0.. QuestViewModel? { + guard isInRagne(for: indexPath) else { return nil } + return questList.remove(at: indexPath.row) + } + + subscript(indexPath: IndexPath) -> QuestViewModel? { + guard isInRagne(for: indexPath) else { return nil } + return questList[indexPath.row] + } + } +} diff --git a/UniPlogger/Scene/Quest/Main/QuestModels.swift b/UniPlogger/Scene/Quest/Main/QuestModels.swift index f7014b2..8314d3c 100644 --- a/UniPlogger/Scene/Quest/Main/QuestModels.swift +++ b/UniPlogger/Scene/Quest/Main/QuestModels.swift @@ -20,53 +20,4 @@ enum QuestModels { struct Response { var questList: [Quest] } - - struct ViewModel { - struct QuestViewModel { - var title: String - var content: String - var category: Quest.Category - var cellImage: UIImage? - var cellImageBackground: UIColor? - var accessoryImage: UIImage? - var backgroundColor: String - } - - init() { - categoryOfSection[0] = .training - categoryOfSection[1] = .routine - } - - private var questList = [Quest.Category: [QuestViewModel]]() - private(set) var categoryOfSection = [Int: Quest.Category]() - - func numberOfSections() -> Int { - return categoryOfSection.count - } - - func numberOfQuest(in section: Int) -> Int { - guard 0.. QuestViewModel? { - guard let section = categoryOfSection[indexPath.section] else { return nil } - return questList[section]?[indexPath.row] - } - - mutating func append(_ viewModel: QuestViewModel) { - questList[viewModel.category, default: []].append(viewModel) - } - - @discardableResult - mutating func remove(at indexPath: IndexPath) -> QuestViewModel? { - guard let category = categoryOfSection[indexPath.section] else { return nil } - return questList[category]?.remove(at: indexPath.row) - } - - subscript(indexPath: IndexPath) -> QuestViewModel? { - guard let category = categoryOfSection[indexPath.section] else { return nil } - return questList[category]?[indexPath.row] - } - } } diff --git a/UniPlogger/Scene/Quest/Main/QuestViewController.swift b/UniPlogger/Scene/Quest/Main/QuestViewController.swift index 5960bfd..070f06b 100644 --- a/UniPlogger/Scene/Quest/Main/QuestViewController.swift +++ b/UniPlogger/Scene/Quest/Main/QuestViewController.swift @@ -22,11 +22,6 @@ class QuestViewController: QuestBaseViewController { static let viewLeading: CGFloat = 16 static let viewTrailing: CGFloat = -16 static let verticalSpacing: CGFloat = 20 - - struct Cell { - static let trainingHeight: CGFloat = 176 + 20 - static let routineHeight: CGFloat = 88 + 20 - } } private struct Images { @@ -202,12 +197,7 @@ extension QuestViewController: UITableViewDelegate { } func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { - guard let category = questViewModel?.categoryOfSection[indexPath.section] else { return 0 } - - switch category { - case .training: return Metric.Cell.trainingHeight - case .routine: return Metric.Cell.routineHeight - } + return questViewModel?.height(at: indexPath) ?? .zero } func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? { diff --git a/UniPlogger/Scene/Quest/QuestBaseViewController.swift b/UniPlogger/Scene/Quest/QuestBaseViewController.swift index 065d989..df8aaed 100644 --- a/UniPlogger/Scene/Quest/QuestBaseViewController.swift +++ b/UniPlogger/Scene/Quest/QuestBaseViewController.swift @@ -10,6 +10,9 @@ import UIKit class QuestBaseViewController: BaseViewController { + // status bar 색이랑 탭바 색을 맞추기 위해서 추가. + // view: tabBar 색 + // backgroundView: 원하는 배경색 var backgroundView = UIView().then { $0.translatesAutoresizingMaskIntoConstraints = false $0.backgroundColor = Color.questBackground