diff --git a/Signal/src/ViewControllers/HomeView/ConversationSearchViewController.swift b/Signal/src/ViewControllers/HomeView/ConversationSearchViewController.swift index 7416c7d65..a4e8ac75e 100644 --- a/Signal/src/ViewControllers/HomeView/ConversationSearchViewController.swift +++ b/Signal/src/ViewControllers/HomeView/ConversationSearchViewController.swift @@ -5,7 +5,7 @@ import Foundation @objc -class ConversationSearchViewController: UITableViewController { +class ConversationSearchViewController: UITableViewController, UISearchBarDelegate { var searchResultSet: SearchResultSet = SearchResultSet.empty @@ -122,52 +122,20 @@ class ConversationSearchViewController: UITableViewController { } } - /* - @available(iOS 2.0, *) - optional public func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? - - - // Editing - - // Individual rows can opt out of having the -editing property set for them. If not implemented, all rows are assumed to be editable. - @available(iOS 2.0, *) - optional public func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool - - - // Moving/reordering - - // Allows the reorder accessory view to optionally be shown for a particular row. By default, the reorder control will be shown only if the datasource implements -tableView:moveRowAtIndexPath:toIndexPath: - @available(iOS 2.0, *) - optional public func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool - - - // Index - - @available(iOS 2.0, *) - optional public func sectionIndexTitles(for tableView: UITableView) -> [String]? // return list of section titles to display in section index view (e.g. "ABCD...Z#") - - @available(iOS 2.0, *) - optional public func tableView(_ tableView: UITableView, sectionForSectionIndexTitle title: String, at index: Int) -> Int // tell table which section corresponds to section title/index (e.g. "B",1)) - - - // Data manipulation - insert and delete support - - // After a row has the minus or plus button invoked (based on the UITableViewCellEditingStyle for the cell), the dataSource must commit the change - // Not called for edit actions using UITableViewRowAction - the action's handler will be invoked instead - @available(iOS 2.0, *) - optional public func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) - - - // Data manipulation - reorder / moving support - - @available(iOS 2.0, *) - optional public func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) - - */ + // MARK: UISearchBarDelegate -} + @objc + public var searchBar: UISearchBar? + + override func scrollViewWillBeginDragging(_ scrollView: UIScrollView) { + guard let searchBar = self.searchBar else { + owsFail("\(logTag) searchBar was unexpectedly nil") + return + } + + searchBar.resignFirstResponder() + } -extension ConversationSearchViewController: UISearchBarDelegate { public func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) { guard searchText.stripped.count > 0 else { self.searchResultSet = SearchResultSet.empty @@ -193,15 +161,19 @@ class ChatSearchResultCell: UITableViewCell { let nameLabel: UILabel let snippetLabel: UILabel let avatarView: AvatarImageView + let avatarWidth: UInt = 40 override init(style: UITableViewCellStyle, reuseIdentifier: String?) { self.nameLabel = UILabel() self.snippetLabel = UILabel() self.avatarView = AvatarImageView() - avatarView.autoSetDimensions(to: CGSize(width: 40, height: 40)) + avatarView.autoSetDimensions(to: CGSize(width: CGFloat(avatarWidth), height: CGFloat(avatarWidth))) super.init(style: style, reuseIdentifier: reuseIdentifier) + nameLabel.font = UIFont.ows_dynamicTypeBody.ows_mediumWeight() + snippetLabel.font = UIFont.ows_dynamicTypeFootnote + let textRows = UIStackView(arrangedSubviews: [nameLabel, snippetLabel]) textRows.axis = .vertical @@ -217,7 +189,12 @@ class ChatSearchResultCell: UITableViewCell { fatalError("init(coder:) has not been implemented") } + var contactsManager: OWSContactsManager { + return Environment.current().contactsManager + } + func configure(searchResult: SearchResult) { + self.avatarView.image = OWSAvatarBuilder.buildImage(thread: searchResult.thread.threadRecord, diameter: avatarWidth, contactsManager: self.contactsManager) self.nameLabel.text = searchResult.thread.name self.snippetLabel.text = searchResult.snippet } @@ -235,6 +212,9 @@ class MessageSearchResultCell: UITableViewCell { super.init(style: style, reuseIdentifier: reuseIdentifier) + nameLabel.font = UIFont.ows_dynamicTypeBody.ows_mediumWeight() + snippetLabel.font = UIFont.ows_dynamicTypeFootnote + let textRows = UIStackView(arrangedSubviews: [nameLabel, snippetLabel]) textRows.axis = .vertical @@ -261,9 +241,12 @@ class MessageSearchResultCell: UITableViewCell { // Bold snippet text do { - let attributedSnippet = try NSAttributedString(data: encodedString, - options: [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html], - documentAttributes: nil) + + // FIXME - apply our font without clobbering bold. + let attributedSnippet = try NSMutableAttributedString(data: encodedString, + options: [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html], + documentAttributes: nil) + attributedSnippet.addAttribute(NSAttributedStringKey.font, value: self.snippetLabel.font, range: NSRange(location: 0, length: attributedSnippet.length)) self.snippetLabel.attributedText = attributedSnippet } catch { diff --git a/Signal/src/ViewControllers/HomeView/HomeViewController.m b/Signal/src/ViewControllers/HomeView/HomeViewController.m index 42cf6d2c7..116b6039f 100644 --- a/Signal/src/ViewControllers/HomeView/HomeViewController.m +++ b/Signal/src/ViewControllers/HomeView/HomeViewController.m @@ -313,6 +313,7 @@ NSString *const kArchivedConversationsReuseIdentifier = @"kArchivedConversations // TODO - better/more flexible way to pin below search bar? [searchController.view autoPinEdgesToSuperviewEdgesWithInsets:UIEdgeInsetsMake(60, 0, 0, 0)]; searchBar.delegate = searchController; + searchController.searchBar = searchBar; OWSAssert(self.tableView.tableHeaderView == nil); self.tableView.tableHeaderView = self.searchBar; diff --git a/SignalMessaging/utils/ConversationSearcher.swift b/SignalMessaging/utils/ConversationSearcher.swift index 93d8393fc..fcdc7656f 100644 --- a/SignalMessaging/utils/ConversationSearcher.swift +++ b/SignalMessaging/utils/ConversationSearcher.swift @@ -64,6 +64,8 @@ public class ConversationSearcher: NSObject { let searchResult = SearchResult(thread: threadViewModel, snippet: snippet) messages.append(searchResult) + } else if let signalAccount = match as? SignalAccount { + // TODO show "other contact" results when there is no existing thread } else { Logger.debug("\(self.logTag) in \(#function) unhandled item: \(match)") }