Skip to content
This repository was archived by the owner on Dec 20, 2023. It is now read-only.

Commit 7b47a23

Browse files
committed
Рефакторинг кода
1 parent 621afbe commit 7b47a23

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

AvitoTech-TraineeAssignment/AvitoTech-TraineeAssignment/Screens/Catalog/CatalogViewController.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ final class CatalogViewController: UIViewController, CatalogViewControllerProtoc
5757
cell.dateLabel(date: model.createdDate)
5858
}
5959

60+
func showCatalogsObjectView(viewController: CatalogsObjectViewController) {
61+
navigationController?.pushViewController(viewController, animated: true)
62+
}
63+
6064
private func configureCollection() {
6165
collectionView.backgroundColor = .clear
6266
collectionView.refreshControl = refreshControl
@@ -119,12 +123,8 @@ extension CatalogViewController: UICollectionViewDataSource {
119123
}
120124

121125
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
122-
//tODO: Перенести в презентер
123126
guard let cell = collectionView.cellForItem(at: indexPath) as? CatalogCell,
124127
let id = cell.id else { return }
125-
let catalogsObjectPresenter = CatalogsObjectViewPresenter(objectId: id)
126-
let catalogsViewController = CatalogsObjectViewController(presenter: catalogsObjectPresenter)
127-
catalogsObjectPresenter.injectViewController(viewController: catalogsViewController)
128-
navigationController?.pushViewController(catalogsViewController, animated: true)
128+
presenter.viewDidTapCell(id: id)
129129
}
130130
}

AvitoTech-TraineeAssignment/AvitoTech-TraineeAssignment/Screens/Catalog/CatalogViewPresenter.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ final class CatalogViewPresenter: CatalogViewPresenterProtocol {
5050
viewController?.configureCell(cell: cell, with: model)
5151
}
5252

53+
func viewDidTapCell(id: String) {
54+
let catalogsObjectPresenter = CatalogsObjectViewPresenter(objectId: id)
55+
let catalogsObjectViewController = CatalogsObjectViewController(presenter: catalogsObjectPresenter)
56+
catalogsObjectPresenter.injectViewController(viewController: catalogsObjectViewController)
57+
viewController?.showCatalogsObjectView(viewController: catalogsObjectViewController)
58+
}
59+
5360
private func updateViewCollection() {
5461
viewController?.removeHud()
5562
viewController?.updateCollection()

AvitoTech-TraineeAssignment/AvitoTech-TraineeAssignment/Screens/Catalog/CatalogViewProtocol.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ protocol CatalogViewPresenterProtocol {
1313
func viewDidLoad()
1414
func viewDidPullToRefresh()
1515
func viewWillConfigureCell(cell: CatalogCell, with indexPath: IndexPath)
16+
func viewDidTapCell(id: String)
1617
}
1718

1819
protocol CatalogViewControllerProtocol: AnyObject {
@@ -21,4 +22,5 @@ protocol CatalogViewControllerProtocol: AnyObject {
2122
func showHud()
2223
func removeHud()
2324
func configureCell(cell: CatalogCell, with model: Advertisement)
25+
func showCatalogsObjectView(viewController: CatalogsObjectViewController)
2426
}

0 commit comments

Comments
 (0)