Avatar, label fonts, resignFirstResponder on scroll

-[] Backend
  -[] indexes e5.25
    -[x] wire up results: Contacts / Conversations / Messages actual: 3hr
    -[x] group thread est: actual:
      -[x] group name actual: e.25
      -[x] group member name: e.25
      -[x] group member number: e.25
    -[ ] contact thread e.5
      -[ ] name
      -[ ] number
    -[x] messages e1
      -[x] content
-[] Frontend e10.75
  -[x] wire up VC's a.5
  -[x] show search results only when search box has content a.25
  -[] show search results: Contact / Conversation / Messages e2
   -[x] wire up matchs
   -[] style contact cell
   -[] style conversation cell
   -[] style messages cell
  -[] tapping thread search result takes you to conversation e1
  -[] tapping message search result takes you to message e1
  -[x] show snippet text for matched message e1
  -[] highlight matched text in thread e3
  -[] No Results page
pull/1/head
Michael Kirk 7 years ago
parent e6b913b139
commit 21788f5f93

@ -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?
// MARK: UISearchBarDelegate
@objc
public var searchBar: UISearchBar?
// 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)
*/
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,
// 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 {

@ -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;

@ -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)")
}

Loading…
Cancel
Save