mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Various Fixes
This commit is contained in:
parent
8c5e0ae260
commit
22b5379d9c
@ -120,6 +120,7 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi
|
||||
private let reactionSelected: (ReactionContextItem.Reaction) -> Void
|
||||
private let beganAnimatingOut: () -> Void
|
||||
private let attemptTransitionControllerIntoNavigation: () -> Void
|
||||
fileprivate var dismissedForCancel: (() -> Void)?
|
||||
private let getController: () -> ContextControllerProtocol?
|
||||
private weak var gesture: ContextGesture?
|
||||
private var displayTextSelectionTip: Bool
|
||||
@ -478,6 +479,7 @@ private final class ContextControllerNode: ViewControllerTracingNode, UIScrollVi
|
||||
}
|
||||
|
||||
@objc private func dimNodeTapped() {
|
||||
self.dismissedForCancel?()
|
||||
self.beginDismiss(.default)
|
||||
}
|
||||
|
||||
@ -1817,6 +1819,11 @@ public final class ContextController: ViewController, StandalonePresentableContr
|
||||
|
||||
public var reactionSelected: ((ReactionContextItem.Reaction) -> Void)?
|
||||
public var dismissed: (() -> Void)?
|
||||
public var dismissedForCancel: (() -> Void)? {
|
||||
didSet {
|
||||
self.controllerNode.dismissedForCancel = self.dismissedForCancel
|
||||
}
|
||||
}
|
||||
|
||||
public var useComplexItemsTransitionAnimation = false
|
||||
public var immediateItemsTransitionAnimation = false
|
||||
@ -1872,7 +1879,7 @@ public final class ContextController: ViewController, StandalonePresentableContr
|
||||
override public func loadDisplayNode() {
|
||||
self.displayNode = ContextControllerNode(account: self.account, controller: self, presentationData: self.presentationData, source: self.source, items: self.items, reactionItems: self.reactionItems, beginDismiss: { [weak self] result in
|
||||
self?.dismiss(result: result, completion: nil)
|
||||
}, recognizer: self.recognizer, gesture: self.gesture, reactionSelected: { [weak self] value in
|
||||
}, recognizer: self.recognizer, gesture: self.gesture, reactionSelected: { [weak self] value in
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
@ -1893,7 +1900,7 @@ public final class ContextController: ViewController, StandalonePresentableContr
|
||||
break
|
||||
}
|
||||
}, displayTextSelectionTip: self.displayTextSelectionTip)
|
||||
|
||||
self.controllerNode.dismissedForCancel = self.dismissedForCancel
|
||||
self.displayNodeDidLoad()
|
||||
|
||||
self._ready.set(combineLatest(queue: .mainQueue(), self.controllerNode.itemsReady.get(), self.controllerNode.contentReady.get())
|
||||
|
@ -52,24 +52,110 @@ public func customizeDefaultDayTheme(theme: PresentationTheme, specialMode: Bool
|
||||
var suggestedWallpaper: TelegramWallpaper?
|
||||
|
||||
var bubbleColors = bubbleColors
|
||||
if bubbleColors.isEmpty, editing {
|
||||
if day {
|
||||
let accentColor = accentColor ?? defaultDayAccentColor
|
||||
bubbleColors = [accentColor.withMultiplied(hue: 0.966, saturation: 0.61, brightness: 0.98).rgb, accentColor.rgb]
|
||||
} else {
|
||||
if let accentColor = accentColor, !accentColor.alpha.isZero {
|
||||
let hsb = accentColor.hsb
|
||||
bubbleColors = [UIColor(hue: hsb.0, saturation: (hsb.1 > 0.0 && hsb.2 > 0.0) ? 0.14 : 0.0, brightness: 0.79 + hsb.2 * 0.21, alpha: 1.0).rgb]
|
||||
if accentColor.lightness > 0.705 {
|
||||
outgoingAccent = UIColor(hue: hsb.0, saturation: min(1.0, hsb.1 * 1.1), brightness: min(hsb.2, 0.6), alpha: 1.0)
|
||||
} else {
|
||||
outgoingAccent = accentColor
|
||||
if specialMode, bubbleColors.count < 3, let color = bubbleColors.first.flatMap({ UIColor(rgb: $0) }) {
|
||||
let colorHSB = color.hsb
|
||||
if colorHSB.b > 0.9 {
|
||||
let bubbleColor = color.withMultiplied(hue: 0.93, saturation: 1.0, brightness: 1.0)
|
||||
bubbleColors = [bubbleColor.rgb]
|
||||
|
||||
let colorPairs: [(UInt32, UInt32)] = [
|
||||
(0xe8f9d7, 0x6cd516),
|
||||
(0xe7faff, 0x43b6f9),
|
||||
(0xe3f7f5, 0x4ccbb8),
|
||||
(0xfff3cf, 0xe8b816),
|
||||
(0xfffac9, 0xe2c714),
|
||||
(0xc5a61e, 0xd6b534)
|
||||
]
|
||||
|
||||
func generateAccentColor(color: UIColor) -> UIColor {
|
||||
var nearest: (color: (UInt32, UInt32), distance: Int32)?
|
||||
for (sample, accentSample) in colorPairs {
|
||||
let distance = color.distance(to: UIColor(rgb: sample))
|
||||
if let currentNearest = nearest {
|
||||
if distance < currentNearest.distance {
|
||||
nearest = ((sample, accentSample), distance)
|
||||
}
|
||||
} else {
|
||||
nearest = ((sample, accentSample), distance)
|
||||
}
|
||||
}
|
||||
|
||||
if let colors = nearest?.color {
|
||||
let colorHsb = color.hsb
|
||||
let similarColorHsb = UIColor(rgb: colors.0).hsb
|
||||
let complementingColorHsb = UIColor(rgb: colors.1).hsb
|
||||
|
||||
let correction = (similarColorHsb.0 > 0.0 ? colorHsb.0 / similarColorHsb.0 : 1.0, similarColorHsb.1 > 0.0 ? colorHsb.1 / similarColorHsb.1 : 1.0, similarColorHsb.2 > 0.0 ? colorHsb.2 / similarColorHsb.2 : 1.0)
|
||||
let correctedComplementingColor = UIColor(hue: min(1.0, complementingColorHsb.0 * correction.0), saturation: min(1.0, complementingColorHsb.1 * correction.1), brightness: min(1.0, complementingColorHsb.2 * correction.2), alpha: 1.0)
|
||||
return correctedComplementingColor
|
||||
} else {
|
||||
return color
|
||||
}
|
||||
}
|
||||
|
||||
outgoingAccent = generateAccentColor(color: color)
|
||||
// color.withMultiplied(hue: 1.01, saturation: 7.8, brightness: 0.9)
|
||||
} else {
|
||||
let bubbleColor = color.withMultiplied(hue: 1.014, saturation: 0.12, brightness: 1.29)
|
||||
bubbleColors = [bubbleColor.rgb]
|
||||
|
||||
outgoingAccent = color
|
||||
}
|
||||
|
||||
suggestedWallpaper = .gradient(TelegramWallpaper.Gradient(id: nil, colors: defaultBuiltinWallpaperGradientColors.map(\.rgb), settings: WallpaperSettings()))
|
||||
// float[] colorHsv = getTempHsv(5);
|
||||
// Color.colorToHSV(color, colorHsv);
|
||||
//
|
||||
// final float diffH = Math.min(Math.abs(colorHsv[0] - baseHsv[0]), Math.abs(colorHsv[0] - baseHsv[0] - 360f));
|
||||
// if (diffH > 30f) {
|
||||
// return color;
|
||||
// }
|
||||
//
|
||||
// float dist = Math.min(1.5f * colorHsv[1] / baseHsv[1], 1f);
|
||||
//
|
||||
// colorHsv[0] = colorHsv[0] + accentHsv[0] - baseHsv[0];
|
||||
// colorHsv[1] = colorHsv[1] * accentHsv[1] / baseHsv[1];
|
||||
// colorHsv[2] = colorHsv[2] * (1f - dist + dist * accentHsv[2] / baseHsv[2]);
|
||||
//
|
||||
// int newColor = Color.HSVToColor(Color.alpha(color), colorHsv);
|
||||
//
|
||||
// float origBrightness = AndroidUtilities.computePerceivedBrightness(color);
|
||||
// float newBrightness = AndroidUtilities.computePerceivedBrightness(newColor);
|
||||
//
|
||||
// // We need to keep colors lighter in dark themes and darker in light themes
|
||||
// boolean needRevertBrightness = isDarkTheme ? origBrightness > newBrightness : origBrightness < newBrightness;
|
||||
//
|
||||
// if (needRevertBrightness) {
|
||||
// float amountOfNew = 0.6f;
|
||||
// float fallbackAmount = (1f - amountOfNew) * origBrightness / newBrightness + amountOfNew;
|
||||
// newColor = changeBrightness(newColor, fallbackAmount);
|
||||
// }
|
||||
//
|
||||
// return newColor;
|
||||
|
||||
// outgoingAccent = color.withMultiplied(hue: 1.035, saturation: 4.294, brightness: 1.289)
|
||||
//
|
||||
// let bubbleColor = color.withMultiplied(hue: 1.014, saturation: 0.101, brightness: 1.289)
|
||||
// bubbleColors = [bubbleColor.rgb]
|
||||
} else {
|
||||
if bubbleColors.isEmpty, editing {
|
||||
if day {
|
||||
let accentColor = accentColor ?? defaultDayAccentColor
|
||||
bubbleColors = [accentColor.withMultiplied(hue: 0.966, saturation: 0.61, brightness: 0.98).rgb, accentColor.rgb]
|
||||
} else {
|
||||
bubbleColors = [UIColor(rgb: 0xe1ffc7).rgb]
|
||||
suggestedWallpaper = .gradient(TelegramWallpaper.Gradient(id: nil, colors: defaultBuiltinWallpaperGradientColors.map(\.rgb), settings: WallpaperSettings()))
|
||||
if let accentColor = accentColor, !accentColor.alpha.isZero {
|
||||
let hsb = accentColor.hsb
|
||||
bubbleColors = [UIColor(hue: hsb.0, saturation: (hsb.1 > 0.0 && hsb.2 > 0.0) ? 0.14 : 0.0, brightness: 0.79 + hsb.2 * 0.21, alpha: 1.0).rgb]
|
||||
if accentColor.lightness > 0.705 {
|
||||
outgoingAccent = UIColor(hue: hsb.0, saturation: min(1.0, hsb.1 * 1.1), brightness: min(hsb.2, 0.6), alpha: 1.0)
|
||||
} else {
|
||||
outgoingAccent = accentColor
|
||||
}
|
||||
|
||||
suggestedWallpaper = .gradient(TelegramWallpaper.Gradient(id: nil, colors: defaultBuiltinWallpaperGradientColors.map(\.rgb), settings: WallpaperSettings()))
|
||||
} else {
|
||||
bubbleColors = [UIColor(rgb: 0xe1ffc7).rgb]
|
||||
suggestedWallpaper = .gradient(TelegramWallpaper.Gradient(id: nil, colors: defaultBuiltinWallpaperGradientColors.map(\.rgb), settings: WallpaperSettings()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -168,7 +254,7 @@ public func customizeDefaultDayTheme(theme: PresentationTheme, specialMode: Bool
|
||||
outgoingLinkTextColor = outgoingAccent
|
||||
outgoingScamColor = UIColor(rgb: 0xff3b30)
|
||||
outgoingControlColor = outgoingAccent
|
||||
outgoingInactiveControlColor = outgoingAccent //1111
|
||||
outgoingInactiveControlColor = outgoingAccent
|
||||
outgoingFileTitleColor = outgoingAccent
|
||||
outgoingPollsProgressColor = accentColor
|
||||
outgoingSelectionColor = outgoingAccent.withMultiplied(hue: 1.0, saturation: 1.292, brightness: 0.871)
|
||||
|
@ -38,12 +38,12 @@ public func makePresentationTheme(settings: TelegramThemeSettings, specialMode:
|
||||
return customizePresentationTheme(defaultTheme, specialMode: specialMode, editing: true, title: title, accentColor: UIColor(argb: settings.accentColor), backgroundColors: [], bubbleColors: settings.messageColors, animateBubbleColors: settings.animateMessageColors, wallpaper: settings.wallpaper)
|
||||
}
|
||||
|
||||
public func makePresentationTheme(mediaBox: MediaBox, themeReference: PresentationThemeReference, extendingThemeReference: PresentationThemeReference? = nil, accentColor: UIColor? = nil, backgroundColors: [UInt32] = [], bubbleColors: [UInt32] = [], animateBubbleColors: Bool? = nil, wallpaper: TelegramWallpaper? = nil, baseColor: PresentationThemeBaseColor? = nil, serviceBackgroundColor: UIColor? = nil, preview: Bool = false) -> PresentationTheme? {
|
||||
public func makePresentationTheme(mediaBox: MediaBox, themeReference: PresentationThemeReference, extendingThemeReference: PresentationThemeReference? = nil, accentColor: UIColor? = nil, backgroundColors: [UInt32] = [], bubbleColors: [UInt32] = [], animateBubbleColors: Bool? = nil, wallpaper: TelegramWallpaper? = nil, baseColor: PresentationThemeBaseColor? = nil, serviceBackgroundColor: UIColor? = nil, specialMode: Bool = false, preview: Bool = false) -> PresentationTheme? {
|
||||
let theme: PresentationTheme
|
||||
switch themeReference {
|
||||
case let .builtin(reference):
|
||||
let defaultTheme = makeDefaultPresentationTheme(reference: reference, extendingThemeReference: extendingThemeReference, serviceBackgroundColor: serviceBackgroundColor, preview: preview)
|
||||
theme = customizePresentationTheme(defaultTheme, editing: true, accentColor: accentColor, backgroundColors: backgroundColors, bubbleColors: bubbleColors, animateBubbleColors: animateBubbleColors, wallpaper: wallpaper, baseColor: baseColor)
|
||||
theme = customizePresentationTheme(defaultTheme, specialMode: specialMode, editing: true, accentColor: accentColor, backgroundColors: backgroundColors, bubbleColors: bubbleColors, animateBubbleColors: animateBubbleColors, wallpaper: wallpaper, baseColor: baseColor)
|
||||
case let .local(info):
|
||||
if let path = mediaBox.completedResourcePath(info.resource), let data = try? Data(contentsOf: URL(fileURLWithPath: path), options: .mappedRead), let loadedTheme = makePresentationTheme(data: data, themeReference: themeReference, resolvedWallpaper: info.resolvedWallpaper) {
|
||||
theme = customizePresentationTheme(loadedTheme, editing: false, accentColor: accentColor, backgroundColors: backgroundColors, bubbleColors: bubbleColors, animateBubbleColors: animateBubbleColors, wallpaper: wallpaper)
|
||||
|
@ -5616,6 +5616,13 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
|
||||
}
|
||||
|
||||
let contextController = ContextController(account: strongSelf.context.account, presentationData: strongSelf.presentationData, source: .controller(ContextControllerContentSourceImpl(controller: chatController, sourceNode: sourceNode, passthroughTouches: true)), items: items, reactionItems: [])
|
||||
contextController.dismissedForCancel = { [weak self, weak chatController] in
|
||||
if let selectedMessageIds = (chatController as? ChatControllerImpl)?.selectedMessageIds {
|
||||
var forwardMessageIds = strongSelf.presentationInterfaceState.interfaceState.forwardMessageIds ?? []
|
||||
forwardMessageIds = forwardMessageIds.filter { selectedMessageIds.contains($0) }
|
||||
strongSelf.updateChatPresentationInterfaceState(interactive: false, { $0.updatedInterfaceState({ $0.withUpdatedForwardMessageIds(forwardMessageIds) }) })
|
||||
}
|
||||
}
|
||||
contextController.immediateItemsTransitionAnimation = true
|
||||
strongSelf.presentInGlobalOverlay(contextController)
|
||||
}
|
||||
|
@ -272,28 +272,43 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate {
|
||||
if attribute is ReplyMessageAttribute {
|
||||
return false
|
||||
}
|
||||
if attribute is ReplyMarkupMessageAttribute {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
var messageText = message.text
|
||||
var forwardInfo = message.forwardInfo
|
||||
if forwardInfo == nil {
|
||||
forwardInfo = MessageForwardInfo(author: message.author, source: nil, sourceMessageId: nil, date: 0, authorSignature: nil, psaType: nil, flags: [])
|
||||
}
|
||||
var messageMedia = message.media
|
||||
var hasDice = false
|
||||
if options.hideNames {
|
||||
forwardInfo = nil
|
||||
}
|
||||
|
||||
if options.hideNames && options.hideCaptions {
|
||||
for media in message.media {
|
||||
if media is TelegramMediaImage || media is TelegramMediaFile {
|
||||
messageText = ""
|
||||
break
|
||||
if options.hideCaptions {
|
||||
if media is TelegramMediaImage || media is TelegramMediaFile {
|
||||
messageText = ""
|
||||
break
|
||||
}
|
||||
}
|
||||
if let poll = media as? TelegramMediaPoll {
|
||||
var updatedMedia = message.media.filter { !($0 is TelegramMediaPoll) }
|
||||
updatedMedia.append(TelegramMediaPoll(pollId: poll.pollId, publicity: poll.publicity, kind: poll.kind, text: poll.text, options: poll.options, correctAnswers: poll.correctAnswers, results: TelegramMediaPollResults(voters: nil, totalVoters: nil, recentVoters: [], solution: nil), isClosed: false, deadlineTimeout: nil))
|
||||
messageMedia = updatedMedia
|
||||
}
|
||||
if let _ = media as? TelegramMediaDice {
|
||||
hasDice = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return message.withUpdatedFlags(flags).withUpdatedText(messageText).withUpdatedTimestamp(scheduleWhenOnlineTimestamp).withUpdatedAttributes(attributes).withUpdatedAuthor(accountPeer).withUpdatedForwardInfo(forwardInfo)
|
||||
var forwardInfo = message.forwardInfo
|
||||
if forwardInfo == nil {
|
||||
forwardInfo = MessageForwardInfo(author: message.author, source: nil, sourceMessageId: nil, date: 0, authorSignature: nil, psaType: nil, flags: [])
|
||||
}
|
||||
if options.hideNames && !hasDice {
|
||||
forwardInfo = nil
|
||||
}
|
||||
|
||||
return message.withUpdatedFlags(flags).withUpdatedText(messageText).withUpdatedMedia(messageMedia).withUpdatedTimestamp(scheduleWhenOnlineTimestamp).withUpdatedAttributes(attributes).withUpdatedAuthor(accountPeer).withUpdatedForwardInfo(forwardInfo)
|
||||
}
|
||||
|
||||
return (messages, Int32(messages.count), false)
|
||||
|
@ -1310,7 +1310,7 @@ public func themeIconImage(account: Account, accountManager: AccountManager<Tele
|
||||
themeSignal = .single(makeDefaultPresentationTheme(reference: theme, serviceBackgroundColor: nil))
|
||||
} else if case let .cloud(theme) = theme, let settings = theme.theme.settings {
|
||||
themeSignal = Signal { subscriber in
|
||||
let theme = makePresentationTheme(mediaBox: accountManager.mediaBox, themeReference: .builtin(PresentationBuiltinThemeReference(baseTheme: settings.baseTheme)), accentColor: UIColor(argb: settings.accentColor), backgroundColors: [], bubbleColors: settings.messageColors, wallpaper: settings.wallpaper, serviceBackgroundColor: nil, preview: false)
|
||||
let theme = makePresentationTheme(mediaBox: accountManager.mediaBox, themeReference: .builtin(PresentationBuiltinThemeReference(baseTheme: settings.baseTheme)), accentColor: UIColor(argb: settings.accentColor), backgroundColors: [], bubbleColors: settings.messageColors, wallpaper: settings.wallpaper, serviceBackgroundColor: nil, specialMode: emoticon, preview: false)
|
||||
subscriber.putNext(theme)
|
||||
subscriber.putCompletion()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user