From 7a9b5b9cc9522e35a1a7ba3415c855c76131a015 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=B0=95=EC=9D=80=EB=B9=84?= Date: Fri, 3 May 2019 14:01:30 +0900 Subject: [PATCH] =?UTF-8?q?QurationTag=20API=20=EB=B6=99=EC=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../RecommendCollectionViewCell.swift | 52 +++++++++++++++++-- .../RecommendCollectionViewCell.xib | 11 ++-- .../RecommendTableViewCell.swift | 50 +++++++++++++++--- .../RecommendView/RecommendTableViewCell.xib | 18 +++---- Toonie/Feed/View/Feed.storyboard | 22 ++++---- .../Network/Service/CurationTagService.swift | 3 +- 6 files changed, 118 insertions(+), 38 deletions(-) diff --git a/Toonie/Feed/RecommendView/RecommendCollectionViewCell.swift b/Toonie/Feed/RecommendView/RecommendCollectionViewCell.swift index 9314556..5cc67af 100644 --- a/Toonie/Feed/RecommendView/RecommendCollectionViewCell.swift +++ b/Toonie/Feed/RecommendView/RecommendCollectionViewCell.swift @@ -11,24 +11,66 @@ import UIKit // '지금나는 final class RecommendCollectionViewCell: UICollectionViewCell { + // MARK: - Properties + var toonID: String = "" + var toonName: String = "" + var instaID: String = "" + var instaUrl: String = "" + var instaThumnailUrl: String = "" + var instafollowerCnt: String = "" + var instaLatestPostUrl: String = "" + // MARK: - IBOutlets @IBOutlet private weak var recentToonImageView: UIImageView! - @IBOutlet private weak var artistLabel: UILabel! + @IBOutlet private weak var toonNameTitle: UILabel! @IBOutlet private weak var bookMarkButton: UIButton! + @IBOutlet weak var curationTagList: UILabel! override func prepareForReuse() { super.prepareForReuse() recentToonImageView.image = nil - artistLabel.text = nil + toonNameTitle.text = nil bookMarkButton.isSelected = false } // MARK: - Functions /// 컬렉션뷰셀 데이터 설정 - func setRecommendCollectionViewCellProperties() { - recentToonImageView.image = UIImage(named: "sample2") - artistLabel.text = "임유끼" + func setRecommendCollectionViewCellProperties(curationInfoList: ToonInfoList?) { + prepareForReuse() + + if let info = curationInfoList { + DispatchQueue.main.async { + if let url = URL(string: info.instaThumnailUrl ?? "") { + do { + let data = try Data(contentsOf: url) + self.recentToonImageView.image = UIImage(data: data) + } catch let error { + print("Error : \(error.localizedDescription)") + } + } + } + if let nameString = info.toonName { + toonNameTitle.text = nameString + } + + var tagList = "" + if let toonTagList = info.toonTagList { + for index in 0.. - + - + @@ -20,8 +20,9 @@ - + + @@ -72,16 +73,16 @@ - + + - diff --git a/Toonie/Feed/RecommendView/RecommendTableViewCell.swift b/Toonie/Feed/RecommendView/RecommendTableViewCell.swift index 4e3f183..d4b92a7 100644 --- a/Toonie/Feed/RecommendView/RecommendTableViewCell.swift +++ b/Toonie/Feed/RecommendView/RecommendTableViewCell.swift @@ -11,6 +11,10 @@ import UIKit // '지금 나는' 테이블뷰 셀 - storyboard에서 collectionView 소스분리가 되지않아 xib로 분리. final class RecommendTableViewCell: UITableViewCell { + // MARK: - Properties + private var titleString: String? = "" + private var curationTagArray: [ToonInfoList]? + // MARK: - IBOutlet @IBOutlet private weak var recommentTitleLabel: UILabel! @@ -20,6 +24,7 @@ final class RecommendTableViewCell: UITableViewCell { override func awakeFromNib() { super.awakeFromNib() setRecommendCollectionView() + } override func setSelected(_ selected: Bool, animated: Bool) { @@ -29,16 +34,36 @@ final class RecommendTableViewCell: UITableViewCell { // MARK: - Function ///delegate세팅 및 xib(nib) 세팅 - func setRecommendCollectionView() { + private func setRecommendCollectionView() { recommendCollectionView.delegate = self recommendCollectionView.dataSource = self let nibName = UINib(nibName: "RecommendCollectionViewCell", bundle: nil) - recommendCollectionView.register(nibName, forCellWithReuseIdentifier: "RecommendCollectionViewCell") + recommendCollectionView.register(nibName, + forCellWithReuseIdentifier: "RecommendCollectionViewCell") } func setRecommentTitleLabel(titleString: String?) { - recommentTitleLabel.text = titleString + if let title = titleString { + recommentTitleLabel.text = "#\(title)" + } + self.titleString = titleString + setCurationTag() + } + + private func setCurationTag() { + if let string = titleString { + CurationTagService.shared.getCurationTagList(tagName: string) { (result) in + if let curationTagArray = result { + self.curationTagArray = curationTagArray + } + + self.recommendCollectionView.reloadData() + + } + + } + } } @@ -46,7 +71,7 @@ final class RecommendTableViewCell: UITableViewCell { extension RecommendTableViewCell: UICollectionViewDataSource { func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { - return 3 + return curationTagArray?.count ?? 0 } func collectionView(_ collectionView: UICollectionView, @@ -55,7 +80,7 @@ extension RecommendTableViewCell: UICollectionViewDataSource { for: indexPath) as? RecommendCollectionViewCell else { return UICollectionViewCell() } - cell.setRecommendCollectionViewCellProperties() + cell.setRecommendCollectionViewCellProperties(curationInfoList: curationTagArray?[indexPath.row]) return cell } @@ -63,7 +88,18 @@ extension RecommendTableViewCell: UICollectionViewDataSource { // MARK: - UICollectionViewDelegate extension RecommendTableViewCell: UICollectionViewDelegate { - func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { -// print("선택 \(indexPath.row)") + func collectionView(_ collectionView: UICollectionView, + didSelectItemAt indexPath: IndexPath) { + + let storyboard = UIStoryboard(name: "Detail", bundle: nil) + if let viewController = storyboard + .instantiateViewController(withIdentifier: "DetailToonView") + as? DetailToonViewController { + viewController.detailToonID = curationTagArray?[indexPath.row].toonID + CommonUtility.sharedInstance.mainNavigationViewController? + .pushViewController(viewController, + animated: true) + } + } } diff --git a/Toonie/Feed/RecommendView/RecommendTableViewCell.xib b/Toonie/Feed/RecommendView/RecommendTableViewCell.xib index 7f143b2..0b42a66 100644 --- a/Toonie/Feed/RecommendView/RecommendTableViewCell.xib +++ b/Toonie/Feed/RecommendView/RecommendTableViewCell.xib @@ -1,11 +1,11 @@ - + - + @@ -26,13 +26,7 @@ - - + @@ -67,6 +61,12 @@ + diff --git a/Toonie/Feed/View/Feed.storyboard b/Toonie/Feed/View/Feed.storyboard index ed04efa..6441ab5 100644 --- a/Toonie/Feed/View/Feed.storyboard +++ b/Toonie/Feed/View/Feed.storyboard @@ -424,18 +424,18 @@ - - + + - + - + - + @@ -515,26 +515,26 @@