Skip to content

Commit 6bea84e

Browse files
authored
Merge pull request #13 from engingulek/feature/add-comments
added comments
2 parents a0d8c86 + 69b271e commit 6bea84e

14 files changed

Lines changed: 273 additions & 103 deletions

ICTMDBHomeModule.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ICTMDBHomeModule/HomeInteractor.swift

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,48 +8,75 @@
88
import Foundation
99
import ICTMDBNetworkManagerKit
1010

11-
final class HomeInteractor : @preconcurrency PresenterToInteractorHomeProtocol {
11+
import Foundation
12+
13+
/// `HomeInteractor` handles the data-fetching logic for the Home module.
14+
final class HomeInteractor: @preconcurrency PresenterToInteractorHomeProtocol {
15+
16+
// MARK: - Properties
17+
18+
/// Reference to the Presenter to send data or errors back.
1219
var presenter: (any InteractorToPresenterHomeProtocol)?
13-
14-
private let network : NetworkManagerProtocol
1520

16-
let deviceLanguageCode = Locale.current.language.languageCode ?? .english
21+
/// Network manager responsible for API requests.
22+
private let network: NetworkManagerProtocol
1723

24+
/// Current device language code (e.g., tr, en).
25+
let deviceLanguageCode = Locale.current.language.languageCode ?? .english
1826

19-
init(network: NetworkManagerProtocol) {
2027

28+
init(network: NetworkManagerProtocol) {
2129
self.network = network
2230
}
2331

24-
func loadPopularMovies() {
32+
// MARK: - Popular TV Shows
33+
34+
/// Loads the list of popular TV shows from the API.
35+
func loadPopularMovies() {
2536
let request = PopularMoviesRequest(
2637
language: deviceLanguageCode == .turkish ? .tr : .en,
27-
page: 1)
28-
38+
page: 1
39+
)
2940

30-
network.execute(request) {[weak self] result in
31-
guard let self else {return}
41+
// Executes the network request asynchronously.
42+
network.execute(request) { [weak self] result in
43+
guard let self else { return }
44+
3245
switch result {
33-
case .success(let list):
46+
case .success(let list):
47+
// Sends the fetched popular shows to the Presenter.
3448
presenter?.sendPopularTvShows(list.results)
49+
3550
case .failure:
51+
// Notifies Presenter of an error.
3652
presenter?.sendError(.popular)
3753
}
3854
}
3955
}
4056

41-
func loadAiringMovies() {
57+
// MARK: - Airing Today TV Shows
58+
59+
/// Loads the list of TV shows airing today.
60+
func loadAiringMovies() {
4261
let request = AiringTodayRequest(
4362
language: deviceLanguageCode == .turkish ? .tr : .en,
44-
page: 1)
63+
page: 1
64+
)
65+
66+
// Executes the network request asynchronously.
4567
network.execute(request) { [weak self] result in
46-
guard let self else {return}
68+
guard let self else { return }
69+
4770
switch result {
4871
case .success(let list):
72+
// Sends the fetched airing shows to the Presenter.
4973
presenter?.sendAiringTvShows(list.results)
74+
5075
case .failure:
76+
// Notifies Presenter of an error.
5177
presenter?.sendError(.airingToday)
5278
}
5379
}
5480
}
5581
}
82+

ICTMDBHomeModule/HomePresenter.swift

Lines changed: 83 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,47 @@ import GenericCollectionViewKit
1010
import ICTMDBViewKit
1111
import UIKit
1212

13-
//MARK: CellItemType
14-
15-
16-
//MARK: HomePresenter
13+
// MARK: - HomePresenter
14+
/// Handles the presentation logic for the Home module.
1715
final class HomePresenter {
16+
17+
// MARK: - Typealias
18+
/// Typealias for cell items displayed in collection view
1819
typealias CellItem = CellItemType
20+
21+
// MARK: - Properties
22+
23+
/// Reference to the View layer
1924
weak var view: PresenterToViewHomeProtocol?
20-
private var interactor : PresenterToInteractorHomeProtocol
21-
private var router : PresenterToRouterHomeProtocol
22-
private var popularTvShows : [PopularTVShowPresentation] = []
23-
private var airingTodayShows : [AiringTodayPresentation] = []
25+
26+
/// Reference to the Interactor layer
27+
private var interactor: PresenterToInteractorHomeProtocol
28+
29+
/// Reference to the Router layer
30+
private var router: PresenterToRouterHomeProtocol
31+
32+
/// List of popular TV shows for UI display
33+
private var popularTvShows: [PopularTVShowPresentation] = []
34+
35+
/// List of airing today shows for UI display
36+
private var airingTodayShows: [AiringTodayPresentation] = []
37+
38+
39+
// MARK: - Init
2440
init(view: PresenterToViewHomeProtocol?,
25-
interactor:PresenterToInteractorHomeProtocol,
26-
router : PresenterToRouterHomeProtocol
41+
interactor: PresenterToInteractorHomeProtocol,
42+
router: PresenterToRouterHomeProtocol
2743
) {
2844
self.view = view
2945
self.interactor = interactor
3046
self.router = router
3147
}
3248
}
3349

34-
//MARK: HomePresenter : ViewToPresenterHomeProtocol
35-
extension HomePresenter : ViewToPresenterHomeProtocol {
50+
51+
// MARK: - ViewToPresenterHomeProtocol
52+
/// Handles actions triggered by the View layer.
53+
extension HomePresenter: ViewToPresenterHomeProtocol {
3654

3755
func viewDidLoad() {
3856
view?.setBackColorAble(color: "backColor")
@@ -41,8 +59,11 @@ extension HomePresenter : ViewToPresenterHomeProtocol {
4159
}
4260
}
4361

44-
//MARK: CollectionViewSources
62+
63+
// MARK: - CollectionViewSources
64+
/// Provides collection view data, layout, and interaction logic.
4565
extension HomePresenter {
66+
4667
func layout(for sectionIndex: Int) -> LayoutSource {
4768
guard let sectionType = SectionType(rawValue: sectionIndex) else {
4869
return LayoutSourceTeamplate.none.template
@@ -56,21 +77,19 @@ extension HomePresenter {
5677
}
5778

5879
func numberOfRowsInSection(in section: Int) -> Int {
59-
guard let sectionType = SectionType(rawValue: section) else {return 0}
80+
guard let sectionType = SectionType(rawValue: section) else { return 0 }
6081
switch sectionType {
61-
case .popular:
62-
return popularTvShows.count
63-
case .airingToday:
64-
return airingTodayShows.count
82+
case .popular: return popularTvShows.count
83+
case .airingToday: return airingTodayShows.count
6584
}
6685
}
6786

87+
6888
func numberOfSections() -> Int {
6989
SectionType.allCases.count
7090
}
71-
72-
func cellForItem(section: Int,item:Int) -> CellItemType {
73-
91+
92+
func cellForItem(section: Int, item: Int) -> CellItemType {
7493
guard let sectionType = SectionType(rawValue: section) else { return .none }
7594
switch sectionType {
7695
case .popular:
@@ -80,11 +99,11 @@ extension HomePresenter {
8099
let tvShow = airingTodayShows[item]
81100
return .airing(tvShow)
82101
}
83-
84102
}
85103

104+
86105
func didSelectItem(section: Int, item: Int) {
87-
guard let sectionType = SectionType(rawValue: section) else { return }
106+
guard let sectionType = SectionType(rawValue: section) else { return }
88107
switch sectionType {
89108
case .popular:
90109
let id = popularTvShows[item].id
@@ -94,28 +113,37 @@ extension HomePresenter {
94113
router.toDetailPage(view: view, id: id)
95114
}
96115
}
97-
98-
func titleForSection(at section: Int) ->(
99-
title: String, sizeType:SectionSizeType,
100-
buttonType: [TitleForSectionButtonType]?) {
101-
102-
guard let sectionType = SectionType(rawValue: section)
103-
else { return (title:"",sizeType:.small,buttonType:[]) }
104-
105-
var item : (
106-
title: String,
107-
sizeType: SectionSizeType,
108-
buttonType: [TitleForSectionButtonType]?)
109-
110-
switch sectionType {
111-
case .popular:
112-
item = (title:LocalizableUI.popular.localized,sizeType:.large,buttonType:[.allList])
113-
case .airingToday:
114-
item = (title:LocalizableUI.airingToday.localized,sizeType:.small,buttonType:[.allList])
115-
}
116-
return item
116+
117+
118+
func titleForSection(at section: Int) -> (
119+
title: String,
120+
sizeType: SectionSizeType,
121+
buttonType: [TitleForSectionButtonType]?
122+
) {
123+
guard let sectionType = SectionType(rawValue: section) else {
124+
return (title: "", sizeType: .small, buttonType: [])
125+
}
126+
127+
var item: (title: String, sizeType: SectionSizeType, buttonType: [TitleForSectionButtonType]?)
128+
129+
switch sectionType {
130+
case .popular:
131+
item = (
132+
title: LocalizableUI.popular.localized,
133+
sizeType: .large,
134+
buttonType: [.allList]
135+
)
136+
case .airingToday:
137+
item = (
138+
title: LocalizableUI.airingToday.localized,
139+
sizeType: .small,
140+
buttonType: [.allList]
141+
)
117142
}
143+
return item
144+
}
118145

146+
119147
func onTappedTitleButton(buttonType: TitleForSectionButtonType, section: Int) {
120148
guard let sectionType = SectionType(rawValue: section) else { return }
121149

@@ -124,7 +152,6 @@ extension HomePresenter {
124152
switch buttonType {
125153
case .allList:
126154
router.toAllListPage(view: view, type: .popular)
127-
print("Popular All List")
128155
default:
129156
break
130157
}
@@ -144,40 +171,43 @@ extension HomePresenter {
144171
}
145172

146173
func cellIdentifier(at section: Int) -> String {
147-
guard let section = SectionType(rawValue: section) else {return ""}
174+
guard let section = SectionType(rawValue: section) else { return "" }
148175
switch section {
149176
case .popular: return PopularCell.identifier
150177
case .airingToday: return AiringTodayCell.identifier
151-
152178
}
153179
}
154180
}
155181

156-
//MARK: HomePresenter: InteractorToPresenterHomeProtocol
182+
183+
// MARK: - InteractorToPresenterHomeProtocol
184+
/// Receives data from the Interactor and updates the view.
157185
extension HomePresenter: InteractorToPresenterHomeProtocol {
186+
158187
func sendAiringTvShows(_ data: [AiringToday]) {
159188
view?.startLoading()
160-
airingTodayShows = data.map {
161-
AiringTodayPresentation(
162-
tvShow: $0)}
189+
airingTodayShows = data.map { AiringTodayPresentation(tvShow: $0) }
163190
view?.sendError(errorState: (isHidden: false, message: ""))
164191
view?.relaodCollectionView()
165192
view?.finishLoading()
166193
}
167194

168195
func sendPopularTvShows(_ data: [PopularTvShows]) {
169196
view?.startLoading()
170-
popularTvShows = data.map {PopularTVShowPresentation(
171-
tvShow: $0)}.sorted{$0.rating > $1.rating }
197+
popularTvShows = data
198+
.map { PopularTVShowPresentation(tvShow: $0) }
199+
.sorted { $0.rating > $1.rating }
172200
view?.sendError(errorState: (isHidden: false, message: ""))
173201
view?.relaodCollectionView()
174202
view?.finishLoading()
175203
}
176204

177205
func sendError(_ type: HomePageErrorType) {
178206
view?.startLoading()
179-
view?.sendError(errorState: (isHidden: true, message: LocalizableUI.somethingWentWrong.localized))
207+
view?.sendError(errorState: (isHidden: true,
208+
message: LocalizableUI.somethingWentWrong.localized))
180209
view?.relaodCollectionView()
181210
view?.finishLoading()
182211
}
183212
}
213+

0 commit comments

Comments
 (0)