Skip to content

Commit

Permalink
Merge pull request #337 from MaeumGaGym/feature/#334-poseDetailRefact…
Browse files Browse the repository at this point in the history
…oring

REFACT :: [#334] 자세 - 디테일 리펙토링
  • Loading branch information
Eunho0922 authored Jun 7, 2024
2 parents 9658fed + 831e5eb commit 5021199
Show file tree
Hide file tree
Showing 7 changed files with 269 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,30 @@ public struct PostureDetailModel {
public var detailImage: UIImage
public var titleTextData: PostureDetailTitleTextModel
public var exerciseKindData: [PostureDetailExerciseKindModel]
public var exercisePartData: PostureDetailInfoModel
public var exerciseStartData: PostureDetailInfoModel
public var exerciseWayData: PostureDetailInfoModel
public var exerciseBreathData: PostureDetailInfoModel
public var exerciseCautionData: PostureDetailInfoModel
public var relatedPickleData: PostureDetailPickleModel

public init(detailImage: UIImage,
titleTextData: PostureDetailTitleTextModel,
exerciseKindData: [PostureDetailExerciseKindModel],
exercisePartData: PostureDetailInfoModel,
exerciseStartData: PostureDetailInfoModel,
exerciseWayData: PostureDetailInfoModel,
exerciseBreathData: PostureDetailInfoModel,
exerciseCautionData: PostureDetailInfoModel,
relatedPickleData: PostureDetailPickleModel)
{
self.detailImage = detailImage
self.titleTextData = titleTextData
self.exerciseKindData = exerciseKindData
self.exercisePartData = exercisePartData
self.exerciseStartData = exerciseStartData
self.exerciseWayData = exerciseWayData
self.exerciseBreathData = exerciseBreathData
self.exerciseCautionData = exerciseCautionData
self.relatedPickleData = relatedPickleData
}
Expand Down
22 changes: 14 additions & 8 deletions Projects/Features/PostureFeature/Demo/Sources/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,20 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {

window = UIWindow(frame: scene.coordinateSpace.bounds)
window?.windowScene = scene

mainFlow = PostureFlow()

coordinator.coordinate(flow: mainFlow, with: OneStepper(withSingleStep: MGStep.postureMainIsRequired))
Flows.use(mainFlow, when: .created) { root in
self.window?.rootViewController = root
self.window?.makeKey()
}

let useCase = DefaultPostureUseCase(repository: PostureRepository(networkService: PostureService()))
let viewModel = PostureDetailViewModel(useCase: useCase)
let viewController = PostureDetailViewController(viewModel)

window?.rootViewController = viewController

// mainFlow = PostureFlow()
//
// coordinator.coordinate(flow: mainFlow, with: OneStepper(withSingleStep: MGStep.postureDetailIsRequired(withDetailId: 0)))
// Flows.use(mainFlow, when: .created) { root in
// self.window?.rootViewController = root
// self.window?.makeKey()
// }
window?.makeKeyAndVisible()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,34 @@ public class PostureDetailViewController: BaseViewController<PostureDetailViewMo
forCellReuseIdentifier: PostureDetailTitleTableViewCell.identifier)
$0.register(PostureDetailTagTableViewCell.self,
forCellReuseIdentifier: PostureDetailTagTableViewCell.identifier)
$0.register(PostureDetailInfoTableViewCell.self,
forCellReuseIdentifier: PostureDetailInfoTableViewCell.identifier)
$0.register(PostureDetailInfoTableViewCell.self,
forCellReuseIdentifier: PostureDetailInfoTableViewCell.identifier)

$0.register(PostureDetailTableViewCell.self,
forCellReuseIdentifier: PostureDetailTableViewCell.identifier)
$0.register(PostureDetailTableViewCell.self,
forCellReuseIdentifier: PostureDetailTableViewCell.identifier)
$0.register(PostureDetailTableViewCell.self,
forCellReuseIdentifier: PostureDetailTableViewCell.identifier)
$0.register(PostureDetailTableViewCell.self,
forCellReuseIdentifier: PostureDetailTableViewCell.identifier)
$0.register(PostureDetailTableViewCell.self,
forCellReuseIdentifier: PostureDetailTableViewCell.identifier)

$0.register(PostureDetailPickeTableViewCell.self,
forCellReuseIdentifier: PostureDetailPickeTableViewCell.identifier)
$0.showsVerticalScrollIndicator = false
$0.showsHorizontalScrollIndicator = false
$0.backgroundColor = .white
$0.separatorStyle = .none
}

private var postureDetailModel: PostureDetailModel = PostureDetailModel(
detailImage: UIImage(),
titleTextData: PostureDetailTitleTextModel(englishName: "", koreanName: ""),
exerciseKindData: [PostureDetailExerciseKindModel](),
exerciseKindData: [],
exercisePartData: PostureDetailInfoModel(titleText: "", infoText: []),
exerciseStartData: PostureDetailInfoModel(titleText: "", infoText: []),
exerciseWayData: PostureDetailInfoModel(titleText: "", infoText: []),
exerciseBreathData: PostureDetailInfoModel(titleText: "", infoText: []),
exerciseCautionData: PostureDetailInfoModel(titleText: "", infoText: []),
relatedPickleData: PostureDetailPickleModel(titleText: "", pickleImage: [])
)
Expand All @@ -54,10 +66,10 @@ public class PostureDetailViewController: BaseViewController<PostureDetailViewMo
public override func layout() {
super.layout()

view.addSubview(postureDetailTableView)

view.addSubviews([postureDetailTableView])
postureDetailTableView.snp.makeConstraints {
$0.top.equalToSuperview().offset(105.0)
$0.top.equalTo(view.safeAreaLayoutGuide)
$0.leading.trailing.equalToSuperview()
$0.bottom.equalToSuperview()
}
Expand All @@ -66,9 +78,6 @@ public class PostureDetailViewController: BaseViewController<PostureDetailViewMo
public override func bindViewModel() {
super.bindViewModel()

// let useCase = DefaultPostureUseCase(repository: PostureRepository(networkService: PostureService()))
// viewModel = PostureDetailViewModel(useCase: useCase)

let input = PostureDetailViewModel.Input(
getDetailData: Observable.just(()).asDriver(onErrorDriveWith: .never())
)
Expand All @@ -82,6 +91,26 @@ public class PostureDetailViewController: BaseViewController<PostureDetailViewMo
}
)
}

private func calculateCellHeight(model: [PostureDetailInfoTextModel]) -> CGFloat {
let model = model
var lineCount = 0
var modelCount = model.count
var middleDistance = 12

for data in model {
lineCount += data.text.components(separatedBy: "\n").count - 1
}

if modelCount == 1 {
modelCount = 0
lineCount += 1
} else {
middleDistance = 8
}

return CGFloat(80 + (modelCount * 48) + (lineCount * 20) + middleDistance)
}
}

extension PostureDetailViewController: UITableViewDelegate {
Expand All @@ -97,26 +126,19 @@ extension PostureDetailViewController: UITableViewDelegate {
case 2:
return 60
case 3:
let model = postureDetailModel.exerciseWayData.infoText
var lineCount = 0
for data in model {
lineCount += data.text.components(separatedBy: "\n").count - 1
}
print("\(lineCount)")
print("\(model.count)")
print(92 + (model.count * 48) + (lineCount * 20))
return CGFloat(92 + (model.count * 48) + (lineCount * 20))
return calculateCellHeight(model: postureDetailModel.exercisePartData.infoText)
case 4:
let model = postureDetailModel.exerciseCautionData.infoText
var lineCount = 0
for data in model {
lineCount += data.text.components(separatedBy: "\n").count - 1
}
return CGFloat(92 + (model.count * 48) + (lineCount * 20))
return calculateCellHeight(model: postureDetailModel.exerciseStartData.infoText)
case 5:
return calculateCellHeight(model: postureDetailModel.exerciseWayData.infoText)
case 6:
return calculateCellHeight(model: postureDetailModel.exerciseBreathData.infoText)
case 7:
return calculateCellHeight(model: postureDetailModel.exerciseCautionData.infoText)
case 8:
return 360
default:
return UITableView.automaticDimension
return 0
}
}
}
Expand All @@ -126,7 +148,7 @@ extension PostureDetailViewController: UITableViewDataSource {
_ tableView: UITableView,
numberOfRowsInSection section: Int
) -> Int {
return 6
return 9
}

public func tableView(
Expand Down Expand Up @@ -160,21 +182,45 @@ extension PostureDetailViewController: UITableViewDataSource {
return cell ?? UITableViewCell()
case 3:
let cell = postureDetailTableView.dequeueReusableCell(
withIdentifier: PostureDetailInfoTableViewCell.identifier,
for: indexPath) as? PostureDetailInfoTableViewCell
let model = postureDetailModel.exerciseWayData
withIdentifier: PostureDetailTableViewCell.identifier,
for: indexPath) as? PostureDetailTableViewCell
let model = postureDetailModel.exercisePartData
cell?.setup(with: model)
cell?.selectionStyle = .none
return cell ?? UITableViewCell()
case 4:
let cell = postureDetailTableView.dequeueReusableCell(
withIdentifier: PostureDetailInfoTableViewCell.identifier,
for: indexPath) as? PostureDetailInfoTableViewCell
let model = postureDetailModel.exerciseCautionData
withIdentifier: PostureDetailTableViewCell.identifier,
for: indexPath) as? PostureDetailTableViewCell
let model = postureDetailModel.exerciseStartData
cell?.setup(with: model)
cell?.selectionStyle = .none
return cell ?? UITableViewCell()
case 5:
let cell = postureDetailTableView.dequeueReusableCell(
withIdentifier: PostureDetailTableViewCell.identifier,
for: indexPath) as? PostureDetailTableViewCell
let model = postureDetailModel.exerciseWayData
cell?.setup(with: model)
cell?.selectionStyle = .none
return cell ?? UITableViewCell()
case 6:
let cell = postureDetailTableView.dequeueReusableCell(
withIdentifier: PostureDetailTableViewCell.identifier,
for: indexPath) as? PostureDetailTableViewCell
let model = postureDetailModel.exerciseBreathData
cell?.setup(with: model)
cell?.selectionStyle = .none
return cell ?? UITableViewCell()
case 7:
let cell = postureDetailTableView.dequeueReusableCell(
withIdentifier: PostureDetailTableViewCell.identifier,
for: indexPath) as? PostureDetailTableViewCell
let model = postureDetailModel.exerciseCautionData
cell?.setup(with: model)
cell?.selectionStyle = .none
return cell ?? UITableViewCell()
case 8:
let cell = postureDetailTableView.dequeueReusableCell(
withIdentifier: PostureDetailPickeTableViewCell.identifier,
for: indexPath) as? PostureDetailPickeTableViewCell
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Core
import Domain
import MGLogger

public class PostureDetailViewModel: BaseViewModel {
public class PostureDetailViewModel: PostureViewModelType {

public typealias ViewModel = PostureDetailViewModel

Expand Down
Loading

0 comments on commit 5021199

Please sign in to comment.