| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- //
- // NotificationCell.swift
- // Sirani
- //
- // Created by Anhar Solehudin on 10/11/20.
- // Copyright © 2020 Anhar Solehudin. All rights reserved.
- //
- import UIKit
- import MaterialComponents.MaterialCards
- import SkeletonView
- 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?
-
- override func awakeFromNib() {
- super.awakeFromNib()
-
- self.selectionStyle = .none
- self.backgroundColor = .clear
-
- card.cornerRadius = 16
- card.setShadowElevation(ShadowElevation(rawValue: 2), for: .normal)
- card.setShadowColor(UIColor.black.withAlphaComponent(0.08), for: .normal)
-
- lblNotifContent.font = UIFont.systemFont(ofSize: 14, weight: .bold)
- lblNotifContent.textColor = UIColor.siraniTextPrimary
-
- lblNotifCustName.font = UIFont.systemFont(ofSize: 13, weight: .medium)
- lblNotifCustName.textColor = UIColor.siraniTextSecondary
-
- lblNotifDate.font = UIFont.systemFont(ofSize: 11, weight: .semibold)
- lblNotifDate.textColor = UIColor.siraniPrimaryBlue
-
- self.isSkeletonable = true
- card.isSkeletonable = true
- lblNotifContent.isSkeletonable = true
- lblNotifPlgId.isSkeletonable = true
- lblNotifCustName.isSkeletonable = true
- lblNotifDate.isSkeletonable = true
- }
- 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 = .white
- } else {
- // Unread: Soft blue tint highlight
- card.backgroundColor = UIColor.siraniSoftBlue
- }
-
- 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)
- }
- }
|