Various fixes

This commit is contained in:
Ilya Laktyushin
2024-03-28 17:25:59 +04:00
parent 40007ea9d0
commit 83ea35df09
5 changed files with 43 additions and 43 deletions

View File

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

View File

@@ -58,13 +58,13 @@ public struct RevenueStatsContextState: Equatable {
}
private func requestRevenueStats(postbox: Postbox, network: Network, peerId: PeerId, dark: Bool = false) -> Signal<RevenueStats?, NoError> {
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<RevenueStats?, NoError> in
guard let (statsDatacenterId, peer) = data, let inputChannel = apiInputChannel(peer) else {
} |> mapToSignal { peer -> Signal<RevenueStats?, NoError> 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<Api.stats.BroadcastRevenueStats, MTRpcError>
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)
}

View File

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

View File

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

View File

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