From d4d82c2f4f71cef2a0b8f268a2ac11642236ad31 Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Mon, 19 Aug 2024 16:10:53 +0200 Subject: [PATCH] Move timer to cell (#2220) As the timestamp never changes, I don't see the need to reload the entire tableView if it's sufficient to update the Timestamp-Label --- deltachat-ios/Chat/Views/Cells/BaseMessageCell.swift | 11 +++++++++++ deltachat-ios/Chat/Views/StatusView.swift | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/deltachat-ios/Chat/Views/Cells/BaseMessageCell.swift b/deltachat-ios/Chat/Views/Cells/BaseMessageCell.swift index 66b10c1e7..1707139e2 100644 --- a/deltachat-ios/Chat/Views/Cells/BaseMessageCell.swift +++ b/deltachat-ios/Chat/Views/Cells/BaseMessageCell.swift @@ -173,6 +173,7 @@ public class BaseMessageCell: UITableViewCell { let reactionsView: ReactionsView private var showSelectionBackground: Bool + private var timer: Timer? override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { @@ -439,7 +440,15 @@ public class BaseMessageCell: UITableViewCell { } else { tintColor = DcColors.incomingMessageSecondaryTextColor } + bottomLabel.update(message: msg, tintColor: tintColor) + let timer = Timer.scheduledTimer(withTimeInterval: 60, repeats: true) { [weak self] _ in + guard let self else { return } + + self.bottomLabel.dateLabel.text = msg.formattedSentDate() + } + + self.timer = timer } if let quoteText = msg.quoteText { @@ -586,6 +595,8 @@ public class BaseMessageCell: UITableViewCell { actionButton.isEnabled = true showSelectionBackground = false reactionsView.prepareForReuse() + timer?.invalidate() + timer = nil } @objc func reactionsViewTapped(_ sender: Any?) { diff --git a/deltachat-ios/Chat/Views/StatusView.swift b/deltachat-ios/Chat/Views/StatusView.swift index ee6a30fc1..c7e2096e7 100644 --- a/deltachat-ios/Chat/Views/StatusView.swift +++ b/deltachat-ios/Chat/Views/StatusView.swift @@ -4,7 +4,7 @@ import DcCore public class StatusView: UIView { private let contentStackView: UIStackView - private let dateLabel: UILabel + let dateLabel: UILabel private let padlockView: UIImageView private let locationView: UIImageView private let stateView: UIImageView