AnalysisItemViewCell.swift
7.38 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
//
// AnalysisItemViewCell.swift
// SwiftWarplyFramework
//
// Created by Manos Chorianopoulos on 18/7/22.
//
import UIKit
class AnalysisItemViewCell: UITableViewCell {
@IBOutlet weak var dateLabel: UILabel!
@IBOutlet weak var itemImage: UIImageView!
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var priceLabel: UILabel!
@IBOutlet weak var subtitleLabel: UILabel!
var postImageURL: String? {
didSet {
if let url = postImageURL {
self.itemImage.image = UIImage() // UIImage(named: "loading")
UIImage.loadImageUsingCacheWithUrlString(url) { image in
// set the image only when we are still displaying the content for the image we finished downloading
if url == self.postImageURL {
self.itemImage.image = image
}
}
}
else {
self.itemImage.image = nil
}
}
}
// lifecycle
override func awakeFromNib() {
super.awakeFromNib()
// date
dateLabel.textColor = UIColor(rgb: 0x212121)
// title
titleLabel.textColor = UIColor(rgb: 0x212121)
// price
priceLabel.textColor = UIColor(rgb: 0x212121)
// subtitle
// subtitleLabel.textColor = UIColor(rgb: 0x9D9D9C)
subtitleLabel.textColor = UIColor(rgb: 0x212121)
}
}
extension AnalysisItemViewCell {
func configureCell(item: swiftApi.SharingCouponModel) {
let merchantList:Array<swiftApi.MerchantModel> = swiftApi().getMerchantList()
titleLabel.text = ""
for merchant in merchantList {
if (merchant._uuid == item._merchant_uuid) {
// itemImage.load(link: merchant._img_preview, placeholder: UIImage(), cache: URLCache())
self.postImageURL = merchant._img_preview
titleLabel.text = merchant._admin_name
break;
}
}
dateLabel.text = item._date
// titleLabel.text = item._name
let priceFloat = Float(round(100 * (Float(item._final_price) )) / 100)
var priceString = "0"
priceString = String(format: "%.2f", priceFloat).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
priceLabel.text = priceString + "€"
if ("sent" == item._sharing_type) {
subtitleLabel.text = String(format: "Εκπτωτικό κουπόνι προς " + item._receiver_msisdn)
} else if ("received" == item._sharing_type) {
subtitleLabel.text = String(format: "Εκπτωτικό κουπόνι από " + item._sender_msisdn)
}
}
func configureCell(item: swiftApi.SharingCouponModel, isMarket: Bool) {
let merchantList:Array<swiftApi.MerchantModel> = swiftApi().getMerchantList()
let couponSetData: swiftApi.CouponSetItemModel? = item._sm_couponset_data
titleLabel.text = ""
for merchant in merchantList {
if (merchant._uuid == item._merchant_uuid) {
// itemImage.load(link: merchant._img_preview, placeholder: UIImage(), cache: URLCache())
self.postImageURL = merchant._img_preview
titleLabel.text = merchant._admin_name
break;
}
}
dateLabel.text = item._date
// titleLabel.text = item._name
// titleLabel.text = couponSetData?.name ?? ""
// let priceFloat = Float(round(100 * (Float(item._final_price) )) / 100)
let priceFloat = Float(round(100 * (Float(couponSetData?.final_price ?? 0.0) )) / 100)
var priceString = "0"
priceString = String(format: "%.2f", priceFloat).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
priceLabel.text = priceString + "€"
if ("sent" == item._sharing_type) {
subtitleLabel.text = String(format: "Εκπτωτικό κουπόνι προς " + item._receiver_msisdn)
} else if ("received" == item._sharing_type) {
subtitleLabel.text = String(format: "Εκπτωτικό κουπόνι από " + item._sender_msisdn)
}
}
func configureCell(item: swiftApi.CouponItemModel) {
// COUPONSET: desc, img_preview, name, terms, merchant_uuid
// COUPON: coupon, expiration, discount, status
// MERCHANT: _img_preview,_admin_name
let merchantList:Array<swiftApi.MerchantModel> = swiftApi().getMerchantList()
let couponSetData: swiftApi.CouponSetItemModel? = item.couponset_data
titleLabel.text = ""
for merchant in merchantList {
if (merchant._uuid == couponSetData?.merchant_uuid) {
// itemImage.load(link: merchant._img_preview, placeholder: UIImage(), cache: URLCache())
self.postImageURL = merchant._img_preview
titleLabel.text = merchant._admin_name
break;
}
}
dateLabel.text = item.redeemed ?? "" // expiration
// itemImage.load(link: couponSetData?.img_preview ?? "", placeholder: UIImage(), cache: URLCache())
// titleLabel.text = couponSetData?.name ?? ""
let priceFloat = Float(round(100 * (Float(couponSetData?.final_price ?? 0.0) )) / 100)
var priceString = "0"
priceString = String(format: "%.2f", priceFloat).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
priceLabel.text = priceString + "€"
subtitleLabel.text = "Έκπτωτικό κουπόνι"
// subtitleLabel.text = couponSetData?.short_description ?? ""
// OR
// let htmlText = couponSetData?.inner_text ?? ""
// subtitleLabel.text = htmlText.htmlToString
}
func configureCell(item: swiftApi.CouponItemModel, isMarket: Bool) {
// COUPONSET: desc, img_preview, name, terms, merchant_uuid
// COUPON: coupon, expiration, discount, status
// MERCHANT: _img_preview,_admin_name
let merchantList:Array<swiftApi.MerchantModel> = swiftApi().getMerchantList()
// let couponSetData: swiftApi.CouponSetItemModel? = item.couponset_data
titleLabel.text = ""
for merchant in merchantList {
if (merchant._uuid == item.merchant_uuid) {
// itemImage.load(link: merchant._img_preview, placeholder: UIImage(), cache: URLCache())
self.postImageURL = merchant._img_preview
titleLabel.text = merchant._admin_name
break;
}
}
// titleLabel.text = item.name
// self.postImageURL = item.image
dateLabel.text = item.redeemed ?? ""
let priceFloat = Float(round(100 * (Float(item.discount ?? "0.0") ?? 0.0 )) / 100)
var priceString = "0"
priceString = String(format: "%.2f", priceFloat).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
priceLabel.text = priceString + "€"
subtitleLabel.text = "Έκπτωτικό κουπόνι"
// subtitleLabel.text = couponSetData?.short_description ?? ""
// OR
// let htmlText = couponSetData?.inner_text ?? ""
// subtitleLabel.text = htmlText.htmlToString
}
}