mirror of
https://github.com/TelegramMessenger/Telegram-iOS.git
synced 2026-07-06 03:33:41 +02:00
Update text styles data
This commit is contained in:
parent
d0fce97c93
commit
784b43934a
5 changed files with 25 additions and 52 deletions
|
|
@ -415,17 +415,17 @@ public enum TelegramComposeAIMessageMode {
|
|||
}
|
||||
|
||||
public struct Style: Equatable {
|
||||
public let name: String
|
||||
public let emoji: String
|
||||
public let type: String
|
||||
public let title: String
|
||||
public let emojiFileId: Int64?
|
||||
|
||||
public var id: StyleId {
|
||||
return .style(self.name)
|
||||
return .style(self.type)
|
||||
}
|
||||
|
||||
public init(name: String, emoji: String, emojiFileId: Int64?) {
|
||||
self.name = name
|
||||
self.emoji = emoji
|
||||
public init(type: String, title: String, emojiFileId: Int64?) {
|
||||
self.type = type
|
||||
self.title = title
|
||||
self.emojiFileId = emojiFileId
|
||||
}
|
||||
}
|
||||
|
|
@ -459,9 +459,9 @@ func _internal_composeAIMessageStyles(account: Account) -> Signal<[TelegramCompo
|
|||
var result: [TelegramComposeAIMessageMode.Style] = []
|
||||
if let data = currentAppConfiguration(transaction: transaction).data, let value = data["ai_compose_styles"] as? [[String]] {
|
||||
for item in value {
|
||||
if item.count >= 2 {
|
||||
let emojiFileId: Int64? = item.count > 2 ? Int64(item[2]) : nil
|
||||
result.append(TelegramComposeAIMessageMode.Style(name: item[1], emoji: item[0], emojiFileId: emojiFileId))
|
||||
if item.count >= 3 {
|
||||
let emojiFileId: Int64? = Int64(item[1])
|
||||
result.append(TelegramComposeAIMessageMode.Style(type: item[0], title: item[2], emojiFileId: emojiFileId))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -475,10 +475,10 @@ final class TextProcessingLanguageSelectionComponent: Component {
|
|||
var selectedStyleItemFrame: CGRect?
|
||||
let stylesSpacing: CGFloat = 8.0
|
||||
if let displayStyles = component.displayStyles {
|
||||
var styleData: [(id: TelegramComposeAIMessageMode.StyleId, icon: String, iconFileId: Int64?, iconFile: TelegramMediaFile?, title: String)] = []
|
||||
styleData.append((.neutral, "🏳️", nil, nil, localizedStyleName(strings: component.strings, styleId: .neutral)))
|
||||
var styleData: [(id: TelegramComposeAIMessageMode.StyleId, iconFileId: Int64?, iconFile: TelegramMediaFile?, title: String)] = []
|
||||
styleData.append((.neutral, nil, nil, component.strings.TextProcessingStyle_Neutral))
|
||||
for item in displayStyles {
|
||||
styleData.append((item.id, item.emoji, item.emojiFileId, item.emojiFile, localizedStyleName(strings: component.strings, styleId: item.id)))
|
||||
styleData.append((item.id, item.emojiFileId, item.emojiFile, item.title))
|
||||
}
|
||||
|
||||
let stylesItemSize = CGSize(width: 82.0, height: 60.0)
|
||||
|
|
@ -500,7 +500,6 @@ final class TextProcessingLanguageSelectionComponent: Component {
|
|||
component: AnyComponent(StyleItemComponent(
|
||||
context: component.context,
|
||||
theme: component.theme,
|
||||
icon: item.icon,
|
||||
iconFileId: item.iconFileId,
|
||||
iconFile: item.iconFile,
|
||||
title: item.title,
|
||||
|
|
@ -854,7 +853,6 @@ private final class LanguageItemComponent: Component {
|
|||
private final class StyleItemComponent: Component {
|
||||
let context: AccountContext
|
||||
let theme: PresentationTheme
|
||||
let icon: String
|
||||
let iconFileId: Int64?
|
||||
let iconFile: TelegramMediaFile?
|
||||
let title: String
|
||||
|
|
@ -863,7 +861,6 @@ private final class StyleItemComponent: Component {
|
|||
init(
|
||||
context: AccountContext,
|
||||
theme: PresentationTheme,
|
||||
icon: String,
|
||||
iconFileId: Int64?,
|
||||
iconFile: TelegramMediaFile?,
|
||||
title: String,
|
||||
|
|
@ -871,7 +868,6 @@ private final class StyleItemComponent: Component {
|
|||
) {
|
||||
self.context = context
|
||||
self.theme = theme
|
||||
self.icon = icon
|
||||
self.iconFileId = iconFileId
|
||||
self.iconFile = iconFile
|
||||
self.title = title
|
||||
|
|
@ -882,9 +878,6 @@ private final class StyleItemComponent: Component {
|
|||
if lhs.theme !== rhs.theme {
|
||||
return false
|
||||
}
|
||||
if lhs.icon != rhs.icon {
|
||||
return false
|
||||
}
|
||||
if lhs.iconFileId != rhs.iconFileId {
|
||||
return false
|
||||
}
|
||||
|
|
@ -973,7 +966,7 @@ private final class StyleItemComponent: Component {
|
|||
))
|
||||
} else {
|
||||
iconComponent = AnyComponent(MultilineTextComponent(
|
||||
text: .plain(NSAttributedString(string: component.icon, font: Font.regular(25.0), textColor: .black))
|
||||
text: .plain(NSAttributedString(string: "❌", font: Font.regular(25.0), textColor: .black))
|
||||
))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1065,18 +1065,18 @@ public class TextProcessingScreen: ViewControllerComponentContainer {
|
|||
}
|
||||
|
||||
public struct Style: Equatable {
|
||||
public let name: String
|
||||
public let emoji: String
|
||||
public let type: String
|
||||
public let title: String
|
||||
public let emojiFileId: Int64?
|
||||
public let emojiFile: TelegramMediaFile?
|
||||
|
||||
public var id: TelegramComposeAIMessageMode.StyleId {
|
||||
return .style(self.name)
|
||||
return .style(self.type)
|
||||
}
|
||||
|
||||
public init(name: String, emoji: String, emojiFileId: Int64?, emojiFile: TelegramMediaFile?) {
|
||||
self.name = name
|
||||
self.emoji = emoji
|
||||
public init(type: String, title: String, emojiFileId: Int64?, emojiFile: TelegramMediaFile?) {
|
||||
self.type = type
|
||||
self.title = title
|
||||
self.emojiFileId = emojiFileId
|
||||
self.emojiFile = emojiFile
|
||||
}
|
||||
|
|
@ -1100,8 +1100,8 @@ public class TextProcessingScreen: ViewControllerComponentContainer {
|
|||
let resolvedEmojiFiles: [Int64: TelegramMediaFile] = await context.engine.stickers.resolveInlineStickersLocal(fileIds: Array(Set(rawStyles.compactMap({ $0.emojiFileId })))).get()
|
||||
for value in rawStyles {
|
||||
styles.append(Style(
|
||||
name: value.name,
|
||||
emoji: value.emoji,
|
||||
type: value.type,
|
||||
title: value.title,
|
||||
emojiFileId: value.emojiFileId,
|
||||
emojiFile: value.emojiFileId.flatMap { resolvedEmojiFiles[$0] }
|
||||
))
|
||||
|
|
|
|||
|
|
@ -8,19 +8,6 @@ import TelegramCore
|
|||
import EmojiStatusComponent
|
||||
import AccountContext
|
||||
|
||||
func localizedStyleName(strings: PresentationStrings, styleId: TelegramComposeAIMessageMode.StyleId) -> String {
|
||||
switch styleId {
|
||||
case .neutral:
|
||||
return strings.TextProcessingStyle_Neutral
|
||||
case let .style(name):
|
||||
if let value = strings.primaryComponent.dict["TextProcessingStyle.\(name)"] {
|
||||
return value
|
||||
} else {
|
||||
return name.capitalized
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final class TextProcessingStyleSelectionComponent: Component {
|
||||
let context: AccountContext
|
||||
let theme: PresentationTheme
|
||||
|
|
@ -160,10 +147,9 @@ final class TextProcessingStyleSelectionComponent: Component {
|
|||
component: AnyComponent(ItemComponent(
|
||||
context: component.context,
|
||||
theme: component.theme,
|
||||
icon: style.emoji,
|
||||
iconFileId: style.emojiFileId,
|
||||
iconFile: style.emojiFile,
|
||||
title: localizedStyleName(strings: component.strings, styleId: .style(style.name))
|
||||
title: style.title
|
||||
)),
|
||||
environment: {},
|
||||
containerSize: CGSize(width: maxItemWidth, height: availableSize.height)
|
||||
|
|
@ -272,7 +258,6 @@ final class TextProcessingStyleSelectionComponent: Component {
|
|||
private final class ItemComponent: Component {
|
||||
let context: AccountContext
|
||||
let theme: PresentationTheme
|
||||
let icon: String
|
||||
let iconFileId: Int64?
|
||||
let iconFile: TelegramMediaFile?
|
||||
let title: String
|
||||
|
|
@ -280,14 +265,12 @@ private final class ItemComponent: Component {
|
|||
init(
|
||||
context: AccountContext,
|
||||
theme: PresentationTheme,
|
||||
icon: String,
|
||||
iconFileId: Int64?,
|
||||
iconFile: TelegramMediaFile?,
|
||||
title: String
|
||||
) {
|
||||
self.context = context
|
||||
self.theme = theme
|
||||
self.icon = icon
|
||||
self.iconFileId = iconFileId
|
||||
self.iconFile = iconFile
|
||||
self.title = title
|
||||
|
|
@ -297,9 +280,6 @@ private final class ItemComponent: Component {
|
|||
if lhs.theme !== rhs.theme {
|
||||
return false
|
||||
}
|
||||
if lhs.icon != rhs.icon {
|
||||
return false
|
||||
}
|
||||
if lhs.iconFileId != rhs.iconFileId {
|
||||
return false
|
||||
}
|
||||
|
|
@ -377,7 +357,7 @@ private final class ItemComponent: Component {
|
|||
))
|
||||
} else {
|
||||
iconComponent = AnyComponent(MultilineTextComponent(
|
||||
text: .plain(NSAttributedString(string: component.icon, font: Font.regular(25.0), textColor: .black))
|
||||
text: .plain(NSAttributedString(string: "❌", font: Font.regular(25.0), textColor: .black))
|
||||
))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -311,8 +311,8 @@ final class TextProcessingTranslateContentComponent: Component {
|
|||
fromFormat = component.strings.TextProcessing_Translate_FromLanguage
|
||||
toFormat = component.strings.TextProcessing_Translate_ToLanguage
|
||||
toTitle = localizedLanguageName(strings: component.strings, language: component.externalState.result?.language ?? "", kind: .translateTo)
|
||||
if case .style = component.externalState.style {
|
||||
toTitle = component.strings.TextProcessing_Translate_LanguageStyle(toTitle, localizedStyleName(strings: component.strings, styleId: component.externalState.style)).string
|
||||
if case .style = component.externalState.style, let styleTitle = component.styles.first(where: { $0.id == component.externalState.style })?.title {
|
||||
toTitle = component.strings.TextProcessing_Translate_LanguageStyle(toTitle, styleTitle).string
|
||||
}
|
||||
case .stylize, .fix:
|
||||
fromFormat = component.strings.TextProcessing_OriginalBadge
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue