NotificationCell.swift 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. import SkeletonView
  11. protocol NotificationCellDelegate: NSObjectProtocol {
  12. func openNotifDetail(notificationItem: NotificationItem?, position: Int?)
  13. }
  14. class NotificationCell: UITableViewCell {
  15. @IBOutlet weak var card: MDCCard!
  16. @IBOutlet weak var lblNotifContent: UILabel!
  17. @IBOutlet weak var lblNotifPlgId: UILabel!
  18. @IBOutlet weak var lblNotifCustName: UILabel!
  19. @IBOutlet weak var lblNotifDate: UILabel!
  20. var cellDelegate: NotificationCellDelegate?
  21. var selectedNotificationItem: NotificationItem?
  22. var selectedPosition: Int?
  23. override func awakeFromNib() {
  24. super.awakeFromNib()
  25. self.selectionStyle = .none
  26. self.backgroundColor = .clear
  27. card.cornerRadius = 16
  28. card.setShadowElevation(ShadowElevation(rawValue: 2), for: .normal)
  29. card.setShadowColor(UIColor.black.withAlphaComponent(0.08), for: .normal)
  30. lblNotifContent.font = UIFont.systemFont(ofSize: 14, weight: .bold)
  31. lblNotifContent.textColor = UIColor.siraniTextPrimary
  32. lblNotifCustName.font = UIFont.systemFont(ofSize: 13, weight: .medium)
  33. lblNotifCustName.textColor = UIColor.siraniTextSecondary
  34. lblNotifDate.font = UIFont.systemFont(ofSize: 11, weight: .semibold)
  35. lblNotifDate.textColor = UIColor.siraniPrimaryBlue
  36. self.isSkeletonable = true
  37. card.isSkeletonable = true
  38. lblNotifContent.isSkeletonable = true
  39. lblNotifPlgId.isSkeletonable = true
  40. lblNotifCustName.isSkeletonable = true
  41. lblNotifDate.isSkeletonable = true
  42. }
  43. func updateViews(notificationItem: NotificationItem, position: Int) {
  44. card.isInteractable = true
  45. let gesture = UITapGestureRecognizer(target: self, action: #selector(self.onItemTap))
  46. card.addGestureRecognizer(gesture)
  47. if notificationItem.is_read == 1 {
  48. card.backgroundColor = .white
  49. } else {
  50. // Unread: Soft blue tint highlight
  51. card.backgroundColor = UIColor.siraniSoftBlue
  52. }
  53. selectedPosition = position
  54. selectedNotificationItem = notificationItem
  55. lblNotifContent.text = "\(notificationItem.judul_notifikasi)"
  56. lblNotifPlgId.text = "\(notificationItem.plg_id)"
  57. lblNotifCustName.text = "\(notificationItem.cust_name)"
  58. var activityDate = notificationItem.activity_date
  59. let dates = activityDate.split(separator: " ")
  60. if !dates.isEmpty {
  61. activityDate = String(dates[0])
  62. }
  63. lblNotifDate.text = activityDate
  64. }
  65. @objc func onItemTap(sender : UITapGestureRecognizer) {
  66. cellDelegate?.openNotifDetail(notificationItem: selectedNotificationItem, position: selectedPosition)
  67. }
  68. }