diff --git a/TelegramUI/ActivityIndicator.swift b/TelegramUI/ActivityIndicator.swift index 0d95e78805..6ed06cb267 100644 --- a/TelegramUI/ActivityIndicator.swift +++ b/TelegramUI/ActivityIndicator.swift @@ -37,6 +37,19 @@ final class ActivityIndicator: ASDisplayNode { case let .custom(color, diameter, lineWidth): self.indicatorNode.image = generateIndefiniteActivityIndicatorImage(color: color, diameter: diameter, lineWidth: lineWidth) } + + switch self.type { + case let .navigationAccent(theme): + self.indicatorView?.color = theme.rootController.navigationBar.controlColor + case let .custom(color, diameter, lineWidth): + if color.isEqual(UIColor(rgb: 0x007ee5)) { + self.indicatorView?.color = .gray + } else if color.isEqual(UIColor(rgb: 0x000000)) { + self.indicatorView?.color = .gray + } else { + self.indicatorView?.color = color + } + } } } @@ -51,6 +64,7 @@ final class ActivityIndicator: ASDisplayNode { private let speed: ActivityIndicatorSpeed private let indicatorNode: ASImageNode + private var indicatorView: UIActivityIndicatorView? init(type: ActivityIndicatorType, speed: ActivityIndicatorSpeed = .regular) { self.type = type @@ -70,15 +84,38 @@ final class ActivityIndicator: ASDisplayNode { super.init() - self.isLayerBacked = true + //self.isLayerBacked = true - self.addSubnode(self.indicatorNode) + //self.addSubnode(self.indicatorNode) + } + + override func didLoad() { + super.didLoad() + + let indicatorView = UIActivityIndicatorView(activityIndicatorStyle: .whiteLarge) + switch self.type { + case let .navigationAccent(theme): + indicatorView.color = theme.rootController.navigationBar.controlColor + case let .custom(color, diameter, lineWidth): + if color.isEqual(UIColor(rgb: 0x007ee5)) { + indicatorView.color = .gray + } else { + indicatorView.color = color + } + } + self.indicatorView = indicatorView + self.view.addSubview(indicatorView) + let size = self.bounds.size + if !size.width.isZero { + self.layoutContents(size: size) + } } private var isAnimating = false { didSet { if self.isAnimating != oldValue { if self.isAnimating { + self.indicatorView?.startAnimating() let basicAnimation = CABasicAnimation(keyPath: "transform.rotation.z") basicAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut) switch self.speed { @@ -95,6 +132,7 @@ final class ActivityIndicator: ASDisplayNode { self.indicatorNode.layer.add(basicAnimation, forKey: "progressRotation") } else { + self.indicatorView?.stopAnimating() self.indicatorNode.layer.removeAnimation(forKey: "progressRotation") } } @@ -133,6 +171,10 @@ final class ActivityIndicator: ASDisplayNode { let size = self.bounds.size + self.layoutContents(size: size) + } + + private func layoutContents(size: CGSize) { let indicatorSize: CGSize switch self.type { case .navigationAccent: @@ -141,5 +183,11 @@ final class ActivityIndicator: ASDisplayNode { indicatorSize = CGSize(width: diameter, height: diameter) } self.indicatorNode.frame = CGRect(origin: CGPoint(x: floor((size.width - indicatorSize.width) / 2.0), y: floor((size.height - indicatorSize.height) / 2.0)), size: indicatorSize) + if let indicatorView = self.indicatorView { + let intrinsicSize = indicatorView.bounds.size + self.subnodeTransform = CATransform3DMakeScale(indicatorSize.width / intrinsicSize.width, indicatorSize.height / intrinsicSize.height, 1.0) + //indicatorView.transform = CGAffineTransform(scaleX: indicatorSize.width / intrinsicSize.width, y: indicatorSize.height / intrinsicSize.height) + indicatorView.center = CGPoint(x: size.width / 2.0, y: size.height / 2.0) + } } } diff --git a/TelegramUI/ChatController.swift b/TelegramUI/ChatController.swift index 8740d3f44a..55a308d608 100644 --- a/TelegramUI/ChatController.swift +++ b/TelegramUI/ChatController.swift @@ -3033,11 +3033,17 @@ public final class ChatController: TelegramController, KeyShortcutResponder, UIV linkPreviews = .single(true) } } - self.urlPreviewQueryState = (updatedUrlPreviewUrl, (combineLatest(updatedUrlPreviewSignal, linkPreviews) |> deliverOnMainQueue).start(next: { [weak self] (result, enabled) in - var result = result - if !enabled { - result = { _ in return nil } + let filteredPreviewSignal = linkPreviews + |> take(1) + |> mapToSignal { value -> Signal<(TelegramMediaWebpage?) -> TelegramMediaWebpage?, NoError> in + if value { + return updatedUrlPreviewSignal + } else { + return .single({ _ in return nil }) } + } + + self.urlPreviewQueryState = (updatedUrlPreviewUrl, (filteredPreviewSignal |> deliverOnMainQueue).start(next: { [weak self] (result) in if let strongSelf = self { if Thread.isMainThread && inScope { inScope = false diff --git a/TelegramUI/ChatListItem.swift b/TelegramUI/ChatListItem.swift index 17b7e4f7ea..1cd5893c9a 100644 --- a/TelegramUI/ChatListItem.swift +++ b/TelegramUI/ChatListItem.swift @@ -943,7 +943,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode { strongSelf.titleNode.frame = CGRect(origin: CGPoint(x: contentRect.origin.x + titleOffset, y: contentRect.origin.y + UIScreenPixel), size: titleLayout.size) let authorNodeFrame = CGRect(origin: CGPoint(x: contentRect.origin.x - 1.0, y: contentRect.minY + titleLayout.size.height), size: authorLayout.size) strongSelf.authorNode.frame = authorNodeFrame - let textNodeFrame = CGRect(origin: CGPoint(x: contentRect.origin.x - 1.0, y: contentRect.minY + titleLayout.size.height - 1.0 + UIScreenPixel + (authorLayout.size.height.isZero ? 0.0 : (authorLayout.size.height - 3.0))), size: textLayout.size) + let textNodeFrame = CGRect(origin: CGPoint(x: contentRect.origin.x, y: contentRect.minY + titleLayout.size.height - 1.0 + UIScreenPixel + (authorLayout.size.height.isZero ? 0.0 : (authorLayout.size.height - 3.0))), size: textLayout.size) strongSelf.textNode.frame = textNodeFrame var animateInputActivitiesFrame = false @@ -1096,7 +1096,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode { transition.updateFrame(node: self.inputActivitiesNode, frame: CGRect(origin: CGPoint(x: contentRect.origin.x, y: self.inputActivitiesNode.frame.minY), size: self.inputActivitiesNode.bounds.size)) let textFrame = self.textNode.frame - transition.updateFrame(node: self.textNode, frame: CGRect(origin: CGPoint(x: contentRect.origin.x - 1.0, y: textFrame.origin.y), size: textFrame.size)) + transition.updateFrame(node: self.textNode, frame: CGRect(origin: CGPoint(x: contentRect.origin.x, y: textFrame.origin.y), size: textFrame.size)) let dateFrame = self.dateNode.frame transition.updateFrame(node: self.dateNode, frame: CGRect(origin: CGPoint(x: contentRect.origin.x + contentRect.size.width - dateFrame.size.width, y: dateFrame.minY), size: dateFrame.size)) diff --git a/TelegramUI/ChatMessageDateHeader.swift b/TelegramUI/ChatMessageDateHeader.swift index 38d928f639..e33f778235 100644 --- a/TelegramUI/ChatMessageDateHeader.swift +++ b/TelegramUI/ChatMessageDateHeader.swift @@ -180,13 +180,16 @@ final class ChatMessageDateHeaderNode: ListViewItemHeaderNode { override func updateLayout(size: CGSize, leftInset: CGFloat, rightInset: CGFloat) { //let labelLayout = TextNode.asyncLayout(self.labelNode) - let labelSize = self.labelNode.bounds.size - let backgroundSize = CGSize(width: labelSize.width + 8.0 + 8.0, height: 26.0) + let chatDateSize: CGFloat = 20.0 + let chatDateInset: CGFloat = 6.0 - let backgroundFrame = CGRect(origin: CGPoint(x: floorToScreenPixels((size.width - backgroundSize.width) / 2.0), y: (34.0 - 26.0) / 2.0), size: backgroundSize) + let labelSize = self.labelNode.bounds.size + let backgroundSize = CGSize(width: labelSize.width + chatDateInset * 2.0, height: chatDateSize) + + let backgroundFrame = CGRect(origin: CGPoint(x: floorToScreenPixels((size.width - backgroundSize.width) / 2.0), y: (34.0 - chatDateSize) / 2.0), size: backgroundSize) self.stickBackgroundNode.frame = CGRect(origin: CGPoint(), size: backgroundFrame.size) self.backgroundNode.frame = backgroundFrame - self.labelNode.frame = CGRect(origin: CGPoint(x: backgroundFrame.origin.x + 8.0, y: backgroundFrame.origin.y + floorToScreenPixels((backgroundSize.height - labelSize.height) / 2.0)), size: labelSize) + self.labelNode.frame = CGRect(origin: CGPoint(x: backgroundFrame.origin.x + chatDateInset, y: backgroundFrame.origin.y + floorToScreenPixels((backgroundSize.height - labelSize.height) / 2.0)), size: labelSize) } override func updateStickDistanceFactor(_ factor: CGFloat, transition: ContainedViewLayoutTransition) { diff --git a/TelegramUI/InAppNotificationSettings.swift b/TelegramUI/InAppNotificationSettings.swift index 04d89dbda9..f371ff6593 100644 --- a/TelegramUI/InAppNotificationSettings.swift +++ b/TelegramUI/InAppNotificationSettings.swift @@ -37,8 +37,8 @@ public struct InAppNotificationSettings: PreferencesEntry, Equatable { self.playSounds = decoder.decodeInt32ForKey("s", orElse: 0) != 0 self.vibrate = decoder.decodeInt32ForKey("v", orElse: 0) != 0 self.displayPreviews = decoder.decodeInt32ForKey("p", orElse: 0) != 0 - self.totalUnreadCountDisplayStyle = TotalUnreadCountDisplayStyle(rawValue: decoder.decodeInt32ForKey("tds", orElse: 0)) ?? .filtered - self.totalUnreadCountDisplayCategory = TotalUnreadCountDisplayCategory(rawValue: decoder.decodeInt32ForKey("totalUnreadCountDisplayCategory", orElse: 0)) ?? .messages + self.totalUnreadCountDisplayStyle = TotalUnreadCountDisplayStyle(rawValue: decoder.decodeInt32ForKey("tds", orElse: 1)) ?? .raw + self.totalUnreadCountDisplayCategory = TotalUnreadCountDisplayCategory(rawValue: decoder.decodeInt32ForKey("totalUnreadCountDisplayCategory", orElse: 1)) ?? .messages self.displayNameOnLockscreen = decoder.decodeInt32ForKey("displayNameOnLockscreen", orElse: 1) != 0 } diff --git a/TelegramUI/ManagedAudioSession.swift b/TelegramUI/ManagedAudioSession.swift index b9f7803486..06b530183e 100644 --- a/TelegramUI/ManagedAudioSession.swift +++ b/TelegramUI/ManagedAudioSession.swift @@ -663,7 +663,10 @@ public final class ManagedAudioSession { if let routes = AVAudioSession.sharedInstance().availableInputs { for route in routes { if route.portType == AVAudioSessionPortBuiltInMic { - let _ = try? AVAudioSession.sharedInstance().setPreferredInput(route) + if type == .record && self.isHeadsetPluggedInValue { + } else { + let _ = try? AVAudioSession.sharedInstance().setPreferredInput(route) + } break } } diff --git a/TelegramUI/PresentationThemeEssentialGraphics.swift b/TelegramUI/PresentationThemeEssentialGraphics.swift index 7eac1858eb..69547bd8b6 100644 --- a/TelegramUI/PresentationThemeEssentialGraphics.swift +++ b/TelegramUI/PresentationThemeEssentialGraphics.swift @@ -158,17 +158,18 @@ public final class PrincipalThemeEssentialGraphics { self.mediaImpressionIcon = generateTintedImage(image: impressionCountImage, color: .white)! self.freeImpressionIcon = generateTintedImage(image: impressionCountImage, color: theme.serviceMessage.serviceMessagePrimaryTextColor)! - self.dateStaticBackground = generateImage(CGSize(width: 26.0, height: 26.0), contextGenerator: { size, context -> Void in + let chatDateSize: CGFloat = 20.0 + self.dateStaticBackground = generateImage(CGSize(width: chatDateSize, height: chatDateSize), contextGenerator: { size, context -> Void in context.clear(CGRect(origin: CGPoint(), size: size)) context.setFillColor(theme.serviceMessage.dateFillStaticColor.cgColor) context.fillEllipse(in: CGRect(origin: CGPoint(), size: size)) - })!.stretchableImage(withLeftCapWidth: 13, topCapHeight: 13) + })!.stretchableImage(withLeftCapWidth: Int(chatDateSize) / 2, topCapHeight: Int(chatDateSize) / 2) - self.dateFloatingBackground = generateImage(CGSize(width: 26.0, height: 26.0), contextGenerator: { size, context -> Void in + self.dateFloatingBackground = generateImage(CGSize(width: chatDateSize, height: chatDateSize), contextGenerator: { size, context -> Void in context.clear(CGRect(origin: CGPoint(), size: size)) context.setFillColor(theme.serviceMessage.dateFillFloatingColor.cgColor) context.fillEllipse(in: CGRect(origin: CGPoint(), size: size)) - })!.stretchableImage(withLeftCapWidth: 13, topCapHeight: 13) + })!.stretchableImage(withLeftCapWidth: Int(chatDateSize) / 2, topCapHeight: Int(chatDateSize) / 2) self.radialIndicatorFileIconIncoming = generateTintedImage(image: UIImage(bundleImageName: "Chat/Message/RadialProgressIconDocumentIncoming"), color: incoming.fill)! self.radialIndicatorFileIconOutgoing = generateTintedImage(image: UIImage(bundleImageName: "Chat/Message/RadialProgressIconDocumentIncoming"), color: outgoing.fill)!