From a7a090cfcdd7310830037b1eb1c0fa5ecf4fae6d Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Mon, 29 Apr 2019 21:35:57 +0400 Subject: [PATCH] UI fixes --- TelegramUI/ChatListBadgeNode.swift | 9 ++++++++- TelegramUI/ChatListNode.swift | 8 ++++---- TelegramUI/ChatMessageInteractiveMediaNode.swift | 15 ++++++++++----- TelegramUI/SelectablePeerNode.swift | 2 +- TelegramUI/ShareControllerPeerGridItem.swift | 1 - 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/TelegramUI/ChatListBadgeNode.swift b/TelegramUI/ChatListBadgeNode.swift index dcc0bfcb2d..f31695d044 100644 --- a/TelegramUI/ChatListBadgeNode.swift +++ b/TelegramUI/ChatListBadgeNode.swift @@ -42,6 +42,8 @@ final class ChatListBadgeNode: ASDisplayNode { private var text: String? private var content: ChatListBadgeContent? + private var isHiddenInternal = false + override init() { self.backgroundNode = ASImageNode() self.backgroundNode.isLayerBacked = true @@ -114,6 +116,7 @@ final class ChatListBadgeNode: ASDisplayNode { } if currentIsEmpty && !nextIsEmpty { + strongSelf.isHiddenInternal = false strongSelf.layer.animateScale(from: 0.0001, to: 1.2, duration: 0.2, removeOnCompletion: false, completion: { [weak self] finished in if let strongSelf = self { strongSelf.layer.animateScale(from: 1.15, to: 1.0, duration: 0.12, removeOnCompletion: false) @@ -121,6 +124,7 @@ final class ChatListBadgeNode: ASDisplayNode { }) } else if !currentIsEmpty && !nextIsEmpty && currentContent?.text != content.text { var animateScale = true + strongSelf.isHiddenInternal = false if let currentText = currentContent?.text, let currentValue = Int(currentText), let text = content.text, let value = Int(text) { if value < currentValue { animateScale = false @@ -148,7 +152,8 @@ final class ChatListBadgeNode: ASDisplayNode { snapshotView.layer.animatePosition(from: CGPoint(), to: CGPoint(x: (badgeWidth - previousBadgeWidth) / 2.0, y: -8.0), duration: 0.15, timingFunction: kCAMediaTimingFunctionEaseInEaseOut, removeOnCompletion: false, additive: true) } animateTextNode = true - } else if !currentIsEmpty && nextIsEmpty { + } else if !currentIsEmpty && nextIsEmpty && !strongSelf.isHiddenInternal { + strongSelf.isHiddenInternal = true strongSelf.layer.animateScale(from: 1.0, to: 0.0001, duration: 0.12, removeOnCompletion: true, completion: { [weak self] finished in if let strongSelf = self { strongSelf.isHidden = true @@ -158,8 +163,10 @@ final class ChatListBadgeNode: ASDisplayNode { } else { if case .none = content { strongSelf.isHidden = true + strongSelf.isHiddenInternal = true } else { strongSelf.isHidden = false + strongSelf.isHiddenInternal = false } if case .text = content { strongSelf.textNode.alpha = 1.0 diff --git a/TelegramUI/ChatListNode.swift b/TelegramUI/ChatListNode.swift index d6712ab77d..af0dc37758 100644 --- a/TelegramUI/ChatListNode.swift +++ b/TelegramUI/ChatListNode.swift @@ -293,7 +293,7 @@ enum ChatListNodeScrollPosition { case top } -enum ChatListNodeEmtpyState: Equatable { +enum ChatListNodeEmptyState: Equatable { case notEmpty(containsChats: Bool) case empty(isLoading: Bool) } @@ -365,8 +365,8 @@ final class ChatListNode: ListView { } } - var isEmptyUpdated: ((ChatListNodeEmtpyState) -> Void)? - private var currentIsEmptyState: ChatListNodeEmtpyState? + var isEmptyUpdated: ((ChatListNodeEmptyState) -> Void)? + private var currentIsEmptyState: ChatListNodeEmptyState? var addedVisibleChatsWithPeerIds: (([PeerId]) -> Void)? @@ -1141,7 +1141,7 @@ final class ChatListNode: ListView { strongSelf._ready.set(true) } - let isEmptyState: ChatListNodeEmtpyState + let isEmptyState: ChatListNodeEmptyState if transition.chatListView.isLoading { isEmptyState = .empty(isLoading: true) } else if transition.chatListView.filteredEntries.isEmpty { diff --git a/TelegramUI/ChatMessageInteractiveMediaNode.swift b/TelegramUI/ChatMessageInteractiveMediaNode.swift index c8be128641..cfd1a75ed5 100644 --- a/TelegramUI/ChatMessageInteractiveMediaNode.swift +++ b/TelegramUI/ChatMessageInteractiveMediaNode.swift @@ -785,6 +785,7 @@ final class ChatMessageInteractiveMediaNode: ASDisplayNode { } } + var game: TelegramMediaGame? var webpage: TelegramMediaWebpage? var invoice: TelegramMediaInvoice? for media in message.media { @@ -792,6 +793,8 @@ final class ChatMessageInteractiveMediaNode: ASDisplayNode { webpage = media } else if let media = media as? TelegramMediaInvoice { invoice = media + } else if let media = media as? TelegramMediaGame { + game = media } } @@ -904,6 +907,8 @@ final class ChatMessageInteractiveMediaNode: ASDisplayNode { fetchStatus = actualFetchStatus } + let gifTitle = game != nil ? strings.Message_Game.uppercased() : strings.Message_Animation.uppercased() + switch fetchStatus { case let .Fetching(_, progress): let adjustedProgress = max(progress, 0.027) @@ -922,10 +927,10 @@ final class ChatMessageInteractiveMediaNode: ASDisplayNode { if let size = file.size { let sizeString = "\(dataSizeString(Int(Float(size) * progress), forceDecimal: true, decimalSeparator: decimalSeparator)) / \(dataSizeString(size, forceDecimal: true, decimalSeparator: decimalSeparator))" if file.isAnimated && (!automaticDownload || !automaticPlayback) { - badgeContent = .mediaDownload(backgroundColor: bubbleTheme.mediaDateAndStatusFillColor, foregroundColor: bubbleTheme.mediaDateAndStatusTextColor, duration: "GIF " + sizeString, size: nil, muted: false, active: false) + badgeContent = .mediaDownload(backgroundColor: bubbleTheme.mediaDateAndStatusFillColor, foregroundColor: bubbleTheme.mediaDateAndStatusTextColor, duration: "\(gifTitle) " + sizeString, size: nil, muted: false, active: false) } else if let duration = file.duration, !message.flags.contains(.Unsent) { - let durationString = file.isAnimated ? "GIF" : stringForDuration(playerDuration > 0 ? playerDuration : duration, position: playerPosition) + let durationString = file.isAnimated ? gifTitle : stringForDuration(playerDuration > 0 ? playerDuration : duration, position: playerPosition) if isMediaStreamable(message: message, media: file) { badgeContent = .mediaDownload(backgroundColor: bubbleTheme.mediaDateAndStatusFillColor, foregroundColor: bubbleTheme.mediaDateAndStatusTextColor, duration: durationString, size: active ? sizeString : nil, muted: muted, active: active) mediaDownloadState = .fetching(progress: automaticPlayback ? nil : adjustedProgress) @@ -1019,17 +1024,17 @@ final class ChatMessageInteractiveMediaNode: ASDisplayNode { } } if let file = media as? TelegramMediaFile, let duration = file.duration { - let durationString = file.isAnimated ? "GIF" : stringForDuration(playerDuration > 0 ? playerDuration : duration, position: playerPosition) + let durationString = file.isAnimated ? gifTitle : stringForDuration(playerDuration > 0 ? playerDuration : duration, position: playerPosition) badgeContent = .mediaDownload(backgroundColor: bubbleTheme.mediaDateAndStatusFillColor, foregroundColor: bubbleTheme.mediaDateAndStatusTextColor, duration: durationString, size: nil, muted: muted, active: false) } case .Remote: state = .download(bubbleTheme.mediaOverlayControlForegroundColor) if let file = self.media as? TelegramMediaFile { if file.isAnimated && (!automaticDownload || !automaticPlayback) { - let string = "GIF " + dataSizeString(file.size ?? 0, decimalSeparator: decimalSeparator) + let string = "\(gifTitle) " + dataSizeString(file.size ?? 0, decimalSeparator: decimalSeparator) badgeContent = .mediaDownload(backgroundColor: bubbleTheme.mediaDateAndStatusFillColor, foregroundColor: bubbleTheme.mediaDateAndStatusTextColor, duration: string, size: nil, muted: false, active: false) } else { - let durationString = file.isAnimated ? "GIF" : stringForDuration(playerDuration > 0 ? playerDuration : (file.duration ?? 0), position: playerPosition) + let durationString = file.isAnimated ? gifTitle : stringForDuration(playerDuration > 0 ? playerDuration : (file.duration ?? 0), position: playerPosition) if wideLayout { if isMediaStreamable(message: message, media: file) { state = automaticPlayback ? .none : .play(bubbleTheme.mediaOverlayControlForegroundColor) diff --git a/TelegramUI/SelectablePeerNode.swift b/TelegramUI/SelectablePeerNode.swift index 231e94e091..382ee65a11 100644 --- a/TelegramUI/SelectablePeerNode.swift +++ b/TelegramUI/SelectablePeerNode.swift @@ -232,7 +232,7 @@ final class SelectablePeerNode: ASDisplayNode { let avatarFrame = self.avatarNode.frame - self.onlineNode.frame = CGRect(origin: CGPoint(x: avatarFrame.width - self.onlineNode.frame.width + 2.0, y: avatarFrame.height - self.onlineNode.frame.height + 2.0), size: self.onlineNode.frame.size) + self.onlineNode.frame = CGRect(origin: CGPoint(x: avatarFrame.maxX - self.onlineNode.frame.width + 9.0, y: avatarFrame.maxY - self.onlineNode.frame.height + 2.0), size: self.onlineNode.frame.size) if let checkView = self.checkView { let checkSize = checkView.bounds.size diff --git a/TelegramUI/ShareControllerPeerGridItem.swift b/TelegramUI/ShareControllerPeerGridItem.swift index 5276d04ec2..2fc1767fc8 100644 --- a/TelegramUI/ShareControllerPeerGridItem.swift +++ b/TelegramUI/ShareControllerPeerGridItem.swift @@ -126,7 +126,6 @@ final class ShareControllerPeerGridItem: GridItem { final class ShareControllerPeerGridItemNode: GridItemNode { private var currentState: (Account, RenderedPeer, Bool)? private let peerNode: SelectablePeerNode - var controllerInteraction: ShareControllerInteraction?