Showing
5 changed files
with
237 additions
and
3 deletions
No preview for this file type
... | @@ -8,10 +8,172 @@ | ... | @@ -8,10 +8,172 @@ |
8 | import UIKit | 8 | import UIKit |
9 | 9 | ||
10 | class ActiveCodeTableViewCell: UITableViewCell { | 10 | class ActiveCodeTableViewCell: UITableViewCell { |
11 | + @IBOutlet weak var activeCodeView: UIView! | ||
12 | + @IBOutlet weak var activeCodeViewHeight: NSLayoutConstraint! | ||
13 | + @IBOutlet weak var activeCodesCountLabel: UILabel! | ||
14 | + @IBOutlet weak var activeCodeLabel: UILabel! | ||
15 | + @IBOutlet weak var activeCodeExpirationLabel: UILabel! | ||
16 | + @IBOutlet weak var activeCodeImage: UIImageView! | ||
17 | + @IBOutlet weak var activeCodeScrollView: UIScrollView! | ||
18 | + @IBOutlet weak var activeCodeScrollViewHeight: NSLayoutConstraint! | ||
19 | + @IBOutlet weak var activeCodeContentView: UIView! | ||
20 | + @IBOutlet weak var activeCodeContentViewHeight: NSLayoutConstraint! | ||
21 | + | ||
22 | + public var dfyCoupons:Array<swiftApi.ActiveDFYCouponModel> = swiftApi().getActiveDFYCoupons() | ||
11 | 23 | ||
12 | override func awakeFromNib() { | 24 | override func awakeFromNib() { |
13 | super.awakeFromNib() | 25 | super.awakeFromNib() |
14 | - // Initialization code | 26 | + |
27 | + // TODO: DELETE ===> | ||
28 | + // let coupon = swiftApi.ActiveDFYCouponModel() | ||
29 | + // coupon._value = "12" | ||
30 | + // // coupon._date = "2022-12-05 01:55:01" | ||
31 | + // coupon._date = "2022-10-26 23:59:01" | ||
32 | + // coupon._code = "123456789" | ||
33 | + | ||
34 | + // let coupon2 = swiftApi.ActiveDFYCouponModel() | ||
35 | + // coupon2._value = "23" | ||
36 | + // coupon2._date = "2022-11-05 01:55" | ||
37 | + // coupon2._code = "234567891" | ||
38 | + | ||
39 | + // let coupon3 = swiftApi.ActiveDFYCouponModel() | ||
40 | + // coupon3._value = "34" | ||
41 | + // coupon3._date = "2022-07-01 01:55" | ||
42 | + // coupon3._code = "345678912" | ||
43 | + | ||
44 | + // let couponsArray: Array<swiftApi.ActiveDFYCouponModel> = [coupon, coupon2, coupon3, coupon3, coupon3] | ||
45 | + | ||
46 | + // swiftApi().setActiveDFYCoupons(dfyCoupons: couponsArray) | ||
47 | + | ||
48 | + // dfyCoupons = swiftApi().getActiveDFYCoupons() | ||
49 | + // TODO: DELETE <=== | ||
50 | + | ||
51 | + activeCodeView.layer.cornerRadius = 5.0 | ||
52 | + activeCodeView.layer.shadowColor = UIColor(red: 0.00, green: 0.00, blue: 0.00, alpha: 0.16).cgColor | ||
53 | + activeCodeView.layer.shadowOffset = CGSize(width: 0.0, height: 0.0) | ||
54 | + activeCodeView.layer.shadowOpacity = 1.0 | ||
55 | + activeCodeView.layer.shadowRadius = 6.0 | ||
56 | + | ||
57 | + activeCodeImage.image = UIImage(named: "active_code_logo", in: MyEmptyClass.resourceBundle(), compatibleWith: nil) | ||
58 | + | ||
59 | + if (dfyCoupons.count > 0) { | ||
60 | + if (dfyCoupons.count == 1) { | ||
61 | + let dateFormatter = DateFormatter() | ||
62 | + dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss" | ||
63 | + // dateFormatter.dateFormat = "yyyy-MM-dd HH:mm" | ||
64 | + | ||
65 | + // sort dfyCoupons by date | ||
66 | + dfyCoupons.sort(by: { | ||
67 | + let date1 = dateFormatter.date(from: $0._date) | ||
68 | + let date2 = dateFormatter.date(from: $1._date) | ||
69 | + | ||
70 | + if ((date1 != nil) && (date2 != nil)) { | ||
71 | + return date1!.compare(date2!) == .orderedAscending | ||
72 | + } else { | ||
73 | + return false | ||
74 | + } | ||
75 | + | ||
76 | + }) | ||
77 | + | ||
78 | + // Get days from now of the most recet coupon | ||
79 | + var daysFromNow = "" | ||
80 | + let calendar = Calendar.current | ||
81 | + | ||
82 | + // Replace the hour (time) of both dates with 00:00 | ||
83 | + let date1 = calendar.startOfDay(for: Date()) | ||
84 | + if let date2 = dateFormatter.date(from: dfyCoupons[0]._date) { | ||
85 | + let components = calendar.dateComponents([.day], from: date1, to: date2) | ||
86 | + daysFromNow = (components.day) != nil ? String((components.day ?? 0) + 1) : "" | ||
87 | + } | ||
88 | + | ||
89 | + activeCodesCountLabel.text = "Ενεργός κωδικός:" | ||
90 | + // activeCodeLabel.text = dfyCoupons[0]._code | ||
91 | + let newLabel = CopyableLabel() | ||
92 | + newLabel.text = String(dfyCoupons[0]._code) | ||
93 | + newLabel.font = UIFont(name: "PFSquareSansPro-Bold", size: 19) | ||
94 | + newLabel.textColor = UIColor(rgb: 0x3C5365) | ||
95 | + newLabel.frame.size.width = newLabel.intrinsicContentSize.width | ||
96 | + newLabel.frame.size.height = newLabel.intrinsicContentSize.height // tagHeight | ||
97 | + activeCodeContentView.addSubview(newLabel) | ||
98 | + // set the btn frame origin | ||
99 | + newLabel.frame.origin.x = 0 | ||
100 | + newLabel.frame.origin.y = 0 | ||
101 | + let scrollHeight = newLabel.intrinsicContentSize.height | ||
102 | + activeCodeContentViewHeight.constant = scrollHeight | ||
103 | + activeCodeScrollViewHeight.constant = scrollHeight | ||
104 | + | ||
105 | + activeCodeExpirationLabel.isHidden = false | ||
106 | + if (daysFromNow == "1") { | ||
107 | + activeCodeExpirationLabel.text = "Λήγει σε " + daysFromNow + " ημέρα" | ||
108 | + } else { | ||
109 | + activeCodeExpirationLabel.text = "Λήγει σε " + daysFromNow + " ημέρες" | ||
110 | + } | ||
111 | + | ||
112 | + } else { | ||
113 | + var tagHeight:CGFloat = 30 | ||
114 | + let tagPadding: CGFloat = 0 | ||
115 | + let tagSpacingX: CGFloat = 0 | ||
116 | + let tagSpacingY: CGFloat = 2 | ||
117 | + | ||
118 | + let containerWidth = activeCodeContentView.frame.size.width | ||
119 | + | ||
120 | + var currentOriginX: CGFloat = 0 | ||
121 | + var currentOriginY: CGFloat = 0 | ||
122 | + | ||
123 | + // var couponCodesString = "" | ||
124 | + for (index, item) in dfyCoupons.enumerated() { | ||
125 | + let newLabel = CopyableLabel() | ||
126 | + newLabel.font = UIFont(name: "PFSquareSansPro-Bold", size: 19) | ||
127 | + newLabel.textColor = UIColor(rgb: 0x3C5365) | ||
128 | + | ||
129 | + if (index == (dfyCoupons.endIndex - 1)) { | ||
130 | + // couponCodesString += String(item._code) | ||
131 | + newLabel.text = String(item._code) | ||
132 | + } else { | ||
133 | + // couponCodesString += String(item._code) + ", " | ||
134 | + newLabel.text = String(item._code) + ", " | ||
135 | + } | ||
136 | + | ||
137 | + newLabel.frame.size.width = newLabel.intrinsicContentSize.width + tagPadding | ||
138 | + newLabel.frame.size.height = newLabel.intrinsicContentSize.height // tagHeight | ||
139 | + tagHeight = newLabel.intrinsicContentSize.height | ||
140 | + activeCodeContentView.addSubview(newLabel) | ||
141 | + | ||
142 | + // if current X + label width will be greater than container view width | ||
143 | + // "move to next row" | ||
144 | + if currentOriginX + newLabel.frame.width > containerWidth { | ||
145 | + currentOriginX = 0 | ||
146 | + currentOriginY += tagHeight + tagSpacingY | ||
147 | + } | ||
148 | + | ||
149 | + // set the btn frame origin | ||
150 | + newLabel.frame.origin.x = currentOriginX | ||
151 | + newLabel.frame.origin.y = currentOriginY | ||
152 | + | ||
153 | + // increment current X by btn width + spacing | ||
154 | + currentOriginX += newLabel.frame.width + tagSpacingX | ||
155 | + } | ||
156 | + | ||
157 | + activeCodesCountLabel.text = String(dfyCoupons.count) + " Ενεργοί κωδικοί:" | ||
158 | + // activeCodeLabel.text = couponCodesString | ||
159 | + activeCodeExpirationLabel.isHidden = true | ||
160 | + | ||
161 | + // update container view height | ||
162 | + activeCodeContentViewHeight.constant = currentOriginY + tagHeight | ||
163 | + if ((currentOriginY + tagHeight) <= (2 * tagHeight + tagSpacingY)) { | ||
164 | + activeCodeScrollViewHeight.constant = currentOriginY + tagHeight | ||
165 | + } else { | ||
166 | + activeCodeScrollViewHeight.constant = 2 * tagHeight + tagSpacingY | ||
167 | + } | ||
168 | + } | ||
169 | + } else { | ||
170 | + activeCodeLabel.text = "-" | ||
171 | + activeCodeExpirationLabel.text = "" | ||
172 | + | ||
173 | + activeCodeView.isHidden = true | ||
174 | + | ||
175 | + activeCodeViewHeight.constant = 0 | ||
176 | + } | ||
15 | } | 177 | } |
16 | 178 | ||
17 | override func setSelected(_ selected: Bool, animated: Bool) { | 179 | override func setSelected(_ selected: Bool, animated: Bool) { | ... | ... |
This diff is collapsed. Click to expand it.
... | @@ -5,19 +5,91 @@ | ... | @@ -5,19 +5,91 @@ |
5 | // Created by Manos Chorianopoulos on 3/4/23. | 5 | // Created by Manos Chorianopoulos on 3/4/23. |
6 | // | 6 | // |
7 | 7 | ||
8 | +import Foundation | ||
8 | import UIKit | 9 | import UIKit |
9 | 10 | ||
10 | class UnifiedCouponsTableViewCell: UITableViewCell { | 11 | class UnifiedCouponsTableViewCell: UITableViewCell { |
12 | + @IBOutlet weak var couponBgImage: UIImageView! | ||
13 | + @IBOutlet weak var couponImage: UIImageView! | ||
14 | + @IBOutlet weak var borderView: UIView! | ||
15 | + @IBOutlet weak var nameLabel: UILabel! | ||
16 | + @IBOutlet weak var dicountLabel: UILabel! | ||
17 | + @IBOutlet weak var discriptionLabel: UILabel! | ||
18 | + @IBOutlet weak var expirationLabel: UILabel! | ||
19 | + | ||
20 | + var postImageURL: String? { | ||
21 | + didSet { | ||
22 | + if let url = postImageURL { | ||
23 | + self.couponImage.image = UIImage() // UIImage(named: "loading") | ||
11 | 24 | ||
12 | - override func awakeFromNib() { | 25 | + UIImage.loadImageUsingCacheWithUrlString(url) { image in |
26 | + // set the image only when we are still displaying the content for the image we finished downloading | ||
27 | + if url == self.postImageURL { | ||
28 | + self.couponImage.image = image | ||
29 | + } | ||
30 | + } | ||
31 | + } | ||
32 | + else { | ||
33 | + self.couponImage.image = nil | ||
34 | + } | ||
35 | + } | ||
36 | + } | ||
37 | + | ||
38 | + | ||
39 | + public override func awakeFromNib() { | ||
13 | super.awakeFromNib() | 40 | super.awakeFromNib() |
14 | // Initialization code | 41 | // Initialization code |
42 | + | ||
43 | + couponBgImage.image = UIImage(named: "coupon_bg", in: MyEmptyClass.resourceBundle(), compatibleWith: nil) | ||
44 | + | ||
45 | + borderView.addDashedBorderVertical(color: UIColor(red: 0.44, green: 0.44, blue: 0.44, alpha: 1.00), width: 1.0, height: 110.0) | ||
15 | } | 46 | } |
16 | 47 | ||
17 | - override func setSelected(_ selected: Bool, animated: Bool) { | 48 | + public override func setSelected(_ selected: Bool, animated: Bool) { |
18 | super.setSelected(selected, animated: animated) | 49 | super.setSelected(selected, animated: animated) |
19 | 50 | ||
20 | // Configure the view for the selected state | 51 | // Configure the view for the selected state |
21 | } | 52 | } |
53 | + | ||
54 | + public override func layoutSubviews() { | ||
55 | + super.layoutSubviews() | ||
56 | + //set the values for top,left,bottom,right margins | ||
57 | + let margins = UIEdgeInsets(top: 0, left: 0, bottom: 8, right: 0) | ||
58 | + contentView.frame = contentView.frame.inset(by: margins) | ||
59 | + } | ||
60 | + | ||
61 | + | ||
62 | + func configureCell(coupon: swiftApi.CouponItemModel) { | ||
63 | +// COUPONSET: desc, img_preview, name, terms, merchant_uuid, discount_type, final_price | ||
64 | +// COUPON: coupon, expiration, discount, status | ||
65 | +// MERCHANT: _img_preview,_admin_name | ||
66 | + | ||
67 | + let merchantList:Array<swiftApi.MerchantModel> = swiftApi().getMerchantList() | ||
68 | + | ||
69 | + let couponSetData: swiftApi.CouponSetItemModel? = coupon.couponset_data | ||
70 | + | ||
71 | + nameLabel.text = "" | ||
72 | + | ||
73 | + for merchant in merchantList { | ||
74 | + if (merchant._uuid == couponSetData?.merchant_uuid) { | ||
75 | + // couponImage.load(link: merchant._img_preview, placeholder: UIImage(), cache: URLCache()) | ||
76 | + self.postImageURL = merchant._img_preview | ||
77 | + nameLabel.text = merchant._admin_name | ||
78 | + break; | ||
79 | + } | ||
80 | + } | ||
81 | + | ||
82 | +// couponImage.load(link: couponSetData?.img_preview ?? "", placeholder: UIImage(), cache: URLCache()) | ||
83 | +// nameLabel.text = couponSetData?.name ?? "" | ||
84 | + let discount = couponSetData?.discount_type == "value" ? ((coupon.discount ?? "") + "€") | ||
85 | + : couponSetData?.discount_type == "percentage" ? ((coupon.discount ?? "") + "%") | ||
86 | + : couponSetData?.discount_type == "plus_one" ? "1+1" | ||
87 | + : ((coupon.discount ?? "") + "€") | ||
88 | + dicountLabel.text = discount | ||
89 | + // let htmlText = couponSetData?.inner_text ?? "" | ||
90 | + // discriptionLabel.text = htmlText.htmlToString | ||
91 | + discriptionLabel.text = couponSetData?.inner_text ?? "" | ||
92 | + expirationLabel.text = "Ισχύει έως "+(coupon.expiration ?? "") | ||
93 | + } | ||
22 | 94 | ||
23 | } | 95 | } | ... | ... |
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment