Add outgoing accent color customization

This commit is contained in:
Ilya Laktyushin
2021-09-04 21:45:26 +03:00
parent cb93fdbc08
commit 767a30038b
10 changed files with 127 additions and 63 deletions

View File

@@ -21,6 +21,9 @@ public final class TelegramThemeSettings: PostboxCoding, Equatable {
if lhs.accentColor != rhs.accentColor {
return false
}
if lhs.outgoingAccentColor != rhs.outgoingAccentColor {
return false
}
if lhs.messageColors != rhs.messageColors {
return false
}
@@ -35,13 +38,15 @@ public final class TelegramThemeSettings: PostboxCoding, Equatable {
public let baseTheme: TelegramBaseTheme
public let accentColor: UInt32
public let outgoingAccentColor: UInt32?
public let messageColors: [UInt32]
public let animateMessageColors: Bool
public let wallpaper: TelegramWallpaper?
public init(baseTheme: TelegramBaseTheme, accentColor: UInt32, messageColors: [UInt32], animateMessageColors: Bool, wallpaper: TelegramWallpaper?) {
public init(baseTheme: TelegramBaseTheme, accentColor: UInt32, outgoingAccentColor: UInt32?, messageColors: [UInt32], animateMessageColors: Bool, wallpaper: TelegramWallpaper?) {
self.baseTheme = baseTheme
self.accentColor = accentColor
self.outgoingAccentColor = outgoingAccentColor
self.messageColors = messageColors
self.animateMessageColors = animateMessageColors
self.wallpaper = wallpaper
@@ -50,6 +55,7 @@ public final class TelegramThemeSettings: PostboxCoding, Equatable {
public init(decoder: PostboxDecoder) {
self.baseTheme = TelegramBaseTheme(rawValue: decoder.decodeInt32ForKey("baseTheme", orElse: 0)) ?? .classic
self.accentColor = UInt32(bitPattern: decoder.decodeInt32ForKey("accent", orElse: 0))
self.outgoingAccentColor = decoder.decodeOptionalInt32ForKey("outgoingAccent").flatMap { UInt32(bitPattern: $0) }
let messageColors = decoder.decodeInt32ArrayForKey("messageColors")
if !messageColors.isEmpty {
self.messageColors = messageColors.map(UInt32.init(bitPattern:))
@@ -67,6 +73,11 @@ public final class TelegramThemeSettings: PostboxCoding, Equatable {
public func encode(_ encoder: PostboxEncoder) {
encoder.encodeInt32(self.baseTheme.rawValue, forKey: "baseTheme")
encoder.encodeInt32(Int32(bitPattern: self.accentColor), forKey: "accent")
if let outgoingAccentColor = self.outgoingAccentColor {
encoder.encodeInt32(Int32(bitPattern: outgoingAccentColor), forKey: "outgoingAccent")
} else {
encoder.encodeNil(forKey: "outgoingAccent")
}
encoder.encodeInt32Array(self.messageColors.map(Int32.init(bitPattern:)), forKey: "messageColors")
encoder.encodeInt32(self.animateMessageColors ? 1 : 0, forKey: "animateMessageColors")
if let wallpaper = self.wallpaper {