Manos Chorianopoulos

CouponsetViewController redesign

......@@ -8,6 +8,31 @@
import UIKit
extension UIViewController {
func addFloatingBackButton(icon: String = "ic_back_3") {
let button = UIButton(type: .custom)
button.translatesAutoresizingMaskIntoConstraints = false
button.backgroundColor = .white
button.layer.cornerRadius = 20
button.layer.shadowColor = UIColor.black.cgColor
button.layer.shadowOpacity = 0.1
button.layer.shadowOffset = CGSize(width: 0, height: 2)
button.layer.shadowRadius = 4
if let img = UIImage(named: icon, in: Bundle.frameworkResourceBundle, compatibleWith: nil) {
button.setImage(img, for: .normal)
}
button.addTarget(self, action: #selector(moveToBack(_:)), for: .touchUpInside)
self.view.addSubview(button)
NSLayoutConstraint.activate([
button.widthAnchor.constraint(equalToConstant: 40),
button.heightAnchor.constraint(equalToConstant: 40),
button.leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant: 16),
button.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor, constant: 16)
])
}
func setBackButton(_ icon:String = "ic_back_3") {
// let uiscreen: CGRect = UIScreen.main.bounds
......@@ -247,6 +272,20 @@ extension UIView {
lineLayer.path = path
self.layer.addSublayer(lineLayer)
}
func addDashedBorder(color: UIColor, lineWidth: CGFloat = 1, dash: CGFloat = 3, gap: CGFloat = 3) {
// Remove any existing dashed border layer to avoid duplicates on re-layout
layer.sublayers?.removeAll(where: { $0.name == "dashedBorderLayer" })
let shapeLayer = CAShapeLayer()
shapeLayer.name = "dashedBorderLayer"
shapeLayer.strokeColor = color.cgColor
shapeLayer.fillColor = UIColor.clear.cgColor
shapeLayer.lineWidth = lineWidth
shapeLayer.lineDashPattern = [dash as NSNumber, gap as NSNumber]
shapeLayer.path = UIBezierPath(rect: bounds).cgPath
layer.addSublayer(shapeLayer)
}
}
extension UIImageView {
......
......@@ -30,8 +30,10 @@ import UIKit
@IBOutlet weak var favoriteImage: UIImageView!
@IBOutlet weak var shareImage: UIImageView!
@IBOutlet weak var merchantNameLabel: UILabel!
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var subtitleLabel: UILabel!
@IBOutlet weak var expirationView: UIView!
@IBOutlet weak var expirationLabel: UILabel!
@IBOutlet weak var detailsLabel: UILabel!
......@@ -75,9 +77,19 @@ import UIKit
super.viewDidLoad()
// Show navigation bar for this screen (with back button)
self.navigationController?.setNavigationBarHidden(false, animated: false)
setBackButton()
setNavigationTitle("Προσφορά")
// self.navigationController?.setNavigationBarHidden(false, animated: false)
// setBackButton()
// setNavigationTitle("Προσφορά")
self.navigationController?.setNavigationBarHidden(true, animated: false)
addFloatingBackButton()
for label in [merchantNameLabel, titleLabel, subtitleLabel, expirationLabel, detailsLabel] {
label?.setContentHuggingPriority(.defaultHigh, for: .vertical)
}
couponImage.backgroundColor = UIColor(rgb: 0x00A3E033)
infoView.backgroundColor = UIColor(rgb: 0xFFFFFF)
infoView.layer.cornerRadius = 10.0
......@@ -92,18 +104,26 @@ import UIKit
infoLabel.textColor = UIColor(rgb: 0x020E1C)
infoLabel.text = "Περισσότερα"
termsButtonTitleLabel.font = UIFont(name: "PingLCG-Bold", size: 16)
termsButtonTitleLabel.textColor = UIColor(rgb: 0x020E1C)
termsButtonTitleLabel.text = "Όροι Χρήσης"
expirationView.backgroundColor = UIColor(rgb: 0xDDEFFB)
expirationView.layer.cornerRadius = 6.0
expirationView.layer.borderWidth = 1.0
expirationView.layer.borderColor = UIColor(rgb: 0xCCE9FB).cgColor
termsButtonTitleLabel.font = UIFont(name: "PingLCG-Bold", size: 15)
termsButtonTitleLabel.textColor = UIColor(rgb: 0x5C6369)
// termsButtonTitleLabel.text = "Όροι Χρήσης"
termsButtonTitleLabel.text = "Offer terms of use"
termsButton.addTarget(self, action: #selector(toggleTerms), for: .touchUpInside)
termsLabelHeight.constant = 0
redeemButton.titleLabel?.font = UIFont(name: "PingLCG-Bold", size: 16)
redeemButton.setTitle("Απόκτησε το κουπόνι", for: .normal)
redeemButton.titleLabel?.font = UIFont(name: "PingLCG-Regular", size: 16)
// redeemButton.setTitle("Απόκτησε το κουπόνι", for: .normal)
redeemButton.setTitle("Get coupon", for: .normal)
redeemButton.setTitleColor(UIColor(rgb: 0xFFFFFF), for: .normal)
redeemButton.setTitleColor(UIColor(rgb: 0xFFFFFF), for: .highlighted)
redeemButton.layer.cornerRadius = 4.0
redeemButton.backgroundColor = UIColor(rgb: 0x000F1E)
redeemButton.layer.cornerRadius = redeemButton.bounds.height / 2
// redeemButton.backgroundColor = UIColor(rgb: 0x000F1E)
redeemButton.backgroundColor = UIColor(rgb: 0x00A3E0)
redeemButton.addTarget(self, action: #selector(redeemButtonTapped), for: .touchUpInside)
// Configure the view with offer data
......@@ -112,6 +132,28 @@ import UIKit
}
}
public override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
redeemButton.layer.cornerRadius = redeemButton.bounds.height / 2
couponImage.addDashedBorder(
color: UIColor(rgb: 0x00A3E033),
lineWidth: 1,
dash: 3,
gap: 3
)
}
public override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
self.navigationController?.setNavigationBarHidden(true, animated: animated)
}
public override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
self.navigationController?.setNavigationBarHidden(false, animated: animated)
}
@objc private func redeemButtonTapped() {
guard let couponSetUuid = couponset?._uuid, !couponSetUuid.isEmpty else {
showErrorAlert(message: "Δεν βρέθηκε το αναγνωριστικό της προσφοράς.")
......@@ -216,23 +258,28 @@ import UIKit
// Default to not favorite for coupon sets
favoriteImage.image = UIImage(named: "favorite2_empty", in: Bundle.frameworkResourceBundle, compatibleWith: nil)
merchantNameLabel.font = UIFont(name: "PingLCG-Bold", size: 15)
merchantNameLabel.textColor = UIColor(rgb: 0x9BA1A6)
merchantNameLabel.text = couponset._merchant?._name
titleLabel.font = UIFont(name: "PingLCG-Bold", size: 24)
titleLabel.textColor = UIColor(rgb: 0xF2709D)
titleLabel.textColor = UIColor(rgb: 0x000F1E)
titleLabel.text = couponset._name
subtitleLabel.font = UIFont(name: "PingLCG-Regular", size: 18)
subtitleLabel.textColor = UIColor(rgb: 0x020E1C)
subtitleLabel.textColor = UIColor(rgb: 0x000F1E)
subtitleLabel.text = couponset._short_description
expirationLabel.font = UIFont(name: "PingLCG-Regular", size: 14)
expirationLabel.textColor = UIColor(rgb: 0x020E1C)
expirationLabel.text = ("Η προσφορά ισχύει έως " + couponset.formattedEndDate(format: "dd-MM-yyyy"))
expirationLabel.font = UIFont(name: "PingLCG-Bold", size: 13)
expirationLabel.textColor = UIColor(rgb: 0x002430)
expirationLabel.text = ("Valid until " + couponset.formattedEndDate(format: "MMMM d, yyyy"))
// expirationLabel.text = ("Η προσφορά ισχύει έως " + couponset.formattedEndDate(format: "dd-MM-yyyy"))
// expirationLabel.text = "Η προσφορά ισχύει έως 30-09-2025"
setupExpandableDetails()
termsLabel.font = UIFont(name: "PingLCG-Regular", size: 16)
termsLabel.textColor = UIColor(rgb: 0x020E1C)
termsLabel.font = UIFont(name: "PingLCG-Regular", size: 15)
termsLabel.textColor = UIColor(rgb: 0x5C6369)
// termsLabel.text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas sed ex euismod, feugiat justo eu, faucibus urna. Nulla sodales euismod arcu volutpat finibus. Etiam id urna at justo facilisis tempor. Morbi dignissim erat vitae magna sodales dignissim ac in mauris. Mauris tempor convallis tortor, interdum hendrerit turpis eleifend at. Praesent."
termsLabel.text = couponset._terms
}
......@@ -244,8 +291,8 @@ import UIKit
// fullDetailsText = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas sed ex euismod, feugiat justo eu, faucibus urna. Nulla sodales euismod arcu volutpat finibus. Etiam id urna at justo facilisis tempor. Morbi dignissim erat vitae magna sodales dignissim ac in mauris. Mauris tempor convallis tortor, interdum hendrerit turpis eleifend at. Praesent."
fullDetailsText = couponset?._description ?? ""
detailsLabel.font = UIFont(name: "PingLCG-Regular", size: 18)
detailsLabel.textColor = UIColor(rgb: 0x020E1C)
detailsLabel.font = UIFont(name: "PingLCG-Regular", size: 16)
detailsLabel.textColor = UIColor(rgb: 0x5C6369)
updateDetailsText()
......@@ -258,8 +305,11 @@ import UIKit
if isDetailsExpanded {
// Show full text with "Λιγότερα"
if (shouldTruncaitDetails) {
let fullTextWithLess = fullDetailsText + " Λιγότερα"
let attributedString = createAttributedString(text: fullTextWithLess, linkText: "Λιγότερα")
// let fullTextWithLess = fullDetailsText + " Λιγότερα"
// let attributedString = createAttributedString(text: fullTextWithLess, linkText: "Λιγότερα")
let fullTextWithLess = fullDetailsText + " View less"
let attributedString = createAttributedString(text: fullTextWithLess, linkText: "View less")
detailsLabel.attributedText = attributedString
} else {
detailsLabel.text = fullDetailsText
......@@ -267,8 +317,10 @@ import UIKit
detailsLabel.numberOfLines = 0
} else {
// Calculate approximate characters for 4 lines and truncate if needed
// let truncatedText = getTruncatedTextForFourLines()
// let attributedString = createAttributedString(text: truncatedText, linkText: "Περισσότερα")
let truncatedText = getTruncatedTextForFourLines()
let attributedString = createAttributedString(text: truncatedText, linkText: "Περισσότερα")
let attributedString = createAttributedString(text: truncatedText, linkText: "View more")
detailsLabel.attributedText = attributedString
detailsLabel.numberOfLines = 4
}
......@@ -282,7 +334,8 @@ import UIKit
let charactersPerLine = Int(labelWidth / averageCharWidth)
let maxCharactersFor4Lines = charactersPerLine * 4
let moreText = " Περισσότερα"
// let moreText = " Περισσότερα"
let moreText = " View more"
let ellipsis = "..."
let reservedCharacters = ellipsis.count + moreText.count + 15
......@@ -307,14 +360,14 @@ import UIKit
// Regular text attributes
let regularAttributes: [NSAttributedString.Key: Any] = [
.font: UIFont(name: "PingLCG-Regular", size: 18) ?? UIFont.systemFont(ofSize: 18),
.foregroundColor: UIColor(rgb: 0x020E1C)
.font: UIFont(name: "PingLCG-Regular", size: 16) ?? UIFont.systemFont(ofSize: 16),
.foregroundColor: UIColor(rgb: 0x5C6369)
]
// Link text attributes (blue color)
let linkAttributes: [NSAttributedString.Key: Any] = [
.font: UIFont(name: "PingLCG-Regular", size: 18) ?? UIFont.systemFont(ofSize: 18),
.foregroundColor: UIColor(rgb: 0x00A8E8) // Blue color
.font: UIFont(name: "PingLCG-Bold", size: 16) ?? UIFont.systemFont(ofSize: 16),
.foregroundColor: UIColor(rgb: 0x1D2023) // Blue color
]
// Apply regular attributes to entire text
......