improve unhighlighted text colour and contrast

pull/555/head
Ryan Zhao 3 years ago
parent af7dd3e82f
commit 675dde9b1e

@ -204,7 +204,6 @@ final class ConversationCell : UITableViewCell {
AssertIsOnMainThread() AssertIsOnMainThread()
guard let thread = threadViewModel?.threadRecord else { return } guard let thread = threadViewModel?.threadRecord else { return }
profilePictureView.update(for: thread) profilePictureView.update(for: thread)
displayNameLabel.text = getDisplayName()
isPinnedIcon.isHidden = true isPinnedIcon.isHidden = true
unreadCountView.isHidden = true unreadCountView.isHidden = true
hasMentionView.isHidden = true hasMentionView.isHidden = true
@ -213,24 +212,25 @@ final class ConversationCell : UITableViewCell {
public func configure(messageDate: Date?, snippet: String?, searchText: String) { public func configure(messageDate: Date?, snippet: String?, searchText: String) {
if let messageDate = messageDate, let snippet = snippet { if let messageDate = messageDate, let snippet = snippet {
// Message // Message
displayNameLabel.attributedText = NSMutableAttributedString(string: getDisplayName(), attributes: [.foregroundColor:Colors.text])
timestampLabel.isHidden = false timestampLabel.isHidden = false
timestampLabel.text = DateUtil.formatDate(forDisplay: messageDate) timestampLabel.text = DateUtil.formatDate(forDisplay: messageDate)
bottomLabelStackView.isHidden = false bottomLabelStackView.isHidden = false
snippetLabel.attributedText = getHighlightedSnippet(snippet: snippet, searchText: searchText) snippetLabel.attributedText = getHighlightedSnippet(snippet: snippet, searchText: searchText, fontSize: Values.smallFontSize)
} else { } else {
// Contact // Contact
displayNameLabel.attributedText = getHighlightedSnippet(snippet: displayNameLabel.text!, searchText: searchText) displayNameLabel.attributedText = getHighlightedSnippet(snippet: getDisplayName(), searchText: searchText, fontSize: Values.mediumFontSize)
bottomLabelStackView.isHidden = true bottomLabelStackView.isHidden = true
timestampLabel.isHidden = true timestampLabel.isHidden = true
} }
} }
private func getHighlightedSnippet(snippet: String, searchText: String) -> NSMutableAttributedString { private func getHighlightedSnippet(snippet: String, searchText: String, fontSize: CGFloat) -> NSMutableAttributedString {
guard snippet != NSLocalizedString("NOTE_TO_SELF", comment: "") else { guard snippet != NSLocalizedString("NOTE_TO_SELF", comment: "") else {
return NSMutableAttributedString(string: snippet, attributes: [.foregroundColor:Colors.text]) return NSMutableAttributedString(string: snippet, attributes: [.foregroundColor:Colors.text])
} }
let result = NSMutableAttributedString(string: snippet, attributes: [.foregroundColor:UIColor.gray]) let result = NSMutableAttributedString(string: snippet, attributes: [.foregroundColor:Colors.text.withAlphaComponent(Values.lowOpacity)])
let normalizedSnippet = snippet.lowercased() as NSString let normalizedSnippet = snippet.lowercased() as NSString
let normalizedSearchText = searchText.lowercased() let normalizedSearchText = searchText.lowercased()
@ -238,6 +238,7 @@ final class ConversationCell : UITableViewCell {
let range = normalizedSnippet.range(of: normalizedSearchText) let range = normalizedSnippet.range(of: normalizedSearchText)
result.addAttribute(.foregroundColor, value: Colors.text, range: range) result.addAttribute(.foregroundColor, value: Colors.text, range: range)
result.addAttribute(.font, value: UIFont.boldSystemFont(ofSize: fontSize), range: range)
return result return result
} }

Loading…
Cancel
Save