Skip to content

Commit

Permalink
refactor: BanchanListViewController Refactoring
Browse files Browse the repository at this point in the history
BanchanListViewController 의 Datasource 에서 작업하던 cell 의 image 업데이트를 cell이 직접하도록 수정
  • Loading branch information
youngminshim-de committed Apr 22, 2021
1 parent 30af0d2 commit 5eaa3b0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,26 @@ class BanchanCustomCell: UICollectionViewCell {

var banchan: Banchan? {
didSet{
loadImages(imgURL: banchan?.image ?? "")
titleLabel.text = banchan?.title
descriptionLabel.text = banchan?.description
netPriceLabel.text = "1000"
salePriceLabel.text = "2000"
priceTypeLabel.text = "3000"
}
}

private func loadImages(imgURL: String) {
DispatchQueue.global().async {
FetchImageUseCase.fetch(network: NetworkSerivce.shared,
imgURL: self.banchan?.image ?? "") { (data) in
guard let data = data else {
return
}
DispatchQueue.main.async {
self.imageView.image = UIImage(data: data)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class BanchanCustomCellHeader: UICollectionReusableView {
return UINib(nibName: identifier, bundle: nil)
}

func configure(title: String, count: Int) {
titleLabel.text = title
cellCount = count
}

@objc func headerTouched(_ sender: UITapGestureRecognizer) {
Toast(text: "\(cellCount)개 상품이 등록되어 있습니다.").show()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ extension BanchanListViewController {
let dataSource = DataSource(collectionView: banchanCollectionView) { (collectionView, indexPath, banchan) -> UICollectionViewCell? in
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: BanchanCustomCell.identifer, for: indexPath) as? BanchanCustomCell else { return nil }

FetchImageUseCase.fetch(network: NetworkSerivce.shared, imgURL: banchan.image) { (data) in
guard let data = data else {
return
}
cell.imageView.image = UIImage(data: data)
}
cell.banchan = banchan
return cell
}
Expand All @@ -69,8 +63,7 @@ extension BanchanListViewController {

guard let view = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: BanchanCustomCellHeader.identifier, for: indexPath) as? BanchanCustomCellHeader else { return nil }

view.titleLabel.text = section.rawValue
view.cellCount = self.viewModel.count(section: section)
view.configure(title: section.rawValue, count: self.viewModel.count(section: section))
return view

}
Expand All @@ -91,7 +84,6 @@ extension BanchanListViewController {
}
}


// MARK: - Delegate
extension BanchanListViewController: UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
Expand Down

0 comments on commit 5eaa3b0

Please sign in to comment.