Import legacy accent color setting if any

This commit is contained in:
Ilya Laktyushin 2019-06-26 00:56:27 +02:00
parent 3ac2825b6c
commit fa32fa3e30
3 changed files with 47 additions and 26 deletions

View File

@ -1527,7 +1527,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
let textDeltaX = textFrame.origin.x - contentRect.origin.x let textDeltaX = textFrame.origin.x - contentRect.origin.x
transition.animatePositionAdditive(node: self.textNode, offset: CGPoint(x: textDeltaX, y: 0.0)) transition.animatePositionAdditive(node: self.textNode, offset: CGPoint(x: textDeltaX, y: 0.0))
textFrame.origin.x = contentRect.origin.x textFrame.origin.x = contentRect.origin.x
self.textNode.frame = textFrame transition.updateFrame(node: textNode, frame: textFrame)
var contentImageFrame = self.contentImageNode.frame var contentImageFrame = self.contentImageNode.frame
contentImageFrame.origin = textFrame.origin.offsetBy(dx: 1.0, dy: 0.0) contentImageFrame.origin = textFrame.origin.offsetBy(dx: 1.0, dy: 0.0)

View File

@ -10,12 +10,12 @@ import TelegramUIPreferences
private final class ChatRecentActionsFilterControllerArguments { private final class ChatRecentActionsFilterControllerArguments {
let account: Account let account: Account
let toggleAllActions: () -> Void let toggleAllActions: (Bool) -> Void
let toggleAction: ([AdminLogEventsFlags]) -> Void let toggleAction: ([AdminLogEventsFlags]) -> Void
let toggleAllAdmins: () -> Void let toggleAllAdmins: (Bool) -> Void
let toggleAdmin: (PeerId) -> Void let toggleAdmin: (PeerId) -> Void
init(account: Account, toggleAllActions: @escaping () -> Void, toggleAction: @escaping ([AdminLogEventsFlags]) -> Void, toggleAllAdmins: @escaping () -> Void, toggleAdmin: @escaping (PeerId) -> Void) { init(account: Account, toggleAllActions: @escaping (Bool) -> Void, toggleAction: @escaping ([AdminLogEventsFlags]) -> Void, toggleAllAdmins: @escaping (Bool) -> Void, toggleAdmin: @escaping (PeerId) -> Void) {
self.account = account self.account = account
self.toggleAllActions = toggleAllActions self.toggleAllActions = toggleAllActions
self.toggleAction = toggleAction self.toggleAction = toggleAction
@ -206,8 +206,8 @@ private enum ChatRecentActionsFilterEntry: ItemListNodeEntry {
case let .actionsTitle(theme, text): case let .actionsTitle(theme, text):
return ItemListSectionHeaderItem(theme: theme, text: text, sectionId: self.section) return ItemListSectionHeaderItem(theme: theme, text: text, sectionId: self.section)
case let .allActions(theme, text, value): case let .allActions(theme, text, value):
return ItemListSwitchItem(theme: theme, title: text, value: value, enabled: true, sectionId: self.section, style: .blocks, updated: { _ in return ItemListSwitchItem(theme: theme, title: text, value: value, enabled: true, sectionId: self.section, style: .blocks, updated: { value in
arguments.toggleAllActions() arguments.toggleAllActions(value)
}) })
case let .actionItem(theme, _, events, text, value): case let .actionItem(theme, _, events, text, value):
return ItemListCheckboxItem(theme: theme, title: text, style: .right, checked: value, zeroSeparatorInsets: false, sectionId: self.section, action: { return ItemListCheckboxItem(theme: theme, title: text, style: .right, checked: value, zeroSeparatorInsets: false, sectionId: self.section, action: {
@ -216,8 +216,8 @@ private enum ChatRecentActionsFilterEntry: ItemListNodeEntry {
case let .adminsTitle(theme, text): case let .adminsTitle(theme, text):
return ItemListSectionHeaderItem(theme: theme, text: text, sectionId: self.section) return ItemListSectionHeaderItem(theme: theme, text: text, sectionId: self.section)
case let .allAdmins(theme, text, value): case let .allAdmins(theme, text, value):
return ItemListSwitchItem(theme: theme, title: text, value: value, enabled: true, sectionId: self.section, style: .blocks, updated: { _ in return ItemListSwitchItem(theme: theme, title: text, value: value, enabled: true, sectionId: self.section, style: .blocks, updated: { value in
arguments.toggleAllAdmins() arguments.toggleAllAdmins(value)
}) })
case let .adminPeerItem(theme, strings, dateTimeFormat, nameDisplayOrder, _, participant, checked): case let .adminPeerItem(theme, strings, dateTimeFormat, nameDisplayOrder, _, participant, checked):
let peerText: String let peerText: String
@ -374,9 +374,9 @@ public func channelRecentActionsFilterController(context: AccountContext, peer:
let actionsDisposable = DisposableSet() let actionsDisposable = DisposableSet()
let arguments = ChatRecentActionsFilterControllerArguments(account: context.account, toggleAllActions: { let arguments = ChatRecentActionsFilterControllerArguments(account: context.account, toggleAllActions: { value in
updateState { current in updateState { current in
if current.events.isEmpty { if value {
return current.withUpdatedEvents(.all) return current.withUpdatedEvents(.all)
} else { } else {
return current.withUpdatedEvents([]) return current.withUpdatedEvents([])
@ -398,13 +398,13 @@ public func channelRecentActionsFilterController(context: AccountContext, peer:
return current.withUpdatedEvents(updatedEvents) return current.withUpdatedEvents(updatedEvents)
} }
} }
}, toggleAllAdmins: { }, toggleAllAdmins: { value in
let _ = (adminsPromise.get() let _ = (adminsPromise.get()
|> take(1) |> take(1)
|> deliverOnMainQueue).start(next: { admins in |> deliverOnMainQueue).start(next: { admins in
if let _ = admins { if let _ = admins {
updateState { current in updateState { current in
if let _ = current.adminPeerIds { if value {
return current.withUpdatedAdminPeerIds(nil) return current.withUpdatedAdminPeerIds(nil)
} else { } else {
return current.withUpdatedAdminPeerIds([]) return current.withUpdatedAdminPeerIds([])
@ -424,7 +424,9 @@ public func channelRecentActionsFilterController(context: AccountContext, peer:
return current.withUpdatedAdminPeerIds(updatedAdminPeerIds) return current.withUpdatedAdminPeerIds(updatedAdminPeerIds)
} else { } else {
var updatedAdminPeerIds = current.adminPeerIds ?? admins.map { $0.peer.id } var updatedAdminPeerIds = current.adminPeerIds ?? admins.map { $0.peer.id }
if !updatedAdminPeerIds.contains(adminId) { if updatedAdminPeerIds.contains(adminId), let index = updatedAdminPeerIds.index(of: adminId) {
updatedAdminPeerIds.remove(at: index)
} else {
updatedAdminPeerIds.append(adminId) updatedAdminPeerIds.append(adminId)
} }
return current.withUpdatedAdminPeerIds(updatedAdminPeerIds) return current.withUpdatedAdminPeerIds(updatedAdminPeerIds)

View File

@ -252,7 +252,6 @@ public struct PresentationThemeAccentColor: PostboxCoding, Equatable {
public struct PresentationThemeSettings: PreferencesEntry { public struct PresentationThemeSettings: PreferencesEntry {
public var chatWallpaper: TelegramWallpaper public var chatWallpaper: TelegramWallpaper
public var theme: PresentationThemeReference public var theme: PresentationThemeReference
// public var themeAccentColor: Int32?
public var themeSpecificAccentColors: [Int64: PresentationThemeAccentColor] public var themeSpecificAccentColors: [Int64: PresentationThemeAccentColor]
public var themeSpecificChatWallpapers: [Int64: TelegramWallpaper] public var themeSpecificChatWallpapers: [Int64: TelegramWallpaper]
public var fontSize: PresentationFontSize public var fontSize: PresentationFontSize
@ -301,19 +300,44 @@ public struct PresentationThemeSettings: PreferencesEntry {
public init(decoder: PostboxDecoder) { public init(decoder: PostboxDecoder) {
self.chatWallpaper = (decoder.decodeObjectForKey("w", decoder: { TelegramWallpaper(decoder: $0) }) as? TelegramWallpaper) ?? .builtin(WallpaperSettings()) self.chatWallpaper = (decoder.decodeObjectForKey("w", decoder: { TelegramWallpaper(decoder: $0) }) as? TelegramWallpaper) ?? .builtin(WallpaperSettings())
self.theme = decoder.decodeObjectForKey("t", decoder: { PresentationThemeReference(decoder: $0) }) as! PresentationThemeReference self.theme = decoder.decodeObjectForKey("t", decoder: { PresentationThemeReference(decoder: $0) }) as! PresentationThemeReference
//self.themeAccentColor = decoder.decodeOptionalInt32ForKey("themeAccentColor")
self.themeSpecificChatWallpapers = decoder.decodeObjectDictionaryForKey("themeSpecificChatWallpapers", keyDecoder: { decoder in
return decoder.decodeInt64ForKey("k", orElse: 0)
}, valueDecoder: { decoder in
return TelegramWallpaper(decoder: decoder)
})
self.themeSpecificAccentColors = decoder.decodeObjectDictionaryForKey("themeSpecificAccentColors", keyDecoder: { decoder in self.themeSpecificAccentColors = decoder.decodeObjectDictionaryForKey("themeSpecificAccentColors", keyDecoder: { decoder in
return decoder.decodeInt64ForKey("k", orElse: 0) return decoder.decodeInt64ForKey("k", orElse: 0)
}, valueDecoder: { decoder in }, valueDecoder: { decoder in
return PresentationThemeAccentColor(decoder: decoder) return PresentationThemeAccentColor(decoder: decoder)
}) })
self.themeSpecificChatWallpapers = decoder.decodeObjectDictionaryForKey("themeSpecificChatWallpapers", keyDecoder: { decoder in if self.themeSpecificAccentColors[PresentationThemeReference.builtin(.day).index] == nil, let themeAccentColor = decoder.decodeOptionalInt32ForKey("themeAccentColor") {
return decoder.decodeInt64ForKey("k", orElse: 0) let baseColor: PresentationThemeBaseColor
}, valueDecoder: { decoder in switch themeAccentColor {
return TelegramWallpaper(decoder: decoder) case 0xf83b4c:
}) baseColor = .red
case 0xff7519:
baseColor = .orange
case 0xeba239:
baseColor = .yellow
case 0x29b327:
baseColor = .green
case 0x00c2ed:
baseColor = .cyan
case 0x007ee5:
baseColor = .blue
case 0x7748ff:
baseColor = .purple
case 0xff5da2:
baseColor = .pink
default:
baseColor = .blue
}
self.themeSpecificAccentColors[PresentationThemeReference.builtin(.day).index] = PresentationThemeAccentColor(baseColor: baseColor, value: 0.5)
}
self.fontSize = PresentationFontSize(rawValue: decoder.decodeInt32ForKey("f", orElse: PresentationFontSize.regular.rawValue)) ?? .regular self.fontSize = PresentationFontSize(rawValue: decoder.decodeInt32ForKey("f", orElse: PresentationFontSize.regular.rawValue)) ?? .regular
self.automaticThemeSwitchSetting = (decoder.decodeObjectForKey("automaticThemeSwitchSetting", decoder: { AutomaticThemeSwitchSetting(decoder: $0) }) as? AutomaticThemeSwitchSetting) ?? AutomaticThemeSwitchSetting(trigger: .none, theme: .nightAccent) self.automaticThemeSwitchSetting = (decoder.decodeObjectForKey("automaticThemeSwitchSetting", decoder: { AutomaticThemeSwitchSetting(decoder: $0) }) as? AutomaticThemeSwitchSetting) ?? AutomaticThemeSwitchSetting(trigger: .none, theme: .nightAccent)
self.largeEmoji = decoder.decodeBoolForKey("largeEmoji", orElse: true) self.largeEmoji = decoder.decodeBoolForKey("largeEmoji", orElse: true)
@ -323,11 +347,6 @@ public struct PresentationThemeSettings: PreferencesEntry {
public func encode(_ encoder: PostboxEncoder) { public func encode(_ encoder: PostboxEncoder) {
encoder.encodeObject(self.chatWallpaper, forKey: "w") encoder.encodeObject(self.chatWallpaper, forKey: "w")
encoder.encodeObject(self.theme, forKey: "t") encoder.encodeObject(self.theme, forKey: "t")
// if let themeAccentColor = self.themeAccentColor {
// encoder.encodeInt32(themeAccentColor, forKey: "themeAccentColor")
// } else {
// encoder.encodeNil(forKey: "themeAccentColor")
// }
encoder.encodeObjectDictionary(self.themeSpecificAccentColors, forKey: "themeSpecificAccentColors", keyEncoder: { key, encoder in encoder.encodeObjectDictionary(self.themeSpecificAccentColors, forKey: "themeSpecificAccentColors", keyEncoder: { key, encoder in
encoder.encodeInt64(key, forKey: "k") encoder.encodeInt64(key, forKey: "k")
}) })