Skip to content

Commit

Permalink
[Fix/#7] Presentation 형식에 맞게 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
kim-seonwoo committed Jun 7, 2024
1 parent abfbc4f commit 36e9761
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 173 deletions.
87 changes: 0 additions & 87 deletions Tving-Clone/Tving-Clone/Network/MovieService.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ extension LoginViewController {
nickNameViewController.modalPresentationStyle = .formSheet
self.present(nickNameViewController, animated: true)
}

@objc private func textFieldChanged() {
if let idText = loginView.idTextField.text,
let passwordText = loginView.passwordTextField.text {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ final class LiveCell: UICollectionViewCell {
}
}

func bindData(data: MainData, rank: Int) {
liveImageView.image = data.image
func bindData(data: ContentData, rank: Int) {
liveImageView.image = UIImage(named: data.image)
rankLabel.text = "\(rank)"
makerLabel.text = data.maker
subTitleLabel.text = data.subTitle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ final class MainCarouselCell: UICollectionViewCell {
}
}

func bindData(data: MainDataModel) {
func bindData(data: Content) {
pageViews.removeAll()
totalPage = data.data.count
pageControl.numberOfPages = totalPage
scrollView.contentSize = CGSize(width: (375 * totalPage), height: 498)
for i in 0..<totalPage {
let pageView = UIImageView().then {
$0.image = data.data[i].image
$0.image = UIImage(named: data.data[i].image)
$0.translatesAutoresizingMaskIntoConstraints = false
$0.clipsToBounds = true
$0.layer.cornerRadius = 3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ final class MainHeaderView: UICollectionReusableView {
}
}

func bindData(data: MainData) {
func bindData(data: ContentData) {
titleLabel.text = data.title
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ final class MoviePosterCell: UICollectionViewCell {
}
}

func bindData(data: MainData) {
movieImage.image = data.image
func bindData(data: ContentData) {
movieImage.image = UIImage(named: data.image)
movieTitle.text = data.title
codeNumber = data.ratio
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@ import Then

final class DetailViewController: UIViewController {

let detailView = DetailView()
let detailView: DetailView

init(detailView: DetailView) {
self.detailView = detailView
super.init(nibName: nil, bundle: nil)
}

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

override func viewDidLoad() {
super.viewDidLoad()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,25 @@ protocol MainContentViewControllerDelegate: AnyObject {

final class MainContentViewController: UIViewController {

private var mainData: [MainDataModel] = [] {
didSet {
rootView.mainCollectionView.reloadData()
}
}

private var detailData: DetailDataModel = DetailDataModel(title: "", openDt: "", directors: "", actors: "", audits: "", companys: "")

private var viewModel: MainContentViewModel!

weak var delegate: MainContentViewControllerDelegate?

private let rootView = MainContentView()


init(viewModel: MainContentViewModel) {
self.viewModel = viewModel
super.init(nibName: nil, bundle: nil)
}

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

override func viewWillAppear(_ animated: Bool) {
self.navigationController?.navigationBar.isHidden = true
requestMovieInfo()
viewModel.fetchContent()
}

override func viewDidLoad() {
Expand All @@ -38,6 +41,7 @@ final class MainContentViewController: UIViewController {
setHierarchy()
setLayout()
setTarget()
bindViewModel()
}

private func setHierarchy() {
Expand All @@ -55,10 +59,19 @@ final class MainContentViewController: UIViewController {
}
}

private func bindViewModel() {
viewModel.content.bind { [weak self] _ in
self?.rootView.mainCollectionView.reloadData()
}
}

@objc private func handleCellTap(code: String) {
requestDetailInfo(code: code) { [weak self] detailData in
let detailViewController = DetailViewController()
detailViewController.detailView.configure(with: detailData)
viewModel.fetchContentDetail(code: code)
viewModel.contentDetail.bind { [weak self] detailData in
guard let detailData = detailData else { return }
let detailView = DetailView()
detailView.configure(with: detailData)
let detailViewController = DetailViewController(detailView: detailView)
if let presentationController = detailViewController.presentationController as? UISheetPresentationController {
presentationController.detents = [.medium()]
}
Expand All @@ -73,15 +86,15 @@ extension MainContentViewController: UICollectionViewDelegate {}
extension MainContentViewController: UICollectionViewDataSource {

func numberOfSections(in collectionView: UICollectionView) -> Int {
return mainData.count
return viewModel.content.value.count
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
switch MainSectionType.allCases[section] {
case .MainCarousel:
return 1
default:
return mainData[section].data.count
return viewModel.content.value[section].data.count
}
}

Expand Down Expand Up @@ -114,13 +127,13 @@ extension MainContentViewController: UICollectionViewDataSource {
case .MainCarousel:
guard let cell = rootView.mainCollectionView.dequeueReusableCell(withReuseIdentifier: MainCarouselCell.identifier, for: indexPath) as? MainCarouselCell else { return UICollectionViewCell()}

let cellData = mainData[indexPath.section]
let cellData = viewModel.content.value[indexPath.section]
cell.bindData(data: cellData)
return cell
case .Live:
guard let cell = rootView.mainCollectionView.dequeueReusableCell(withReuseIdentifier: LiveCell.identifier, for: indexPath) as? LiveCell else { return UICollectionViewCell()}

let cellData = (mainData[indexPath.section].data[indexPath.row])
let cellData = (viewModel.content.value[indexPath.section].data[indexPath.row])
cell.bindData(data: cellData, rank: indexPath.row + 1)
return cell

Expand All @@ -132,55 +145,55 @@ extension MainContentViewController: UICollectionViewDataSource {
case .RecommendedContent, .Paramount, .MovieDictionary:
guard let cell = rootView.mainCollectionView.dequeueReusableCell(withReuseIdentifier: MoviePosterCell.identifier, for: indexPath) as? MoviePosterCell else { return UICollectionViewCell()}

let cellData = mainData[indexPath.section].data[indexPath.row]
let cellData = viewModel.content.value[indexPath.section].data[indexPath.row]
cell.bindData(data: cellData)
cell.delegate = self
return cell
}
}

private func requestMovieInfo() {
MovieService.shared.getMovieInfo { [weak self] response in
switch response {
case .success(let data):
if let data = data as? [MainDataModel] {
self?.mainData = data
}
case .requestErr:
print("요청 오류 입니다")
case .decodedErr:
print("디코딩 오류 입니다")
case .pathErr:
print("경로 오류 입니다")
case .serverErr:
print("서버 오류입니다")
case .networkFail:
print("네트워크 오류입니다")
}
}
}

private func requestDetailInfo(code: String, completion: @escaping (DetailDataModel) -> Void) {
MovieService.shared.getDetailInfo(code: code) { [weak self] response in
switch response {
case .success(let data):
if let detailData = data as? DetailDataModel {
// 비동기 작업이 완료된 후에 클로저 내부에서 completion 블록을 호출하여 다음 작업을 실행합니다.
completion(detailData)
}
case .requestErr:
print("요청 오류 입니다")
case .decodedErr:
print("디코딩 오류 입니다")
case .pathErr:
print("경로 오류 입니다")
case .serverErr:
print("서버 오류입니다")
case .networkFail:
print("네트워크 오류입니다")
}
}
}
//
// private func requestMovieInfo() {
// MovieService.shared.getMovieInfo { [weak self] response in
// switch response {
// case .success(let data):
// if let data = data as? [MainDataModel] {
// self?.mainData = data
// }
// case .requestErr:
// print("요청 오류 입니다")
// case .decodedErr:
// print("디코딩 오류 입니다")
// case .pathErr:
// print("경로 오류 입니다")
// case .serverErr:
// print("서버 오류입니다")
// case .networkFail:
// print("네트워크 오류입니다")
// }
// }
// }

// private func requestDetailInfo(code: String, completion: @escaping (DetailDataModel) -> Void) {
// MovieService.shared.getDetailInfo(code: code) { [weak self] response in
// switch response {
// case .success(let data):
// if let detailData = data as? DetailDataModel {
// // 비동기 작업이 완료된 후에 클로저 내부에서 completion 블록을 호출하여 다음 작업을 실행합니다.
// completion(detailData)
// }
// case .requestErr:
// print("요청 오류 입니다")
// case .decodedErr:
// print("디코딩 오류 입니다")
// case .pathErr:
// print("경로 오류 입니다")
// case .serverErr:
// print("서버 오류입니다")
// case .networkFail:
// print("네트워크 오류입니다")
// }
// }
// }
}

extension MainContentViewController: UIScrollViewDelegate {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import UIKit
import SnapKit

final class MainViewController: UIViewController {
private let mainvc = MainContentViewController()
private let mainContentViewModel: MainContentViewModel

private lazy var mainvc: MainContentViewController = {
return MainContentViewController(viewModel: mainContentViewModel)
}()
private let onAirVC = OnAirViewController()
private let tvProgramVC = TVProgramViewController()
private let movieVC = MovieViewController()
Expand Down Expand Up @@ -47,6 +51,16 @@ final class MainViewController: UIViewController {
}
}

init(mainContentViewModel: MainContentViewModel) {
self.mainContentViewModel = mainContentViewModel
super.init(nibName: nil, bundle: nil)
}

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


override func viewWillAppear(_ animated: Bool) {
self.navigationController?.navigationBar.isHidden = true
}
Expand Down
Loading

0 comments on commit 36e9761

Please sign in to comment.