AnalysisHeaderMessageViewCell.swift
6.35 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
//
// AnalysisHeaderMessageViewCell.swift
// SwiftWarplyFramework
//
// Created by Manos Chorianopoulos on 18/7/22.
//
import UIKit
class AnalysisHeaderMessageViewCell: UITableViewCell {
// attributes
@IBOutlet weak var itemImage: UIImageView!
@IBOutlet weak var messageLabelView: UIView!
@IBOutlet weak var messageLabel: UILabel!
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var emptyLabel: UILabel!
@IBOutlet weak var emptyLabelHeight: NSLayoutConstraint!
@IBOutlet weak var emptyLabelTopSpace: NSLayoutConstraint!
@IBOutlet weak var emptyLabelBottomSpace: NSLayoutConstraint!
public var loyaltyBadge:swiftApi.LoyaltyBadgeModel = swiftApi().getLoyaltyBadge()
// lifecycle
override func awakeFromNib() {
super.awakeFromNib()
// image
// itemImage.image = UIImage(named: "ic_gift_circle_2", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
// title
titleLabel.textColor = UIColor(rgb: 0x212121)
titleLabel.text = "Αναλυτικά:"
// message
messageLabel.textColor = UIColor(rgb: 0x212121)
messageLabelView.layer.borderWidth = 1.0
messageLabelView.layer.borderColor = UIColor(rgb: 0xE6E6E6).cgColor
messageLabelView.layer.cornerRadius = 16.5
messageLabelView.backgroundColor = .white
// messageLabel.text = "Μέχρι τώρα έχεις κερδίσει " + totalCouponDiscountString + "€ σε προσφορές από " + String(loyaltyBadge._couponCount) + " κουπόνια!"
}
}
extension AnalysisHeaderMessageViewCell {
func configureCell(isEmpty: Bool, isMarket: Bool) {
if (isEmpty == true) {
emptyLabel.isHidden = false
emptyLabelHeight.constant = 18.5
emptyLabelTopSpace.constant = 30.0
emptyLabelBottomSpace.constant = 10.0
} else {
emptyLabel.isHidden = true
emptyLabelHeight.constant = 0.0
emptyLabelTopSpace.constant = 0.0
emptyLabelBottomSpace.constant = 0.0
}
if (isMarket == true) {
itemImage.image = UIImage(named: "ic_history_market", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
let oldUnifiedCouponList: Array<swiftApi.CouponItemModel> = swiftApi().getOldUnifiedCouponList()
let oldUnifiedCouponListLength = oldUnifiedCouponList.count
var unifiedCouponsDiscount: Float = 0.0
for coupon in oldUnifiedCouponList {
if let discountFloat = Float(coupon.discount ?? "0.0") {
unifiedCouponsDiscount += discountFloat
}
}
let totalCouponDiscount = Float(round(100 * unifiedCouponsDiscount) / 100)
var totalCouponDiscountString = "0"
totalCouponDiscountString = String(format: "%.2f", totalCouponDiscount).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
let coupNormalText1 = "Μέχρι τώρα έχεις κερδίσει "
let coupBoldText = totalCouponDiscountString + "€"
let coupNormalText2 = " σε προσφορές από "
let coupBoldText2 = String(oldUnifiedCouponListLength)
let coupNormalText3 = " κουπόνια!"
let attrRegular = [NSAttributedString.Key.font : UIFont(name: "PeridotPE-Regular", size: 17) ?? UIFont.systemFont(ofSize: 16)]
let attrBold = [NSAttributedString.Key.font : UIFont(name: "PeridotPE-Bold", size: 17) ?? UIFont.boldSystemFont(ofSize: 16)]
let coupAttributedString = NSMutableAttributedString(string:coupNormalText1, attributes:attrRegular)
let coupBoldString = NSMutableAttributedString(string: coupBoldText, attributes:attrBold)
let coupNormalString2 = NSMutableAttributedString(string:coupNormalText2, attributes:attrRegular)
let coupBoldString2 = NSMutableAttributedString(string: coupBoldText2, attributes:attrBold)
let coupNormalString3 = NSMutableAttributedString(string:coupNormalText3, attributes:attrRegular)
coupAttributedString.append(coupBoldString)
coupAttributedString.append(coupNormalString2)
coupAttributedString.append(coupBoldString2)
coupAttributedString.append(coupNormalString3)
messageLabel.attributedText = coupAttributedString
} else {
itemImage.image = UIImage(named: "ic_gift_history", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
let totalCouponDiscount = Float(round(100 * loyaltyBadge._value) / 100)
var totalCouponDiscountString = "0"
totalCouponDiscountString = String(format: "%.2f", totalCouponDiscount).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
let coupNormalText1 = "Μέχρι τώρα έχεις κερδίσει "
let coupBoldText = totalCouponDiscountString + "€"
let coupNormalText2 = " σε προσφορές από "
let coupBoldText2 = String(loyaltyBadge._couponCount)
let coupNormalText3 = " κουπόνια!"
let attrRegular = [NSAttributedString.Key.font : UIFont(name: "PeridotPE-Regular", size: 17) ?? UIFont.systemFont(ofSize: 16)]
let attrBold = [NSAttributedString.Key.font : UIFont(name: "PeridotPE-Bold", size: 17) ?? UIFont.boldSystemFont(ofSize: 16)]
let coupAttributedString = NSMutableAttributedString(string:coupNormalText1, attributes:attrRegular)
let coupBoldString = NSMutableAttributedString(string: coupBoldText, attributes:attrBold)
let coupNormalString2 = NSMutableAttributedString(string:coupNormalText2, attributes:attrRegular)
let coupBoldString2 = NSMutableAttributedString(string: coupBoldText2, attributes:attrBold)
let coupNormalString3 = NSMutableAttributedString(string:coupNormalText3, attributes:attrRegular)
coupAttributedString.append(coupBoldString)
coupAttributedString.append(coupNormalString2)
coupAttributedString.append(coupBoldString2)
coupAttributedString.append(coupNormalString3)
messageLabel.attributedText = coupAttributedString
}
}
}