Skip to content

Commit cf0ef3c

Browse files
authored
Merge pull request #19 from engingulek/feature/update-concurrency
updated concurency
2 parents 3bee87d + 6d2ed70 commit cf0ef3c

8 files changed

Lines changed: 62 additions & 68 deletions

.DS_Store

0 Bytes
Binary file not shown.

ICTMDBDetailModule/DetailInteractor.swift

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
import Foundation
88
import ICTMDBNetworkManagerKit
99

10-
final class TvShowDetailInteractor : PresenterToInteractorTvShowDetailProtocol {
10+
final class TvShowDetailInteractor : PresenterToInteractorTvShowDetailProtocol,@unchecked Sendable {
11+
1112

12-
13-
14-
1513
weak var presenter: (any InteractorToPresenterTvShowDetailProtocol)?
1614

1715
private let network : NetworkManagerProtocol
@@ -23,28 +21,25 @@ final class TvShowDetailInteractor : PresenterToInteractorTvShowDetailProtocol {
2321
let deviceLanguageCode = Locale.current.language.languageCode ?? .english
2422

2523

26-
func loadTvShowDetail(id: Int?) async {
24+
func loadData(id: Int?) async {
25+
guard let id else {return}
26+
let detailRequest = TvShowDetailRequest(
27+
language: deviceLanguageCode == .turkish ? .tr : .en,
28+
id: id)
29+
let castRequest = CastRequest(id: id)
30+
31+
async let detail = network.execute(detailRequest)
32+
async let cast = network.execute(castRequest)
33+
2734
do{
28-
guard let id = id else {return}
29-
let request = TvShowDetailRequest(
30-
language: deviceLanguageCode == .turkish ? .tr : .en,
31-
id: id)
32-
let result = try await network.execute(request)
33-
presenter?.onHandle(handle: .sendData(result))
35+
let (detailResult,castResult) = try await (detail,cast)
36+
await presenter?.onHandle(handle: .sendData(detailResult))
37+
await presenter?.onHandle(handle: .sendCast(castResult.cast))
3438
}catch{
35-
presenter?.onHandle(handle: .sendError(.detailError))
39+
await presenter?.onHandle(handle: .sendError)
3640
}
41+
3742
}
3843

39-
func loadTvShowCasts(id: Int?) async {
40-
do{
41-
guard let id = id else {return}
42-
let request = CastRequest(id: id)
43-
let result = try await network.execute(request)
44-
presenter?.onHandle(handle: .sendCast(result.cast))
45-
}catch{
46-
presenter?.onHandle(handle: .sendError(.castError))
47-
}
48-
}
4944
}
5045

ICTMDBDetailModule/DetailPresenter.swift

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ final class TvShowDetailPresenter {
2424

2525
func viewDidLoad() {
2626
view?.setBackColorAble(color: "backColor")
27-
view?.setNavigationTitle(title: "Detail")
28-
// view?.prepareCollectionView()
27+
view?.setNavigationTitle(title: LocalizableUI.detailNavTitle.localized)
2928
}
3029
}
3130

3231
extension TvShowDetailPresenter: ViewToPresenterTvShowDetailProtocol {
32+
33+
3334
func layout(for sectionIndex: Int) -> LayoutSource {
3435
guard let sectionType = SectionType(rawValue: sectionIndex) else {
3536
return LayoutSourceTeamplate.none.template
@@ -58,11 +59,8 @@ extension TvShowDetailPresenter: ViewToPresenterTvShowDetailProtocol {
5859
func getID(id: Int?) {
5960
guard let id = id else {return}
6061
Task{@MainActor in
61-
await interactor.loadTvShowDetail(id: id)
62-
await interactor.loadTvShowCasts(id: id)
62+
await interactor.loadData(id: id)
6363
}
64-
// interactor.loadTvShowDetail(id: id)
65-
// interactor.loadTvShowCasts(id: id)
6664

6765
}
6866

@@ -92,21 +90,31 @@ extension TvShowDetailPresenter: ViewToPresenterTvShowDetailProtocol {
9290
}
9391
}
9492

95-
96-
97-
func titleForSection(at section: Int) -> (
98-
title: String, sizeType:SectionSizeType,
99-
buttonType: [TitleForSectionButtonType]?) {
100-
guard let sectionType = SectionType(rawValue: section) else { return (title:"",sizeType:.small,buttonType:[]) }
101-
var item : (title: String, sizeType: SectionSizeType,buttonType: [TitleForSectionButtonType]?)
102-
switch sectionType {
103-
case .cast:
104-
item = (title:LocalizableUI.cast.localized,sizeType:.large,buttonType:[])
105-
case .season:
106-
item = (title:LocalizableUI.season.localized,sizeType:.large,buttonType:[])
107-
}
108-
return item
93+
func titleForSection(at section: Int) -> GenericCollectionViewKit.HeaderViewItem {
94+
let headerViewItem : HeaderViewItem
95+
guard let sectionType = SectionType(rawValue: section)
96+
else {
97+
return .init(title: "", sizeType: .empty)
98+
}
99+
switch sectionType {
100+
case .cast:
101+
headerViewItem = .init(
102+
title: LocalizableUI.cast.localized,
103+
icon: .init(
104+
image: .systemImage("person.3"),
105+
tintColor: .secondary),
106+
sizeType: .large)
107+
case .season:
108+
headerViewItem = .init(
109+
title: LocalizableUI.season.localized,
110+
icon: .init(
111+
image: .systemImage("film.stack"),
112+
tintColor: .custom(hex:"#FFA500")),
113+
sizeType: .large)
109114
}
115+
return headerViewItem
116+
117+
}
110118

111119
func sectionType(at section: Int) -> SectionType {
112120
return SectionType(rawValue: section) ?? .cast
@@ -132,13 +140,9 @@ extension TvShowDetailPresenter: InteractorToPresenterTvShowDetailProtocol {
132140
guard let seasons = seasons else {return}
133141
seasonList = seasons.map { SeasonPresentation(season: $0) }
134142

135-
case .sendError(let error):
136-
switch error {
137-
case .detailError:
138-
break
139-
case .castError:
140-
castList = []
141-
}
143+
case .sendError:
144+
castList = []
145+
break
142146
case .sendCast(let casts):
143147
castList = casts.map{CastPresentation(cast: $0) }
144148

ICTMDBDetailModule/DetailProtocols.swift

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,23 @@ protocol PresenterToViewTvShowDetailProtocol : AnyObject,Ables{
2828
func prepareCollectionView()
2929
}
3030

31-
@MainActor
32-
protocol PresenterToInteractorTvShowDetailProtocol {
31+
32+
protocol PresenterToInteractorTvShowDetailProtocol:Sendable,AnyObject {
3333
var presenter: InteractorToPresenterTvShowDetailProtocol? {get set}
34-
func loadTvShowDetail(id:Int?) async
35-
func loadTvShowCasts(id:Int?) async
34+
func loadData(id:Int?) async
3635
}
3736

3837

39-
enum TvShowErrorType : Error{
40-
case detailError
41-
case castError
42-
}
38+
4339
enum TvShowInteractorResult {
4440
case sendData(_ data: TvShowDetail,)
4541
case sendCast(_ data:[Cast])
46-
case sendError(_ error:TvShowErrorType)
42+
case sendError
4743
}
4844

45+
@MainActor
4946
protocol InteractorToPresenterTvShowDetailProtocol : AnyObject {
5047
func onHandle(handle:TvShowInteractorResult)
51-
5248
}
5349

5450

ICTMDBDetailModule/viewController/DetailViewController+CollectionView.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
// Created by Engin Gülek on 12.11.2025.
66
//
77

8-
import UIKit
8+
import UIKit
99
import SnapKit
1010

11-
12-
1311
extension DetailViewController {
1412

1513
func setupCollectionView() {

ICTMDBDetailModule/viewController/DetailViewController+Setup.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ extension DetailViewController {
5858
posterTopLayoutConstraint.isActive = true
5959

6060
mainPoster.snp.makeConstraints {
61+
$0.top.equalTo(view.safeAreaLayoutGuide.snp.top)
6162
$0.centerX.equalToSuperview()
6263
$0.height.equalTo(view.safeAreaLayoutGuide.snp.height).multipliedBy(0.4)
6364
$0.width.equalTo(view.safeAreaLayoutGuide.snp.height).multipliedBy(0.3)

ICTMDBDetailModule/viewController/DetailViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ private extension DetailViewController {
160160

161161
#Preview {
162162
let module = ICTMDBDetailModule()
163-
module.createTvShowDetailModule(id: 79744)
163+
UINavigationController(rootViewController: module.createTvShowDetailModule(id: 79744))
164164
}
165165

166166

Package.resolved

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

0 commit comments

Comments
 (0)