mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 14:20:20 +00:00
Group boosts
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
|
||||
|
||||
swift_library(
|
||||
name = "GroupStickerPackSetupController",
|
||||
module_name = "GroupStickerPackSetupController",
|
||||
srcs = glob([
|
||||
"Sources/**/*.swift",
|
||||
]),
|
||||
copts = [
|
||||
"-warnings-as-errors",
|
||||
],
|
||||
deps = [
|
||||
"//submodules/Display:Display",
|
||||
"//submodules/Postbox:Postbox",
|
||||
"//submodules/TelegramCore:TelegramCore",
|
||||
"//submodules/TelegramPresentationData:TelegramPresentationData",
|
||||
"//submodules/TelegramUIPreferences:TelegramUIPreferences",
|
||||
"//submodules/ItemListUI:ItemListUI",
|
||||
"//submodules/PresentationDataUtils:PresentationDataUtils",
|
||||
"//submodules/AccountContext:AccountContext",
|
||||
"//submodules/StickerPackPreviewUI:StickerPackPreviewUI",
|
||||
"//submodules/ItemListStickerPackItem:ItemListStickerPackItem",
|
||||
],
|
||||
visibility = [
|
||||
"//visibility:public",
|
||||
],
|
||||
)
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>$(EXECUTABLE_NAME)</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>$(PRODUCT_NAME)</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>FMWK</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string>1.0</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>$(CURRENT_PROJECT_VERSION)</string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,422 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
import Display
|
||||
import AsyncDisplayKit
|
||||
import SwiftSignalKit
|
||||
import Postbox
|
||||
import TelegramCore
|
||||
import TelegramPresentationData
|
||||
import ItemListUI
|
||||
import PresentationDataUtils
|
||||
import ActivityIndicator
|
||||
import StickerResources
|
||||
import AppBundle
|
||||
|
||||
enum GroupStickerPackCurrentItemContent: Equatable {
|
||||
case notFound
|
||||
case searching
|
||||
case found(packInfo: StickerPackCollectionInfo, topItem: StickerPackItem?, subtitle: String)
|
||||
}
|
||||
|
||||
final class GroupStickerPackCurrentItem: ListViewItem, ItemListItem {
|
||||
let theme: PresentationTheme
|
||||
let strings: PresentationStrings
|
||||
let account: Account
|
||||
let content: GroupStickerPackCurrentItemContent
|
||||
let sectionId: ItemListSectionId
|
||||
let action: (() -> Void)?
|
||||
|
||||
init(theme: PresentationTheme, strings: PresentationStrings, account: Account, content: GroupStickerPackCurrentItemContent, sectionId: ItemListSectionId, action: (() -> Void)?) {
|
||||
self.theme = theme
|
||||
self.strings = strings
|
||||
self.account = account
|
||||
self.content = content
|
||||
self.sectionId = sectionId
|
||||
self.action = action
|
||||
}
|
||||
|
||||
func nodeConfiguredForParams(async: @escaping (@escaping () -> Void) -> Void, params: ListViewItemLayoutParams, synchronousLoads: Bool, previousItem: ListViewItem?, nextItem: ListViewItem?, completion: @escaping (ListViewItemNode, @escaping () -> (Signal<Void, NoError>?, (ListViewItemApply) -> Void)) -> Void) {
|
||||
async {
|
||||
let node = GroupStickerPackCurrentItemNode()
|
||||
let (layout, apply) = node.asyncLayout()(self, params, itemListNeighbors(item: self, topItem: previousItem as? ItemListItem, bottomItem: nextItem as? ItemListItem))
|
||||
|
||||
node.contentSize = layout.contentSize
|
||||
node.insets = layout.insets
|
||||
|
||||
Queue.mainQueue().async {
|
||||
completion(node, {
|
||||
return (nil, { _ in apply(false) })
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func updateNode(async: @escaping (@escaping () -> Void) -> Void, node: @escaping () -> ListViewItemNode, params: ListViewItemLayoutParams, previousItem: ListViewItem?, nextItem: ListViewItem?, animation: ListViewItemUpdateAnimation, completion: @escaping (ListViewItemNodeLayout, @escaping (ListViewItemApply) -> Void) -> Void) {
|
||||
Queue.mainQueue().async {
|
||||
if let nodeValue = node() as? GroupStickerPackCurrentItemNode {
|
||||
let makeLayout = nodeValue.asyncLayout()
|
||||
|
||||
var animated = true
|
||||
if case .None = animation {
|
||||
animated = false
|
||||
}
|
||||
|
||||
async {
|
||||
let (layout, apply) = makeLayout(self, params, itemListNeighbors(item: self, topItem: previousItem as? ItemListItem, bottomItem: nextItem as? ItemListItem))
|
||||
Queue.mainQueue().async {
|
||||
completion(layout, { _ in
|
||||
apply(animated)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var selectable: Bool = true
|
||||
|
||||
func selected(listView: ListView){
|
||||
listView.clearHighlightAnimated(true)
|
||||
self.action?()
|
||||
}
|
||||
}
|
||||
|
||||
private let titleFont = Font.bold(15.0)
|
||||
private let statusFont = Font.regular(14.0)
|
||||
|
||||
class GroupStickerPackCurrentItemNode: ItemListRevealOptionsItemNode {
|
||||
private let backgroundNode: ASDisplayNode
|
||||
private let topStripeNode: ASDisplayNode
|
||||
private let bottomStripeNode: ASDisplayNode
|
||||
private let highlightedBackgroundNode: ASDisplayNode
|
||||
private let maskNode: ASImageNode
|
||||
|
||||
fileprivate let imageNode: TransformImageNode
|
||||
private let notFoundNode: ASImageNode
|
||||
private let titleNode: TextNode
|
||||
private let statusNode: TextNode
|
||||
private let activityIndicator: ActivityIndicator
|
||||
|
||||
private var item: GroupStickerPackCurrentItem?
|
||||
|
||||
private var editableControlNode: ItemListEditableControlNode?
|
||||
|
||||
private let fetchDisposable = MetaDisposable()
|
||||
|
||||
override var canBeSelected: Bool {
|
||||
if let item = self.item {
|
||||
if case .found = item.content {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
init() {
|
||||
self.backgroundNode = ASDisplayNode()
|
||||
self.backgroundNode.isLayerBacked = true
|
||||
|
||||
self.topStripeNode = ASDisplayNode()
|
||||
self.topStripeNode.isLayerBacked = true
|
||||
|
||||
self.bottomStripeNode = ASDisplayNode()
|
||||
self.bottomStripeNode.isLayerBacked = true
|
||||
|
||||
self.maskNode = ASImageNode()
|
||||
self.maskNode.isUserInteractionEnabled = false
|
||||
|
||||
self.imageNode = TransformImageNode()
|
||||
self.imageNode.isLayerBacked = !smartInvertColorsEnabled()
|
||||
|
||||
self.notFoundNode = ASImageNode()
|
||||
self.notFoundNode.isLayerBacked = true
|
||||
self.notFoundNode.displayWithoutProcessing = true
|
||||
self.notFoundNode.displaysAsynchronously = false
|
||||
|
||||
self.titleNode = TextNode()
|
||||
self.titleNode.isUserInteractionEnabled = false
|
||||
self.titleNode.displaysAsynchronously = false
|
||||
self.titleNode.contentMode = .left
|
||||
self.titleNode.contentsScale = UIScreen.main.scale
|
||||
|
||||
self.statusNode = TextNode()
|
||||
self.statusNode.isUserInteractionEnabled = false
|
||||
self.statusNode.displaysAsynchronously = false
|
||||
self.statusNode.contentMode = .left
|
||||
self.statusNode.contentsScale = UIScreen.main.scale
|
||||
|
||||
self.activityIndicator = ActivityIndicator(type: .custom(.blue, 22.0, 1.0, false))
|
||||
|
||||
self.highlightedBackgroundNode = ASDisplayNode()
|
||||
self.highlightedBackgroundNode.isLayerBacked = true
|
||||
|
||||
super.init(layerBacked: false, dynamicBounce: false, rotated: false, seeThrough: false)
|
||||
|
||||
self.addSubnode(self.imageNode)
|
||||
self.addSubnode(self.titleNode)
|
||||
self.addSubnode(self.statusNode)
|
||||
self.addSubnode(self.notFoundNode)
|
||||
self.addSubnode(self.activityIndicator)
|
||||
}
|
||||
|
||||
deinit {
|
||||
self.fetchDisposable.dispose()
|
||||
}
|
||||
|
||||
func asyncLayout() -> (_ item: GroupStickerPackCurrentItem, _ params: ListViewItemLayoutParams, _ neighbors: ItemListNeighbors) -> (ListViewItemNodeLayout, (Bool) -> Void) {
|
||||
let makeImageLayout = self.imageNode.asyncLayout()
|
||||
let makeTitleLayout = TextNode.asyncLayout(self.titleNode)
|
||||
let makeStatusLayout = TextNode.asyncLayout(self.statusNode)
|
||||
|
||||
let currentItem = self.item
|
||||
|
||||
return { item, params, neighbors in
|
||||
var titleAttributedString: NSAttributedString?
|
||||
var statusAttributedString: NSAttributedString?
|
||||
|
||||
var updatedTheme: PresentationTheme?
|
||||
|
||||
var updatedNotFoundImage: UIImage?
|
||||
if currentItem?.theme !== item.theme {
|
||||
updatedTheme = item.theme
|
||||
updatedNotFoundImage = generateTintedImage(image: UIImage(bundleImageName: "Peer Info/GroupStickerPackNotFound"), color: item.theme.list.freeMonoIconColor)
|
||||
}
|
||||
|
||||
let rightInset: CGFloat = params.rightInset
|
||||
|
||||
var file: TelegramMediaFile?
|
||||
var previousFile: TelegramMediaFile?
|
||||
if let currentItem = currentItem, case let .found(_, topItem, _) = currentItem.content {
|
||||
previousFile = topItem?.file
|
||||
}
|
||||
|
||||
switch item.content {
|
||||
case .notFound:
|
||||
titleAttributedString = NSAttributedString(string: item.strings.Channel_Stickers_NotFound, font: titleFont, textColor: item.theme.list.itemDestructiveColor)
|
||||
statusAttributedString = NSAttributedString(string: item.strings.Channel_Stickers_NotFoundHelp, font: statusFont, textColor: item.theme.list.itemSecondaryTextColor)
|
||||
case .searching:
|
||||
titleAttributedString = NSAttributedString(string: item.strings.Channel_Stickers_Searching, font: titleFont, textColor: item.theme.list.itemPrimaryTextColor)
|
||||
statusAttributedString = NSAttributedString(string: "", font: statusFont, textColor: item.theme.list.itemSecondaryTextColor)
|
||||
case let .found(packInfo, topItem, subtitle):
|
||||
file = topItem?.file
|
||||
titleAttributedString = NSAttributedString(string: packInfo.title, font: titleFont, textColor: item.theme.list.itemPrimaryTextColor)
|
||||
statusAttributedString = NSAttributedString(string: subtitle, font: statusFont, textColor: item.theme.list.itemSecondaryTextColor)
|
||||
}
|
||||
|
||||
var fileUpdated = false
|
||||
if let file = file, let previousFile = previousFile {
|
||||
fileUpdated = !file.isEqual(to: previousFile)
|
||||
} else if (file != nil) != (previousFile != nil) {
|
||||
fileUpdated = true
|
||||
}
|
||||
|
||||
let leftInset: CGFloat = 65.0 + params.leftInset
|
||||
|
||||
let insets = itemListNeighborsGroupedInsets(neighbors, params)
|
||||
let contentSize = CGSize(width: params.width, height: 59.0)
|
||||
let separatorHeight = UIScreenPixel
|
||||
|
||||
let layout = ListViewItemNodeLayout(contentSize: contentSize, insets: insets)
|
||||
let layoutSize = layout.size
|
||||
|
||||
let editingOffset: CGFloat = 0.0
|
||||
|
||||
let (titleLayout, titleApply) = makeTitleLayout(TextNodeLayoutArguments(attributedString: titleAttributedString, backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: params.width - leftInset - 8.0 - rightInset - 10.0, height: CGFloat.greatestFiniteMagnitude), alignment: .natural, cutout: nil, insets: UIEdgeInsets()))
|
||||
let (statusLayout, statusApply) = makeStatusLayout(TextNodeLayoutArguments(attributedString: statusAttributedString, backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: params.width - leftInset - 8.0 - rightInset, height: CGFloat.greatestFiniteMagnitude), alignment: .natural, cutout: nil, insets: UIEdgeInsets()))
|
||||
|
||||
var imageApply: (() -> Void)?
|
||||
var imageSize: CGSize = CGSize(width: 34.0, height: 34.0)
|
||||
if let file = file, let dimensions = file.dimensions {
|
||||
let imageBoundingSize = CGSize(width: 34.0, height: 34.0)
|
||||
imageSize = dimensions.cgSize.aspectFitted(imageBoundingSize)
|
||||
imageApply = makeImageLayout(TransformImageArguments(corners: ImageCorners(), imageSize: imageSize, boundingSize: imageSize, intrinsicInsets: UIEdgeInsets()))
|
||||
}
|
||||
|
||||
var updatedImageSignal: Signal<(TransformImageArguments) -> DrawingContext?, NoError>?
|
||||
var updatedFetchSignal: Signal<FetchResourceSourceType, FetchResourceError>?
|
||||
if fileUpdated {
|
||||
if let file = file {
|
||||
updatedImageSignal = chatMessageSticker(account: item.account, userLocation: .other, file: file, small: false)
|
||||
updatedFetchSignal = fetchedMediaResource(mediaBox: item.account.postbox.mediaBox, userLocation: .other, userContentType: .sticker, reference: stickerPackFileReference(file).resourceReference(file.resource))
|
||||
} else {
|
||||
updatedImageSignal = .single({ _ in return nil })
|
||||
updatedFetchSignal = .complete()
|
||||
}
|
||||
}
|
||||
|
||||
return (layout, { [weak self] animated in
|
||||
if let strongSelf = self {
|
||||
strongSelf.item = item
|
||||
|
||||
if let _ = updatedTheme {
|
||||
strongSelf.topStripeNode.backgroundColor = item.theme.list.itemBlocksSeparatorColor
|
||||
strongSelf.bottomStripeNode.backgroundColor = item.theme.list.itemBlocksSeparatorColor
|
||||
strongSelf.backgroundNode.backgroundColor = item.theme.list.itemBlocksBackgroundColor
|
||||
strongSelf.highlightedBackgroundNode.backgroundColor = item.theme.list.itemHighlightedBackgroundColor
|
||||
strongSelf.activityIndicator.type = .custom(item.theme.list.itemAccentColor, 22.0, 1.0, false)
|
||||
}
|
||||
|
||||
if case .notFound = item.content {
|
||||
strongSelf.notFoundNode.isHidden = false
|
||||
} else {
|
||||
strongSelf.notFoundNode.isHidden = true
|
||||
}
|
||||
|
||||
if case .searching = item.content {
|
||||
strongSelf.activityIndicator.isHidden = false
|
||||
} else {
|
||||
strongSelf.activityIndicator.isHidden = true
|
||||
}
|
||||
|
||||
let revealOffset = strongSelf.revealOffset
|
||||
|
||||
let transition: ContainedViewLayoutTransition = .immediate
|
||||
|
||||
imageApply?()
|
||||
|
||||
let _ = titleApply()
|
||||
let _ = statusApply()
|
||||
|
||||
if strongSelf.backgroundNode.supernode == nil {
|
||||
strongSelf.insertSubnode(strongSelf.backgroundNode, at: 0)
|
||||
}
|
||||
if strongSelf.topStripeNode.supernode == nil {
|
||||
strongSelf.insertSubnode(strongSelf.topStripeNode, at: 1)
|
||||
}
|
||||
if strongSelf.bottomStripeNode.supernode == nil {
|
||||
strongSelf.insertSubnode(strongSelf.bottomStripeNode, at: 2)
|
||||
}
|
||||
if strongSelf.maskNode.supernode == nil {
|
||||
strongSelf.addSubnode(strongSelf.maskNode)
|
||||
}
|
||||
// switch neighbors.top {
|
||||
// case .sameSection(false):
|
||||
// strongSelf.topStripeNode.isHidden = true
|
||||
// default:
|
||||
// strongSelf.topStripeNode.isHidden = false
|
||||
// }
|
||||
// let bottomStripeInset: CGFloat
|
||||
// let bottomStripeOffset: CGFloat
|
||||
// switch neighbors.bottom {
|
||||
// case .sameSection(false):
|
||||
// bottomStripeInset = leftInset + editingOffset
|
||||
// bottomStripeOffset = -separatorHeight
|
||||
// default:
|
||||
// bottomStripeInset = 0.0
|
||||
// bottomStripeOffset = 0.0
|
||||
// }
|
||||
|
||||
let hasCorners = itemListHasRoundedBlockLayout(params)
|
||||
var hasTopCorners = false
|
||||
var hasBottomCorners = false
|
||||
switch neighbors.top {
|
||||
case .sameSection(false):
|
||||
strongSelf.topStripeNode.isHidden = true
|
||||
default:
|
||||
hasTopCorners = true
|
||||
strongSelf.topStripeNode.isHidden = hasCorners
|
||||
}
|
||||
let bottomStripeInset: CGFloat
|
||||
let bottomStripeOffset: CGFloat
|
||||
switch neighbors.bottom {
|
||||
case .sameSection(false):
|
||||
bottomStripeInset = leftInset + editingOffset
|
||||
bottomStripeOffset = -separatorHeight
|
||||
strongSelf.bottomStripeNode.isHidden = false
|
||||
default:
|
||||
bottomStripeInset = 0.0
|
||||
bottomStripeOffset = 0.0
|
||||
hasBottomCorners = true
|
||||
strongSelf.bottomStripeNode.isHidden = hasCorners
|
||||
}
|
||||
|
||||
strongSelf.maskNode.image = hasCorners ? PresentationResourcesItemList.cornersImage(item.theme, top: hasTopCorners, bottom: hasBottomCorners) : nil
|
||||
|
||||
strongSelf.backgroundNode.frame = CGRect(origin: CGPoint(x: 0.0, y: -min(insets.top, separatorHeight)), size: CGSize(width: params.width, height: contentSize.height + min(insets.top, separatorHeight) + min(insets.bottom, separatorHeight)))
|
||||
strongSelf.maskNode.frame = strongSelf.backgroundNode.frame.insetBy(dx: params.leftInset, dy: 0.0)
|
||||
transition.updateFrame(node: strongSelf.topStripeNode, frame: CGRect(origin: CGPoint(x: 0.0, y: -min(insets.top, separatorHeight)), size: CGSize(width: layoutSize.width, height: separatorHeight)))
|
||||
transition.updateFrame(node: strongSelf.bottomStripeNode, frame: CGRect(origin: CGPoint(x: bottomStripeInset, y: contentSize.height + bottomStripeOffset), size: CGSize(width: layoutSize.width - bottomStripeInset, height: separatorHeight)))
|
||||
|
||||
let titleVerticalOffset: CGFloat
|
||||
if statusLayout.size.width.isZero {
|
||||
titleVerticalOffset = 19.0
|
||||
} else {
|
||||
titleVerticalOffset = 11.0
|
||||
}
|
||||
transition.updateFrame(node: strongSelf.titleNode, frame: CGRect(origin: CGPoint(x: leftInset, y: titleVerticalOffset), size: titleLayout.size))
|
||||
transition.updateFrame(node: strongSelf.statusNode, frame: CGRect(origin: CGPoint(x: leftInset, y: 32.0), size: statusLayout.size))
|
||||
|
||||
let boundingSize = CGSize(width: 34.0, height: 34.0)
|
||||
transition.updateFrame(node: strongSelf.imageNode, frame: CGRect(origin: CGPoint(x: params.leftInset + revealOffset + editingOffset + 15.0 + floor((boundingSize.width - imageSize.width) / 2.0), y: 11.0 + floor((boundingSize.height - imageSize.height) / 2.0)), size: imageSize))
|
||||
let indicatorSize = CGSize(width: 22.0, height: 22.0)
|
||||
transition.updateFrame(node: strongSelf.activityIndicator, frame: CGRect(origin: CGPoint(x: params.leftInset + 15.0 + floor((boundingSize.width - indicatorSize.width) / 2.0), y: 11.0 + floor((boundingSize.height - indicatorSize.height) / 2.0)), size: indicatorSize))
|
||||
|
||||
if let image = updatedNotFoundImage {
|
||||
strongSelf.notFoundNode.image = image
|
||||
}
|
||||
if let image = strongSelf.notFoundNode.image {
|
||||
transition.updateFrame(node: strongSelf.notFoundNode, frame: CGRect(origin: CGPoint(x: params.leftInset + 15.0 + floor((boundingSize.width - image.size.width) / 2.0), y: 13.0 + floor((boundingSize.height - image.size.height) / 2.0)), size: image.size))
|
||||
}
|
||||
|
||||
if let updatedImageSignal = updatedImageSignal {
|
||||
strongSelf.imageNode.setSignal(updatedImageSignal)
|
||||
}
|
||||
|
||||
strongSelf.highlightedBackgroundNode.frame = CGRect(origin: CGPoint(x: 0.0, y: -UIScreenPixel), size: CGSize(width: params.width, height: contentSize.height + UIScreenPixel + UIScreenPixel))
|
||||
|
||||
strongSelf.updateLayout(size: layout.contentSize, leftInset: params.leftInset, rightInset: params.rightInset)
|
||||
|
||||
if let updatedFetchSignal = updatedFetchSignal {
|
||||
strongSelf.fetchDisposable.set(updatedFetchSignal.start())
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
override func setHighlighted(_ highlighted: Bool, at point: CGPoint, animated: Bool) {
|
||||
super.setHighlighted(highlighted, at: point, animated: animated)
|
||||
|
||||
if highlighted {
|
||||
self.highlightedBackgroundNode.alpha = 1.0
|
||||
if self.highlightedBackgroundNode.supernode == nil {
|
||||
var anchorNode: ASDisplayNode?
|
||||
if self.bottomStripeNode.supernode != nil {
|
||||
anchorNode = self.bottomStripeNode
|
||||
} else if self.topStripeNode.supernode != nil {
|
||||
anchorNode = self.topStripeNode
|
||||
} else if self.backgroundNode.supernode != nil {
|
||||
anchorNode = self.backgroundNode
|
||||
}
|
||||
if let anchorNode = anchorNode {
|
||||
self.insertSubnode(self.highlightedBackgroundNode, aboveSubnode: anchorNode)
|
||||
} else {
|
||||
self.addSubnode(self.highlightedBackgroundNode)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if self.highlightedBackgroundNode.supernode != nil {
|
||||
if animated {
|
||||
self.highlightedBackgroundNode.layer.animateAlpha(from: self.highlightedBackgroundNode.alpha, to: 0.0, duration: 0.4, completion: { [weak self] completed in
|
||||
if let strongSelf = self {
|
||||
if completed {
|
||||
strongSelf.highlightedBackgroundNode.removeFromSupernode()
|
||||
}
|
||||
}
|
||||
})
|
||||
self.highlightedBackgroundNode.alpha = 0.0
|
||||
} else {
|
||||
self.highlightedBackgroundNode.removeFromSupernode()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override func animateInsertion(_ currentTimestamp: Double, duration: Double, short: Bool) {
|
||||
self.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.4)
|
||||
}
|
||||
|
||||
override func animateRemoved(_ currentTimestamp: Double, duration: Double) {
|
||||
self.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.15, removeOnCompletion: false)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,536 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
import Display
|
||||
import SwiftSignalKit
|
||||
import Postbox
|
||||
import TelegramCore
|
||||
import TelegramPresentationData
|
||||
import TelegramUIPreferences
|
||||
import ItemListUI
|
||||
import PresentationDataUtils
|
||||
import AccountContext
|
||||
import StickerPackPreviewUI
|
||||
import ItemListStickerPackItem
|
||||
|
||||
private final class GroupStickerPackSetupControllerArguments {
|
||||
let context: AccountContext
|
||||
|
||||
let selectStickerPack: (StickerPackCollectionInfo) -> Void
|
||||
let openStickerPack: (StickerPackCollectionInfo) -> Void
|
||||
let updateSearchText: (String) -> Void
|
||||
let openStickersBot: () -> Void
|
||||
|
||||
init(context: AccountContext, selectStickerPack: @escaping (StickerPackCollectionInfo) -> Void, openStickerPack: @escaping (StickerPackCollectionInfo) -> Void, updateSearchText: @escaping (String) -> Void, openStickersBot: @escaping () -> Void) {
|
||||
self.context = context
|
||||
self.selectStickerPack = selectStickerPack
|
||||
self.openStickerPack = openStickerPack
|
||||
self.updateSearchText = updateSearchText
|
||||
self.openStickersBot = openStickersBot
|
||||
}
|
||||
}
|
||||
|
||||
private enum GroupStickerPackSection: Int32 {
|
||||
case search
|
||||
case stickers
|
||||
}
|
||||
|
||||
private enum GroupStickerPackEntryId: Hashable {
|
||||
case index(Int32)
|
||||
case pack(ItemCollectionId)
|
||||
|
||||
static func ==(lhs: GroupStickerPackEntryId, rhs: GroupStickerPackEntryId) -> Bool {
|
||||
switch lhs {
|
||||
case let .index(index):
|
||||
if case .index(index) = rhs {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case let .pack(id):
|
||||
if case .pack(id) = rhs {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private enum GroupStickerPackEntry: ItemListNodeEntry {
|
||||
case search(PresentationTheme, PresentationStrings, String, String, String)
|
||||
case currentPack(Int32, PresentationTheme, PresentationStrings, GroupStickerPackCurrentItemContent)
|
||||
case searchInfo(PresentationTheme, String)
|
||||
case packsTitle(PresentationTheme, String)
|
||||
case pack(Int32, PresentationTheme, PresentationStrings, StickerPackCollectionInfo, StickerPackItem?, String, Bool, Bool)
|
||||
|
||||
var section: ItemListSectionId {
|
||||
switch self {
|
||||
case .search, .currentPack, .searchInfo:
|
||||
return GroupStickerPackSection.search.rawValue
|
||||
case .packsTitle, .pack:
|
||||
return GroupStickerPackSection.stickers.rawValue
|
||||
}
|
||||
}
|
||||
|
||||
var stableId: GroupStickerPackEntryId {
|
||||
switch self {
|
||||
case .search:
|
||||
return .index(0)
|
||||
case .currentPack:
|
||||
return .index(1)
|
||||
case .searchInfo:
|
||||
return .index(2)
|
||||
case .packsTitle:
|
||||
return .index(3)
|
||||
case let .pack(_, _, _, info, _, _, _, _):
|
||||
return .pack(info.id)
|
||||
}
|
||||
}
|
||||
|
||||
static func ==(lhs: GroupStickerPackEntry, rhs: GroupStickerPackEntry) -> Bool {
|
||||
switch lhs {
|
||||
case let .search(lhsTheme, lhsStrings, lhsPrefix, lhsPlaceholder, lhsValue):
|
||||
if case let .search(rhsTheme, rhsStrings, rhsPrefix, rhsPlaceholder, rhsValue) = rhs, lhsTheme === rhsTheme, lhsStrings === rhsStrings, lhsPrefix == rhsPrefix, lhsPlaceholder == rhsPlaceholder, lhsValue == rhsValue {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case let .searchInfo(lhsTheme, lhsText):
|
||||
if case let .searchInfo(rhsTheme, rhsText) = rhs, lhsTheme === rhsTheme, lhsText == rhsText {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case let .packsTitle(lhsTheme, lhsText):
|
||||
if case let .packsTitle(rhsTheme, rhsText) = rhs, lhsTheme === rhsTheme, lhsText == rhsText {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case let .currentPack(lhsIndex, lhsTheme, lhsStrings, lhsContent):
|
||||
if case let .currentPack(rhsIndex, rhsTheme, rhsStrings, rhsContent) = rhs {
|
||||
if lhsIndex != rhsIndex {
|
||||
return false
|
||||
}
|
||||
if lhsTheme !== rhsTheme {
|
||||
return false
|
||||
}
|
||||
if lhsStrings !== rhsStrings {
|
||||
return false
|
||||
}
|
||||
if lhsContent != rhsContent {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
case let .pack(lhsIndex, lhsTheme, lhsStrings, lhsInfo, lhsTopItem, lhsCount, lhsPlayAnimatedStickers, lhsSelected):
|
||||
if case let .pack(rhsIndex, rhsTheme, rhsStrings, rhsInfo, rhsTopItem, rhsCount, rhsPlayAnimatedStickers, rhsSelected) = rhs {
|
||||
if lhsIndex != rhsIndex {
|
||||
return false
|
||||
}
|
||||
if lhsTheme !== rhsTheme {
|
||||
return false
|
||||
}
|
||||
if lhsStrings !== rhsStrings {
|
||||
return false
|
||||
}
|
||||
if lhsInfo != rhsInfo {
|
||||
return false
|
||||
}
|
||||
if lhsTopItem != rhsTopItem {
|
||||
return false
|
||||
}
|
||||
if lhsCount != rhsCount {
|
||||
return false
|
||||
}
|
||||
if lhsPlayAnimatedStickers != rhsPlayAnimatedStickers {
|
||||
return false
|
||||
}
|
||||
if lhsSelected != rhsSelected {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static func <(lhs: GroupStickerPackEntry, rhs: GroupStickerPackEntry) -> Bool {
|
||||
switch lhs {
|
||||
case .search:
|
||||
switch rhs {
|
||||
case .search:
|
||||
return false
|
||||
default:
|
||||
return true
|
||||
}
|
||||
case .currentPack:
|
||||
switch rhs {
|
||||
case .search, .currentPack:
|
||||
return false
|
||||
default:
|
||||
return true
|
||||
}
|
||||
case .searchInfo:
|
||||
switch rhs {
|
||||
case .search, .currentPack, .searchInfo:
|
||||
return false
|
||||
default:
|
||||
return true
|
||||
}
|
||||
case .packsTitle:
|
||||
switch rhs {
|
||||
case .search, .currentPack, .searchInfo, .packsTitle:
|
||||
return false
|
||||
default:
|
||||
return true
|
||||
}
|
||||
case let .pack(lhsIndex, _, _, _, _, _, _, _):
|
||||
switch rhs {
|
||||
case let .pack(rhsIndex, _, _, _, _, _, _, _):
|
||||
return lhsIndex < rhsIndex
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem {
|
||||
let arguments = arguments as! GroupStickerPackSetupControllerArguments
|
||||
switch self {
|
||||
case let .search(theme, _, prefix, placeholder, value):
|
||||
let isEmoji = prefix.contains("addemoji")
|
||||
return ItemListSingleLineInputItem(presentationData: presentationData, title: NSAttributedString(string: prefix, textColor: theme.list.itemPrimaryTextColor), text: value, placeholder: placeholder, type: .regular(capitalization: false, autocorrection: false), spacing: 0.0, clearType: .always, tag: nil, sectionId: self.section, textUpdated: { value in
|
||||
arguments.updateSearchText(value)
|
||||
}, processPaste: { text in
|
||||
if let url = (URL(string: text) ?? URL(string: "http://" + text)), url.host == "t.me" || url.host == "telegram.me" {
|
||||
let prefix = isEmoji ? "/addemoji/" : "/addstickers/"
|
||||
if url.path.hasPrefix(prefix) {
|
||||
return String(url.path[url.path.index(url.path.startIndex, offsetBy: prefix.count)...])
|
||||
}
|
||||
}
|
||||
return text
|
||||
}, action: {})
|
||||
case let .searchInfo(_, text):
|
||||
return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section, linkAction: nil)
|
||||
case let .packsTitle(_, text):
|
||||
return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section)
|
||||
case let .pack(_, _, _, info, topItem, count, playAnimatedStickers, selected):
|
||||
return ItemListStickerPackItem(presentationData: presentationData, context: arguments.context, packInfo: info, itemCount: count, topItem: topItem, unread: false, control: selected ? .selection : .none, editing: ItemListStickerPackItemEditing(editable: false, editing: false, revealed: false, reorderable: false, selectable: false), enabled: true, playAnimatedStickers: playAnimatedStickers, sectionId: self.section, action: {
|
||||
if selected {
|
||||
arguments.openStickerPack(info)
|
||||
} else {
|
||||
arguments.selectStickerPack(info)
|
||||
}
|
||||
}, setPackIdWithRevealedOptions: { _, _ in
|
||||
}, addPack: {
|
||||
}, removePack: {
|
||||
}, toggleSelected: {
|
||||
})
|
||||
case let .currentPack(_, theme, strings, content):
|
||||
return GroupStickerPackCurrentItem(theme: theme, strings: strings, account: arguments.context.account, content: content, sectionId: self.section, action: {
|
||||
if case let .found(packInfo, _, _) = content {
|
||||
arguments.openStickerPack(packInfo)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private struct StickerPackData: Equatable {
|
||||
let info: StickerPackCollectionInfo
|
||||
let item: StickerPackItem?
|
||||
}
|
||||
|
||||
private enum InitialStickerPackData {
|
||||
case noData
|
||||
case data(StickerPackData)
|
||||
}
|
||||
|
||||
private enum GroupStickerPackSearchState: Equatable {
|
||||
case none
|
||||
case found(StickerPackData)
|
||||
case notFound
|
||||
case searching
|
||||
}
|
||||
|
||||
private struct GroupStickerPackSetupControllerState: Equatable {
|
||||
var isSaving: Bool
|
||||
}
|
||||
|
||||
private func groupStickerPackSetupControllerEntries(context: AccountContext, presentationData: PresentationData, searchText: String, view: CombinedView, initialData: InitialStickerPackData?, searchState: GroupStickerPackSearchState, stickerSettings: StickerSettings, emoji: Bool) -> [GroupStickerPackEntry] {
|
||||
if initialData == nil {
|
||||
return []
|
||||
}
|
||||
var entries: [GroupStickerPackEntry] = []
|
||||
|
||||
entries.append(.search(presentationData.theme, presentationData.strings, emoji ? "t.me/addemoji/" : "t.me/addstickers/", emoji ? "emojiset" : presentationData.strings.Channel_Stickers_Placeholder, searchText))
|
||||
switch searchState {
|
||||
case .none:
|
||||
break
|
||||
case .notFound:
|
||||
entries.append(.currentPack(0, presentationData.theme, presentationData.strings, .notFound))
|
||||
case .searching:
|
||||
entries.append(.currentPack(0, presentationData.theme, presentationData.strings, .searching))
|
||||
case let .found(data):
|
||||
entries.append(.currentPack(0, presentationData.theme, presentationData.strings, .found(packInfo: data.info, topItem: data.item, subtitle: presentationData.strings.StickerPack_StickerCount(data.info.count))))
|
||||
}
|
||||
entries.append(.searchInfo(presentationData.theme, emoji ? "All members will be able to use these emoji in the group, even if they don't have Telegram Premium." : presentationData.strings.Channel_Stickers_CreateYourOwn))
|
||||
entries.append(.packsTitle(presentationData.theme, emoji ? "CHOOSE FROM YOUR EMOJI" : presentationData.strings.Channel_Stickers_YourStickers))
|
||||
|
||||
let namespace = emoji ? Namespaces.ItemCollection.CloudEmojiPacks : Namespaces.ItemCollection.CloudStickerPacks
|
||||
if let stickerPacksView = view.views[.itemCollectionInfos(namespaces: [namespace])] as? ItemCollectionInfosView {
|
||||
if let packsEntries = stickerPacksView.entriesByNamespace[namespace] {
|
||||
var index: Int32 = 0
|
||||
for entry in packsEntries {
|
||||
if let info = entry.info as? StickerPackCollectionInfo {
|
||||
var selected = false
|
||||
if case let .found(found) = searchState {
|
||||
selected = found.info.id == info.id
|
||||
}
|
||||
entries.append(.pack(index, presentationData.theme, presentationData.strings, info, entry.firstItem as? StickerPackItem, presentationData.strings.StickerPack_StickerCount(info.count == 0 ? entry.count : info.count), context.sharedContext.energyUsageSettings.loopStickers, selected))
|
||||
index += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return entries
|
||||
}
|
||||
|
||||
public func groupStickerPackSetupController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal<PresentationData, NoError>)? = nil, peerId: PeerId, emoji: Bool = false, currentPackInfo: StickerPackCollectionInfo?, completion: ((StickerPackCollectionInfo?) -> Void)? = nil) -> ViewController {
|
||||
let initialState = GroupStickerPackSetupControllerState(isSaving: false)
|
||||
|
||||
let statePromise = ValuePromise(initialState, ignoreRepeated: true)
|
||||
let stateValue = Atomic(value: initialState)
|
||||
let updateState: ((GroupStickerPackSetupControllerState) -> GroupStickerPackSetupControllerState) -> Void = { f in
|
||||
statePromise.set(stateValue.modify { f($0) })
|
||||
}
|
||||
|
||||
let searchText = ValuePromise<String>(currentPackInfo?.shortName ?? "", ignoreRepeated: true)
|
||||
|
||||
let initialData = Promise<InitialStickerPackData?>()
|
||||
if let currentPackInfo = currentPackInfo {
|
||||
initialData.set(context.engine.stickers.cachedStickerPack(reference: .id(id: currentPackInfo.id.id, accessHash: currentPackInfo.accessHash), forceRemote: false)
|
||||
|> map { result -> InitialStickerPackData? in
|
||||
switch result {
|
||||
case .none:
|
||||
return .noData
|
||||
case .fetching:
|
||||
return nil
|
||||
case let .result(info, items, _):
|
||||
return InitialStickerPackData.data(StickerPackData(info: info, item: items.first))
|
||||
}
|
||||
})
|
||||
} else {
|
||||
initialData.set(.single(.noData))
|
||||
}
|
||||
|
||||
let stickerPacks = Promise<CombinedView>()
|
||||
stickerPacks.set(context.account.postbox.combinedView(keys: [.itemCollectionInfos(namespaces: [emoji ? Namespaces.ItemCollection.CloudEmojiPacks : Namespaces.ItemCollection.CloudStickerPacks])]))
|
||||
|
||||
let searchState = Promise<(String, GroupStickerPackSearchState)>()
|
||||
searchState.set(combineLatest(searchText.get(), initialData.get(), stickerPacks.get())
|
||||
|> mapToSignal { searchText, initialData, view -> Signal<(String, GroupStickerPackSearchState), NoError> in
|
||||
if let initialData = initialData {
|
||||
if searchText.isEmpty {
|
||||
return .single((searchText, .none))
|
||||
} else if case let .data(data) = initialData, searchText.lowercased() == data.info.shortName {
|
||||
return .single((searchText, .found(StickerPackData(info: data.info, item: data.item))))
|
||||
} else {
|
||||
let namespace = emoji ? Namespaces.ItemCollection.CloudEmojiPacks : Namespaces.ItemCollection.CloudStickerPacks
|
||||
if let stickerPacksView = view.views[.itemCollectionInfos(namespaces: [namespace])] as? ItemCollectionInfosView {
|
||||
if let packsEntries = stickerPacksView.entriesByNamespace[namespace] {
|
||||
for entry in packsEntries {
|
||||
if let info = entry.info as? StickerPackCollectionInfo {
|
||||
if info.shortName.lowercased() == searchText.lowercased() {
|
||||
return .single((searchText, .found(StickerPackData(info: info, item: entry.firstItem as? StickerPackItem))))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return .single((searchText, .searching))
|
||||
|> then((context.engine.stickers.loadedStickerPack(reference: .name(searchText.lowercased()), forceActualized: false) |> delay(0.3, queue: Queue.concurrentDefaultQueue()))
|
||||
|> mapToSignal { value -> Signal<(String, GroupStickerPackSearchState), NoError> in
|
||||
switch value {
|
||||
case .fetching:
|
||||
return .complete()
|
||||
case .none:
|
||||
return .single((searchText, .notFound))
|
||||
case let .result(info, items, _):
|
||||
return .single((searchText, .found(StickerPackData(info: info, item: items.first))))
|
||||
}
|
||||
})
|
||||
}
|
||||
} else {
|
||||
return .single((searchText, .none))
|
||||
}
|
||||
})
|
||||
|
||||
var presentControllerImpl: ((ViewController, ViewControllerPresentationArguments?) -> Void)?
|
||||
var navigateToChatControllerImpl: ((PeerId) -> Void)?
|
||||
var dismissInputImpl: (() -> Void)?
|
||||
var dismissImpl: (() -> Void)?
|
||||
|
||||
let actionsDisposable = DisposableSet()
|
||||
|
||||
let resolveDisposable = MetaDisposable()
|
||||
actionsDisposable.add(resolveDisposable)
|
||||
|
||||
let saveDisposable = MetaDisposable()
|
||||
actionsDisposable.add(saveDisposable)
|
||||
|
||||
var presentStickerPackController: ((StickerPackCollectionInfo) -> Void)?
|
||||
|
||||
let arguments = GroupStickerPackSetupControllerArguments(context: context, selectStickerPack: { info in
|
||||
searchText.set(info.shortName)
|
||||
if let completion {
|
||||
completion(info)
|
||||
}
|
||||
}, openStickerPack: { info in
|
||||
presentStickerPackController?(info)
|
||||
}, updateSearchText: { text in
|
||||
searchText.set(text)
|
||||
if text == "", let completion {
|
||||
completion(nil)
|
||||
}
|
||||
}, openStickersBot: {
|
||||
resolveDisposable.set((context.engine.peers.resolvePeerByName(name: "stickers")
|
||||
|> mapToSignal { result -> Signal<EnginePeer?, NoError> in
|
||||
guard case let .result(result) = result else {
|
||||
return .complete()
|
||||
}
|
||||
return .single(result)
|
||||
}
|
||||
|> deliverOnMainQueue).start(next: { peer in
|
||||
if let peer = peer {
|
||||
dismissImpl?()
|
||||
navigateToChatControllerImpl?(peer.id)
|
||||
}
|
||||
}))
|
||||
})
|
||||
|
||||
let previousHadData = Atomic<Bool>(value: false)
|
||||
|
||||
let presentationData = updatedPresentationData?.signal ?? context.sharedContext.presentationData
|
||||
let signal = combineLatest(presentationData, statePromise.get() |> deliverOnMainQueue, initialData.get() |> deliverOnMainQueue, stickerPacks.get() |> deliverOnMainQueue, searchState.get() |> deliverOnMainQueue, context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.stickerSettings]) |> deliverOnMainQueue)
|
||||
|> map { presentationData, state, initialData, view, searchState, sharedData -> (ItemListControllerState, (ItemListNodeState, Any)) in
|
||||
var stickerSettings = StickerSettings.defaultSettings
|
||||
if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.stickerSettings]?.get(StickerSettings.self) {
|
||||
stickerSettings = value
|
||||
}
|
||||
|
||||
let leftNavigationButton: ItemListNavigationButton?
|
||||
if emoji {
|
||||
leftNavigationButton = nil
|
||||
} else {
|
||||
leftNavigationButton = ItemListNavigationButton(content: .text(presentationData.strings.Common_Cancel), style: .regular, enabled: true, action: {
|
||||
dismissImpl?()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
var rightNavigationButton: ItemListNavigationButton?
|
||||
if let _ = completion {
|
||||
rightNavigationButton = ItemListNavigationButton(content: .icon(.search), style: .regular, enabled: true, action: {})
|
||||
} else {
|
||||
if initialData != nil {
|
||||
if state.isSaving {
|
||||
rightNavigationButton = ItemListNavigationButton(content: .text(""), style: .activity, enabled: true, action: {})
|
||||
} else {
|
||||
let enabled: Bool
|
||||
var info: StickerPackCollectionInfo?
|
||||
switch searchState.1 {
|
||||
case .searching, .notFound:
|
||||
enabled = false
|
||||
case .none:
|
||||
enabled = true
|
||||
case let .found(data):
|
||||
enabled = true
|
||||
info = data.info
|
||||
}
|
||||
rightNavigationButton = ItemListNavigationButton(content: .text(presentationData.strings.Common_Done), style: .bold, enabled: enabled, action: {
|
||||
if let completion {
|
||||
completion(info)
|
||||
dismissImpl?()
|
||||
} else {
|
||||
if info?.id == currentPackInfo?.id {
|
||||
dismissImpl?()
|
||||
} else {
|
||||
updateState { state in
|
||||
var state = state
|
||||
state.isSaving = true
|
||||
return state
|
||||
}
|
||||
saveDisposable.set((context.engine.peers.updateGroupSpecificStickerset(peerId: peerId, info: info)
|
||||
|> deliverOnMainQueue).start(error: { _ in
|
||||
updateState { state in
|
||||
var state = state
|
||||
state.isSaving = false
|
||||
return state
|
||||
}
|
||||
}, completed: {
|
||||
dismissImpl?()
|
||||
}))
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let controllerState = ItemListControllerState(presentationData: ItemListPresentationData(presentationData), title: .text(emoji ? "Group Emoji Pack" : presentationData.strings.Channel_Info_Stickers), leftNavigationButton: leftNavigationButton, rightNavigationButton: rightNavigationButton, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back), animateChanges: true)
|
||||
|
||||
let hasData = initialData != nil
|
||||
let hadData = previousHadData.swap(hasData)
|
||||
|
||||
var emptyStateItem: ItemListLoadingIndicatorEmptyStateItem?
|
||||
if !hasData {
|
||||
emptyStateItem = ItemListLoadingIndicatorEmptyStateItem(theme: presentationData.theme)
|
||||
}
|
||||
|
||||
let listState = ItemListNodeState(presentationData: ItemListPresentationData(presentationData), entries: groupStickerPackSetupControllerEntries(context: context, presentationData: presentationData, searchText: searchState.0, view: view, initialData: initialData, searchState: searchState.1, stickerSettings: stickerSettings, emoji: emoji), style: .blocks, emptyStateItem: emptyStateItem, animateChanges: hasData && hadData)
|
||||
return (controllerState, (listState, arguments))
|
||||
} |> afterDisposed {
|
||||
actionsDisposable.dispose()
|
||||
}
|
||||
|
||||
let controller = ItemListController(context: context, state: signal)
|
||||
|
||||
presentControllerImpl = { [weak controller] c, p in
|
||||
if let controller = controller {
|
||||
controller.present(c, in: .window(.root), with: p)
|
||||
}
|
||||
}
|
||||
dismissInputImpl = { [weak controller] in
|
||||
controller?.view.endEditing(true)
|
||||
}
|
||||
presentStickerPackController = { [weak controller] info in
|
||||
dismissInputImpl?()
|
||||
let packReference: StickerPackReference = .id(id: info.id.id, accessHash: info.accessHash)
|
||||
presentControllerImpl?(StickerPackScreen(context: context, updatedPresentationData: updatedPresentationData, mainStickerPack: packReference, stickerPacks: [packReference], parentNavigationController: controller?.navigationController as? NavigationController), nil)
|
||||
}
|
||||
navigateToChatControllerImpl = { [weak controller] peerId in
|
||||
let _ = (context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: peerId))
|
||||
|> deliverOnMainQueue).start(next: { peer in
|
||||
guard let peer = peer else {
|
||||
return
|
||||
}
|
||||
|
||||
if let controller = controller, let navigationController = controller.navigationController as? NavigationController {
|
||||
context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: context, chatLocation: .peer(peer)))
|
||||
}
|
||||
})
|
||||
}
|
||||
dismissImpl = { [weak controller] in
|
||||
dismissInputImpl?()
|
||||
controller?.dismiss()
|
||||
}
|
||||
|
||||
return controller
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user