// // NotificationDetailVC.swift // Sirani // // Created by Anhar Solehudin on 12/11/20. // Copyright © 2020 Anhar Solehudin. All rights reserved. // import UIKit class NotificationDetailVC: UIViewController { @IBOutlet weak var lblTitle: UILabel! @IBOutlet weak var lblDate: UILabel! @IBOutlet weak var lblPlgId: UILabel! @IBOutlet weak var lblCustName: UILabel! @IBOutlet weak var lblMerk: UILabel! @IBOutlet weak var lblModel: UILabel! @IBOutlet weak var lblBrand: UILabel! @IBOutlet weak var lblPabrik: UILabel! @IBOutlet weak var lblPabrikNegara: UILabel! @IBOutlet weak var lblCatatan: UILabel! @IBOutlet weak var progressLayout: UIView! @IBOutlet weak var progress: UIActivityIndicatorView! // Initialize private var presenter: NotificationDetailPresenter! // Others private var loading = false // Public Variable, Use by Segue var notifId: Int = 0 // View Lifecycles override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent } override func viewDidLoad() { super.viewDidLoad() presenter = NotificationDetailPresenter(siraniApiServices: SiraniApiServices()) presenter.attachView(view: self) loadData(notifId: notifId) } override func viewWillAppear(_ animated: Bool) { AppUtility.lockOrientation(.portrait) presenter.attachView(view: self) } override func viewDidAppear(_ animated: Bool) { } override func viewWillDisappear(_ animated: Bool) { AppUtility.lockOrientation(.all) presenter.detachView() } override func viewDidDisappear(_ animated: Bool) { } override func prepare(for segue: UIStoryboardSegue, sender: Any?) { } @IBAction func onBackTapped(_ sender: Any) { performSegue(withIdentifier: "unwindNotificationDetailToNotificationList", sender: self) } // private functions private func loadData(notifId: Int) { if !loading { if ConnectionHelper.isConnectedToNetwork() { presenter.loadData(notifId: notifId) } } } } // View Delegate Protocols extension NotificationDetailVC: NotificationDetailViewDelegate { func showLoading() { loading = true progress.startAnimating() progressLayout.show() } func hideLoading() { loading = false progress.stopAnimating() progressLayout.hide() } func setNotificationDetail(notificationDetail: NotificationDetail) { lblTitle.text = "\(notificationDetail.judul_notifikasi)" var activityDate = notificationDetail.activity_date let dates = activityDate.split(separator: " ") if !dates.isEmpty { activityDate = String(dates[0]) } lblDate.text = "Tanggal Notifikasi: \(activityDate)" lblPlgId.text = "\(notificationDetail.plg_id)" lblCustName.text = "\(notificationDetail.cust_name)" lblMerk.text = "\(notificationDetail.eqp_name)" lblModel.text = "\(notificationDetail.models)" lblBrand.text = "\(notificationDetail.models)" lblPabrik.text = "\(notificationDetail.fullname)" lblPabrikNegara.text = "\(notificationDetail.negara)" lblCatatan.text = "\(notificationDetail.note)" if ConnectionHelper.isConnectedToNetwork() { presenter.readNotif(notifId: notifId) } } }