NotificationDetailVC.swift 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. self.presenter.loadData(notifId: notifId)
  60. }
  61. else {
  62. CommonHelper.showNoConnection(in: self)
  63. }
  64. }
  65. }
  66. }
  67. // View Delegate Protocols
  68. extension NotificationDetailVC: NotificationDetailViewDelegate {
  69. func showLoading() {
  70. loading = true
  71. progress.startAnimating()
  72. progressLayout.show()
  73. }
  74. func hideLoading() {
  75. loading = false
  76. progress.stopAnimating()
  77. progressLayout.hide()
  78. }
  79. func setNotificationDetail(notificationDetail: NotificationDetail) {
  80. lblTitle.text = "\(notificationDetail.judul_notifikasi)"
  81. var activityDate = notificationDetail.activity_date
  82. let dates = activityDate.split(separator: " ")
  83. if !dates.isEmpty {
  84. activityDate = String(dates[0])
  85. }
  86. lblDate.text = "Tanggal Notifikasi: \(activityDate)"
  87. lblPlgId.text = "\(notificationDetail.plg_id)"
  88. lblCustName.text = "\(notificationDetail.cust_name)"
  89. lblMerk.text = "\(notificationDetail.eqp_name)"
  90. lblModel.text = "\(notificationDetail.models)"
  91. lblBrand.text = "\(notificationDetail.models)"
  92. lblPabrik.text = "\(notificationDetail.fullname)"
  93. lblPabrikNegara.text = "\(notificationDetail.negara)"
  94. lblCatatan.text = "\(notificationDetail.note)"
  95. if ConnectionHelper.isConnectedToNetwork() {
  96. self.presenter.loadData(notifId: self.notifId)
  97. } else {
  98. CommonHelper.showNoConnection(in: self)
  99. }
  100. }
  101. }