mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-15 21:45:19 +00:00
Rewrite default pattern loading
This commit is contained in:
parent
719a749322
commit
9131d607f7
@ -1469,6 +1469,7 @@ swift_library(
|
||||
"//submodules/TelegramVoip:TelegramVoip",
|
||||
"//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit",
|
||||
"//submodules/BuildConfig:BuildConfig",
|
||||
"//submodules/WidgetItems:WidgetItems",
|
||||
],
|
||||
)
|
||||
|
||||
|
@ -121,28 +121,23 @@ public final class CachedPatternWallpaperMaskRepresentation: CachedMediaResource
|
||||
public let keepDuration: CachedMediaRepresentationKeepDuration = .general
|
||||
|
||||
public let size: CGSize?
|
||||
public let scaleFromCenter: CGFloat?
|
||||
|
||||
public var uniqueId: String {
|
||||
if let size = self.size {
|
||||
var result = "pattern-wallpaper-mask-\(Int(size.width))x\(Int(size.height))"
|
||||
if let scaleFromCenter = self.scaleFromCenter {
|
||||
result.append("-scale\(scaleFromCenter)")
|
||||
}
|
||||
return result
|
||||
} else {
|
||||
return "pattern-wallpaper-mask"
|
||||
}
|
||||
}
|
||||
|
||||
public init(size: CGSize?, scaleFromCenter: CGFloat?) {
|
||||
public init(size: CGSize?) {
|
||||
self.size = size
|
||||
self.scaleFromCenter = scaleFromCenter
|
||||
}
|
||||
|
||||
public func isEqual(to: CachedMediaResourceRepresentation) -> Bool {
|
||||
if let to = to as? CachedPatternWallpaperMaskRepresentation {
|
||||
return self.size == to.size && self.scaleFromCenter == to.scaleFromCenter
|
||||
return self.size == to.size
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
|
@ -2,32 +2,33 @@ import Foundation
|
||||
import Postbox
|
||||
import SyncCore
|
||||
import TelegramUIPreferences
|
||||
import TelegramPresentationData
|
||||
|
||||
private func patternWallpaper(slug: String, colors: [UInt32], intensity: Int32?, rotation: Int32?) -> TelegramWallpaper {
|
||||
return TelegramWallpaper.file(id: 0, accessHash: 0, isCreator: false, isDefault: true, isPattern: true, isDark: false, slug: slug, file: TelegramMediaFile(fileId: MediaId(namespace: 0, id: 0), partialReference: nil, resource: LocalFileMediaResource(fileId: 0), previewRepresentations: [], videoThumbnails: [], immediateThumbnailData: nil, mimeType: "", size: nil, attributes: []), settings: WallpaperSettings(colors: colors, intensity: intensity ?? 50, rotation: rotation))
|
||||
private func patternWallpaper(colors: [UInt32], intensity: Int32?, rotation: Int32?) -> TelegramWallpaper {
|
||||
return defaultBuiltinWallpaper(colors: colors, intensity: intensity ?? 50, rotation: rotation)
|
||||
}
|
||||
|
||||
var dayClassicColorPresets: [PresentationThemeAccentColor] = [
|
||||
// Pink with Blue
|
||||
PresentationThemeAccentColor(index: 106, baseColor: .preset, accentColor: 0xfff55783, bubbleColors: (0xffd6f5ff, 0xffc9fdfe), wallpaper: patternWallpaper(slug: "fqv01SQemVIBAAAApND8LDRUhRU", colors: [0x8dc0eb, 0xb9d1ea, 0xc6b1ef, 0xebd7ef], intensity: 50, rotation: nil)),
|
||||
PresentationThemeAccentColor(index: 106, baseColor: .preset, accentColor: 0xfff55783, bubbleColors: (0xffd6f5ff, 0xffc9fdfe), wallpaper: patternWallpaper(colors: [0x8dc0eb, 0xb9d1ea, 0xc6b1ef, 0xebd7ef], intensity: 50, rotation: nil)),
|
||||
|
||||
// Pink with Gold
|
||||
PresentationThemeAccentColor(index: 102, baseColor: .preset, accentColor: 0xFFFF5FA9, bubbleColors: (0xFFFFF4D7, nil), wallpaper: patternWallpaper(slug: "9GcNVISdSVADAAAAUcw5BYjELW4", colors: [0xeaa36e, 0xf0e486, 0xf29ebf, 0xe8c06e], intensity: 50, rotation: nil)),
|
||||
PresentationThemeAccentColor(index: 102, baseColor: .preset, accentColor: 0xFFFF5FA9, bubbleColors: (0xFFFFF4D7, nil), wallpaper: patternWallpaper(colors: [0xeaa36e, 0xf0e486, 0xf29ebf, 0xe8c06e], intensity: 50, rotation: nil)),
|
||||
|
||||
// Green
|
||||
PresentationThemeAccentColor(index: 104, baseColor: .preset, accentColor: 0xFF5A9E29, bubbleColors: (0xffFFF8DF, nil), wallpaper: patternWallpaper(slug: "-Xc-np9y2VMCAAAARKr0yNNPYW0", colors: [0x7fc289, 0xe4d573, 0xafd677, 0xf0c07a], intensity: 50, rotation: nil)),
|
||||
PresentationThemeAccentColor(index: 104, baseColor: .preset, accentColor: 0xFF5A9E29, bubbleColors: (0xffFFF8DF, nil), wallpaper: patternWallpaper(colors: [0x7fc289, 0xe4d573, 0xafd677, 0xf0c07a], intensity: 50, rotation: nil)),
|
||||
|
||||
// Purple
|
||||
PresentationThemeAccentColor(index: 101, baseColor: .preset, accentColor: 0xFF7E5FE5, bubbleColors: (0xFFF5e2FF, nil), wallpaper: patternWallpaper(slug: "JrNEYdNhSFABAAAA9WtRdJkPRbY", colors: [0xe4b2ea, 0x8376c2, 0xeab9d9, 0xb493e6], intensity: 50, rotation: nil)),
|
||||
PresentationThemeAccentColor(index: 101, baseColor: .preset, accentColor: 0xFF7E5FE5, bubbleColors: (0xFFF5e2FF, nil), wallpaper: patternWallpaper(colors: [0xe4b2ea, 0x8376c2, 0xeab9d9, 0xb493e6], intensity: 50, rotation: nil)),
|
||||
|
||||
// Light Blue
|
||||
PresentationThemeAccentColor(index: 107, baseColor: .preset, accentColor: 0xFF2CB9ED, bubbleColors: (0xFFADF7B5, 0xFFFCFF8B), wallpaper: patternWallpaper(slug: "CJNyxPMgSVAEAAAAvW9sMwc51cw", colors: [0x1a2e1a, 0x47623c, 0x222e24, 0x314429], intensity: 50, rotation: nil)),
|
||||
PresentationThemeAccentColor(index: 107, baseColor: .preset, accentColor: 0xFF2CB9ED, bubbleColors: (0xFFADF7B5, 0xFFFCFF8B), wallpaper: patternWallpaper(colors: [0x1a2e1a, 0x47623c, 0x222e24, 0x314429], intensity: 50, rotation: nil)),
|
||||
|
||||
// Mint
|
||||
PresentationThemeAccentColor(index: 103, baseColor: .preset, accentColor: 0xFF199972, bubbleColors: (0xFFFFFEC7, nil), wallpaper: patternWallpaper(slug: "CJNyxPMgSVAEAAAAvW9sMwc51cw", colors: [0xdceb92, 0x8fe1d6, 0x67a3f2, 0x85d685], intensity: 50, rotation: nil)),
|
||||
PresentationThemeAccentColor(index: 103, baseColor: .preset, accentColor: 0xFF199972, bubbleColors: (0xFFFFFEC7, nil), wallpaper: patternWallpaper(colors: [0xdceb92, 0x8fe1d6, 0x67a3f2, 0x85d685], intensity: 50, rotation: nil)),
|
||||
|
||||
// Pink with Green
|
||||
PresentationThemeAccentColor(index: 105, baseColor: .preset, accentColor: 0xFFDA90D9, bubbleColors: (0xFF94FFF9, 0xFFCCFFC7), wallpaper: patternWallpaper(slug: "mP3FG_iwSFAFAAAA2AklJO978pA", colors: [0xffc3b2, 0xe2c0ff, 0xffe7b2], intensity: 50, rotation: nil))
|
||||
PresentationThemeAccentColor(index: 105, baseColor: .preset, accentColor: 0xFFDA90D9, bubbleColors: (0xFF94FFF9, 0xFFCCFFC7), wallpaper: patternWallpaper(colors: [0xffc3b2, 0xe2c0ff, 0xffe7b2], intensity: 50, rotation: nil))
|
||||
]
|
||||
|
||||
var dayColorPresets: [PresentationThemeAccentColor] = [
|
||||
|
@ -859,7 +859,7 @@ final class WallpaperGalleryItemNode: GalleryItemNode {
|
||||
let dimensions = file.file.dimensions ?? PixelDimensions(width: 1440, height: 2960)
|
||||
|
||||
let size = dimensions.cgSize.fitted(CGSize(width: 1280.0, height: 1280.0))
|
||||
let _ = self.context.account.postbox.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperMaskRepresentation(size: size, scaleFromCenter: nil), complete: false, fetch: true).start()
|
||||
let _ = self.context.account.postbox.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedPatternWallpaperMaskRepresentation(size: size), complete: false, fetch: true).start()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,6 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
UIImage * _Nullable drawSvgImage(NSData * _Nonnull data, CGSize size, UIColor *backgroundColor, UIColor *foregroundColor, CGFloat scaleFromCenter);
|
||||
UIImage * _Nullable drawSvgImage(NSData * _Nonnull data, CGSize size, UIColor *backgroundColor, UIColor *foregroundColor);
|
||||
|
||||
#endif /* Lottie_h */
|
||||
|
@ -83,7 +83,7 @@ CGSize aspectFillSize(CGSize size, CGSize bounds) {
|
||||
|
||||
@end
|
||||
|
||||
UIImage * _Nullable drawSvgImage(NSData * _Nonnull data, CGSize size, UIColor *backgroundColor, UIColor *foregroundColor, CGFloat scaleFromCenter) {
|
||||
UIImage * _Nullable drawSvgImage(NSData * _Nonnull data, CGSize size, UIColor *backgroundColor, UIColor *foregroundColor) {
|
||||
NSDate *startTime = [NSDate date];
|
||||
|
||||
NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];
|
||||
@ -128,10 +128,6 @@ UIImage * _Nullable drawSvgImage(NSData * _Nonnull data, CGSize size, UIColor *b
|
||||
|
||||
CGContextScaleCTM(context, scale, scale);
|
||||
CGContextTranslateCTM(context, (size.width - drawingSize.width) / 2.0, (size.height - drawingSize.height) / 2.0);
|
||||
|
||||
CGContextTranslateCTM(context, size.width / 2.0f, size.height / 2.0f);
|
||||
CGContextScaleCTM(context, scaleFromCenter, scaleFromCenter);
|
||||
CGContextTranslateCTM(context, -size.width / 2.0f, -size.height / 2.0f);
|
||||
|
||||
for (NSVGshape *shape = image->shapes; shape != NULL; shape = shape->next) {
|
||||
if (!(shape->flags & NSVG_FLAGS_VISIBLE)) {
|
||||
|
@ -7,7 +7,7 @@ import SyncCore
|
||||
|
||||
public func telegramWallpapers(postbox: Postbox, network: Network, forceUpdate: Bool = false) -> Signal<[TelegramWallpaper], NoError> {
|
||||
let fetch: ([TelegramWallpaper]?, Int32?) -> Signal<[TelegramWallpaper], NoError> = { current, hash in
|
||||
network.request(Api.functions.account.getWallPapers(hash: hash ?? 0))
|
||||
network.request(Api.functions.account.getWallPapers(hash: 0))
|
||||
|> retryRequest
|
||||
|> mapToSignal { result -> Signal<([TelegramWallpaper], Int32), NoError> in
|
||||
switch result {
|
||||
|
@ -48,7 +48,7 @@ public func customizeDefaultDarkTintedPresentationTheme(theme: PresentationTheme
|
||||
if bubbleColors == nil, editing {
|
||||
if let accentColor = accentColor {
|
||||
if let wallpaperGradientColors = wallpaperGradientColors, !wallpaperGradientColors.isEmpty {
|
||||
suggestedWallpaper = .file(id: 0, accessHash: 0, isCreator: false, isDefault: true, isPattern: true, isDark: false, slug: "fqv01SQemVIBAAAApND8LDRUhRU", file: TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: 36542425), partialReference: nil, resource: WallpaperDataResource(slug: "fqv01SQemVIBAAAApND8LDRUhRU"), previewRepresentations: [TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: 600, height: 800), resource: WallpaperDataResource(slug: "fqv01SQemVIBAAAApND8LDRUhRU"), progressiveSizes: [], immediateThumbnailData: nil)], videoThumbnails: [], immediateThumbnailData: nil, mimeType: "image/tgv", size: nil, attributes: []), settings: WallpaperSettings(colors: wallpaperGradientColors, intensity: 50))
|
||||
suggestedWallpaper = defaultBuiltinWallpaper(colors: wallpaperGradientColors)
|
||||
} else {
|
||||
let color = accentColor.withMultiplied(hue: 1.024, saturation: 0.573, brightness: 0.18)
|
||||
suggestedWallpaper = .color(color.argb)
|
||||
@ -757,7 +757,7 @@ public func makeDefaultDarkTintedPresentationTheme(extendingThemeReference: Pres
|
||||
)
|
||||
|
||||
let chat = PresentationThemeChat(
|
||||
defaultWallpaper: .file(id: 0, accessHash: 0, isCreator: false, isDefault: true, isPattern: true, isDark: false, slug: "fqv01SQemVIBAAAApND8LDRUhRU", file: TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: 36542425), partialReference: nil, resource: WallpaperDataResource(slug: "fqv01SQemVIBAAAApND8LDRUhRU"), previewRepresentations: [TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: 600, height: 800), resource: WallpaperDataResource(slug: "fqv01SQemVIBAAAApND8LDRUhRU"), progressiveSizes: [], immediateThumbnailData: nil)], videoThumbnails: [], immediateThumbnailData: nil, mimeType: "image/tgv", size: nil, attributes: []), settings: WallpaperSettings(colors: [0x1b2836, 0x121a22, 0x1b2836, 0x121a22], intensity: 50)),
|
||||
defaultWallpaper: defaultBuiltinWallpaper(colors: [0x1b2836, 0x121a22, 0x1b2836, 0x121a22]),
|
||||
message: message,
|
||||
serviceMessage: serviceMessage,
|
||||
inputPanel: inputPanel,
|
||||
|
@ -738,7 +738,7 @@ public func makeDefaultDayPresentationTheme(extendingThemeReference: Presentatio
|
||||
badgeTextColor: UIColor(rgb: 0xffffff)
|
||||
)
|
||||
|
||||
let defaultPatternWallpaper: TelegramWallpaper = .file(id: 0, accessHash: 0, isCreator: false, isDefault: true, isPattern: true, isDark: false, slug: "fqv01SQemVIBAAAApND8LDRUhRU", file: TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: 36542425), partialReference: nil, resource: WallpaperDataResource(slug: "fqv01SQemVIBAAAApND8LDRUhRU"), previewRepresentations: [TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: 600, height: 800), resource: WallpaperDataResource(slug: "fqv01SQemVIBAAAApND8LDRUhRU"), progressiveSizes: [], immediateThumbnailData: nil)], videoThumbnails: [], immediateThumbnailData: nil, mimeType: "image/tgv", size: nil, attributes: []), settings: WallpaperSettings(colors: defaultBuiltinWallpaperGradientColors.map(\.rgb), intensity: 50))
|
||||
let defaultPatternWallpaper: TelegramWallpaper = defaultBuiltinWallpaper(colors: defaultBuiltinWallpaperGradientColors.map(\.rgb))
|
||||
|
||||
let chat = PresentationThemeChat(
|
||||
defaultWallpaper: day ? .color(0xffffff) : defaultPatternWallpaper,
|
||||
@ -841,3 +841,50 @@ public let defaultBuiltinWallpaperGradientColors: [UIColor] = [
|
||||
UIColor(rgb: 0xd5d88d),
|
||||
UIColor(rgb: 0x88b884)
|
||||
]
|
||||
|
||||
public func defaultBuiltinWallpaper(colors: [UInt32], intensity: Int32 = 50, rotation: Int32? = nil) -> TelegramWallpaper {
|
||||
return .file(
|
||||
id: 5933856211186221059,
|
||||
accessHash: 7039846297018949116,
|
||||
isCreator: false,
|
||||
isDefault: false,
|
||||
isPattern: true,
|
||||
isDark: false,
|
||||
slug: "fqv01SQemVIBAAAApND8LDRUhRU",
|
||||
file: TelegramMediaFile(
|
||||
fileId: MediaId(namespace: Namespaces.Media.CloudFile, id: 5789658100176783156),
|
||||
partialReference: nil,
|
||||
resource: CloudDocumentMediaResource(
|
||||
datacenterId: 1,
|
||||
fileId: 5789658100176783156,
|
||||
accessHash: 5949005087206403318,
|
||||
size: 183832,
|
||||
fileReference: Data(),
|
||||
fileName: "pattern.tgv"
|
||||
),
|
||||
previewRepresentations: [
|
||||
TelegramMediaImageRepresentation(
|
||||
dimensions: PixelDimensions(width: 155, height: 320),
|
||||
resource: CloudDocumentSizeMediaResource(
|
||||
datacenterId: 1,
|
||||
documentId: 5789658100176783156,
|
||||
accessHash: 5949005087206403318,
|
||||
sizeSpec: "m",
|
||||
fileReference: Data()
|
||||
),
|
||||
progressiveSizes: [],
|
||||
immediateThumbnailData: nil
|
||||
)
|
||||
],
|
||||
videoThumbnails: [],
|
||||
immediateThumbnailData: nil,
|
||||
mimeType: "application/x-tgwallpattern",
|
||||
size: 183832,
|
||||
attributes: [
|
||||
.ImageSize(size: PixelDimensions(width: 1440, height: 2960)),
|
||||
.FileName(fileName: "pattern.tgv")
|
||||
]
|
||||
),
|
||||
settings: WallpaperSettings(colors: colors, intensity: intensity, rotation: rotation)
|
||||
)
|
||||
}
|
||||
|
BIN
submodules/TelegramUI/Resources/5789658100176783156-m.resource
Normal file
BIN
submodules/TelegramUI/Resources/5789658100176783156-m.resource
Normal file
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
@ -430,7 +430,7 @@ private func fetchCachedPatternWallpaperMaskRepresentation(resource: MediaResour
|
||||
if data.count > 5, let string = String(data: data.subdata(in: 0 ..< 5), encoding: .utf8), string == "<?xml" {
|
||||
let size = representation.size ?? CGSize(width: 1440.0, height: 2960.0)
|
||||
|
||||
if let image = drawSvgImage(data, size, .black, .white, representation.scaleFromCenter ?? 1.0) {
|
||||
if let image = drawSvgImage(data, size, .black, .white) {
|
||||
if let alphaDestination = CGImageDestinationCreateWithURL(url as CFURL, kUTTypeJPEG, 1, nil) {
|
||||
CGImageDestinationSetProperties(alphaDestination, [:] as CFDictionary)
|
||||
|
||||
@ -496,7 +496,7 @@ private func fetchCachedPatternWallpaperRepresentation(resource: MediaResource,
|
||||
if data.count > 5, let string = String(data: data.subdata(in: 0 ..< 5), encoding: .utf8), string == "<?xml" {
|
||||
let defaultSize = CGSize(width: 1440.0, height: 2960.0)
|
||||
size = defaultSize
|
||||
if let image = drawSvgImage(data, defaultSize, .black, .white, 1.0) {
|
||||
if let image = drawSvgImage(data, defaultSize, .black, .white) {
|
||||
maskImage = image
|
||||
}
|
||||
} else if let image = UIImage(data: data) {
|
||||
|
@ -61,6 +61,37 @@ public let telegramAccountAuxiliaryMethods = AccountAuxiliaryMethods(updatePeerC
|
||||
}
|
||||
}
|
||||
return nil
|
||||
} else if let cloudDocumentMediaResource = resource as? CloudDocumentMediaResource {
|
||||
if cloudDocumentMediaResource.fileId == 5789658100176783156 {
|
||||
if let url = getAppBundle().url(forResource: "fqv01SQemVIBAAAApND8LDRUhRU", withExtension: "tgv") {
|
||||
return Signal { subscriber in
|
||||
subscriber.putNext(.reset)
|
||||
if let data = try? Data(contentsOf: url, options: .mappedRead) {
|
||||
subscriber.putNext(.dataPart(resourceOffset: 0, data: data, range: 0 ..< data.count, complete: true))
|
||||
}
|
||||
|
||||
return EmptyDisposable
|
||||
}
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
} else if let cloudDocumentSizeMediaResource = resource as? CloudDocumentSizeMediaResource {
|
||||
if cloudDocumentSizeMediaResource.documentId == 5789658100176783156 && cloudDocumentSizeMediaResource.sizeSpec == "m" {
|
||||
if let url = getAppBundle().url(forResource: "5789658100176783156-m", withExtension: "resource") {
|
||||
return Signal { subscriber in
|
||||
subscriber.putNext(.reset)
|
||||
if let data = try? Data(contentsOf: url, options: .mappedRead) {
|
||||
subscriber.putNext(.dataPart(resourceOffset: 0, data: data, range: 0 ..< data.count, complete: true))
|
||||
}
|
||||
|
||||
return EmptyDisposable
|
||||
}
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}, fetchResourceMediaReferenceHash: { resource in
|
||||
|
@ -362,18 +362,13 @@ private func patternWallpaperDatas(account: Account, accountManager: AccountMana
|
||||
if let smallestRepresentation = smallestImageRepresentation(representations.map({ $0.representation })), let largestRepresentation = largestImageRepresentation(representations.map({ $0.representation })), let smallestIndex = representations.firstIndex(where: { $0.representation == smallestRepresentation }), let largestIndex = representations.firstIndex(where: { $0.representation == largestRepresentation }) {
|
||||
|
||||
let size: CGSize?
|
||||
var scaleFromCenter: CGFloat?
|
||||
switch mode {
|
||||
case .thumbnail:
|
||||
size = largestRepresentation.dimensions.cgSize.fitted(CGSize(width: 640.0, height: 640.0))
|
||||
let factor = smallestRepresentation.dimensions.cgSize.width / largestRepresentation.dimensions.cgSize.width
|
||||
if smallestRepresentation.dimensions.height >= 700 && abs(factor - 1.0) <= .ulpOfOne {
|
||||
scaleFromCenter = 2.1
|
||||
}
|
||||
default:
|
||||
size = nil
|
||||
}
|
||||
let maybeFullSize = combineLatest(accountManager.mediaBox.cachedResourceRepresentation(largestRepresentation.resource, representation: CachedPatternWallpaperMaskRepresentation(size: size, scaleFromCenter: scaleFromCenter), complete: false, fetch: false), account.postbox.mediaBox.cachedResourceRepresentation(largestRepresentation.resource, representation: CachedPatternWallpaperMaskRepresentation(size: size, scaleFromCenter: scaleFromCenter), complete: false, fetch: false))
|
||||
let maybeFullSize = combineLatest(accountManager.mediaBox.cachedResourceRepresentation(largestRepresentation.resource, representation: CachedPatternWallpaperMaskRepresentation(size: size), complete: false, fetch: false), account.postbox.mediaBox.cachedResourceRepresentation(largestRepresentation.resource, representation: CachedPatternWallpaperMaskRepresentation(size: size), complete: false, fetch: false))
|
||||
|
||||
let signal = maybeFullSize
|
||||
|> take(1)
|
||||
@ -393,12 +388,12 @@ private func patternWallpaperDatas(account: Account, accountManager: AccountMana
|
||||
|
||||
let accountThumbnailData = Signal<Data?, NoError> { subscriber in
|
||||
let fetchedDisposable = fetchedThumbnail.start()
|
||||
let thumbnailDisposable = account.postbox.mediaBox.cachedResourceRepresentation(representations[smallestIndex].representation.resource, representation: CachedPatternWallpaperMaskRepresentation(size: size, scaleFromCenter: scaleFromCenter), complete: false, fetch: true).start(next: { next in
|
||||
let thumbnailDisposable = account.postbox.mediaBox.cachedResourceRepresentation(representations[smallestIndex].representation.resource, representation: CachedPatternWallpaperMaskRepresentation(size: size), complete: false, fetch: true).start(next: { next in
|
||||
subscriber.putNext(next.size == 0 ? nil : try? Data(contentsOf: URL(fileURLWithPath: next.path), options: []))
|
||||
|
||||
if next.complete, let data = try? Data(contentsOf: URL(fileURLWithPath: next.path), options: .mappedRead) {
|
||||
accountManager.mediaBox.storeResourceData(representations[smallestIndex].representation.resource.id, data: data)
|
||||
let _ = accountManager.mediaBox.cachedResourceRepresentation(representations[smallestIndex].representation.resource, representation: CachedPatternWallpaperMaskRepresentation(size: size, scaleFromCenter: scaleFromCenter), complete: false, fetch: true).start()
|
||||
let _ = accountManager.mediaBox.cachedResourceRepresentation(representations[smallestIndex].representation.resource, representation: CachedPatternWallpaperMaskRepresentation(size: size), complete: false, fetch: true).start()
|
||||
}
|
||||
}, error: subscriber.putError, completed: subscriber.putCompletion)
|
||||
|
||||
@ -409,7 +404,7 @@ private func patternWallpaperDatas(account: Account, accountManager: AccountMana
|
||||
}
|
||||
|
||||
let sharedThumbnailData = Signal<Data?, NoError> { subscriber in
|
||||
let thumbnailDisposable = accountManager.mediaBox.cachedResourceRepresentation(representations[smallestIndex].representation.resource, representation: CachedPatternWallpaperMaskRepresentation(size: size, scaleFromCenter: scaleFromCenter), complete: false, fetch: true).start(next: { next in
|
||||
let thumbnailDisposable = accountManager.mediaBox.cachedResourceRepresentation(representations[smallestIndex].representation.resource, representation: CachedPatternWallpaperMaskRepresentation(size: size), complete: false, fetch: true).start(next: { next in
|
||||
subscriber.putNext(next.size == 0 ? nil : try? Data(contentsOf: URL(fileURLWithPath: next.path), options: []))
|
||||
}, error: subscriber.putError, completed: subscriber.putCompletion)
|
||||
|
||||
@ -439,12 +434,12 @@ private func patternWallpaperDatas(account: Account, accountManager: AccountMana
|
||||
|
||||
let accountFullSizeData = Signal<(Data?, Bool), NoError> { subscriber in
|
||||
let fetchedFullSizeDisposable = fetchedFullSize.start()
|
||||
let fullSizeDisposable = account.postbox.mediaBox.cachedResourceRepresentation(representations[largestIndex].representation.resource, representation: CachedPatternWallpaperMaskRepresentation(size: size, scaleFromCenter: scaleFromCenter), complete: false, fetch: true).start(next: { next in
|
||||
let fullSizeDisposable = account.postbox.mediaBox.cachedResourceRepresentation(representations[largestIndex].representation.resource, representation: CachedPatternWallpaperMaskRepresentation(size: size), complete: false, fetch: true).start(next: { next in
|
||||
subscriber.putNext((next.size == 0 ? nil : try? Data(contentsOf: URL(fileURLWithPath: next.path), options: []), next.complete))
|
||||
|
||||
if next.complete, let data = try? Data(contentsOf: URL(fileURLWithPath: next.path), options: .mappedRead) {
|
||||
accountManager.mediaBox.storeResourceData(representations[largestIndex].representation.resource.id, data: data)
|
||||
let _ = accountManager.mediaBox.cachedResourceRepresentation(representations[largestIndex].representation.resource, representation: CachedPatternWallpaperMaskRepresentation(size: size, scaleFromCenter: scaleFromCenter), complete: false, fetch: true).start()
|
||||
let _ = accountManager.mediaBox.cachedResourceRepresentation(representations[largestIndex].representation.resource, representation: CachedPatternWallpaperMaskRepresentation(size: size), complete: false, fetch: true).start()
|
||||
}
|
||||
}, error: subscriber.putError, completed: subscriber.putCompletion)
|
||||
|
||||
@ -455,7 +450,7 @@ private func patternWallpaperDatas(account: Account, accountManager: AccountMana
|
||||
}
|
||||
|
||||
let sharedFullSizeData = Signal<(Data?, Bool), NoError> { subscriber in
|
||||
let fullSizeDisposable = accountManager.mediaBox.cachedResourceRepresentation(representations[largestIndex].representation.resource, representation: CachedPatternWallpaperMaskRepresentation(size: size, scaleFromCenter: scaleFromCenter), complete: false, fetch: true).start(next: { next in
|
||||
let fullSizeDisposable = accountManager.mediaBox.cachedResourceRepresentation(representations[largestIndex].representation.resource, representation: CachedPatternWallpaperMaskRepresentation(size: size), complete: false, fetch: true).start(next: { next in
|
||||
subscriber.putNext((next.size == 0 ? nil : try? Data(contentsOf: URL(fileURLWithPath: next.path), options: []), next.complete))
|
||||
}, error: subscriber.putError, completed: subscriber.putCompletion)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user