WalletBannersTableViewCell.swift
12.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
//
// WalletBannersTableViewCell.swift
// SwiftWarplyFramework
//
// Created by Manos Chorianopoulos on 24/4/23.
//
import UIKit
@objc public class WalletBannersTableViewCell: UITableViewCell {
@IBOutlet weak var sumBannerArrowImage: UIImageView!
@IBOutlet weak var sumBannerInnerView: UIView!
@IBOutlet weak var sumBadgeImage: UIImageView!
@IBOutlet weak var sumBadgeLabel: UILabel!
@IBOutlet weak var sumBannerLabel: UILabel!
@IBOutlet weak var dfyBannerView: UIView!
@IBOutlet weak var dfyBannerHeight: NSLayoutConstraint!
@IBOutlet weak var dfyBannerTopSpace: NSLayoutConstraint!
@IBOutlet weak var dfyBannerInnerView: UIView!
@IBOutlet weak var dfyBadgeImage: UIImageView!
@IBOutlet weak var dfyBadgeLabel: UILabel!
@IBOutlet weak var dfyBannerLabel: UILabel!
@IBOutlet weak var gfyBannerView: UIView!
@IBOutlet weak var gfyBannerHeight: NSLayoutConstraint!
@IBOutlet weak var gfyBannerTopSpace: NSLayoutConstraint!
@IBOutlet weak var gfyBannerInnerView: UIView!
@IBOutlet weak var couponBadgeImage: UIImageView!
@IBOutlet weak var couponBadgeLabel: UILabel!
@IBOutlet weak var gfyBannerLabel: UILabel!
@IBOutlet weak var marketBannerView: UIView!
@IBOutlet weak var marketBannerHeight: NSLayoutConstraint!
@IBOutlet weak var marketBannerTopSpace: NSLayoutConstraint!
@IBOutlet weak var marketBannerInnerView: UIView!
@IBOutlet weak var marketBadgeImage: UIImageView!
@IBOutlet weak var marketBadgeLabel: UILabel!
@IBOutlet weak var marketBannerLabel: UILabel!
public var loyaltyBadge:swiftApi.LoyaltyBadgeModel = swiftApi().getLoyaltyBadge()
public override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
sumBadgeImage.image = UIImage(named: "wallet_summary_2", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
dfyBadgeImage.image = UIImage(named: "wallet_dfy_3", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
couponBadgeImage.image = UIImage(named: "wallet_coupons_4", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
marketBadgeImage.image = UIImage(named: "wallet_market_2", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
sumBannerInnerView.layer.cornerRadius = 16.5
// sumBannerInnerView.layer.borderWidth = 1
// sumBannerInnerView.layer.borderColor = UIColor(red: 0.90, green: 0.90, blue: 0.90, alpha: 1.00).cgColor
dfyBannerInnerView.layer.cornerRadius = 16.5
// dfyBannerInnerView.layer.borderWidth = 1
// dfyBannerInnerView.layer.borderColor = UIColor(red: 0.90, green: 0.90, blue: 0.90, alpha: 1.00).cgColor
gfyBannerInnerView.layer.cornerRadius = 16.5
// gfyBannerInnerView.layer.borderWidth = 1
// gfyBannerInnerView.layer.borderColor = UIColor(red: 0.90, green: 0.90, blue: 0.90, alpha: 1.00).cgColor
marketBannerInnerView.layer.cornerRadius = 16.5
// marketBannerInnerView.layer.borderWidth = 1
// marketBannerInnerView.layer.borderColor = UIColor(red: 0.90, green: 0.90, blue: 0.90, alpha: 1.00).cgColor
// Add shadow
sumBannerInnerView.layer.shadowColor = UIColor(red: 0.00, green: 0.00, blue: 0.00, alpha: 0.2).cgColor
sumBannerInnerView.layer.shadowOffset = CGSize(width: 0.0, height: 1.0)
sumBannerInnerView.layer.shadowOpacity = 1.0
sumBannerInnerView.layer.shadowRadius = 1.0
dfyBannerInnerView.layer.shadowColor = UIColor(red: 0.00, green: 0.00, blue: 0.00, alpha: 0.2).cgColor
dfyBannerInnerView.layer.shadowOffset = CGSize(width: 0.0, height: 1.0)
dfyBannerInnerView.layer.shadowOpacity = 1.0
dfyBannerInnerView.layer.shadowRadius = 1.0
gfyBannerInnerView.layer.shadowColor = UIColor(red: 0.00, green: 0.00, blue: 0.00, alpha: 0.2).cgColor
gfyBannerInnerView.layer.shadowOffset = CGSize(width: 0.0, height: 1.0)
gfyBannerInnerView.layer.shadowOpacity = 1.0
gfyBannerInnerView.layer.shadowRadius = 1.0
marketBannerInnerView.layer.shadowColor = UIColor(red: 0.00, green: 0.00, blue: 0.00, alpha: 0.2).cgColor
marketBannerInnerView.layer.shadowOffset = CGSize(width: 0.0, height: 1.0)
marketBannerInnerView.layer.shadowOpacity = 1.0
marketBannerInnerView.layer.shadowRadius = 1.0
dfyBannerView.isHidden = true
dfyBannerHeight.constant = 0.0
dfyBannerTopSpace.constant = 0.0
gfyBannerView.isHidden = true
gfyBannerHeight.constant = 0.0
gfyBannerTopSpace.constant = 0.0
marketBannerView.isHidden = true
marketBannerHeight.constant = 0.0
marketBannerTopSpace.constant = 0.0
}
public override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
// public override func layoutSubviews() {
// super.layoutSubviews()
// //set the values for top,left,bottom,right margins
// let margins = UIEdgeInsets(top: 0, left: 0, bottom: 4, right: 0)
// contentView.frame = contentView.frame.inset(by: margins)
// }
func configureCell(totalCouponValue: Float, totalCouponDiscount: Float, unifiedCouponsDiscount: Float, forYouExpanded: Bool) {
loyaltyBadge = swiftApi().getLoyaltyBadge()
if (forYouExpanded == false) {
sumBannerArrowImage.image = UIImage(named: "ic_down_dark_2", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
dfyBannerView.isHidden = true
dfyBannerHeight.constant = 0.0
dfyBannerTopSpace.constant = 0.0
gfyBannerView.isHidden = true
gfyBannerHeight.constant = 0.0
gfyBannerTopSpace.constant = 0.0
marketBannerView.isHidden = true
marketBannerHeight.constant = 0.0
marketBannerTopSpace.constant = 0.0
} else {
sumBannerArrowImage.image = UIImage(named: "ic_up_dark_2", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
dfyBannerView.isHidden = false
dfyBannerHeight.constant = 80.0
dfyBannerTopSpace.constant = 8.0
gfyBannerView.isHidden = false
gfyBannerHeight.constant = 80.0
gfyBannerTopSpace.constant = 8.0
marketBannerView.isHidden = false
marketBannerHeight.constant = 80.0
marketBannerTopSpace.constant = 8.0
}
if (totalCouponValue == 0.0 && loyaltyBadge._couponCount == 0 && unifiedCouponsDiscount == 0.0) {
sumBannerArrowImage.isHidden = true
} else {
sumBannerArrowImage.isHidden = false
}
// ===
let sumRewards = totalCouponValue + totalCouponDiscount + unifiedCouponsDiscount
// if (sumRewards == 0.0) {
// sumBannerArrowImage.isHidden = true
// } else {
// sumBannerArrowImage.isHidden = false
// }
// sumRewards = Float(round(100 * sumRewards) / 100)
var sumRewardsString = "0"
sumRewardsString = String(format: "%.2f", sumRewards).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
sumBadgeLabel.text = sumRewardsString + "€"
let sumRewardsIntCount = String(Int(sumRewards)).count
if (sumRewardsIntCount >= 3) {
sumBadgeLabel.font = UIFont(name: "PeridotPE-Bold", size: 11)
} else {
sumBadgeLabel.font = UIFont(name: "PeridotPE-Bold", size: 13)
}
let sumNormalText1 = "Μέχρι τώρα έχεις κερδίσει "
let sumBoldText = sumRewardsString + "€"
let sumNormalText2 = " στο For You!"
let attrRegular = [NSAttributedString.Key.font : UIFont(name: "PeridotPE-Regular", size: 14) ?? UIFont.systemFont(ofSize: 13), NSAttributedString.Key.foregroundColor: UIColor(red: 0.13, green: 0.13, blue: 0.13, alpha: 1.00)]
let attrBold = [NSAttributedString.Key.font : UIFont(name: "PeridotPE-Bold", size: 14) ?? UIFont.boldSystemFont(ofSize: 13), NSAttributedString.Key.foregroundColor: UIColor(red: 0.13, green: 0.13, blue: 0.13, alpha: 1.00)]
let sumAttributedString = NSMutableAttributedString(string:sumNormalText1, attributes:attrRegular)
let sumBoldString = NSMutableAttributedString(string: sumBoldText, attributes:attrBold)
let sumNormalString = NSMutableAttributedString(string:sumNormalText2, attributes:attrRegular)
sumAttributedString.append(sumBoldString)
sumAttributedString.append(sumNormalString)
sumBannerLabel.attributedText = sumAttributedString
// ===
let totalCouponValueFixed = Float(round(100 * totalCouponValue) / 100)
var totalCouponValueString = "0"
totalCouponValueString = String(format: "%.2f", totalCouponValueFixed).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
dfyBadgeLabel.text = totalCouponValueString + "€"
// let totalCouponValueIntCount = String(Int(totalCouponValueFixed)).count
// if (totalCouponValueIntCount >= 3) {
// dfyBadgeLabel.font = UIFont(name: "PeridotPE-Bold", size: 9)
// } else {
// dfyBadgeLabel.font = UIFont(name: "PeridotPE-Bold", size: 11)
// }
let dfyNormalText1 = "Έχεις κερδίσει "
let dfyBoldText = totalCouponValueString + "€"
let dfyNormalText2 = " με το DEALS for YOU!"
let dfyAttributedString = NSMutableAttributedString(string:dfyNormalText1, attributes:attrRegular)
let dfyBoldString = NSMutableAttributedString(string: dfyBoldText, attributes:attrBold)
let dfyNormalString = NSMutableAttributedString(string:dfyNormalText2, attributes:attrRegular)
dfyAttributedString.append(dfyBoldString)
dfyAttributedString.append(dfyNormalString)
dfyBannerLabel.attributedText = dfyAttributedString
// ===
var totalCouponDiscountString = "0"
totalCouponDiscountString = String(format: "%.2f", totalCouponDiscount).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
couponBadgeLabel.text = totalCouponDiscountString + "€"
let gfyNormalText1 = "Έχεις κερδίσει "
let gfyBoldText = totalCouponDiscountString + "€"
let gfyNormalText2 = " με το GIFTS for YOU!"
let gfyAttributedString = NSMutableAttributedString(string:gfyNormalText1, attributes:attrRegular)
let gfyBoldString = NSMutableAttributedString(string: gfyBoldText, attributes:attrBold)
let gfyNormalString = NSMutableAttributedString(string:gfyNormalText2, attributes:attrRegular)
gfyAttributedString.append(gfyBoldString)
gfyAttributedString.append(gfyNormalString)
gfyBannerLabel.attributedText = gfyAttributedString
// ===
let marketDiscount = Float(round(100 * unifiedCouponsDiscount) / 100)
var marketDiscountString = "0"
marketDiscountString = String(format: "%.2f", marketDiscount).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
self.marketBadgeLabel.text = marketDiscountString + "€"
let marketNormalText1 = "Έχεις κερδίσει "
let marketBoldText = marketDiscountString + "€"
let marketNormalText2 = " με τα SUPERMARKET DEALS!"
let marketAttributedString = NSMutableAttributedString(string:marketNormalText1, attributes:attrRegular)
let marketBoldString = NSMutableAttributedString(string: marketBoldText, attributes:attrBold)
let marketNormalString = NSMutableAttributedString(string:marketNormalText2, attributes:attrRegular)
marketAttributedString.append(marketBoldString)
marketAttributedString.append(marketNormalString)
marketBannerLabel.attributedText = marketAttributedString
}
}