Small bug fixes

This commit is contained in:
Ali 2020-03-11 21:44:16 +05:30
parent d624e5b5a9
commit 97c2d9fc91
5 changed files with 58 additions and 35 deletions

View File

@ -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)
}
})
}
})
}))
}
}

View File

@ -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()
}
}
}

View File

@ -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

View File

@ -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
}

View File

@ -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 {