From fa32fa3e304d2f9380687de56c802f686421851c Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Wed, 26 Jun 2019 00:56:27 +0200 Subject: [PATCH] Import legacy accent color setting if any --- .../TelegramUI/TelegramUI/ChatListItem.swift | 2 +- .../ChatRecentActionsFilterController.swift | 26 ++++++----- .../Sources/PresentationThemeSettings.swift | 45 +++++++++++++------ 3 files changed, 47 insertions(+), 26 deletions(-) diff --git a/submodules/TelegramUI/TelegramUI/ChatListItem.swift b/submodules/TelegramUI/TelegramUI/ChatListItem.swift index 21a00300e6..739dc4cbe4 100644 --- a/submodules/TelegramUI/TelegramUI/ChatListItem.swift +++ b/submodules/TelegramUI/TelegramUI/ChatListItem.swift @@ -1527,7 +1527,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode { let textDeltaX = textFrame.origin.x - contentRect.origin.x transition.animatePositionAdditive(node: self.textNode, offset: CGPoint(x: textDeltaX, y: 0.0)) textFrame.origin.x = contentRect.origin.x - self.textNode.frame = textFrame + transition.updateFrame(node: textNode, frame: textFrame) var contentImageFrame = self.contentImageNode.frame contentImageFrame.origin = textFrame.origin.offsetBy(dx: 1.0, dy: 0.0) diff --git a/submodules/TelegramUI/TelegramUI/ChatRecentActionsFilterController.swift b/submodules/TelegramUI/TelegramUI/ChatRecentActionsFilterController.swift index 983072c7b0..7f39107943 100644 --- a/submodules/TelegramUI/TelegramUI/ChatRecentActionsFilterController.swift +++ b/submodules/TelegramUI/TelegramUI/ChatRecentActionsFilterController.swift @@ -10,12 +10,12 @@ import TelegramUIPreferences private final class ChatRecentActionsFilterControllerArguments { let account: Account - let toggleAllActions: () -> Void + let toggleAllActions: (Bool) -> Void let toggleAction: ([AdminLogEventsFlags]) -> Void - let toggleAllAdmins: () -> Void + let toggleAllAdmins: (Bool) -> 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.toggleAllActions = toggleAllActions self.toggleAction = toggleAction @@ -206,8 +206,8 @@ private enum ChatRecentActionsFilterEntry: ItemListNodeEntry { case let .actionsTitle(theme, text): return ItemListSectionHeaderItem(theme: theme, text: text, sectionId: self.section) case let .allActions(theme, text, value): - return ItemListSwitchItem(theme: theme, title: text, value: value, enabled: true, sectionId: self.section, style: .blocks, updated: { _ in - arguments.toggleAllActions() + return ItemListSwitchItem(theme: theme, title: text, value: value, enabled: true, sectionId: self.section, style: .blocks, updated: { value in + arguments.toggleAllActions(value) }) case let .actionItem(theme, _, events, text, value): 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): return ItemListSectionHeaderItem(theme: theme, text: text, sectionId: self.section) case let .allAdmins(theme, text, value): - return ItemListSwitchItem(theme: theme, title: text, value: value, enabled: true, sectionId: self.section, style: .blocks, updated: { _ in - arguments.toggleAllAdmins() + return ItemListSwitchItem(theme: theme, title: text, value: value, enabled: true, sectionId: self.section, style: .blocks, updated: { value in + arguments.toggleAllAdmins(value) }) case let .adminPeerItem(theme, strings, dateTimeFormat, nameDisplayOrder, _, participant, checked): let peerText: String @@ -374,9 +374,9 @@ public func channelRecentActionsFilterController(context: AccountContext, peer: let actionsDisposable = DisposableSet() - let arguments = ChatRecentActionsFilterControllerArguments(account: context.account, toggleAllActions: { + let arguments = ChatRecentActionsFilterControllerArguments(account: context.account, toggleAllActions: { value in updateState { current in - if current.events.isEmpty { + if value { return current.withUpdatedEvents(.all) } else { return current.withUpdatedEvents([]) @@ -398,13 +398,13 @@ public func channelRecentActionsFilterController(context: AccountContext, peer: return current.withUpdatedEvents(updatedEvents) } } - }, toggleAllAdmins: { + }, toggleAllAdmins: { value in let _ = (adminsPromise.get() |> take(1) |> deliverOnMainQueue).start(next: { admins in if let _ = admins { updateState { current in - if let _ = current.adminPeerIds { + if value { return current.withUpdatedAdminPeerIds(nil) } else { return current.withUpdatedAdminPeerIds([]) @@ -424,7 +424,9 @@ public func channelRecentActionsFilterController(context: AccountContext, peer: return current.withUpdatedAdminPeerIds(updatedAdminPeerIds) } else { 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) } return current.withUpdatedAdminPeerIds(updatedAdminPeerIds) diff --git a/submodules/TelegramUIPreferences/Sources/PresentationThemeSettings.swift b/submodules/TelegramUIPreferences/Sources/PresentationThemeSettings.swift index 407ec6df35..87d0b19ae7 100644 --- a/submodules/TelegramUIPreferences/Sources/PresentationThemeSettings.swift +++ b/submodules/TelegramUIPreferences/Sources/PresentationThemeSettings.swift @@ -252,7 +252,6 @@ public struct PresentationThemeAccentColor: PostboxCoding, Equatable { public struct PresentationThemeSettings: PreferencesEntry { public var chatWallpaper: TelegramWallpaper public var theme: PresentationThemeReference -// public var themeAccentColor: Int32? public var themeSpecificAccentColors: [Int64: PresentationThemeAccentColor] public var themeSpecificChatWallpapers: [Int64: TelegramWallpaper] public var fontSize: PresentationFontSize @@ -301,19 +300,44 @@ public struct PresentationThemeSettings: PreferencesEntry { public init(decoder: PostboxDecoder) { 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.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 return decoder.decodeInt64ForKey("k", orElse: 0) }, valueDecoder: { decoder in return PresentationThemeAccentColor(decoder: decoder) }) - self.themeSpecificChatWallpapers = decoder.decodeObjectDictionaryForKey("themeSpecificChatWallpapers", keyDecoder: { decoder in - return decoder.decodeInt64ForKey("k", orElse: 0) - }, valueDecoder: { decoder in - return TelegramWallpaper(decoder: decoder) - }) + if self.themeSpecificAccentColors[PresentationThemeReference.builtin(.day).index] == nil, let themeAccentColor = decoder.decodeOptionalInt32ForKey("themeAccentColor") { + let baseColor: PresentationThemeBaseColor + switch themeAccentColor { + 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.automaticThemeSwitchSetting = (decoder.decodeObjectForKey("automaticThemeSwitchSetting", decoder: { AutomaticThemeSwitchSetting(decoder: $0) }) as? AutomaticThemeSwitchSetting) ?? AutomaticThemeSwitchSetting(trigger: .none, theme: .nightAccent) self.largeEmoji = decoder.decodeBoolForKey("largeEmoji", orElse: true) @@ -323,11 +347,6 @@ public struct PresentationThemeSettings: PreferencesEntry { public func encode(_ encoder: PostboxEncoder) { encoder.encodeObject(self.chatWallpaper, forKey: "w") 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.encodeInt64(key, forKey: "k") })