From 729195465a3ecf54ee019e320f43fdf884f40c2a Mon Sep 17 00:00:00 2001 From: Choyoungjun Date: Thu, 16 May 2024 22:43:38 +0900 Subject: [PATCH] =?UTF-8?q?BURN=20::=20[#326]=20=EC=A4=91=EB=8B=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Application/SceneDelegate.swift | 6 +- .../SelfCareMyRoutineAddViewController.swift | 202 ++++++++++++++++++ ...elfCareMyRoutineDetailViewController.swift | 0 .../SelfCareMyRoutineEditViewController.swift | 0 .../SelfCareMyRoutineViewController.swift | 21 +- .../SelfCarePostureAddViewController.swift} | 10 +- .../{View => VC}/SelfCareViewController.swift | 0 .../Detail/MyRoutineDetailTableViewCell.swift | 0 .../Detail/MyRoutineDetailTitleView.swift | 0 .../View}/Edit/MyRoutineCountView.swift | 0 .../MyRoutineDateCollectionViewCell.swift | 0 .../Edit/MyRoutineDateTableViewCell.swift | 0 .../Edit/MyRoutineEditTableViewCell.swift | 0 .../View}/Main/MyRoutineTableViewCell.swift | 0 .../SelfCareMyRoutineAddViewModel.swift | 56 +++++ .../Sources/Supporter/SelfCareButton.swift | 2 +- 16 files changed, 271 insertions(+), 26 deletions(-) create mode 100644 Projects/Features/SelfCareFeature/Sources/RoutineScene/VC/SelfCareMyRoutineAddViewController.swift rename Projects/Features/SelfCareFeature/Sources/RoutineScene/{View => VC}/SelfCareMyRoutineDetailViewController.swift (100%) rename Projects/Features/SelfCareFeature/Sources/RoutineScene/{View => VC}/SelfCareMyRoutineEditViewController.swift (100%) rename Projects/Features/SelfCareFeature/Sources/RoutineScene/{View => VC}/SelfCareMyRoutineViewController.swift (86%) rename Projects/Features/SelfCareFeature/Sources/RoutineScene/{Test/TestViewController.swift => VC/SelfCarePostureAddViewController.swift} (73%) rename Projects/Features/SelfCareFeature/Sources/RoutineScene/{View => VC}/SelfCareViewController.swift (100%) rename Projects/Features/SelfCareFeature/Sources/{Supporter/MyRoutine => RoutineScene/View}/Detail/MyRoutineDetailTableViewCell.swift (100%) rename Projects/Features/SelfCareFeature/Sources/{Supporter/MyRoutine => RoutineScene/View}/Detail/MyRoutineDetailTitleView.swift (100%) rename Projects/Features/SelfCareFeature/Sources/{Supporter/MyRoutine => RoutineScene/View}/Edit/MyRoutineCountView.swift (100%) rename Projects/Features/SelfCareFeature/Sources/{Supporter/MyRoutine => RoutineScene/View}/Edit/MyRoutineDateCollectionViewCell.swift (100%) rename Projects/Features/SelfCareFeature/Sources/{Supporter/MyRoutine => RoutineScene/View}/Edit/MyRoutineDateTableViewCell.swift (100%) rename Projects/Features/SelfCareFeature/Sources/{Supporter/MyRoutine => RoutineScene/View}/Edit/MyRoutineEditTableViewCell.swift (100%) rename Projects/Features/SelfCareFeature/Sources/{Supporter/MyRoutine => RoutineScene/View}/Main/MyRoutineTableViewCell.swift (100%) create mode 100644 Projects/Features/SelfCareFeature/Sources/RoutineScene/ViewModel/SelfCareMyRoutineAddViewModel.swift diff --git a/Projects/Features/SelfCareFeature/Demo/Sources/Application/SceneDelegate.swift b/Projects/Features/SelfCareFeature/Demo/Sources/Application/SceneDelegate.swift index f182e3d6..49ca62b0 100644 --- a/Projects/Features/SelfCareFeature/Demo/Sources/Application/SceneDelegate.swift +++ b/Projects/Features/SelfCareFeature/Demo/Sources/Application/SceneDelegate.swift @@ -18,8 +18,10 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { window = UIWindow(windowScene: windowScene) let useCase = DefaultSelfCareUseCase(repository: SelfCareRepository(networkService: SelfCareService())) - let viewModel = SelfCareMyRoutineViewModel(useCase: useCase) - let viewController = SelfCareMyRoutineViewController(viewModel) + let viewModel = SelfCareHomeViewModel() + let viewController = SelfCareHomeViewController(viewModel) +// let viewModel = SelfCareMyRoutineViewModel(useCase: useCase) +// let viewController = SelfCareMyRoutineViewController(viewModel) window?.configure(withRootViewController: viewController) window?.makeKeyAndVisible() } diff --git a/Projects/Features/SelfCareFeature/Sources/RoutineScene/VC/SelfCareMyRoutineAddViewController.swift b/Projects/Features/SelfCareFeature/Sources/RoutineScene/VC/SelfCareMyRoutineAddViewController.swift new file mode 100644 index 00000000..6ec27647 --- /dev/null +++ b/Projects/Features/SelfCareFeature/Sources/RoutineScene/VC/SelfCareMyRoutineAddViewController.swift @@ -0,0 +1,202 @@ +import UIKit + +import RxFlow +import RxCocoa +import RxSwift + +import SnapKit +import Then + +import Core +import Data +import DSKit + +import Domain +import MGLogger +import MGNetworks + +import SelfCareFeatureInterface + +public class SelfCareMyRoutineAddViewController: BaseViewController, Stepper, UIGestureRecognizerDelegate { + + private var myRoutineEditData: SelfCareMyRoutineEditModel = + SelfCareMyRoutineEditModel( + textFieldData: + MyRoutineEditTextFieldModel( + textFieldTitle: "", + textFieldText: "", + textFieldPlaceholder: "" + ), date: [], + exerciseData: [] + ) + + private var naviBar = RoutineNavigationBarBar() + + private var headerView = UIView() + + private var titleTextView = MGTitleTextFieldView(titleText: "제목", textLimit: 3, placeholder: "제목을 입력해주세요") + + private var textFieldData: MyRoutineEditTextFieldModel = MyRoutineEditTextFieldModel( + textFieldTitle: "", + textFieldText: "", + textFieldPlaceholder: "" + ) + private var myRoutineDetailTableView = UITableView().then { + $0.showsVerticalScrollIndicator = false + $0.showsHorizontalScrollIndicator = false + $0.backgroundColor = .white + $0.separatorStyle = .none + $0.register( + MyRoutineEditTableViewCell.self, + forCellReuseIdentifier: MyRoutineEditTableViewCell.identifier + ) + $0.register( + MyRoutineDateTableViewCell.self, + forCellReuseIdentifier: MyRoutineDateTableViewCell.identifier + ) + } + + private let underLine = MGLine(lineHeight: 1.0) + private let underBackView = UIView() + private let buttonSpaceView = UIView() + + private var plusPostureButton = SelfCareButton(type: .posturePlus) + private var editButton = SelfCareButton(type: .complete) + + override public func viewDidLoad() { + super.viewDidLoad() + + view.backgroundColor = .white + } + + public override func configureNavigationBar() { + super.configureNavigationBar() + navigationController?.isNavigationBarHidden = true + self.view.frame = self.view.frame.inset(by: UIEdgeInsets(top: .zero, left: 0, bottom: .zero, right: 0)) + } + + public override func attribute() { + super.attribute() + + naviBar.setLeftText(text: "루틴 추가") + + myRoutineDetailTableView.delegate = self + myRoutineDetailTableView.dataSource = self + navigationController?.interactivePopGestureRecognizer?.delegate = self + } + + public override func layout() { + super.layout() + + headerView = UIView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: 132.0)) + view.addSubviews([naviBar, myRoutineDetailTableView, underBackView]) + + headerView.addSubview(titleTextView) + + naviBar.snp.makeConstraints { + $0.leading.top.trailing.equalTo(view.safeAreaLayoutGuide) + } + + titleTextView.snp.makeConstraints { + $0.top.equalToSuperview().offset(24.0) + $0.leading.trailing.equalToSuperview().inset(20.0) + $0.bottom.equalToSuperview().inset(32.0) + } + + myRoutineDetailTableView.tableHeaderView = headerView + myRoutineDetailTableView.snp.makeConstraints { + $0.top.equalToSuperview().offset(105.0) + $0.leading.trailing.equalToSuperview() + $0.height.equalTo(695.0) + } + + underBackView.snp.makeConstraints { + $0.bottom.equalTo(view.safeAreaLayoutGuide) + $0.leading.trailing.equalToSuperview() + $0.top.equalTo(myRoutineDetailTableView.snp.bottom) + } + + underBackView.addSubviews([underLine, buttonSpaceView, plusPostureButton, editButton]) + + underLine.snp.makeConstraints { + $0.trailing.leading.equalToSuperview() + $0.top.equalToSuperview() + } + + buttonSpaceView.snp.makeConstraints { + $0.top.bottom.equalToSuperview() + $0.width.equalTo(8.0) + $0.centerX.equalToSuperview() + } + + plusPostureButton.snp.makeConstraints { + $0.top.bottom.equalToSuperview().inset(20.0) + $0.leading.equalToSuperview().offset(20.0) + $0.trailing.equalTo(buttonSpaceView.snp.leading) + } + + editButton.snp.makeConstraints { + $0.top.bottom.equalToSuperview().inset(20.0) + $0.trailing.equalToSuperview().offset(-20.0) + $0.leading.equalTo(buttonSpaceView.snp.trailing) + } + } + + public override func bindActions() { + self.naviBar.leftButtonTap + .bind(onNext: { [weak self] in + self?.navigationController?.popViewController(animated: true) + }).disposed(by: disposeBag) + } +// public override func bindViewModel() { +// let useCase = DefaultSelfCareUseCase(repository: SelfCareRepository(networkService: SelfCareService())) +// +// viewModel = SelfCareMyRoutineEditViewModel(useCase: useCase) +// +// let input = SelfCareMyRoutineEditViewModel.Input( +// getMyRoutineEditData: Observable.just(()).asDriver(onErrorDriveWith: .never())) +// +// let output = viewModel.transform(input, action: { output in +// output.myRoutineEditData +// .subscribe(onNext: { myRoutineEditData in +// MGLogger.debug("myRoutineEditData: \(myRoutineEditData)") +// self.myRoutineEditData = myRoutineEditData +// self.textFieldData = myRoutineEditData.textFieldData +// }).disposed(by: disposeBag) +// }) +// } +} + +extension SelfCareMyRoutineAddViewController: UITableViewDelegate { + public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { + switch indexPath.row { + case 0: + return 104 + default: + return 216 + } + } +} + +extension SelfCareMyRoutineAddViewController: UITableViewDataSource { + public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + myRoutineEditData.exerciseData.count + 1 + } + + public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + switch indexPath.row { + case 0: + let cell = tableView.dequeueReusableCell(withIdentifier: MyRoutineDateTableViewCell.identifier, for: indexPath) as? MyRoutineDateTableViewCell + cell?.selectionStyle = .none + return cell ?? UITableViewCell() + default: + let cell = tableView.dequeueReusableCell( + withIdentifier: MyRoutineEditTableViewCell.identifier, + for: indexPath) as? MyRoutineEditTableViewCell + let editData = myRoutineEditData.exerciseData[indexPath.row - 1] + cell?.setup(with: editData) + cell?.selectionStyle = .none + return cell ?? UITableViewCell() + } + } +} diff --git a/Projects/Features/SelfCareFeature/Sources/RoutineScene/View/SelfCareMyRoutineDetailViewController.swift b/Projects/Features/SelfCareFeature/Sources/RoutineScene/VC/SelfCareMyRoutineDetailViewController.swift similarity index 100% rename from Projects/Features/SelfCareFeature/Sources/RoutineScene/View/SelfCareMyRoutineDetailViewController.swift rename to Projects/Features/SelfCareFeature/Sources/RoutineScene/VC/SelfCareMyRoutineDetailViewController.swift diff --git a/Projects/Features/SelfCareFeature/Sources/RoutineScene/View/SelfCareMyRoutineEditViewController.swift b/Projects/Features/SelfCareFeature/Sources/RoutineScene/VC/SelfCareMyRoutineEditViewController.swift similarity index 100% rename from Projects/Features/SelfCareFeature/Sources/RoutineScene/View/SelfCareMyRoutineEditViewController.swift rename to Projects/Features/SelfCareFeature/Sources/RoutineScene/VC/SelfCareMyRoutineEditViewController.swift diff --git a/Projects/Features/SelfCareFeature/Sources/RoutineScene/View/SelfCareMyRoutineViewController.swift b/Projects/Features/SelfCareFeature/Sources/RoutineScene/VC/SelfCareMyRoutineViewController.swift similarity index 86% rename from Projects/Features/SelfCareFeature/Sources/RoutineScene/View/SelfCareMyRoutineViewController.swift rename to Projects/Features/SelfCareFeature/Sources/RoutineScene/VC/SelfCareMyRoutineViewController.swift index 0f923909..a1186e0f 100644 --- a/Projects/Features/SelfCareFeature/Sources/RoutineScene/View/SelfCareMyRoutineViewController.swift +++ b/Projects/Features/SelfCareFeature/Sources/RoutineScene/VC/SelfCareMyRoutineViewController.swift @@ -126,8 +126,8 @@ public class SelfCareMyRoutineViewController: BaseViewController + } + + public struct Output { + let myRoutineEditData: Observable + } + + private let myRoutineEditDataSubject = PublishSubject() + + public init(useCase: SelfCareUseCase) { + self.useCase = useCase + } + + public func transform(_ input: Input, action: (Output) -> Void) -> Output { + let output = Output( + myRoutineEditData: myRoutineEditDataSubject.asObservable() + ) + + action(output) + + self.bindOutput(output: output) + + input.getMyRoutineEditData + .drive(onNext: { [weak self] _ in + self?.useCase.getMyRoutineEditData() + }).disposed(by: disposeBag) + + return output + } + + private func bindOutput(output: Output) { + useCase.myRoutineEditData + .subscribe(onNext: { myRoutineEditData in + self.myRoutineEditDataSubject.onNext(myRoutineEditData) + }).disposed(by: disposeBag) + } +} diff --git a/Projects/Features/SelfCareFeature/Sources/Supporter/SelfCareButton.swift b/Projects/Features/SelfCareFeature/Sources/Supporter/SelfCareButton.swift index 150919e1..101cdfd6 100644 --- a/Projects/Features/SelfCareFeature/Sources/Supporter/SelfCareButton.swift +++ b/Projects/Features/SelfCareFeature/Sources/Supporter/SelfCareButton.swift @@ -13,7 +13,7 @@ public class SelfCareButton: BaseButton { private var buttonImage = UIImageView() private var buttonLabel = MGLabel(font: UIFont.Pretendard.labelLarge, - isCenter: false, + isCenter: true, numberOfLineCount: 1 )