Add 'Archive' token in search bar when searching in archive

This commit is contained in:
Ilya Laktyushin 2021-12-10 17:35:52 +04:00
parent 6630833866
commit 54cd578656
10 changed files with 154 additions and 13 deletions

View File

@ -7139,3 +7139,5 @@ Sorry for the inconvenience.";
"UserInfo.QRCode.InfoOther" = "Everyone on Telegram can scan this code to message %@.";
"PeerInfo.QRCode.Title" = "QR Code";
"ChatList.Archive" = "Archive";

View File

@ -31,6 +31,7 @@ import UndoUI
import TextFormat
private enum ChatListTokenId: Int32 {
case archive
case filter
case peer
case date
@ -457,13 +458,17 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo
private func updateSearchOptions(_ options: ChatListSearchOptions?, clearQuery: Bool = false) {
var options = options
var tokens: [SearchBarToken] = []
if self.groupId == .archive {
tokens.append(SearchBarToken(id: ChatListTokenId.archive.rawValue, icon: UIImage(bundleImageName: "Chat List/Search/Archive"), title: self.presentationData.strings.ChatList_Archive, permanent: true))
}
if options?.isEmpty ?? true {
options = nil
}
self.searchOptionsValue = options
self.searchOptions.set(.single(options))
var tokens: [SearchBarToken] = []
if let (peerId, isGroup, peerName) = options?.peer {
let image: UIImage?
if isGroup {
@ -473,11 +478,11 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo
} else {
image = UIImage(bundleImageName: "Chat List/Search/User")
}
tokens.append(SearchBarToken(id: ChatListTokenId.peer.rawValue, icon:image, title: peerName))
tokens.append(SearchBarToken(id: ChatListTokenId.peer.rawValue, icon: image, title: peerName, permanent: false))
}
if let (_, _, dateTitle) = options?.date {
tokens.append(SearchBarToken(id: ChatListTokenId.date.rawValue, icon: UIImage(bundleImageName: "Chat List/Search/Calendar"), title: dateTitle))
tokens.append(SearchBarToken(id: ChatListTokenId.date.rawValue, icon: UIImage(bundleImageName: "Chat List/Search/Calendar"), title: dateTitle, permanent: false))
self.suggestedDates.set(.single([]))
}
@ -524,7 +529,12 @@ public final class ChatListSearchContainerNode: SearchDisplayControllerContentNo
self.paneContainerNode.requestSelectPane(key)
self.updateSearchOptions(nil)
self.searchTextUpdated(text: query ?? "")
self.setQuery?(nil, [], query ?? "")
var tokens: [SearchBarToken] = []
if self.groupId == .archive {
tokens.append(SearchBarToken(id: ChatListTokenId.archive.rawValue, icon: UIImage(bundleImageName: "Chat List/Search/Archive"), title: self.presentationData.strings.ChatList_Archive, permanent: true))
}
self.setQuery?(nil, tokens, query ?? "")
}
override public func containerLayoutUpdated(_ layout: ContainerViewLayout, navigationBarHeight: CGFloat, transition: ContainedViewLayoutTransition) {

View File

@ -43,12 +43,14 @@ public struct SearchBarToken {
public let icon: UIImage?
public let title: String
public let style: Style?
public let permanent: Bool
public init(id: AnyHashable, icon: UIImage?, title: String, style: Style? = nil) {
public init(id: AnyHashable, icon: UIImage?, title: String, style: Style? = nil, permanent: Bool) {
self.id = id
self.icon = icon
self.title = title
self.style = style
self.permanent = permanent
}
}
@ -106,6 +108,7 @@ private final class TokenNode: ASDisplayNode {
}
@objc private func tapGesture() {
self.tapped?()
}
@ -264,7 +267,7 @@ private class SearchBarTextField: UITextField, UIScrollViewDelegate {
if i < self.tokens.count - 1 && isSelected {
hasSelected = true
}
let isCollapsed = !isSelected && (i < self.tokens.count - 1 || hasSelected)
let isCollapsed = !isSelected && (token.permanent || (i < self.tokens.count - 1 || hasSelected))
tokenNode.update(theme: self.theme, token: token, isSelected: isSelected, isCollapsed: isCollapsed)
}
var removeKeys: [AnyHashable] = []
@ -863,8 +866,10 @@ public class SearchBarNode: ASDisplayNode, UITextFieldDelegate {
return false
}
if let index = strongSelf.textField.selectedTokenIndex {
if !strongSelf.tokens[index].permanent {
strongSelf.tokens.remove(at: index)
strongSelf.tokensUpdated?(strongSelf.tokens)
}
return true
} else if strongSelf.text.isEmpty {
strongSelf.clearPressed()

View File

@ -70,15 +70,18 @@ public final class SearchDisplayController {
self.contentNode.dismissInput = { [weak self] in
self?.searchBar.deactivate(clear: false)
}
var isFirstTime = true
self.contentNode.setQuery = { [weak self] prefix, tokens, query in
if let strongSelf = self {
strongSelf.searchBar.prefixString = prefix
let previousTokens = strongSelf.searchBar.tokens
strongSelf.searchBar.tokens = tokens
strongSelf.searchBar.text = query
if previousTokens.count < tokens.count {
if previousTokens.count < tokens.count && !isFirstTime {
strongSelf.searchBar.selectLastToken()
}
isFirstTime = false
}
}
if let placeholder = placeholder {

View File

@ -681,7 +681,7 @@ final class ThemeGridSearchContentNode: SearchDisplayControllerContentNode {
foregroundColor = .white
strokeColor = color.displayColor
}
tokens = [SearchBarToken(id: 0, icon: UIImage(bundleImageName: "Settings/WallpaperSearchColorIcon"), title: color.localizedString(strings: self.presentationData.strings), style: SearchBarToken.Style(backgroundColor: backgroundColor, foregroundColor: foregroundColor, strokeColor: strokeColor))]
tokens = [SearchBarToken(id: 0, icon: UIImage(bundleImageName: "Settings/WallpaperSearchColorIcon"), title: color.localizedString(strings: self.presentationData.strings), style: SearchBarToken.Style(backgroundColor: backgroundColor, foregroundColor: foregroundColor, strokeColor: strokeColor), permanent: false)]
text = query
placeholder = self.presentationData.strings.Wallpaper_SearchShort
}

View File

@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "archive_18.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

View File

@ -0,0 +1,109 @@
%PDF-1.7
1 0 obj
<< >>
endobj
2 0 obj
<< /Length 3 0 R >>
stream
/DeviceRGB CS
/DeviceRGB cs
q
1.000000 0.000000 -0.000000 1.000000 3.000000 11.625000 cm
0.000000 0.000000 0.000000 scn
0.000000 1.500000 m
0.000000 1.848739 -0.000000 2.023109 0.038333 2.166172 c
0.142359 2.554400 0.445600 2.857641 0.833829 2.961667 c
0.976891 3.000000 1.151261 3.000000 1.500000 3.000000 c
10.500000 3.000000 l
10.848740 3.000000 11.023109 3.000000 11.166171 2.961667 c
11.554400 2.857641 11.857641 2.554400 11.961666 2.166172 c
12.000000 2.023109 12.000000 1.848739 12.000000 1.500000 c
12.000000 1.500000 l
12.000000 1.151261 12.000000 0.976891 11.961666 0.833829 c
11.857641 0.445600 11.554400 0.142359 11.166171 0.038333 c
11.023109 0.000000 10.848740 0.000000 10.500000 0.000000 c
1.500000 0.000000 l
1.151261 0.000000 0.976891 0.000000 0.833829 0.038333 c
0.445600 0.142359 0.142359 0.445600 0.038333 0.833829 c
-0.000000 0.976891 0.000000 1.151261 0.000000 1.500000 c
0.000000 1.500000 l
h
f
n
Q
q
1.000000 0.000000 -0.000000 1.000000 3.750000 3.375000 cm
0.000000 0.000000 0.000000 scn
0.000000 3.200033 m
0.000000 7.625000 l
10.500000 7.625000 l
10.500000 3.200035 l
10.500000 2.079930 10.500000 1.519877 10.282013 1.092054 c
10.090266 0.715730 9.784306 0.409769 9.407981 0.218022 c
8.980158 0.000035 8.420105 0.000035 7.300000 0.000035 c
3.200000 0.000035 l
2.079895 0.000035 1.519843 0.000035 1.092019 0.218022 c
0.715695 0.409769 0.409734 0.715730 0.217987 1.092054 c
0.000000 1.519877 0.000000 2.079929 0.000000 3.200033 c
h
3.000000 6.500000 m
2.723858 6.500000 2.500000 6.276142 2.500000 6.000000 c
2.500000 5.723858 2.723858 5.500000 3.000000 5.500000 c
7.500000 5.500000 l
7.776143 5.500000 8.000000 5.723858 8.000000 6.000000 c
8.000000 6.276142 7.776143 6.500000 7.500000 6.500000 c
3.000000 6.500000 l
h
f*
n
Q
endstream
endobj
3 0 obj
1750
endobj
4 0 obj
<< /Annots []
/Type /Page
/MediaBox [ 0.000000 0.000000 18.000000 18.000000 ]
/Resources 1 0 R
/Contents 2 0 R
/Parent 5 0 R
>>
endobj
5 0 obj
<< /Kids [ 4 0 R ]
/Count 1
/Type /Pages
>>
endobj
6 0 obj
<< /Pages 5 0 R
/Type /Catalog
>>
endobj
xref
0 7
0000000000 65535 f
0000000010 00000 n
0000000034 00000 n
0000001840 00000 n
0000001863 00000 n
0000002036 00000 n
0000002110 00000 n
trailer
<< /ID [ (some) (id) ]
/Root 6 0 R
/Size 7
>>
startxref
2169
%%EOF

View File

@ -112,7 +112,7 @@ final class ChatSearchNavigationContentNode: NavigationBarContentNode {
self.searchBar.prefixString = NSAttributedString(string: strings.Conversation_SearchByName_Prefix, font: searchBarFont, textColor: theme.rootController.navigationSearchBar.inputTextColor)
self.searchBar.placeholderString = nil
case let .member(peer):
self.searchBar.tokens = [SearchBarToken(id: peer.id, icon: UIImage(bundleImageName: "Chat List/Search/User"), title: EnginePeer(peer).compactDisplayTitle)]
self.searchBar.tokens = [SearchBarToken(id: peer.id, icon: UIImage(bundleImageName: "Chat List/Search/User"), title: EnginePeer(peer).compactDisplayTitle, permanent: false)]
self.searchBar.prefixString = nil
self.searchBar.placeholderString = nil
}

View File

@ -114,7 +114,7 @@ final class MessageMediaPlaylistItem: SharedMediaPlaylistItem {
albumArt = SharedMediaPlaybackAlbumArt(thumbnailResource: ExternalMusicAlbumArtResource(title: updatedTitle ?? "", performer: updatedPerformer ?? "", isThumbnail: true), fullSizeResource: ExternalMusicAlbumArtResource(title: updatedTitle ?? "", performer: updatedPerformer ?? "", isThumbnail: false))
}
return SharedMediaPlaybackDisplayData.music(title: updatedTitle, performer: updatedPerformer, albumArt: albumArt, long: duration > 60 * 20)
return SharedMediaPlaybackDisplayData.music(title: updatedTitle, performer: updatedPerformer, albumArt: albumArt, long: CGFloat(duration) > 10.0 * 60.0)
}
case let .Video(_, _, flags):
if flags.contains(.instantRoundVideo) {

View File

@ -528,7 +528,7 @@ class StickerPaneTrendingListGridItemNode: GridItemNode {
let titleFrame = CGRect(origin: CGPoint(x: params.leftInset + leftInset, y: topOffset), size: titleLayout.size)
let dismissButtonSize = CGSize(width: 12.0, height: 12.0)
self.dismissButtonNode.frame = CGRect(origin: CGPoint(x: params.width - params.rightInset - rightInset - dismissButtonSize.width, y: topOffset - 1.0), size: dismissButtonSize)
self.dismissButtonNode.frame = CGRect(origin: CGPoint(x: params.width - params.rightInset - rightInset - dismissButtonSize.width + 1.0, y: topOffset - 1.0), size: dismissButtonSize)
self.dismissButtonNode.isHidden = item.dismiss == nil
self.titleNode.frame = titleFrame
}