Skip to content

Commit 0cb35e2

Browse files
authored
Merge pull request #9 from engingulek/feature/create-collection-view-and-cells
created collection view and cell
2 parents aa01c55 + 7aa7e7d commit 0cb35e2

5 files changed

Lines changed: 225 additions & 25 deletions

File tree

ICTMDBHomeModule/Enums.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
//
77

88
enum CellItemType {
9-
case popular
10-
case airing
9+
case popular(String)
10+
case airing(String)
1111
case none
1212
}
1313

1414
//MARK: SectionType
1515
enum SectionType: Int, CaseIterable {
1616
case popular
17-
case onAir
17+
case airingToday
1818
}

ICTMDBHomeModule/HomePresenter.swift

Lines changed: 67 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,47 @@ extension HomePresenter : ViewToPresenterHomeProtocol {
3434

3535
func viewDidLoad() {
3636
view?.setBackColorAble(color: "backColor")
37-
interactor.loadPopularMovies()
38-
interactor.loadAiringMovies()
3937
}
4038
}
4139

4240
//MARK: CollectionViewSources
4341
extension HomePresenter {
4442
func layout(for sectionIndex: Int) -> LayoutSource {
45-
43+
guard let sectionType = SectionType(rawValue: sectionIndex) else {
44+
return LayoutSourceTeamplate.none.template
45+
}
46+
switch sectionType {
47+
case .popular:
48+
return LayoutSourceTeamplate.horizontalSingleRow.template
49+
case .airingToday:
50+
return LayoutSourceTeamplate.verticalTwoPerRow.template
51+
}
4652
}
4753

4854
func numberOfRowsInSection(in section: Int) -> Int {
49-
55+
guard let sectionType = SectionType(rawValue: section) else {return 0}
56+
switch sectionType {
57+
case .popular:
58+
return 5
59+
case .airingToday:
60+
return 3
61+
}
5062
}
5163

5264
func numberOfSections() -> Int {
53-
65+
SectionType.allCases.count
5466
}
5567

5668
func cellForItem(section: Int,item:Int) -> CellItemType {
57-
69+
guard let sectionType = SectionType(rawValue: section) else { return .none }
70+
switch sectionType {
71+
case .popular:
72+
73+
return .popular("popular")
74+
case .airingToday:
75+
76+
return .airing("airing")
77+
}
5878

5979

6080
}
@@ -67,19 +87,57 @@ extension HomePresenter {
6787
title: String, sizeType:SectionSizeType,
6888
buttonType: [TitleForSectionButtonType]?) {
6989

70-
90+
guard let sectionType = SectionType(rawValue: section)
91+
else { return (title:"",sizeType:.small,buttonType:[]) }
92+
93+
var item : (
94+
title: String,
95+
sizeType: SectionSizeType,
96+
buttonType: [TitleForSectionButtonType]?)
97+
98+
switch sectionType {
99+
case .popular:
100+
item = (title:LocalizableUI.popular.localized,sizeType:.large,buttonType:[.allList])
101+
case .airingToday:
102+
item = (title:LocalizableUI.airingToday.localized,sizeType:.small,buttonType:[.allList])
103+
}
104+
return item
71105
}
72106

73107
func onTappedTitleButton(buttonType: TitleForSectionButtonType, section: Int) {
108+
guard let sectionType = SectionType(rawValue: section) else { return }
74109

110+
switch sectionType {
111+
case .popular:
112+
switch buttonType {
113+
case .allList:
114+
router.toAllListPage(view: view, type: .popular)
115+
print("Popular All List")
116+
default:
117+
break
118+
}
119+
120+
case .airingToday:
121+
switch buttonType {
122+
case .allList:
123+
router.toAllListPage(view: view, type: .airingToday)
124+
default:
125+
break
126+
}
127+
}
75128
}
76129

77130
func sectionType(at section: Int) -> SectionType {
78-
131+
return SectionType(rawValue: section) ?? .popular
79132
}
80133

81134
func cellIdentifier(at section: Int) -> String {
82-
135+
guard let section = SectionType(rawValue: section) else {return ""}
136+
switch section {
137+
case .popular: return PopularCell.identifier
138+
case .airingToday: return AiringTodayCell.identifier
139+
140+
}
83141
}
84142
}
85143

ICTMDBHomeModule/HomeViewController.swift

Lines changed: 72 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,93 @@ import UIKit
1010
import GenericCollectionViewKit
1111
import ICTMDBViewKit
1212
import SnapKit
13-
14-
15-
final class HomeViewController : UIViewController {
16-
var presenter: (any ViewToPresenterHomeProtocol)?
13+
//MARK: HomeViewController
14+
final class HomeViewController: UIViewController {
1715

16+
var presenter: (any ViewToPresenterHomeProtocol)?
17+
private var collectionView: UICollectionView!
18+
private let acitvityIndicator = UIActivityIndicatorView.baseActivityIndicator()
19+
private var dataSource: GenericCollectionDataSource<HomePresenter>?
20+
private var delegateSource: GenericCollectionDelegate<HomePresenter>?
21+
private var layout : GenericCollectionLayoutProvider<HomePresenter>?
22+
private var errorMessageLabeal = UILabel()
1823
override func viewDidLoad() {
1924
super.viewDidLoad()
25+
26+
presenter?.viewDidLoad()
27+
setupCollectionView()
28+
collectionPrepareView()
29+
setupUI()
2030
}
21-
}
22-
23-
24-
25-
extension HomeViewController : PresenterToViewHomeProtocol {
26-
func relaodCollectionView() {
31+
32+
private func setupCollectionView() {
33+
guard let presenter = presenter as? HomePresenter else { return }
34+
layout = GenericCollectionLayoutProvider<HomePresenter>(source: presenter)
35+
collectionView = UICollectionView(frame: view.bounds, collectionViewLayout: layout!.createLayout())
36+
collectionView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
37+
collectionView.register(PopularCell.self, forCellWithReuseIdentifier: PopularCell.identifier)
38+
collectionView.register(AiringTodayCell.self, forCellWithReuseIdentifier: AiringTodayCell.identifier)
39+
40+
collectionView.register(CHeaderView.self,
41+
forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader,
42+
withReuseIdentifier: String(describing: CHeaderView.self))
2743

44+
2845
}
2946

30-
func sendError(errorState: (isHidden: Bool, message: String)) {
47+
private func collectionPrepareView() {
48+
guard let presenter = presenter as? HomePresenter else { return }
49+
dataSource = GenericCollectionDataSource(source: presenter) { identifier, cell, item in
50+
guard let item = item as? CellItemType else { return }
51+
52+
switch item {
53+
case .popular(let item):
54+
if let c = cell as? PopularCell { c.configure() }
55+
case .airing(let value):
56+
if let c = cell as? AiringTodayCell { c.configure() }
57+
case .none:
58+
break
59+
}
60+
}
61+
delegateSource = GenericCollectionDelegate<HomePresenter>(source: presenter)
62+
collectionView.dataSource = dataSource
63+
collectionView.delegate = delegateSource
64+
view.addSubview(collectionView)
3165

3266
}
3367

68+
private func setupUI() {
69+
70+
view.addSubview(errorMessageLabeal)
71+
errorMessageLabeal.snp.makeConstraints { make in
72+
make.center.equalToSuperview()
73+
}
74+
}
75+
}
76+
77+
extension HomeViewController : @MainActor PresenterToViewHomeProtocol {
3478
func startLoading() {
35-
79+
acitvityIndicator.startAnimating()
3680
}
3781

3882
func finishLoading() {
39-
83+
acitvityIndicator.stopAnimating()
4084
}
4185

86+
func relaodCollectionView() {
87+
collectionView.reloadData()
88+
}
4289

90+
func sendError(errorState: (isHidden:Bool,message:String)) {
91+
collectionView.isHidden = errorState.isHidden
92+
errorMessageLabeal.text = errorState.message
93+
errorMessageLabeal.isHidden = !errorState.isHidden
94+
95+
}
4396
}
97+
98+
#Preview {
99+
let module = ICTMDBHomeModule()
100+
module.createHomeModule()
101+
}
102+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// AiringTodayCell.swift
3+
// ICTMDBHomeModule
4+
//
5+
// Created by Engin Gülek on 12.11.2025.
6+
//
7+
8+
import UIKit
9+
import SnapKit
10+
import ICTMDBViewKit
11+
12+
final class AiringTodayCell: UICollectionViewCell {
13+
static let identifier = "AiringTodayCell"
14+
15+
16+
17+
override init(frame: CGRect) {
18+
super.init(frame: frame)
19+
setupUI()
20+
contentView.backgroundColor = .blue
21+
}
22+
23+
required init?(coder: NSCoder) {
24+
fatalError("init(coder:) has not been implemented")
25+
}
26+
27+
//MARK: SetupUI
28+
private func setupUI() {
29+
30+
31+
}
32+
33+
//MARK: Configure
34+
func configure() {
35+
36+
}
37+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// PopularCell.swift
3+
// ICTMDBHomeModule
4+
//
5+
// Created by Engin Gülek on 12.11.2025.
6+
//
7+
8+
import UIKit
9+
import SnapKit
10+
import ICTMDBViewKit
11+
12+
final class PopularCell: UICollectionViewCell {
13+
static let identifier: String = "PopularCell"
14+
15+
16+
17+
18+
override init(frame: CGRect) {
19+
super.init(frame: frame)
20+
setupUI()
21+
configureUI()
22+
contentView.backgroundColor = .red
23+
}
24+
25+
required init?(coder: NSCoder) {
26+
fatalError("init(coder:) has not been implemented")
27+
}
28+
29+
//MARK: setupUI
30+
private func setupUI() {
31+
layer.cornerRadius = 10
32+
clipsToBounds = true
33+
}
34+
35+
//MARK: Configure
36+
func configure() {
37+
38+
}
39+
40+
//MARK: ConfigureUI
41+
func configureUI() {
42+
43+
}
44+
45+
46+
}

0 commit comments

Comments
 (0)