Manos Chorianopoulos

CouponViewController part1

......@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
1E4C4CFB2DE6014500279AAD /* CopyableLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E4C4CFA2DE6014500279AAD /* CopyableLabel.swift */; };
1E64E1832DE48E0600543217 /* MyRewardsOfferCollectionViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1E64E1822DE48E0600543217 /* MyRewardsOfferCollectionViewCell.xib */; };
1E64E1842DE48E0600543217 /* MyRewardsOfferCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E64E1812DE48E0600543217 /* MyRewardsOfferCollectionViewCell.swift */; };
1E917CD62DDF64B2002221D8 /* MyRewardsViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1E917CD52DDF64B2002221D8 /* MyRewardsViewController.xib */; };
......@@ -150,6 +151,7 @@
/* Begin PBXFileReference section */
1E108A9728A3FA9B0008B8E7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
1E4C4CFA2DE6014500279AAD /* CopyableLabel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CopyableLabel.swift; sourceTree = "<group>"; };
1E64E1812DE48E0600543217 /* MyRewardsOfferCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyRewardsOfferCollectionViewCell.swift; sourceTree = "<group>"; };
1E64E1822DE48E0600543217 /* MyRewardsOfferCollectionViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MyRewardsOfferCollectionViewCell.xib; sourceTree = "<group>"; };
1E917CD42DDF64B2002221D8 /* MyRewardsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyRewardsViewController.swift; sourceTree = "<group>"; };
......@@ -462,6 +464,7 @@
E6A77850282933340045BBA8 /* SwiftWarplyFramework */ = {
isa = PBXGroup;
children = (
1E4C4CFA2DE6014500279AAD /* CopyableLabel.swift */,
1E108A9728A3FA9B0008B8E7 /* Info.plist */,
1EA8E5B42DDF315600CD3418 /* screens */,
1EA8E5BC2DDF34FB00CD3418 /* cells */,
......@@ -926,6 +929,7 @@
1E917CD72DDF64B2002221D8 /* MyRewardsViewController.swift in Sources */,
E6A77915282933E60045BBA8 /* WLUtils.m in Sources */,
1E917CDC2DDF68C7002221D8 /* CouponViewController.swift in Sources */,
1E4C4CFB2DE6014500279AAD /* CopyableLabel.swift in Sources */,
E6A77947282933E70045BBA8 /* FMDatabaseQueue.m in Sources */,
E6A77922282933E60045BBA8 /* NSData+SSToolkitAdditions.m in Sources */,
E6A7794A282933E70045BBA8 /* FMDatabaseAdditions.m in Sources */,
......
//
// CopyableLabel.swift
// SwiftWarplyFramework
//
// Created by Manos Chorianopoulos on 26/10/22.
//
import Foundation
import UIKit
class CopyableLabel: UILabel {
override init(frame: CGRect) {
super.init(frame: frame)
sharedInit()
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
sharedInit()
}
func sharedInit() {
isUserInteractionEnabled = true
addGestureRecognizer(UILongPressGestureRecognizer(target: self, action: #selector(showMenu(sender:))))
}
@objc
func showMenu(sender: AnyObject?) {
becomeFirstResponder()
let menu = UIMenuController.shared
if !menu.isMenuVisible {
menu.setTargetRect(bounds, in: self)
menu.setMenuVisible(true, animated: true)
}
}
override var canBecomeFirstResponder: Bool {
return true
}
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
if action == #selector(UIResponderStandardEditActions.copy(_:)) {
return true
}
return false
}
override func copy(_ sender: Any?) {
let board = UIPasteboard.general
if var textToCopy = text {
if (textToCopy.contains(", ")) {
textToCopy = textToCopy.replacingOccurrences(of: ", ", with: "")
}
print(textToCopy)
board.string = textToCopy
}
// board.string = text
let menu = UIMenuController.shared
menu.setMenuVisible(false, animated: true)
}
}
......@@ -8,13 +8,125 @@
import UIKit
@objc public class CouponViewController: UIViewController {
@IBOutlet weak var couponImage: UIImageView!
@IBOutlet weak var infoView: UIView!
@IBOutlet weak var infoImage: UIImageView!
@IBOutlet weak var infoLabel: UILabel!
@IBOutlet weak var favoriteImage: UIImageView!
@IBOutlet weak var shareImage: UIImageView!
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var subtitleLabel: UILabel!
@IBOutlet weak var expirationLabel: UILabel!
@IBOutlet weak var detailsLabel: UILabel!
// MARK: - IBOutlets for Coupon Code Section
@IBOutlet weak var couponCodeContainerView: UIView!
@IBOutlet weak var couponCodeHeaderView: UIView!
@IBOutlet weak var couponCodeContentView: UIView!
// Header elements
@IBOutlet weak var couponCodeTitleLabel: UILabel!
@IBOutlet weak var couponCodeArrowImage: UIImageView!
@IBOutlet weak var couponCodeButton: UIButton!
// Content elements (initially hidden)
@IBOutlet weak var couponCodeValueLabel: CopyableLabel!
@IBOutlet weak var copyButtonImage: UIImageView!
@IBOutlet weak var copyButton: UIButton!
// Constraints for animation
@IBOutlet weak var couponCodeContentHeightConstraint: NSLayoutConstraint!
// MARK: - IBOutlets for Coupon Code Section
@IBOutlet weak var couponQRContainerView: UIView!
@IBOutlet weak var couponQRHeaderView: UIView!
@IBOutlet weak var couponQRContentView: UIView!
// Header elements
@IBOutlet weak var couponQRTitleLabel: UILabel!
@IBOutlet weak var couponQRArrowImage: UIImageView!
@IBOutlet weak var couponQRButton: UIButton!
// Content elements (initially hidden)
@IBOutlet weak var couponQRImage: UIImageView!
// Constraints for animation
@IBOutlet weak var couponQRContentHeightConstraint: NSLayoutConstraint!
@IBOutlet weak var termsButton: UIButton!
@IBOutlet weak var termsLabel: UILabel!
@IBOutlet weak var termsLabelHeight: NSLayoutConstraint!
@IBOutlet weak var mapButton: UIButton!
@IBOutlet weak var websiteButton: UIButton!
var coupon: OfferModel?
private var isDetailsExpanded = false
private var isCouponCodeExpanded = false
private var isCouponBarcodeExpanded = false
private var isTermsExpanded = false
public override func viewDidLoad() {
super.viewDidLoad()
// Show navigation bar for this screen (with back button)
self.navigationController?.setNavigationBarHidden(false, animated: false)
setBackButton()
setNavigationTitle("Προσφορά")
infoView.backgroundColor = UIColor(rgb: 0xFFFFFF)
infoView.layer.cornerRadius = 10.0
infoView.layer.borderWidth = 1.0
infoView.layer.borderColor = UIColor(red: 0.01, green: 0.05, blue: 0.11, alpha: 0.19).cgColor
infoImage.image = UIImage(named: "info", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
shareImage.image = UIImage(named: "share", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
couponCodeArrowImage.image = UIImage(named: "arrow_down", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
copyButtonImage.image = UIImage(named: "copy", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
couponQRArrowImage.image = UIImage(named: "arrow_down", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
couponQRImage.image = UIImage(named: "barcode", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
infoLabel.font = UIFont(name: "PingLCG-Regular", size: 13)
infoLabel.textColor = UIColor(rgb: 0x020E1C)
infoLabel.text = "Περισσότερα"
setupExpandableDetails()
couponCodeContainerView.backgroundColor = UIColor(rgb: 0xFFFFFF)
couponCodeContainerView.layer.cornerRadius = 8.0
couponQRContainerView.backgroundColor = UIColor(rgb: 0xFFFFFF)
couponQRContainerView.layer.cornerRadius = 8.0
termsButton.titleLabel?.font = UIFont(name: "PingLCG-Bold", size: 16)
// termsButton.imageView?.layer.transform = CATransform3DMakeScale(1.5, 1.5, 1.5)
termsButton.setTitle("Όροι Χρήσης", for: .normal)
termsButton.setTitleColor(UIColor(rgb: 0x020E1C), for: .normal)
termsButton.setImage(UIImage(named: "arrow_down.png", in: MyEmptyClass.resourceBundle(), compatibleWith: nil), for: .normal)
termsButton.semanticContentAttribute = .forceRightToLeft
termsButton.tintColor = UIColor(red: 0.00, green: 0.00, blue: 0.00, alpha: 1.00)
termsButton.imageEdgeInsets = UIEdgeInsets(top: 0, left: 5, bottom: 0, right: 0);
termsButton.titleEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 5);
termsButton.imageView?.layer.transform = CATransform3DMakeScale(0.8, 0.8, 0.8)
termsLabelHeight.constant = 0
mapButton.titleLabel?.font = UIFont(name: "PingLCG-Bold", size: 16)
mapButton.setTitle("Όροι Χρήσης", for: .normal)
mapButton.setTitleColor(UIColor(rgb: 0xFFFFFF), for: .normal)
mapButton.layer.cornerRadius = 4.0
websiteButton.titleLabel?.font = UIFont(name: "PingLCG-Bold", size: 16)
websiteButton.setTitle("Όροι Χρήσης", for: .normal)
websiteButton.setTitleColor(UIColor(rgb: 0x000F1E), for: .normal)
websiteButton.backgroundColor = .clear
websiteButton.layer.borderWidth = 1
websiteButton.layer.borderColor = UIColor(rgb: 0x000F1E).cgColor
websiteButton.layer.cornerRadius = 4.0
// Configure the view with offer data
if let offer = coupon {
......@@ -23,7 +135,59 @@ import UIKit
}
private func setupUI(with coupon: OfferModel) {
// Set up the UI based on the offer data
couponImage.image = UIImage(named: coupon.bannerImage, in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
favoriteImage.image = UIImage(named: coupon.isFavorite ? "favorite2_filled" : "favorite2_empty", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
titleLabel.font = UIFont(name: "PingLCG-Bold", size: 24)
titleLabel.textColor = UIColor(rgb: 0xF2709D)
titleLabel.text = coupon.title
subtitleLabel.font = UIFont(name: "PingLCG-Regular", size: 18)
subtitleLabel.textColor = UIColor(rgb: 0x020E1C)
subtitleLabel.text = coupon.description
expirationLabel.font = UIFont(name: "PingLCG-Regular", size: 18)
expirationLabel.textColor = UIColor(rgb: 0x020E1C)
// expirationLabel.text = ("Η προσφορά ισχύει " + coupon.expirationDate)
expirationLabel.text = "Η προσφορά ισχύει έως 30-09-2025"
couponCodeTitleLabel.font = UIFont(name: "PingLCG-Regular", size: 16)
couponCodeTitleLabel.textColor = UIColor(rgb: 0x000F1E)
couponCodeTitleLabel.text = "Κωδικός Κουπονιού"
couponCodeTitleLabel.font = UIFont(name: "PingLCG-Bold", size: 24)
couponCodeTitleLabel.textColor = UIColor(rgb: 0x000F1E)
couponCodeTitleLabel.text = "coupons_ab"
couponCodeTitleLabel.font = UIFont(name: "PingLCG-Regular", size: 16)
couponCodeTitleLabel.textColor = UIColor(rgb: 0x000F1E)
couponCodeTitleLabel.text = "QR Κουπονιού"
termsLabel.font = UIFont(name: "PingLCG-Regular", size: 16)
termsLabel.textColor = UIColor(rgb: 0x020E1C)
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."
}
private func setupExpandableDetails() {
let fullText = "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."
detailsLabel.text = fullText
detailsLabel.numberOfLines = 3
detailsLabel.font = UIFont(name: "PingLCG-Regular", size: 18)
detailsLabel.textColor = UIColor(rgb: 0x020E1C)
// Add tap gesture
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(toggleDetailsExpansion))
detailsLabel.isUserInteractionEnabled = true
detailsLabel.addGestureRecognizer(tapGesture)
}
@objc private func toggleDetailsExpansion() {
isDetailsExpanded.toggle()
UIView.animate(withDuration: 0.3) {
self.detailsLabel.numberOfLines = self.isDetailsExpanded ? 0 : 3
self.view.layoutIfNeeded()
}
}
}
......