diff --git a/submodules/ChatListUI/Sources/ChatListController.swift b/submodules/ChatListUI/Sources/ChatListController.swift index 2271813bfb..48731695cb 100644 --- a/submodules/ChatListUI/Sources/ChatListController.swift +++ b/submodules/ChatListUI/Sources/ChatListController.swift @@ -1136,35 +1136,42 @@ public class ChatListControllerImpl: TelegramBaseController, ChatListController, guard let strongSelf = self, let featuredState = featuredState else { return } - strongSelf.processedFeaturedFilters = true - if !featuredState.isSeen && !featuredState.filters.isEmpty { - let _ = (currentChatListFilters(postbox: strongSelf.context.account.postbox) - |> deliverOnMainQueue).start(next: { filters in - guard let strongSelf = self else { - return - } - let hasFilters = !filters.isEmpty - if let _ = strongSelf.validLayout, let parentController = strongSelf.parent as? TabBarController, let sourceFrame = parentController.frameForControllerTab(controller: strongSelf) { - let absoluteFrame = sourceFrame - //TODO:localize - let text: String - if hasFilters { - text = "Hold on 'Chats' to edit folders and switch between views." - } else { - text = "Hold to organize your chats with folders." + + let _ = (currentChatListFilters(postbox: strongSelf.context.account.postbox) + |> deliverOnMainQueue).start(next: { filters in + guard let strongSelf = self else { + return + } + strongSelf.processedFeaturedFilters = true + if !featuredState.isSeen && !featuredState.filters.isEmpty && filters.isEmpty { + let _ = (currentChatListFilters(postbox: strongSelf.context.account.postbox) + |> deliverOnMainQueue).start(next: { filters in + guard let strongSelf = self else { + return } - parentController.present(TooltipScreen(text: text, location: CGPoint(x: absoluteFrame.midX - 14.0, y: absoluteFrame.minY - 8.0), shouldDismissOnTouch: { point in - guard let strongSelf = self, let parentController = strongSelf.parent as? TabBarController else { + let hasFilters = !filters.isEmpty + if let _ = strongSelf.validLayout, let parentController = strongSelf.parent as? TabBarController, let sourceFrame = parentController.frameForControllerTab(controller: strongSelf) { + let absoluteFrame = sourceFrame + //TODO:localize + let text: String + if hasFilters { + text = "Hold on 'Chats' to edit folders and switch between views." + } else { + text = "Hold to organize your chats with folders." + } + parentController.present(TooltipScreen(text: text, location: CGPoint(x: absoluteFrame.midX - 14.0, y: absoluteFrame.minY - 8.0), shouldDismissOnTouch: { point in + guard let strongSelf = self, let parentController = strongSelf.parent as? TabBarController else { + return true + } + if parentController.isPointInsideContentArea(point: point) { + return false + } return true - } - if parentController.isPointInsideContentArea(point: point) { - return false - } - return true - }), in: .current) - } - }) - } + }), in: .current) + } + }) + } + }) })) } } diff --git a/submodules/ChatListUI/Sources/ChatListControllerNode.swift b/submodules/ChatListUI/Sources/ChatListControllerNode.swift index 16fc512da7..bdde633318 100644 --- a/submodules/ChatListUI/Sources/ChatListControllerNode.swift +++ b/submodules/ChatListUI/Sources/ChatListControllerNode.swift @@ -720,9 +720,21 @@ final class ChatListContainerNode: ASDisplayNode, UIGestureRecognizerDelegate { func updateAvailableFilters(_ availableFilters: [ChatListContainerNodeFilter]) { if self.availableFilters != availableFilters { - self.availableFilters = availableFilters - if let (layout, navigationBarHeight, visualNavigationHeight, cleanNavigationBarHeight, isReorderingFilters, isEditing) = self.validLayout { - self.update(layout: layout, navigationBarHeight: navigationBarHeight, visualNavigationHeight: visualNavigationHeight, cleanNavigationBarHeight: cleanNavigationBarHeight, isReorderingFilters: isReorderingFilters, isEditing: isEditing, transition: .immediate) + let apply: () -> Void = { [weak self] in + guard let strongSelf = self else { + return + } + strongSelf.availableFilters = availableFilters + if let (layout, navigationBarHeight, visualNavigationHeight, cleanNavigationBarHeight, isReorderingFilters, isEditing) = strongSelf.validLayout { + strongSelf.update(layout: layout, navigationBarHeight: navigationBarHeight, visualNavigationHeight: visualNavigationHeight, cleanNavigationBarHeight: cleanNavigationBarHeight, isReorderingFilters: isReorderingFilters, isEditing: isEditing, transition: .immediate) + } + } + if !availableFilters.contains(where: { $0.id == self.selectedId }) { + self.switchToFilter(id: .all, completion: { + apply() + }) + } else { + apply() } } } diff --git a/submodules/ChatListUI/Sources/ChatListFilterPresetController.swift b/submodules/ChatListUI/Sources/ChatListFilterPresetController.swift index 2d20a73f7d..8f6ee3873e 100644 --- a/submodules/ChatListUI/Sources/ChatListFilterPresetController.swift +++ b/submodules/ChatListUI/Sources/ChatListFilterPresetController.swift @@ -310,7 +310,7 @@ private enum ChatListFilterPresetEntry: ItemListNodeEntry { case let .nameHeader(title): return ItemListSectionHeaderItem(presentationData: presentationData, text: title, sectionId: self.section) case let .name(placeholder, value): - return ItemListSingleLineInputItem(presentationData: presentationData, title: NSAttributedString(), text: value, placeholder: placeholder, type: .regular(capitalization: true, autocorrection: false), clearType: .always, sectionId: self.section, textUpdated: { value in + return ItemListSingleLineInputItem(presentationData: presentationData, title: NSAttributedString(), text: value, placeholder: placeholder, type: .regular(capitalization: true, autocorrection: false), clearType: .always, maxLength: 20, sectionId: self.section, textUpdated: { value in arguments.updateState { current in var state = current state.name = value @@ -968,7 +968,7 @@ func chatListFilterPresetController(context: AccountContext, currentPreset: Chat applyImpl?() }) - let controllerState = ItemListControllerState(presentationData: ItemListPresentationData(presentationData), title: .text(currentPreset != nil ? "Folder" : "Create Folder"), leftNavigationButton: leftNavigationButton, rightNavigationButton: rightNavigationButton, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back), animateChanges: false) + let controllerState = ItemListControllerState(presentationData: ItemListPresentationData(presentationData), title: .text(currentPreset != nil ? "Edit Folder" : "Create Folder"), leftNavigationButton: leftNavigationButton, rightNavigationButton: rightNavigationButton, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back), animateChanges: false) let listState = ItemListNodeState(presentationData: ItemListPresentationData(presentationData), entries: chatListFilterPresetControllerEntries(presentationData: presentationData, isNewFilter: currentPreset == nil, state: state, includePeers: includePeers, excludePeers: excludePeers), style: .blocks, emptyStateItem: nil, animateChanges: !skipStateAnimation) skipStateAnimation = false diff --git a/submodules/ChatListUI/Sources/ChatListFilterPresetListController.swift b/submodules/ChatListUI/Sources/ChatListFilterPresetListController.swift index 971a515f02..398b2eb674 100644 --- a/submodules/ChatListUI/Sources/ChatListFilterPresetListController.swift +++ b/submodules/ChatListUI/Sources/ChatListFilterPresetListController.swift @@ -217,7 +217,7 @@ private func chatListFilterPresetListControllerEntries(presentationData: Present entries.append(.listFooter("Tap \"Edit\" to change the order or delete folders.")) } - if !filteredSuggestedFilters.isEmpty { + if !filteredSuggestedFilters.isEmpty && filters.count < 10 { entries.append(.suggestedListHeader("RECOMMENDED FOLDERS")) for filter in filteredSuggestedFilters { entries.append(.suggestedPreset(index: PresetIndex(value: entries.count), title: filter.title, label: filter.description, preset: filter.data)) @@ -492,4 +492,3 @@ public func chatListFilterPresetListController(context: AccountContext, mode: Ch return controller } - diff --git a/submodules/ItemListUI/Sources/Items/ItemListSingleLineInputItem.swift b/submodules/ItemListUI/Sources/Items/ItemListSingleLineInputItem.swift index 6173e2adb4..adadacfda0 100644 --- a/submodules/ItemListUI/Sources/Items/ItemListSingleLineInputItem.swift +++ b/submodules/ItemListUI/Sources/Items/ItemListSingleLineInputItem.swift @@ -38,6 +38,7 @@ public class ItemListSingleLineInputItem: ListViewItem, ItemListItem { let returnKeyType: UIReturnKeyType let spacing: CGFloat let clearType: ItemListSingleLineInputClearType + let maxLength: Int let enabled: Bool public let sectionId: ItemListSectionId let action: () -> Void @@ -48,7 +49,7 @@ public class ItemListSingleLineInputItem: ListViewItem, ItemListItem { let cleared: (() -> Void)? public let tag: ItemListItemTag? - public init(presentationData: ItemListPresentationData, title: NSAttributedString, text: String, placeholder: String, type: ItemListSingleLineInputItemType = .regular(capitalization: true, autocorrection: true), returnKeyType: UIReturnKeyType = .`default`, spacing: CGFloat = 0.0, clearType: ItemListSingleLineInputClearType = .none, enabled: Bool = true, tag: ItemListItemTag? = nil, sectionId: ItemListSectionId, textUpdated: @escaping (String) -> Void, shouldUpdateText: @escaping (String) -> Bool = { _ in return true }, processPaste: ((String) -> String)? = nil, updatedFocus: ((Bool) -> Void)? = nil, action: @escaping () -> Void, cleared: (() -> Void)? = nil) { + public init(presentationData: ItemListPresentationData, title: NSAttributedString, text: String, placeholder: String, type: ItemListSingleLineInputItemType = .regular(capitalization: true, autocorrection: true), returnKeyType: UIReturnKeyType = .`default`, spacing: CGFloat = 0.0, clearType: ItemListSingleLineInputClearType = .none, maxLength: Int = 0, enabled: Bool = true, tag: ItemListItemTag? = nil, sectionId: ItemListSectionId, textUpdated: @escaping (String) -> Void, shouldUpdateText: @escaping (String) -> Bool = { _ in return true }, processPaste: ((String) -> String)? = nil, updatedFocus: ((Bool) -> Void)? = nil, action: @escaping () -> Void, cleared: (() -> Void)? = nil) { self.presentationData = presentationData self.title = title self.text = text @@ -57,6 +58,7 @@ public class ItemListSingleLineInputItem: ListViewItem, ItemListItem { self.returnKeyType = returnKeyType self.spacing = spacing self.clearType = clearType + self.maxLength = maxLength self.enabled = enabled self.tag = tag self.sectionId = sectionId @@ -441,6 +443,9 @@ public class ItemListSingleLineInputItemNode: ListViewItemNode, UITextFieldDeleg if !item.shouldUpdateText(newText) { return false } + if item.maxLength != 0 && newText.count > item.maxLength { + return false + } } if string.count > 1, let item = self.item, let processPaste = item.processPaste {