@@ -12,6 +12,7 @@ import UIKit
1212
1313// MARK: - HomePresenter
1414/// Handles the presentation logic for the Home module.
15+
1516final 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+
5355extension 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.
187196extension 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
0 commit comments