Skip to content

Commit

Permalink
Move timer to cell (#2220)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
zeitschlag committed Aug 21, 2024
1 parent bc3b756 commit d4d82c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions deltachat-ios/Chat/Views/Cells/BaseMessageCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?) {

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -586,6 +595,8 @@ public class BaseMessageCell: UITableViewCell {
actionButton.isEnabled = true
showSelectionBackground = false
reactionsView.prepareForReuse()
timer?.invalidate()
timer = nil
}

@objc func reactionsViewTapped(_ sender: Any?) {
Expand Down
2 changes: 1 addition & 1 deletion deltachat-ios/Chat/Views/StatusView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d4d82c2

Please sign in to comment.