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

[Quest] Main Quest List 로직 수정 #35

Merged
merged 13 commits into from
Nov 1, 2020
6 changes: 5 additions & 1 deletion UniPlogger.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -88,6 +89,7 @@
4C8956822532D0630099934E /* QuestFactory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuestFactory.swift; sourceTree = "<group>"; };
4C8956852532E3230099934E /* QuestTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuestTableViewCell.swift; sourceTree = "<group>"; };
4CB979C32524E5BC00498E81 /* NavigationTabsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationTabsView.swift; sourceTree = "<group>"; };
4CBA217A254EB1AF002BDCC3 /* QuestModels+ViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "QuestModels+ViewModel.swift"; sourceTree = "<group>"; };
4CC9C7C725231581004D873D /* QuestViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuestViewController.swift; sourceTree = "<group>"; };
4CC9C7CA252315D7004D873D /* QuestInteractor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuestInteractor.swift; sourceTree = "<group>"; };
4CC9C7CD252315E0004D873D /* QuestPresenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuestPresenter.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -193,6 +195,7 @@
4CC9C7D6252315FC004D873D /* QuestWorker.swift */,
4C8956822532D0630099934E /* QuestFactory.swift */,
4CC9C7D3252315F3004D873D /* QuestModels.swift */,
4CBA217A254EB1AF002BDCC3 /* QuestModels+ViewModel.swift */,
4C7248A82541CDE300ACB32B /* QuestList.swift */,
);
path = Main;
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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)",
Expand Down
11 changes: 11 additions & 0 deletions UniPlogger/Model/Quest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
5 changes: 1 addition & 4 deletions UniPlogger/Scene/Quest/Main/QuestInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
}
4 changes: 4 additions & 0 deletions UniPlogger/Scene/Quest/Main/QuestList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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? {
Expand Down
83 changes: 83 additions & 0 deletions UniPlogger/Scene/Quest/Main/QuestModels+ViewModel.swift
Original file line number Diff line number Diff line change
@@ -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..<questList.count ~= indexPath.row && indexPath.section == 0
}

@discardableResult
mutating func remove(at indexPath: IndexPath) -> 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]
}
}
}
49 changes: 0 additions & 49 deletions UniPlogger/Scene/Quest/Main/QuestModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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..<categoryOfSection.count ~= section else { return 0 }
return questList[categoryOfSection[section]!]?.count ?? 0
}

func quest(at indexPath: IndexPath) -> 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]
}
}
}
12 changes: 1 addition & 11 deletions UniPlogger/Scene/Quest/Main/QuestViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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? {
Expand Down
3 changes: 3 additions & 0 deletions UniPlogger/Scene/Quest/QuestBaseViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down