mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
UI improvements on contact search results
This commit is contained in:
parent
72802b9579
commit
5c112064da
|
@ -265,7 +265,7 @@ extension GlobalSearchViewController {
|
||||||
cell.isShowingGlobalSearchResult = true
|
cell.isShowingGlobalSearchResult = true
|
||||||
let searchResult = sectionResults[safe: indexPath.row]
|
let searchResult = sectionResults[safe: indexPath.row]
|
||||||
cell.threadViewModel = searchResult?.thread
|
cell.threadViewModel = searchResult?.thread
|
||||||
cell.configure(messageDate: searchResult?.messageDate, snippet: searchResult?.snippet)
|
cell.configure(messageDate: searchResult?.messageDate, snippet: searchResult?.snippet, searchText: searchResultSet.searchText)
|
||||||
return cell
|
return cell
|
||||||
case .messages:
|
case .messages:
|
||||||
let sectionResults = searchResultSet.messages
|
let sectionResults = searchResultSet.messages
|
||||||
|
@ -273,7 +273,7 @@ extension GlobalSearchViewController {
|
||||||
cell.isShowingGlobalSearchResult = true
|
cell.isShowingGlobalSearchResult = true
|
||||||
let searchResult = sectionResults[safe: indexPath.row]
|
let searchResult = sectionResults[safe: indexPath.row]
|
||||||
cell.threadViewModel = searchResult?.thread
|
cell.threadViewModel = searchResult?.thread
|
||||||
cell.configure(messageDate: searchResult?.messageDate, snippet: searchResult?.snippet)
|
cell.configure(messageDate: searchResult?.messageDate, snippet: searchResult?.snippet, searchText: searchResultSet.searchText)
|
||||||
return cell
|
return cell
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,6 +101,22 @@ final class ConversationCell : UITableViewCell {
|
||||||
return result
|
return result
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
private lazy var topLabelStackView: UIStackView = {
|
||||||
|
let result = UIStackView()
|
||||||
|
result.axis = .horizontal
|
||||||
|
result.alignment = .center
|
||||||
|
result.spacing = Values.smallSpacing / 2 // Effectively Values.smallSpacing because there'll be spacing before and after the invisible spacer
|
||||||
|
return result
|
||||||
|
}()
|
||||||
|
|
||||||
|
private lazy var bottomLabelStackView: UIStackView = {
|
||||||
|
let result = UIStackView()
|
||||||
|
result.axis = .horizontal
|
||||||
|
result.alignment = .center
|
||||||
|
result.spacing = Values.smallSpacing / 2 // Effectively Values.smallSpacing because there'll be spacing before and after the invisible spacer
|
||||||
|
return result
|
||||||
|
}()
|
||||||
|
|
||||||
// MARK: Settings
|
// MARK: Settings
|
||||||
private static let unreadCountViewSize: CGFloat = 20
|
private static let unreadCountViewSize: CGFloat = 20
|
||||||
private static let statusIndicatorSize: CGFloat = 14
|
private static let statusIndicatorSize: CGFloat = 14
|
||||||
|
@ -140,21 +156,20 @@ final class ConversationCell : UITableViewCell {
|
||||||
hasMentionLabel.pin(to: hasMentionView)
|
hasMentionLabel.pin(to: hasMentionView)
|
||||||
// Label stack view
|
// Label stack view
|
||||||
let topLabelSpacer = UIView.hStretchingSpacer()
|
let topLabelSpacer = UIView.hStretchingSpacer()
|
||||||
let topLabelStackView = UIStackView(arrangedSubviews: [ displayNameLabel, isPinnedIcon, unreadCountView, hasMentionView, topLabelSpacer, timestampLabel ])
|
[ displayNameLabel, isPinnedIcon, unreadCountView, hasMentionView, topLabelSpacer, timestampLabel ].forEach{ view in
|
||||||
topLabelStackView.axis = .horizontal
|
topLabelStackView.addArrangedSubview(view)
|
||||||
topLabelStackView.alignment = .center
|
}
|
||||||
topLabelStackView.spacing = Values.smallSpacing / 2 // Effectively Values.smallSpacing because there'll be spacing before and after the invisible spacer
|
|
||||||
let snippetLabelContainer = UIView()
|
let snippetLabelContainer = UIView()
|
||||||
snippetLabelContainer.addSubview(snippetLabel)
|
snippetLabelContainer.addSubview(snippetLabel)
|
||||||
snippetLabelContainer.addSubview(typingIndicatorView)
|
snippetLabelContainer.addSubview(typingIndicatorView)
|
||||||
let bottomLabelSpacer = UIView.hStretchingSpacer()
|
let bottomLabelSpacer = UIView.hStretchingSpacer()
|
||||||
let bottomLabelStackView = UIStackView(arrangedSubviews: [ snippetLabelContainer, bottomLabelSpacer, statusIndicatorView ])
|
[ snippetLabelContainer, bottomLabelSpacer, statusIndicatorView ].forEach{ view in
|
||||||
bottomLabelStackView.axis = .horizontal
|
bottomLabelStackView.addArrangedSubview(view)
|
||||||
bottomLabelStackView.alignment = .center
|
}
|
||||||
bottomLabelStackView.spacing = Values.smallSpacing / 2 // Effectively Values.smallSpacing because there'll be spacing before and after the invisible spacer
|
let labelContainerView = UIStackView(arrangedSubviews: [ topLabelStackView, bottomLabelStackView ])
|
||||||
let labelContainerView = UIView()
|
labelContainerView.axis = .vertical
|
||||||
labelContainerView.addSubview(topLabelStackView)
|
labelContainerView.alignment = .leading
|
||||||
labelContainerView.addSubview(bottomLabelStackView)
|
labelContainerView.spacing = 6
|
||||||
// Main stack view
|
// Main stack view
|
||||||
let stackView = UIStackView(arrangedSubviews: [ accentLineView, profilePictureView, labelContainerView ])
|
let stackView = UIStackView(arrangedSubviews: [ accentLineView, profilePictureView, labelContainerView ])
|
||||||
stackView.axis = .horizontal
|
stackView.axis = .horizontal
|
||||||
|
@ -177,16 +192,6 @@ final class ConversationCell : UITableViewCell {
|
||||||
snippetLabel.pin(to: snippetLabelContainer)
|
snippetLabel.pin(to: snippetLabelContainer)
|
||||||
typingIndicatorView.pin(.leading, to: .leading, of: snippetLabelContainer)
|
typingIndicatorView.pin(.leading, to: .leading, of: snippetLabelContainer)
|
||||||
typingIndicatorView.centerYAnchor.constraint(equalTo: snippetLabel.centerYAnchor).isActive = true
|
typingIndicatorView.centerYAnchor.constraint(equalTo: snippetLabel.centerYAnchor).isActive = true
|
||||||
// HACK: Not using a stack view for this is part of a workaround for a weird layout bug
|
|
||||||
topLabelStackView.pin(.leading, to: .leading, of: labelContainerView)
|
|
||||||
topLabelStackView.pin(.top, to: .top, of: labelContainerView, withInset: 12)
|
|
||||||
topLabelStackView.pin(.trailing, to: .trailing, of: labelContainerView)
|
|
||||||
bottomLabelStackView.pin(.leading, to: .leading, of: labelContainerView)
|
|
||||||
bottomLabelStackView.pin(.top, to: .bottom, of: topLabelStackView, withInset: 6)
|
|
||||||
labelContainerView.pin(.bottom, to: .bottom, of: bottomLabelStackView, withInset: 12)
|
|
||||||
// HACK: The two lines below are part of a workaround for a weird layout bug
|
|
||||||
labelContainerView.set(.width, to: UIScreen.main.bounds.width - Values.accentLineThickness - Values.mediumSpacing - profilePictureViewSize - Values.mediumSpacing - Values.mediumSpacing)
|
|
||||||
labelContainerView.set(.height, to: cellHeight)
|
|
||||||
stackView.pin(.leading, to: .leading, of: contentView)
|
stackView.pin(.leading, to: .leading, of: contentView)
|
||||||
stackView.pin(.top, to: .top, of: contentView)
|
stackView.pin(.top, to: .top, of: contentView)
|
||||||
// HACK: The two lines below are part of a workaround for a weird layout bug
|
// HACK: The two lines below are part of a workaround for a weird layout bug
|
||||||
|
@ -205,16 +210,33 @@ final class ConversationCell : UITableViewCell {
|
||||||
hasMentionView.isHidden = true
|
hasMentionView.isHidden = true
|
||||||
}
|
}
|
||||||
|
|
||||||
public func configure(messageDate: Date?, snippet: 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
|
||||||
|
timestampLabel.isHidden = false
|
||||||
timestampLabel.text = DateUtil.formatDate(forDisplay: messageDate)
|
timestampLabel.text = DateUtil.formatDate(forDisplay: messageDate)
|
||||||
snippetLabel.text = snippet
|
bottomLabelStackView.isHidden = false
|
||||||
|
snippetLabel.attributedText = getHighlightedSnippet(snippet: snippet, searchText: searchText)
|
||||||
} else {
|
} else {
|
||||||
timestampLabel.text = DateUtil.formatDate(forDisplay: threadViewModel.lastMessageDate)
|
// Contact
|
||||||
snippetLabel.attributedText = getSnippet()
|
displayNameLabel.attributedText = getHighlightedSnippet(snippet: displayNameLabel.text!, searchText: searchText)
|
||||||
|
bottomLabelStackView.isHidden = true
|
||||||
|
timestampLabel.isHidden = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func getHighlightedSnippet(snippet: String, searchText: String) -> NSMutableAttributedString {
|
||||||
|
let result = NSMutableAttributedString(string: snippet, attributes: [.foregroundColor:UIColor.gray])
|
||||||
|
let normalizedSnippet = snippet.lowercased() as NSString
|
||||||
|
let normalizedSearchText = searchText.lowercased()
|
||||||
|
|
||||||
|
guard normalizedSnippet.contains(normalizedSearchText) else { return result }
|
||||||
|
|
||||||
|
let range = normalizedSnippet.range(of: normalizedSearchText)
|
||||||
|
result.addAttribute(.foregroundColor, value: Colors.text, range: range)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: Updating
|
// MARK: Updating
|
||||||
private func update() {
|
private func update() {
|
||||||
AssertIsOnMainThread()
|
AssertIsOnMainThread()
|
||||||
|
|
Loading…
Reference in a new issue