NotificationDetailVC.swift 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. //
  2. // NotificationDetailVC.swift
  3. // Sirani
  4. //
  5. // Created by Anhar Solehudin on 12/11/20.
  6. // Copyright © 2020 Anhar Solehudin. All rights reserved.
  7. //
  8. import UIKit
  9. class NotificationDetailVC: UIViewController {
  10. @IBOutlet weak var lblTitle: UILabel!
  11. @IBOutlet weak var lblDate: UILabel!
  12. @IBOutlet weak var lblPlgId: UILabel!
  13. @IBOutlet weak var lblCustName: UILabel!
  14. @IBOutlet weak var lblMerk: UILabel!
  15. @IBOutlet weak var lblModel: UILabel!
  16. @IBOutlet weak var lblBrand: UILabel!
  17. @IBOutlet weak var lblPabrik: UILabel!
  18. @IBOutlet weak var lblPabrikNegara: UILabel!
  19. @IBOutlet weak var lblCatatan: UILabel!
  20. @IBOutlet weak var progressLayout: UIView!
  21. @IBOutlet weak var progress: UIActivityIndicatorView!
  22. // Initialize
  23. private var presenter: NotificationDetailPresenter!
  24. // Others
  25. private var loading = false
  26. // Public Variable, Use by Segue
  27. var notifId: Int = 0
  28. // View Lifecycles
  29. override var preferredStatusBarStyle: UIStatusBarStyle {
  30. return .lightContent
  31. }
  32. override func viewDidLoad() {
  33. super.viewDidLoad()
  34. presenter = NotificationDetailPresenter(siraniApiServices: SiraniApiServices())
  35. presenter.attachView(view: self)
  36. loadData(notifId: notifId)
  37. }
  38. override func viewWillAppear(_ animated: Bool) {
  39. AppUtility.lockOrientation(.portrait)
  40. presenter.attachView(view: self)
  41. }
  42. override func viewDidAppear(_ animated: Bool) {
  43. }
  44. override func viewWillDisappear(_ animated: Bool) {
  45. AppUtility.lockOrientation(.all)
  46. presenter.detachView()
  47. }
  48. override func viewDidDisappear(_ animated: Bool) {
  49. }
  50. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  51. }
  52. @IBAction func onBackTapped(_ sender: Any) {
  53. performSegue(withIdentifier: "unwindNotificationDetailToNotificationList", sender: self)
  54. }
  55. // private functions
  56. private func loadData(notifId: Int) {
  57. if !loading {
  58. if ConnectionHelper.isConnectedToNetwork() {
  59. ConnectionHelper.checkIpAddress { [weak self] success in
  60. guard let self = self else { return }
  61. DispatchQueue.main.async {
  62. if success {
  63. self.presenter.loadData(notifId: notifId)
  64. } else {
  65. CommonHelper.showNotAllowConnection(in: self)
  66. }
  67. }
  68. }
  69. }
  70. else {
  71. CommonHelper.showNoConnection(in: self)
  72. }
  73. }
  74. }
  75. }
  76. // View Delegate Protocols
  77. extension NotificationDetailVC: NotificationDetailViewDelegate {
  78. func showLoading() {
  79. loading = true
  80. progress.startAnimating()
  81. progressLayout.show()
  82. }
  83. func hideLoading() {
  84. loading = false
  85. progress.stopAnimating()
  86. progressLayout.hide()
  87. }
  88. func setNotificationDetail(notificationDetail: NotificationDetail) {
  89. lblTitle.text = "\(notificationDetail.judul_notifikasi)"
  90. var activityDate = notificationDetail.activity_date
  91. let dates = activityDate.split(separator: " ")
  92. if !dates.isEmpty {
  93. activityDate = String(dates[0])
  94. }
  95. lblDate.text = "Tanggal Notifikasi: \(activityDate)"
  96. lblPlgId.text = "\(notificationDetail.plg_id)"
  97. lblCustName.text = "\(notificationDetail.cust_name)"
  98. lblMerk.text = "\(notificationDetail.eqp_name)"
  99. lblModel.text = "\(notificationDetail.models)"
  100. lblBrand.text = "\(notificationDetail.models)"
  101. lblPabrik.text = "\(notificationDetail.fullname)"
  102. lblPabrikNegara.text = "\(notificationDetail.negara)"
  103. lblCatatan.text = "\(notificationDetail.note)"
  104. if ConnectionHelper.isConnectedToNetwork() {
  105. ConnectionHelper.checkIpAddress { [weak self] success in
  106. guard let self = self else { return }
  107. DispatchQueue.main.async {
  108. if success {
  109. self.presenter.loadData(notifId: self.notifId)
  110. } else {
  111. CommonHelper.showNotAllowConnection(in: self)
  112. }
  113. }
  114. }
  115. } else {
  116. CommonHelper.showNoConnection(in: self)
  117. }
  118. }
  119. }