Skip to content

Commit 8b79f3d

Browse files
authored
Merge pull request #20 from engingulek/develop
Develop
2 parents 28b072b + bd62451 commit 8b79f3d

12 files changed

Lines changed: 72 additions & 80 deletions

.DS_Store

2 KB
Binary file not shown.

ICTMDBDetailModule/.DS_Store

6 KB
Binary file not shown.

ICTMDBDetailModule/DetailInteractor.swift

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

10-
final class TvShowDetailInteractor : @preconcurrency PresenterToInteractorTvShowDetailProtocol {
11-
12-
10+
final class TvShowDetailInteractor : PresenterToInteractorTvShowDetailProtocol,@unchecked Sendable {
11+
12+
1313
weak var presenter: (any InteractorToPresenterTvShowDetailProtocol)?
1414

1515
private let network : NetworkManagerProtocol
@@ -19,37 +19,27 @@ final class TvShowDetailInteractor : @preconcurrency PresenterToInteractorTvShow
1919
self.network = network
2020
}
2121
let deviceLanguageCode = Locale.current.language.languageCode ?? .english
22-
@MainActor func loadTvShowDetail(id: Int?) {
23-
guard let id = id else {return}
24-
let request = TvShowDetailRequest(
22+
23+
24+
func loadData(id: Int?) async {
25+
guard let id else {return}
26+
let detailRequest = TvShowDetailRequest(
2527
language: deviceLanguageCode == .turkish ? .tr : .en,
2628
id: id)
29+
let castRequest = CastRequest(id: id)
2730

28-
network.execute(request) {[weak self] result in
29-
guard let self else {return}
30-
switch result {
31-
case .success(let data):
32-
presenter?.onHandle(handle: .sendData(data))
33-
34-
case .failure:
35-
presenter?.onHandle(handle: .sendError(.detailError))
36-
37-
}
31+
async let detail = network.execute(detailRequest)
32+
async let cast = network.execute(castRequest)
33+
34+
do{
35+
let (detailResult,castResult) = try await (detail,cast)
36+
await presenter?.onHandle(handle: .sendData(detailResult))
37+
await presenter?.onHandle(handle: .sendCast(castResult.cast))
38+
}catch{
39+
await presenter?.onHandle(handle: .sendError)
3840
}
41+
3942
}
4043

41-
@MainActor func loadTvShowCasts(id: Int?) {
42-
guard let id = id else {return}
43-
let request = CastRequest(id: id)
44-
network.execute(request) { [weak self] result in
45-
guard let self else {return}
46-
switch result {
47-
case .success(let casts):
48-
presenter?.onHandle(handle: .sendCast(casts.cast))
49-
case .failure:
50-
presenter?.onHandle(handle: .sendError(.castError))
51-
}
52-
}
53-
}
5444
}
5545

ICTMDBDetailModule/DetailPresenter.swift

Lines changed: 33 additions & 25 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
@@ -57,8 +58,9 @@ extension TvShowDetailPresenter: ViewToPresenterTvShowDetailProtocol {
5758

5859
func getID(id: Int?) {
5960
guard let id = id else {return}
60-
interactor.loadTvShowDetail(id: id)
61-
interactor.loadTvShowCasts(id: id)
61+
Task{@MainActor in
62+
await interactor.loadData(id: id)
63+
}
6264

6365
}
6466

@@ -88,21 +90,31 @@ extension TvShowDetailPresenter: ViewToPresenterTvShowDetailProtocol {
8890
}
8991
}
9092

91-
92-
93-
func titleForSection(at section: Int) -> (
94-
title: String, sizeType:SectionSizeType,
95-
buttonType: [TitleForSectionButtonType]?) {
96-
guard let sectionType = SectionType(rawValue: section) else { return (title:"",sizeType:.small,buttonType:[]) }
97-
var item : (title: String, sizeType: SectionSizeType,buttonType: [TitleForSectionButtonType]?)
98-
switch sectionType {
99-
case .cast:
100-
item = (title:LocalizableUI.cast.localized,sizeType:.large,buttonType:[])
101-
case .season:
102-
item = (title:LocalizableUI.season.localized,sizeType:.large,buttonType:[])
103-
}
104-
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)
10598
}
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)
114+
}
115+
return headerViewItem
116+
117+
}
106118

107119
func sectionType(at section: Int) -> SectionType {
108120
return SectionType(rawValue: section) ?? .cast
@@ -128,13 +140,9 @@ extension TvShowDetailPresenter: InteractorToPresenterTvShowDetailProtocol {
128140
guard let seasons = seasons else {return}
129141
seasonList = seasons.map { SeasonPresentation(season: $0) }
130142

131-
case .sendError(let error):
132-
switch error {
133-
case .detailError:
134-
break
135-
case .castError:
136-
castList = []
137-
}
143+
case .sendError:
144+
castList = []
145+
break
138146
case .sendCast(let casts):
139147
castList = casts.map{CastPresentation(cast: $0) }
140148

ICTMDBDetailModule/DetailProtocols.swift

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ typealias Ables = UIViewAble & NavConUIAble
1010
import GenericCollectionViewKit
1111

1212

13-
13+
@MainActor
1414
protocol ViewToPresenterTvShowDetailProtocol:
1515
AnyObject, GenericCollectionDataSourceProtocol,
1616
GenericCollectionDelegateSourceProtocol,
@@ -29,26 +29,22 @@ protocol PresenterToViewTvShowDetailProtocol : AnyObject,Ables{
2929
}
3030

3131

32-
protocol PresenterToInteractorTvShowDetailProtocol {
32+
protocol PresenterToInteractorTvShowDetailProtocol:Sendable,AnyObject {
3333
var presenter: InteractorToPresenterTvShowDetailProtocol? {get set}
34-
func loadTvShowDetail(id:Int?)
35-
func loadTvShowCasts(id:Int?)
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/ICTMDBDetailModule.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import UIKit
1010
import ICTMDBModularProtocols
1111
import ICTMDBNetworkManagerKit
1212

13-
public class ICTMDBDetailModule : @preconcurrency TvShowDetailProtocol {
13+
public class ICTMDBDetailModule : @MainActor TvShowDetailProtocol {
1414

1515

1616
public init() { }

ICTMDBDetailModule/cells/.DS_Store

6 KB
Binary file not shown.

ICTMDBDetailModule/request/CastRequest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ struct CastRequest : NetworkRequest {
1414
var path: NetworkPath {.casts(id)}
1515
var method: AlamofireMethod { .GET}
1616
var headers: [String : String]?
17-
var parameters: [String : Any]?
17+
var parameters: [String : Any]? { [:]}
1818
}

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.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ final class DetailViewController: UIViewController {
100100
}
101101
}
102102

103-
extension DetailViewController: @preconcurrency PresenterToViewTvShowDetailProtocol {
103+
extension DetailViewController: @MainActor PresenterToViewTvShowDetailProtocol {
104104
func sendData(detail: TvShowDetailPresentation, title: TvShowDetailTitlePresentation) {
105105
configureExampleData(detail, title)
106106
}

0 commit comments

Comments
 (0)