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

[Feat] 기록하기 case 뷰 구현 완료 #5

Merged
merged 4 commits into from
Nov 26, 2024
Merged
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
47 changes: 47 additions & 0 deletions Projects/Core/Models/Sources/Entity/DiaryEntity.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// DiaryEntity.swift
// Models
//
// Created by 박서연 on 2024/11/25.
// Copyright © 2024 inner-dev. All rights reserved.
//

import Foundation

public struct DiaryEntity {
public let event: String
public let behavior: String
public let think: String
public let emotions: [String]

public init(event: String, behavior: String, think: String, emotions: [String]) {
self.event = event
self.behavior = behavior
self.think = think
self.emotions = emotions
}
}

public struct DiaryString: Sequence {
public let event = "사건"
public let behavior = "생각"
public let think = "행동"

public let eventString: String
public let behaviorString: String
public let thinkString: String

public init(
eventString: String,
behaviorString: String,
thinkString: String
) {
self.eventString = eventString
self.behaviorString = behaviorString
self.thinkString = thinkString
}

public func makeIterator() -> Array<String>.Iterator {
return [eventString, behaviorString, thinkString].makeIterator()
}
}
20 changes: 15 additions & 5 deletions Projects/Core/Models/Sources/Enums/EmotionType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ public enum EmotionType: String, Decodable, CaseIterable {
["곤란한","불편한","귀찮은","어색한","부끄러운","지루한","부담스러운","피곤한","부러운","황당한","찝찝한","매스꺼운"]
case .angry:
["답답한","미운","원망스러운","지긋지긋한","짜증나는","억울한","화가나는","역겨운","신경질나는","기분이상한","눈물나는","우려스러운"]

// case .somehow:
// []
}
}

Expand All @@ -47,8 +44,6 @@ public enum EmotionType: String, Decodable, CaseIterable {
return UIColor.fear
case .offensive:
return UIColor.offensive
// case .somehow:
// return UIColor.somehow
}
}

Expand All @@ -67,6 +62,21 @@ public enum EmotionType: String, Decodable, CaseIterable {
}
}

public var image: UIImage {
switch self {
case .happy:
return .icHappy
case .sad:
return .icSad
case .angry:
return .icAnger
case .fear:
return .icFear
case .offensive:
return .icOffensive
}
}

public func gestureEvent(direction: GestureDirection) -> EmotionType {
guard let currentIndex = EmotionType.allCases.firstIndex(of: self) else {
return .happy
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0.910",
"green" : "0.910",
"red" : "0.910"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
7 changes: 7 additions & 0 deletions Projects/DesignSystem/Sources/Color/UIColor+Ex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public enum appColor {
case systemRed
case systemBlue
case systemGreen
case backgroundColor

case pink900
case pink800
Expand Down Expand Up @@ -139,13 +140,19 @@ public extension UIColor {
static var systemRed: UIColor {
return DesignSystemAsset.systemRed.color
}

static var systemBlue: UIColor {
return DesignSystemAsset.systemBlue.color
}

static var systemGreen: UIColor {
return DesignSystemAsset.systemGreen.color
}

static var backgroundColor: UIColor {
return DesignSystemAsset.backgroundColor.color
}

// MARK: - White/Black
static var pureWhite: UIColor {
return DesignSystemAsset.pureWhite.color
Expand Down
39 changes: 34 additions & 5 deletions Projects/DesignSystem/Sources/Navigation/CustomNavigationBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ public enum NavigationBarType {

public class CustomNavigationBar: UIView {

private let titleLabel = UILabel()
private let leftButton = UIButton()
private let rightButton = UIButton()
private let rightLabel = UILabel()
public let titleLabel = UILabel()
public let leftButton = UIButton()
public var rightButton = UIButton()
public var rightLabel = UILabel()
public var config = UIButton.Configuration.filled()

override init(frame: CGRect) {
super.init(frame: frame)
Expand All @@ -41,12 +42,25 @@ public class CustomNavigationBar: UIView {
rightLabel.translatesAutoresizingMaskIntoConstraints = false
}

public func updateRightButtonTitle(_ title: String) {
var config = UIButton.Configuration.filled()
var attributedTitle = AttributedString(title)
attributedTitle.font = FontCase.semibold(.footnote).toUIFont
attributedTitle.foregroundColor = UIColor.coolgray50
config.attributedTitle = attributedTitle
config.contentInsets = NSDirectionalEdgeInsets(top: 8, leading: 12, bottom: 8, trailing: 12)
config.baseBackgroundColor = UIColor.coolgray800
rightButton.configuration = config
}

public func configure(
title: String?,
font: UIFont? = FontCase.regular(.title3).toUIFont,
rightImage: UIImage? = nil,
leftAction: Selector? = nil,
rightAction: Selector? = nil,
RButtonTitle: String? = nil,
RButtonTitleFont: FontCase = FontCase.semibold(.footnote),
target: Any?,
type: NavigationBarType
) {
Expand Down Expand Up @@ -131,6 +145,18 @@ public class CustomNavigationBar: UIView {
leftButton.setImage(.icArrowBack, for: .normal)
titleLabel.text = title
titleLabel.font = font

if let rButtonTitle = RButtonTitle {
var attributedTitle = AttributedString(rButtonTitle)
attributedTitle.font = FontCase.semibold(.footnote).toUIFont
attributedTitle.foregroundColor = UIColor.coolgray50
config.attributedTitle = attributedTitle
}

config.contentInsets = NSDirectionalEdgeInsets(top: 8, leading: 12, bottom: 8, trailing: 12)
config.baseBackgroundColor = UIColor.coolgray800
rightButton.configuration = config

addSubview(titleLabel)
addSubview(leftButton)
addSubview(rightButton)
Expand All @@ -139,8 +165,11 @@ public class CustomNavigationBar: UIView {
leftButton.addTarget(target, action: action, for: .touchUpInside)
}

if let image = rightImage, let action = rightAction {
if let image = rightImage {
rightButton.setImage(image, for: .normal)
}

if let action = rightAction {
rightButton.addTarget(target, action: action, for: .touchUpInside)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import UIKit
import Record
import Models

public class RecordCoordinator {
private let navigationController: UINavigationController
Expand All @@ -33,6 +34,11 @@ public class RecordCoordinator {
}

navigationController.pushViewController(viewController, animated: true)

// let viewModel = ResultViewModel(diaryEntity: DiaryEntity(event: "event", behavior: "behavior", think: "think", emotions: ["감동적인","감사한","자신있는","우려스러운","조마조마한"]), diaryString: DiaryString(eventString: "eventString", behaviorString: "behaviorString", thinkString: "thinkString"))
//
// let viewController = ResultViewController(viewModel: viewModel)
// navigationController.pushViewController(viewController, animated: true)
}

private func secondView(text: String) {
Expand Down Expand Up @@ -73,5 +79,32 @@ public class RecordCoordinator {
viewModel.backButton = {
self.navigationController.popViewController(animated: true)
}

viewModel.nextButton = { [weak self] text in
self?.fifthView()
}
}

private func fifthView() {
let viewModel = ResultViewModel(
diaryEntity: DiaryEntity(
event: "event",
behavior: "behavior",
think: "think",
emotions: ["감동적인","감사한","자신있는","우려스러운","조마조마한"]
),
diaryString: DiaryString(
eventString: "eventString",
behaviorString: "behaviorString",
thinkString: "thinkString"
)
)
let viewController = ResultViewController(viewModel: viewModel)

viewModel.backButton = {
self.navigationController.popViewController(animated: true)
}

navigationController.pushViewController(viewController, animated: true)
}
}
3 changes: 2 additions & 1 deletion Projects/Feature/Scene/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ let module = Project.module(
.core(.service),
.core(.model),
.core(.common),
.designSystem
.designSystem,
.spm(.lottie)
],
infoPlist: false
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ extension EmotionViewController {
}

nextButton.tap {
self.viewModel.nextButtonTapped(text: "")
print("next button tapped")
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
//
// CharacterView.swift
// Home
//
// Created by 박서연 on 2024/11/27.
// Copyright © 2024 inner-dev. All rights reserved.
//

import UIKit
import DesignSystem
import Models

public class CharacterResultView: UIView {

override init(frame: CGRect) {
super.init(frame: frame)
setupView()
}

required init?(coder: NSCoder) {
super.init(coder: coder)
setupView()
}

private let characterImageView: UIImageView = {
let image = UIImageView()
image.contentMode = .scaleAspectFit
image.translatesAutoresizingMaskIntoConstraints = false
return image
}()

private let mainEmotionLabel: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.applyFontCase(FontCase.bold(.caption1))
label.textColor = .coolgray800
return label
}()

private let empathyLabel: UILabel = {
let label = UILabel()
label.numberOfLines = 0
label.applyFontCase(FontCase.semibold(.subheadline))
label.translatesAutoresizingMaskIntoConstraints = false
label.textColor = .coolgray900
return label
}()

private let stackView: UIStackView = {
let stackView = UIStackView()
stackView.axis = .vertical
stackView.spacing = 8
stackView.translatesAutoresizingMaskIntoConstraints = false
return stackView
}()

private let containerView: UIView = {
let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()

private let totalView: UIView = {
let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()

private func setupView() {
stackView.addArrangedSubview(mainEmotionLabel)
stackView.addArrangedSubview(empathyLabel)
containerView.layer.cornerRadius = 4
containerView.addSubview(stackView)
totalView.addSubview(characterImageView)
totalView.addSubview(containerView)
addSubview(totalView)

NSLayoutConstraint.activate([
characterImageView.centerXAnchor.constraint(equalTo: centerXAnchor),
characterImageView.widthAnchor.constraint(equalToConstant: 131),
characterImageView.heightAnchor.constraint(equalToConstant: 131),
characterImageView.topAnchor.constraint(equalTo: topAnchor, constant: 16),

stackView.topAnchor.constraint(equalTo: containerView.topAnchor, constant: 12),
stackView.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: 16),
stackView.trailingAnchor.constraint(equalTo: containerView.trailingAnchor, constant: -16),
stackView.bottomAnchor.constraint(equalTo: containerView.bottomAnchor, constant: -12),

containerView.topAnchor.constraint(equalTo: characterImageView.bottomAnchor, constant: 12),
containerView.leadingAnchor.constraint(equalTo: totalView.leadingAnchor, constant: 16),
containerView.trailingAnchor.constraint(equalTo: totalView.trailingAnchor, constant: -16),
containerView.bottomAnchor.constraint(equalTo: totalView.bottomAnchor, constant: -16),

totalView.topAnchor.constraint(equalTo: topAnchor),
totalView.leadingAnchor.constraint(equalTo: leadingAnchor),
totalView.trailingAnchor.constraint(equalTo: trailingAnchor),
totalView.bottomAnchor.constraint(equalTo: bottomAnchor),
])
}

public func configure(mainEmotion: String, empathyMessage: String, stackViewColor: UIColor, image: UIImage) {
mainEmotionLabel.text = "오늘의 주 감정은, \(mainEmotion)"
empathyLabel.text = empathyMessage
containerView.backgroundColor = stackViewColor
characterImageView.image = image
}
}
Loading