Manos Chorianopoulos

remove MarketPassDetails Request from MarketPassViewController

...@@ -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() {
...@@ -226,25 +245,25 @@ import AVFoundation ...@@ -226,25 +245,25 @@ import AVFoundation
226 self.view.layoutIfNeeded() 245 self.view.layoutIfNeeded()
227 } 246 }
228 247
229 - func showSpinner() { 248 + // func showSpinner() {
230 - // add the spinner view controller 249 + // // add the spinner view controller
250 + // // addChild(spinner)
251 + // // spinner.view.frame = view.frame
252 + // // view.addSubview(spinner.view)
253 + // // spinner.didMove(toParent: self)
254 +
231 // addChild(spinner) 255 // addChild(spinner)
232 - // spinner.view.frame = view.frame 256 + // spinner.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height)
233 - // view.addSubview(spinner.view) 257 + // self.view.addSubview(spinner.view)
234 // spinner.didMove(toParent: self) 258 // spinner.didMove(toParent: self)
259 + // }
235 260
236 - addChild(spinner) 261 + // func hideSpinner() {
237 - spinner.view.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height) 262 + // // remove the spinner view controller
238 - self.view.addSubview(spinner.view) 263 + // spinner.willMove(toParent: nil)
239 - spinner.didMove(toParent: self) 264 + // spinner.view.removeFromSuperview()
240 - } 265 + // spinner.removeFromParent()
241 - 266 + // }
242 - func hideSpinner() {
243 - // remove the spinner view controller
244 - spinner.willMove(toParent: nil)
245 - spinner.view.removeFromSuperview()
246 - spinner.removeFromParent()
247 - }
248 267
249 func showDialog(_ alertTitle: String, _ alertSubTitle: String) -> Void { 268 func showDialog(_ alertTitle: String, _ alertSubTitle: String) -> Void {
250 269
...@@ -302,31 +321,30 @@ import AVFoundation ...@@ -302,31 +321,30 @@ import AVFoundation
302 } 321 }
303 322
304 // MARK: - API Functions 323 // MARK: - API Functions
305 - func getMarketPassDetailsRequest() { 324 + // func getMarketPassDetailsRequest() {
306 - showSpinner() 325 + // showSpinner()
307 - 326 +
308 - swiftApi().getMarketPassDetailsAsync(getMarketPassDetailsCallback, failureCallback: {errorCode in 327 + // swiftApi().getMarketPassDetailsAsync(getMarketPassDetailsCallback, failureCallback: {errorCode in
309 - print("========= getMarketPassDetailsRequest ERROR CODE =========", errorCode) 328 + // print("========= getMarketPassDetailsRequest ERROR CODE =========", errorCode)
310 - self.hideSpinner() 329 + // self.hideSpinner()
311 - self.showDialog("Αποτυχία","Κάτι πήγε στραβά") 330 + // self.showDialog("Αποτυχία","Κάτι πήγε στραβά")
312 - }) 331 + // })
313 - } 332 + // }
314 - 333 +
315 - func getMarketPassDetailsCallback (_ marketPassDetailsData: swiftApi.MarketPassDetailsModel?) -> Void { 334 + // func getMarketPassDetailsCallback (_ marketPassDetailsData: swiftApi.MarketPassDetailsModel?) -> Void {
316 - self.hideSpinner() 335 + // self.hideSpinner()
317 - 336 +
318 - if (marketPassDetailsData != nil) { 337 + // if (marketPassDetailsData != nil) {
319 - DispatchQueue.main.async { 338 + // DispatchQueue.main.async {
320 - if let tempMarketPassDetailsData = marketPassDetailsData { 339 + // if let tempMarketPassDetailsData = marketPassDetailsData {
321 - self.marketPassDetails = tempMarketPassDetailsData 340 + // self.marketPassDetails = tempMarketPassDetailsData
322 - self.updateUI() 341 + // self.updateUI()
323 - } 342 + // }
324 - } 343 + // }
325 - } else { 344 + // } else {
326 - self.showDialog("Αποτυχία","Κάτι πήγε στραβά") 345 + // self.showDialog("Αποτυχία","Κάτι πήγε στραβά")
327 - } 346 + // }
328 - } 347 + // }
329 - // MARK: - API Functions
330 348
331 // MARK: - Actions 349 // MARK: - Actions
332 @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?
...@@ -195,6 +196,16 @@ public class swiftApi { ...@@ -195,6 +196,16 @@ public class swiftApi {
195 } 196 }
196 197
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 +
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"
200 if (success == "true" || success == "false" || success == "null") { 211 if (success == "true" || success == "false" || success == "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 {
......