Skip to content

Commit

Permalink
Merge pull request #64 from HanweeeeLee/develop
Browse files Browse the repository at this point in the history
새로운 타입의 커버 추가
  • Loading branch information
HanweeeeLee authored Jan 25, 2023
2 parents 5f266da + 290cc08 commit 4aef5d2
Show file tree
Hide file tree
Showing 40 changed files with 1,604 additions and 115 deletions.
32 changes: 24 additions & 8 deletions Archive.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions Archive/Define/CommonDefine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ enum Direction {
case bottom
}

enum CoverType: String, Codable, CaseIterable {
case cover = "EMOTION_COVER"
case image = "NO_COVER"

static func coverTypeFromRawValue(_ rawValue: String) -> CoverType? {
var returnValue: CoverType?
for item in CoverType.allCases where item.rawValue == rawValue {
returnValue = item
}
return returnValue
}
}

class CommonDefine: NSObject {
static let kakaoAppKey: String = "147a5c186ee0f5fdc58244b704165132"
static let devApiServer: String = "https://archive-ticket.site/dev" // 개발
Expand Down
2 changes: 1 addition & 1 deletion Archive/Detail/DetailReactor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class DetailReactor: Reactor, Stepper {
guard let self = self else { return }
guard let cardView: ShareCardView = ShareCardView.instance() else { return }
cardView.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.width * 1.73)
cardView.setInfoData(emotion: self.recordData.emotion, thumbnailImage: UIImage(data: data) ?? UIImage(), eventName: self.recordData.name, date: self.recordData.watchedOn)
cardView.setInfoData(emotion: self.recordData.emotion, thumbnailImage: UIImage(data: data) ?? UIImage(), eventName: self.recordData.name, date: self.recordData.watchedOn, coverType: self.recordData.coverType)
completion(cardView)
}
} else {
Expand Down
17 changes: 16 additions & 1 deletion Archive/Detail/DetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ class DetailViewController: UIViewController, StoryboardView, ActivityIndicatora
private lazy var dataSource = RxCollectionViewSectionedReloadDataSource<SectionModel<String, CellModel>>(configureCell: { [weak self] dataSource, collectionView, indexPath, item in
switch item {
case .cover(let infoData):
return self?.makeCardCell(with: infoData, from: collectionView, indexPath: indexPath) ?? UICollectionViewCell()
switch self?.reactor?.currentState.detailData.coverType {
case .cover:
return self?.makeCardCell(with: infoData, from: collectionView, indexPath: indexPath) ?? UICollectionViewCell()
case .image:
return self?.makeCardImageTypeCell(with: infoData, from: collectionView, indexPath: indexPath) ?? UICollectionViewCell()
case .none:
return self?.makeCardCell(with: infoData, from: collectionView, indexPath: indexPath) ?? UICollectionViewCell()
}
case .commonImage(let imageInfo, let emotion, let name):
return self?.makeImageCell(with: imageInfo, emotion: emotion, name: name, from: collectionView, indexPath: indexPath) ?? UICollectionViewCell()
}
Expand Down Expand Up @@ -201,6 +208,7 @@ class DetailViewController: UIViewController, StoryboardView, ActivityIndicatora

self.collectionView.showsHorizontalScrollIndicator = false
self.collectionView.register(UINib(nibName: DetailCardCollectionViewCell.identifier, bundle: nil), forCellWithReuseIdentifier: DetailCardCollectionViewCell.identifier)
self.collectionView.register(UINib(nibName: DetailCardImageTypeCollectionViewCell.identifier, bundle: nil), forCellWithReuseIdentifier: DetailCardImageTypeCollectionViewCell.identifier)
self.collectionView.register(UINib(nibName: DetailContentsCollectionViewCell.identifier, bundle: nil), forCellWithReuseIdentifier: DetailContentsCollectionViewCell.identifier)

self.pageControl.pageIndicatorTintColor = Gen.Colors.gray03.color
Expand All @@ -219,6 +227,13 @@ class DetailViewController: UIViewController, StoryboardView, ActivityIndicatora
return cell
}

private func makeCardImageTypeCell(with element: ArchiveDetailInfo, from collectionView: UICollectionView, indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: DetailCardImageTypeCollectionViewCell.identifier, for: indexPath) as? DetailCardImageTypeCollectionViewCell else { return UICollectionViewCell() }
cell.infoData = element
cell.topContainerViewHeightConstraint.constant = self.topbarHeight
return cell
}

private func makeImageCell(with element: ArchiveDetailImageInfo, emotion: Emotion, name: String, from collectionView: UICollectionView, indexPath: IndexPath) -> UICollectionViewCell {
guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: DetailContentsCollectionViewCell.identifier, for: indexPath) as? DetailContentsCollectionViewCell else { return UICollectionViewCell() }
cell.infoData = element
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
//
// DetailCardImageTypeCollectionViewCell.swift
// Archive
//
// Created by hanwe on 2021/12/26.
//

import UIKit
import Kingfisher

class DetailCardImageTypeCollectionViewCell: UICollectionViewCell, ClassIdentifiable {

// MARK: IBOutlet
@IBOutlet weak var mainBackgroundView: UIView!
@IBOutlet weak var scrollView: UIScrollView!
@IBOutlet weak var mainContetnsView: UIView!

@IBOutlet weak var topContainerView: UIView!
@IBOutlet weak var topContainerViewHeightConstraint: NSLayoutConstraint!

@IBOutlet weak var centerContainerView: UIView!
@IBOutlet weak var miniEmotionImageView: UIImageView!
@IBOutlet weak var emotionLabel: UILabel!
@IBOutlet weak var mainImageView: UIImageView!

@IBOutlet weak var bottomContainerView: UIView!
@IBOutlet weak var eventNameLabel: UILabel!
@IBOutlet weak var eventDateLabel: UILabel!

@IBOutlet weak var friendsCollectionView: UICollectionView!

private let emotionContainerView = UIView().then {
$0.layer.cornerRadius = 10
$0.backgroundColor = Gen.Colors.whiteOpacity70.color
}

private lazy var emotionImageView: UIImageView = {
let imageView = UIImageView()
return imageView
}()

private lazy var emotionTitleLabel: UILabel = {
let label: UILabel = UILabel()
label.font = .fonts(.subTitle)
label.textColor = Gen.Colors.black.color
return label
}()

// MARK: private property

// MARK: internal property

var infoData: ArchiveDetailInfo? {
didSet {
guard let info = self.infoData else { return }
DispatchQueue.main.async { [weak self] in
self?.setNewEmotion(info.emotion)
self?.mainImageView.kf.setImage(with: URL(string: info.mainImage),
placeholder: nil,
options: [.cacheMemoryOnly],
completionHandler: { [weak self] _ in
self?.mainImageView.fadeIn(duration: 0.1, completeHandler: nil)
})
self?.eventNameLabel.text = info.name
self?.eventDateLabel.text = info.watchedOn
}
}
}

// MARK: lifeCycle

override func awakeFromNib() {
super.awakeFromNib()
initUI()
ImageCache.default.clearCache()
}

// MARK: private function

private func initUI() {
self.scrollView.backgroundColor = .clear
self.mainContetnsView.backgroundColor = .clear

self.topContainerView.backgroundColor = .clear

self.centerContainerView.backgroundColor = .clear

self.emotionLabel.font = .fonts(.subTitle)
self.emotionLabel.textColor = Gen.Colors.white.color

self.bottomContainerView.backgroundColor = Gen.Colors.white.color

self.eventNameLabel.font = .fonts(.header2)
self.eventNameLabel.textColor = Gen.Colors.black.color

self.eventDateLabel.font = .fonts(.header3)
self.eventDateLabel.textColor = Gen.Colors.black.color

self.friendsCollectionView.register(UINib(nibName: DetailFriendsCollectionViewCell.identifier, bundle: nil), forCellWithReuseIdentifier: DetailFriendsCollectionViewCell.identifier)
self.friendsCollectionView.showsHorizontalScrollIndicator = false
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.scrollDirection = .horizontal
layout.sectionInset = UIEdgeInsets(top: 0, left: 9, bottom: 0, right: 0)
layout.minimumLineSpacing = 12
self.friendsCollectionView.collectionViewLayout = layout
self.friendsCollectionView.dataSource = self
self.friendsCollectionView.delegate = self
self.friendsCollectionView.backgroundColor = .clear

self.mainImageView.contentMode = .scaleAspectFill

centerContainerView.addSubview(self.emotionContainerView)
self.emotionContainerView.snp.makeConstraints {
$0.leading.equalTo(self.centerContainerView).offset(12)
$0.top.equalTo(self.topContainerView.snp.bottom).offset(12)
}

emotionContainerView.addSubview(emotionImageView)
emotionImageView.snp.makeConstraints {
$0.width.equalTo(24)
$0.height.equalTo(24)
$0.leading.equalTo(self.emotionContainerView).offset(8)
$0.top.equalTo(self.emotionContainerView).offset(6)
$0.bottom.equalTo(self.emotionContainerView).offset(-6)
}

emotionContainerView.addSubview(emotionTitleLabel)
emotionTitleLabel.snp.makeConstraints {
$0.centerY.equalTo(emotionImageView.snp.centerY)
$0.leading.equalTo(emotionImageView.snp.trailing).offset(8)
$0.trailing.equalTo(emotionContainerView.snp.trailing).offset(-8)
}

}

private func setNewEmotion(_ emotion: Emotion) {
self.mainContetnsView.backgroundColor = Gen.Colors.gray05.color
self.emotionLabel.text = emotion.localizationTitle
self.miniEmotionImageView.image = emotion.preImage
self.emotionImageView.image = emotion.typeImage
self.emotionTitleLabel.text = emotion.localizationTitle
}

private func getFriendsCellWidth(_ text: String) -> CGFloat {
let fontAttributes = [NSAttributedString.Key.font: UIFont.fonts(.subTitle)]
return (text as NSString).size(withAttributes: fontAttributes).width + 25
}

// MARK: internal function

// MARK: action

}

extension DetailCardImageTypeCollectionViewCell: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.infoData?.companions?.count ?? 0
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
guard let cell: DetailFriendsCollectionViewCell = collectionView.dequeueReusableCell(withReuseIdentifier: DetailFriendsCollectionViewCell.identifier, for: indexPath) as? DetailFriendsCollectionViewCell else {
return UICollectionViewCell()
}

if let title = self.infoData?.companions?[indexPath.item] {
cell.mainTitleLabel.text = title
}

return cell
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {

var cellSize: CGSize = CGSize(width: 10, height: 10)
if let companions = self.infoData?.companions {
let text = companions[indexPath.item]
cellSize = CGSize(width: self.getFriendsCellWidth(text), height: 36)
}

return cellSize
}
}
Loading

0 comments on commit 4aef5d2

Please sign in to comment.