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

자기관리 메인 페이지 구현 #215

Merged
merged 13 commits into from
Feb 22, 2024
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import UIKit

public struct SelfCareIntroductModel {
public var image: UIImage
public var mainText: String
public var subText: String

public init(image: UIImage, mainText: String, subText: String) {
self.image = image
self.mainText = mainText
self.subText = subText
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import UIKit

public struct SelfCareMenuModel {
public var menuImage: UIImage
public var menuName: String

public init(menuImage: UIImage, menuName: String) {
self.menuImage = menuImage
self.menuName = menuName
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import UIKit

public struct SelfCareProfileModel {
public var userImage: UIImage
public var userName: String
public var userTimer: String
public var userBage: UIImage

public init(userImage: UIImage, userName: String, userTimer: Int, userBage: UIImage) {
self.userImage = userImage
self.userName = userName
self.userTimer = "\(userTimer)시간"
self.userBage = userBage
}
}
11 changes: 7 additions & 4 deletions Projects/Features/HomeFeature/Demo/Sources/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: windowScene)
window?.rootViewController = MetronomeViewController(
viewModel: MetronomeViewModel(metronome: Metronome.sharedInstance)
)
// window?.configure(withRootViewController: TimerViewController(TimerViewModel()))
// window?.rootViewController = MetronomeViewController(
// viewModel: MetronomeViewModel(metronome: Metronome.sharedInstance)
// )
let useCase = DefaultHomeUseCase(repository: HomeRepository(networkService: HomeService()))
let viewModel = HomeViewModel(useCase: useCase)
let viewController = HomeViewController(viewModel)
window?.configure(withRootViewController: viewController)
window?.makeKeyAndVisible()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
// let viewModel = SelfCareMyRoutineDetailViewModel(useCase: useCase)
// let viewController = SelfCareMyRoutineDetailViewController(viewModel)
// window?.configure(withRootViewController: viewController)
window?.configure(withRootViewController: CameraViewController(CameraViewModel()))
window?.configure(withRootViewController: SelfCareHomeViewController(SelfCareHomeViewModel()))
window?.makeKeyAndVisible()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final public class AlbumViewController: BaseViewController<Any> {
view.contentInset = .zero
view.backgroundColor = .clear
view.clipsToBounds = true
view.register(PhotoCell.self, forCellWithReuseIdentifier: PhotoCell.id)
view.register(AlbumCell.self, forCellWithReuseIdentifier: AlbumCell.id)
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
Expand Down Expand Up @@ -118,9 +118,9 @@ extension AlbumViewController: UICollectionViewDataSource {
cellForItemAt indexPath: IndexPath
) -> UICollectionViewCell {
guard
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: PhotoCell.id,
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: AlbumCell.id,
for: indexPath
) as? PhotoCell
) as? AlbumCell
else { fatalError() }

PhotoService.shared.fetchImage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import UIKit
import Then
import SnapKit

final public class PhotoCell: UICollectionViewCell {
final public class AlbumCell: UICollectionViewCell {
static public let id = "PhotoCell"

private let imageView = UIImageView().then {
Expand Down Expand Up @@ -31,7 +31,7 @@ final public class PhotoCell: UICollectionViewCell {
}
}

private extension PhotoCell {
private extension AlbumCell {
func layout() {
contentView.addSubview(imageView)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
import UIKit
import Data

import MGLogger
import MGNetworks

import RxSwift
import RxCocoa
import RxFlow

import Then
import SnapKit

import Core
import DSKit

import Domain

enum SelfCareCell {
case introductMessage
case profile
case selfCare
}

public class SelfCareHomeViewController: BaseViewController<SelfCareHomeViewModel> {

private var cellList: [UITableViewCell] = []
private var cells: [SelfCareCell] = []

var introducts = SelfCareIntroductModel(image: DSKitAsset.Assets.selfCareMainImage.image,
mainText: "자기관리",
subText: "나만의 루틴과 목표를 설정하여\n자기관리에 도전해보세요.")

var profiles = SelfCareProfileModel(userImage: DSKitAsset.Assets.basicProfile.image,
userName: "박준하",
userTimer: 123,
userBage: DSKitAsset.Assets.bage1.image)

var menus = [SelfCareMenuModel(menuImage: DSKitAsset.Assets.selfCareMenuMyRoutine.image, menuName: "내루틴"),
SelfCareMenuModel(menuImage: DSKitAsset.Assets.selfCareGoul.image, menuName: "목표"),
SelfCareMenuModel(menuImage: DSKitAsset.Assets.selfCareFood.image, menuName: "식단"),
SelfCareMenuModel(menuImage: DSKitAsset.Assets.selfCareOunwan.image, menuName: "오운완")]

private lazy var tableView: UITableView = UITableView().then {
$0.delegate = self
$0.dataSource = self
$0.backgroundColor = DSKitAsset.Colors.gray25.color
$0.separatorStyle = .none
$0.showsVerticalScrollIndicator = false
$0.register(SelfCareIntroductTableViewCell.self,
forCellReuseIdentifier: SelfCareIntroductTableViewCell.identifier)
$0.register(SelfCareProfileTableViewCell.self, forCellReuseIdentifier: SelfCareProfileTableViewCell.identifier
)
$0.register(SelfCareMenuTableViewCell.self, forCellReuseIdentifier: SelfCareMenuTableViewCell.identifier
)
}

public override func configureNavigationBar() {
super.configureNavigationBar()

navigationController?.isNavigationBarHidden = true
}

public override func attribute() {
super.attribute()

view.backgroundColor = DSKitAsset.Colors.gray25.color
addCells()
}

public override func layout() {
view.addSubviews([tableView])

tableView.snp.makeConstraints {
$0.top.equalTo(view.safeAreaLayoutGuide)
$0.leading.trailing.equalToSuperview()
$0.bottom.equalTo(view.safeAreaLayoutGuide.snp.bottom)
}
}

private func addCells() {
cells.append(.introductMessage)
cells.append(.profile)
cells.append(.selfCare)
}

func menuheightForCell(with menus: [SelfCareMenuModel]) -> CGFloat {
let cellHeight: CGFloat = 64.0
return max(CGFloat(menus.count) * cellHeight, cellHeight) + 92
}

}

extension SelfCareHomeViewController: UITableViewDelegate {
public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
switch cells[indexPath.item] {
case .introductMessage:
return 232
case .profile:
return 80
case .selfCare:
return menuheightForCell(with: menus)
}
}

public func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
switch cells[indexPath.item] {
case .introductMessage, .profile, .selfCare:
cell.separatorInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
}
}
}

extension SelfCareHomeViewController: UITableViewDataSource {
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return cells.count
}

public func numberOfSections(in tableView: UITableView) -> Int {
return 1
}

public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch cells[indexPath.item] {
case .introductMessage:
guard let cell = tableView.dequeueReusableCell(
withIdentifier: SelfCareIntroductTableViewCell.identifier
) as? SelfCareIntroductTableViewCell else {
return UITableViewCell()
}
cell.configure(with: introducts)

return cell
case .profile:
guard let cell = tableView.dequeueReusableCell(
withIdentifier: SelfCareProfileTableViewCell.identifier
) as? SelfCareProfileTableViewCell else {
return UITableViewCell()
}
cell.configure(with: profiles)

return cell
case .selfCare:
guard let cell = tableView.dequeueReusableCell(
withIdentifier: SelfCareMenuTableViewCell.identifier
) as? SelfCareMenuTableViewCell else {
return UITableViewCell()
}
cell.menus = menus

return cell
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import UIKit

import RxSwift
import RxCocoa

import Then
import SnapKit

import Core
import DSKit

import Domain

public class SelfCareIntroductTableViewCell: BaseTableViewCell {

static public var identifier: String = "SelfCareIntroductTableViewCell"

private let titleImageView = MGProfileView(
profileImage: MGProfileImage(type: .custom,
customImage: DSKitAsset.Assets.selfCareMainImage.image),
profileType: .smallProfile
)

private let mainTitle = UILabel().then {
$0.font = UIFont.Pretendard.titleLarge
}

private let subTitle = UILabel().then {
$0.font = UIFont.Pretendard.bodyMedium
$0.textColor = DSKitAsset.Colors.gray600.color
$0.numberOfLines = 2
}

public func configure(with message: SelfCareIntroductModel) {
titleImageView.configureImage(with: MGProfileImage(type: .custom,
customImage: message.image))
mainTitle.text = "\"\(message.mainText)\""
subTitle.text = "\(message.subText)"
}

public override func attribute() {
super.attribute()

backgroundColor = .white
setupRxBindings()
}

public override func layout() {
super.layout()

addSubviews([titleImageView, mainTitle, subTitle])
titleImageView.snp.makeConstraints {
$0.top.equalToSuperview().offset(40.0)
$0.leading.equalToSuperview().inset(20.0)
}

mainTitle.snp.makeConstraints {
$0.top.equalTo(titleImageView.snp.bottom).offset(12.0)
$0.leading.equalTo(titleImageView.snp.leading)
}

subTitle.snp.makeConstraints {
$0.top.equalTo(mainTitle.snp.bottom).offset(12.0)
$0.leading.equalTo(mainTitle.snp.leading)
}
}

private func setupRxBindings() {
rx.deallocated
.subscribe(onNext: { [weak self] in
self?.disposeBag = DisposeBag()
})
.disposed(by: disposeBag)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import UIKit

import RxSwift
import RxCocoa

import Then
import SnapKit

import Core
import DSKit

import Domain

public class SelfCareMenuCollectionCell: UICollectionViewCell {

static let identifier: String = "SelfCareMenuCollectionCell"

private var menuImageView = UIImageView().then {
$0.layer.cornerRadius = 8.0
}

private var menuLabel = UILabel().then {
$0.textColor = .black
$0.textAlignment = .center
}
// 보류
// private var arrowImageView = UIImageView().then {
// $0.image = UIImage(systemName: "chevron.right")
// $0.tintColor = .gray
// }
public override init(frame: CGRect) {
super.init(frame: frame)

contentView.addSubviews([menuImageView,
menuLabel])

menuImageView.snp.makeConstraints {
$0.centerY.equalToSuperview()
$0.leading.equalToSuperview().offset(20.0)
$0.height.width.equalTo(40.0)
}

menuLabel.snp.makeConstraints {
$0.leading.equalTo(menuImageView.snp.trailing).offset(16.0)
$0.centerY.equalTo(menuImageView.snp.centerY)
}
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

public func configure(with menus: SelfCareMenuModel) {
menuImageView.image = menus.menuImage
menuLabel.text = menus.menuName
}
}
Loading