diff --git a/Telegram/Telegram-iOS/en.lproj/Localizable.strings b/Telegram/Telegram-iOS/en.lproj/Localizable.strings index bad4ac6864..dbdfd53f41 100644 --- a/Telegram/Telegram-iOS/en.lproj/Localizable.strings +++ b/Telegram/Telegram-iOS/en.lproj/Localizable.strings @@ -6371,6 +6371,7 @@ Sorry for the inconvenience."; "StickerPacks.ActionDelete" = "Delete"; "StickerPacks.ActionArchive" = "Archive"; +"StickerPacks.ActionUnarchive" = "Unarchive"; "StickerPacks.ActionShare" = "Share"; "StickerPacks.DeleteStickerPacksConfirmation_0" = "Delete %@ Sticker Sets"; @@ -8956,3 +8957,6 @@ Sorry for the inconvenience."; "Conversation.ShareLinkTooltip.Chat.One" = "Link shared with **%@**"; "Conversation.ShareLinkTooltip.TwoChats.One" = "Link shared with **%@** and **%@**"; "Conversation.ShareLinkTooltip.ManyChats.One" = "Link shared with **%@** and %@ others"; + +"StickerPacks.UnarchiveStickerPacksConfirmation_1" = "Unarchive %@ Pack"; +"StickerPacks.UnarchiveStickerPacksConfirmation_any" = "Unarchive %@ Packs"; diff --git a/submodules/AuthorizationUI/Sources/AuthorizationSequenceAwaitingAccountResetControllerNode.swift b/submodules/AuthorizationUI/Sources/AuthorizationSequenceAwaitingAccountResetControllerNode.swift index def523172c..53f0c8f3e3 100644 --- a/submodules/AuthorizationUI/Sources/AuthorizationSequenceAwaitingAccountResetControllerNode.swift +++ b/submodules/AuthorizationUI/Sources/AuthorizationSequenceAwaitingAccountResetControllerNode.swift @@ -162,7 +162,7 @@ final class AuthorizationSequenceAwaitingAccountResetControllerNode: ASDisplayNo items.append(AuthorizationLayoutItem(node: self.noticeNode, size: noticeSize, spacingBefore: AuthorizationLayoutItemSpacing(weight: 20.0, maxValue: 10.0), spacingAfter: AuthorizationLayoutItemSpacing(weight: 0.0, maxValue: 0.0))) items.append(AuthorizationLayoutItem(node: self.timerTitleNode, size: timerTitleSize, spacingBefore: AuthorizationLayoutItemSpacing(weight: 100.0, maxValue: 100.0), spacingAfter: AuthorizationLayoutItemSpacing(weight: 0.0, maxValue: 0.0))) - items.append(AuthorizationLayoutItem(node: self.self.timerValueNode, size: timerValueSize, spacingBefore: AuthorizationLayoutItemSpacing(weight: 10.0, maxValue: 10.0), spacingAfter: AuthorizationLayoutItemSpacing(weight: 0.0, maxValue: 0.0))) + items.append(AuthorizationLayoutItem(node: self.timerValueNode, size: timerValueSize, spacingBefore: AuthorizationLayoutItemSpacing(weight: 10.0, maxValue: 10.0), spacingAfter: AuthorizationLayoutItemSpacing(weight: 0.0, maxValue: 0.0))) items.append(AuthorizationLayoutItem(node: self.resetNode, size: resetSize, spacingBefore: AuthorizationLayoutItemSpacing(weight: 10.0, maxValue: 10.0), spacingAfter: AuthorizationLayoutItemSpacing(weight: 0.0, maxValue: 0.0))) let _ = layoutAuthorizationItems(bounds: CGRect(origin: CGPoint(x: 0.0, y: insets.top), size: CGSize(width: layout.size.width, height: layout.size.height - insets.top - insets.bottom - 20.0)), items: items, transition: transition, failIfDoesNotFit: false) diff --git a/submodules/ItemListStickerPackItem/Sources/ItemListStickerPackItem.swift b/submodules/ItemListStickerPackItem/Sources/ItemListStickerPackItem.swift index 890828c391..fb1fd3a18d 100644 --- a/submodules/ItemListStickerPackItem/Sources/ItemListStickerPackItem.swift +++ b/submodules/ItemListStickerPackItem/Sources/ItemListStickerPackItem.swift @@ -651,41 +651,76 @@ class ItemListStickerPackItemNode: ItemListRevealOptionsItemNode { let _ = titleApply() let _ = statusApply() - let _ = installApply() switch item.control { - case .none: - strongSelf.installationActionNode.isHidden = true - strongSelf.installationActionBackgroundNode.isHidden = true - strongSelf.selectionIconNode.isHidden = true - case let .installation(installed): - strongSelf.installationActionBackgroundNode.isHidden = false - strongSelf.installationActionNode.isHidden = false - strongSelf.selectionIconNode.isHidden = true - strongSelf.installationActionNode.isUserInteractionEnabled = !installed + case .none: + strongSelf.installationActionNode.isHidden = true + strongSelf.installationActionBackgroundNode.isHidden = true + strongSelf.selectionIconNode.isHidden = true + let _ = installApply() + case let .installation(installed): + strongSelf.installationActionBackgroundNode.isHidden = false + if let previousControl = currentItem?.control, case .check = previousControl { + strongSelf.installationActionBackgroundNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2) + transition.animateTransformScale(node: strongSelf.installationActionBackgroundNode, from: 0.01) + transition.animatePosition(node: strongSelf.installationActionBackgroundNode, from: strongSelf.installationActionBackgroundNode.position.offsetBy(dx: 64.0, dy: 0.0)) + + strongSelf.installTextNode.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2) + transition.animateTransformScale(node: strongSelf.installTextNode, from: 0.01) + transition.animatePosition(node: strongSelf.installTextNode, from: strongSelf.installTextNode.position.offsetBy(dx: 64.0, dy: 0.0)) + } + strongSelf.installationActionNode.isHidden = false + strongSelf.selectionIconNode.isHidden = true + strongSelf.installationActionNode.isUserInteractionEnabled = !installed - if let backgroundImage = installationBackgroundImage { - strongSelf.installationActionBackgroundNode.image = backgroundImage + if let backgroundImage = installationBackgroundImage { + strongSelf.installationActionBackgroundNode.image = backgroundImage + } + + let installationActionFrame = CGRect(origin: CGPoint(x: params.width - rightInset - installWidth - 16.0, y: 0.0), size: CGSize(width: installWidth, height: layout.contentSize.height)) + strongSelf.installationActionNode.frame = installationActionFrame + + let buttonFrame = CGRect(origin: CGPoint(x: params.width - rightInset - installWidth - 16.0, y: installationActionFrame.minY + floor((installationActionFrame.size.height - 28.0) / 2.0)), size: CGSize(width: installWidth, height: 28.0)) + strongSelf.installationActionBackgroundNode.frame = buttonFrame + strongSelf.installTextNode.frame = CGRect(origin: CGPoint(x: buttonFrame.minX + floorToScreenPixels((buttonFrame.width - installLayout.size.width) / 2.0), y: buttonFrame.minY + floorToScreenPixels((buttonFrame.height - installLayout.size.height) / 2.0) + 1.0), size: installLayout.size) + let _ = installApply() + case .selection: + strongSelf.installationActionBackgroundNode.isHidden = true + strongSelf.installationActionNode.isHidden = true + strongSelf.selectionIconNode.isHidden = false + if let image = checkImage { + strongSelf.selectionIconNode.image = image + strongSelf.selectionIconNode.frame = CGRect(origin: CGPoint(x: params.width - params.rightInset - image.size.width - floor((44.0 - image.size.width) / 2.0), y: floor((contentSize.height - image.size.height) / 2.0)), size: image.size) + } + let _ = installApply() + case .check: + if let previousControl = currentItem?.control, case .installation = previousControl { + strongSelf.installationActionBackgroundNode.alpha = 0.0 + strongSelf.installationActionBackgroundNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2) + strongSelf.installationActionBackgroundNode.layer.animateScale(from: 1.0, to: 0.01, duration: 0.2, completion: { [weak self] _ in + if let strongSelf = self { + strongSelf.installationActionBackgroundNode.isHidden = true + strongSelf.installationActionBackgroundNode.alpha = 1.0 + } + }) + transition.animatePosition(node: strongSelf.installationActionBackgroundNode, to: CGPoint(x: 64.0, y: 0.0), additive: true) + + if let installTextSnapshot = strongSelf.installTextNode.view.snapshotContentTree() { + installTextSnapshot.frame = strongSelf.installTextNode.frame + strongSelf.installTextNode.view.superview?.addSubview(installTextSnapshot) + installTextSnapshot.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false) + installTextSnapshot.layer.animateScale(from: 1.0, to: 0.01, duration: 0.2, removeOnCompletion: false) + transition.animatePosition(layer: installTextSnapshot.layer, from: .zero, to: CGPoint(x: 64.0, y: 0.0), additive: true, completion: { [weak installTextSnapshot] _ in + installTextSnapshot?.removeFromSuperview() + }) } - - let installationActionFrame = CGRect(origin: CGPoint(x: params.width - rightInset - installWidth - 16.0, y: 0.0), size: CGSize(width: installWidth, height: layout.contentSize.height)) - strongSelf.installationActionNode.frame = installationActionFrame - - let buttonFrame = CGRect(origin: CGPoint(x: params.width - rightInset - installWidth - 16.0, y: installationActionFrame.minY + floor((installationActionFrame.size.height - 28.0) / 2.0)), size: CGSize(width: installWidth, height: 28.0)) - strongSelf.installationActionBackgroundNode.frame = buttonFrame - strongSelf.installTextNode.frame = CGRect(origin: CGPoint(x: buttonFrame.minX + floorToScreenPixels((buttonFrame.width - installLayout.size.width) / 2.0), y: buttonFrame.minY + floorToScreenPixels((buttonFrame.height - installLayout.size.height) / 2.0) + 1.0), size: installLayout.size) - case .selection: - strongSelf.installationActionNode.isHidden = true + let _ = installApply() + } else { strongSelf.installationActionBackgroundNode.isHidden = true - strongSelf.selectionIconNode.isHidden = false - if let image = checkImage { - strongSelf.selectionIconNode.image = image - strongSelf.selectionIconNode.frame = CGRect(origin: CGPoint(x: params.width - params.rightInset - image.size.width - floor((44.0 - image.size.width) / 2.0), y: floor((contentSize.height - image.size.height) / 2.0)), size: image.size) - } - case .check: - strongSelf.installationActionNode.isHidden = true - strongSelf.installationActionBackgroundNode.isHidden = true - strongSelf.selectionIconNode.isHidden = true + let _ = installApply() + } + strongSelf.installationActionNode.isHidden = true + strongSelf.selectionIconNode.isHidden = true } if strongSelf.backgroundNode.supernode == nil { diff --git a/submodules/SettingsUI/Sources/Stickers/ArchivedStickerPacksController.swift b/submodules/SettingsUI/Sources/Stickers/ArchivedStickerPacksController.swift index 4ed1549c49..c72c87f6c8 100644 --- a/submodules/SettingsUI/Sources/Stickers/ArchivedStickerPacksController.swift +++ b/submodules/SettingsUI/Sources/Stickers/ArchivedStickerPacksController.swift @@ -13,6 +13,7 @@ import AccountContext import StickerPackPreviewUI import ItemListStickerPackItem import UndoUI +import ShareController public enum ArchivedStickerPacksControllerMode { case stickers @@ -27,13 +28,15 @@ private final class ArchivedStickerPacksControllerArguments { let setPackIdWithRevealedOptions: (ItemCollectionId?, ItemCollectionId?) -> Void let addPack: (StickerPackCollectionInfo) -> Void let removePack: (StickerPackCollectionInfo) -> Void + let togglePackSelected: (ItemCollectionId) -> Void - init(context: AccountContext, openStickerPack: @escaping (StickerPackCollectionInfo) -> Void, setPackIdWithRevealedOptions: @escaping (ItemCollectionId?, ItemCollectionId?) -> Void, addPack: @escaping (StickerPackCollectionInfo) -> Void, removePack: @escaping (StickerPackCollectionInfo) -> Void) { + init(context: AccountContext, openStickerPack: @escaping (StickerPackCollectionInfo) -> Void, setPackIdWithRevealedOptions: @escaping (ItemCollectionId?, ItemCollectionId?) -> Void, addPack: @escaping (StickerPackCollectionInfo) -> Void, removePack: @escaping (StickerPackCollectionInfo) -> Void, togglePackSelected: @escaping (ItemCollectionId) -> Void) { self.context = context self.openStickerPack = openStickerPack self.setPackIdWithRevealedOptions = setPackIdWithRevealedOptions self.addPack = addPack self.removePack = removePack + self.togglePackSelected = togglePackSelected } } @@ -48,7 +51,7 @@ private enum ArchivedStickerPacksEntryId: Hashable { private enum ArchivedStickerPacksEntry: ItemListNodeEntry { case info(PresentationTheme, String) - case pack(Int32, PresentationTheme, PresentationStrings, StickerPackCollectionInfo, StickerPackItem?, String, Bool, Bool, ItemListStickerPackItemEditing) + case pack(Int32, PresentationTheme, PresentationStrings, StickerPackCollectionInfo, StickerPackItem?, String, Bool, Bool, ItemListStickerPackItemEditing, Bool?) var section: ItemListSectionId { switch self { @@ -61,7 +64,7 @@ private enum ArchivedStickerPacksEntry: ItemListNodeEntry { switch self { case .info: return .index(0) - case let .pack(_, _, _, info, _, _, _, _, _): + case let .pack(_, _, _, info, _, _, _, _, _, _): return .pack(info.id) } } @@ -74,8 +77,8 @@ private enum ArchivedStickerPacksEntry: ItemListNodeEntry { } else { return false } - case let .pack(lhsIndex, lhsTheme, lhsStrings, lhsInfo, lhsTopItem, lhsCount, lhsPlayAnimatedStickers, lhsEnabled, lhsEditing): - if case let .pack(rhsIndex, rhsTheme, rhsStrings, rhsInfo, rhsTopItem, rhsCount, rhsPlayAnimatedStickers, rhsEnabled, rhsEditing) = rhs { + case let .pack(lhsIndex, lhsTheme, lhsStrings, lhsInfo, lhsTopItem, lhsCount, lhsPlayAnimatedStickers, lhsEnabled, lhsEditing, lhsSelected): + if case let .pack(rhsIndex, rhsTheme, rhsStrings, rhsInfo, rhsTopItem, rhsCount, rhsPlayAnimatedStickers, rhsEnabled, rhsEditing, rhsSelected) = rhs { if lhsIndex != rhsIndex { return false } @@ -103,6 +106,9 @@ private enum ArchivedStickerPacksEntry: ItemListNodeEntry { if lhsEditing != rhsEditing { return false } + if lhsSelected != rhsSelected { + return false + } return true } else { return false @@ -119,9 +125,9 @@ private enum ArchivedStickerPacksEntry: ItemListNodeEntry { default: return true } - case let .pack(lhsIndex, _, _, _, _, _, _, _, _): + case let .pack(lhsIndex, _, _, _, _, _, _, _, _, _): switch rhs { - case let .pack(rhsIndex, _, _, _, _, _, _, _, _): + case let .pack(rhsIndex, _, _, _, _, _, _, _, _, _): return lhsIndex < rhsIndex default: return false @@ -134,8 +140,8 @@ private enum ArchivedStickerPacksEntry: ItemListNodeEntry { switch self { case let .info(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) - case let .pack(_, _, _, info, topItem, count, animatedStickers, enabled, editing): - return ItemListStickerPackItem(presentationData: presentationData, context: arguments.context, packInfo: info, itemCount: count, topItem: topItem, unread: false, control: .installation(installed: false), editing: editing, enabled: enabled, playAnimatedStickers: animatedStickers, sectionId: self.section, action: { + case let .pack(_, _, _, info, topItem, count, animatedStickers, enabled, editing, selected): + return ItemListStickerPackItem(presentationData: presentationData, context: arguments.context, packInfo: info, itemCount: count, topItem: topItem, unread: false, control: editing.editing ? .check(checked: selected ?? false) : .installation(installed: false), editing: editing, enabled: enabled, playAnimatedStickers: animatedStickers, sectionId: self.section, action: { arguments.openStickerPack(info) }, setPackIdWithRevealedOptions: { current, previous in arguments.setPackIdWithRevealedOptions(current, previous) @@ -144,6 +150,7 @@ private enum ArchivedStickerPacksEntry: ItemListNodeEntry { }, removePack: { arguments.removePack(info) }, toggleSelected: { + arguments.togglePackSelected(info.id) }) } } @@ -151,17 +158,20 @@ private enum ArchivedStickerPacksEntry: ItemListNodeEntry { private struct ArchivedStickerPacksControllerState: Equatable { let editing: Bool + let selectedPackIds: Set? let packIdWithRevealedOptions: ItemCollectionId? let removingPackIds: Set init() { self.editing = false + self.selectedPackIds = nil self.packIdWithRevealedOptions = nil self.removingPackIds = Set() } - init(editing: Bool, packIdWithRevealedOptions: ItemCollectionId?, removingPackIds: Set) { + init(editing: Bool, selectedPackIds: Set?, packIdWithRevealedOptions: ItemCollectionId?, removingPackIds: Set) { self.editing = editing + self.selectedPackIds = selectedPackIds self.packIdWithRevealedOptions = packIdWithRevealedOptions self.removingPackIds = removingPackIds } @@ -170,6 +180,9 @@ private struct ArchivedStickerPacksControllerState: Equatable { if lhs.editing != rhs.editing { return false } + if lhs.selectedPackIds != rhs.selectedPackIds { + return false + } if lhs.packIdWithRevealedOptions != rhs.packIdWithRevealedOptions { return false } @@ -181,15 +194,19 @@ private struct ArchivedStickerPacksControllerState: Equatable { } func withUpdatedEditing(_ editing: Bool) -> ArchivedStickerPacksControllerState { - return ArchivedStickerPacksControllerState(editing: editing, packIdWithRevealedOptions: self.packIdWithRevealedOptions, removingPackIds: self.removingPackIds) + return ArchivedStickerPacksControllerState(editing: editing, selectedPackIds: self.selectedPackIds, packIdWithRevealedOptions: self.packIdWithRevealedOptions, removingPackIds: self.removingPackIds) + } + + func withUpdatedSelectedPackIds(_ selectedPackIds: Set?) -> ArchivedStickerPacksControllerState { + return ArchivedStickerPacksControllerState(editing: self.editing, selectedPackIds: selectedPackIds, packIdWithRevealedOptions: self.packIdWithRevealedOptions, removingPackIds: self.removingPackIds) } func withUpdatedPackIdWithRevealedOptions(_ packIdWithRevealedOptions: ItemCollectionId?) -> ArchivedStickerPacksControllerState { - return ArchivedStickerPacksControllerState(editing: self.editing, packIdWithRevealedOptions: packIdWithRevealedOptions, removingPackIds: self.removingPackIds) + return ArchivedStickerPacksControllerState(editing: self.editing, selectedPackIds: self.selectedPackIds, packIdWithRevealedOptions: packIdWithRevealedOptions, removingPackIds: self.removingPackIds) } func withUpdatedRemovingPackIds(_ removingPackIds: Set) -> ArchivedStickerPacksControllerState { - return ArchivedStickerPacksControllerState(editing: editing, packIdWithRevealedOptions: self.self.packIdWithRevealedOptions, removingPackIds: removingPackIds) + return ArchivedStickerPacksControllerState(editing: self.editing, selectedPackIds: self.selectedPackIds, packIdWithRevealedOptions: self.packIdWithRevealedOptions, removingPackIds: removingPackIds) } } @@ -216,7 +233,7 @@ private func archivedStickerPacksControllerEntries(context: AccountContext, pres countTitle = presentationData.strings.StickerPack_StickerCount(item.info.count) } - entries.append(.pack(index, presentationData.theme, presentationData.strings, item.info, item.topItems.first, countTitle, context.sharedContext.energyUsageSettings.loopStickers, !state.removingPackIds.contains(item.info.id), ItemListStickerPackItemEditing(editable: true, editing: state.editing, revealed: state.packIdWithRevealedOptions == item.info.id, reorderable: false, selectable: true))) + entries.append(.pack(index, presentationData.theme, presentationData.strings, item.info, item.topItems.first, countTitle, context.sharedContext.energyUsageSettings.loopStickers, !state.removingPackIds.contains(item.info.id), ItemListStickerPackItemEditing(editable: true, editing: state.editing, revealed: state.packIdWithRevealedOptions == item.info.id, reorderable: false, selectable: true), state.selectedPackIds?.contains(item.info.id))) index += 1 } } @@ -295,10 +312,10 @@ public func archivedStickerPacksController(context: AccountContext, mode: Archiv return .complete() } else { return context.engine.stickers.addStickerPackInteractively(info: info, items: items) - |> ignoreValues - |> mapToSignal { _ -> Signal<(StickerPackCollectionInfo, [StickerPackItem]), NoError> in - } - |> then(.single((info, items))) + |> ignoreValues + |> mapToSignal { _ -> Signal<(StickerPackCollectionInfo, [StickerPackItem]), NoError> in + } + |> then(.single((info, items))) } case .fetching: break @@ -357,22 +374,22 @@ public func archivedStickerPacksController(context: AccountContext, mode: Archiv } if remove { let applyPacks: Signal = stickerPacks.get() - |> filter { $0 != nil } - |> take(1) - |> deliverOnMainQueue - |> mapToSignal { packs -> Signal in - if let packs = packs { - var updatedPacks = packs - for i in 0 ..< updatedPacks.count { - if updatedPacks[i].info.id == info.id { - updatedPacks.remove(at: i) - break - } + |> filter { $0 != nil } + |> take(1) + |> deliverOnMainQueue + |> mapToSignal { packs -> Signal in + if let packs = packs { + var updatedPacks = packs + for i in 0 ..< updatedPacks.count { + if updatedPacks[i].info.id == info.id { + updatedPacks.remove(at: i) + break } - stickerPacks.set(.single(updatedPacks)) } - - return .complete() + stickerPacks.set(.single(updatedPacks)) + } + + return .complete() } removePackDisposables.set((context.engine.stickers.removeArchivedStickerPack(info: info) |> then(applyPacks) |> deliverOnMainQueue).start(completed: { updateState { state in @@ -382,49 +399,155 @@ public func archivedStickerPacksController(context: AccountContext, mode: Archiv } }), forKey: info.id) } + }, togglePackSelected: { packId in + updateState { state in + if var selectedPackIds = state.selectedPackIds { + if selectedPackIds.contains(packId) { + selectedPackIds.remove(packId) + } else { + selectedPackIds.insert(packId) + } + return state.withUpdatedSelectedPackIds(selectedPackIds) + } else { + return state + } + } }) var previousPackCount: Int? let signal = combineLatest(context.sharedContext.presentationData, statePromise.get() |> deliverOnMainQueue, stickerPacks.get() |> deliverOnMainQueue, installedStickerPacks.get() |> deliverOnMainQueue, context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.stickerSettings]) |> deliverOnMainQueue) - |> deliverOnMainQueue - |> map { presentationData, state, packs, installedView, sharedData -> (ItemListControllerState, (ItemListNodeState, Any)) in - var stickerSettings = StickerSettings.defaultSettings - if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.stickerSettings]?.get(StickerSettings.self) { - stickerSettings = value - } - - var rightNavigationButton: ItemListNavigationButton? - if let packs = packs, packs.count != 0 { - if state.editing { - rightNavigationButton = ItemListNavigationButton(content: .text(presentationData.strings.Common_Done), style: .bold, enabled: true, action: { + |> deliverOnMainQueue + |> map { presentationData, state, packs, installedView, sharedData -> (ItemListControllerState, (ItemListNodeState, Any)) in + var stickerSettings = StickerSettings.defaultSettings + if let value = sharedData.entries[ApplicationSpecificSharedDataKeys.stickerSettings]?.get(StickerSettings.self) { + stickerSettings = value + } + + var rightNavigationButton: ItemListNavigationButton? + var toolbarItem: ItemListToolbarItem? + if let packs = packs, packs.count != 0 { + if state.editing { + rightNavigationButton = ItemListNavigationButton(content: .text(presentationData.strings.Common_Done), style: .bold, enabled: true, action: { + updateState { + $0.withUpdatedEditing(false) + } + }) + + let selectedCount = Int32(state.selectedPackIds?.count ?? 0) + toolbarItem = StickersToolbarItem(selectedCount: selectedCount, actions: [.init(title: presentationData.strings.StickerPacks_ActionDelete, isEnabled: selectedCount > 0, action: { + let actionSheet = ActionSheetController(presentationData: presentationData) + var items: [ActionSheetItem] = [] + + let title: String + switch mode { + case .emoji: + title = presentationData.strings.StickerPacks_DeleteEmojiPacksConfirmation(selectedCount) + default: + title = presentationData.strings.StickerPacks_DeleteStickerPacksConfirmation(selectedCount) + } + + items.append(ActionSheetButtonItem(title: title, color: .destructive, action: { [weak actionSheet] in + actionSheet?.dismissAnimated() + updateState { - $0.withUpdatedEditing(false) + $0.withUpdatedEditing(false).withUpdatedSelectedPackIds(nil) } - }) - } else { - rightNavigationButton = ItemListNavigationButton(content: .text(presentationData.strings.Common_Edit), style: .regular, enabled: true, action: { + + for entry in packs { + if let selectedPackIds = state.selectedPackIds, selectedPackIds.contains(entry.info.id) { + let _ = (context.engine.stickers.loadedStickerPack(reference: .id(id: entry.info.id.id, accessHash: entry.info.accessHash), forceActualized: false) + |> mapToSignal { result -> Signal<(StickerPackCollectionInfo, [StickerPackItem]), NoError> in + switch result { + case let .result(info, items, installed): + if installed { + return .complete() + } else { + return context.engine.stickers.addStickerPackInteractively(info: info, items: items) + |> ignoreValues + |> mapToSignal { _ -> Signal<(StickerPackCollectionInfo, [StickerPackItem]), NoError> in + } + |> then(.single((info, items))) + } + case .fetching: + break + case .none: + break + } + return .complete() + }).start() + } + } + })) + actionSheet.setItemGroups([ActionSheetItemGroup(items: items), ActionSheetItemGroup(items: [ + ActionSheetButtonItem(title: presentationData.strings.Common_Cancel, color: .accent, font: .bold, action: { [weak actionSheet] in + actionSheet?.dismissAnimated() + }) + ])]) + presentControllerImpl?(actionSheet, nil) + }), .init(title: presentationData.strings.StickerPacks_ActionUnarchive, isEnabled: selectedCount > 0, action: { + let actionSheet = ActionSheetController(presentationData: presentationData) + var items: [ActionSheetItem] = [] + items.append(ActionSheetButtonItem(title: presentationData.strings.StickerPacks_UnarchiveStickerPacksConfirmation(selectedCount), color: .destructive, action: { [weak actionSheet] in + actionSheet?.dismissAnimated() + updateState { - $0.withUpdatedEditing(true) + $0.withUpdatedEditing(false).withUpdatedSelectedPackIds(nil) } - }) - } + + var packIds: [ItemCollectionId] = [] + for entry in packs { + if let selectedPackIds = state.selectedPackIds, selectedPackIds.contains(entry.info.id) { + packIds.append(entry.info.id) + } + } + + let _ = context.engine.stickers.removeStickerPacksInteractively(ids: packIds, option: .archive).start() + })) + actionSheet.setItemGroups([ActionSheetItemGroup(items: items), ActionSheetItemGroup(items: [ + ActionSheetButtonItem(title: presentationData.strings.Common_Cancel, color: .accent, font: .bold, action: { [weak actionSheet] in + actionSheet?.dismissAnimated() + }) + ])]) + presentControllerImpl?(actionSheet, nil) + }), .init(title: presentationData.strings.StickerPacks_ActionShare, isEnabled: selectedCount > 0, action: { + updateState { + $0.withUpdatedEditing(true).withUpdatedSelectedPackIds(nil) + } + + var packNames: [String] = [] + for entry in packs { + if let selectedPackIds = state.selectedPackIds, selectedPackIds.contains(entry.info.id) { + packNames.append(entry.info.shortName) + } + } + let text = packNames.map { "https://t.me/addstickers/\($0)" }.joined(separator: "\n") + let shareController = ShareController(context: context, subject: .text(text), externalShare: true) + presentControllerImpl?(shareController, nil) + })]) + } else { + rightNavigationButton = ItemListNavigationButton(content: .text(presentationData.strings.Common_Edit), style: .regular, enabled: true, action: { + updateState { + $0.withUpdatedEditing(true).withUpdatedSelectedPackIds(Set()) + } + }) } - - let previous = previousPackCount - previousPackCount = packs?.count - - var emptyStateItem: ItemListControllerEmptyStateItem? - if packs == nil { - emptyStateItem = ItemListLoadingIndicatorEmptyStateItem(theme: presentationData.theme) - } - - let controllerState = ItemListControllerState(presentationData: ItemListPresentationData(presentationData), title: .text(presentationData.strings.StickerPacksSettings_ArchivedPacks), leftNavigationButton: nil, rightNavigationButton: rightNavigationButton, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back), animateChanges: true) - - let listState = ItemListNodeState(presentationData: ItemListPresentationData(presentationData), entries: archivedStickerPacksControllerEntries(context: context, presentationData: presentationData, state: state, packs: packs, installedView: installedView, stickerSettings: stickerSettings), style: .blocks, emptyStateItem: emptyStateItem, animateChanges: previous != nil && packs != nil && (previous! != 0 && previous! >= packs!.count - 10)) - return (controllerState, (listState, arguments)) - } |> afterDisposed { - actionsDisposable.dispose() + } + + let previous = previousPackCount + previousPackCount = packs?.count + + var emptyStateItem: ItemListControllerEmptyStateItem? + if packs == nil { + emptyStateItem = ItemListLoadingIndicatorEmptyStateItem(theme: presentationData.theme) + } + + let controllerState = ItemListControllerState(presentationData: ItemListPresentationData(presentationData), title: .text(presentationData.strings.StickerPacksSettings_ArchivedPacks), leftNavigationButton: nil, rightNavigationButton: rightNavigationButton, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back), animateChanges: true) + + let listState = ItemListNodeState(presentationData: ItemListPresentationData(presentationData), entries: archivedStickerPacksControllerEntries(context: context, presentationData: presentationData, state: state, packs: packs, installedView: installedView, stickerSettings: stickerSettings), style: .blocks, emptyStateItem: emptyStateItem, toolbarItem: toolbarItem, animateChanges: previous != nil && packs != nil && (previous! != 0 && previous! >= packs!.count - 10)) + return (controllerState, (listState, arguments)) + } |> afterDisposed { + actionsDisposable.dispose() } let controller = ItemListController(context: context, state: signal) diff --git a/submodules/SettingsUI/Sources/Stickers/InstalledStickerPacksController.swift b/submodules/SettingsUI/Sources/Stickers/InstalledStickerPacksController.swift index 8794b9750c..5c244678cc 100644 --- a/submodules/SettingsUI/Sources/Stickers/InstalledStickerPacksController.swift +++ b/submodules/SettingsUI/Sources/Stickers/InstalledStickerPacksController.swift @@ -1239,7 +1239,7 @@ public func installedStickerPacksController(context: AccountContext, mode: Insta return controller } -private class StickersToolbarItem: ItemListToolbarItem { +class StickersToolbarItem: ItemListToolbarItem { private let selectedCount: Int32 init(selectedCount: Int32, actions: [Action]) {