Skip to content

Commit

Permalink
Merge pull request #38 from HanweeeeLee/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
HanweeeeLee authored Dec 26, 2021
2 parents bd26fa1 + 1284e3b commit 700345e
Show file tree
Hide file tree
Showing 31 changed files with 1,089 additions and 776 deletions.
108 changes: 56 additions & 52 deletions Archive.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions Archive/Define/CommonDefine.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// CommonDefine.swift
// Archive
//
// Created by hanwe on 2021/12/26.
//

import UIKit

enum Direction {
case left
case right
case top
case bottom
}

class CommonDefine: NSObject {

}
194 changes: 55 additions & 139 deletions Archive/Detail/Detail.storyboard

Large diffs are not rendered by default.

84 changes: 30 additions & 54 deletions Archive/Detail/DetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,22 @@ class DetailViewController: UIViewController, StoryboardView, ActivityIndicatora

enum CellModel {
case cover(ArchiveDetailInfo)
case commonImage(ArchiveDetailImageInfo)
case commonImage(ArchiveDetailImageInfo, Emotion, String)
}

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

@IBOutlet weak var mainContainerView: UIView!

@IBOutlet weak var topContainerView: UIView!
@IBOutlet weak var collectionView: UICollectionView!

@IBOutlet weak var bottomContainerView: UIView!
@IBOutlet weak var archiveTitleLabel: UILabel!
@IBOutlet weak var dateLabel: UILabel!

@IBOutlet weak var pageControl: UIPageControl!

// MARK: private property

private let photoContentsView: DetailPhotoContentsView? = DetailPhotoContentsView.instance()
private let modalShareViewController: ModalShareViewController = ModalShareViewController.init(nibName: "ModalShareViewController", bundle: nil)
private var willDisplayIndex: Int = 0

weak var delegate: DetailViewControllerDelegate?

Expand Down Expand Up @@ -72,14 +65,13 @@ class DetailViewController: UIViewController, StoryboardView, ActivityIndicatora
.asDriver(onErrorJustReturn: nil)
.compactMap { $0 }
.drive(onNext: { [weak self] info in
self?.setCardInfo(info)
self?.collectionView.delegate = nil
self?.collectionView.dataSource = nil
guard let images = info.images else { return }
self?.pageControl.numberOfPages = images.count + 1
var imageCellArr: [CellModel] = []
for imageItem in images {
imageCellArr.append(CellModel.commonImage(imageItem))
imageCellArr.append(CellModel.commonImage(imageItem, Emotion.fromString(info.emotion) ?? .fun, info.name))
}
let sections = Observable.just([
SectionModel(model: "card", items: [
Expand All @@ -92,16 +84,16 @@ class DetailViewController: UIViewController, StoryboardView, ActivityIndicatora
switch item {
case .cover(let infoData):
return self.makeCardCell(with: infoData, from: collectionView, indexPath: indexPath)
case .commonImage(let imageInfo):
return self.makeImageCell(with: imageInfo, from: collectionView, indexPath: indexPath)
case .commonImage(let imageInfo, let emotion, let name):
return self.makeImageCell(with: imageInfo, emotion: emotion, name: name, from: collectionView, indexPath: indexPath)
}
})
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.minimumLineSpacing = 0
layout.minimumInteritemSpacing = 0
layout.scrollDirection = .horizontal
let width = UIScreen.main.bounds.width
let height = width * 520 / 375
let height = UIScreen.main.bounds.height
layout.itemSize = CGSize(width: width, height: height)
layout.sectionInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
self.collectionView.collectionViewLayout = layout
Expand All @@ -111,28 +103,26 @@ class DetailViewController: UIViewController, StoryboardView, ActivityIndicatora
})
.disposed(by: self.disposeBag)

self.collectionView.rx.willDisplayCell
self.collectionView.rx.didEndDisplayingCell
.asDriver()
.drive(onNext: { [weak self] info in
if info.at.section == 0 {
self?.pageControl.currentPage = 0
} else {
self?.pageControl.currentPage = info.at.item + 1
var index: Int = 0
if info.at.section != 0 {
index = info.at.item + 1
}

if index != (self?.willDisplayIndex ?? 0) {
self?.pageControl.currentPage = self?.willDisplayIndex ?? 0
}
})
.disposed(by: self.disposeBag)

self.collectionView.rx.willDisplayCell
.asDriver()
.drive(onNext: { [weak self] info in
.subscribe(onNext: { [weak self] info in
if info.at.section == 0 {
self?.photoContentsView?.isHidden = true
self?.willDisplayIndex = 0
} else {
self?.photoContentsView?.isHidden = false
if let imageInfo = reactor.currentState.detailData?.images?[info.at.item] {
self?.photoContentsView?.imageInfo = imageInfo
self?.photoContentsView?.index = info.at.item
}
self?.willDisplayIndex = info.at.item + 1
}
})
.disposed(by: self.disposeBag)
Expand Down Expand Up @@ -181,64 +171,49 @@ class DetailViewController: UIViewController, StoryboardView, ActivityIndicatora
// MARK: private function

private func initUI() {
self.mainBackgroundView.backgroundColor = Gen.Colors.white.color
self.mainBackgroundView.backgroundColor = Gen.Colors.gray04.color
self.mainContainerView.backgroundColor = .clear
self.scrollContainerView.backgroundColor = .clear
self.scrollView.backgroundColor = .clear
self.topContainerView.backgroundColor = Gen.Colors.white.color
self.collectionView.backgroundColor = .clear

self.bottomContainerView.backgroundColor = Gen.Colors.white.color
self.archiveTitleLabel.font = .fonts(.header2)
self.archiveTitleLabel.textColor = Gen.Colors.black.color
self.dateLabel.font = .fonts(.header3)
self.dateLabel.textColor = Gen.Colors.black.color

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

self.pageControl.pageIndicatorTintColor = Gen.Colors.gray03.color
self.pageControl.currentPageIndicatorTintColor = Gen.Colors.gray01.color

if let photoContentsView = self.photoContentsView {
self.bottomContainerView.addSubview(photoContentsView)
photoContentsView.snp.makeConstraints {
$0.edges.equalToSuperview()
}
photoContentsView.isHidden = true
}

makeNaviBtn()
}

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

private func makeImageCell(with element: ArchiveDetailImageInfo, from collectionView: UICollectionView, indexPath: IndexPath) -> UICollectionViewCell {
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.imageInfo = element
cell.infoData = element
cell.topContainerViewHeightConstraint.constant = self.topbarHeight
cell.emotion = emotion
cell.name = name
return cell
}

private func setCardInfo(_ info: ArchiveDetailInfo) {
self.archiveTitleLabel.text = info.name
self.dateLabel.text = info.watchedOn
}

private func makeNaviBtn() {
let moreImage = Gen.Images.moreVertBlack24dp.image
moreImage.withRenderingMode(.alwaysTemplate)
let moreBarButtonItem = UIBarButtonItem(image: moreImage, style: .plain, target: self, action: #selector(moreButtonClicked(_:)))
moreBarButtonItem.tintColor = Gen.Colors.white.color
self.navigationItem.rightBarButtonItem = moreBarButtonItem

let closeImage = Gen.Images.xIcon.image
closeImage.withRenderingMode(.alwaysTemplate)
let backBarButtonItem = UIBarButtonItem(image: closeImage, style: .plain, target: self, action: #selector(backButtonClicked(_:)))
backBarButtonItem.tintColor = Gen.Colors.white.color
self.navigationItem.leftBarButtonItem = backBarButtonItem
self.navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: Gen.Colors.white.color]
}

// MARK: internal function
Expand All @@ -263,6 +238,7 @@ class DetailViewController: UIViewController, StoryboardView, ActivityIndicatora
self?.modalShareViewController.fadeIn()
})
}
alert.view.tintColor = .black
alert.addAction(deleteAction)
alert.addAction(shareAction)
alert.addAction(UIAlertAction(title: "취소", style: .cancel, handler: nil))
Expand Down
165 changes: 165 additions & 0 deletions Archive/Detail/Sub/DetailCard/DetailCardCollectionViewCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
//
// DetailCardCollectionViewCell.swift
// Archive
//
// Created by hanwe on 2021/12/26.
//

import UIKit

class DetailCardCollectionViewCell: 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 emotionCoverImageView: UIImageView!

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

@IBOutlet weak var friendsCollectionView: UICollectionView!

// MARK: private property

// MARK: internal property

var infoData: ArchiveDetailInfo? {
didSet {
guard let info = self.infoData else { return }
DispatchQueue.main.async { [weak self] in
if let emotion: Emotion = Emotion.fromString(info.emotion) {
self?.setNewEmotion(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()
}

// 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
// layout.itemSize = CGSize(width: 264, height: 365)
self.friendsCollectionView.collectionViewLayout = layout
self.friendsCollectionView.dataSource = self
self.friendsCollectionView.delegate = self
self.friendsCollectionView.backgroundColor = .clear

}

private func setNewEmotion(_ emotion: Emotion) {
switch emotion {
case .fun:
self.emotionCoverImageView.image = Gen.Images.colorFun.image
self.mainContetnsView.backgroundColor = Gen.Colors.funYellow.color
self.emotionLabel.text = "재미있는"
self.miniEmotionImageView.image = Gen.Images.preFun.image
case .impressive:
self.emotionCoverImageView.image = Gen.Images.colorImpressive.image
self.mainContetnsView.backgroundColor = Gen.Colors.impressiveGreen.color
self.emotionLabel.text = "인상적인"
self.miniEmotionImageView.image = Gen.Images.preImpressive.image
case .pleasant:
self.emotionCoverImageView.image = Gen.Images.colorPleasant.image
self.mainContetnsView.backgroundColor = Gen.Colors.pleasantRed.color
self.emotionLabel.text = "기분좋은"
self.miniEmotionImageView.image = Gen.Images.prePleasant.image
case .splendid:
self.emotionCoverImageView.image = Gen.Images.colorSplendid.image
self.mainContetnsView.backgroundColor = Gen.Colors.splendidBlue.color
self.emotionLabel.text = "아름다운"
self.miniEmotionImageView.image = Gen.Images.preSplendid.image
case .wonderful:
self.emotionCoverImageView.image = Gen.Images.colorWonderful.image
self.mainContetnsView.backgroundColor = Gen.Colors.wonderfulPurple.color
self.emotionLabel.text = "경이로운"
self.miniEmotionImageView.image = Gen.Images.preWonderful.image
}
}

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 DetailCardCollectionViewCell: 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 700345e

Please sign in to comment.