Manos Chorianopoulos

marketPassDetails fixes

...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
8 import UIKit 8 import UIKit
9 import RSBarcodes_Swift 9 import RSBarcodes_Swift
10 import AVFoundation 10 import AVFoundation
11 +import SwiftEventBus
11 12
12 @objc public class MarketPassViewController: UIViewController { 13 @objc public class MarketPassViewController: UIViewController {
13 @IBOutlet weak var passContainerView: UIView! 14 @IBOutlet weak var passContainerView: UIView!
...@@ -21,9 +22,9 @@ import AVFoundation ...@@ -21,9 +22,9 @@ import AVFoundation
21 @IBOutlet weak var smLogosView: UIView! 22 @IBOutlet weak var smLogosView: UIView!
22 @IBOutlet weak var mapButton: UIButton! 23 @IBOutlet weak var mapButton: UIButton!
23 24
24 - var marketPassDetails:swiftApi.MarketPassDetailsModel? 25 + var marketPassDetails:swiftApi.MarketPassDetailsModel? = swiftApi().getMarketPassDetails()
25 26
26 - let spinner = SpinnerViewController() 27 + // let spinner = SpinnerViewController()
27 28
28 let uiscreen: CGRect = UIScreen.main.bounds 29 let uiscreen: CGRect = UIScreen.main.bounds
29 30
...@@ -33,7 +34,19 @@ import AVFoundation ...@@ -33,7 +34,19 @@ import AVFoundation
33 self.hidesBottomBarWhenPushed = true 34 self.hidesBottomBarWhenPushed = true
34 35
35 passContainerView.isHidden = true 36 passContainerView.isHidden = true
36 - getMarketPassDetailsRequest() 37 + // getMarketPassDetailsRequest()
38 +
39 + SwiftEventBus.onBackgroundThread(self, name: "market_pass_details_fetched") { result in
40 +
41 + DispatchQueue.main.async {
42 + if let tempMarketPassDetails = swiftApi().getMarketPassDetails() {
43 + self.marketPassDetails = tempMarketPassDetails
44 + self.updateUI()
45 + } else {
46 + // self.showDialog("Αποτυχία","Κάτι πήγε στραβά")
47 + }
48 + }
49 + }
37 50
38 setBackButton() 51 setBackButton()
39 setNavigationTitle("SUPERMARKET DEALS") 52 setNavigationTitle("SUPERMARKET DEALS")
...@@ -97,19 +110,18 @@ import AVFoundation ...@@ -97,19 +110,18 @@ import AVFoundation
97 // barcodeImageHeight.constant = 0 110 // barcodeImageHeight.constant = 0
98 // } 111 // }
99 112
100 - // TODO: FIX 113 + let couponsValueString = "0.00"
101 - // let couponsValueString = "30" 114 + let attrRegular = [NSAttributedString.Key.font : UIFont(name: "PeridotPE-Regular", size: 17) ?? UIFont.systemFont(ofSize: 16), NSAttributedString.Key.foregroundColor: UIColor.white]
102 - // let attrRegular = [NSAttributedString.Key.font : UIFont(name: "PeridotPE-Regular", size: 17) ?? UIFont.systemFont(ofSize: 16), NSAttributedString.Key.foregroundColor: UIColor.white] 115 + let attrBold = [NSAttributedString.Key.font : UIFont(name: "PeridotPE-Bold", size: 17) ?? UIFont.boldSystemFont(ofSize: 16), NSAttributedString.Key.foregroundColor: UIColor.white]
103 - // let attrBold = [NSAttributedString.Key.font : UIFont(name: "PeridotPE-Bold", size: 17) ?? UIFont.boldSystemFont(ofSize: 16), NSAttributedString.Key.foregroundColor: UIColor.white]
104 116
105 - // let couponsValueNormalText1 = "Έχεις κουπόνια συνολικής αξίας " 117 + let couponsValueNormalText1 = "Έχεις κουπόνια συνολικής αξίας "
106 - // let couponsValueBoldText = couponsValueString + "€" 118 + let couponsValueBoldText = couponsValueString + "€"
107 119
108 - // let couponsValueAttributedString = NSMutableAttributedString(string:couponsValueNormalText1, attributes:attrRegular) 120 + let couponsValueAttributedString = NSMutableAttributedString(string:couponsValueNormalText1, attributes:attrRegular)
109 - // let couponsValueBoldString = NSMutableAttributedString(string: couponsValueBoldText, attributes:attrBold) 121 + let couponsValueBoldString = NSMutableAttributedString(string: couponsValueBoldText, attributes:attrBold)
110 122
111 - // couponsValueAttributedString.append(couponsValueBoldString) 123 + couponsValueAttributedString.append(couponsValueBoldString)
112 - // couponsValueLabel.attributedText = couponsValueAttributedString 124 + couponsValueLabel.attributedText = couponsValueAttributedString
113 125
114 mapButton.titleLabel?.font = UIFont(name: "PeridotPE-SBold", size: 16) 126 mapButton.titleLabel?.font = UIFont(name: "PeridotPE-SBold", size: 16)
115 mapButton.setTitle("Δες στο χάρτη", for: .normal) 127 mapButton.setTitle("Δες στο χάρτη", for: .normal)
...@@ -155,6 +167,13 @@ import AVFoundation ...@@ -155,6 +167,13 @@ import AVFoundation
155 // stackView.leadingAnchor.constraint(equalTo: smLogosView.leadingAnchor, constant: 25), 167 // stackView.leadingAnchor.constraint(equalTo: smLogosView.leadingAnchor, constant: 25),
156 // stackView.centerYAnchor.constraint(equalTo: smLogosView.centerYAnchor), 168 // stackView.centerYAnchor.constraint(equalTo: smLogosView.centerYAnchor),
157 // ]) 169 // ])
170 +
171 + if let tempMarketPassDetails = swiftApi().getMarketPassDetails() {
172 + self.marketPassDetails = tempMarketPassDetails
173 + self.updateUI()
174 + } else {
175 + self.showDialog("Αποτυχία","Κάτι πήγε στραβά")
176 + }
158 } 177 }
159 178
160 func updateUI() { 179 func updateUI() {
...@@ -174,8 +193,10 @@ import AVFoundation ...@@ -174,8 +193,10 @@ import AVFoundation
174 } else { 193 } else {
175 barcodeImageHeight.constant = 0 194 barcodeImageHeight.constant = 0
176 } 195 }
177 - 196 +
178 - let couponsValueString = String(marketPassDetails?._total_available_discount ?? 0.0) 197 + let couponsValueFloat = marketPassDetails?._total_available_discount ?? 0.0
198 + let couponsValueString = String(format: "%.2f", couponsValueFloat)
199 + // let couponsValueString = String(marketPassDetails?._total_available_discount ?? 0.0)
179 let attrRegular = [NSAttributedString.Key.font : UIFont(name: "PeridotPE-Regular", size: 17) ?? UIFont.systemFont(ofSize: 16), NSAttributedString.Key.foregroundColor: UIColor.white] 200 let attrRegular = [NSAttributedString.Key.font : UIFont(name: "PeridotPE-Regular", size: 17) ?? UIFont.systemFont(ofSize: 16), NSAttributedString.Key.foregroundColor: UIColor.white]
180 let attrBold = [NSAttributedString.Key.font : UIFont(name: "PeridotPE-Bold", size: 17) ?? UIFont.boldSystemFont(ofSize: 16), NSAttributedString.Key.foregroundColor: UIColor.white] 201 let attrBold = [NSAttributedString.Key.font : UIFont(name: "PeridotPE-Bold", size: 17) ?? UIFont.boldSystemFont(ofSize: 16), NSAttributedString.Key.foregroundColor: UIColor.white]
181 202
...@@ -193,7 +214,7 @@ import AVFoundation ...@@ -193,7 +214,7 @@ import AVFoundation
193 // Create a horizontal stack view 214 // Create a horizontal stack view
194 let stackView = UIStackView() 215 let stackView = UIStackView()
195 stackView.axis = .horizontal 216 stackView.axis = .horizontal
196 - stackView.spacing = 15 // Spacing between images 217 + stackView.spacing = 5 // Spacing between images
197 stackView.alignment = .center 218 stackView.alignment = .center
198 stackView.distribution = .equalSpacing 219 stackView.distribution = .equalSpacing
199 220
...@@ -201,8 +222,8 @@ import AVFoundation ...@@ -201,8 +222,8 @@ import AVFoundation
201 for sm in supermarkets { 222 for sm in supermarkets {
202 let imageView = UIImageView() 223 let imageView = UIImageView()
203 imageView.contentMode = .scaleAspectFit 224 imageView.contentMode = .scaleAspectFit
204 - imageView.widthAnchor.constraint(equalToConstant: 40).isActive = true 225 + imageView.widthAnchor.constraint(equalToConstant: 50).isActive = true
205 - imageView.heightAnchor.constraint(equalToConstant: 40).isActive = true 226 + imageView.heightAnchor.constraint(equalToConstant: 50).isActive = true
206 227
207 imageView.load(link: sm._logo, placeholder: UIImage(), cache: URLCache()) 228 imageView.load(link: sm._logo, placeholder: UIImage(), cache: URLCache())
208 229
...@@ -224,25 +245,25 @@ import AVFoundation ...@@ -224,25 +245,25 @@ import AVFoundation
224 self.view.layoutIfNeeded() 245 self.view.layoutIfNeeded()
225 } 246 }
226 247
227 - func showSpinner() { 248 + // func showSpinner() {
228 - // add the spinner view controller 249 + // // add the spinner view controller
229 - // addChild(spinner) 250 + // // addChild(spinner)
230 - // spinner.view.frame = view.frame 251 + // // spinner.view.frame = view.frame
231 - // view.addSubview(spinner.view) 252 + // // view.addSubview(spinner.view)
232 - // spinner.didMove(toParent: self) 253 + // // spinner.didMove(toParent: self)
233 254
234 - addChild(spinner) 255 + // addChild(spinner)
235 - spinner.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height) 256 + // spinner.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height)
236 - self.view.addSubview(spinner.view) 257 + // self.view.addSubview(spinner.view)
237 - spinner.didMove(toParent: self) 258 + // spinner.didMove(toParent: self)
238 - } 259 + // }
239 260
240 - func hideSpinner() { 261 + // func hideSpinner() {
241 - // remove the spinner view controller 262 + // // remove the spinner view controller
242 - spinner.willMove(toParent: nil) 263 + // spinner.willMove(toParent: nil)
243 - spinner.view.removeFromSuperview() 264 + // spinner.view.removeFromSuperview()
244 - spinner.removeFromParent() 265 + // spinner.removeFromParent()
245 - } 266 + // }
246 267
247 func showDialog(_ alertTitle: String, _ alertSubTitle: String) -> Void { 268 func showDialog(_ alertTitle: String, _ alertSubTitle: String) -> Void {
248 269
...@@ -300,31 +321,30 @@ import AVFoundation ...@@ -300,31 +321,30 @@ import AVFoundation
300 } 321 }
301 322
302 // MARK: - API Functions 323 // MARK: - API Functions
303 - func getMarketPassDetailsRequest() { 324 + // func getMarketPassDetailsRequest() {
304 - showSpinner() 325 + // showSpinner()
305 326
306 - swiftApi().getMarketPassDetailsAsync(getMarketPassDetailsCallback, failureCallback: {errorCode in 327 + // swiftApi().getMarketPassDetailsAsync(getMarketPassDetailsCallback, failureCallback: {errorCode in
307 - print("========= getMarketPassDetailsRequest ERROR CODE =========", errorCode) 328 + // print("========= getMarketPassDetailsRequest ERROR CODE =========", errorCode)
308 - self.hideSpinner() 329 + // self.hideSpinner()
309 - self.showDialog("Αποτυχία","Κάτι πήγε στραβά") 330 + // self.showDialog("Αποτυχία","Κάτι πήγε στραβά")
310 - }) 331 + // })
311 - } 332 + // }
312 333
313 - func getMarketPassDetailsCallback (_ marketPassDetailsData: swiftApi.MarketPassDetailsModel?) -> Void { 334 + // func getMarketPassDetailsCallback (_ marketPassDetailsData: swiftApi.MarketPassDetailsModel?) -> Void {
314 - self.hideSpinner() 335 + // self.hideSpinner()
315 336
316 - if (marketPassDetailsData != nil) { 337 + // if (marketPassDetailsData != nil) {
317 - DispatchQueue.main.async { 338 + // DispatchQueue.main.async {
318 - if let tempMarketPassDetailsData = marketPassDetailsData { 339 + // if let tempMarketPassDetailsData = marketPassDetailsData {
319 - self.marketPassDetails = tempMarketPassDetailsData 340 + // self.marketPassDetails = tempMarketPassDetailsData
320 - self.updateUI() 341 + // self.updateUI()
321 - } 342 + // }
322 - } 343 + // }
323 - } else { 344 + // } else {
324 - self.showDialog("Αποτυχία","Κάτι πήγε στραβά") 345 + // self.showDialog("Αποτυχία","Κάτι πήγε στραβά")
325 - } 346 + // }
326 - } 347 + // }
327 - // MARK: - API Functions
328 348
329 // MARK: - Actions 349 // MARK: - Actions
330 @IBAction func mapButtonAction(_ sender: Any) { 350 @IBAction func mapButtonAction(_ sender: Any) {
......
...@@ -40,6 +40,7 @@ public struct GlobalVariables { ...@@ -40,6 +40,7 @@ public struct GlobalVariables {
40 static var trackingStepsEnabled: Bool = false 40 static var trackingStepsEnabled: Bool = false
41 static var carouselList: Array<swiftApi.CampaignItemModel> = [] 41 static var carouselList: Array<swiftApi.CampaignItemModel> = []
42 static var showVouchersBanner: String = "" // We use String in order to have 3 different states: "", "true", "false" 42 static var showVouchersBanner: String = "" // We use String in order to have 3 different states: "", "true", "false"
43 + static var marketPassDetails: swiftApi.MarketPassDetailsModel?
43 } 44 }
44 45
45 var timer: DispatchSourceTimer? 46 var timer: DispatchSourceTimer?
...@@ -194,6 +195,16 @@ public class swiftApi { ...@@ -194,6 +195,16 @@ public class swiftApi {
194 GlobalVariables.showVouchersBanner = "" 195 GlobalVariables.showVouchersBanner = ""
195 } 196 }
196 197
198 +
199 + public func setMarketPassDetails(_ newValue: swiftApi.MarketPassDetailsModel) {
200 + GlobalVariables.marketPassDetails = newValue
201 + }
202 +
203 +
204 + public func getMarketPassDetails() -> swiftApi.MarketPassDetailsModel? {
205 + return GlobalVariables.marketPassDetails
206 + }
207 +
197 208
198 public func setVouchersFetched(_ success: String) -> Void { 209 public func setVouchersFetched(_ success: String) -> Void {
199 // Possible values "true", "false", "null" 210 // Possible values "true", "false", "null"
...@@ -9567,6 +9578,8 @@ public class swiftApi { ...@@ -9567,6 +9578,8 @@ public class swiftApi {
9567 9578
9568 if let responseDataResult = responseDataDictionary["result"] as? [String : Any] { 9579 if let responseDataResult = responseDataDictionary["result"] as? [String : Any] {
9569 let tempMarketPassDetails = MarketPassDetailsModel(dictionary: responseDataResult) 9580 let tempMarketPassDetails = MarketPassDetailsModel(dictionary: responseDataResult)
9581 + swiftApi().setMarketPassDetails(tempMarketPassDetails)
9582 + SwiftEventBus.post("market_pass_details_fetched")
9570 successCallback(tempMarketPassDetails) 9583 successCallback(tempMarketPassDetails)
9571 9584
9572 } else { 9585 } else {
......