diff --git a/TelegramUI/ChatListController.swift b/TelegramUI/ChatListController.swift index 665dd84b0c..c48d01b8b3 100644 --- a/TelegramUI/ChatListController.swift +++ b/TelegramUI/ChatListController.swift @@ -984,7 +984,7 @@ public class ChatListController: TelegramController, KeyShortcutResponder, UIVie } } - return [ + let inputShortcuts: [KeyShortcut] = [ KeyShortcut(title: strings.KeyCommand_JumpToPreviousChat, input: UIKeyInputUpArrow, modifiers: [.alternate], action: { [weak self] in if let strongSelf = self { strongSelf.chatListDisplayNode.chatListNode.selectChat(.previous(unread: false)) @@ -1013,6 +1013,24 @@ public class ChatListController: TelegramController, KeyShortcutResponder, UIVie KeyShortcut(title: strings.KeyCommand_Find, input: "\t", modifiers: [], action: toggleSearch), KeyShortcut(input: UIKeyInputEscape, modifiers: [], action: toggleSearch) ] + + let openChat: (Int) -> Void = { [weak self] index in + if let strongSelf = self { + if index == 0 { + strongSelf.chatListDisplayNode.chatListNode.selectChat(.peerId(strongSelf.account.peerId)) + } else { + strongSelf.chatListDisplayNode.chatListNode.selectChat(.index(index - 1)) + } + } + } + + let chatShortcuts: [KeyShortcut] = (0 ... 9).map { index in + return KeyShortcut(input: "\(index)", modifiers: [.command], action: { + openChat(index) + }) + } + + return inputShortcuts + chatShortcuts } override public func toolbarActionSelected(left: Bool) { diff --git a/TelegramUI/ChatListNode.swift b/TelegramUI/ChatListNode.swift index 7523c8a453..1f148313d8 100644 --- a/TelegramUI/ChatListNode.swift +++ b/TelegramUI/ChatListNode.swift @@ -262,6 +262,8 @@ private final class ChatListOpaqueTransactionState { enum ChatListSelectionOption { case previous(unread: Bool) case next(unread: Bool) + case peerId(PeerId) + case index(Int) } enum ChatListGlobalScrollOption { @@ -645,8 +647,7 @@ final class ChatListNode: ListView { } if let location = location, location != strongSelf.currentLocation { - strongSelf.currentLocation = location - strongSelf.chatListLocation.set(location) + strongSelf.setChatListLocation(location) } strongSelf.enqueueHistoryPreloadUpdate() @@ -687,16 +688,13 @@ final class ChatListNode: ListView { self.chatListDisposable.set(appliedTransition.start()) let initialLocation: ChatListNodeLocation - switch mode { - case .chatList: - initialLocation = .initial(count: 50) - case .peers: - initialLocation = .initial(count: 200) + case .chatList: + initialLocation = .initial(count: 50) + case .peers: + initialLocation = .initial(count: 200) } - - self.currentLocation = initialLocation - self.chatListLocation.set(initialLocation) + self.setChatListLocation(initialLocation) let postbox = context.account.postbox let previousPeerCache = Atomic<[PeerId: Peer]>(value: [:]) @@ -1075,19 +1073,22 @@ final class ChatListNode: ListView { if view.laterIndex == nil { self.transaction(deleteIndices: [], insertIndicesAndItems: [], updateIndicesAndItems: [], options: [.Synchronous], scrollToItem: ListViewScrollToItem(index: 0, position: .top(0.0), animated: true, curve: .Default(duration: nil), directionHint: .Up), updateSizeAndInsets: nil, stationaryItemRange: nil, updateOpaqueState: nil, completion: { _ in }) } else { - let location: ChatListNodeLocation = .scroll(index: ChatListIndex.absoluteUpperBound, sourceIndex: ChatListIndex.absoluteLowerBound + let location: ChatListNodeLocation = .scroll(index: .absoluteUpperBound, sourceIndex: .absoluteLowerBound , scrollPosition: .top(0.0), animated: true) - self.currentLocation = location - self.chatListLocation.set(location) + self.setChatListLocation(location) } } else { - let location: ChatListNodeLocation = .scroll(index: ChatListIndex.absoluteUpperBound, sourceIndex: ChatListIndex.absoluteLowerBound + let location: ChatListNodeLocation = .scroll(index: .absoluteUpperBound, sourceIndex: .absoluteLowerBound , scrollPosition: .top(0.0), animated: true) - self.currentLocation = location - self.chatListLocation.set(location) + self.setChatListLocation(location) } } + private func setChatListLocation(_ location: ChatListNodeLocation) { + self.currentLocation = location + self.chatListLocation.set(location) + } + private func relativeUnreadChatListIndex(position: ChatListRelativePosition) -> Signal { let postbox = self.context.account.postbox return self.context.sharedContext.accountManager.transaction { transaction -> Signal in @@ -1114,15 +1115,13 @@ final class ChatListNode: ListView { } if let index = index { - let location: ChatListNodeLocation = .scroll(index: index, sourceIndex: self?.currentlyVisibleLatestChatListIndex() ?? ChatListIndex.absoluteUpperBound + let location: ChatListNodeLocation = .scroll(index: index, sourceIndex: self?.currentlyVisibleLatestChatListIndex() ?? .absoluteUpperBound , scrollPosition: .center(.top), animated: true) - strongSelf.currentLocation = location - strongSelf.chatListLocation.set(location) + strongSelf.setChatListLocation(location) } else { - let location: ChatListNodeLocation = .scroll(index: ChatListIndex.absoluteUpperBound, sourceIndex: ChatListIndex.absoluteLowerBound + let location: ChatListNodeLocation = .scroll(index: .absoluteUpperBound, sourceIndex: .absoluteLowerBound , scrollPosition: .top(0.0), animated: true) - strongSelf.currentLocation = location - strongSelf.chatListLocation.set(location) + strongSelf.setChatListLocation(location) } }) } @@ -1140,14 +1139,14 @@ final class ChatListNode: ListView { return } - if interaction.highlightedChatLocation == nil { - let location: ChatListNodeLocation = .scroll(index: ChatListIndex.absoluteUpperBound, sourceIndex: ChatListIndex.absoluteLowerBound - , scrollPosition: .top(0.0), animated: true) - self.currentLocation = location - self.chatListLocation.set(location) - //interaction.highlightedChatLocation = ChatListHighlightedLocation(location: .peer(0), progress: 1.0) - return - } +// if interaction.highlightedChatLocation == nil { +// let location: ChatListNodeLocation = .scroll(index: ChatListIndex.absoluteUpperBound, sourceIndex: ChatListIndex.absoluteLowerBound +// , scrollPosition: .top(0.0), animated: true) +// self.currentLocation = location +// self.chatListLocation.set(location) +// //interaction.highlightedChatLocation = ChatListHighlightedLocation(location: .peer(0), progress: 1.0) +// return +// } let entryCount = chatListView.filteredEntries.count var current: (ChatListIndex, PeerId, Int)? = nil @@ -1170,53 +1169,67 @@ final class ChatListNode: ListView { } } - if let current = current { - switch option { - case .previous(unread: true), .next(unread: true): - let position: ChatListRelativePosition + switch option { + case .previous(unread: true), .next(unread: true): + let position: ChatListRelativePosition + if let current = current { if case .previous = option { position = .earlier(than: current.0) } else { position = .later(than: current.0) } - let _ = (relativeUnreadChatListIndex(position: position) |> deliverOnMainQueue).start(next: { [weak self] index in - guard let strongSelf = self, let index = index else { - return - } - - let location: ChatListNodeLocation = .scroll(index: index, sourceIndex: self?.currentlyVisibleLatestChatListIndex() ?? ChatListIndex.absoluteUpperBound, scrollPosition: .center(.top), animated: true) - strongSelf.currentLocation = location - strongSelf.chatListLocation.set(location) - strongSelf.peerSelected?(index.messageIndex.id.peerId, false, false) - }) - break - case .previous(unread: false), .next(unread: false): - if entryCount > 1 { - if current.2 > 0, case let .PeerEntry(index, _, _, _, _, _, peer, _, _, _, _, _, _) = chatListView.filteredEntries[current.2 - 1] { - next = (index, peer.peerId) - } - if current.2 <= entryCount - 2, case let .PeerEntry(index, _, _, _, _, _, peer, _, _, _, _, _, _) = chatListView.filteredEntries[current.2 + 1] { - previous = (index, peer.peerId) - } + } else { + position = .later(than: nil) + } + let _ = (relativeUnreadChatListIndex(position: position) |> deliverOnMainQueue).start(next: { [weak self] index in + guard let strongSelf = self, let index = index else { + return } - - var target: (ChatListIndex, PeerId)? = nil - switch option { - case .previous: - target = previous - case .next: - target = next + let location: ChatListNodeLocation = .scroll(index: index, sourceIndex: strongSelf.currentlyVisibleLatestChatListIndex() ?? .absoluteUpperBound, scrollPosition: .center(.top), animated: true) + strongSelf.setChatListLocation(location) + strongSelf.peerSelected?(index.messageIndex.id.peerId, false, false) + }) + case .previous(unread: false), .next(unread: false): + var target: (ChatListIndex, PeerId)? = nil + if let current = current, entryCount > 1 { + if current.2 > 0, case let .PeerEntry(index, _, _, _, _, _, peer, _, _, _, _, _, _) = chatListView.filteredEntries[current.2 - 1] { + next = (index, peer.peerId) } - - if let target = target { - let location: ChatListNodeLocation = .scroll(index: target.0, sourceIndex: ChatListIndex.absoluteLowerBound - , scrollPosition: .center(.top), animated: true) - self.currentLocation = location - self.chatListLocation.set(location) - self.peerSelected?(target.1, false, false) + if current.2 <= entryCount - 2, case let .PeerEntry(index, _, _, _, _, _, peer, _, _, _, _, _, _) = chatListView.filteredEntries[current.2 + 1] { + previous = (index, peer.peerId) } - break - } + if case .previous = option { + target = previous + } else { + target = next + } + } else if entryCount > 0 { + if case let .PeerEntry(index, _, _, _, _, _, peer, _, _, _, _, _, _) = chatListView.filteredEntries[entryCount - 1] { + target = (index, peer.peerId) + } + } + if let target = target { + let location: ChatListNodeLocation = .scroll(index: target.0, sourceIndex: .absoluteLowerBound, scrollPosition: .center(.top), animated: true) + self.setChatListLocation(location) + self.peerSelected?(target.1, false, false) + } + case let .peerId(peerId): + self.peerSelected?(peerId, false, false) + case let .index(index): + guard index < 10 else { + return + } + let _ = (chatListViewForLocation(groupId: nil, location: .initial(count: 10), account: self.account) + |> take(1) + |> deliverOnMainQueue).start(next: { update in + let entries = update.view.entries + if entries.count > index, case let .MessageEntry(index, _, _, _, _, renderedPeer, _) = entries[10 - index - 1] { + let location: ChatListNodeLocation = .scroll(index: index, sourceIndex: .absoluteLowerBound, scrollPosition: .center(.top), animated: true) + self.setChatListLocation(location) + self.peerSelected?(renderedPeer.peerId, false, false) + } + }) + break } } diff --git a/TelegramUI/ChatMessageActionButtonsNode.swift b/TelegramUI/ChatMessageActionButtonsNode.swift index b9d3311553..a51ab7c4fc 100644 --- a/TelegramUI/ChatMessageActionButtonsNode.swift +++ b/TelegramUI/ChatMessageActionButtonsNode.swift @@ -88,7 +88,7 @@ private final class ChatMessageActionButtonNode: ASDisplayNode { } } - let (titleSize, titleApply) = titleLayout(TextNodeLayoutArguments(attributedString: NSAttributedString(string: title, font: titleFont, textColor: incoming ? theme.theme.chat.bubble.actionButtonsIncomingTextColor : theme.theme.chat.bubble.actionButtonsOutgoingTextColor), backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: max(44.0, constrainedWidth - minimumSideInset - minimumSideInset), height: CGFloat.greatestFiniteMagnitude), alignment: .center, cutout: nil, insets: UIEdgeInsets(top: 1.0, left: 0.0, bottom: 1.0, right: 0.0))) + let (titleSize, titleApply) = titleLayout(TextNodeLayoutArguments(attributedString: NSAttributedString(string: title, font: titleFont, textColor: incoming ? bubbleVariableColor(variableColor: theme.theme.chat.bubble.actionButtonsIncomingTextColor, wallpaper: theme.wallpaper) : bubbleVariableColor(variableColor: theme.theme.chat.bubble.actionButtonsOutgoingTextColor, wallpaper: theme.wallpaper)), backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: max(44.0, constrainedWidth - minimumSideInset - minimumSideInset), height: CGFloat.greatestFiniteMagnitude), alignment: .center, cutout: nil, insets: UIEdgeInsets(top: 1.0, left: 0.0, bottom: 1.0, right: 0.0))) let graphics = PresentationResourcesChat.additionalGraphics(theme.theme, wallpaper: theme.wallpaper) let backgroundImage: UIImage? diff --git a/TelegramUI/ChatMessageAnimatedStickerItemNode.swift b/TelegramUI/ChatMessageAnimatedStickerItemNode.swift index 5f7c66a216..d2df99cff3 100644 --- a/TelegramUI/ChatMessageAnimatedStickerItemNode.swift +++ b/TelegramUI/ChatMessageAnimatedStickerItemNode.swift @@ -495,7 +495,7 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView { if translation.x < -45.0, self.swipeToReplyNode == nil, let item = self.item { self.swipeToReplyFeedback?.impact() - let swipeToReplyNode = ChatMessageSwipeToReplyNode(fillColor: bubbleVariableColor(variableColor: item.presentationData.theme.theme.chat.bubble.shareButtonFillColor, wallpaper: item.presentationData.theme.wallpaper), strokeColor: item.presentationData.theme.theme.chat.bubble.shareButtonStrokeColor, foregroundColor: item.presentationData.theme.theme.chat.bubble.shareButtonForegroundColor) + let swipeToReplyNode = ChatMessageSwipeToReplyNode(fillColor: bubbleVariableColor(variableColor: item.presentationData.theme.theme.chat.bubble.shareButtonFillColor, wallpaper: item.presentationData.theme.wallpaper), strokeColor: bubbleVariableColor(variableColor: item.presentationData.theme.theme.chat.bubble.shareButtonStrokeColor, wallpaper: item.presentationData.theme.wallpaper), foregroundColor: bubbleVariableColor(variableColor: item.presentationData.theme.theme.chat.bubble.shareButtonForegroundColor, wallpaper: item.presentationData.theme.wallpaper)) self.swipeToReplyNode = swipeToReplyNode self.addSubnode(swipeToReplyNode) animateReplyNodeIn = true diff --git a/TelegramUI/ChatMessageBubbleItemNode.swift b/TelegramUI/ChatMessageBubbleItemNode.swift index 62bec12aa3..17d86234c9 100644 --- a/TelegramUI/ChatMessageBubbleItemNode.swift +++ b/TelegramUI/ChatMessageBubbleItemNode.swift @@ -2002,7 +2002,7 @@ class ChatMessageBubbleItemNode: ChatMessageItemView { if translation.x < -45.0, self.swipeToReplyNode == nil, let item = self.item { self.swipeToReplyFeedback?.impact() - let swipeToReplyNode = ChatMessageSwipeToReplyNode(fillColor: bubbleVariableColor(variableColor: item.presentationData.theme.theme.chat.bubble.shareButtonFillColor, wallpaper: item.presentationData.theme.wallpaper), strokeColor: item.presentationData.theme.theme.chat.bubble.shareButtonStrokeColor, foregroundColor: item.presentationData.theme.theme.chat.bubble.shareButtonForegroundColor) + let swipeToReplyNode = ChatMessageSwipeToReplyNode(fillColor: bubbleVariableColor(variableColor: item.presentationData.theme.theme.chat.bubble.shareButtonFillColor, wallpaper: item.presentationData.theme.wallpaper), strokeColor: bubbleVariableColor(variableColor: item.presentationData.theme.theme.chat.bubble.shareButtonStrokeColor, wallpaper: item.presentationData.theme.wallpaper), foregroundColor: bubbleVariableColor(variableColor: item.presentationData.theme.theme.chat.bubble.shareButtonForegroundColor, wallpaper: item.presentationData.theme.wallpaper)) self.swipeToReplyNode = swipeToReplyNode self.addSubnode(swipeToReplyNode) animateReplyNodeIn = true diff --git a/TelegramUI/ChatMessageDateHeader.swift b/TelegramUI/ChatMessageDateHeader.swift index ac7d8f676d..a7d1ec11cb 100644 --- a/TelegramUI/ChatMessageDateHeader.swift +++ b/TelegramUI/ChatMessageDateHeader.swift @@ -106,9 +106,6 @@ final class ChatMessageDateHeaderNode: ListViewItemHeaderNode { self.stickBackgroundNode.displayWithoutProcessing = true self.stickBackgroundNode.displaysAsynchronously = false - //self.testNode.backgroundColor = .black - //self.testNode.isLayerBacked = true - super.init(layerBacked: false, dynamicBounce: true, isRotated: true, seeThrough: false) self.transform = CATransform3DMakeRotation(CGFloat.pi, 0.0, 0.0, 1.0) @@ -122,8 +119,6 @@ final class ChatMessageDateHeaderNode: ListViewItemHeaderNode { self.addSubnode(self.backgroundNode) self.addSubnode(self.labelNode) - //self.addSubnode(self.testNode) - let nowTimestamp = Int32(CFAbsoluteTimeGetCurrent() + NSTimeIntervalSince1970) var t: time_t = time_t(localTimestamp) @@ -145,21 +140,12 @@ final class ChatMessageDateHeaderNode: ListViewItemHeaderNode { text = presentationData.strings.Date_ChatDateHeaderYear(monthAtIndex(Int(timeinfo.tm_mon), strings: presentationData.strings), "\(timeinfo.tm_mday)", "\(1900 + timeinfo.tm_year)").0 } - let attributedString = NSAttributedString(string: text, font: titleFont, textColor: presentationData.theme.theme.chat.serviceMessage.dateTextColor) + let attributedString = NSAttributedString(string: text, font: titleFont, textColor: bubbleVariableColor(variableColor: presentationData.theme.theme.chat.serviceMessage.dateTextColor, wallpaper: presentationData.theme.wallpaper)) let labelLayout = TextNode.asyncLayout(self.labelNode) let (size, apply) = labelLayout(TextNodeLayoutArguments(attributedString: attributedString, backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: 320.0, height: CGFloat.greatestFiniteMagnitude), alignment: .natural, cutout: nil, insets: UIEdgeInsets())) let _ = apply() self.labelNode.frame = CGRect(origin: CGPoint(), size: size.size) - - /*(self.layer as! CASeeThroughTracingLayer).updateRelativePosition = { [weak self] position in - if let strongSelf = self { - strongSelf.testNode.frame = CGRect(origin: CGPoint(x: 0.0, y: 70.0 + position.y), size: CGSize(width: 40.0, height: 20.0)) - print("position \(position.x), \(position.y)") - } - }*/ - - } override func didLoad() { @@ -178,8 +164,6 @@ final class ChatMessageDateHeaderNode: ListViewItemHeaderNode { } override func updateLayout(size: CGSize, leftInset: CGFloat, rightInset: CGFloat) { - //let labelLayout = TextNode.asyncLayout(self.labelNode) - let chatDateSize: CGFloat = 20.0 let chatDateInset: CGFloat = 6.0 @@ -232,8 +216,6 @@ final class ChatMessageDateHeaderNode: ListViewItemHeaderNode { } } - - override func hitTest(_ point: CGPoint, with event: UIEvent?) -> UIView? { if !self.bounds.contains(point) { return nil @@ -247,15 +229,13 @@ final class ChatMessageDateHeaderNode: ListViewItemHeaderNode { return nil } - - override func touchesCancelled(_ touches: Set?, with event: UIEvent?) { super.touchesCancelled(touches, with: event) } @objc func tapGesture(_ recognizer: ListViewTapGestureRecognizer) { if case .ended = recognizer.state { - action?(self.localTimestamp) + self.action?(self.localTimestamp) } } } diff --git a/TelegramUI/ChatMessageInstantVideoItemNode.swift b/TelegramUI/ChatMessageInstantVideoItemNode.swift index ed9da659c1..957c1a447c 100644 --- a/TelegramUI/ChatMessageInstantVideoItemNode.swift +++ b/TelegramUI/ChatMessageInstantVideoItemNode.swift @@ -559,7 +559,7 @@ class ChatMessageInstantVideoItemNode: ChatMessageItemView { if translation.x < -45.0, self.swipeToReplyNode == nil, let item = self.item { self.swipeToReplyFeedback?.impact() - let swipeToReplyNode = ChatMessageSwipeToReplyNode(fillColor: bubbleVariableColor(variableColor: item.presentationData.theme.theme.chat.bubble.shareButtonFillColor, wallpaper: item.presentationData.theme.wallpaper), strokeColor: item.presentationData.theme.theme.chat.bubble.shareButtonStrokeColor, foregroundColor: item.presentationData.theme.theme.chat.bubble.shareButtonForegroundColor) + let swipeToReplyNode = ChatMessageSwipeToReplyNode(fillColor: bubbleVariableColor(variableColor: item.presentationData.theme.theme.chat.bubble.shareButtonFillColor, wallpaper: item.presentationData.theme.wallpaper), strokeColor: bubbleVariableColor(variableColor: item.presentationData.theme.theme.chat.bubble.shareButtonStrokeColor, wallpaper: item.presentationData.theme.wallpaper), foregroundColor: bubbleVariableColor(variableColor: item.presentationData.theme.theme.chat.bubble.shareButtonForegroundColor, wallpaper: item.presentationData.theme.wallpaper)) self.swipeToReplyNode = swipeToReplyNode self.addSubnode(swipeToReplyNode) animateReplyNodeIn = true diff --git a/TelegramUI/ChatMessageStickerItemNode.swift b/TelegramUI/ChatMessageStickerItemNode.swift index 0490264b05..dde843457d 100644 --- a/TelegramUI/ChatMessageStickerItemNode.swift +++ b/TelegramUI/ChatMessageStickerItemNode.swift @@ -600,7 +600,7 @@ class ChatMessageStickerItemNode: ChatMessageItemView { if translation.x < -45.0, self.swipeToReplyNode == nil, let item = self.item { self.swipeToReplyFeedback?.impact() - let swipeToReplyNode = ChatMessageSwipeToReplyNode(fillColor: bubbleVariableColor(variableColor: item.presentationData.theme.theme.chat.bubble.shareButtonFillColor, wallpaper: item.presentationData.theme.wallpaper), strokeColor: item.presentationData.theme.theme.chat.bubble.shareButtonStrokeColor, foregroundColor: item.presentationData.theme.theme.chat.bubble.shareButtonForegroundColor) + let swipeToReplyNode = ChatMessageSwipeToReplyNode(fillColor: bubbleVariableColor(variableColor: item.presentationData.theme.theme.chat.bubble.shareButtonFillColor, wallpaper: item.presentationData.theme.wallpaper), strokeColor: bubbleVariableColor(variableColor: item.presentationData.theme.theme.chat.bubble.shareButtonStrokeColor, wallpaper: item.presentationData.theme.wallpaper), foregroundColor: bubbleVariableColor(variableColor: item.presentationData.theme.theme.chat.bubble.shareButtonForegroundColor, wallpaper: item.presentationData.theme.wallpaper)) self.swipeToReplyNode = swipeToReplyNode self.addSubnode(swipeToReplyNode) animateReplyNodeIn = true diff --git a/TelegramUI/DefaultDarkAccentPresentationTheme.swift b/TelegramUI/DefaultDarkAccentPresentationTheme.swift index 282ebc067c..3e752f99d4 100644 --- a/TelegramUI/DefaultDarkAccentPresentationTheme.swift +++ b/TelegramUI/DefaultDarkAccentPresentationTheme.swift @@ -172,17 +172,17 @@ private let bubble = PresentationThemeChatBubble( outgoingFileDescriptionColor: UIColor(rgb: 0xDBF5FF, alpha: 0.5), incomingFileDurationColor: UIColor(rgb: 0xDBF5FF, alpha: 0.5), outgoingFileDurationColor: UIColor(rgb: 0xDBF5FF, alpha: 0.5), - shareButtonFillColor: PresentationThemeVariableColor(withWallpaper: UIColor(rgb: 0x18222D, alpha: 0.5), withoutWallpaper: UIColor(rgb: 0x18222D, alpha: 0.5)), - shareButtonStrokeColor: UIColor(rgb: 0x587fa3, alpha: 0.15), - shareButtonForegroundColor: UIColor(rgb: 0xb2b2b2), + shareButtonFillColor: PresentationThemeVariableColor(color: UIColor(rgb: 0x18222d, alpha: 0.5)), + shareButtonStrokeColor: PresentationThemeVariableColor(color: UIColor(rgb: 0x587fa3, alpha: 0.15)), + shareButtonForegroundColor: PresentationThemeVariableColor(color: UIColor(rgb: 0xb2b2b2)), mediaOverlayControlBackgroundColor: UIColor(white: 0.0, alpha: 0.6), //!!! mediaOverlayControlForegroundColor: UIColor(white: 1.0, alpha: 1.0), //!!! actionButtonsIncomingFillColor: PresentationThemeVariableColor(withWallpaper: UIColor(rgb: 0x18222D, alpha: 0.5), withoutWallpaper: UIColor(rgb: 0x18222D, alpha: 0.5)), - actionButtonsIncomingStrokeColor: UIColor(rgb: 0x587fa3, alpha: 0.15), - actionButtonsIncomingTextColor: UIColor(rgb: 0xffffff), + actionButtonsIncomingStrokeColor: PresentationThemeVariableColor(color: UIColor(rgb: 0x587fa3, alpha: 0.15)), + actionButtonsIncomingTextColor: PresentationThemeVariableColor(color: UIColor(rgb: 0xffffff)), actionButtonsOutgoingFillColor: PresentationThemeVariableColor(withWallpaper: UIColor(rgb: 0x18222D, alpha: 0.5), withoutWallpaper: UIColor(rgb: 0x18222D, alpha: 0.5)), - actionButtonsOutgoingStrokeColor: UIColor(rgb: 0x587fa3, alpha: 0.15), - actionButtonsOutgoingTextColor: UIColor(rgb: 0xffffff), + actionButtonsOutgoingStrokeColor: PresentationThemeVariableColor(color: UIColor(rgb: 0x587fa3, alpha: 0.15)), + actionButtonsOutgoingTextColor: PresentationThemeVariableColor(color: UIColor(rgb: 0xffffff)), selectionControlBorderColor: .white, selectionControlFillColor: accentColor, selectionControlForegroundColor: .white, @@ -200,7 +200,7 @@ private let serviceMessage = PresentationThemeServiceMessage( unreadBarFillColor: UIColor(rgb: 0x213040), unreadBarStrokeColor: UIColor(rgb: 0x213040), unreadBarTextColor: UIColor(rgb: 0xffffff), - dateTextColor: UIColor(rgb: 0xffffff) + dateTextColor: PresentationThemeVariableColor(color: UIColor(rgb: 0xffffff)) ) private let inputPanelMediaRecordingControl = PresentationThemeChatInputPanelMediaRecordingControl( diff --git a/TelegramUI/DefaultDarkPresentationTheme.swift b/TelegramUI/DefaultDarkPresentationTheme.swift index 4a06a0d340..6cc2c0d2c0 100644 --- a/TelegramUI/DefaultDarkPresentationTheme.swift +++ b/TelegramUI/DefaultDarkPresentationTheme.swift @@ -173,16 +173,16 @@ private let bubble = PresentationThemeChatBubble( incomingFileDurationColor: UIColor(rgb: 0xffffff, alpha: 0.5), outgoingFileDurationColor: UIColor(rgb: 0xffffff, alpha: 0.5), shareButtonFillColor: PresentationThemeVariableColor(withWallpaper: UIColor(rgb: 0x000000, alpha: 0.5), withoutWallpaper: UIColor(rgb: 0x000000, alpha: 0.5)), - shareButtonStrokeColor: UIColor(rgb: 0xb2b2b2, alpha: 0.18), - shareButtonForegroundColor: UIColor(rgb: 0xb2b2b2), //!!! + shareButtonStrokeColor: PresentationThemeVariableColor(withWallpaper: UIColor(rgb: 0xb2b2b2, alpha: 0.18), withoutWallpaper: UIColor(rgb: 0xb2b2b2, alpha: 0.18)), + shareButtonForegroundColor: PresentationThemeVariableColor(withWallpaper: UIColor(rgb: 0xb2b2b2), withoutWallpaper: UIColor(rgb: 0xb2b2b2)), //!!! mediaOverlayControlBackgroundColor: UIColor(white: 0.0, alpha: 0.6), //!!! mediaOverlayControlForegroundColor: UIColor(white: 1.0, alpha: 1.0), //!!! actionButtonsIncomingFillColor: PresentationThemeVariableColor(withWallpaper: UIColor(rgb: 0x000000, alpha: 0.5), withoutWallpaper: UIColor(rgb: 0x000000, alpha: 0.5)), - actionButtonsIncomingStrokeColor: UIColor(rgb: 0xb2b2b2, alpha: 0.18), - actionButtonsIncomingTextColor: UIColor(rgb: 0xffffff), + actionButtonsIncomingStrokeColor: PresentationThemeVariableColor(color: UIColor(rgb: 0xb2b2b2, alpha: 0.18)), + actionButtonsIncomingTextColor: PresentationThemeVariableColor(color: UIColor(rgb: 0xffffff)), actionButtonsOutgoingFillColor: PresentationThemeVariableColor(withWallpaper: UIColor(rgb: 0x000000, alpha: 0.5), withoutWallpaper: UIColor(rgb: 0x000000, alpha: 0.5)), - actionButtonsOutgoingStrokeColor: UIColor(rgb: 0xb2b2b2, alpha: 0.18), - actionButtonsOutgoingTextColor: UIColor(rgb: 0xffffff), + actionButtonsOutgoingStrokeColor: PresentationThemeVariableColor(color: UIColor(rgb: 0xb2b2b2, alpha: 0.18)), + actionButtonsOutgoingTextColor: PresentationThemeVariableColor(color: UIColor(rgb: 0xffffff)), selectionControlBorderColor: .white, selectionControlFillColor: accentColor, selectionControlForegroundColor: .black, @@ -200,7 +200,7 @@ private let serviceMessage = PresentationThemeServiceMessage( unreadBarFillColor: UIColor(rgb: 0x1b1b1b), //!!! unreadBarStrokeColor: UIColor(rgb: 0x000000), unreadBarTextColor: UIColor(rgb: 0xb2b2b2), //!!! - dateTextColor: UIColor(rgb: 0xb2b2b2) + dateTextColor: PresentationThemeVariableColor(color: UIColor(rgb: 0xb2b2b2)) ) private let inputPanelMediaRecordingControl = PresentationThemeChatInputPanelMediaRecordingControl( diff --git a/TelegramUI/DefaultPresentationTheme.swift b/TelegramUI/DefaultPresentationTheme.swift index c9375b9a4b..d78b82b229 100644 --- a/TelegramUI/DefaultPresentationTheme.swift +++ b/TelegramUI/DefaultPresentationTheme.swift @@ -187,12 +187,12 @@ private func makeDefaultPresentationTheme(accentColor: UIColor, serviceBackgroun incomingAccentTextColor: UIColor(rgb: 0x007ee5), outgoingAccentTextColor: UIColor(rgb: 0x00a700), incomingAccentControlColor: UIColor(rgb: 0x007ee5), - outgoingAccentControlColor: UIColor(rgb: 0x3FC33B), + outgoingAccentControlColor: UIColor(rgb: 0x3fc33b), incomingMediaActiveControlColor: UIColor(rgb: 0x007ee5), - outgoingMediaActiveControlColor: UIColor(rgb: 0x3FC33B), + outgoingMediaActiveControlColor: UIColor(rgb: 0x3fc33b), incomingMediaInactiveControlColor: UIColor(rgb: 0xcacaca), - outgoingMediaInactiveControlColor: UIColor(rgb: 0x93D987), - outgoingCheckColor: UIColor(rgb: 0x19C700), + outgoingMediaInactiveControlColor: UIColor(rgb: 0x93d987), + outgoingCheckColor: UIColor(rgb: 0x19c700), incomingPendingActivityColor: UIColor(rgb: 0x525252, alpha: 0.6), outgoingPendingActivityColor: UIColor(rgb: 0x42b649), mediaDateAndStatusFillColor: UIColor(white: 0.0, alpha: 0.5), @@ -204,17 +204,17 @@ private func makeDefaultPresentationTheme(accentColor: UIColor, serviceBackgroun incomingFileDurationColor: UIColor(rgb: 0x525252, alpha: 0.6), outgoingFileDurationColor: UIColor(rgb: 0x008c09, alpha: 0.8), shareButtonFillColor: PresentationThemeVariableColor(withWallpaper: serviceBackgroundColor, withoutWallpaper: UIColor(rgb: 0x748391, alpha: 0.45)), - shareButtonStrokeColor: .clear, - shareButtonForegroundColor: .white, + shareButtonStrokeColor: PresentationThemeVariableColor(withWallpaper: .clear, withoutWallpaper: .clear), + shareButtonForegroundColor: PresentationThemeVariableColor(withWallpaper: .white, withoutWallpaper: .white), mediaOverlayControlBackgroundColor: UIColor(white: 0.0, alpha: 0.6), mediaOverlayControlForegroundColor: UIColor(white: 1.0, alpha: 1.0), - actionButtonsIncomingFillColor: PresentationThemeVariableColor(withWallpaper: serviceBackgroundColor, withoutWallpaper: UIColor(rgb: 0x596E89, alpha: 0.35)), - actionButtonsIncomingStrokeColor: .clear, - actionButtonsIncomingTextColor: .white, - actionButtonsOutgoingFillColor: PresentationThemeVariableColor(withWallpaper: serviceBackgroundColor, withoutWallpaper: UIColor(rgb: 0x596E89, alpha: 0.35)), - actionButtonsOutgoingStrokeColor: .clear, - actionButtonsOutgoingTextColor: .white, - selectionControlBorderColor: UIColor(rgb: 0xC7C7CC), + actionButtonsIncomingFillColor: PresentationThemeVariableColor(withWallpaper: serviceBackgroundColor, withoutWallpaper: UIColor(rgb: 0x596e89, alpha: 0.35)), + actionButtonsIncomingStrokeColor: PresentationThemeVariableColor(color: .clear), + actionButtonsIncomingTextColor: PresentationThemeVariableColor(color: .white), + actionButtonsOutgoingFillColor: PresentationThemeVariableColor(withWallpaper: serviceBackgroundColor, withoutWallpaper: UIColor(rgb: 0x596e89, alpha: 0.35)), + actionButtonsOutgoingStrokeColor: PresentationThemeVariableColor(color: .clear), + actionButtonsOutgoingTextColor: PresentationThemeVariableColor(color: .white), + selectionControlBorderColor: UIColor(rgb: 0xc7c7cc), selectionControlFillColor: accentColor, selectionControlForegroundColor: .white, mediaHighlightOverlayColor: UIColor(white: 1.0, alpha: 0.6), @@ -223,7 +223,7 @@ private func makeDefaultPresentationTheme(accentColor: UIColor, serviceBackgroun incomingMediaPlaceholderColor: UIColor(rgb: 0xe8ecf0), outgoingMediaPlaceholderColor: UIColor(rgb: 0xd2f2b6), incomingPolls: PresentationThemeChatBubblePolls(radioButton: UIColor(rgb: 0xc8c7cc), radioProgress: UIColor(rgb: 0x007ee5), highlight: UIColor(rgb: 0x007ee5).withAlphaComponent(0.08), separator: UIColor(rgb: 0xc8c7cc), bar: UIColor(rgb: 0x007ee5)), - outgoingPolls: PresentationThemeChatBubblePolls(radioButton: UIColor(rgb: 0x93d987), radioProgress: UIColor(rgb: 0x3FC33B), highlight: UIColor(rgb: 0x3FC33B).withAlphaComponent(0.08), separator: UIColor(rgb: 0x93d987), bar: UIColor(rgb: 0x3fc33b)) + outgoingPolls: PresentationThemeChatBubblePolls(radioButton: UIColor(rgb: 0x93d987), radioProgress: UIColor(rgb: 0x3fc33b), highlight: UIColor(rgb: 0x3fc33b).withAlphaComponent(0.08), separator: UIColor(rgb: 0x93d987), bar: UIColor(rgb: 0x3fc33b)) ) let bubbleDay = PresentationThemeChatBubble( @@ -259,18 +259,18 @@ private func makeDefaultPresentationTheme(accentColor: UIColor, serviceBackgroun outgoingFileDescriptionColor: UIColor(rgb: 0xffffff, alpha: 0.7), incomingFileDurationColor: UIColor(rgb: 0x525252, alpha: 0.6), outgoingFileDurationColor: UIColor(rgb: 0xffffff, alpha: 0.7), - shareButtonFillColor: PresentationThemeVariableColor(withWallpaper: UIColor(rgb: 0xffffff, alpha: 0.8), withoutWallpaper: UIColor(rgb: 0xffffff, alpha: 0.8)), - shareButtonStrokeColor: UIColor(rgb: 0xE5E5EA), - shareButtonForegroundColor: accentColor, + shareButtonFillColor: PresentationThemeVariableColor(withWallpaper: serviceBackgroundColor, withoutWallpaper: UIColor(rgb: 0xffffff, alpha: 0.8)), + shareButtonStrokeColor: PresentationThemeVariableColor(withWallpaper: .clear, withoutWallpaper: UIColor(rgb: 0xe5e5ea)), + shareButtonForegroundColor: PresentationThemeVariableColor(withWallpaper: .white, withoutWallpaper: accentColor), mediaOverlayControlBackgroundColor: UIColor(rgb: 0x000000, alpha: 0.6), mediaOverlayControlForegroundColor: UIColor(rgb: 0xffffff, alpha: 1.0), - actionButtonsIncomingFillColor: PresentationThemeVariableColor(withWallpaper: UIColor(rgb: 0xffffff, alpha: 0.8), withoutWallpaper: UIColor(rgb: 0xffffff, alpha: 0.8)), - actionButtonsIncomingStrokeColor: accentColor.withMultipliedBrightnessBy(1.2), - actionButtonsIncomingTextColor: accentColor.withMultipliedBrightnessBy(1.2), - actionButtonsOutgoingFillColor: PresentationThemeVariableColor(withWallpaper: UIColor(rgb: 0xffffff, alpha: 0.8), withoutWallpaper: UIColor(rgb: 0xffffff, alpha: 0.8)), - actionButtonsOutgoingStrokeColor: accentColor.withMultipliedBrightnessBy(1.2), - actionButtonsOutgoingTextColor: accentColor.withMultipliedBrightnessBy(1.2), - selectionControlBorderColor: UIColor(rgb: 0xC7C7CC), + actionButtonsIncomingFillColor: PresentationThemeVariableColor(withWallpaper: serviceBackgroundColor, withoutWallpaper: UIColor(rgb: 0xffffff, alpha: 0.8)), + actionButtonsIncomingStrokeColor: PresentationThemeVariableColor(withWallpaper: .clear, withoutWallpaper: accentColor.withMultipliedBrightnessBy(1.2)), + actionButtonsIncomingTextColor: PresentationThemeVariableColor(withWallpaper: .white, withoutWallpaper: accentColor.withMultipliedBrightnessBy(1.2)), + actionButtonsOutgoingFillColor: PresentationThemeVariableColor(withWallpaper: serviceBackgroundColor, withoutWallpaper: UIColor(rgb: 0xffffff, alpha: 0.8)), + actionButtonsOutgoingStrokeColor: PresentationThemeVariableColor(withWallpaper: .clear, withoutWallpaper: accentColor.withMultipliedBrightnessBy(1.2)), + actionButtonsOutgoingTextColor: PresentationThemeVariableColor(withWallpaper: .white, withoutWallpaper: accentColor.withMultipliedBrightnessBy(1.2)), + selectionControlBorderColor: UIColor(rgb: 0xc7c7cc), selectionControlFillColor: accentColor, selectionControlForegroundColor: .white, mediaHighlightOverlayColor: UIColor(rgb: 0xffffff, alpha: 0.6), @@ -287,15 +287,15 @@ private func makeDefaultPresentationTheme(accentColor: UIColor, serviceBackgroun unreadBarFillColor: UIColor(white: 1.0, alpha: 0.9), unreadBarStrokeColor: UIColor(white: 0.0, alpha: 0.2), unreadBarTextColor: UIColor(rgb: 0x86868d), - dateTextColor: .white + dateTextColor: PresentationThemeVariableColor(color: .white) ) let serviceMessageDay = PresentationThemeServiceMessage( - components: PresentationThemeServiceMessageColor(withDefaultWallpaper: PresentationThemeServiceMessageColorComponents(fill: UIColor(rgb: 0xffffff, alpha: 0.8), primaryText: UIColor(rgb: 0x8D8E93), linkHighlight: UIColor(rgb: 0x748391, alpha: 0.25), dateFillStatic: UIColor(rgb: 0xffffff, alpha: 0.8), dateFillFloating: UIColor(rgb: 0xffffff, alpha: 0.8)), withCustomWallpaper: PresentationThemeServiceMessageColorComponents(fill: UIColor(rgb: 0xffffff, alpha: 0.8), primaryText: UIColor(rgb: 0x8D8E93), linkHighlight: UIColor(rgb: 0x748391, alpha: 0.25), dateFillStatic: UIColor(rgb: 0xffffff, alpha: 0.8), dateFillFloating: UIColor(rgb: 0xffffff, alpha: 0.8))), + components: PresentationThemeServiceMessageColor(withDefaultWallpaper: PresentationThemeServiceMessageColorComponents(fill: UIColor(rgb: 0xffffff, alpha: 0.8), primaryText: UIColor(rgb: 0x8d8e93), linkHighlight: UIColor(rgb: 0x748391, alpha: 0.25), dateFillStatic: UIColor(rgb: 0xffffff, alpha: 0.8), dateFillFloating: UIColor(rgb: 0xffffff, alpha: 0.8)), withCustomWallpaper: PresentationThemeServiceMessageColorComponents(fill: serviceBackgroundColor, primaryText: .white, linkHighlight: UIColor(rgb: 0x748391, alpha: 0.25), dateFillStatic: serviceBackgroundColor, dateFillFloating: serviceBackgroundColor.withAlphaComponent(serviceBackgroundColor.alpha * 0.6667))), unreadBarFillColor: UIColor(rgb: 0xffffff), unreadBarStrokeColor: UIColor(rgb: 0xffffff), unreadBarTextColor: UIColor(rgb: 0x8D8E93), - dateTextColor: UIColor(rgb: 0x8D8E93) + dateTextColor: PresentationThemeVariableColor(withWallpaper: .white, withoutWallpaper: UIColor(rgb: 0x8d8e93)) ) let inputPanelMediaRecordingControl = PresentationThemeChatInputPanelMediaRecordingControl( @@ -427,20 +427,21 @@ private func makeDefaultPresentationTheme(accentColor: UIColor, serviceBackgroun ) } -public let defaultPresentationTheme = makeDefaultPresentationTheme(accentColor: UIColor(rgb: 0x007ee5), serviceBackgroundColor: UIColor(rgb: 0x000000, alpha: 0.3), day: false) +public let defaultPresentationTheme = makeDefaultPresentationTheme(accentColor: UIColor(rgb: 0x007ee5), serviceBackgroundColor: defaultServiceBackgroundColor, day: false) let defaultDayAccentColor: Int32 = 0x007ee5 +let defaultServiceBackgroundColor: UIColor = UIColor(rgb: 0x000000, alpha: 0.3) func makeDefaultPresentationTheme(serviceBackgroundColor: UIColor?) -> PresentationTheme { return makeDefaultPresentationTheme(accentColor: UIColor(rgb: 0x007ee5), serviceBackgroundColor: serviceBackgroundColor ?? .black, day: false) } -func makeDefaultDayPresentationTheme(accentColor: Int32?) -> PresentationTheme { +func makeDefaultDayPresentationTheme(accentColor: Int32?, serviceBackgroundColor: UIColor) -> PresentationTheme { let color: UIColor if let accentColor = accentColor { color = UIColor(rgb: UInt32(bitPattern: accentColor)) } else { color = UIColor(rgb: UInt32(bitPattern: defaultDayAccentColor)) } - return makeDefaultPresentationTheme(accentColor: color, serviceBackgroundColor: UIColor(rgb: 0x000000, alpha: 0.3), day: true) + return makeDefaultPresentationTheme(accentColor: color, serviceBackgroundColor: serviceBackgroundColor, day: true) } diff --git a/TelegramUI/PresentationData.swift b/TelegramUI/PresentationData.swift index 821fbb4988..7fc05964ce 100644 --- a/TelegramUI/PresentationData.swift +++ b/TelegramUI/PresentationData.swift @@ -261,7 +261,7 @@ public func currentPresentationDataAndSettings(accountManager: AccountManager) - case .nightAccent: themeValue = defaultDarkAccentPresentationTheme case .day: - themeValue = makeDefaultDayPresentationTheme(accentColor: themeSettings.themeAccentColor ?? defaultDayAccentColor) + themeValue = makeDefaultDayPresentationTheme(accentColor: themeSettings.themeAccentColor ?? defaultDayAccentColor, serviceBackgroundColor: defaultServiceBackgroundColor) } } let stringsValue: PresentationStrings @@ -408,7 +408,7 @@ public func updatedPresentationData(accountManager: AccountManager, applicationB case .nightAccent: themeValue = defaultDarkAccentPresentationTheme case .day: - themeValue = makeDefaultDayPresentationTheme(accentColor: themeSettings.themeAccentColor ?? defaultDayAccentColor) + themeValue = makeDefaultDayPresentationTheme(accentColor: themeSettings.themeAccentColor ?? defaultDayAccentColor, serviceBackgroundColor: serviceBackgroundColor) } } diff --git a/TelegramUI/PresentationTheme.swift b/TelegramUI/PresentationTheme.swift index 1c3644c64f..9484ab30fc 100644 --- a/TelegramUI/PresentationTheme.swift +++ b/TelegramUI/PresentationTheme.swift @@ -428,6 +428,11 @@ public final class PresentationThemeVariableColor { self.withWallpaper = withWallpaper self.withoutWallpaper = withoutWallpaper } + + public init(color: UIColor) { + self.withWallpaper = color + self.withoutWallpaper = color + } } public func bubbleColorComponents(theme: PresentationTheme, incoming: Bool, wallpaper: Bool) -> PresentationThemeBubbleColorComponents { @@ -447,7 +452,7 @@ public func bubbleColorComponents(theme: PresentationTheme, incoming: Bool, wall } public func bubbleVariableColor(variableColor: PresentationThemeVariableColor, wallpaper: TelegramWallpaper) -> UIColor { - if wallpaper != .builtin { + if wallpaper != .builtin && wallpaper != .color(0xffffff) { return variableColor.withWallpaper } else { return variableColor.withoutWallpaper @@ -512,19 +517,19 @@ public final class PresentationThemeChatBubble { public let outgoingFileDurationColor: UIColor public let shareButtonFillColor: PresentationThemeVariableColor - public let shareButtonStrokeColor: UIColor - public let shareButtonForegroundColor: UIColor + public let shareButtonStrokeColor: PresentationThemeVariableColor + public let shareButtonForegroundColor: PresentationThemeVariableColor public let mediaOverlayControlBackgroundColor: UIColor public let mediaOverlayControlForegroundColor: UIColor public let actionButtonsIncomingFillColor: PresentationThemeVariableColor - public let actionButtonsIncomingStrokeColor: UIColor - public let actionButtonsIncomingTextColor: UIColor + public let actionButtonsIncomingStrokeColor: PresentationThemeVariableColor + public let actionButtonsIncomingTextColor: PresentationThemeVariableColor public let actionButtonsOutgoingFillColor: PresentationThemeVariableColor - public let actionButtonsOutgoingStrokeColor: UIColor - public let actionButtonsOutgoingTextColor: UIColor + public let actionButtonsOutgoingStrokeColor: PresentationThemeVariableColor + public let actionButtonsOutgoingTextColor: PresentationThemeVariableColor public let selectionControlBorderColor: UIColor public let selectionControlFillColor: UIColor @@ -541,7 +546,7 @@ public final class PresentationThemeChatBubble { public let incomingPolls: PresentationThemeChatBubblePolls public let outgoingPolls: PresentationThemeChatBubblePolls - public init(incoming: PresentationThemeBubbleColor, outgoing: PresentationThemeBubbleColor, freeform: PresentationThemeBubbleColor, incomingPrimaryTextColor: UIColor, incomingSecondaryTextColor: UIColor, incomingLinkTextColor: UIColor, incomingLinkHighlightColor: UIColor, outgoingPrimaryTextColor: UIColor, outgoingSecondaryTextColor: UIColor, outgoingLinkTextColor: UIColor, outgoingLinkHighlightColor: UIColor, infoPrimaryTextColor: UIColor, infoLinkTextColor: UIColor, incomingAccentTextColor: UIColor, outgoingAccentTextColor: UIColor, incomingAccentControlColor: UIColor, outgoingAccentControlColor: UIColor, incomingMediaActiveControlColor: UIColor, outgoingMediaActiveControlColor: UIColor, incomingMediaInactiveControlColor: UIColor, outgoingMediaInactiveControlColor: UIColor, outgoingCheckColor: UIColor, incomingPendingActivityColor: UIColor, outgoingPendingActivityColor: UIColor, mediaDateAndStatusFillColor: UIColor, mediaDateAndStatusTextColor: UIColor, incomingFileTitleColor: UIColor, outgoingFileTitleColor: UIColor, incomingFileDescriptionColor: UIColor, outgoingFileDescriptionColor: UIColor, incomingFileDurationColor: UIColor, outgoingFileDurationColor: UIColor, shareButtonFillColor: PresentationThemeVariableColor, shareButtonStrokeColor: UIColor, shareButtonForegroundColor: UIColor, mediaOverlayControlBackgroundColor: UIColor, mediaOverlayControlForegroundColor: UIColor, actionButtonsIncomingFillColor: PresentationThemeVariableColor, actionButtonsIncomingStrokeColor: UIColor, actionButtonsIncomingTextColor: UIColor, actionButtonsOutgoingFillColor: PresentationThemeVariableColor, actionButtonsOutgoingStrokeColor: UIColor, actionButtonsOutgoingTextColor: UIColor, selectionControlBorderColor: UIColor, selectionControlFillColor: UIColor, selectionControlForegroundColor: UIColor, mediaHighlightOverlayColor: UIColor, deliveryFailedFillColor: UIColor, deliveryFailedForegroundColor: UIColor, incomingMediaPlaceholderColor: UIColor, outgoingMediaPlaceholderColor: UIColor, incomingPolls: PresentationThemeChatBubblePolls, outgoingPolls: PresentationThemeChatBubblePolls) { + public init(incoming: PresentationThemeBubbleColor, outgoing: PresentationThemeBubbleColor, freeform: PresentationThemeBubbleColor, incomingPrimaryTextColor: UIColor, incomingSecondaryTextColor: UIColor, incomingLinkTextColor: UIColor, incomingLinkHighlightColor: UIColor, outgoingPrimaryTextColor: UIColor, outgoingSecondaryTextColor: UIColor, outgoingLinkTextColor: UIColor, outgoingLinkHighlightColor: UIColor, infoPrimaryTextColor: UIColor, infoLinkTextColor: UIColor, incomingAccentTextColor: UIColor, outgoingAccentTextColor: UIColor, incomingAccentControlColor: UIColor, outgoingAccentControlColor: UIColor, incomingMediaActiveControlColor: UIColor, outgoingMediaActiveControlColor: UIColor, incomingMediaInactiveControlColor: UIColor, outgoingMediaInactiveControlColor: UIColor, outgoingCheckColor: UIColor, incomingPendingActivityColor: UIColor, outgoingPendingActivityColor: UIColor, mediaDateAndStatusFillColor: UIColor, mediaDateAndStatusTextColor: UIColor, incomingFileTitleColor: UIColor, outgoingFileTitleColor: UIColor, incomingFileDescriptionColor: UIColor, outgoingFileDescriptionColor: UIColor, incomingFileDurationColor: UIColor, outgoingFileDurationColor: UIColor, shareButtonFillColor: PresentationThemeVariableColor, shareButtonStrokeColor: PresentationThemeVariableColor, shareButtonForegroundColor: PresentationThemeVariableColor, mediaOverlayControlBackgroundColor: UIColor, mediaOverlayControlForegroundColor: UIColor, actionButtonsIncomingFillColor: PresentationThemeVariableColor, actionButtonsIncomingStrokeColor: PresentationThemeVariableColor, actionButtonsIncomingTextColor: PresentationThemeVariableColor, actionButtonsOutgoingFillColor: PresentationThemeVariableColor, actionButtonsOutgoingStrokeColor: PresentationThemeVariableColor, actionButtonsOutgoingTextColor: PresentationThemeVariableColor, selectionControlBorderColor: UIColor, selectionControlFillColor: UIColor, selectionControlForegroundColor: UIColor, mediaHighlightOverlayColor: UIColor, deliveryFailedFillColor: UIColor, deliveryFailedForegroundColor: UIColor, incomingMediaPlaceholderColor: UIColor, outgoingMediaPlaceholderColor: UIColor, incomingPolls: PresentationThemeChatBubblePolls, outgoingPolls: PresentationThemeChatBubblePolls) { self.incoming = incoming self.outgoing = outgoing self.freeform = freeform @@ -644,7 +649,7 @@ public func serviceMessageColorComponents(theme: PresentationTheme, wallpaper: T } public func serviceMessageColorComponents(chatTheme: PresentationThemeChat, wallpaper: TelegramWallpaper) -> PresentationThemeServiceMessageColorComponents { - if wallpaper != .builtin { + if wallpaper != .builtin && wallpaper != .color(0xffffff) { return chatTheme.serviceMessage.components.withCustomWallpaper } else { return chatTheme.serviceMessage.components.withDefaultWallpaper @@ -658,9 +663,9 @@ public final class PresentationThemeServiceMessage { public let unreadBarStrokeColor: UIColor public let unreadBarTextColor: UIColor - public let dateTextColor: UIColor + public let dateTextColor: PresentationThemeVariableColor - public init(components: PresentationThemeServiceMessageColor, unreadBarFillColor: UIColor, unreadBarStrokeColor: UIColor, unreadBarTextColor: UIColor, dateTextColor: UIColor) { + public init(components: PresentationThemeServiceMessageColor, unreadBarFillColor: UIColor, unreadBarStrokeColor: UIColor, unreadBarTextColor: UIColor, dateTextColor: PresentationThemeVariableColor) { self.components = components self.unreadBarFillColor = unreadBarFillColor self.unreadBarStrokeColor = unreadBarStrokeColor diff --git a/TelegramUI/PresentationThemeEssentialGraphics.swift b/TelegramUI/PresentationThemeEssentialGraphics.swift index 27b5a385c4..db594a9142 100644 --- a/TelegramUI/PresentationThemeEssentialGraphics.swift +++ b/TelegramUI/PresentationThemeEssentialGraphics.swift @@ -245,25 +245,25 @@ public final class PrincipalThemeAdditionalGraphics { self.chatEmptyItemBackgroundImage = generateStretchableFilledCircleImage(radius: 14.0, color: serviceColor.fill)! self.chatLoadingIndicatorBackgroundImage = generateStretchableFilledCircleImage(diameter: 30.0, color: serviceColor.fill)! - self.chatBubbleShareButtonImage = chatBubbleActionButtonImage(fillColor: bubbleVariableColor(variableColor: theme.bubble.shareButtonFillColor, wallpaper: wallpaper), strokeColor: theme.bubble.shareButtonStrokeColor, foregroundColor: theme.bubble.shareButtonForegroundColor, image: UIImage(bundleImageName: "Chat/Message/ShareIcon"))! - self.chatBubbleNavigateButtonImage = chatBubbleActionButtonImage(fillColor: bubbleVariableColor(variableColor: theme.bubble.shareButtonFillColor, wallpaper: wallpaper), strokeColor: theme.bubble.shareButtonStrokeColor, foregroundColor: theme.bubble.shareButtonForegroundColor, image: UIImage(bundleImageName: "Chat/Message/NavigateToMessageIcon"), iconOffset: CGPoint(x: 0.0, y: 1.0))! - self.chatBubbleActionButtonIncomingMiddleImage = messageBubbleActionButtonImage(color: bubbleVariableColor(variableColor: theme.bubble.actionButtonsIncomingFillColor, wallpaper: wallpaper), strokeColor: theme.bubble.actionButtonsIncomingStrokeColor, position: .middle) - self.chatBubbleActionButtonIncomingBottomLeftImage = messageBubbleActionButtonImage(color: bubbleVariableColor(variableColor: theme.bubble.actionButtonsIncomingFillColor, wallpaper: wallpaper), strokeColor: theme.bubble.actionButtonsIncomingStrokeColor, position: .bottomLeft) - self.chatBubbleActionButtonIncomingBottomRightImage = messageBubbleActionButtonImage(color: bubbleVariableColor(variableColor: theme.bubble.actionButtonsIncomingFillColor, wallpaper: wallpaper), strokeColor: theme.bubble.actionButtonsIncomingStrokeColor, position: .bottomRight) - self.chatBubbleActionButtonIncomingBottomSingleImage = messageBubbleActionButtonImage(color: bubbleVariableColor(variableColor: theme.bubble.actionButtonsIncomingFillColor, wallpaper: wallpaper), strokeColor: theme.bubble.actionButtonsIncomingStrokeColor, position: .bottomSingle) - self.chatBubbleActionButtonOutgoingMiddleImage = messageBubbleActionButtonImage(color: bubbleVariableColor(variableColor: theme.bubble.actionButtonsOutgoingFillColor, wallpaper: wallpaper), strokeColor: theme.bubble.actionButtonsOutgoingStrokeColor, position: .middle) - self.chatBubbleActionButtonOutgoingBottomLeftImage = messageBubbleActionButtonImage(color: bubbleVariableColor(variableColor: theme.bubble.actionButtonsOutgoingFillColor, wallpaper: wallpaper), strokeColor: theme.bubble.actionButtonsOutgoingStrokeColor, position: .bottomLeft) - self.chatBubbleActionButtonOutgoingBottomRightImage = messageBubbleActionButtonImage(color: bubbleVariableColor(variableColor: theme.bubble.actionButtonsOutgoingFillColor, wallpaper: wallpaper), strokeColor: theme.bubble.actionButtonsOutgoingStrokeColor, position: .bottomRight) - self.chatBubbleActionButtonOutgoingBottomSingleImage = messageBubbleActionButtonImage(color: bubbleVariableColor(variableColor: theme.bubble.actionButtonsOutgoingFillColor, wallpaper: wallpaper), strokeColor: theme.bubble.actionButtonsOutgoingStrokeColor, position: .bottomSingle) - self.chatBubbleActionButtonIncomingMessageIconImage = generateTintedImage(image: UIImage(bundleImageName: "Chat/Message/BotMessage"), color: theme.bubble.actionButtonsIncomingTextColor)! - self.chatBubbleActionButtonIncomingLinkIconImage = generateTintedImage(image: UIImage(bundleImageName: "Chat/Message/BotLink"), color: theme.bubble.actionButtonsIncomingTextColor)! - self.chatBubbleActionButtonIncomingShareIconImage = generateTintedImage(image: UIImage(bundleImageName: "Chat/Message/BotShare"), color: theme.bubble.actionButtonsIncomingTextColor)! - self.chatBubbleActionButtonIncomingPhoneIconImage = generateTintedImage(image: UIImage(bundleImageName: "Chat/Message/BotPhone"), color: theme.bubble.actionButtonsIncomingTextColor)! - self.chatBubbleActionButtonIncomingLocationIconImage = generateTintedImage(image: UIImage(bundleImageName: "Chat/Message/BotLocation"), color: theme.bubble.actionButtonsIncomingTextColor)! - self.chatBubbleActionButtonOutgoingMessageIconImage = generateTintedImage(image: UIImage(bundleImageName: "Chat/Message/BotMessage"), color: theme.bubble.actionButtonsOutgoingTextColor)! - self.chatBubbleActionButtonOutgoingLinkIconImage = generateTintedImage(image: UIImage(bundleImageName: "Chat/Message/BotLink"), color: theme.bubble.actionButtonsOutgoingTextColor)! - self.chatBubbleActionButtonOutgoingShareIconImage = generateTintedImage(image: UIImage(bundleImageName: "Chat/Message/BotShare"), color: theme.bubble.actionButtonsOutgoingTextColor)! - self.chatBubbleActionButtonOutgoingPhoneIconImage = generateTintedImage(image: UIImage(bundleImageName: "Chat/Message/BotPhone"), color: theme.bubble.actionButtonsOutgoingTextColor)! - self.chatBubbleActionButtonOutgoingLocationIconImage = generateTintedImage(image: UIImage(bundleImageName: "Chat/Message/BotLocation"), color: theme.bubble.actionButtonsOutgoingTextColor)! + self.chatBubbleShareButtonImage = chatBubbleActionButtonImage(fillColor: bubbleVariableColor(variableColor: theme.bubble.shareButtonFillColor, wallpaper: wallpaper), strokeColor: bubbleVariableColor(variableColor: theme.bubble.shareButtonStrokeColor, wallpaper: wallpaper), foregroundColor: bubbleVariableColor(variableColor: theme.bubble.shareButtonForegroundColor, wallpaper: wallpaper), image: UIImage(bundleImageName: "Chat/Message/ShareIcon"))! + self.chatBubbleNavigateButtonImage = chatBubbleActionButtonImage(fillColor: bubbleVariableColor(variableColor: theme.bubble.shareButtonFillColor, wallpaper: wallpaper), strokeColor: bubbleVariableColor(variableColor: theme.bubble.shareButtonStrokeColor, wallpaper: wallpaper), foregroundColor: bubbleVariableColor(variableColor: theme.bubble.shareButtonForegroundColor, wallpaper: wallpaper), image: UIImage(bundleImageName: "Chat/Message/NavigateToMessageIcon"), iconOffset: CGPoint(x: 0.0, y: 1.0))! + self.chatBubbleActionButtonIncomingMiddleImage = messageBubbleActionButtonImage(color: bubbleVariableColor(variableColor: theme.bubble.actionButtonsIncomingFillColor, wallpaper: wallpaper), strokeColor: bubbleVariableColor(variableColor: theme.bubble.actionButtonsIncomingStrokeColor, wallpaper: wallpaper), position: .middle) + self.chatBubbleActionButtonIncomingBottomLeftImage = messageBubbleActionButtonImage(color: bubbleVariableColor(variableColor: theme.bubble.actionButtonsIncomingFillColor, wallpaper: wallpaper), strokeColor: bubbleVariableColor(variableColor: theme.bubble.actionButtonsIncomingStrokeColor, wallpaper: wallpaper), position: .bottomLeft) + self.chatBubbleActionButtonIncomingBottomRightImage = messageBubbleActionButtonImage(color: bubbleVariableColor(variableColor: theme.bubble.actionButtonsIncomingFillColor, wallpaper: wallpaper), strokeColor: bubbleVariableColor(variableColor: theme.bubble.actionButtonsIncomingStrokeColor, wallpaper: wallpaper), position: .bottomRight) + self.chatBubbleActionButtonIncomingBottomSingleImage = messageBubbleActionButtonImage(color: bubbleVariableColor(variableColor: theme.bubble.actionButtonsIncomingFillColor, wallpaper: wallpaper), strokeColor: bubbleVariableColor(variableColor: theme.bubble.actionButtonsIncomingStrokeColor, wallpaper: wallpaper), position: .bottomSingle) + self.chatBubbleActionButtonOutgoingMiddleImage = messageBubbleActionButtonImage(color: bubbleVariableColor(variableColor: theme.bubble.actionButtonsOutgoingFillColor, wallpaper: wallpaper), strokeColor: bubbleVariableColor(variableColor: theme.bubble.actionButtonsOutgoingStrokeColor, wallpaper: wallpaper), position: .middle) + self.chatBubbleActionButtonOutgoingBottomLeftImage = messageBubbleActionButtonImage(color: bubbleVariableColor(variableColor: theme.bubble.actionButtonsOutgoingFillColor, wallpaper: wallpaper), strokeColor: bubbleVariableColor(variableColor: theme.bubble.actionButtonsOutgoingStrokeColor, wallpaper: wallpaper), position: .bottomLeft) + self.chatBubbleActionButtonOutgoingBottomRightImage = messageBubbleActionButtonImage(color: bubbleVariableColor(variableColor: theme.bubble.actionButtonsOutgoingFillColor, wallpaper: wallpaper), strokeColor: bubbleVariableColor(variableColor: theme.bubble.actionButtonsOutgoingStrokeColor, wallpaper: wallpaper), position: .bottomRight) + self.chatBubbleActionButtonOutgoingBottomSingleImage = messageBubbleActionButtonImage(color: bubbleVariableColor(variableColor: theme.bubble.actionButtonsOutgoingFillColor, wallpaper: wallpaper), strokeColor: bubbleVariableColor(variableColor: theme.bubble.actionButtonsOutgoingStrokeColor, wallpaper: wallpaper), position: .bottomSingle) + self.chatBubbleActionButtonIncomingMessageIconImage = generateTintedImage(image: UIImage(bundleImageName: "Chat/Message/BotMessage"), color: bubbleVariableColor(variableColor: theme.bubble.actionButtonsIncomingTextColor, wallpaper: wallpaper))! + self.chatBubbleActionButtonIncomingLinkIconImage = generateTintedImage(image: UIImage(bundleImageName: "Chat/Message/BotLink"), color: bubbleVariableColor(variableColor: theme.bubble.actionButtonsIncomingTextColor, wallpaper: wallpaper))! + self.chatBubbleActionButtonIncomingShareIconImage = generateTintedImage(image: UIImage(bundleImageName: "Chat/Message/BotShare"), color: bubbleVariableColor(variableColor: theme.bubble.actionButtonsIncomingTextColor, wallpaper: wallpaper))! + self.chatBubbleActionButtonIncomingPhoneIconImage = generateTintedImage(image: UIImage(bundleImageName: "Chat/Message/BotPhone"), color: bubbleVariableColor(variableColor: theme.bubble.actionButtonsIncomingTextColor, wallpaper: wallpaper))! + self.chatBubbleActionButtonIncomingLocationIconImage = generateTintedImage(image: UIImage(bundleImageName: "Chat/Message/BotLocation"), color: bubbleVariableColor(variableColor: theme.bubble.actionButtonsIncomingTextColor, wallpaper: wallpaper))! + self.chatBubbleActionButtonOutgoingMessageIconImage = generateTintedImage(image: UIImage(bundleImageName: "Chat/Message/BotMessage"), color: bubbleVariableColor(variableColor: theme.bubble.actionButtonsOutgoingTextColor, wallpaper: wallpaper))! + self.chatBubbleActionButtonOutgoingLinkIconImage = generateTintedImage(image: UIImage(bundleImageName: "Chat/Message/BotLink"), color: bubbleVariableColor(variableColor: theme.bubble.actionButtonsOutgoingTextColor, wallpaper: wallpaper))! + self.chatBubbleActionButtonOutgoingShareIconImage = generateTintedImage(image: UIImage(bundleImageName: "Chat/Message/BotShare"), color: bubbleVariableColor(variableColor: theme.bubble.actionButtonsOutgoingTextColor, wallpaper: wallpaper))! + self.chatBubbleActionButtonOutgoingPhoneIconImage = generateTintedImage(image: UIImage(bundleImageName: "Chat/Message/BotPhone"), color: bubbleVariableColor(variableColor: theme.bubble.actionButtonsOutgoingTextColor, wallpaper: wallpaper))! + self.chatBubbleActionButtonOutgoingLocationIconImage = generateTintedImage(image: UIImage(bundleImageName: "Chat/Message/BotLocation"), color: bubbleVariableColor(variableColor: theme.bubble.actionButtonsOutgoingTextColor, wallpaper: wallpaper))! } } diff --git a/TelegramUI/ProxyServerActionSheetController.swift b/TelegramUI/ProxyServerActionSheetController.swift index 0682f50dc5..d0961aad3c 100644 --- a/TelegramUI/ProxyServerActionSheetController.swift +++ b/TelegramUI/ProxyServerActionSheetController.swift @@ -31,8 +31,8 @@ public final class ProxyServerActionSheetController: ActionSheetController { if case .mtp = server.connection { items.append(ActionSheetTextItem(title: strings.SocksProxySetup_AdNoticeHelp)) } - items.append(ProxyServerInfoItem(strings: strings, server: server)) - items.append(ProxyServerActionItem(accountManager: accountManager, postbox: postbox, network: network, presentationTheme: theme, strings: strings, server: server, dismiss: { [weak self] success in + items.append(ProxyServerInfoItem(strings: strings, network: network, server: server)) + items.append(ProxyServerActionItem(accountManager:accountManager, postbox: postbox, network: network, presentationTheme: theme, strings: strings, server: server, dismiss: { [weak self] success in guard let strongSelf = self, !strongSelf.isDismissed else { return } @@ -73,15 +73,17 @@ public final class ProxyServerActionSheetController: ActionSheetController { private final class ProxyServerInfoItem: ActionSheetItem { private let strings: PresentationStrings + private let network: Network private let server: ProxyServerSettings - init(strings: PresentationStrings, server: ProxyServerSettings) { + init(strings: PresentationStrings, network: Network, server: ProxyServerSettings) { self.strings = strings + self.network = network self.server = server } func node(theme: ActionSheetControllerTheme) -> ActionSheetItemNode { - return ProxyServerInfoItemNode(theme: theme, strings: self.strings, server: self.server) + return ProxyServerInfoItemNode(theme: theme, strings: self.strings, network: self.network, server: self.server) } func updateNode(_ node: ActionSheetItemNode) { @@ -90,16 +92,27 @@ private final class ProxyServerInfoItem: ActionSheetItem { private let textFont = Font.regular(16.0) +private enum ProxyServerInfoStatusType { + case generic(String) + case failed(String) +} + private final class ProxyServerInfoItemNode: ActionSheetItemNode { private let theme: ActionSheetControllerTheme private let strings: PresentationStrings + + private let network: Network private let server: ProxyServerSettings private let fieldNodes: [(ImmediateTextNode, ImmediateTextNode)] + private let statusTextNode: ImmediateTextNode - init(theme: ActionSheetControllerTheme, strings: PresentationStrings, server: ProxyServerSettings) { + private let statusDisposable = MetaDisposable() + + init(theme: ActionSheetControllerTheme, strings: PresentationStrings, network: Network, server: ProxyServerSettings) { self.theme = theme self.strings = strings + self.network = network self.server = server var fieldNodes: [(ImmediateTextNode, ImmediateTextNode)] = [] @@ -160,7 +173,18 @@ private final class ProxyServerInfoItemNode: ActionSheetItemNode { fieldNodes.append((passwordTitleNode, passwordTextNode)) } + let statusTitleNode = ImmediateTextNode() + statusTitleNode.isUserInteractionEnabled = false + statusTitleNode.displaysAsynchronously = false + statusTitleNode.attributedText = NSAttributedString(string: strings.SocksProxySetup_Status, font: textFont, textColor: theme.secondaryTextColor) + let statusTextNode = ImmediateTextNode() + statusTextNode.isUserInteractionEnabled = false + statusTextNode.displaysAsynchronously = false + statusTextNode.attributedText = NSAttributedString(string: strings.SocksProxySetup_ProxyStatusChecking, font: textFont, textColor: theme.primaryTextColor) + fieldNodes.append((statusTitleNode, statusTextNode)) + self.fieldNodes = fieldNodes + self.statusTextNode = statusTextNode super.init(theme: theme) @@ -170,6 +194,46 @@ private final class ProxyServerInfoItemNode: ActionSheetItemNode { } } + deinit { + self.statusDisposable.dispose() + } + + override func didLoad() { + super.didLoad() + + let statusesContext = ProxyServersStatuses(network: network, servers: .single([self.server])) + self.statusDisposable.set((statusesContext.statuses() + |> map { return $0.first?.value } + |> distinctUntilChanged + |> deliverOnMainQueue).start(next: { [weak self] status in + if let strongSelf = self, let status = status { + let statusType: ProxyServerInfoStatusType + switch status { + case .checking: + statusType = .generic(strongSelf.strings.SocksProxySetup_ProxyStatusChecking) + case let .available(rtt): + let pingTime = Int(rtt * 1000.0) + statusType = .generic(strongSelf.strings.SocksProxySetup_ProxyStatusPing("\(pingTime)").0) + case .notAvailable: + statusType = .failed(strongSelf.strings.SocksProxySetup_ProxyStatusUnavailable) + } + strongSelf.setStatus(statusType) + } + })) + } + + func setStatus(_ status: ProxyServerInfoStatusType) { + let attributedString: NSAttributedString + switch status { + case let .generic(text): + attributedString = NSAttributedString(string: text, font: textFont, textColor: theme.primaryTextColor) + case let .failed(text): + attributedString = NSAttributedString(string: text, font: textFont, textColor: theme.destructiveActionTextColor) + } + self.statusTextNode.attributedText = attributedString + self.setNeedsLayout() + } + override func calculateSizeThatFits(_ constrainedSize: CGSize) -> CGSize { return CGSize(width: constrainedSize.width, height: 36.0 * CGFloat(self.fieldNodes.count) + 12.0) } diff --git a/TelegramUI/ThemeSettingsController.swift b/TelegramUI/ThemeSettingsController.swift index ed723e22ea..a3f1ea5804 100644 --- a/TelegramUI/ThemeSettingsController.swift +++ b/TelegramUI/ThemeSettingsController.swift @@ -318,27 +318,46 @@ public func themeSettingsController(context: AccountContext) -> ViewController { let previousTheme = Atomic(value: nil) let signal = combineLatest(context.sharedContext.presentationData, context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.presentationThemeSettings])) - |> deliverOnMainQueue - |> map { presentationData, sharedData -> (ItemListControllerState, (ItemListNodeState, ThemeSettingsControllerEntry.ItemGenerationArguments)) in - let theme: PresentationTheme - let fontSize: PresentationFontSize - let wallpaper: TelegramWallpaper - let strings: PresentationStrings - let dateTimeFormat: PresentationDateTimeFormat - let disableAnimations: Bool - - let settings = (sharedData.entries[ApplicationSpecificSharedDataKeys.presentationThemeSettings] as? PresentationThemeSettings) ?? PresentationThemeSettings.defaultSettings - switch settings.theme { - case let .builtin(reference): - switch reference { - case .dayClassic: - theme = defaultPresentationTheme - case .nightGrayscale: - theme = defaultDarkPresentationTheme - case .nightAccent: - theme = defaultDarkAccentPresentationTheme - case .day: - theme = makeDefaultDayPresentationTheme(accentColor: settings.themeAccentColor ?? defaultDayAccentColor) + |> deliverOnMainQueue + |> map { presentationData, sharedData -> (ItemListControllerState, (ItemListNodeState, ThemeSettingsControllerEntry.ItemGenerationArguments)) in + let theme: PresentationTheme + let fontSize: PresentationFontSize + let wallpaper: TelegramWallpaper + let strings: PresentationStrings + let dateTimeFormat: PresentationDateTimeFormat + let disableAnimations: Bool + + let settings = (sharedData.entries[ApplicationSpecificSharedDataKeys.presentationThemeSettings] as? PresentationThemeSettings) ?? PresentationThemeSettings.defaultSettings + switch settings.theme { + case let .builtin(reference): + switch reference { + case .dayClassic: + theme = defaultPresentationTheme + case .nightGrayscale: + theme = defaultDarkPresentationTheme + case .nightAccent: + theme = defaultDarkAccentPresentationTheme + case .day: + theme = makeDefaultDayPresentationTheme(accentColor: settings.themeAccentColor ?? defaultDayAccentColor, serviceBackgroundColor: defaultServiceBackgroundColor) + } + } + wallpaper = settings.chatWallpaper + fontSize = settings.fontSize + + if let localizationSettings = preferences.values[localizationSettingsKey] as? LocalizationSettings { + strings = PresentationStrings(primaryComponent: PresentationStringsComponent(languageCode: localizationSettings.primaryComponent.languageCode, localizedName: localizationSettings.primaryComponent.localizedName, pluralizationRulesCode: localizationSettings.primaryComponent.customPluralizationCode, dict: dictFromLocalization(localizationSettings.primaryComponent.localization)), secondaryComponent: localizationSettings.secondaryComponent.flatMap({ PresentationStringsComponent(languageCode: $0.languageCode, localizedName: $0.localizedName, pluralizationRulesCode: $0.customPluralizationCode, dict: dictFromLocalization($0.localization)) })) + } else { + strings = defaultPresentationStrings + } + + dateTimeFormat = presentationData.dateTimeFormat + disableAnimations = settings.disableAnimations + + let controllerState = ItemListControllerState(theme: presentationData.theme, title: .text(presentationData.strings.Appearance_Title), leftNavigationButton: nil, rightNavigationButton: nil, backNavigationButton: ItemListBackButton(title: strings.Common_Back)) + let listState = ItemListNodeState(entries: themeSettingsControllerEntries(presentationData: presentationData, theme: theme, themeAccentColor: settings.themeAccentColor, autoNightSettings: settings.automaticThemeSwitchSetting, strings: presentationData.strings, wallpaper: wallpaper, fontSize: fontSize, dateTimeFormat: dateTimeFormat, disableAnimations: disableAnimations), style: .blocks, animateChanges: false) + + if previousTheme.swap(theme)?.name != theme.name { + presentControllerImpl?(ThemeSettingsCrossfadeController()) } } wallpaper = settings.chatWallpaper