Various fixes

This commit is contained in:
Ilya Laktyushin 2022-04-28 19:28:30 +04:00
parent 451b9d92d1
commit d36b6b0b7f
5 changed files with 76 additions and 21 deletions

View File

@ -357,6 +357,8 @@
if (_downloadDisposable == nil)
_downloadDisposable = [[SMetaDisposable alloc] init];
[self setProgressVisible:true value:0.027 animated:true];
__weak TGMediaPickerGalleryVideoItemView *weakSelf = self;
[_downloadDisposable setDisposable:[[[TGMediaAssetImageSignals avAssetForVideoAsset:(TGMediaAsset *)self.item.asset allowNetworkAccess:true] deliverOn:[SQueue mainQueue]] startWithNext:^(id next)
{
@ -379,6 +381,7 @@
[strongSelf->_progressView setPlay];
strongSelf->_progressView.alpha = 1.0;
strongSelf->_downloading = false;
strongSelf->_downloaded = true;
if (strongSelf->_currentAvailabilityObserver != nil)
strongSelf->_currentAvailabilityObserver(true);

View File

@ -249,6 +249,7 @@ final class StickerPackPreviewGridItemNode: GridItemNode {
}
self.animationNode?.alpha = isLocked ? 0.5 : 1.0
self.imageNode.alpha = isLocked ? 0.5 : 1.0
self.currentState = (account, stickerItem)
self.setNeedsLayout()

View File

@ -349,8 +349,12 @@ private final class StickerPackContainer: ASDisplayNode {
if let (info, _, _) = strongSelf.currentStickerPack, info.id.namespace == Namespaces.ItemCollection.CloudStickerPacks {
if strongSelf.sendSticker != nil {
menuItems.append(.action(ContextMenuActionItem(text: strongSelf.presentationData.strings.StickerPack_Send, icon: { theme in generateTintedImage(image: UIImage(bundleImageName: "Chat/Context Menu/Resend"), color: theme.contextMenu.primaryColor) }, action: { _, f in
if let strongSelf = self, let peekController = strongSelf.peekController, let animationNode = (peekController.contentNode as? StickerPreviewPeekContentNode)?.animationNode {
let _ = strongSelf.sendSticker?(.standalone(media: item.file), animationNode, animationNode.bounds)
if let strongSelf = self, let peekController = strongSelf.peekController {
if let animationNode = (peekController.contentNode as? StickerPreviewPeekContentNode)?.animationNode {
let _ = strongSelf.sendSticker?(.standalone(media: item.file), animationNode, animationNode.bounds)
} else if let imageNode = (peekController.contentNode as? StickerPreviewPeekContentNode)?.imageNode {
let _ = strongSelf.sendSticker?(.standalone(media: item.file), imageNode, imageNode.bounds)
}
}
f(.default)
})))
@ -449,8 +453,15 @@ private final class StickerPackContainer: ASDisplayNode {
f(.default)
if let strongSelf = self {
let controller = ShareController(context: strongSelf.context, subject: .url(link))
strongSelf.controller?.present(controller, in: .window(.root))
let parentNavigationController = strongSelf.controller?.parentNavigationController
let shareController = ShareController(context: strongSelf.context, subject: .url(link))
shareController.actionCompleted = { [weak parentNavigationController] in
if let parentNavigationController = parentNavigationController, let controller = parentNavigationController.topViewController as? ViewController {
let presentationData = strongSelf.context.sharedContext.currentPresentationData.with { $0 }
controller.present(UndoOverlayController(presentationData: presentationData, content: .linkCopied(text: presentationData.strings.Conversation_LinkCopied), elevatedLayout: false, animateInAsReplacement: false, action: { _ in return false }), in: .window(.root))
}
}
strongSelf.controller?.present(shareController, in: .window(.root))
}
})))
items.append(.action(ContextMenuActionItem(text: strings.StickerPack_CopyLink, icon: { theme in
@ -486,17 +497,32 @@ private final class StickerPackContainer: ASDisplayNode {
guard let strongSelf = self else {
return
}
if installed {
let _ = strongSelf.context.engine.stickers.removeStickerPackInteractively(id: info.id, option: .delete).start()
} else {
let _ = strongSelf.context.engine.stickers.addStickerPackInteractively(info: info, items: items).start()
var dismissed = false
switch strongSelf.decideNextAction(strongSelf, installed ? .remove : .add) {
case .dismiss:
strongSelf.requestDismiss()
dismissed = true
case .navigatedNext, .ignored:
strongSelf.updateStickerPackContents(.result(info: info, items: items, installed: !installed), hasPremium: false)
}
switch strongSelf.decideNextAction(strongSelf, installed ? .remove : .add) {
case .dismiss:
strongSelf.requestDismiss()
case .navigatedNext, .ignored:
strongSelf.updateStickerPackContents(.result(info: info, items: items, installed: !installed), hasPremium: false)
let actionPerformed = strongSelf.controller?.actionPerformed
if installed {
let _ = (strongSelf.context.engine.stickers.removeStickerPackInteractively(id: info.id, option: .delete)
|> deliverOnMainQueue).start(next: { indexAndItems in
guard let (positionInList, _) = indexAndItems else {
return
}
if dismissed {
actionPerformed?(info, items, .remove(positionInList: positionInList))
}
})
} else {
let _ = strongSelf.context.engine.stickers.addStickerPackInteractively(info: info, items: items).start()
if dismissed {
actionPerformed?(info, items, .add)
}
}
})
}
@ -1197,7 +1223,7 @@ public final class StickerPackScreenImpl: ViewController {
private let stickerPacks: [StickerPackReference]
private let initialSelectedStickerPackIndex: Int
private weak var parentNavigationController: NavigationController?
fileprivate weak var parentNavigationController: NavigationController?
private let sendSticker: ((FileMediaReference, ASDisplayNode, CGRect) -> Bool)?
private var controllerNode: StickerPackScreenNode {
@ -1205,6 +1231,7 @@ public final class StickerPackScreenImpl: ViewController {
}
public var dismissed: (() -> Void)?
public var actionPerformed: ((StickerPackCollectionInfo, [StickerPackItem], StickerPackScreenPerformedAction) -> Void)?
private let _ready = Promise<Bool>()
override public var ready: Promise<Bool> {
@ -1213,13 +1240,14 @@ public final class StickerPackScreenImpl: ViewController {
private var alreadyDidAppear: Bool = false
public init(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal<PresentationData, NoError>)? = nil, stickerPacks: [StickerPackReference], selectedStickerPackIndex: Int = 0, parentNavigationController: NavigationController? = nil, sendSticker: ((FileMediaReference, ASDisplayNode, CGRect) -> Bool)? = nil) {
public init(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal<PresentationData, NoError>)? = nil, stickerPacks: [StickerPackReference], selectedStickerPackIndex: Int = 0, parentNavigationController: NavigationController? = nil, sendSticker: ((FileMediaReference, ASDisplayNode, CGRect) -> Bool)? = nil, actionPerformed: ((StickerPackCollectionInfo, [StickerPackItem], StickerPackScreenPerformedAction) -> Void)? = nil) {
self.context = context
self.presentationData = updatedPresentationData?.initial ?? context.sharedContext.currentPresentationData.with { $0 }
self.stickerPacks = stickerPacks
self.initialSelectedStickerPackIndex = selectedStickerPackIndex
self.parentNavigationController = parentNavigationController
self.sendSticker = sendSticker
self.actionPerformed = actionPerformed
super.init(navigationBarPresentationData: nil)
@ -1293,7 +1321,9 @@ public enum StickerPackScreenPerformedAction {
}
public func StickerPackScreen(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal<PresentationData, NoError>)? = nil, mode: StickerPackPreviewControllerMode = .default, mainStickerPack: StickerPackReference, stickerPacks: [StickerPackReference], parentNavigationController: NavigationController? = nil, sendSticker: ((FileMediaReference, ASDisplayNode, CGRect) -> Bool)? = nil, actionPerformed: ((StickerPackCollectionInfo, [StickerPackItem], StickerPackScreenPerformedAction) -> Void)? = nil, dismissed: (() -> Void)? = nil) -> ViewController {
return StickerPackScreenImpl(context: context, stickerPacks: stickerPacks, selectedStickerPackIndex: stickerPacks.firstIndex(of: mainStickerPack) ?? 0, parentNavigationController: parentNavigationController, sendSticker: sendSticker)
let controller = StickerPackScreenImpl(context: context, stickerPacks: stickerPacks, selectedStickerPackIndex: stickerPacks.firstIndex(of: mainStickerPack) ?? 0, parentNavigationController: parentNavigationController, sendSticker: sendSticker, actionPerformed: actionPerformed)
controller.dismissed = dismissed
return controller
// let controller = StickerPackPreviewController(context: context, updatedPresentationData: updatedPresentationData, stickerPack: mainStickerPack, mode: mode, parentNavigationController: parentNavigationController, actionPerformed: actionPerformed)
// controller.dismissed = dismissed

View File

@ -115,20 +115,40 @@ final class AudioWaveformNode: ASDisplayNode {
memset(adjustedSamplesMemory, 0, numSamples * 2)
var generateFakeSamples = false
var minSample: UInt16 = maxSample
var bins: [UInt16: Int] = [:]
for i in 0 ..< maxReadSamples {
let index = i * numSamples / maxReadSamples
let sample = samples[i]
if adjustedSamples[index] < sample {
adjustedSamples[index] = sample
}
if sample < minSample {
minSample = sample
if let count = bins[sample] {
bins[sample] = count + 1
} else {
bins[sample] = 1
}
}
if maxSample - minSample < 3 {
var sortedSamples: [(UInt16, Int)] = []
var totalCount: Int = 0
for (sample, count) in bins {
if sample > 0 {
sortedSamples.append((sample, count))
totalCount += count
}
}
sortedSamples.sort { $0.1 > $1.1 }
let topSamples = sortedSamples.prefix(1)
let topCount = topSamples.map{ $0.1 }.reduce(.zero, +)
var topCountPercent: Float = 0.0
if bins.count > 0 {
topCountPercent = Float(topCount) / Float(totalCount)
}
if topCountPercent > 0.75 {
generateFakeSamples = true
}
@ -138,7 +158,7 @@ final class AudioWaveformNode: ASDisplayNode {
}
for i in 0 ..< maxReadSamples {
let index = i * numSamples / maxReadSamples
adjustedSamples[index] = UInt16.random(in: 5...maxSample)
adjustedSamples[index] = UInt16.random(in: 6...maxSample)
}
}

View File

@ -10772,6 +10772,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
var peerType = peerType
if bot.peer.id == peer.id {
peerType.insert(.sameBot)
peerType.remove(.bot)
}
if !bot.peerTypes.intersection(peerType).isEmpty {