Skip to content

Commit a0d8c86

Browse files
authored
Merge pull request #11 from engingulek/10-create-request-and-last-view-desing
10 create request and last view desing
2 parents 0cb35e2 + 95032f5 commit a0d8c86

17 files changed

Lines changed: 485 additions & 62 deletions

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

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

ICTMDBHomeModule/Enums.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
//
77

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

@@ -16,3 +16,10 @@ enum SectionType: Int, CaseIterable {
1616
case popular
1717
case airingToday
1818
}
19+
20+
21+
//MARK: HomePageErrorType
22+
enum HomePageErrorType {
23+
case popular
24+
case airingToday
25+
}

ICTMDBHomeModule/HomeInteractor.swift

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,51 @@
55
// Created by Engin Gülek on 12.11.2025.
66
//
77

8+
import Foundation
9+
import ICTMDBNetworkManagerKit
810

9-
final class HomeInteractor : PresenterToInteractorHomeProtocol {
11+
final class HomeInteractor : @preconcurrency PresenterToInteractorHomeProtocol {
1012
var presenter: (any InteractorToPresenterHomeProtocol)?
1113

14+
private let network : NetworkManagerProtocol
15+
16+
let deviceLanguageCode = Locale.current.language.languageCode ?? .english
17+
18+
19+
init(network: NetworkManagerProtocol) {
20+
21+
self.network = network
22+
}
23+
1224
func loadPopularMovies() {
13-
25+
let request = PopularMoviesRequest(
26+
language: deviceLanguageCode == .turkish ? .tr : .en,
27+
page: 1)
28+
29+
30+
network.execute(request) {[weak self] result in
31+
guard let self else {return}
32+
switch result {
33+
case .success(let list):
34+
presenter?.sendPopularTvShows(list.results)
35+
case .failure:
36+
presenter?.sendError(.popular)
37+
}
38+
}
1439
}
1540

1641
func loadAiringMovies() {
17-
42+
let request = AiringTodayRequest(
43+
language: deviceLanguageCode == .turkish ? .tr : .en,
44+
page: 1)
45+
network.execute(request) { [weak self] result in
46+
guard let self else {return}
47+
switch result {
48+
case .success(let list):
49+
presenter?.sendAiringTvShows(list.results)
50+
case .failure:
51+
presenter?.sendError(.airingToday)
52+
}
53+
}
1854
}
1955
}

ICTMDBHomeModule/HomePresenter.swift

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import Foundation
99
import GenericCollectionViewKit
1010
import ICTMDBViewKit
11+
import UIKit
1112

1213
//MARK: CellItemType
1314

@@ -18,6 +19,8 @@ final class HomePresenter {
1819
weak var view: PresenterToViewHomeProtocol?
1920
private var interactor : PresenterToInteractorHomeProtocol
2021
private var router : PresenterToRouterHomeProtocol
22+
private var popularTvShows : [PopularTVShowPresentation] = []
23+
private var airingTodayShows : [AiringTodayPresentation] = []
2124
init(view: PresenterToViewHomeProtocol?,
2225
interactor:PresenterToInteractorHomeProtocol,
2326
router : PresenterToRouterHomeProtocol
@@ -31,9 +34,10 @@ final class HomePresenter {
3134
//MARK: HomePresenter : ViewToPresenterHomeProtocol
3235
extension HomePresenter : ViewToPresenterHomeProtocol {
3336

34-
3537
func viewDidLoad() {
3638
view?.setBackColorAble(color: "backColor")
39+
interactor.loadPopularMovies()
40+
interactor.loadAiringMovies()
3741
}
3842
}
3943

@@ -55,9 +59,9 @@ extension HomePresenter {
5559
guard let sectionType = SectionType(rawValue: section) else {return 0}
5660
switch sectionType {
5761
case .popular:
58-
return 5
62+
return popularTvShows.count
5963
case .airingToday:
60-
return 3
64+
return airingTodayShows.count
6165
}
6266
}
6367

@@ -66,23 +70,31 @@ extension HomePresenter {
6670
}
6771

6872
func cellForItem(section: Int,item:Int) -> CellItemType {
73+
6974
guard let sectionType = SectionType(rawValue: section) else { return .none }
7075
switch sectionType {
7176
case .popular:
72-
73-
return .popular("popular")
77+
let tvShow = popularTvShows[item]
78+
return .popular(tvShow)
7479
case .airingToday:
75-
76-
return .airing("airing")
80+
let tvShow = airingTodayShows[item]
81+
return .airing(tvShow)
7782
}
78-
7983

8084
}
8185

82-
func didSelectItem(at indexPath: IndexPath) {
83-
86+
func didSelectItem(section: Int, item: Int) {
87+
guard let sectionType = SectionType(rawValue: section) else { return }
88+
switch sectionType {
89+
case .popular:
90+
let id = popularTvShows[item].id
91+
router.toDetailPage(view: view, id: id)
92+
case .airingToday:
93+
let id = airingTodayShows[item].id
94+
router.toDetailPage(view: view, id: id)
95+
}
8496
}
85-
97+
8698
func titleForSection(at section: Int) ->(
8799
title: String, sizeType:SectionSizeType,
88100
buttonType: [TitleForSectionButtonType]?) {
@@ -143,15 +155,29 @@ extension HomePresenter {
143155

144156
//MARK: HomePresenter: InteractorToPresenterHomeProtocol
145157
extension HomePresenter: InteractorToPresenterHomeProtocol {
146-
func sendAiringTvShows() {
147-
158+
func sendAiringTvShows(_ data: [AiringToday]) {
159+
view?.startLoading()
160+
airingTodayShows = data.map {
161+
AiringTodayPresentation(
162+
tvShow: $0)}
163+
view?.sendError(errorState: (isHidden: false, message: ""))
164+
view?.relaodCollectionView()
165+
view?.finishLoading()
148166
}
149167

150-
func sendPopularTvShows() {
151-
168+
func sendPopularTvShows(_ data: [PopularTvShows]) {
169+
view?.startLoading()
170+
popularTvShows = data.map {PopularTVShowPresentation(
171+
tvShow: $0)}.sorted{$0.rating > $1.rating }
172+
view?.sendError(errorState: (isHidden: false, message: ""))
173+
view?.relaodCollectionView()
174+
view?.finishLoading()
152175
}
153176

154-
func sendError() {
155-
177+
func sendError(_ type: HomePageErrorType) {
178+
view?.startLoading()
179+
view?.sendError(errorState: (isHidden: true, message: LocalizableUI.somethingWentWrong.localized))
180+
view?.relaodCollectionView()
181+
view?.finishLoading()
156182
}
157183
}

ICTMDBHomeModule/HomeProtocols.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,38 +12,38 @@ import GenericCollectionViewKit
1212
typealias Ables = UIViewAble & SegueAble
1313

1414
protocol ViewToPresenterHomeProtocol: AnyObject,
15-
GenericCollectionDataSourceProtocol,
16-
GenericCollectionDelegateSourceProtocol,
17-
GenericCollectionLayoutProviderProtocol{
18-
var view : PresenterToViewHomeProtocol? {get}
19-
func viewDidLoad()
15+
GenericCollectionDataSourceProtocol,
16+
GenericCollectionDelegateSourceProtocol,
17+
GenericCollectionLayoutProviderProtocol{
18+
var view : PresenterToViewHomeProtocol? {get}
19+
func viewDidLoad()
2020
}
2121

2222

2323
protocol PresenterToViewHomeProtocol : AnyObject,Ables{
24-
func relaodCollectionView()
25-
func sendError(errorState: (isHidden:Bool,message:String))
26-
func startLoading()
27-
func finishLoading()
24+
func relaodCollectionView()
25+
func sendError(errorState: (isHidden:Bool,message:String))
26+
func startLoading()
27+
func finishLoading()
2828
}
2929

3030

3131
protocol PresenterToInteractorHomeProtocol {
32-
var presenter: InteractorToPresenterHomeProtocol? {get set}
33-
func loadPopularMovies()
34-
func loadAiringMovies()
32+
var presenter: InteractorToPresenterHomeProtocol? {get set}
33+
func loadPopularMovies()
34+
func loadAiringMovies()
3535
}
3636

3737

3838
protocol InteractorToPresenterHomeProtocol {
39-
func sendPopularTvShows()
40-
func sendAiringTvShows()
41-
func sendError()
39+
func sendPopularTvShows(_ data: [PopularTvShows])
40+
func sendAiringTvShows(_ data: [AiringToday])
41+
func sendError(_ type:HomePageErrorType)
4242
}
4343

4444
protocol PresenterToRouterHomeProtocol {
4545
func toAllListPage(view:PresenterToViewHomeProtocol?,type:SectionType)
46-
func toDetailPage(view:PresenterToViewHomeProtocol?,id:Int?)
46+
func toDetailPage(view:PresenterToViewHomeProtocol?,id:Int?)
4747
}
4848

4949

ICTMDBHomeModule/HomeRouter.swift

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,24 @@
66
//
77

88
import UIKit
9-
10-
public class HomeRouter : PresenterToRouterHomeProtocol {
11-
9+
import ICTMDBModularProtocols
10+
import DependencyKit
11+
import ICTMDBViewKit
12+
public class HomeRouter : @preconcurrency PresenterToRouterHomeProtocol {
1213

13-
func toAllListPage(view:PresenterToViewHomeProtocol?,type:SectionType) {
14-
14+
@MainActor func toAllListPage(view:PresenterToViewHomeProtocol?,type: SectionType) {
15+
let listType : AllListType = type == .popular ? .popular : .airingToday
16+
let allListModule = DependencyRegister.shared.resolve(AllListModuleProtocol.self)
17+
let allListViewController = allListModule.createAllListModule(type: listType)
18+
view?.pushViewControllerAble(allListViewController, animated: true)
19+
1520
}
1621

17-
func toDetailPage(view: (any PresenterToViewHomeProtocol)?, id: Int?) {
18-
22+
@MainActor func toDetailPage(view: (any PresenterToViewHomeProtocol)?, id: Int?) {
23+
let detailModule = DependencyRegister.shared.resolve(TvShowDetailProtocol.self)
24+
let detailViewController = detailModule.createTvShowDetailModule(id: id)
25+
view?.pushViewControllerAble(detailViewController, animated: true)
1926
}
2027

21-
2228

2329
}

ICTMDBHomeModule/HomeViewController.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ final class HomeViewController: UIViewController {
5151

5252
switch item {
5353
case .popular(let item):
54-
if let c = cell as? PopularCell { c.configure() }
54+
if let c = cell as? PopularCell { c.configure(with: item) }
5555
case .airing(let value):
56-
if let c = cell as? AiringTodayCell { c.configure() }
56+
if let c = cell as? AiringTodayCell { c.configure(with: value) }
5757
case .none:
5858
break
5959
}
@@ -99,4 +99,3 @@ extension HomeViewController : @MainActor PresenterToViewHomeProtocol {
9999
let module = ICTMDBHomeModule()
100100
module.createHomeModule()
101101
}
102-

ICTMDBHomeModule/ICTMDBHomeModule.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@
88
import Foundation
99
import UIKit
1010
import ICTMDBModularProtocols
11-
public class ICTMDBHomeModule : HomeModuleProtocol {
11+
import ICTMDBNetworkManagerKit
12+
13+
public class ICTMDBHomeModule : @preconcurrency HomeModuleProtocol {
1214
public init() { }
1315
@MainActor public func createHomeModule() -> UIViewController {
1416

1517
let viewController = HomeViewController()
1618

1719
let router = HomeRouter()
18-
let interactor = HomeInteractor()
20+
let interactor = HomeInteractor(network: NetworkManager())
1921

2022
let presenter : any ViewToPresenterHomeProtocol & InteractorToPresenterHomeProtocol
2123
= HomePresenter(view: viewController, interactor: interactor,router: router)

0 commit comments

Comments
 (0)