Various UI fixes

This commit is contained in:
Ilya Laktyushin 2019-08-25 21:46:01 +03:00
parent 9b7bbc5ae7
commit dd04bdb4e2
14 changed files with 59 additions and 52 deletions

View File

@ -63,7 +63,7 @@ public func peerAvatarImageData(account: Account, peer: Peer, authorOfMessage: M
}
}
public func peerAvatarImage(account: Account, peer: Peer, authorOfMessage: MessageReference?, representation: TelegramMediaImageRepresentation?, displayDimensions: CGSize = CGSize(width: 60.0, height: 60.0), emptyColor: UIColor? = nil, synchronousLoad: Bool = false) -> Signal<UIImage?, NoError>? {
public func peerAvatarImage(account: Account, peer: Peer, authorOfMessage: MessageReference?, representation: TelegramMediaImageRepresentation?, displayDimensions: CGSize = CGSize(width: 60.0, height: 60.0), inset: CGFloat = 0.0, emptyColor: UIColor? = nil, synchronousLoad: Bool = false) -> Signal<UIImage?, NoError>? {
if let imageData = peerAvatarImageData(account: account, peer: peer, authorOfMessage: authorOfMessage, representation: representation, synchronousLoad: synchronousLoad) {
return imageData
|> mapToSignal { data -> Signal<UIImage?, NoError> in
@ -74,21 +74,22 @@ public func peerAvatarImage(account: Account, peer: Peer, authorOfMessage: Messa
return .single(generateImage(displayDimensions, contextGenerator: { size, context -> Void in
if let data = data {
if let imageSource = CGImageSourceCreateWithData(data as CFData, nil), let dataImage = CGImageSourceCreateImageAtIndex(imageSource, 0, nil) {
context.clear(CGRect(origin: CGPoint(), size: displayDimensions))
context.setBlendMode(.copy)
context.draw(dataImage, in: CGRect(origin: CGPoint(), size: displayDimensions))
context.draw(dataImage, in: CGRect(origin: CGPoint(), size: displayDimensions).insetBy(dx: inset, dy: inset))
context.setBlendMode(.destinationOut)
context.draw(roundCorners.cgImage!, in: CGRect(origin: CGPoint(), size: displayDimensions))
context.draw(roundCorners.cgImage!, in: CGRect(origin: CGPoint(), size: displayDimensions).insetBy(dx: inset, dy: inset))
} else {
if let emptyColor = emptyColor {
context.clear(CGRect(origin: CGPoint(), size: displayDimensions))
context.setFillColor(emptyColor.cgColor)
context.fillEllipse(in: CGRect(origin: CGPoint(), size: displayDimensions))
context.fillEllipse(in: CGRect(origin: CGPoint(), size: displayDimensions).insetBy(dx: inset, dy: inset))
}
}
} else if let emptyColor = emptyColor {
context.clear(CGRect(origin: CGPoint(), size: displayDimensions))
context.setFillColor(emptyColor.cgColor)
context.fillEllipse(in: CGRect(origin: CGPoint(), size: displayDimensions))
context.fillEllipse(in: CGRect(origin: CGPoint(), size: displayDimensions).insetBy(dx: inset, dy: inset))
}
}))
}

View File

@ -915,9 +915,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
if let mutedCount = unreadCount.mutedCount, mutedCount > 0 {
let mutedUnreadCountText = compactNumericCountString(Int(mutedCount), decimalSeparator: item.presentationData.dateTimeFormat.decimalSeparator)
currentMentionBadgeImage = PresentationResourcesChatList.badgeBackgroundInactive(item.presentationData.theme)
mentionBadgeContent = .text(NSAttributedString(string: mutedUnreadCountText, font: badgeFont, textColor: theme.unreadBadgeInactiveTextColor))
}
}
@ -1331,8 +1329,8 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
if let currentMutedIconImage = currentMutedIconImage {
strongSelf.mutedIconNode.image = currentMutedIconImage
strongSelf.mutedIconNode.isHidden = false
transition.updateFrame(node: strongSelf.mutedIconNode, frame: CGRect(origin: CGPoint(x: nextTitleIconOrigin, y: contentRect.origin.y + 5.0), size: currentMutedIconImage.size))
nextTitleIconOrigin += currentMutedIconImage.size.width + 3.0
transition.updateFrame(node: strongSelf.mutedIconNode, frame: CGRect(origin: CGPoint(x: nextTitleIconOrigin - 4.0, y: contentRect.origin.y - 2.0), size: currentMutedIconImage.size))
nextTitleIconOrigin += currentMutedIconImage.size.width + 1.0
} else {
strongSelf.mutedIconNode.image = nil
strongSelf.mutedIconNode.isHidden = true

View File

@ -434,10 +434,10 @@ class TabBarNode: ASDisplayNode {
let backgroundSize = CGSize(width: hasSingleLetterValue ? 18.0 : max(18.0, badgeSize.width + 10.0 + 1.0), height: 18.0)
let backgroundFrame: CGRect
if horizontal {
backgroundFrame = CGRect(origin: CGPoint(x: originX + 8.0, y: 2.0), size: backgroundSize)
backgroundFrame = CGRect(origin: CGPoint(x: originX + 10.0, y: 2.0), size: backgroundSize)
} else {
let contentWidth = node.contentWidth ?? node.frame.width
backgroundFrame = CGRect(origin: CGPoint(x: floor(originX + node.frame.width / 2.0) - 1.0 + contentWidth - backgroundSize.width - 1.0, y: 2.0), size: backgroundSize)
backgroundFrame = CGRect(origin: CGPoint(x: floor(originX + node.frame.width / 2.0) + contentWidth - backgroundSize.width - 5.0, y: 2.0), size: backgroundSize)
}
transition.updateFrame(node: container.badgeContainerNode, frame: backgroundFrame)
container.badgeBackgroundNode.frame = CGRect(origin: CGPoint(), size: backgroundFrame.size)

View File

@ -60,9 +60,9 @@ private func displayLineFrame(frame: CGRect, isRTL: Bool, boundingRect: CGRect,
return frame
}
var lineFrame = frame
let intersectionFrame = lineFrame.offsetBy(dx: 0.0, dy: -lineFrame.height)
if isRTL {
lineFrame.origin.x = max(0.0, floor(boundingRect.width - lineFrame.size.width))
let intersectionFrame = lineFrame.offsetBy(dx: 0.0, dy: -lineFrame.height / 4.5)
if let topRight = cutout?.topRight {
let topRightRect = CGRect(origin: CGPoint(x: boundingRect.width - topRight.width, y: 0.0), size: topRight)
if intersectionFrame.intersects(topRightRect) {
@ -225,9 +225,6 @@ public final class TextNodeLayout: NSObject {
case .center:
lineFrame.origin.x = floor((self.size.width - lineFrame.size.width) / 2.0)
case .natural:
if line.isRTL {
lineFrame.origin.x = self.size.width - lineFrame.size.width
}
lineFrame = displayLineFrame(frame: lineFrame, isRTL: line.isRTL, boundingRect: CGRect(origin: CGPoint(), size: self.size), cutout: self.cutout)
default:
break
@ -296,9 +293,6 @@ public final class TextNodeLayout: NSObject {
case .center:
lineFrame.origin.x = floor((self.size.width - lineFrame.size.width) / 2.0)
case .natural:
if line.isRTL {
lineFrame.origin.x = self.size.width - lineFrame.size.width
}
lineFrame = displayLineFrame(frame: lineFrame, isRTL: line.isRTL, boundingRect: CGRect(origin: CGPoint(), size: self.size), cutout: self.cutout)
default:
break
@ -374,9 +368,6 @@ public final class TextNodeLayout: NSObject {
case .center:
lineFrame.origin.x = floor((self.size.width - lineFrame.size.width) / 2.0)
case .natural:
if line.isRTL {
lineFrame.origin.x = floor(self.size.width - lineFrame.size.width)
}
lineFrame = displayLineFrame(frame: lineFrame, isRTL: line.isRTL, boundingRect: CGRect(origin: CGPoint(), size: self.size), cutout: self.cutout)
default:
break

View File

@ -1220,7 +1220,7 @@ public func settingsController(context: AccountContext, accountManager: AccountM
|> distinctUntilChanged(isEqual: { $0?.0 === $1?.0 && arePeersEqual($0?.1, $1?.1) })
|> mapToSignal { primary -> Signal<UIImage?, NoError> in
if let primary = primary {
if let signal = peerAvatarImage(account: primary.0, peer: primary.1, authorOfMessage: nil, representation: primary.1.profileImageRepresentations.first, displayDimensions: CGSize(width: 25.0, height: 25.0), emptyColor: nil, synchronousLoad: false) {
if let signal = peerAvatarImage(account: primary.0, peer: primary.1, authorOfMessage: nil, representation: primary.1.profileImageRepresentations.first, displayDimensions: CGSize(width: 31.0, height: 31.0), inset: 3.0, emptyColor: nil, synchronousLoad: false) {
return signal
|> map { image -> UIImage? in
return image.flatMap { image -> UIImage in
@ -1229,9 +1229,10 @@ public func settingsController(context: AccountContext, accountManager: AccountM
}
} else {
return Signal { subscriber in
let size = CGSize(width: 25.0, height: 25.0)
let size = CGSize(width: 31.0, height: 31.0)
let image = generateImage(size, rotatedContext: { size, context in
context.clear(CGRect(origin: CGPoint(), size: size))
context.translateBy(x: 3.0, y: 3.0)
drawPeerAvatarLetters(context: context, size: size, font: avatarFont, letters: primary.1.displayLetters, accountPeerId: primary.1.id, peerId: primary.1.id)
})?.withRenderingMode(.alwaysOriginal)
subscriber.putNext(image)

View File

@ -92,7 +92,6 @@ public func channelMembers(postbox: Postbox, network: Network, accountPeerId: Pe
if let peer = peers[participant.peerId] {
items.append(RenderedChannelParticipant(participant: participant, peer: peer, peers: peers, presences: presences))
}
}
case .channelParticipantsNotModified:
return nil

View File

@ -286,11 +286,7 @@ extension PeerMessageSound {
case .default:
return nil
case let .bundledModern(id):
if id == 0 {
return "default"
} else {
return "\(id + 100)"
}
return "\(id + 100)"
case let .bundledClassic(id):
return "\(id + 2)"
}

View File

@ -1,12 +1,12 @@
import Foundation
#if os(macOS)
import PostboxMac
import SwiftSignalKitMac
import TelegramApiMac
import PostboxMac
import SwiftSignalKitMac
import TelegramApiMac
#else
import Postbox
import SwiftSignalKit
import TelegramApi
import Postbox
import SwiftSignalKit
import TelegramApi
#endif
final class CachedThemesConfiguration: PostboxCoding {

View File

@ -2,7 +2,7 @@
"images" : [
{
"idiom" : "universal",
"filename" : "ic_addchannel.pdf"
"filename" : "ic_addchannel (2).pdf"
}
],
"info" : {

View File

@ -198,7 +198,7 @@ final class ChatChannelSubscriberInputPanelNode: ChatInputPanelNode {
guard let strongSelf = self, let interfaceState = strongSelf.presentationInterfaceState, let image = strongSelf.badgeBackground.image else {
return
}
let text = "\(value ?? 0)"
let text = compactNumericCountString(value ?? 0, decimalSeparator: interfaceState.dateTimeFormat.decimalSeparator)
strongSelf.badgeText.attributedText = NSAttributedString(string: text, font: badgeFont, textColor: interfaceState.theme.chatList.unreadBadgeActiveTextColor)
let textSize = strongSelf.badgeText.updateLayout(CGSize(width: 100.0, height: 100.0))

View File

@ -1653,24 +1653,35 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
var hasScheduledMessages: Signal<Bool, NoError> = .single(false)
if peerId.namespace == Namespaces.Peer.CloudChannel {
let recentOnlineSignal: Signal<Int32, NoError> = context.account.viewTracker.peerView(peerId)
|> map { view -> Bool in
if let cachedData = view.cachedData as? CachedChannelData, let memberCount = cachedData.participantsSummary.memberCount, memberCount > 50 {
return true
let recentOnlineSignal: Signal<Int32?, NoError> = peerView.get()
|> map { view -> Bool? in
if let cachedData = view.cachedData as? CachedChannelData, let peer = peerViewMainPeer(view) as? TelegramChannel {
if case .broadcast = peer.info {
return nil
} else if let memberCount = cachedData.participantsSummary.memberCount, memberCount > 50 {
return true
} else {
return false
}
} else {
return false
}
}
|> distinctUntilChanged
|> mapToSignal { isLarge -> Signal<Int32, NoError> in
if isLarge {
return context.peerChannelMemberCategoriesContextsManager.recentOnline(postbox: context.account.postbox, network: context.account.network, accountPeerId: context.account.peerId, peerId: peerId)
|> mapToSignal { isLarge -> Signal<Int32?, NoError> in
if let isLarge = isLarge {
if isLarge {
return context.peerChannelMemberCategoriesContextsManager.recentOnline(postbox: context.account.postbox, network: context.account.network, accountPeerId: context.account.peerId, peerId: peerId)
|> map(Optional.init)
} else {
return context.peerChannelMemberCategoriesContextsManager.recentOnlineSmall(postbox: context.account.postbox, network: context.account.network, accountPeerId: context.account.peerId, peerId: peerId)
|> map(Optional.init)
}
} else {
return context.peerChannelMemberCategoriesContextsManager.recentOnlineSmall(postbox: context.account.postbox, network: context.account.network, accountPeerId: context.account.peerId, peerId: peerId)
return .single(nil)
}
}
onlineMemberCount = recentOnlineSignal
|> map(Optional.init)
self.reportIrrelvantGeoNoticePromise.set(context.account.postbox.transaction { transaction -> Bool? in
if let _ = transaction.getNoticeEntry(key: ApplicationSpecificNotice.irrelevantPeerGeoReportKey(peerId: peerId)) as? ApplicationSpecificBoolNotice {
@ -1684,9 +1695,17 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
}
if !isScheduledMessages && peerId.namespace != Namespaces.Peer.SecretChat {
hasScheduledMessages = context.account.viewTracker.scheduledMessagesViewForLocation(chatLocation)
|> map { view, _, _ in
return !view.entries.isEmpty
hasScheduledMessages = peerView.get()
|> take(1)
|> mapToSignal { view -> Signal<Bool, NoError> in
if let peer = peerViewMainPeer(view) as? TelegramChannel, !peer.hasPermission(.sendMessages) {
return .single(false)
} else {
return context.account.viewTracker.scheduledMessagesViewForLocation(chatLocation)
|> map { view, _, _ in
return !view.entries.isEmpty
}
}
}
}

View File

@ -99,7 +99,7 @@ private func peerButtons(_ peer: Peer, interfaceState: ChatPresentationInterface
}
}
private let buttonFont = Font.regular(10.0)
private let buttonFont = Font.medium(10.0)
private final class ChatInfoTitlePanelButtonNode: HighlightableButtonNode {
override init() {

View File

@ -510,11 +510,13 @@ private func trimRangesForChatInputText(_ text: NSAttributedString) -> (Int, Int
var lower = 0
var upper = 0
let trimmedCharacters: [UnicodeScalar] = [" ", "\t", "\n", "\u{200C}"]
let nsString: NSString = text.string as NSString
for i in 0 ..< nsString.length {
if let c = UnicodeScalar(nsString.character(at: i)) {
if c == " " as UnicodeScalar || c == "\t" as UnicodeScalar || c == "\n" as UnicodeScalar {
if trimmedCharacters.contains(c) {
lower += 1
} else {
break
@ -527,7 +529,7 @@ private func trimRangesForChatInputText(_ text: NSAttributedString) -> (Int, Int
if lower != nsString.length {
for i in (lower ..< nsString.length).reversed() {
if let c = UnicodeScalar(nsString.character(at: i)) {
if c == " " as UnicodeScalar || c == "\t" as UnicodeScalar || c == "\n" as UnicodeScalar {
if trimmedCharacters.contains(c) {
upper += 1
} else {
break