Skip to content

Commit 56147f4

Browse files
authored
Merge pull request #25 from engingulek/develop
Develop
2 parents 73a4956 + dbca484 commit 56147f4

14 files changed

Lines changed: 131 additions & 170 deletions

.DS_Store

2 KB
Binary file not shown.

ICTMDBHomeModule.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@
380380
ONLY_ACTIVE_ARCH = YES;
381381
SDKROOT = iphoneos;
382382
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)";
383+
SWIFT_DEFAULT_ACTOR_ISOLATION = nonisolated;
383384
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
384385
VERSIONING_SYSTEM = "apple-generic";
385386
VERSION_INFO_PREFIX = "";
@@ -440,6 +441,7 @@
440441
MTL_FAST_MATH = YES;
441442
SDKROOT = iphoneos;
442443
SWIFT_COMPILATION_MODE = wholemodule;
444+
SWIFT_DEFAULT_ACTOR_ISOLATION = nonisolated;
443445
VALIDATE_PRODUCT = YES;
444446
VERSIONING_SYSTEM = "apple-generic";
445447
VERSION_INFO_PREFIX = "";

ICTMDBHomeModule/HomeInteractor.swift

Lines changed: 15 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -8,75 +8,38 @@
88
import Foundation
99
import ICTMDBNetworkManagerKit
1010

11-
import Foundation
1211

13-
/// `HomeInteractor` handles the data-fetching logic for the Home module.
14-
final class HomeInteractor: @preconcurrency PresenterToInteractorHomeProtocol {
15-
12+
final class HomeInteractor: PresenterToInteractorHomeProtocol,@unchecked Sendable {
13+
1614
// MARK: - Properties
1715

1816
/// Reference to the Presenter to send data or errors back.
19-
var presenter: (any InteractorToPresenterHomeProtocol)?
17+
weak var presenter: (any InteractorToPresenterHomeProtocol)?
2018

2119
/// Network manager responsible for API requests.
2220
private let network: NetworkManagerProtocol
2321

2422
/// Current device language code (e.g., tr, en).
2523
let deviceLanguageCode = Locale.current.language.languageCode ?? .english
2624

27-
2825
init(network: NetworkManagerProtocol) {
2926
self.network = network
3027
}
3128

32-
// MARK: - Popular TV Shows
33-
34-
/// Loads the list of popular TV shows from the API.
35-
func loadPopularMovies() {
36-
let request = PopularMoviesRequest(
37-
language: deviceLanguageCode == .turkish ? .tr : .en,
38-
page: 1
39-
)
29+
func loadData() async {
30+
let popularMoviesRequest = PopularMoviesRequest(language: deviceLanguageCode == .turkish ? .tr : .en, page: 1)
31+
let airingTodayRequest = AiringTodayRequest(language: deviceLanguageCode == .turkish ? .tr : .en, page: 1)
32+
async let popularMovies = network.execute(popularMoviesRequest)
4033

41-
// Executes the network request asynchronously.
42-
network.execute(request) { [weak self] result in
43-
guard let self else { return }
44-
45-
switch result {
46-
case .success(let list):
47-
// Sends the fetched popular shows to the Presenter.
48-
presenter?.sendPopularTvShows(list.results)
49-
50-
case .failure:
51-
// Notifies Presenter of an error.
52-
presenter?.sendError(.popular)
53-
}
54-
}
55-
}
56-
57-
// MARK: - Airing Today TV Shows
58-
59-
/// Loads the list of TV shows airing today.
60-
func loadAiringMovies() {
61-
let request = AiringTodayRequest(
62-
language: deviceLanguageCode == .turkish ? .tr : .en,
63-
page: 1
64-
)
65-
66-
// Executes the network request asynchronously.
67-
network.execute(request) { [weak self] result in
68-
guard let self else { return }
34+
async let airingMovies = network.execute(airingTodayRequest)
35+
36+
do {
37+
let (popularResult, airingResult) = try await (popularMovies, airingMovies)
6938

70-
switch result {
71-
case .success(let list):
72-
// Sends the fetched airing shows to the Presenter.
73-
presenter?.sendAiringTvShows(list.results)
74-
75-
case .failure:
76-
// Notifies Presenter of an error.
77-
presenter?.sendError(.airingToday)
78-
}
39+
await presenter?.sendPopularTvShows(popularResult.results)
40+
await presenter?.sendAiringTvShows(airingResult.results)
41+
} catch {
42+
await presenter?.sendError()
7943
}
8044
}
8145
}
82-

ICTMDBHomeModule/HomePresenter.swift

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import UIKit
1212

1313
// MARK: - HomePresenter
1414
/// Handles the presentation logic for the Home module.
15+
1516
final class HomePresenter {
1617

1718
// MARK: - Typealias
@@ -50,15 +51,28 @@ final class HomePresenter {
5051

5152
// MARK: - ViewToPresenterHomeProtocol
5253
/// Handles actions triggered by the View layer.
54+
5355
extension HomePresenter: ViewToPresenterHomeProtocol {
56+
5457

58+
5559
func viewDidLoad() {
5660
view?.setBackColorAble(color: "backColor")
57-
//TODO: move to Localizable
58-
view?.setNavigationTitle(title: "Home Page")
59-
interactor.loadPopularMovies()
60-
interactor.loadAiringMovies()
61+
view?.setNavigationTitle(title: LocalizableUI.homePageNavTitle.localized)
62+
63+
Task {@MainActor in
64+
await loadData()
65+
}
6166
}
67+
68+
69+
@MainActor
70+
func loadData() async {
71+
view?.startLoading()
72+
await interactor.loadData()
73+
view?.finishLoading()
74+
}
75+
6276
}
6377

6478

@@ -116,33 +130,28 @@ extension HomePresenter {
116130
}
117131
}
118132

119-
120-
func titleForSection(at section: Int) -> (
121-
title: String,
122-
sizeType: SectionSizeType,
123-
buttonType: [TitleForSectionButtonType]?
124-
) {
133+
func titleForSection(at section: Int) -> GenericCollectionViewKit.HeaderViewItem {
134+
var headerViewItem:HeaderViewItem
125135
guard let sectionType = SectionType(rawValue: section) else {
126-
return (title: "", sizeType: .small, buttonType: [])
136+
headerViewItem = .init(title: "", sizeType: .empty)
137+
return headerViewItem
127138
}
128139

129-
var item: (title: String, sizeType: SectionSizeType, buttonType: [TitleForSectionButtonType]?)
130-
131140
switch sectionType {
132141
case .popular:
133-
item = (
142+
headerViewItem = .init(
134143
title: LocalizableUI.popular.localized,
144+
icon: .init(image: .systemImage("flame.fill"), tintColor: .custom(hex: "#FF0000")),
135145
sizeType: .large,
136-
buttonType: [.allList]
137-
)
146+
buttonTypes: [.allList])
138147
case .airingToday:
139-
item = (
148+
headerViewItem = .init(
140149
title: LocalizableUI.airingToday.localized,
141-
sizeType: .small,
142-
buttonType: [.allList]
143-
)
150+
icon: .init(image: .systemImage("circle.fill"), tintColor: .custom(hex: "#008000")),
151+
sizeType: .large,
152+
buttonTypes: [.allList])
144153
}
145-
return item
154+
return headerViewItem
146155
}
147156

148157

@@ -185,31 +194,31 @@ extension HomePresenter {
185194
// MARK: - InteractorToPresenterHomeProtocol
186195
/// Receives data from the Interactor and updates the view.
187196
extension HomePresenter: InteractorToPresenterHomeProtocol {
197+
func sendError() {
198+
199+
view?.sendError(errorState: (isHidden: true,
200+
message: LocalizableUI.somethingWentWrong.localized))
201+
view?.relaodCollectionView()
202+
203+
}
204+
188205

189206
func sendAiringTvShows(_ data: [AiringToday]) {
190-
view?.startLoading()
207+
191208
airingTodayShows = data.map { AiringTodayPresentation(tvShow: $0) }
192209
view?.sendError(errorState: (isHidden: false, message: ""))
193210
view?.relaodCollectionView()
194-
view?.finishLoading()
211+
195212
}
196213

197214
func sendPopularTvShows(_ data: [PopularTvShows]) {
198-
view?.startLoading()
215+
199216
popularTvShows = data
200217
.map { PopularTVShowPresentation(tvShow: $0) }
201218
.sorted { $0.rating > $1.rating }
202219
view?.sendError(errorState: (isHidden: false, message: ""))
203220
view?.relaodCollectionView()
204-
view?.finishLoading()
205-
}
206-
207-
func sendError(_ type: HomePageErrorType) {
208-
view?.startLoading()
209-
view?.sendError(errorState: (isHidden: true,
210-
message: LocalizableUI.somethingWentWrong.localized))
211-
view?.relaodCollectionView()
212-
view?.finishLoading()
221+
213222
}
214223
}
215224

ICTMDBHomeModule/HomeProtocols.swift

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ typealias Ables = UIViewAble & SegueAble & NavConUIAble
1717

1818
// MARK: - View → Presenter
1919
/// Protocol for communication from View to Presenter.
20+
@MainActor
2021
protocol ViewToPresenterHomeProtocol: AnyObject,
2122
GenericCollectionDataSourceProtocol,
2223
GenericCollectionDelegateSourceProtocol,
@@ -27,6 +28,7 @@ protocol ViewToPresenterHomeProtocol: AnyObject,
2728

2829
/// Called when the view is loaded
2930
func viewDidLoad()
31+
3032
}
3133

3234
// MARK: - Presenter → View
@@ -48,21 +50,21 @@ protocol PresenterToViewHomeProtocol: AnyObject, Ables {
4850

4951
// MARK: - Presenter → Interactor
5052
/// Protocol defining communication from Presenter to Interactor.
51-
protocol PresenterToInteractorHomeProtocol {
52-
53+
54+
protocol PresenterToInteractorHomeProtocol:Sendable,AnyObject {
55+
5356
/// Reference to the Presenter layer
5457
var presenter: InteractorToPresenterHomeProtocol? { get set }
55-
56-
/// Requests popular TV shows data
57-
func loadPopularMovies()
58-
59-
/// Requests airing today TV shows data
60-
func loadAiringMovies()
58+
59+
// Requests data
60+
func loadData() async
6161
}
6262

63+
6364
// MARK: - Interactor → Presenter
6465
/// Protocol for sending data or errors from Interactor to Presenter.
65-
protocol InteractorToPresenterHomeProtocol {
66+
@MainActor
67+
protocol InteractorToPresenterHomeProtocol : AnyObject{
6668

6769
/// Sends fetched popular TV shows
6870
func sendPopularTvShows(_ data: [PopularTvShows])
@@ -71,11 +73,13 @@ protocol InteractorToPresenterHomeProtocol {
7173
func sendAiringTvShows(_ data: [AiringToday])
7274

7375
/// Sends an error state
74-
func sendError(_ type: HomePageErrorType)
76+
func sendError()
77+
7578
}
7679

7780
// MARK: - Presenter → Router
7881
/// Protocol for navigation actions from Presenter to Router.
82+
7983
protocol PresenterToRouterHomeProtocol {
8084

8185
/// Navigates to All List page

ICTMDBHomeModule/HomeRouter.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ import ICTMDBViewKit
1313
import UIKit
1414

1515
/// `HomeRouter` is responsible for navigation in the Home module.
16-
public class HomeRouter: @preconcurrency PresenterToRouterHomeProtocol {
16+
public class HomeRouter: PresenterToRouterHomeProtocol {
1717

1818
// MARK: - Navigation to All List Page
1919

2020
/// Navigates to the All List screen based on the selected section type.
2121
/// - Parameters:
2222
/// - view: The current view conforming to `PresenterToViewHomeProtocol`.
2323
/// - type: The section type (e.g., popular or airingToday).
24-
@MainActor
24+
2525
func toAllListPage(view: PresenterToViewHomeProtocol?, type: SectionType) {
2626
// Determine the list type based on section
2727
let listType: AllListType = type == .popular ? .popular : .airingToday
@@ -41,14 +41,11 @@ public class HomeRouter: @preconcurrency PresenterToRouterHomeProtocol {
4141
/// - Parameters:
4242
/// - view: The current view conforming to `PresenterToViewHomeProtocol`.
4343
/// - id: The TV show ID to display details for.
44-
@MainActor
44+
4545
func toDetailPage(view: (any PresenterToViewHomeProtocol)?, id: Int?) {
4646
// Resolve Detail module dependency from DependencyRegister
47-
// Detail modülünü DependencyRegister üzerinden alır
4847
let detailModule = DependencyRegister.shared.resolve(TvShowDetailProtocol.self)
49-
5048
// Create the Detail view controller using module
51-
// Modül üzerinden Detail view controller oluşturur
5249
let detailViewController = detailModule.createTvShowDetailModule(id: id)
5350

5451
view?.pushViewControllerAble(detailViewController, animated: true)

ICTMDBHomeModule/HomeViewController.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ final class HomeViewController: UIViewController {
4848
setupCollectionView()
4949
collectionPrepareView()
5050
setupUI()
51+
5152
}
5253

5354

@@ -135,5 +136,6 @@ extension HomeViewController: @MainActor PresenterToViewHomeProtocol {
135136
// MARK: - Preview
136137
#Preview {
137138
let module = ICTMDBHomeModule()
138-
UINavigationController(rootViewController: module.createHomeModule())
139+
140+
return UINavigationController(rootViewController: module.createHomeModule())
139141
}

ICTMDBHomeModule/ICTMDBHomeModule.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import ICTMDBNetworkManagerKit
1212

1313
// MARK: - ICTMDBHomeModule
1414
/// Responsible for creating the Home module and wiring VIPER components.
15-
public class ICTMDBHomeModule : @preconcurrency HomeModuleProtocol {
15+
public class ICTMDBHomeModule : @MainActor HomeModuleProtocol {
1616
public init() { }
1717
@MainActor public func createHomeModule() -> UIViewController {
1818

ICTMDBHomeModule/requests/AiringTodayRequest.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import ICTMDBNetworkManagerKit
99

1010
//MARK: AiringTodayRequest
1111
struct AiringTodayRequest :NetworkRequest {
12+
1213
typealias Response = DataResult<AiringToday>
1314
var language: RequestLanguage
1415
var page: Int

0 commit comments

Comments
 (0)