NotificationCell.swift 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // NotificationCell.swift
  3. // Sirani
  4. //
  5. // Created by Anhar Solehudin on 10/11/20.
  6. // Copyright © 2020 Anhar Solehudin. All rights reserved.
  7. //
  8. import UIKit
  9. import MaterialComponents.MaterialCards
  10. protocol NotificationCellDelegate: NSObjectProtocol {
  11. func openNotifDetail(notificationItem: NotificationItem?, position: Int?)
  12. }
  13. class NotificationCell: UITableViewCell {
  14. @IBOutlet weak var card: MDCCard!
  15. @IBOutlet weak var lblNotifContent: UILabel!
  16. @IBOutlet weak var lblNotifPlgId: UILabel!
  17. @IBOutlet weak var lblNotifCustName: UILabel!
  18. @IBOutlet weak var lblNotifDate: UILabel!
  19. var cellDelegate: NotificationCellDelegate?
  20. var selectedNotificationItem: NotificationItem?
  21. var selectedPosition: Int?
  22. func updateViews(notificationItem: NotificationItem, position: Int) {
  23. card.isInteractable = true
  24. let gesture = UITapGestureRecognizer(target: self, action: #selector(self.onItemTap))
  25. card.addGestureRecognizer(gesture)
  26. if notificationItem.is_read == 1 {
  27. card.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
  28. } else {
  29. card.backgroundColor = #colorLiteral(red: 0.8428310752, green: 0.837821424, blue: 0.8466822505, alpha: 1)
  30. }
  31. selectedPosition = position
  32. selectedNotificationItem = notificationItem
  33. lblNotifContent.text = "\(notificationItem.judul_notifikasi)"
  34. lblNotifPlgId.text = "\(notificationItem.plg_id)"
  35. lblNotifCustName.text = "\(notificationItem.cust_name)"
  36. var activityDate = notificationItem.activity_date
  37. let dates = activityDate.split(separator: " ")
  38. if !dates.isEmpty {
  39. activityDate = String(dates[0])
  40. }
  41. lblNotifDate.text = activityDate
  42. }
  43. @objc func onItemTap(sender : UITapGestureRecognizer) {
  44. cellDelegate?.openNotifDetail(notificationItem: selectedNotificationItem, position: selectedPosition)
  45. }
  46. }