mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 22:55:00 +00:00
Various fixes
This commit is contained in:
@@ -11,28 +11,28 @@ import WallpaperBackgroundNode
|
|||||||
|
|
||||||
public final class DrawingWallpaperRenderer {
|
public final class DrawingWallpaperRenderer {
|
||||||
private let context: AccountContext
|
private let context: AccountContext
|
||||||
private let customDayWallpaper: TelegramWallpaper?
|
private let dayWallpaper: TelegramWallpaper?
|
||||||
private let customNightWallpaper: TelegramWallpaper?
|
private let nightWallpaper: TelegramWallpaper?
|
||||||
|
|
||||||
private let wallpaperBackgroundNode: WallpaperBackgroundNode
|
private let wallpaperBackgroundNode: WallpaperBackgroundNode
|
||||||
private let darkWallpaperBackgroundNode: WallpaperBackgroundNode
|
private let darkWallpaperBackgroundNode: WallpaperBackgroundNode
|
||||||
|
|
||||||
public init (context: AccountContext, customDayWallpaper: TelegramWallpaper?, customNightWallpaper: TelegramWallpaper?) {
|
public init (context: AccountContext, dayWallpaper: TelegramWallpaper?, nightWallpaper: TelegramWallpaper?) {
|
||||||
self.context = context
|
self.context = context
|
||||||
self.customDayWallpaper = customDayWallpaper
|
self.dayWallpaper = dayWallpaper
|
||||||
self.customNightWallpaper = customNightWallpaper
|
self.nightWallpaper = nightWallpaper
|
||||||
|
|
||||||
self.wallpaperBackgroundNode = createWallpaperBackgroundNode(context: context, forChatDisplay: true, useSharedAnimationPhase: false)
|
self.wallpaperBackgroundNode = createWallpaperBackgroundNode(context: context, forChatDisplay: true, useSharedAnimationPhase: false)
|
||||||
self.wallpaperBackgroundNode.displaysAsynchronously = false
|
self.wallpaperBackgroundNode.displaysAsynchronously = false
|
||||||
|
|
||||||
let wallpaper = self.customDayWallpaper ?? context.sharedContext.currentPresentationData.with { $0 }.chatWallpaper
|
let wallpaper = self.dayWallpaper ?? context.sharedContext.currentPresentationData.with { $0 }.chatWallpaper
|
||||||
self.wallpaperBackgroundNode.update(wallpaper: wallpaper, animated: false)
|
self.wallpaperBackgroundNode.update(wallpaper: wallpaper, animated: false)
|
||||||
|
|
||||||
self.darkWallpaperBackgroundNode = createWallpaperBackgroundNode(context: context, forChatDisplay: true, useSharedAnimationPhase: false)
|
self.darkWallpaperBackgroundNode = createWallpaperBackgroundNode(context: context, forChatDisplay: true, useSharedAnimationPhase: false)
|
||||||
self.darkWallpaperBackgroundNode.displaysAsynchronously = false
|
self.darkWallpaperBackgroundNode.displaysAsynchronously = false
|
||||||
|
|
||||||
let darkTheme = defaultDarkColorPresentationTheme
|
let darkTheme = defaultDarkColorPresentationTheme
|
||||||
let darkWallpaper = self.customNightWallpaper ?? darkTheme.chat.defaultWallpaper
|
let darkWallpaper = self.nightWallpaper ?? darkTheme.chat.defaultWallpaper
|
||||||
self.darkWallpaperBackgroundNode.update(wallpaper: darkWallpaper, animated: false)
|
self.darkWallpaperBackgroundNode.update(wallpaper: darkWallpaper, animated: false)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,13 +40,15 @@ public final class DrawingWallpaperRenderer {
|
|||||||
self.updateLayout(size: CGSize(width: 360.0, height: 640.0))
|
self.updateLayout(size: CGSize(width: 360.0, height: 640.0))
|
||||||
|
|
||||||
let resultSize = CGSize(width: 1080, height: 1920)
|
let resultSize = CGSize(width: 1080, height: 1920)
|
||||||
self.generate(view: self.wallpaperBackgroundNode.view) { dayImage in
|
Queue.mainQueue().justDispatch {
|
||||||
if self.customDayWallpaper != nil && self.customNightWallpaper == nil {
|
self.generate(view: self.wallpaperBackgroundNode.view) { dayImage in
|
||||||
completion(resultSize, dayImage, nil, nil)
|
if self.dayWallpaper != nil && self.nightWallpaper == nil {
|
||||||
} else {
|
completion(resultSize, dayImage, nil, nil)
|
||||||
Queue.mainQueue().justDispatch {
|
} else {
|
||||||
self.generate(view: self.darkWallpaperBackgroundNode.view) { nightImage in
|
Queue.mainQueue().justDispatch {
|
||||||
completion(resultSize, dayImage, nightImage, nil)
|
self.generate(view: self.darkWallpaperBackgroundNode.view) { nightImage in
|
||||||
|
completion(resultSize, dayImage, nightImage, nil)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -129,7 +131,7 @@ public final class DrawingMessageRenderer {
|
|||||||
let layout = ContainerViewLayout(size: CGSize(width: 360.0, height: 640.0), metrics: LayoutMetrics(widthClass: .compact, heightClass: .compact, orientation: .portrait), deviceMetrics: .iPhoneX, intrinsicInsets: .zero, safeInsets: .zero, additionalInsets: .zero, statusBarHeight: 0.0, inputHeight: nil, inputHeightIsInteractivellyChanging: false, inVoiceOver: false)
|
let layout = ContainerViewLayout(size: CGSize(width: 360.0, height: 640.0), metrics: LayoutMetrics(widthClass: .compact, heightClass: .compact, orientation: .portrait), deviceMetrics: .iPhoneX, intrinsicInsets: .zero, safeInsets: .zero, additionalInsets: .zero, statusBarHeight: 0.0, inputHeight: nil, inputHeightIsInteractivellyChanging: false, inVoiceOver: false)
|
||||||
let size = self.updateMessagesLayout(layout: layout, presentationData: mockPresentationData)
|
let size = self.updateMessagesLayout(layout: layout, presentationData: mockPresentationData)
|
||||||
|
|
||||||
Queue.mainQueue().after(0.03, {
|
Queue.mainQueue().after(0.05, {
|
||||||
self.generate(size: size) { image in
|
self.generate(size: size) { image in
|
||||||
completion(size, image)
|
completion(size, image)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import AVFoundation
|
|||||||
import SwiftSignalKit
|
import SwiftSignalKit
|
||||||
import TelegramCore
|
import TelegramCore
|
||||||
import AccountContext
|
import AccountContext
|
||||||
|
import TelegramUIPreferences
|
||||||
|
import TelegramPresentationData
|
||||||
|
|
||||||
extension AVPlayer {
|
extension AVPlayer {
|
||||||
func fadeVolume(from: Float, to: Float, duration: Float, completion: (() -> Void)? = nil) -> SwiftSignalKit.Timer? {
|
func fadeVolume(from: Float, to: Float, duration: Float, completion: (() -> Void)? = nil) -> SwiftSignalKit.Timer? {
|
||||||
@@ -133,39 +135,103 @@ func getTextureImage(device: MTLDevice, texture: MTLTexture, mirror: Bool = fals
|
|||||||
}
|
}
|
||||||
|
|
||||||
public func getChatWallpaperImage(context: AccountContext, messageId: EngineMessage.Id) -> Signal<(CGSize, UIImage?, UIImage?), NoError> {
|
public func getChatWallpaperImage(context: AccountContext, messageId: EngineMessage.Id) -> Signal<(CGSize, UIImage?, UIImage?), NoError> {
|
||||||
return context.account.postbox.transaction { transaction -> TelegramWallpaper? in
|
let themeSettings = context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.presentationThemeSettings])
|
||||||
|
|> map { sharedData -> PresentationThemeSettings in
|
||||||
|
let themeSettings: PresentationThemeSettings
|
||||||
|
if let current = sharedData.entries[ApplicationSpecificSharedDataKeys.presentationThemeSettings]?.get(PresentationThemeSettings.self) {
|
||||||
|
themeSettings = current
|
||||||
|
} else {
|
||||||
|
themeSettings = PresentationThemeSettings.defaultSettings
|
||||||
|
}
|
||||||
|
return themeSettings
|
||||||
|
}
|
||||||
|
|
||||||
|
let peerWallpaper = context.account.postbox.transaction { transaction -> TelegramWallpaper? in
|
||||||
return (transaction.getPeerCachedData(peerId: messageId.peerId) as? CachedChannelData)?.wallpaper
|
return (transaction.getPeerCachedData(peerId: messageId.peerId) as? CachedChannelData)?.wallpaper
|
||||||
}
|
}
|
||||||
|> mapToSignal { wallpaper -> Signal<(TelegramWallpaper?, TelegramWallpaper?), NoError> in
|
|
||||||
if let wallpaper, case let .emoticon(emoticon) = wallpaper {
|
return combineLatest(themeSettings, peerWallpaper)
|
||||||
return context.engine.themes.getChatThemes(accountManager: context.sharedContext.accountManager)
|
|> mapToSignal { themeSettings, peerWallpaper -> Signal<(TelegramWallpaper?, TelegramWallpaper?), NoError> in
|
||||||
|> map { themes -> (TelegramWallpaper?, TelegramWallpaper?) in
|
var currentColors = themeSettings.themeSpecificAccentColors[themeSettings.theme.index]
|
||||||
if let theme = themes.first(where: { $0.emoticon?.strippedEmoji == emoticon.strippedEmoji }) {
|
if let colors = currentColors, colors.baseColor == .theme {
|
||||||
if let dayMatch = theme.settings?.first(where: { $0.baseTheme == .classic || $0.baseTheme == .day }) {
|
currentColors = nil
|
||||||
if let dayWallpaper = dayMatch.wallpaper {
|
}
|
||||||
var nightWallpaper: TelegramWallpaper?
|
|
||||||
if let nightMatch = theme.settings?.first(where: { $0.baseTheme == .night || $0.baseTheme == .tinted }) {
|
let themeSpecificWallpaper = (themeSettings.themeSpecificChatWallpapers[coloredThemeIndex(reference: themeSettings.theme, accentColor: currentColors)] ?? themeSettings.themeSpecificChatWallpapers[themeSettings.theme.index])
|
||||||
nightWallpaper = nightMatch.wallpaper
|
|
||||||
|
let dayWallpaper: TelegramWallpaper
|
||||||
|
if let themeSpecificWallpaper = themeSpecificWallpaper {
|
||||||
|
dayWallpaper = themeSpecificWallpaper
|
||||||
|
} else {
|
||||||
|
let theme = makePresentationTheme(mediaBox: context.sharedContext.accountManager.mediaBox, themeReference: themeSettings.theme, accentColor: currentColors?.color, bubbleColors: currentColors?.customBubbleColors ?? [], wallpaper: currentColors?.wallpaper, baseColor: currentColors?.baseColor, preview: true) ?? defaultPresentationTheme
|
||||||
|
dayWallpaper = theme.chat.defaultWallpaper
|
||||||
|
}
|
||||||
|
|
||||||
|
var nightWallpaper: TelegramWallpaper?
|
||||||
|
|
||||||
|
let automaticTheme = themeSettings.automaticThemeSwitchSetting.theme
|
||||||
|
let effectiveColors = themeSettings.themeSpecificAccentColors[automaticTheme.index]
|
||||||
|
let nightThemeSpecificWallpaper = (themeSettings.themeSpecificChatWallpapers[coloredThemeIndex(reference: automaticTheme, accentColor: effectiveColors)] ?? themeSettings.themeSpecificChatWallpapers[automaticTheme.index])
|
||||||
|
|
||||||
|
var preferredBaseTheme: TelegramBaseTheme?
|
||||||
|
if let baseTheme = themeSettings.themePreferredBaseTheme[automaticTheme.index], [.night, .tinted].contains(baseTheme) {
|
||||||
|
preferredBaseTheme = baseTheme
|
||||||
|
} else {
|
||||||
|
preferredBaseTheme = .night
|
||||||
|
}
|
||||||
|
|
||||||
|
let darkTheme = makePresentationTheme(mediaBox: context.sharedContext.accountManager.mediaBox, themeReference: automaticTheme, baseTheme: preferredBaseTheme, accentColor: effectiveColors?.color, bubbleColors: effectiveColors?.customBubbleColors ?? [], wallpaper: effectiveColors?.wallpaper, baseColor: effectiveColors?.baseColor, serviceBackgroundColor: defaultServiceBackgroundColor) ?? defaultPresentationTheme
|
||||||
|
|
||||||
|
if let nightThemeSpecificWallpaper = nightThemeSpecificWallpaper {
|
||||||
|
nightWallpaper = nightThemeSpecificWallpaper
|
||||||
|
} else {
|
||||||
|
switch dayWallpaper {
|
||||||
|
case .builtin, .color, .gradient:
|
||||||
|
nightWallpaper = darkTheme.chat.defaultWallpaper
|
||||||
|
case .file:
|
||||||
|
if dayWallpaper.isPattern {
|
||||||
|
nightWallpaper = darkTheme.chat.defaultWallpaper
|
||||||
|
} else {
|
||||||
|
nightWallpaper = nil
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
nightWallpaper = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if let peerWallpaper {
|
||||||
|
if case let .emoticon(emoticon) = peerWallpaper {
|
||||||
|
return context.engine.themes.getChatThemes(accountManager: context.sharedContext.accountManager)
|
||||||
|
|> map { themes -> (TelegramWallpaper?, TelegramWallpaper?) in
|
||||||
|
if let theme = themes.first(where: { $0.emoticon?.strippedEmoji == emoticon.strippedEmoji }) {
|
||||||
|
if let dayMatch = theme.settings?.first(where: { $0.baseTheme == .classic || $0.baseTheme == .day }) {
|
||||||
|
if let peerDayWallpaper = dayMatch.wallpaper {
|
||||||
|
var peerNightWallpaper: TelegramWallpaper?
|
||||||
|
if let nightMatch = theme.settings?.first(where: { $0.baseTheme == .night || $0.baseTheme == .tinted }) {
|
||||||
|
peerNightWallpaper = nightMatch.wallpaper
|
||||||
|
}
|
||||||
|
return (peerDayWallpaper, peerNightWallpaper)
|
||||||
|
} else {
|
||||||
|
return (dayWallpaper, nightWallpaper)
|
||||||
}
|
}
|
||||||
return (dayWallpaper, nightWallpaper)
|
|
||||||
} else {
|
} else {
|
||||||
return (nil, nil)
|
return (dayWallpaper, nightWallpaper)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return (nil, nil)
|
return (dayWallpaper, nightWallpaper)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return (nil, nil)
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return .single((peerWallpaper, nil))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return .single((wallpaper, nil))
|
return .single((dayWallpaper, nightWallpaper))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|> mapToSignal { customDayWallpaper, customNightWallpaper -> Signal<(CGSize, UIImage?, UIImage?), NoError> in
|
|> mapToSignal { dayWallpaper, nightWallpaper -> Signal<(CGSize, UIImage?, UIImage?), NoError> in
|
||||||
return Signal { subscriber in
|
return Signal { subscriber in
|
||||||
Queue.mainQueue().async {
|
Queue.mainQueue().async {
|
||||||
let wallpaperRenderer = DrawingWallpaperRenderer(context: context, customDayWallpaper: customDayWallpaper, customNightWallpaper: customNightWallpaper)
|
let wallpaperRenderer = DrawingWallpaperRenderer(context: context, dayWallpaper: dayWallpaper, nightWallpaper: nightWallpaper)
|
||||||
wallpaperRenderer.render { size, image, darkImage, mediaRect in
|
wallpaperRenderer.render { size, image, darkImage, mediaRect in
|
||||||
subscriber.putNext((size, image, darkImage))
|
subscriber.putNext((size, image, darkImage))
|
||||||
subscriber.putCompletion()
|
subscriber.putCompletion()
|
||||||
|
|||||||
@@ -2372,6 +2372,9 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
|
|||||||
if let initialVideoPosition = controller.initialVideoPosition {
|
if let initialVideoPosition = controller.initialVideoPosition {
|
||||||
mediaEditor.seek(initialVideoPosition, andPlay: true)
|
mediaEditor.seek(initialVideoPosition, andPlay: true)
|
||||||
}
|
}
|
||||||
|
if case .message = subject, self.context.sharedContext.currentPresentationData.with({$0}).autoNightModeTriggered {
|
||||||
|
mediaEditor.setNightTheme(true)
|
||||||
|
}
|
||||||
mediaEditor.attachPreviewView(self.previewView)
|
mediaEditor.attachPreviewView(self.previewView)
|
||||||
mediaEditor.valuesUpdated = { [weak self] values in
|
mediaEditor.valuesUpdated = { [weak self] values in
|
||||||
if let self, let controller = self.controller, values.gradientColors != nil, controller.previousSavedValues != values {
|
if let self, let controller = self.controller, values.gradientColors != nil, controller.previousSavedValues != values {
|
||||||
@@ -2468,7 +2471,11 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
|
|||||||
let fraction = max(size.width, size.height) / 353.0
|
let fraction = max(size.width, size.height) / 353.0
|
||||||
messageEntity.scale = min(6.0, 3.3 * fraction)
|
messageEntity.scale = min(6.0, 3.3 * fraction)
|
||||||
|
|
||||||
self.entitiesView.add(messageEntity, announce: false)
|
if let entityView = self.entitiesView.add(messageEntity, announce: false) as? DrawingStickerEntityView {
|
||||||
|
if isNightTheme {
|
||||||
|
entityView.isNightTheme = true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.readyValue.set(.single(true))
|
self.readyValue.set(.single(true))
|
||||||
|
|||||||
Reference in New Issue
Block a user