Manos Chorianopoulos

add SM Coupons to UnifiedCouponsViewController

......@@ -7,7 +7,7 @@
<key>Pods-SwiftWarplyFramework.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
<integer>0</integer>
</dict>
</dict>
</dict>
......
......@@ -7,7 +7,7 @@
<key>SwiftWarplyFramework.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
<integer>1</integer>
</dict>
</dict>
</dict>
......
......@@ -20,12 +20,32 @@ import UIKit
@IBOutlet weak var expirationRedImage: UIImageView!
@IBOutlet weak var expirationRedLabel: UILabel!
// Variables for the view, image, and button
var selectView: UIView!
var selectImageView: UIImageView!
var selectButton: UIButton!
// Boolean to track if the selectView should be visible
var isSelectViewVisible: Bool = false {
didSet {
selectView.isHidden = !isSelectViewVisible
}
}
// Boolean to track the selection state of the cell
var isSelectedCell: Bool = false {
didSet {
updateSelectionState()
}
}
// Action closure for button tap inside the cell
var selectButtonAction: (() -> Void)?
var postImageURL: String? {
didSet {
if let url = postImageURL {
// TODO: DELETE LOGS
print("=== postImageURL: ",url)
self.couponImage.image = UIImage() // UIImage(named: "loading")
UIImage.loadImageUsingCacheWithUrlString(url) { image in
......@@ -49,6 +69,8 @@ import UIKit
couponBgImage.image = UIImage(named: "coupon_bg_2", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
borderView.addDashedBorderVertical(color: UIColor(red: 0.62, green: 0.62, blue: 0.61, alpha: 1.00), width: 1.0, height: 110.0)
setupSelectButton()
}
public override func setSelected(_ selected: Bool, animated: Bool) {
......@@ -64,6 +86,69 @@ import UIKit
contentView.frame = contentView.frame.inset(by: margins)
}
// Setup Select Button UI and layout
func setupSelectButton() {
// Create the container view (selectView)
selectView = UIView()
selectView.translatesAutoresizingMaskIntoConstraints = false
contentView.addSubview(selectView)
// Set selectView constraints
NSLayoutConstraint.activate([
selectView.widthAnchor.constraint(equalToConstant: 26),
selectView.heightAnchor.constraint(equalToConstant: 26),
selectView.topAnchor.constraint(equalTo: contentView.topAnchor, constant: 6),
selectView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: -16)
])
// Create the UIImageView inside selectView
selectImageView = UIImageView()
selectImageView.contentMode = .scaleAspectFit
selectImageView.translatesAutoresizingMaskIntoConstraints = false
selectView.addSubview(selectImageView)
// Set imageView constraints to match the size of the selectView
NSLayoutConstraint.activate([
selectImageView.leadingAnchor.constraint(equalTo: selectView.leadingAnchor),
selectImageView.trailingAnchor.constraint(equalTo: selectView.trailingAnchor),
selectImageView.topAnchor.constraint(equalTo: selectView.topAnchor),
selectImageView.bottomAnchor.constraint(equalTo: selectView.bottomAnchor)
])
// Create the transparent button on top of the imageView
selectButton = UIButton(type: .custom)
selectButton.backgroundColor = .clear // Make the button transparent
selectButton.translatesAutoresizingMaskIntoConstraints = false
selectButton.addTarget(self, action: #selector(selectButtonTapped), for: .touchUpInside)
selectView.addSubview(selectButton)
// Set button constraints to match the size of the selectView
NSLayoutConstraint.activate([
selectButton.leadingAnchor.constraint(equalTo: selectView.leadingAnchor),
selectButton.trailingAnchor.constraint(equalTo: selectView.trailingAnchor),
selectButton.topAnchor.constraint(equalTo: selectView.topAnchor),
selectButton.bottomAnchor.constraint(equalTo: selectView.bottomAnchor)
])
// Initially hide the selectView (selectView)
selectView.isHidden = true
}
// Button action handler
@objc func selectButtonTapped() {
// Trigger the action closure when the button is pressed
selectButtonAction?()
}
// Update the cell's appearance based on selection state
func updateSelectionState() {
// Update the image based on the new state
if (isSelectedCell) {
selectImageView.image = UIImage(named: "circle_checked", in: MyEmptyClass.resourceBundle(), compatibleWith: nil) // Selected image
} else {
selectImageView.image = UIImage(named: "circle_unchecked", in: MyEmptyClass.resourceBundle(), compatibleWith: nil) // Unselected image
}
}
func configureCell(coupon: swiftApi.CouponItemModel) {
// COUPONSET: desc, img_preview, name, terms, merchant_uuid, discount_type, final_price
......@@ -240,4 +325,22 @@ import UIKit
}
// Configure the cell with visibility of the selectView, a selected state, and select Button Action
func showSelectButton(isSelectViewVisible: Bool, isSelected: Bool, buttonAction: @escaping () -> Void) {
self.isSelectViewVisible = isSelectViewVisible
self.isSelectedCell = isSelected
self.selectButtonAction = buttonAction
if (isSelected) {
couponBgImage.image = UIImage(named: "coupon_bg_2_selected", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
} else {
couponBgImage.image = UIImage(named: "coupon_bg_2", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
}
// Set nameLabel constraints to not overlap selectView
NSLayoutConstraint.activate([
nameLabel.trailingAnchor.constraint(equalTo: selectView.leadingAnchor, constant: -5)
])
}
}
......