mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-07-04 18:41:00 +00:00
Merge branch 'master' of gitlab.com:peter-iakovlev/telegram-ios
This commit is contained in:
commit
e26ca6274a
@ -3,61 +3,6 @@ import UIKit
|
|||||||
import Display
|
import Display
|
||||||
import AsyncDisplayKit
|
import AsyncDisplayKit
|
||||||
|
|
||||||
private struct GradientPoint {
|
|
||||||
var color: UIColor
|
|
||||||
var position: CGPoint
|
|
||||||
}
|
|
||||||
|
|
||||||
private func applyTransformerToPoints(step: Int, substep: Int) -> [GradientPoint] {
|
|
||||||
var points: [GradientPoint] = []
|
|
||||||
|
|
||||||
var firstSet: [CGPoint]
|
|
||||||
var secondSet: [CGPoint]
|
|
||||||
|
|
||||||
let colors: [UIColor] = [
|
|
||||||
UIColor(rgb: 0x7FA381),
|
|
||||||
UIColor(rgb: 0xFFF5C5),
|
|
||||||
UIColor(rgb: 0x336F55),
|
|
||||||
UIColor(rgb: 0xFBE37D)
|
|
||||||
]
|
|
||||||
|
|
||||||
let firstStepPoints: [CGPoint] = [
|
|
||||||
CGPoint(x: 0.823, y: 0.086),
|
|
||||||
CGPoint(x: 0.362, y: 0.254),
|
|
||||||
CGPoint(x: 0.184, y: 0.923),
|
|
||||||
CGPoint(x: 0.648, y: 0.759)
|
|
||||||
]
|
|
||||||
|
|
||||||
let nextStepPoints: [CGPoint] = [
|
|
||||||
CGPoint(x: 0.59, y: 0.16),
|
|
||||||
CGPoint(x: 0.28, y: 0.58),
|
|
||||||
CGPoint(x: 0.42, y: 0.83),
|
|
||||||
CGPoint(x: 0.74, y: 0.42)
|
|
||||||
]
|
|
||||||
|
|
||||||
if step % 2 == 0 {
|
|
||||||
firstSet = shiftArray(array: firstStepPoints, offset: step / 2)
|
|
||||||
secondSet = shiftArray(array: nextStepPoints, offset: step / 2)
|
|
||||||
} else {
|
|
||||||
firstSet = shiftArray(array: nextStepPoints, offset: step / 2)
|
|
||||||
secondSet = shiftArray(array: firstStepPoints, offset: step / 2 + 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
for index in 0 ..< colors.count {
|
|
||||||
let point = transformPoint(
|
|
||||||
points: (firstSet[index], secondSet[index]),
|
|
||||||
substep: substep
|
|
||||||
)
|
|
||||||
|
|
||||||
points.append(GradientPoint(
|
|
||||||
color: colors[index],
|
|
||||||
position: point
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
return points
|
|
||||||
}
|
|
||||||
|
|
||||||
private func shiftArray(array: [CGPoint], offset: Int) -> [CGPoint] {
|
private func shiftArray(array: [CGPoint], offset: Int) -> [CGPoint] {
|
||||||
var newArray = array
|
var newArray = array
|
||||||
var offset = offset
|
var offset = offset
|
||||||
@ -69,14 +14,6 @@ private func shiftArray(array: [CGPoint], offset: Int) -> [CGPoint] {
|
|||||||
return newArray
|
return newArray
|
||||||
}
|
}
|
||||||
|
|
||||||
private func transformPoint(points: (first: CGPoint, second: CGPoint), substep: Int) -> CGPoint {
|
|
||||||
let delta = CGFloat(substep) / CGFloat(30)
|
|
||||||
let x = points.first.x + (points.second.x - points.first.x) * delta
|
|
||||||
let y = points.first.y + (points.second.y - points.first.y) * delta
|
|
||||||
|
|
||||||
return CGPoint(x: x, y: y)
|
|
||||||
}
|
|
||||||
|
|
||||||
private func generateGradientComponent(size: CGSize, color: UIColor) -> UIImage? {
|
private func generateGradientComponent(size: CGSize, color: UIColor) -> UIImage? {
|
||||||
UIGraphicsBeginImageContextWithOptions(size, false, 1.0)
|
UIGraphicsBeginImageContextWithOptions(size, false, 1.0)
|
||||||
|
|
||||||
@ -86,15 +23,13 @@ private func generateGradientComponent(size: CGSize, color: UIColor) -> UIImage?
|
|||||||
|
|
||||||
c?.setBlendMode(.normal)
|
c?.setBlendMode(.normal)
|
||||||
|
|
||||||
//var gradLocs: [CGFloat] = [0, 0.1, 0.35, 1]
|
var gradLocs: [CGFloat] = [0.0, 0.1, 1.0]
|
||||||
var gradLocs: [CGFloat] = [0.0, 1.0]
|
|
||||||
let colorSpace = CGColorSpaceCreateDeviceRGB()
|
let colorSpace = CGColorSpaceCreateDeviceRGB()
|
||||||
let radius = min(size.width / 2.0, size.height / 2.0)
|
let radius = min(size.width / 2.0, size.height / 2.0)
|
||||||
|
|
||||||
let colors = [
|
let colors = [
|
||||||
color.cgColor,
|
color.cgColor,
|
||||||
//color.withAlphaComponent(0.8).cgColor,
|
color.cgColor,
|
||||||
//color.withAlphaComponent(0.3).cgColor,
|
|
||||||
color.withAlphaComponent(0).cgColor
|
color.withAlphaComponent(0).cgColor
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -112,35 +47,14 @@ private func generateGradientComponent(size: CGSize, color: UIColor) -> UIImage?
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final class GradientBackgroundNode: ASDisplayNode {
|
public final class GradientBackgroundNode: ASDisplayNode {
|
||||||
//private let imageView: UIImageView
|
|
||||||
|
|
||||||
private var pointImages: [UIImageView] = []
|
private var pointImages: [UIImageView] = []
|
||||||
private let dimView: UIView
|
private let dimView: UIView
|
||||||
|
|
||||||
private let firstStepPoints: [CGPoint] = [
|
|
||||||
CGPoint(x: 0.823, y: 0.086),
|
|
||||||
CGPoint(x: 0.362, y: 0.254),
|
|
||||||
CGPoint(x: 0.184, y: 0.923),
|
|
||||||
CGPoint(x: 0.648, y: 0.759)
|
|
||||||
]
|
|
||||||
|
|
||||||
private let nextStepPoints: [CGPoint] = [
|
|
||||||
CGPoint(x: 0.59, y: 0.16),
|
|
||||||
CGPoint(x: 0.28, y: 0.58),
|
|
||||||
CGPoint(x: 0.42, y: 0.83),
|
|
||||||
CGPoint(x: 0.74, y: 0.42)
|
|
||||||
]
|
|
||||||
|
|
||||||
private var phase: Int = 0
|
private var phase: Int = 0
|
||||||
private var subphase: Int = 0
|
|
||||||
|
|
||||||
private var timer: Timer?
|
|
||||||
|
|
||||||
private var validLayout: CGSize?
|
private var validLayout: CGSize?
|
||||||
|
|
||||||
override public init() {
|
override public init() {
|
||||||
//self.imageView = UIImageView()
|
|
||||||
|
|
||||||
self.dimView = UIView()
|
self.dimView = UIView()
|
||||||
self.dimView.backgroundColor = UIColor(white: 1.0, alpha: 0.0)
|
self.dimView.backgroundColor = UIColor(white: 1.0, alpha: 0.0)
|
||||||
|
|
||||||
@ -151,23 +65,6 @@ public final class GradientBackgroundNode: ASDisplayNode {
|
|||||||
self.backgroundColor = .white
|
self.backgroundColor = .white
|
||||||
self.clipsToBounds = true
|
self.clipsToBounds = true
|
||||||
|
|
||||||
//self.view.addSubview(self.imageView)
|
|
||||||
|
|
||||||
/*let compositingModes: [String] = CIFilter
|
|
||||||
.filterNames(inCategory: nil) // fetch all the available filters
|
|
||||||
.filter { $0.contains("Compositing")} // retrieve only the compositing ones
|
|
||||||
.map {
|
|
||||||
let capitalizedFilter = $0.dropFirst(2) // drop the CIn prefix
|
|
||||||
let first = capitalizedFilter.first! // fetch the first letter
|
|
||||||
// lowercase the first letter and drop the `Compositing` suffix
|
|
||||||
return "\(first.lowercased())\(capitalizedFilter.dropFirst().dropLast("Compositing".count))"
|
|
||||||
}*/
|
|
||||||
|
|
||||||
//print("compositingModes: \(compositingModes)")
|
|
||||||
|
|
||||||
//self.imageView.alpha = 0.5
|
|
||||||
//self.imageView.layer.compositingFilter = "multiplyBlendMode"
|
|
||||||
|
|
||||||
let colors: [UIColor] = [
|
let colors: [UIColor] = [
|
||||||
UIColor(rgb: 0x7FA381),
|
UIColor(rgb: 0x7FA381),
|
||||||
UIColor(rgb: 0xFFF5C5),
|
UIColor(rgb: 0xFFF5C5),
|
||||||
@ -183,24 +80,6 @@ public final class GradientBackgroundNode: ASDisplayNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
self.view.addSubview(self.dimView)
|
self.view.addSubview(self.dimView)
|
||||||
|
|
||||||
/*if #available(iOS 10.0, *) {
|
|
||||||
let timer = Timer(timeInterval: 2.0, repeats: true, block: { [weak self] _ in
|
|
||||||
guard let strongSelf = self else {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
strongSelf.phase = (strongSelf.phase + 1) % 4
|
|
||||||
if let size = strongSelf.validLayout {
|
|
||||||
strongSelf.updateLayout(size: size, transition: .animated(duration: 0.5, curve: .spring))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
self.timer = timer
|
|
||||||
RunLoop.main.add(timer, forMode: .common)
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
|
|
||||||
deinit {
|
|
||||||
self.timer?.invalidate()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func updateLayout(size: CGSize, transition: ContainedViewLayoutTransition) {
|
public func updateLayout(size: CGSize, transition: ContainedViewLayoutTransition) {
|
||||||
@ -211,10 +90,10 @@ public final class GradientBackgroundNode: ASDisplayNode {
|
|||||||
let positions: [CGPoint]
|
let positions: [CGPoint]
|
||||||
|
|
||||||
let basePositions: [CGPoint] = [
|
let basePositions: [CGPoint] = [
|
||||||
CGPoint(x: 0.1, y: 0.1),
|
CGPoint(x: 0.2, y: 0.2),
|
||||||
CGPoint(x: 0.1, y: 0.9),
|
CGPoint(x: 0.2, y: 0.8),
|
||||||
CGPoint(x: 0.9, y: 0.9),
|
CGPoint(x: 0.8, y: 0.8),
|
||||||
CGPoint(x: 0.9, y: 0.1),
|
CGPoint(x: 0.8, y: 0.2),
|
||||||
]
|
]
|
||||||
|
|
||||||
switch self.phase % 4 {
|
switch self.phase % 4 {
|
||||||
@ -230,7 +109,7 @@ public final class GradientBackgroundNode: ASDisplayNode {
|
|||||||
preconditionFailure()
|
preconditionFailure()
|
||||||
}
|
}
|
||||||
|
|
||||||
for i in 0 ..< firstStepPoints.count {
|
for i in 0 ..< positions.count {
|
||||||
if self.pointImages.count <= i {
|
if self.pointImages.count <= i {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
public struct TimestampBasedMessageAttributesEntry {
|
public struct TimestampBasedMessageAttributesEntry: CustomStringConvertible {
|
||||||
public let tag: UInt16
|
public let tag: UInt16
|
||||||
public let timestamp: Int32
|
public let timestamp: Int32
|
||||||
public let messageId: MessageId
|
public let messageId: MessageId
|
||||||
@ -8,6 +8,10 @@ public struct TimestampBasedMessageAttributesEntry {
|
|||||||
public var index: MessageIndex {
|
public var index: MessageIndex {
|
||||||
return MessageIndex(id: self.messageId, timestamp: timestamp)
|
return MessageIndex(id: self.messageId, timestamp: timestamp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public var description: String {
|
||||||
|
return "(tag: \(self.tag), timestamp: \(self.timestamp), messageId: \(self.messageId))"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum TimestampBasedMessageAttributesOperation {
|
enum TimestampBasedMessageAttributesOperation {
|
||||||
@ -53,7 +57,11 @@ final class TimestampBasedMessageAttributesTable: Table {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func set(tag: UInt16, id: MessageId, timestamp: Int32, operations: inout [TimestampBasedMessageAttributesOperation]) {
|
func set(tag: UInt16, id: MessageId, timestamp: Int32, operations: inout [TimestampBasedMessageAttributesOperation]) {
|
||||||
if let previousTimestamp = self.indexTable.get(tag: tag, id: id) {
|
let previousTimestamp = self.indexTable.get(tag: tag, id: id)
|
||||||
|
|
||||||
|
postboxLog("TimestampBasedMessageAttributesTable set(tag: \(tag), id: \(id), timestamp: \(timestamp)) previousTimestamp: \(String(describing: previousTimestamp))")
|
||||||
|
|
||||||
|
if let previousTimestamp = previousTimestamp {
|
||||||
if previousTimestamp == timestamp {
|
if previousTimestamp == timestamp {
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
@ -67,7 +75,11 @@ final class TimestampBasedMessageAttributesTable: Table {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func remove(tag: UInt16, id: MessageId, operations: inout [TimestampBasedMessageAttributesOperation]) {
|
func remove(tag: UInt16, id: MessageId, operations: inout [TimestampBasedMessageAttributesOperation]) {
|
||||||
if let previousTimestamp = self.indexTable.get(tag: tag, id: id) {
|
let previousTimestamp = self.indexTable.get(tag: tag, id: id)
|
||||||
|
|
||||||
|
postboxLog("TimestampBasedMessageAttributesTable remove(tag: \(tag), id: \(id)) previousTimestamp: \(String(describing: previousTimestamp))")
|
||||||
|
|
||||||
|
if let previousTimestamp = previousTimestamp {
|
||||||
self.valueBox.remove(self.table, key: self.key(tag: tag, timestamp: previousTimestamp, id: id), secure: false)
|
self.valueBox.remove(self.table, key: self.key(tag: tag, timestamp: previousTimestamp, id: id), secure: false)
|
||||||
self.indexTable.remove(tag: tag, id: id)
|
self.indexTable.remove(tag: tag, id: id)
|
||||||
operations.append(.remove(TimestampBasedMessageAttributesEntry(tag: tag, timestamp: previousTimestamp, messageId: id)))
|
operations.append(.remove(TimestampBasedMessageAttributesEntry(tag: tag, timestamp: previousTimestamp, messageId: id)))
|
||||||
|
@ -7,6 +7,8 @@ final class MutableTimestampBasedMessageAttributesView {
|
|||||||
init(postbox: Postbox, tag: UInt16) {
|
init(postbox: Postbox, tag: UInt16) {
|
||||||
self.tag = tag
|
self.tag = tag
|
||||||
self.head = postbox.timestampBasedMessageAttributesTable.head(tag: tag)
|
self.head = postbox.timestampBasedMessageAttributesTable.head(tag: tag)
|
||||||
|
|
||||||
|
postboxLog("MutableTimestampBasedMessageAttributesView: tag: \(tag) head: \(String(describing: self.head))")
|
||||||
}
|
}
|
||||||
|
|
||||||
func replay(postbox: Postbox, operations: [TimestampBasedMessageAttributesOperation]) -> Bool {
|
func replay(postbox: Postbox, operations: [TimestampBasedMessageAttributesOperation]) -> Bool {
|
||||||
|
@ -62,7 +62,9 @@ func managedAutoremoveMessageOperations(network: Network, postbox: Postbox, isRe
|
|||||||
|> distinctUntilChanged*/
|
|> distinctUntilChanged*/
|
||||||
|
|
||||||
let timeOffset: Signal<Double, NoError> = .single(0.0)
|
let timeOffset: Signal<Double, NoError> = .single(0.0)
|
||||||
|
|
||||||
|
Logger.shared.log("Autoremove", "starting isRemove: \(isRemove)")
|
||||||
|
|
||||||
let disposable = combineLatest(timeOffset, postbox.timestampBasedMessageAttributesView(tag: isRemove ? 0 : 1)).start(next: { timeOffset, view in
|
let disposable = combineLatest(timeOffset, postbox.timestampBasedMessageAttributesView(tag: isRemove ? 0 : 1)).start(next: { timeOffset, view in
|
||||||
let (disposeOperations, beginOperations) = helper.with { helper -> (disposeOperations: [Disposable], beginOperations: [(TimestampBasedMessageAttributesEntry, MetaDisposable)]) in
|
let (disposeOperations, beginOperations) = helper.with { helper -> (disposeOperations: [Disposable], beginOperations: [(TimestampBasedMessageAttributesEntry, MetaDisposable)]) in
|
||||||
return helper.update(view.head)
|
return helper.update(view.head)
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit f000849f159e255fabec70ea18312eb8ae6c69e0
|
Subproject commit cd921e97bfc6af347ff7f938bd2f40e839f64f79
|
Loading…
x
Reference in New Issue
Block a user