Skip to content

Commit

Permalink
#5 Feat: Image HashValue & configure sideCell
Browse files Browse the repository at this point in the history
  • Loading branch information
zzisun committed Apr 28, 2021
1 parent 4bf5c0e commit e3c3e75
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 30 deletions.
8 changes: 8 additions & 0 deletions ios/sidedishApp/sidedishApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
764CE0C22630110500DED09C /* DetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 764CE0C12630110500DED09C /* DetailViewController.swift */; };
764CE0C72630167E00DED09C /* DetailItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = 764CE0C62630167E00DED09C /* DetailItem.swift */; };
764CE0CC26301E7000DED09C /* DetailViewModelType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 764CE0CB26301E7000DED09C /* DetailViewModelType.swift */; };
76785DAB26394A6E0089B8ED /* Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76785DAA26394A6E0089B8ED /* Extension.swift */; };
76785DAD26394ABA0089B8ED /* PriceStackView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 76785DAC26394ABA0089B8ED /* PriceStackView.swift */; };
767DF7A42637B3EB00642F1C /* DetailLayoutManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 767DF7A32637B3EB00642F1C /* DetailLayoutManager.swift */; };
767DF7AA2637B46400642F1C /* DetailImageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 767DF7A82637B46400642F1C /* DetailImageCell.swift */; };
767DF7B42637B4C100642F1C /* DetailInfoCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 767DF7B22637B4C100642F1C /* DetailInfoCell.swift */; };
Expand Down Expand Up @@ -75,6 +77,8 @@
764CE0C12630110500DED09C /* DetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailViewController.swift; sourceTree = "<group>"; };
764CE0C62630167E00DED09C /* DetailItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailItem.swift; sourceTree = "<group>"; };
764CE0CB26301E7000DED09C /* DetailViewModelType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailViewModelType.swift; sourceTree = "<group>"; };
76785DAA26394A6E0089B8ED /* Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extension.swift; sourceTree = "<group>"; };
76785DAC26394ABA0089B8ED /* PriceStackView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PriceStackView.swift; sourceTree = "<group>"; };
767DF7A32637B3EB00642F1C /* DetailLayoutManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailLayoutManager.swift; sourceTree = "<group>"; };
767DF7A82637B46400642F1C /* DetailImageCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailImageCell.swift; sourceTree = "<group>"; };
767DF7B22637B4C100642F1C /* DetailInfoCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailInfoCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -172,6 +176,7 @@
9386C108262D7401008645D9 /* Assets.xcassets */,
9386C10A262D7401008645D9 /* LaunchScreen.storyboard */,
9386C10D262D7401008645D9 /* Info.plist */,
76785DAA26394A6E0089B8ED /* Extension.swift */,
);
path = sidedishApp;
sourceTree = "<group>";
Expand Down Expand Up @@ -255,6 +260,7 @@
767DF7A32637B3EB00642F1C /* DetailLayoutManager.swift */,
767DF7B22637B4C100642F1C /* DetailInfoCell.swift */,
767DF7B32637B4C100642F1C /* DetailInfoCell.xib */,
76785DAC26394ABA0089B8ED /* PriceStackView.swift */,
);
path = Views;
sourceTree = "<group>";
Expand Down Expand Up @@ -462,9 +468,11 @@
764CE0B3263008C500DED09C /* DetailUseCase.swift in Sources */,
9386C156262D86C3008645D9 /* LayoutManager.swift in Sources */,
9386C16E262D8C02008645D9 /* Category.swift in Sources */,
76785DAD26394ABA0089B8ED /* PriceStackView.swift in Sources */,
9386C189262E4DB2008645D9 /* SectionHeader.swift in Sources */,
767DF7BA2637E1F800642F1C /* Image.swift in Sources */,
9386C174262DB13C008645D9 /* SidedishCell.swift in Sources */,
76785DAB26394A6E0089B8ED /* Extension.swift in Sources */,
9386C18E262E51F1008645D9 /* Endpoint.swift in Sources */,
93732723263800EC00FBF7C3 /* OrderViewModel.swift in Sources */,
9386C102262D7400008645D9 /* SceneDelegate.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>PreviewsEnabled</key>
<false/>
</dict>
</plist>
2 changes: 1 addition & 1 deletion ios/sidedishApp/sidedishApp/Domain/Entity/Detail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct Detail: Codable, Hashable, Equatable {
}

func getDescriptionImages() -> [Image] {
return item.getDetailImages()
return item.getDescriptionImages()
}

func getName() -> String {
Expand Down
11 changes: 10 additions & 1 deletion ios/sidedishApp/sidedishApp/Domain/Entity/Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

import Foundation

struct Image: Codable, Hashable, Equatable {
struct Image: Hashable, Equatable {
private var image: String
private let id = UUID()

init(image: String = "") {
self.image = image
Expand All @@ -17,4 +18,12 @@ struct Image: Codable, Hashable, Equatable {
func getImage() -> String {
return image
}

static func ==(lhs: Image, rhs: Image) -> Bool {
return lhs.id == rhs.id
}

func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
}
18 changes: 11 additions & 7 deletions ios/sidedishApp/sidedishApp/Domain/Entity/Item.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,20 @@ struct Item: Codable, Equatable, Hashable {
return self.salePrice
}

func getEventBadgeName(_ index: Int) -> String {
return self.eventBadgeList[index].getName()
func getEventBadgeList() -> [EventBadge] {
return eventBadgeList
}

func getEventBadgeColor(_ index: Int) -> String {
return self.eventBadgeList[index].getColorHex()
}
// func getEventBadgeName(_ index: Int) -> String {
// return self.eventBadgeList[index].getName()
// }
//
// func getEventBadgeColor(_ index: Int) -> String {
// return self.eventBadgeList[index].getColorHex()
// }

func isNotSale() -> Bool {
return self.salePrice == -1 ? true : false
func isSale() -> Bool {
return self.salePrice != -1
}
}

Expand Down
31 changes: 31 additions & 0 deletions ios/sidedishApp/sidedishApp/Extension.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// Extension.swift
// sidedishApp
//
// Created by 김지선 on 2021/04/28.
//

import Foundation
import UIKit

extension UIColor {
class func hexStringToUIColor(hex: String) -> UIColor {
let hexString = hex.trimmingCharacters(in: ["#"])
var rgbValue:UInt32 = 0
Scanner(string: hexString).scanHexInt32(&rgbValue)
return UIColor(
red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,
blue: CGFloat(rgbValue & 0x0000FF) / 255.0,
alpha: CGFloat(1.0)
)
}
}

extension String {
func strikeThrough() -> NSAttributedString {
let attributeString: NSMutableAttributedString = NSMutableAttributedString(string: self)
attributeString.addAttribute(NSAttributedString.Key.strikethroughStyle, value: NSUnderlineStyle.single.rawValue, range: NSMakeRange(0, attributeString.length))
return attributeString
}
}
13 changes: 13 additions & 0 deletions ios/sidedishApp/sidedishApp/Presentation/UI/Views/BadgeLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ import UIKit
class BadgeLabel: UILabel {
var padding : UIEdgeInsets

func configureLabel(text: String, color: String) {
self.text = text
self.backgroundColor = backgroundColor
self.padding = UIEdgeInsets(top: 5, left: 8, bottom: 5, right: 8)
self.sizeToFit()
self.layer.cornerRadius = 8
self.layer.masksToBounds = true
self.textColor = .systemBackground
self.font = UIFont.boldSystemFont(ofSize: 16)
self.backgroundColor = UIColor.hexStringToUIColor(hex: color)
self.text = text
}

required init(padding: UIEdgeInsets = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)) {
self.padding = padding
super.init(frame: CGRect.zero)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// PriceStackView.swift
// sidedishApp
//
// Created by 김지선 on 2021/04/28.
//

import UIKit

class PriceStackView: UIStackView {
let normalPriceLabel = UILabel()
let salePriceLabel = UILabel()

func configureStackView(normalPrice: Int, salePrice: Int) {
if salePrice == -1 {
configureNotSale()
normalPriceLabel.text = "\(normalPrice)"
addArrangedSubview(normalPriceLabel)
} else {
configureSale()
normalPriceLabel.text = "\(normalPrice)"
normalPriceLabel.attributedText = normalPriceLabel.text?.strikeThrough()
salePriceLabel.text = "\(salePrice)"

addArrangedSubview(salePriceLabel)
addArrangedSubview(normalPriceLabel)
}

self.axis = .horizontal
self.spacing = 8
}

func configureNotSale() {
normalPriceLabel.font = UIFont.boldSystemFont(ofSize: 15)
normalPriceLabel.textColor = .black

}

func configureSale() {
salePriceLabel.font = UIFont.boldSystemFont(ofSize: 15)
normalPriceLabel.font = UIFont.systemFont(ofSize: 14)
normalPriceLabel.textColor = .systemGray2
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class SidedishCell: UICollectionViewCell {

let nameLabel = UILabel()
let descriptionLabel = UILabel()
let normalPriceLabel = UILabel()
let salePriceLabel = UILabel()

let priceStack = PriceStackView()
let badgeLabel = BadgeLabel()
let eventBadgeStackView = UIStackView()
let thumbnailImageView = RemoteImageView()
Expand All @@ -31,13 +31,25 @@ class SidedishCell: UICollectionViewCell {
func configureCell(item: Item) {
self.nameLabel.text = item.getName()
self.descriptionLabel.text = item.getDescription()
self.normalPriceLabel.text = "\(item.getNormalPrice())"
self.salePriceLabel.text = "\(item.getSalePrice())"
self.salePriceLabel.isHidden = item.isNotSale()

// self.normalPriceLabel.text = "\(item.getNormalPrice())"
// self.salePriceLabel.text = "\(item.getSalePrice())"
// self.salePriceLabel.isHidden = item.isSale()

guard let url = URL(string: item.getThumbnailImage()) else { return }
self.thumbnailImageView.setImage(with: url)
self.badgeLabel.backgroundColor = .systemGreen
self.badgeLabel.text = "이벤트특가"

priceStack.configureStackView(normalPrice: item.getNormalPrice(), salePrice: item.getSalePrice())

for view in eventBadgeStackView.subviews {
view.removeFromSuperview()
}
item.getEventBadgeList().forEach { eventBadge in
let badgeLabel = BadgeLabel()
badgeLabel.configureLabel(text: eventBadge.getName(), color: eventBadge.getColorHex())

eventBadgeStackView.addArrangedSubview(badgeLabel)
}
}

private func configureUI() {
Expand All @@ -47,25 +59,15 @@ class SidedishCell: UICollectionViewCell {
descriptionLabel.font = UIFont.systemFont(ofSize: 15)
descriptionLabel.textColor = .gray

salePriceLabel.font = UIFont.boldSystemFont(ofSize: 15)
normalPriceLabel.font = UIFont.systemFont(ofSize: 14)
normalPriceLabel.textColor = .systemGray2

badgeLabel.padding = UIEdgeInsets(top: 5, left: 8, bottom: 5, right: 8)
badgeLabel.sizeToFit()
badgeLabel.layer.cornerRadius = 8
badgeLabel.layer.masksToBounds = true
badgeLabel.textColor = .systemBackground
badgeLabel.font = UIFont.boldSystemFont(ofSize: 16)


eventBadgeStackView.spacing = 8
eventBadgeStackView.axis = .horizontal

eventBadgeStackView.addArrangedSubview(badgeLabel)
// let priceStack = PriceStackView()
// priceStack.configureStackView()
// let priceStack = UIStackView(arrangedSubviews: [salePriceLabel, normalPriceLabel])

let priceStack = UIStackView(arrangedSubviews: [salePriceLabel, normalPriceLabel])
priceStack.axis = .horizontal
priceStack.spacing = 8

let textStack = UIStackView(arrangedSubviews: [nameLabel, descriptionLabel, priceStack, eventBadgeStackView])
textStack.axis = .vertical
Expand Down

0 comments on commit e3c3e75

Please sign in to comment.