| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- //
- // QRScannerPresenter.swift
- // Sirani
- //
- // Created by Anhar Solehudin on 10/04/19.
- // Copyright © 2019 Anhar Solehudin. All rights reserved.
- //
- import Foundation
- import SwiftyJSON
- class QRScannerPresenter {
-
- private let siraniApiServices: SiraniApiServices
- weak private var view: QRScannerViewDelegate?
-
- init(siraniApiServices: SiraniApiServices) {
- self.siraniApiServices = siraniApiServices
- }
-
- func attachView(view: QRScannerViewDelegate?) {
- self.view = view
- }
-
- func detachView() {
- self.view = nil
- }
-
- func loadData(code: String) {
- self.view?.showLoading()
-
- siraniApiServices.postToGetResultQrCode(code: code).responseJSON { response in
- if response.error == nil {
- guard let data = response.data else { return }
- if let json = try? JSON(data: data) {
-
- let result = ResultQrCode(
- lic_no: json["lic_no"].stringValue,
- lic_date: json["lic_date"].stringValue,
- cust_id: json["cust_id"].intValue,
- pmh_name: json["pmh_name"].stringValue,
- eqp_name: json["eqp_name"].stringValue,
- merk: json["merk"].stringValue,
- model: json["model"].stringValue,
- imei: json["imei"].stringValue,
- mfc_name: json["mfc_name"].stringValue,
- negara: json["negara"].stringValue,
- acuan: json["acuan"].stringValue,
- eqp_frek: json["eqp_frek"].stringValue,
- eqp_power: json["eqp_power"].stringValue
- )
-
- self.setResult(result: result)
- }
- } else {
- self.setEmptyResult()
- }
- }
- }
-
- // other functions
- private func setResult(result: ResultQrCode) {
- self.view?.setResulQrCode(resultQrCode: result)
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.8) {
- self.view?.hideLoading()
- }
- }
-
- private func setEmptyResult() {
- self.view?.hideLoading()
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.8) {
- self.view?.setEmptyQrCode()
- }
- }
- }
|