NotificationDetailVC.swift 3.5 KB

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