| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- //
- // NotificationCell.swift
- // Sirani
- //
- // Created by Anhar Solehudin on 10/11/20.
- // Copyright © 2020 Anhar Solehudin. All rights reserved.
- //
- import UIKit
- import MaterialComponents.MaterialCards
- protocol NotificationCellDelegate: NSObjectProtocol {
- func openNotifDetail(notificationItem: NotificationItem?, position: Int?)
- }
- class NotificationCell: UITableViewCell {
-
- @IBOutlet weak var card: MDCCard!
- @IBOutlet weak var lblNotifContent: UILabel!
- @IBOutlet weak var lblNotifPlgId: UILabel!
- @IBOutlet weak var lblNotifCustName: UILabel!
- @IBOutlet weak var lblNotifDate: UILabel!
-
- var cellDelegate: NotificationCellDelegate?
- var selectedNotificationItem: NotificationItem?
- var selectedPosition: Int?
- func updateViews(notificationItem: NotificationItem, position: Int) {
- card.isInteractable = true
-
- let gesture = UITapGestureRecognizer(target: self, action: #selector(self.onItemTap))
- card.addGestureRecognizer(gesture)
-
- if notificationItem.is_read == 1 {
- card.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
- } else {
- card.backgroundColor = #colorLiteral(red: 0.8428310752, green: 0.837821424, blue: 0.8466822505, alpha: 1)
- }
-
- selectedPosition = position
- selectedNotificationItem = notificationItem
- lblNotifContent.text = "\(notificationItem.judul_notifikasi)"
- lblNotifPlgId.text = "\(notificationItem.plg_id)"
- lblNotifCustName.text = "\(notificationItem.cust_name)"
-
- var activityDate = notificationItem.activity_date
- let dates = activityDate.split(separator: " ")
- if !dates.isEmpty {
- activityDate = String(dates[0])
- }
- lblNotifDate.text = activityDate
- }
-
- @objc func onItemTap(sender : UITapGestureRecognizer) {
- cellDelegate?.openNotifDetail(notificationItem: selectedNotificationItem, position: selectedPosition)
- }
- }
|