Various improvements

This commit is contained in:
Ilya Laktyushin 2022-05-26 06:13:07 +04:00
parent 070609d969
commit 9339fe6e56
4 changed files with 33 additions and 19 deletions

View File

@ -1980,8 +1980,8 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
return
}
let isPremium = peerView.peers[peerView.peerId]?.isPremium ?? false
strongSelf.isPremium = isPremium
let isPremium = peerView.peers[peerView.peerId]?.isPremium
strongSelf.isPremium = isPremium ?? false
let (_, items) = countAndFilterItems
var filterItems: [ChatListFilterTabEntry] = []
@ -1989,7 +1989,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
for (filter, unreadCount, hasUnmutedUnread) in items {
switch filter {
case .allChats:
if !isPremium && filterItems.count > 0 {
if let isPremium = isPremium, !isPremium && filterItems.count > 0 {
filterItems.insert(.all(unreadCount: 0), at: 0)
} else {
filterItems.append(.all(unreadCount: 0))
@ -2042,7 +2042,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
selectedEntryId = .all
}
}
let filtersLimit = !isPremium ? limits.maxFoldersCount : nil
let filtersLimit = isPremium == false ? limits.maxFoldersCount : nil
strongSelf.tabContainerData = (resolvedItems, displayTabsAtBottom, filtersLimit)
var availableFilters: [ChatListContainerNodeFilter] = []
var hasAllChats = false
@ -2050,7 +2050,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
switch item.0 {
case .allChats:
hasAllChats = true
if !isPremium && availableFilters.count > 0 {
if let isPremium = isPremium, !isPremium && availableFilters.count > 0 {
availableFilters.insert(.all, at: 0)
} else {
availableFilters.append(.all)
@ -2064,7 +2064,9 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
}
strongSelf.chatListDisplayNode.containerNode.updateAvailableFilters(availableFilters, limit: filtersLimit)
if !strongSelf.initializedFilters {
if isPremium == nil && items.isEmpty {
strongSelf.ready.set(strongSelf.chatListDisplayNode.containerNode.currentItemNode.ready)
} else if !strongSelf.initializedFilters {
if selectedEntryId != strongSelf.chatListDisplayNode.containerNode.currentItemFilter {
strongSelf.chatListDisplayNode.containerNode.switchToFilter(id: selectedEntryId, animated: false, completion: { [weak self] in
if let strongSelf = self {
@ -2077,7 +2079,6 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
strongSelf.initializedFilters = true
}
let isEmpty = resolvedItems.count <= 1 || displayTabsAtBottom
let animated = strongSelf.didSetupTabs
@ -2096,7 +2097,7 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController
strongSelf.containerLayoutUpdated(layout, transition: transition)
(strongSelf.parent as? TabBarController)?.updateLayout(transition: transition)
} else {
strongSelf.tabContainerNode.update(size: CGSize(width: layout.size.width, height: 46.0), sideInset: layout.safeInsets.left, filters: resolvedItems, selectedFilter: selectedEntryId, isReordering: strongSelf.chatListDisplayNode.isReorderingFilters || (strongSelf.chatListDisplayNode.containerNode.currentItemNode.currentState.editing && !strongSelf.chatListDisplayNode.didBeginSelectingChatsWhileEditing), isEditing: strongSelf.chatListDisplayNode.containerNode.currentItemNode.currentState.editing, canReorderAllChats: isPremium, filtersLimit: filtersLimit, transitionFraction: strongSelf.chatListDisplayNode.containerNode.transitionFraction, presentationData: strongSelf.presentationData, transition: .animated(duration: 0.4, curve: .spring))
strongSelf.tabContainerNode.update(size: CGSize(width: layout.size.width, height: 46.0), sideInset: layout.safeInsets.left, filters: resolvedItems, selectedFilter: selectedEntryId, isReordering: strongSelf.chatListDisplayNode.isReorderingFilters || (strongSelf.chatListDisplayNode.containerNode.currentItemNode.currentState.editing && !strongSelf.chatListDisplayNode.didBeginSelectingChatsWhileEditing), isEditing: strongSelf.chatListDisplayNode.containerNode.currentItemNode.currentState.editing, canReorderAllChats: strongSelf.isPremium, filtersLimit: filtersLimit, transitionFraction: strongSelf.chatListDisplayNode.containerNode.transitionFraction, presentationData: strongSelf.presentationData, transition: .animated(duration: 0.4, curve: .spring))
strongSelf.chatListDisplayNode.inlineTabContainerNode.update(size: CGSize(width: layout.size.width, height: 40.0), sideInset: layout.safeInsets.left, filters: resolvedItems, selectedFilter: selectedEntryId, isReordering: strongSelf.chatListDisplayNode.isReorderingFilters || (strongSelf.chatListDisplayNode.containerNode.currentItemNode.currentState.editing && !strongSelf.chatListDisplayNode.didBeginSelectingChatsWhileEditing), isEditing: false, transitionFraction: strongSelf.chatListDisplayNode.containerNode.transitionFraction, presentationData: strongSelf.presentationData, transition: .animated(duration: 0.4, curve: .spring))
}
}

View File

@ -878,6 +878,12 @@ final class ChatListContainerNode: ASDisplayNode, UIGestureRecognizerDelegate {
let disposable = MetaDisposable()
self.pendingItemNode = (id, itemNode, disposable)
if !animated {
self.selectedId = id
self.applyItemNodeAsCurrent(id: id, itemNode: itemNode)
self.currentItemFilterUpdated?(self.currentItemFilter, self.transitionFraction, .immediate, false)
}
disposable.set((itemNode.listNode.ready
|> take(1)
|> deliverOnMainQueue).start(next: { [weak self, weak itemNode] _ in

View File

@ -207,7 +207,7 @@ func preparedChatListNodeViewTransition(from fromView: ChatListNodeView?, to toV
}
var adjustScrollToFirstItem = false
if !previewing && !searchMode && fromEmptyView && scrollToItem == nil && toView.filteredEntries.count >= 1 {
if !previewing && !searchMode && fromEmptyView && scrollToItem == nil && toView.filteredEntries.count >= 2 {
adjustScrollToFirstItem = true
}

View File

@ -84,6 +84,7 @@ class PremiumStarComponent: Component {
self.sceneView.backgroundColor = .clear
self.sceneView.transform = CGAffineTransform(scaleX: 0.5, y: 0.5)
self.sceneView.isUserInteractionEnabled = false
self.sceneView.preferredFramesPerSecond = 60
super.init(frame: frame)
@ -213,18 +214,24 @@ class PremiumStarComponent: Component {
}
private func setup() {
guard let url = getAppBundle().url(forResource: "star", withExtension: ""),
let compressedData = try? Data(contentsOf: url),
let decompressedData = TGGUnzipData(compressedData, 8 * 1024 * 1024) else {
return
}
let fileName = "star_\(sceneVersion).scn"
let tmpURL = URL(fileURLWithPath: NSTemporaryDirectory() + fileName)
if !FileManager.default.fileExists(atPath: tmpURL.path) {
try? decompressedData.write(to: tmpURL)
let resourceUrl: URL
if let url = getAppBundle().url(forResource: "star", withExtension: "scn") {
resourceUrl = url
} else {
let fileName = "star_\(sceneVersion).scn"
let tmpUrl = URL(fileURLWithPath: NSTemporaryDirectory() + fileName)
if !FileManager.default.fileExists(atPath: tmpUrl.path) {
guard let url = getAppBundle().url(forResource: "star", withExtension: ""),
let compressedData = try? Data(contentsOf: url),
let decompressedData = TGGUnzipData(compressedData, 8 * 1024 * 1024) else {
return
}
try? decompressedData.write(to: tmpUrl)
}
resourceUrl = tmpUrl
}
guard let scene = try? SCNScene(url: tmpURL, options: nil) else {
guard let scene = try? SCNScene(url: resourceUrl, options: nil) else {
return
}