From 83ea35df09f1cf83ad6526f6c9dd0355432fb2bb Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Thu, 28 Mar 2024 17:25:59 +0400 Subject: [PATCH] Various fixes --- .../Sources/ChannelStatsController.swift | 2 +- .../Statistics/RevenueStatistics.swift | 23 ++------ .../Sources/MediaCutoutScreen.swift | 2 +- .../Sources/MediaEditorScreen.swift | 4 +- .../Sources/StickerCutoutOutlineView.swift | 55 +++++++++++-------- 5 files changed, 43 insertions(+), 43 deletions(-) diff --git a/submodules/StatisticsUI/Sources/ChannelStatsController.swift b/submodules/StatisticsUI/Sources/ChannelStatsController.swift index 3ca9896548..9ca9930720 100644 --- a/submodules/StatisticsUI/Sources/ChannelStatsController.swift +++ b/submodules/StatisticsUI/Sources/ChannelStatsController.swift @@ -1815,7 +1815,7 @@ public func channelStatsController(context: AccountContext, updatedPresentationD emptyStateItem = ItemListLoadingIndicatorEmptyStateItem(theme: presentationData.theme) } case .monetization: - if revenueState == nil { + if revenueState?.stats == nil { emptyStateItem = ItemListLoadingIndicatorEmptyStateItem(theme: presentationData.theme) } } diff --git a/submodules/TelegramCore/Sources/Statistics/RevenueStatistics.swift b/submodules/TelegramCore/Sources/Statistics/RevenueStatistics.swift index 3f1d973124..323b47fe43 100644 --- a/submodules/TelegramCore/Sources/Statistics/RevenueStatistics.swift +++ b/submodules/TelegramCore/Sources/Statistics/RevenueStatistics.swift @@ -58,13 +58,13 @@ public struct RevenueStatsContextState: Equatable { } private func requestRevenueStats(postbox: Postbox, network: Network, peerId: PeerId, dark: Bool = false) -> Signal { - return postbox.transaction { transaction -> (Int32, Peer)? in - if let peer = transaction.getPeer(peerId), let cachedData = transaction.getPeerCachedData(peerId: peerId) as? CachedChannelData { - return (cachedData.statsDatacenterId, peer) + return postbox.transaction { transaction -> Peer? in + if let peer = transaction.getPeer(peerId) { + return peer } return nil - } |> mapToSignal { data -> Signal in - guard let (statsDatacenterId, peer) = data, let inputChannel = apiInputChannel(peer) else { + } |> mapToSignal { peer -> Signal in + guard let peer, let inputChannel = apiInputChannel(peer) else { return .never() } @@ -73,18 +73,7 @@ private func requestRevenueStats(postbox: Postbox, network: Network, peerId: Pee flags |= (1 << 1) } - let signal: Signal - if network.datacenterId != statsDatacenterId { - signal = network.download(datacenterId: Int(statsDatacenterId), isMedia: false, tag: nil) - |> castError(MTRpcError.self) - |> mapToSignal { worker in - return worker.request(Api.functions.stats.getBroadcastRevenueStats(flags: flags, channel: inputChannel)) - } - } else { - signal = network.request(Api.functions.stats.getBroadcastRevenueStats(flags: flags, channel: inputChannel)) - } - - return signal + return network.request(Api.functions.stats.getBroadcastRevenueStats(flags: flags, channel: inputChannel)) |> map { result -> RevenueStats? in return RevenueStats(apiRevenueStats: result, peerId: peerId) } diff --git a/submodules/TelegramUI/Components/MediaEditorScreen/Sources/MediaCutoutScreen.swift b/submodules/TelegramUI/Components/MediaEditorScreen/Sources/MediaCutoutScreen.swift index 7b33ae8f67..ef3a279155 100644 --- a/submodules/TelegramUI/Components/MediaEditorScreen/Sources/MediaCutoutScreen.swift +++ b/submodules/TelegramUI/Components/MediaEditorScreen/Sources/MediaCutoutScreen.swift @@ -245,7 +245,7 @@ private final class MediaCutoutScreenComponent: Component { transition.setFrame(view: view, frame: previewContainerFrame) } - let frameWidth = floor(previewContainerFrame.width * 0.97) + let frameWidth = floorToScreenPixels(previewContainerFrame.width * 0.97) self.fadeView.frame = CGRect(x: floorToScreenPixels((previewContainerFrame.width - frameWidth) / 2.0), y: previewContainerFrame.minY + floorToScreenPixels((previewContainerFrame.height - frameWidth) / 2.0), width: frameWidth, height: frameWidth) self.fadeView.layer.cornerRadius = frameWidth / 8.0 diff --git a/submodules/TelegramUI/Components/MediaEditorScreen/Sources/MediaEditorScreen.swift b/submodules/TelegramUI/Components/MediaEditorScreen/Sources/MediaEditorScreen.swift index 6bb3ca4b66..e2d5601fa1 100644 --- a/submodules/TelegramUI/Components/MediaEditorScreen/Sources/MediaEditorScreen.swift +++ b/submodules/TelegramUI/Components/MediaEditorScreen/Sources/MediaEditorScreen.swift @@ -4431,11 +4431,11 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate transition.setFrame(view: self.selectionContainerView, frame: CGRect(origin: .zero, size: previewFrame.size)) - let stickerFrameWidth = floor(previewSize.width * 0.97) + let stickerFrameWidth = floorToScreenPixels(previewSize.width * 0.97) if let stickerBackgroundView = self.stickerBackgroundView, let stickerOverlayLayer = self.stickerOverlayLayer, let stickerFrameLayer = self.stickerFrameLayer { stickerOverlayLayer.frame = CGRect(origin: .zero, size: previewSize) - let stickerFrameRect = CGRect(origin: CGPoint(x: floor((previewSize.width - stickerFrameWidth) / 2.0), y: floor((previewSize.height - stickerFrameWidth) / 2.0)), size: CGSize(width: stickerFrameWidth, height: stickerFrameWidth)) + let stickerFrameRect = CGRect(origin: CGPoint(x: floorToScreenPixels((previewSize.width - stickerFrameWidth) / 2.0), y: floorToScreenPixels((previewSize.height - stickerFrameWidth) / 2.0)), size: CGSize(width: stickerFrameWidth, height: stickerFrameWidth)) let overlayOuterRect = UIBezierPath(rect: CGRect(origin: .zero, size: previewSize)) let overlayInnerRect = UIBezierPath(cgPath: CGPath(roundedRect: stickerFrameRect, cornerWidth: stickerFrameWidth / 8.0, cornerHeight: stickerFrameWidth / 8.0, transform: nil)) diff --git a/submodules/TelegramUI/Components/MediaEditorScreen/Sources/StickerCutoutOutlineView.swift b/submodules/TelegramUI/Components/MediaEditorScreen/Sources/StickerCutoutOutlineView.swift index e561d496b3..719f8afb76 100644 --- a/submodules/TelegramUI/Components/MediaEditorScreen/Sources/StickerCutoutOutlineView.swift +++ b/submodules/TelegramUI/Components/MediaEditorScreen/Sources/StickerCutoutOutlineView.swift @@ -49,13 +49,13 @@ final class StickerCutoutOutlineView: UIView { self.imageLayer.contents = image.cgImage if let path = getPathFromMaskImage(maskImage, size: size, values: values) { - self.strokeLayer.shadowPath = path.cgPath.expand(width: 1.5) + self.strokeLayer.shadowPath = path.path.cgPath.expand(width: 1.5) self.setupAnimation(path: path) } } - func setupAnimation(path: UIBezierPath) { + private func setupAnimation(path: BezierPath) { self.outlineLayer = CAEmitterLayer() self.outlineLayer.opacity = 0.7 self.glowLayer = CAEmitterLayer() @@ -66,11 +66,13 @@ final class StickerCutoutOutlineView: UIView { let randomBeginTime = (previousBeginTime + 4) % 6 previousBeginTime = randomBeginTime + let duration = path.length / 2200.0 + let outlineAnimation = CAKeyframeAnimation(keyPath: "emitterPosition") - outlineAnimation.path = path.cgPath - outlineAnimation.duration = 5.0 + outlineAnimation.path = path.path.cgPath + outlineAnimation.duration = duration outlineAnimation.repeatCount = .infinity - outlineAnimation.calculationMode = .paced + outlineAnimation.calculationMode = .cubicPaced outlineAnimation.beginTime = Double(randomBeginTime) self.outlineLayer.add(outlineAnimation, forKey: "emitterPosition") @@ -83,8 +85,8 @@ final class StickerCutoutOutlineView: UIView { lineEmitterCell.color = UIColor.white.cgColor lineEmitterCell.contents = UIImage(named: "Media Editor/ParticleDot")?.cgImage lineEmitterCell.lifetime = 2.2 - lineEmitterCell.birthRate = 600 - lineEmitterCell.scale = 0.13 + lineEmitterCell.birthRate = 1000 + lineEmitterCell.scale = 0.14 lineEmitterCell.alphaSpeed = -0.4 self.outlineLayer.emitterCells = [lineEmitterCell] @@ -93,8 +95,8 @@ final class StickerCutoutOutlineView: UIView { self.outlineLayer.emitterShape = .point let glowAnimation = CAKeyframeAnimation(keyPath: "emitterPosition") - glowAnimation.path = path.cgPath - glowAnimation.duration = 5.0 + glowAnimation.path = path.path.cgPath + glowAnimation.duration = duration glowAnimation.repeatCount = .infinity glowAnimation.calculationMode = .cubicPaced glowAnimation.beginTime = Double(randomBeginTime) @@ -136,7 +138,7 @@ final class StickerCutoutOutlineView: UIView { } } -private func getPathFromMaskImage(_ image: CIImage, size: CGSize, values: MediaEditorValues) -> UIBezierPath? { +private func getPathFromMaskImage(_ image: CIImage, size: CGSize, values: MediaEditorValues) -> BezierPath? { let edges = image.applyingFilter("CILineOverlay", parameters: ["inputEdgeIntensity": 0.1]) guard let pixelBuffer = getEdgesBitmap(edges) else { @@ -151,7 +153,7 @@ private func getPathFromMaskImage(_ image: CIImage, size: CGSize, values: MediaE var contour = findContours(pixelBuffer: pixelBuffer) contour = simplify(contour, tolerance: 1.4) - let path = UIBezierPath(points: contour, smooth: false) + let path = BezierPath(points: contour, smooth: false) let firstScale = min(size.width, size.height) / 256.0 let secondScale = size.width / 1080.0 @@ -165,8 +167,8 @@ private func getPathFromMaskImage(_ image: CIImage, size: CGSize, values: MediaE transform = transform.rotated(by: rotation) transform = transform.scaledBy(x: scale * firstScale, y: scale * firstScale) - if !path.isEmpty { - path.apply(transform) + if !path.path.isEmpty { + path.apply(transform, scale: scale) return path } return nil @@ -481,9 +483,12 @@ fileprivate extension Array { } } -private extension UIBezierPath { - convenience init(points: [CGPoint], smooth: Bool) { - self.init() +private class BezierPath { + let path: UIBezierPath + var length: CGFloat = 0.0 + + init(points: [CGPoint], smooth: Bool) { + self.path = UIBezierPath() if smooth { let K: CGFloat = 0.2 @@ -499,19 +504,25 @@ private extension UIBezierPath { c2[(index + points.count - 1) % points.count] = CGPoint(x: p.x - v.x, y: p.y - v.y) //(p - v) c1[(index + points.count) % points.count] = CGPoint(x: p.x + v.x, y: p.y + v.y) //(p + v) } - self.move(to: points[0]) + self.path.move(to: points[0]) for index in 0 ..< points.count - 1 { let c1 = c1[index] ?? points[points.circularIndex(index)] let c2 = c2[index] ?? points[points.circularIndex(index + 1)] - self.addCurve(to: points[circularIndex: index + 1], controlPoint1: c1, controlPoint2: c2) + self.path.addCurve(to: points[circularIndex: index + 1], controlPoint1: c1, controlPoint2: c2) } - self.close() + self.path.close() } else { - self.move(to: points[0]) + self.path.move(to: points[0]) for index in 1 ..< points.count - 1 { - self.addLine(to: points[index]) + self.length += points[index].distanceFrom(points[index - 1]) + self.path.addLine(to: points[index]) } - self.close() + self.path.close() } } + + func apply(_ transform: CGAffineTransform, scale: CGFloat) { + self.path.apply(transform) + self.length *= scale + } }