Fix ChatListArchiveItem

This commit is contained in:
Peter
2019-04-26 20:06:55 +04:00
parent 9e853eca72
commit 385e679453
4 changed files with 46 additions and 21 deletions

View File

@@ -59,6 +59,8 @@ private final class InfoPageNode: ASDisplayNode {
private let titleNode: TextNode
private let textNode: TextNode
private var theme: PresentationTheme?
override init() {
self.iconNodeBase = ASImageNode()
self.iconNodeBase.displaysAsynchronously = false
@@ -112,11 +114,12 @@ private final class InfoPageNode: ASDisplayNode {
return
}
if strongSelf.iconNodeBase.image == nil {
if strongSelf.theme !== theme {
strongSelf.theme = theme
if index == 0 {
strongSelf.iconNodeBase.image = UIImage(bundleImageName: "Chat List/Archive/Intro1Base")
strongSelf.iconNodeBase.image = generateTintedImage(image: UIImage(bundleImageName: "Chat List/Archive/Intro1Base"), color: theme.list.itemPrimaryTextColor)
} else {
strongSelf.iconNodeBase.image = UIImage(bundleImageName: "Chat List/Archive/Intro2Base")
strongSelf.iconNodeBase.image = generateTintedImage(image: UIImage(bundleImageName: "Chat List/Archive/Intro2Base"), color: theme.list.itemPrimaryTextColor)
}
if index == 0 {
strongSelf.iconNodeContent.image = generateTintedImage(image: UIImage(bundleImageName: "Chat List/Archive/Intro1Content"), color: theme.chatList.unreadBadgeActiveBackgroundColor)
@@ -216,8 +219,12 @@ class ChatListArchiveInfoItemNode: ListViewItemNode, UIScrollViewDelegate {
strongSelf.pageControlNode.inactiveDotColor = item.theme.chatList.unreadBadgeInactiveBackgroundColor
}
let resetOffset = !strongSelf.scrollNode.frame.width.isEqual(to: baseWidth)
strongSelf.scrollNode.frame = CGRect(origin: CGPoint(x: params.leftInset, y: 0.0), size: CGSize(width: baseWidth, height: layout.contentSize.height))
strongSelf.scrollNode.view.contentSize = CGSize(width: baseWidth * CGFloat(infoPageLayoutsAndApply.count), height: layout.contentSize.height)
if resetOffset {
strongSelf.scrollNode.view.contentOffset = CGPoint(x: 0.0, y: 0.0)
}
for i in 0 ..< infoPageLayoutsAndApply.count {
strongSelf.infoPageNodes[i].frame = CGRect(origin: CGPoint(x: baseWidth * CGFloat(i), y: 0.0), size: CGSize(width: baseWidth, height: layout.contentSize.height))
infoPageLayoutsAndApply[i].1()
@@ -234,6 +241,9 @@ class ChatListArchiveInfoItemNode: ListViewItemNode, UIScrollViewDelegate {
}
if let headerNode = strongSelf.headerNode {
if themeUpdated {
headerNode.updateTheme(theme: item.theme)
}
headerNode.frame = CGRect(origin: CGPoint(x: 0.0, y: layout.contentSize.height - 28.0), size: CGSize(width: params.width, height: 28.0))
headerNode.updateLayout(size: CGSize(width: params.width, height: 28.0), leftInset: params.leftInset, rightInset: params.rightInset)
}

View File

@@ -666,7 +666,7 @@ public class ChatListController: TelegramController, KeyShortcutResponder, UIVie
return
}
if group {
strongSelf.archiveChat(peerId: peerId)
strongSelf.archiveChats(peerIds: [peerId])
} else {
strongSelf.chatListDisplayNode.chatListNode.setCurrentRemovingPeerId(peerId)
let _ = updatePeerGroupIdInteractively(postbox: strongSelf.context.account.postbox, peerId: peerId, groupId: group ? Namespaces.PeerGroup.archive : .root).start(completed: {
@@ -800,8 +800,8 @@ public class ChatListController: TelegramController, KeyShortcutResponder, UIVie
}
}
self.chatListDisplayNode.toolbarActionSelected = { [weak self] left in
self?.toolbarActionSelected(left: left)
self.chatListDisplayNode.toolbarActionSelected = { [weak self] action in
self?.toolbarActionSelected(action: action)
}
let context = self.context
@@ -838,13 +838,13 @@ public class ChatListController: TelegramController, KeyShortcutResponder, UIVie
case let .selective(enabled):
leftAction = ToolbarAction(title: presentationData.strings.ChatList_Read, isEnabled: enabled)
}
toolbar = Toolbar(leftAction: leftAction, rightAction: ToolbarAction(title: presentationData.strings.Common_Delete, isEnabled: options.delete))
toolbar = Toolbar(leftAction: leftAction, rightAction: ToolbarAction(title: presentationData.strings.Common_Delete, isEnabled: options.delete), middleAction: ToolbarAction(title: presentationData.strings.ChatList_ArchiveAction, isEnabled: options.delete))
}
} else {
if let (options, peerIds) = peerIdsAndOptions {
let leftAction: ToolbarAction
leftAction = ToolbarAction(title: presentationData.strings.ChatList_UnarchiveAction, isEnabled: !peerIds.isEmpty)
toolbar = Toolbar(leftAction: leftAction, rightAction: ToolbarAction(title: presentationData.strings.Common_Delete, isEnabled: options.delete))
toolbar = Toolbar(leftAction: leftAction, rightAction: ToolbarAction(title: presentationData.strings.Common_Delete, isEnabled: options.delete), middleAction: nil)
}
}
strongSelf.setToolbar(toolbar, transition: .animated(duration: 0.3, curve: .easeInOut))
@@ -1250,9 +1250,9 @@ public class ChatListController: TelegramController, KeyShortcutResponder, UIVie
return inputShortcuts + chatShortcuts
}
override public func toolbarActionSelected(left: Bool) {
override public func toolbarActionSelected(action: ToolbarActionOption) {
let peerIds = self.chatListDisplayNode.chatListNode.currentState.selectedPeerIds
if left {
if case .left = action {
if case .root = self.groupId {
let signal: Signal<Void, NoError>
let context = self.context
@@ -1287,7 +1287,7 @@ public class ChatListController: TelegramController, KeyShortcutResponder, UIVie
strongSelf.donePressed()
})
}
} else if !left && !peerIds.isEmpty {
} else if case .right = action, !peerIds.isEmpty {
let actionSheet = ActionSheetController(presentationTheme: self.presentationData.theme)
var items: [ActionSheetItem] = []
items.append(ActionSheetButtonItem(title: self.presentationData.strings.ChatList_DeleteConfirmation(Int32(peerIds.count)), color: .destructive, action: { [weak self, weak actionSheet] in
@@ -1337,6 +1337,8 @@ public class ChatListController: TelegramController, KeyShortcutResponder, UIVie
])
])
self.present(actionSheet, in: .window(.root))
} else if case .middle = action, !peerIds.isEmpty {
self.archiveChats(peerIds: Array(peerIds))
}
}
@@ -1394,12 +1396,19 @@ public class ChatListController: TelegramController, KeyShortcutResponder, UIVie
}
}
private func archiveChat(peerId: PeerId) {
private func archiveChats(peerIds: [PeerId]) {
guard !peerIds.isEmpty else {
return
}
let postbox = self.context.account.postbox
self.chatListDisplayNode.chatListNode.setCurrentRemovingPeerId(peerId)
self.chatListDisplayNode.chatListNode.setCurrentRemovingPeerId(peerIds[0])
let _ = (ApplicationSpecificNotice.incrementArchiveChatTipsTips(accountManager: self.context.sharedContext.accountManager, count: 1)
|> deliverOnMainQueue).start(next: { [weak self] previousHintCount in
let _ = (updatePeerGroupIdInteractively(postbox: postbox, peerId: peerId, groupId: Namespaces.PeerGroup.archive)
let _ = (postbox.transaction { transaction -> Void in
for peerId in peerIds {
updatePeerGroupIdInteractively(transaction: transaction, peerId: peerId, groupId: Namespaces.PeerGroup.archive)
}
}
|> deliverOnMainQueue).start(completed: {
guard let strongSelf = self else {
return
@@ -1411,8 +1420,12 @@ public class ChatListController: TelegramController, KeyShortcutResponder, UIVie
return
}
if !shouldCommit {
strongSelf.chatListDisplayNode.chatListNode.setCurrentRemovingPeerId(peerId)
let _ = (updatePeerGroupIdInteractively(postbox: strongSelf.context.account.postbox, peerId: peerId, groupId: .root)
strongSelf.chatListDisplayNode.chatListNode.setCurrentRemovingPeerId(peerIds[0])
let _ = (postbox.transaction { transaction -> Void in
for peerId in peerIds {
updatePeerGroupIdInteractively(transaction: transaction, peerId: peerId, groupId: .root)
}
}
|> deliverOnMainQueue).start(completed: {
guard let strongSelf = self else {
return

View File

@@ -30,7 +30,7 @@ final class ChatListControllerNode: ASDisplayNode {
var toolbar: Toolbar?
private var toolbarNode: ToolbarNode?
var toolbarActionSelected: ((Bool) -> Void)?
var toolbarActionSelected: ((ToolbarActionOption) -> Void)?
private(set) var searchDisplayController: SearchDisplayController?
@@ -155,9 +155,11 @@ final class ChatListControllerNode: ASDisplayNode {
toolbarNode.updateLayout(size: tabBarFrame.size, leftInset: layout.safeInsets.left, rightInset: layout.safeInsets.right, bottomInset: bottomInset, toolbar: toolbar, transition: transition)
} else {
let toolbarNode = ToolbarNode(theme: TabBarControllerTheme(rootControllerTheme: self.presentationData.theme), displaySeparator: true, left: { [weak self] in
self?.toolbarActionSelected?(true)
}, right: { [weak self] in
self?.toolbarActionSelected?(false)
self?.toolbarActionSelected?(.left)
}, right: { [weak self] in
self?.toolbarActionSelected?(.right)
}, middle: { [weak self] in
self?.toolbarActionSelected?(.middle)
})
toolbarNode.frame = tabBarFrame
toolbarNode.updateLayout(size: tabBarFrame.size, leftInset: layout.safeInsets.left, rightInset: layout.safeInsets.right, bottomInset: bottomInset, toolbar: toolbar, transition: .immediate)

View File

@@ -642,7 +642,7 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
}
editingOffset = sizeAndApply.0
if item.index.pinningIndex != nil && !isAd {
if item.index.pinningIndex != nil && !isAd && !isPeerGroup {
let sizeAndApply = reorderControlLayout(itemHeight, item.presentationData.theme)
reorderControlSizeAndApply = sizeAndApply
reorderInset = sizeAndApply.0.width