diff --git a/submodules/ListMessageItem/Sources/ListMessageSnippetItemNode.swift b/submodules/ListMessageItem/Sources/ListMessageSnippetItemNode.swift index 1bbb8a5347..6cc80b5d17 100644 --- a/submodules/ListMessageItem/Sources/ListMessageSnippetItemNode.swift +++ b/submodules/ListMessageItem/Sources/ListMessageSnippetItemNode.swift @@ -291,7 +291,7 @@ public final class ListMessageSnippetItemNode: ListMessageNode { switch wallpaper { case let .slug(slug, _, colors, intensity, angle): previewWallpaperFileReference = .message(message: MessageReference(item.message), media: file) - previewWallpaper = .file(id: file.fileId.id, accessHash: 0, isCreator: false, isDefault: false, isPattern: true, isDark: false, slug: slug, file: file, settings: WallpaperSettings(blur: false, motion: false, colors: colors, intensity: intensity, rotation: angle)) + previewWallpaper = .file(TelegramWallpaper.File(id: file.fileId.id, accessHash: 0, isCreator: false, isDefault: false, isPattern: true, isDark: false, slug: slug, file: file, settings: WallpaperSettings(blur: false, motion: false, colors: colors, intensity: intensity, rotation: angle))) default: break } diff --git a/submodules/PasscodeUI/Sources/PasscodeEntryControllerNode.swift b/submodules/PasscodeUI/Sources/PasscodeEntryControllerNode.swift index 93cfd75f59..3d99089a0a 100644 --- a/submodules/PasscodeUI/Sources/PasscodeEntryControllerNode.swift +++ b/submodules/PasscodeUI/Sources/PasscodeEntryControllerNode.swift @@ -228,14 +228,14 @@ final class PasscodeEntryControllerNode: ASDisplayNode { color4 = baseColor.withMultiplied(hue: 1.034, saturation: 0.583, brightness: 1.043) } self.background = CustomPasscodeBackground(size: size, colors: [color1, color2, color3, color4], inverted: false) - case let .gradient(_, colors, settings): - self.background = CustomPasscodeBackground(size: size, colors: colors.compactMap { UIColor(rgb: $0) }, inverted: (settings.intensity ?? 0) < 0) + case let .gradient(gradient): + self.background = CustomPasscodeBackground(size: size, colors: gradient.colors.compactMap { UIColor(rgb: $0) }, inverted: (gradient.settings.intensity ?? 0) < 0) case .image, .file: if let image = chatControllerBackgroundImage(theme: self.theme, wallpaper: self.wallpaper, mediaBox: self.accountManager.mediaBox, composed: false, knockoutMode: false) { self.background = ImageBasedPasscodeBackground(image: image, size: size) } else { - if case let .file(_, _, _, _, _, _, _, _, settings) = self.wallpaper, !settings.colors.isEmpty { - self.background = CustomPasscodeBackground(size: size, colors: settings.colors.compactMap { UIColor(rgb: $0) }, inverted: (settings.intensity ?? 0) < 0) + if case let .file(file) = self.wallpaper, !file.settings.colors.isEmpty { + self.background = CustomPasscodeBackground(size: size, colors: file.settings.colors.compactMap { UIColor(rgb: $0) }, inverted: (file.settings.intensity ?? 0) < 0) } else { self.background = GradientPasscodeBackground(size: size, backgroundColors: self.theme.passcode.backgroundColors.colors, buttonColor: self.theme.passcode.buttonColor) } diff --git a/submodules/SettingsUI/BUILD b/submodules/SettingsUI/BUILD index 5a22cf2187..90dbf66c2a 100644 --- a/submodules/SettingsUI/BUILD +++ b/submodules/SettingsUI/BUILD @@ -6,6 +6,9 @@ swift_library( srcs = glob([ "Sources/**/*.swift", ]), + copts = [ + "-warnings-as-errors", + ], deps = [ "//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit", "//submodules/AsyncDisplayKit:AsyncDisplayKit", diff --git a/submodules/SettingsUI/Sources/ChangePhoneNumberCodeController.swift b/submodules/SettingsUI/Sources/ChangePhoneNumberCodeController.swift index da25b216a6..f196db5ebc 100644 --- a/submodules/SettingsUI/Sources/ChangePhoneNumberCodeController.swift +++ b/submodules/SettingsUI/Sources/ChangePhoneNumberCodeController.swift @@ -88,13 +88,13 @@ private enum ChangePhoneNumberCodeEntry: ItemListNodeEntry { func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem { let arguments = arguments as! ChangePhoneNumberCodeControllerArguments switch self { - case let .codeEntry(theme, strings, title, text): + case let .codeEntry(_, _, title, text): return ItemListSingleLineInputItem(presentationData: presentationData, title: NSAttributedString(string: title, textColor: .black), text: text, placeholder: "", type: .number, spacing: 10.0, tag: ChangePhoneNumberCodeTag.input, sectionId: self.section, textUpdated: { updatedText in arguments.updateEntryText(updatedText) }, action: { arguments.next() }) - case let .codeInfo(theme, text): + case let .codeInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) } } @@ -172,7 +172,7 @@ private func timeoutSignal(codeData: ChangeAccountPhoneNumberData) -> Signal ListViewItem { let arguments = arguments as! AutodownloadMediaConnectionTypeControllerArguments switch self { - case let .master(theme, text, value): + case let .master(_, text, value): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, enableInteractiveChanges: true, enabled: true, sectionId: self.section, style: .blocks, updated: { value in arguments.toggleMaster(value) }) - case let .dataUsageHeader(theme, text): + case let .dataUsageHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) case let .dataUsageItem(theme, strings, value, customPosition, enabled): return AutodownloadDataUsagePickerItem(theme: theme, strings: strings, value: value, customPosition: customPosition, enabled: enabled, sectionId: self.section, updated: { preset in arguments.changePreset(preset) }) - case let .typesHeader(theme, text): + case let .typesHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .photos(theme, text, value, enabled): + case let .photos(_, text, value, enabled): return ItemListDisclosureItem(presentationData: presentationData, title: text, enabled: enabled, label: value, labelStyle: .detailText, sectionId: self.section, style: .blocks, action: { arguments.customize(.photo) }) - case let .videos(theme, text, value, enabled): + case let .videos(_, text, value, enabled): return ItemListDisclosureItem(presentationData: presentationData, title: text, enabled: enabled, label: value, labelStyle: .detailText, sectionId: self.section, style: .blocks, action: { arguments.customize(.video) }) - case let .files(theme, text, value, enabled): + case let .files(_, text, value, enabled): return ItemListDisclosureItem(presentationData: presentationData, title: text, enabled: enabled, label: value, labelStyle: .detailText, sectionId: self.section, style: .blocks, action: { arguments.customize(.file) }) - case let .voiceMessagesInfo(theme, text): + case let .voiceMessagesInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) } } @@ -278,7 +278,6 @@ private func autodownloadMediaConnectionTypeControllerEntries(presentationData: func autodownloadMediaConnectionTypeController(context: AccountContext, connectionType: AutomaticDownloadConnectionType) -> ViewController { var pushControllerImpl: ((ViewController) -> Void)? - var presentControllerImpl: ((ViewController) -> Void)? let arguments = AutodownloadMediaConnectionTypeControllerArguments(toggleMaster: { value in let _ = updateMediaDownloadSettingsInteractively(accountManager: context.sharedContext.accountManager, { settings in @@ -356,8 +355,5 @@ func autodownloadMediaConnectionTypeController(context: AccountContext, connecti (controller.navigationController as? NavigationController)?.pushViewController(c) } } - presentControllerImpl = { [weak controller] c in - controller?.present(c, in: .window(.root), with: ViewControllerPresentationArguments(presentationAnimation: .modalSheet)) - } return controller } diff --git a/submodules/SettingsUI/Sources/Data and Storage/DataAndStorageSettingsController.swift b/submodules/SettingsUI/Sources/Data and Storage/DataAndStorageSettingsController.swift index d9432a7a70..fa1918458e 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/DataAndStorageSettingsController.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/DataAndStorageSettingsController.swift @@ -311,49 +311,49 @@ private enum DataAndStorageEntry: ItemListNodeEntry { func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem { let arguments = arguments as! DataAndStorageControllerArguments switch self { - case let .storageUsage(theme, text): + case let .storageUsage(_, text): return ItemListDisclosureItem(presentationData: presentationData, title: text, label: "", sectionId: self.section, style: .blocks, action: { arguments.openStorageUsage() }) - case let .networkUsage(theme, text): + case let .networkUsage(_, text): return ItemListDisclosureItem(presentationData: presentationData, title: text, label: "", sectionId: self.section, style: .blocks, action: { arguments.openNetworkUsage() }) - case let .automaticDownloadHeader(theme, text): + case let .automaticDownloadHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .automaticDownloadCellular(theme, text, value): + case let .automaticDownloadCellular(_, text, value): return ItemListDisclosureItem(presentationData: presentationData, title: text, label: value, labelStyle: .detailText, sectionId: self.section, style: .blocks, action: { arguments.openAutomaticDownloadConnectionType(.cellular) }) - case let .automaticDownloadWifi(theme, text, value): + case let .automaticDownloadWifi(_, text, value): return ItemListDisclosureItem(presentationData: presentationData, title: text, label: value, labelStyle: .detailText, sectionId: self.section, style: .blocks, action: { arguments.openAutomaticDownloadConnectionType(.wifi) }) - case let .automaticDownloadReset(theme, text, enabled): + case let .automaticDownloadReset(_, text, enabled): return ItemListActionItem(presentationData: presentationData, title: text, kind: enabled ? .generic : .disabled, alignment: .natural, sectionId: self.section, style: .blocks, action: { if enabled { arguments.resetAutomaticDownload() } }, tag: DataAndStorageEntryTag.automaticDownloadReset) - case let .autoplayHeader(theme, text): + case let .autoplayHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .autoplayGifs(theme, text, value): + case let .autoplayGifs(_, text, value): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, sectionId: self.section, style: .blocks, updated: { value in arguments.toggleAutoplayGifs(value) }, tag: DataAndStorageEntryTag.autoplayGifs) - case let .autoplayVideos(theme, text, value): + case let .autoplayVideos(_, text, value): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, sectionId: self.section, style: .blocks, updated: { value in arguments.toggleAutoplayVideos(value) }, tag: DataAndStorageEntryTag.autoplayVideos) - case let .voiceCallsHeader(theme, text): + case let .voiceCallsHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .useLessVoiceData(theme, text, value): + case let .useLessVoiceData(_, text, value): return ItemListDisclosureItem(presentationData: presentationData, title: text, label: value, sectionId: self.section, style: .blocks, action: { arguments.openVoiceUseLessData() }) - case let .otherHeader(theme, text): + case let .otherHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .shareSheet(theme, text): + case let .shareSheet(_, text): return ItemListDisclosureItem(presentationData: presentationData, title: text, label: "", sectionId: self.section, style: .blocks, action: { arguments.openIntents() }) @@ -361,27 +361,27 @@ private enum DataAndStorageEntry: ItemListNodeEntry { return ItemListDisclosureItem(presentationData: presentationData, title: text, label: "", sectionId: self.section, style: .blocks, action: { arguments.openWidgetSettings() }) - case let .saveIncomingPhotos(theme, text): + case let .saveIncomingPhotos(_, text): return ItemListDisclosureItem(presentationData: presentationData, title: text, label: "", sectionId: self.section, style: .blocks, action: { arguments.openSaveIncomingPhotos() }) - case let .saveEditedPhotos(theme, text, value): + case let .saveEditedPhotos(_, text, value): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, sectionId: self.section, style: .blocks, updated: { value in arguments.toggleSaveEditedPhotos(value) }, tag: DataAndStorageEntryTag.saveEditedPhotos) - case let .openLinksIn(theme, text, value): + case let .openLinksIn(_, text, value): return ItemListDisclosureItem(presentationData: presentationData, title: text, label: value, sectionId: self.section, style: .blocks, action: { arguments.openBrowserSelection() }) - case let .downloadInBackground(theme, text, value): + case let .downloadInBackground(_, text, value): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, sectionId: self.section, style: .blocks, updated: { value in arguments.toggleDownloadInBackground(value) }, tag: DataAndStorageEntryTag.downloadInBackground) - case let .downloadInBackgroundInfo(theme, text): + case let .downloadInBackgroundInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) - case let .connectionHeader(theme, text): + case let .connectionHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .connectionProxy(theme, text, value): + case let .connectionProxy(_, text, value): return ItemListDisclosureItem(presentationData: presentationData, title: text, label: value, sectionId: self.section, style: .blocks, action: { arguments.openProxy() }) diff --git a/submodules/SettingsUI/Sources/Data and Storage/IntentsSettingsController.swift b/submodules/SettingsUI/Sources/Data and Storage/IntentsSettingsController.swift index 249c510aea..755b4e3860 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/IntentsSettingsController.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/IntentsSettingsController.swift @@ -184,47 +184,46 @@ private enum IntentsSettingsControllerEntry: ItemListNodeEntry { func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem { let arguments = arguments as! IntentsSettingsControllerArguments switch self { - case let .accountHeader(theme, text): + case let .accountHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .account(theme, peer, selected, _): + case let .account(_, peer, selected, _): return ItemListPeerItem(presentationData: presentationData, dateTimeFormat: PresentationDateTimeFormat(), nameDisplayOrder: .firstLast, context: arguments.context.sharedContext.makeTempAccountContext(account: arguments.context.account), peer: peer, height: .generic, aliasHandling: .standard, nameStyle: .plain, presence: nil, text: .none, label: .none, editing: ItemListPeerItemEditing(editable: true, editing: false, revealed: false), revealOptions: nil, switchValue: ItemListPeerItemSwitch(value: selected, style: .check), enabled: true, selectable: true, sectionId: self.section, action: { arguments.updateSettings { $0.withUpdatedAccount(peer.id) } }, setPeerIdWithRevealedOptions: { _, _ in}, removePeer: { _ in }) - return ItemListTextItem(presentationData: presentationData, text: .plain(""), sectionId: self.section) - case let .accountInfo(theme, text): + case let .accountInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) - case let .chatsHeader(theme, text): + case let .chatsHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .contacts(theme, text, value): + case let .contacts(_, text, value): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, enableInteractiveChanges: true, enabled: true, sectionId: self.section, style: .blocks, updated: { value in arguments.updateSettings { $0.withUpdatedContacts(value) } }) - case let .savedMessages(theme, text, value): + case let .savedMessages(_, text, value): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, enableInteractiveChanges: true, enabled: true, sectionId: self.section, style: .blocks, updated: { value in arguments.updateSettings { $0.withUpdatedSavedMessages(value) } }) - case let .privateChats(theme, text, value): + case let .privateChats(_, text, value): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, enableInteractiveChanges: true, enabled: true, sectionId: self.section, style: .blocks, updated: { value in arguments.updateSettings { $0.withUpdatedPrivateChats(value) } }) - case let .groups(theme, text, value): + case let .groups(_, text, value): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, enableInteractiveChanges: true, enabled: true, sectionId: self.section, style: .blocks, updated: { value in arguments.updateSettings { $0.withUpdatedGroups(value) } }) - case let .chatsInfo(theme, text): + case let .chatsInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) - case let .suggestHeader(theme, text): + case let .suggestHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .suggestAll(theme, text, value): + case let .suggestAll(_, text, value): return ItemListCheckboxItem(presentationData: presentationData, title: text, style: .left, checked: value, zeroSeparatorInsets: false, sectionId: self.section, action: { arguments.updateSettings { $0.withUpdatedOnlyShared(false) } }) - case let .suggestOnlyShared(theme, text, value): + case let .suggestOnlyShared(_, text, value): return ItemListCheckboxItem(presentationData: presentationData, title: text, style: .left, checked: value, zeroSeparatorInsets: false, sectionId: self.section, action: { arguments.updateSettings { $0.withUpdatedOnlyShared(true) } }) - case let .resetAll(theme, text): + case let .resetAll(_, text): return ItemListActionItem(presentationData: presentationData, title: text, kind: .destructive, alignment: .natural, sectionId: self.section, style: .blocks, action: { arguments.resetAll() }) @@ -263,16 +262,13 @@ private func intentsSettingsControllerEntries(context: AccountContext, presentat } public func intentsSettingsController(context: AccountContext) -> ViewController { - var pushControllerImpl: ((ViewController) -> Void)? var presentControllerImpl: ((ViewController) -> Void)? - - let updateDisposable = MetaDisposable() + let arguments = IntentsSettingsControllerArguments(context: context, updateSettings: { f in let _ = updateIntentsSettingsInteractively(accountManager: context.sharedContext.accountManager, f).start(next: { previous, updated in guard let previous = previous, let updated = updated else { return } - let accountPeerId = context.account.peerId if previous.contacts && !updated.contacts { deleteAllSendMessageIntents() } @@ -285,7 +281,7 @@ public func intentsSettingsController(context: AccountContext) -> ViewController if previous.groups && !updated.groups { deleteAllSendMessageIntents() } - if previous.account != updated.account, let previousAccount = previous.account { + if previous.account != updated.account, let _ = previous.account { deleteAllSendMessageIntents() } }) @@ -318,9 +314,6 @@ public func intentsSettingsController(context: AccountContext) -> ViewController } let controller = ItemListController(context: context, state: signal) - pushControllerImpl = { [weak controller] c in - (controller?.navigationController as? NavigationController)?.pushViewController(c) - } presentControllerImpl = { [weak controller] c in controller?.present(c, in: .window(.root)) } diff --git a/submodules/SettingsUI/Sources/Data and Storage/KeepMediaDurationPickerItem.swift b/submodules/SettingsUI/Sources/Data and Storage/KeepMediaDurationPickerItem.swift index 575a85d06c..871357d4b5 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/KeepMediaDurationPickerItem.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/KeepMediaDurationPickerItem.swift @@ -108,7 +108,7 @@ private final class KeepMediaDurationPickerItemNode: ListViewItemNode { self.maskNode = ASImageNode() var textNodes: [TextNode] = [] - for i in 0 ..< 4 { + for _ in 0 ..< 4 { let textNode = TextNode() textNode.isUserInteractionEnabled = false textNode.displaysAsynchronously = false diff --git a/submodules/SettingsUI/Sources/Data and Storage/MaximumCacheSizePickerItem.swift b/submodules/SettingsUI/Sources/Data and Storage/MaximumCacheSizePickerItem.swift index 1b7f603eb2..9c072c596d 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/MaximumCacheSizePickerItem.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/MaximumCacheSizePickerItem.swift @@ -123,7 +123,7 @@ private final class MaximumCacheSizePickerItemNode: ListViewItemNode { self.maskNode = ASImageNode() var textNodes: [TextNode] = [] - for i in 0 ..< 4 { + for _ in 0 ..< 4 { let textNode = TextNode() textNode.isUserInteractionEnabled = false textNode.displaysAsynchronously = false diff --git a/submodules/SettingsUI/Sources/Data and Storage/ProxyListSettingsController.swift b/submodules/SettingsUI/Sources/Data and Storage/ProxyListSettingsController.swift index eb26e53988..014cdfdbad 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/ProxyListSettingsController.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/ProxyListSettingsController.swift @@ -200,7 +200,7 @@ private enum ProxySettingsControllerEntry: ItemListNodeEntry { func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem { let arguments = arguments as! ProxySettingsControllerArguments switch self { - case let .enabled(theme, text, value, createsNew): + case let .enabled(_, text, value, createsNew): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, enableInteractiveChanges: !createsNew, enabled: true, sectionId: self.section, style: .blocks, updated: { value in if createsNew { arguments.addNewServer() @@ -208,9 +208,9 @@ private enum ProxySettingsControllerEntry: ItemListNodeEntry { arguments.toggleEnabled(value) } }) - case let .serversHeader(theme, text): + case let .serversHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .addServer(theme, text, _): + case let .addServer(_, text, _): return ProxySettingsActionItem(presentationData: presentationData, title: text, icon: .add, sectionId: self.section, editing: false, action: { arguments.addNewServer() }) @@ -224,15 +224,15 @@ private enum ProxySettingsControllerEntry: ItemListNodeEntry { }, removeServer: { _ in arguments.removeServer(settings) }) - case let .shareProxyList(theme, text): + case let .shareProxyList(_, text): return ProxySettingsActionItem(presentationData: presentationData, title: text, sectionId: self.section, editing: false, action: { arguments.shareProxyList() }) - case let .useForCalls(theme, text, value): + case let .useForCalls(_, text, value): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, enableInteractiveChanges: true, enabled: true, sectionId: self.section, style: .blocks, updated: { value in arguments.toggleUseForCalls(value) }) - case let .useForCallsInfo(theme, text): + case let .useForCallsInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) } } @@ -314,7 +314,6 @@ public func proxySettingsController(context: AccountContext, mode: ProxySettings } public func proxySettingsController(accountManager: AccountManager, context: AccountContext? = nil, postbox: Postbox, network: Network, mode: ProxySettingsControllerMode, presentationData: PresentationData, updatedPresentationData: Signal) -> ViewController { - var presentControllerImpl: ((ViewController, Any?) -> Void)? var pushControllerImpl: ((ViewController) -> Void)? var dismissImpl: (() -> Void)? let stateValue = Atomic(value: ProxySettingsControllerState()) @@ -439,9 +438,6 @@ public func proxySettingsController(accountManager: AccountManager, context: Acc let controller = ItemListController(presentationData: ItemListPresentationData(presentationData), updatedPresentationData: updatedPresentationData |> map(ItemListPresentationData.init(_:)), state: signal, tabBarItem: nil) controller.navigationPresentation = .modal - presentControllerImpl = { [weak controller] c, a in - controller?.present(c, in: .window(.root), with: a) - } pushControllerImpl = { [weak controller] c in (controller?.navigationController as? NavigationController)?.pushViewController(c) } diff --git a/submodules/SettingsUI/Sources/Data and Storage/ProxyServerActionSheetController.swift b/submodules/SettingsUI/Sources/Data and Storage/ProxyServerActionSheetController.swift index 2da448a17a..1b56234871 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/ProxyServerActionSheetController.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/ProxyServerActionSheetController.swift @@ -376,7 +376,7 @@ private final class ProxyServerActionItemNode: ActionSheetItemNode { let proxyServerSettings = self.server let _ = (self.accountManager.transaction { transaction -> ProxySettings in var currentSettings: ProxySettings? - updateProxySettingsInteractively(transaction: transaction, { settings in + let _ = updateProxySettingsInteractively(transaction: transaction, { settings in currentSettings = settings var settings = settings if let index = settings.servers.firstIndex(of: proxyServerSettings) { diff --git a/submodules/SettingsUI/Sources/Data and Storage/ProxyServerSettingsController.swift b/submodules/SettingsUI/Sources/Data and Storage/ProxyServerSettingsController.swift index 10257c7264..5ebc2a616f 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/ProxyServerSettingsController.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/ProxyServerSettingsController.swift @@ -116,13 +116,13 @@ private enum ProxySettingsEntry: ItemListNodeEntry { func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem { let arguments = arguments as! proxyServerSettingsControllerArguments switch self { - case let .usePasteboardSettings(theme, title): + case let .usePasteboardSettings(_, title): return ItemListActionItem(presentationData: presentationData, title: title, kind: .generic, alignment: .natural, sectionId: self.section, style: .blocks, action: { arguments.usePasteboardSettings() }) - case let .usePasteboardInfo(theme, text): + case let .usePasteboardInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) - case let .modeSocks5(theme, text, value): + case let .modeSocks5(_, text, value): return ItemListCheckboxItem(presentationData: presentationData, title: text, style: .left, checked: value, zeroSeparatorInsets: false, sectionId: self.section, action: { arguments.updateState { state in var state = state @@ -130,7 +130,7 @@ private enum ProxySettingsEntry: ItemListNodeEntry { return state } }) - case let .modeMtp(theme, text, value): + case let .modeMtp(_, text, value): return ItemListCheckboxItem(presentationData: presentationData, title: text, style: .left, checked: value, zeroSeparatorInsets: false, sectionId: self.section, action: { arguments.updateState { state in var state = state @@ -138,9 +138,9 @@ private enum ProxySettingsEntry: ItemListNodeEntry { return state } }) - case let .connectionHeader(theme, text): + case let .connectionHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .connectionServer(theme, strings, placeholder, text): + case let .connectionServer(_, _, placeholder, text): return ItemListSingleLineInputItem(presentationData: presentationData, title: NSAttributedString(), text: text, placeholder: placeholder, type: .regular(capitalization: false, autocorrection: false), sectionId: self.section, textUpdated: { value in arguments.updateState { current in var state = current @@ -148,7 +148,7 @@ private enum ProxySettingsEntry: ItemListNodeEntry { return state } }, action: {}) - case let .connectionPort(theme, strings, placeholder, text): + case let .connectionPort(_, _, placeholder, text): return ItemListSingleLineInputItem(presentationData: presentationData, title: NSAttributedString(), text: text, placeholder: placeholder, type: .number, sectionId: self.section, textUpdated: { value in arguments.updateState { current in var state = current @@ -156,9 +156,9 @@ private enum ProxySettingsEntry: ItemListNodeEntry { return state } }, action: {}) - case let .credentialsHeader(theme, text): + case let .credentialsHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .credentialsUsername(theme, strings, placeholder, text): + case let .credentialsUsername(_, _, placeholder, text): return ItemListSingleLineInputItem(presentationData: presentationData, title: NSAttributedString(), text: text, placeholder: placeholder, sectionId: self.section, textUpdated: { value in arguments.updateState { current in var state = current @@ -166,7 +166,7 @@ private enum ProxySettingsEntry: ItemListNodeEntry { return state } }, action: {}) - case let .credentialsPassword(theme, strings, placeholder, text): + case let .credentialsPassword(_, _, placeholder, text): return ItemListSingleLineInputItem(presentationData: presentationData, title: NSAttributedString(), text: text, placeholder: placeholder, type: .password, sectionId: self.section, textUpdated: { value in arguments.updateState { current in var state = current @@ -174,7 +174,7 @@ private enum ProxySettingsEntry: ItemListNodeEntry { return state } }, action: {}) - case let .credentialsSecret(theme, strings, placeholder, text): + case let .credentialsSecret(_, _, placeholder, text): return ItemListSingleLineInputItem(presentationData: presentationData, title: NSAttributedString(), text: text, placeholder: placeholder, type: .regular(capitalization: false, autocorrection: false), sectionId: self.section, textUpdated: { value in arguments.updateState { current in var state = current @@ -182,7 +182,7 @@ private enum ProxySettingsEntry: ItemListNodeEntry { return state } }, action: {}) - case let .share(theme, text, enabled): + case let .share(_, text, enabled): return ItemListActionItem(presentationData: presentationData, title: text, kind: enabled ? .generic : .disabled, alignment: .natural, sectionId: self.section, style: .blocks, action: { arguments.share() }) diff --git a/submodules/SettingsUI/Sources/Data and Storage/SaveIncomingMediaController.swift b/submodules/SettingsUI/Sources/Data and Storage/SaveIncomingMediaController.swift index be37e859fd..b06e56bfb9 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/SaveIncomingMediaController.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/SaveIncomingMediaController.swift @@ -62,21 +62,21 @@ private enum SaveIncomingMediaEntry: ItemListNodeEntry { func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem { let arguments = arguments as! SaveIncomingMediaControllerArguments switch self { - case let .header(theme, text): + case let .header(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .contacts(theme, text, value): + case let .contacts(_, text, value): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, enableInteractiveChanges: true, enabled: true, sectionId: self.section, style: .blocks, updated: { value in arguments.toggle(.contact) }) - case let .otherPrivate(theme, text, value): + case let .otherPrivate(_, text, value): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, enableInteractiveChanges: true, enabled: true, sectionId: self.section, style: .blocks, updated: { value in arguments.toggle(.otherPrivate) }) - case let .groups(theme, text, value): + case let .groups(_, text, value): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, enableInteractiveChanges: true, enabled: true, sectionId: self.section, style: .blocks, updated: { value in arguments.toggle(.group) }) - case let .channels(theme, text, value): + case let .channels(_, text, value): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, enableInteractiveChanges: true, enabled: true, sectionId: self.section, style: .blocks, updated: { value in arguments.toggle(.channel) }) diff --git a/submodules/SettingsUI/Sources/Data and Storage/StorageUsageController.swift b/submodules/SettingsUI/Sources/Data and Storage/StorageUsageController.swift index f3cdb336b6..b5d0018ab7 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/StorageUsageController.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/StorageUsageController.swift @@ -230,7 +230,7 @@ private enum StorageUsageEntry: ItemListNodeEntry { func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem { let arguments = arguments as! StorageUsageControllerArguments switch self { - case let .keepMediaHeader(theme, text): + case let .keepMediaHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) case let .keepMedia(theme, strings, value): return KeepMediaDurationPickerItem(theme: theme, strings: strings, value: value, sectionId: self.section, updated: { updatedValue in diff --git a/submodules/SettingsUI/Sources/Data and Storage/VoiceCallDataSavingController.swift b/submodules/SettingsUI/Sources/Data and Storage/VoiceCallDataSavingController.swift index 9144bd3b83..fe684bb32e 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/VoiceCallDataSavingController.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/VoiceCallDataSavingController.swift @@ -81,19 +81,19 @@ private enum VoiceCallDataSavingEntry: ItemListNodeEntry { func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem { let arguments = arguments as! VoiceCallDataSavingControllerArguments switch self { - case let .never(theme, text, value): + case let .never(_, text, value): return ItemListCheckboxItem(presentationData: presentationData, title: text, style: .left, checked: value, zeroSeparatorInsets: false, sectionId: self.section, action: { arguments.updateSelection(.never) }) - case let .cellular(theme, text, value): + case let .cellular(_, text, value): return ItemListCheckboxItem(presentationData: presentationData, title: text, style: .left, checked: value, zeroSeparatorInsets: false, sectionId: self.section, action: { arguments.updateSelection(.cellular) }) - case let .always(theme, text, value): + case let .always(_, text, value): return ItemListCheckboxItem(presentationData: presentationData, title: text, style: .left, checked: value, zeroSeparatorInsets: false, sectionId: self.section, action: { arguments.updateSelection(.always) }) - case let .info(theme, text): + case let .info(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) } } diff --git a/submodules/SettingsUI/Sources/Data and Storage/WebBrowserItem.swift b/submodules/SettingsUI/Sources/Data and Storage/WebBrowserItem.swift index 4c07fd94de..62e0eb33a0 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/WebBrowserItem.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/WebBrowserItem.swift @@ -133,7 +133,7 @@ private final class WebBrowserItemNode: ListViewItemNode { let currentItem = self.item return { item, params, neighbors in - var leftInset: CGFloat = params.leftInset + 16.0 + 43.0 + let leftInset: CGFloat = params.leftInset + 16.0 + 43.0 let iconSize = CGSize(width: 29.0, height: 29.0) let arguments = TransformImageArguments(corners: ImageCorners(radius: 5.0), imageSize: iconSize, boundingSize: iconSize, intrinsicInsets: UIEdgeInsets(), emptyColor: item.presentationData.theme.list.mediaPlaceholderColor) diff --git a/submodules/SettingsUI/Sources/Data and Storage/WebBrowserSettingsController.swift b/submodules/SettingsUI/Sources/Data and Storage/WebBrowserSettingsController.swift index 5b7a1d76c6..02ee92d985 100644 --- a/submodules/SettingsUI/Sources/Data and Storage/WebBrowserSettingsController.swift +++ b/submodules/SettingsUI/Sources/Data and Storage/WebBrowserSettingsController.swift @@ -68,9 +68,9 @@ private enum WebBrowserSettingsControllerEntry: ItemListNodeEntry { func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem { let arguments = arguments as! WebBrowserSettingsControllerArguments switch self { - case let .browserHeader(theme, text): + case let .browserHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .browser(theme, title, application, identifier, selected, _): + case let .browser(_, title, application, identifier, selected, _): return WebBrowserItem(account: arguments.context.account, presentationData: presentationData, title: title, application: application, checked: selected, sectionId: self.section) { arguments.updateDefaultBrowser(identifier) } @@ -96,10 +96,6 @@ private func webBrowserSettingsControllerEntries(context: AccountContext, presen } public func webBrowserSettingsController(context: AccountContext) -> ViewController { - var pushControllerImpl: ((ViewController) -> Void)? - var presentControllerImpl: ((ViewController) -> Void)? - - let updateDisposable = MetaDisposable() let arguments = WebBrowserSettingsControllerArguments(context: context, updateDefaultBrowser: { identifier in let _ = updateWebBrowserSettingsInteractively(accountManager: context.sharedContext.accountManager, { $0.withUpdatedDefaultWebBrowser(identifier) }).start() }) @@ -116,11 +112,5 @@ public func webBrowserSettingsController(context: AccountContext) -> ViewControl } let controller = ItemListController(context: context, state: signal) - pushControllerImpl = { [weak controller] c in - (controller?.navigationController as? NavigationController)?.pushViewController(c) - } - presentControllerImpl = { [weak controller] c in - controller?.present(c, in: .window(.root)) - } return controller } diff --git a/submodules/SettingsUI/Sources/LogoutOptionsController.swift b/submodules/SettingsUI/Sources/LogoutOptionsController.swift index 737a864dda..6134bfd35c 100644 --- a/submodules/SettingsUI/Sources/LogoutOptionsController.swift +++ b/submodules/SettingsUI/Sources/LogoutOptionsController.swift @@ -75,33 +75,33 @@ private enum LogoutOptionsEntry: ItemListNodeEntry, Equatable { func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem { let arguments = arguments as! LogoutOptionsItemArguments switch self { - case let .alternativeHeader(theme, title): + case let .alternativeHeader(_, title): return ItemListSectionHeaderItem(presentationData: presentationData, text: title, sectionId: self.section) - case let .addAccount(theme, title, text): + case let .addAccount(_, title, text): return ItemListDisclosureItem(presentationData: presentationData, icon: PresentationResourcesSettings.addAccount, title: title, label: text, labelStyle: .multilineDetailText, sectionId: self.section, style: .blocks, disclosureStyle: .arrow, action: { arguments.addAccount() }) - case let .setPasscode(theme, title, text): + case let .setPasscode(_, title, text): return ItemListDisclosureItem(presentationData: presentationData, icon: PresentationResourcesSettings.setPasscode, title: title, label: text, labelStyle: .multilineDetailText, sectionId: self.section, style: .blocks, disclosureStyle: .arrow, action: { arguments.setPasscode() }) - case let .clearCache(theme, title, text): + case let .clearCache(_, title, text): return ItemListDisclosureItem(presentationData: presentationData, icon: PresentationResourcesSettings.clearCache, title: title, label: text, labelStyle: .multilineDetailText, sectionId: self.section, style: .blocks, disclosureStyle: .arrow, action: { arguments.clearCache() }) - case let .changePhoneNumber(theme, title, text): + case let .changePhoneNumber(_, title, text): return ItemListDisclosureItem(presentationData: presentationData, icon: PresentationResourcesSettings.changePhoneNumber, title: title, label: text, labelStyle: .multilineDetailText, sectionId: self.section, style: .blocks, disclosureStyle: .arrow, action: { arguments.changePhoneNumber() }) - case let .contactSupport(theme, title, text): + case let .contactSupport(_, title, text): return ItemListDisclosureItem(presentationData: presentationData, icon: PresentationResourcesSettings.support, title: title, label: text, labelStyle: .multilineDetailText, sectionId: self.section, style: .blocks, disclosureStyle: .arrow, action: { arguments.contactSupport() }) - case let .logout(theme, title): + case let .logout(_, title): return ItemListActionItem(presentationData: presentationData, title: title, kind: .destructive, alignment: .natural, sectionId: self.section, style: .blocks, action: { arguments.logout() }) - case let .logoutInfo(theme, title): + case let .logoutInfo(_, title): return ItemListTextItem(presentationData: presentationData, text: .plain(title), sectionId: self.section) } } diff --git a/submodules/SettingsUI/Sources/Notifications/Exceptions/NotificationExceptionControllerNode.swift b/submodules/SettingsUI/Sources/Notifications/Exceptions/NotificationExceptionControllerNode.swift index 2186263bdb..27e56d5f88 100644 --- a/submodules/SettingsUI/Sources/Notifications/Exceptions/NotificationExceptionControllerNode.swift +++ b/submodules/SettingsUI/Sources/Notifications/Exceptions/NotificationExceptionControllerNode.swift @@ -529,7 +529,7 @@ private enum NotificationExceptionEntry : ItemListNodeEntry { return ItemListPeerActionItem(presentationData: presentationData, icon: icon, title: strings.Notification_Exceptions_AddException, alwaysPlain: true, sectionId: self.section, editing: editing, action: { arguments.selectPeer() }) - case let .peer(_, peer, theme, strings, dateTimeFormat, nameDisplayOrder, value, _, revealed, editing, isSearching): + case let .peer(_, peer, _, _, dateTimeFormat, nameDisplayOrder, value, _, revealed, editing, isSearching): return ItemListPeerItem(presentationData: presentationData, dateTimeFormat: dateTimeFormat, nameDisplayOrder: nameDisplayOrder, context: arguments.context, peer: peer, presence: nil, text: .text(value, .secondary), label: .none, editing: ItemListPeerItemEditing(editable: true, editing: editing, revealed: revealed), switchValue: nil, enabled: true, selectable: true, sectionId: self.section, action: { arguments.openPeer(peer) }, setPeerIdWithRevealedOptions: { peerId, fromPeerId in @@ -542,7 +542,7 @@ private enum NotificationExceptionEntry : ItemListNodeEntry { arguments.openPeer(peer) }, setPeerIdWithRevealedOptions: { _, _ in }) - case let .removeAll(theme, strings): + case let .removeAll(_, strings): return ItemListActionItem(presentationData: presentationData, title: strings.Notification_Exceptions_DeleteAll, kind: .destructive, alignment: .center, sectionId: self.section, style: .blocks, action: { arguments.removeAll() }) diff --git a/submodules/SettingsUI/Sources/Notifications/Exceptions/NotificationExceptionSettingsController.swift b/submodules/SettingsUI/Sources/Notifications/Exceptions/NotificationExceptionSettingsController.swift index 9e6c9ab6cb..9638dd5ef2 100644 --- a/submodules/SettingsUI/Sources/Notifications/Exceptions/NotificationExceptionSettingsController.swift +++ b/submodules/SettingsUI/Sources/Notifications/Exceptions/NotificationExceptionSettingsController.swift @@ -37,9 +37,9 @@ private enum NotificationPeerExceptionEntryId : Hashable { case soundClassicHeader case none case `default` - - var hashValue: Int { - return 0 + + func hash(into hasher: inout Hasher) { + hasher.combine(0) } } diff --git a/submodules/SettingsUI/Sources/Notifications/NotificationsAndSounds.swift b/submodules/SettingsUI/Sources/Notifications/NotificationsAndSounds.swift index c755e29656..27412b4a81 100644 --- a/submodules/SettingsUI/Sources/Notifications/NotificationsAndSounds.swift +++ b/submodules/SettingsUI/Sources/Notifications/NotificationsAndSounds.swift @@ -584,142 +584,142 @@ private enum NotificationsAndSoundsEntry: ItemListNodeEntry { func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem { let arguments = arguments as! NotificationsAndSoundsArguments switch self { - case let .accountsHeader(theme, text): + case let .accountsHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .allAccounts(theme, text, value): + case let .allAccounts(_, text, value): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, sectionId: self.section, style: .blocks, updated: { updatedValue in arguments.updateNotificationsFromAllAccounts(updatedValue) }, tag: self.tag) - case let .accountsInfo(theme, text): + case let .accountsInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) - case let .permissionInfo(theme, title, text, suppressed): + case let .permissionInfo(_, title, text, suppressed): return ItemListInfoItem(presentationData: presentationData, title: title, text: .plain(text), style: .blocks, sectionId: self.section, closeAction: suppressed ? nil : { arguments.suppressWarning() }) - case let .permissionEnable(theme, text): + case let .permissionEnable(_, text): return ItemListActionItem(presentationData: presentationData, title: text, kind: .generic, alignment: .natural, sectionId: self.section, style: .blocks, action: { arguments.authorizeNotifications() }) - case let .messageHeader(theme, text): + case let .messageHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .messageAlerts(theme, text, value): + case let .messageAlerts(_, text, value): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, sectionId: self.section, style: .blocks, updated: { updatedValue in arguments.updateMessageAlerts(updatedValue) }, tag: self.tag) - case let .messagePreviews(theme, text, value): + case let .messagePreviews(_, text, value): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, sectionId: self.section, style: .blocks, updated: { updatedValue in arguments.updateMessagePreviews(updatedValue) }, tag: self.tag) - case let .messageSound(theme, text, value, sound): + case let .messageSound(_, text, value, sound): return ItemListDisclosureItem(presentationData: presentationData, title: text, label: value, sectionId: self.section, style: .blocks, action: { let controller = notificationSoundSelectionController(context: arguments.context, isModal: true, currentSound: sound, defaultSound: nil, completion: { [weak arguments] value in arguments?.updateMessageSound(value) }) arguments.presentController(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet)) }) - case let .userExceptions(theme, strings, text, value): + case let .userExceptions(_, strings, text, value): let label = value.settings.count > 0 ? strings.Notifications_Exceptions(Int32(value.settings.count)) : strings.Notification_Exceptions_Add return ItemListDisclosureItem(presentationData: presentationData, title: text, label: label, sectionId: self.section, style: .blocks, action: { let controller = NotificationExceptionsController(context: arguments.context, mode: value, updatedMode: arguments.updatedExceptionMode) arguments.pushController(controller) }) - case let .messageNotice(theme, text): + case let .messageNotice(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) - case let .groupHeader(theme, text): + case let .groupHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .groupAlerts(theme, text, value): + case let .groupAlerts(_, text, value): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, sectionId: self.section, style: .blocks, updated: { updatedValue in arguments.updateGroupAlerts(updatedValue) }, tag: self.tag) - case let .groupPreviews(theme, text, value): + case let .groupPreviews(_, text, value): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, sectionId: self.section, style: .blocks, updated: { updatedValue in arguments.updateGroupPreviews(updatedValue) }, tag: self.tag) - case let .groupSound(theme, text, value, sound): + case let .groupSound(_, text, value, sound): return ItemListDisclosureItem(presentationData: presentationData, title: text, label: value, sectionId: self.section, style: .blocks, action: { let controller = notificationSoundSelectionController(context: arguments.context, isModal: true, currentSound: sound, defaultSound: nil, completion: { [weak arguments] value in arguments?.updateGroupSound(value) }) arguments.presentController(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet)) }) - case let .groupExceptions(theme, strings, text, value): + case let .groupExceptions(_, strings, text, value): let label = value.settings.count > 0 ? strings.Notifications_Exceptions(Int32(value.settings.count)) : strings.Notification_Exceptions_Add return ItemListDisclosureItem(presentationData: presentationData, title: text, label: label, sectionId: self.section, style: .blocks, action: { let controller = NotificationExceptionsController(context: arguments.context, mode: value, updatedMode: arguments.updatedExceptionMode) arguments.pushController(controller) }) - case let .groupNotice(theme, text): + case let .groupNotice(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) - case let .channelHeader(theme, text): + case let .channelHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .channelAlerts(theme, text, value): + case let .channelAlerts(_, text, value): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, sectionId: self.section, style: .blocks, updated: { updatedValue in arguments.updateChannelAlerts(updatedValue) }, tag: self.tag) - case let .channelPreviews(theme, text, value): + case let .channelPreviews(_, text, value): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, sectionId: self.section, style: .blocks, updated: { updatedValue in arguments.updateChannelPreviews(updatedValue) }, tag: self.tag) - case let .channelSound(theme, text, value, sound): + case let .channelSound(_, text, value, sound): return ItemListDisclosureItem(presentationData: presentationData, title: text, label: value, sectionId: self.section, style: .blocks, action: { let controller = notificationSoundSelectionController(context: arguments.context, isModal: true, currentSound: sound, defaultSound: nil, completion: { [weak arguments] value in arguments?.updateChannelSound(value) }) arguments.presentController(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet)) }) - case let .channelExceptions(theme, strings, text, value): + case let .channelExceptions(_, strings, text, value): let label = value.settings.count > 0 ? strings.Notifications_Exceptions(Int32(value.settings.count)) : strings.Notification_Exceptions_Add return ItemListDisclosureItem(presentationData: presentationData, title: text, label: label, sectionId: self.section, style: .blocks, action: { let controller = NotificationExceptionsController(context: arguments.context, mode: value, updatedMode: arguments.updatedExceptionMode) arguments.pushController(controller) }) - case let .channelNotice(theme, text): + case let .channelNotice(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) - case let .inAppHeader(theme, text): + case let .inAppHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .inAppSounds(theme, text, value): + case let .inAppSounds(_, text, value): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, sectionId: self.section, style: .blocks, updated: { updatedValue in arguments.updateInAppSounds(updatedValue) }, tag: self.tag) - case let .inAppVibrate(theme, text, value): + case let .inAppVibrate(_, text, value): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, sectionId: self.section, style: .blocks, updated: { updatedValue in arguments.updateInAppVibration(updatedValue) }, tag: self.tag) - case let .inAppPreviews(theme, text, value): + case let .inAppPreviews(_, text, value): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, sectionId: self.section, style: .blocks, updated: { updatedValue in arguments.updateInAppPreviews(updatedValue) }, tag: self.tag) - case let .displayNamesOnLockscreen(theme, text, value): + case let .displayNamesOnLockscreen(_, text, value): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, sectionId: self.section, style: .blocks, updated: { updatedValue in arguments.updateDisplayNameOnLockscreen(updatedValue) }, tag: self.tag) - case let .displayNamesOnLockscreenInfo(theme, text): + case let .displayNamesOnLockscreenInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .markdown(text.replacingOccurrences(of: "]", with: "]()")), sectionId: self.section, linkAction: { _ in arguments.openAppSettings() }) - case let .badgeHeader(theme, text): + case let .badgeHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .includeChannels(theme, text, value): + case let .includeChannels(_, text, value): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, sectionId: self.section, style: .blocks, updated: { updatedValue in arguments.updateIncludeTag(.channels, updatedValue) }, tag: self.tag) - case let .unreadCountCategory(theme, text, value): + case let .unreadCountCategory(_, text, value): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, sectionId: self.section, style: .blocks, updated: { updatedValue in arguments.updateTotalUnreadCountCategory(updatedValue) }, tag: self.tag) - case let .unreadCountCategoryInfo(theme, text): + case let .unreadCountCategoryInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) - case let .joinedNotifications(theme, text, value): + case let .joinedNotifications(_, text, value): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, sectionId: self.section, style: .blocks, updated: { updatedValue in arguments.updateJoinedNotifications(updatedValue) }, tag: self.tag) - case let .joinedNotificationsInfo(theme, text): + case let .joinedNotificationsInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) - case let .reset(theme, text): + case let .reset(_, text): return ItemListActionItem(presentationData: presentationData, title: text, kind: .destructive, alignment: .natural, sectionId: self.section, style: .blocks, action: { arguments.resetNotifications() }, tag: self.tag) - case let .resetNotice(theme, text): + case let .resetNotice(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) } } diff --git a/submodules/SettingsUI/Sources/Privacy and Security/BlockedPeersController.swift b/submodules/SettingsUI/Sources/Privacy and Security/BlockedPeersController.swift index dec04096e9..5f9322d222 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/BlockedPeersController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/BlockedPeersController.swift @@ -211,7 +211,6 @@ public func blockedPeersController(context: AccountContext, blockedPeersContext: } var pushControllerImpl: ((ViewController) -> Void)? - var presentControllerImpl: ((ViewController, Any?) -> Void)? let actionsDisposable = DisposableSet() @@ -312,11 +311,6 @@ public func blockedPeersController(context: AccountContext, blockedPeersContext: (controller.navigationController as? NavigationController)?.pushViewController(c) } } - presentControllerImpl = { [weak controller] c, a in - if let controller = controller { - controller.present(c, in: .window(.root), with: a) - } - } controller.visibleBottomContentOffsetChanged = { offset in if case let .known(value) = offset, value < 40.0 { blockedPeersContext.loadMore() diff --git a/submodules/SettingsUI/Sources/Privacy and Security/ConfirmPhoneNumberController.swift b/submodules/SettingsUI/Sources/Privacy and Security/ConfirmPhoneNumberController.swift index 9de89ca41a..1cc0b8723b 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/ConfirmPhoneNumberController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/ConfirmPhoneNumberController.swift @@ -87,13 +87,13 @@ private enum ConfirmPhoneNumberCodeEntry: ItemListNodeEntry { func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem { let arguments = arguments as! ConfirmPhoneNumberCodeControllerArguments switch self { - case let .codeEntry(theme, strings, title, text): + case let .codeEntry(_, _, title, text): return ItemListSingleLineInputItem(presentationData: presentationData, title: NSAttributedString(string: title, textColor: .black), text: text, placeholder: "", type: .number, spacing: 10.0, tag: ConfirmPhoneNumberCodeTag.input, sectionId: self.section, textUpdated: { updatedText in arguments.updateEntryText(updatedText) }, action: { arguments.next() }) - case let .codeInfo(theme, strings, phoneNumber, nextOptionText): + case let .codeInfo(_, strings, phoneNumber, nextOptionText): let formattedNumber = formatPhoneNumber(phoneNumber) let stringAndRanges = strings.CancelResetAccount_TextSMS(formattedNumber) var result = "" @@ -157,7 +157,7 @@ private func timeoutSignal(codeData: CancelAccountResetData) -> Signal ListViewItem { let arguments = arguments as! CreatePasswordControllerArguments switch self { - case let .passwordHeader(theme, text): + case let .passwordHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .password(theme, strings, text, value): + case let .password(_, _, text, value): return ItemListSingleLineInputItem(presentationData: presentationData, title: NSAttributedString(), text: value, placeholder: text, type: .password, returnKeyType: .next, spacing: 0.0, tag: CreatePasswordEntryTag.password, sectionId: self.section, textUpdated: { updatedText in arguments.updateFieldText(.password, updatedText) }, action: { arguments.selectNextInputItem(CreatePasswordEntryTag.password) }) - case let .passwordConfirmation(theme, strings, text, value): + case let .passwordConfirmation(_, _, text, value): return ItemListSingleLineInputItem(presentationData: presentationData, title: NSAttributedString(), text: value, placeholder: text, type: .password, returnKeyType: .next, spacing: 0.0, tag: CreatePasswordEntryTag.passwordConfirmation, sectionId: self.section, textUpdated: { updatedText in arguments.updateFieldText(.passwordConfirmation, updatedText) }, action: { arguments.selectNextInputItem(CreatePasswordEntryTag.passwordConfirmation) }) - case let .passwordInfo(theme, text): + case let .passwordInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) - case let .hintHeader(theme, text): + case let .hintHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .hint(theme, strings, text, value, last): + case let .hint(_, _, text, value, last): return ItemListSingleLineInputItem(presentationData: presentationData, title: NSAttributedString(), text: value, placeholder: text, type: .regular(capitalization: true, autocorrection: false), returnKeyType: last ? .done : .next, spacing: 0.0, tag: CreatePasswordEntryTag.hint, sectionId: self.section, textUpdated: { updatedText in arguments.updateFieldText(.hint, updatedText) }, action: { @@ -148,21 +148,21 @@ private enum CreatePasswordEntry: ItemListNodeEntry, Equatable { arguments.selectNextInputItem(CreatePasswordEntryTag.hint) } }) - case let .hintInfo(theme, text): + case let .hintInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) - case let .emailHeader(theme, text): + case let .emailHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .email(theme, strings, text, value): + case let .email(_, _, text, value): return ItemListSingleLineInputItem(presentationData: presentationData, title: NSAttributedString(), text: value, placeholder: text, type: .email, returnKeyType: .done, spacing: 0.0, tag: CreatePasswordEntryTag.email, sectionId: self.section, textUpdated: { updatedText in arguments.updateFieldText(.email, updatedText) }, action: { arguments.save() }) - case let .emailInfo(theme, text): + case let .emailInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) - case let .emailConfirmation(theme, text): + case let .emailConfirmation(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) - case let .emailCancel(theme, text, enabled): + case let .emailCancel(_, text, enabled): return ItemListActionItem(presentationData: presentationData, title: text, kind: enabled ? .generic : .disabled, alignment: .natural, sectionId: self.section, style: .blocks, action: { arguments.cancelEmailConfirmation() }) diff --git a/submodules/SettingsUI/Sources/Privacy and Security/DataPrivacySettingsController.swift b/submodules/SettingsUI/Sources/Privacy and Security/DataPrivacySettingsController.swift index 2c19e29e1e..755ce09724 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/DataPrivacySettingsController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/DataPrivacySettingsController.swift @@ -211,45 +211,45 @@ private enum PrivacyAndSecurityEntry: ItemListNodeEntry { func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem { let arguments = arguments as! DataPrivacyControllerArguments switch self { - case let .contactsHeader(theme, text): + case let .contactsHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .deleteContacts(theme, text, value): + case let .deleteContacts(_, text, value): return ItemListActionItem(presentationData: presentationData, title: text, kind: value ? .generic : .disabled, alignment: .natural, sectionId: self.section, style: .blocks, action: { arguments.deleteContacts() }) - case let .syncContacts(theme, text, value): + case let .syncContacts(_, text, value): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, sectionId: self.section, style: .blocks, updated: { updatedValue in arguments.updateSyncContacts(updatedValue) }) - case let .syncContactsInfo(theme, text): + case let .syncContactsInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) - case let .frequentContacts(theme, text, value): + case let .frequentContacts(_, text, value): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, enableInteractiveChanges: !value, sectionId: self.section, style: .blocks, updated: { updatedValue in arguments.updateSuggestFrequentContacts(updatedValue) }) - case let .frequentContactsInfo(theme, text): + case let .frequentContactsInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) - case let .chatsHeader(theme, text): + case let .chatsHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .deleteCloudDrafts(theme, text, value): + case let .deleteCloudDrafts(_, text, value): return ItemListActionItem(presentationData: presentationData, title: text, kind: value ? .generic : .disabled, alignment: .natural, sectionId: self.section, style: .blocks, action: { arguments.deleteCloudDrafts() }) - case let .paymentHeader(theme, text): + case let .paymentHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .clearPaymentInfo(theme, text, enabled): + case let .clearPaymentInfo(_, text, enabled): return ItemListActionItem(presentationData: presentationData, title: text, kind: enabled ? .generic : .disabled, alignment: .natural, sectionId: self.section, style: .blocks, action: { arguments.clearPaymentInfo() }) - case let .paymentInfo(theme, text): + case let .paymentInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) - case let .secretChatLinkPreviewsHeader(theme, text): + case let .secretChatLinkPreviewsHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .secretChatLinkPreviews(theme, text, value): + case let .secretChatLinkPreviews(_, text, value): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, sectionId: self.section, style: .blocks, updated: { updatedValue in arguments.updateSecretChatLinkPreviews(updatedValue) }) - case let .secretChatLinkPreviewsInfo(theme, text): + case let .secretChatLinkPreviewsInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) } } @@ -500,8 +500,6 @@ public func dataPrivacyController(context: AccountContext) -> ViewController { presentControllerImpl?(controller) }) - let previousState = Atomic(value: nil) - actionsDisposable.add(context.engine.peers.managedUpdatedRecentPeers().start()) let signal = combineLatest(queue: .mainQueue(), context.sharedContext.presentationData, statePromise.get(), context.sharedContext.accountManager.noticeEntry(key: ApplicationSpecificNotice.secretChatLinkPreviewsKey()), context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.contactSynchronizationSettings]), context.account.postbox.preferencesView(keys: [PreferencesKeys.contactsSettings]), context.engine.peers.recentPeers()) @@ -528,7 +526,6 @@ public func dataPrivacyController(context: AccountContext) -> ViewController { let controllerState = ItemListControllerState(presentationData: ItemListPresentationData(presentationData), title: .text(presentationData.strings.PrivateDataSettings_Title), leftNavigationButton: nil, rightNavigationButton: rightNavigationButton, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back), animateChanges: false) - let previousStateValue = previousState.swap(state) let animateChanges = false let listState = ItemListNodeState(presentationData: ItemListPresentationData(presentationData), entries: dataPrivacyControllerEntries(presentationData: presentationData, state: state, secretChatLinkPreviews: secretChatLinkPreviews, synchronizeDeviceContacts: synchronizeDeviceContacts, frequentContacts: suggestRecentPeers), style: .blocks, animateChanges: animateChanges) diff --git a/submodules/SettingsUI/Sources/Privacy and Security/PasscodeOptionsController.swift b/submodules/SettingsUI/Sources/Privacy and Security/PasscodeOptionsController.swift index 672935076e..0d0814e639 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/PasscodeOptionsController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/PasscodeOptionsController.swift @@ -109,23 +109,23 @@ private enum PasscodeOptionsEntry: ItemListNodeEntry { func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem { let arguments = arguments as! PasscodeOptionsControllerArguments switch self { - case let .togglePasscode(theme, title, value): + case let .togglePasscode(_, title, value): return ItemListActionItem(presentationData: presentationData, title: title, kind: .generic, alignment: .natural, sectionId: self.section, style: .blocks, action: { if value { arguments.turnPasscodeOff() } }) - case let .changePasscode(theme, title): + case let .changePasscode(_, title): return ItemListActionItem(presentationData: presentationData, title: title, kind: .generic, alignment: .natural, sectionId: self.section, style: .blocks, action: { arguments.changePasscode() }) - case let .settingInfo(theme, text): + case let .settingInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) - case let .autoLock(theme, title, value): + case let .autoLock(_, title, value): return ItemListDisclosureItem(presentationData: presentationData, title: title, label: value, sectionId: self.section, style: .blocks, action: { arguments.changePasscodeTimeout() }) - case let .touchId(theme, title, value): + case let .touchId(_, title, value): return ItemListSwitchItem(presentationData: presentationData, title: title, value: value, sectionId: self.section, style: .blocks, updated: { value in arguments.changeTouchId(value) }) @@ -210,10 +210,6 @@ func passcodeOptionsController(context: AccountContext) -> ViewController { let initialState = PasscodeOptionsControllerState() let statePromise = ValuePromise(initialState, ignoreRepeated: true) - let stateValue = Atomic(value: initialState) - let updateState: ((PasscodeOptionsControllerState) -> PasscodeOptionsControllerState) -> Void = { f in - statePromise.set(stateValue.modify { f($0) }) - } var presentControllerImpl: ((ViewController, ViewControllerPresentationArguments) -> Void)? var pushControllerImpl: ((ViewController) -> Void)? diff --git a/submodules/SettingsUI/Sources/Privacy and Security/PrivacyAndSecurityController.swift b/submodules/SettingsUI/Sources/Privacy and Security/PrivacyAndSecurityController.swift index 28207189e0..7be99cbb75 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/PrivacyAndSecurityController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/PrivacyAndSecurityController.swift @@ -284,47 +284,47 @@ private enum PrivacyAndSecurityEntry: ItemListNodeEntry { func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem { let arguments = arguments as! PrivacyAndSecurityControllerArguments switch self { - case let .privacyHeader(theme, text): + case let .privacyHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .blockedPeers(theme, text, value): + case let .blockedPeers(_, text, value): return ItemListDisclosureItem(presentationData: presentationData, icon: UIImage(bundleImageName: "Settings/MenuIcons/Blocked")?.precomposed(), title: text, label: value, sectionId: self.section, style: .blocks, action: { arguments.openBlockedUsers() }) - case let .phoneNumberPrivacy(theme, text, value): + case let .phoneNumberPrivacy(_, text, value): return ItemListDisclosureItem(presentationData: presentationData, title: text, label: value, sectionId: self.section, style: .blocks, action: { arguments.openPhoneNumberPrivacy() }) - case let .lastSeenPrivacy(theme, text, value): + case let .lastSeenPrivacy(_, text, value): return ItemListDisclosureItem(presentationData: presentationData, title: text, label: value, sectionId: self.section, style: .blocks, action: { arguments.openLastSeenPrivacy() }) - case let .profilePhotoPrivacy(theme, text, value): + case let .profilePhotoPrivacy(_, text, value): return ItemListDisclosureItem(presentationData: presentationData, title: text, label: value, sectionId: self.section, style: .blocks, action: { arguments.openProfilePhotoPrivacy() }) - case let .forwardPrivacy(theme, text, value): + case let .forwardPrivacy(_, text, value): return ItemListDisclosureItem(presentationData: presentationData, title: text, label: value, sectionId: self.section, style: .blocks, action: { arguments.openForwardPrivacy() }) - case let .groupPrivacy(theme, text, value): + case let .groupPrivacy(_, text, value): return ItemListDisclosureItem(presentationData: presentationData, title: text, label: value, sectionId: self.section, style: .blocks, action: { arguments.openGroupsPrivacy() }) - case let .selectivePrivacyInfo(theme, text): + case let .selectivePrivacyInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) - case let .voiceCallPrivacy(theme, text, value): + case let .voiceCallPrivacy(_, text, value): return ItemListDisclosureItem(presentationData: presentationData, title: text, label: value, sectionId: self.section, style: .blocks, action: { arguments.openVoiceCallPrivacy() }) - case let .passcode(theme, text, hasFaceId, value): + case let .passcode(_, text, hasFaceId, value): return ItemListDisclosureItem(presentationData: presentationData, icon: UIImage(bundleImageName: hasFaceId ? "Settings/MenuIcons/FaceId" : "Settings/MenuIcons/TouchId")?.precomposed(), title: text, label: value, sectionId: self.section, style: .blocks, action: { arguments.openPasscode() }) - case let .twoStepVerification(theme, text, value, data): + case let .twoStepVerification(_, text, value, data): return ItemListDisclosureItem(presentationData: presentationData, icon: UIImage(bundleImageName: "Settings/MenuIcons/TwoStepAuth")?.precomposed(), title: text, label: value, sectionId: self.section, style: .blocks, action: { arguments.openTwoStepVerification(data) }) - case let .activeSessions(theme, text, value): + case let .activeSessions(_, text, value): return ItemListDisclosureItem(presentationData: presentationData, icon: UIImage(bundleImageName: "Settings/MenuIcons/Websites")?.precomposed(), title: text, label: value, sectionId: self.section, style: .blocks, action: { arguments.openActiveSessions() }) @@ -336,19 +336,19 @@ private enum PrivacyAndSecurityEntry: ItemListNodeEntry { }, tag: PrivacyAndSecurityEntryTag.autoArchive) case let .autoArchiveInfo(text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) - case let .accountHeader(theme, text): + case let .accountHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .accountTimeout(theme, text, value): + case let .accountTimeout(_, text, value): return ItemListDisclosureItem(presentationData: presentationData, title: text, label: value, sectionId: self.section, style: .blocks, action: { arguments.setupAccountAutoremove() }, tag: PrivacyAndSecurityEntryTag.accountTimeout) - case let .accountInfo(theme, text): + case let .accountInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) - case let .dataSettings(theme, text): + case let .dataSettings(_, text): return ItemListDisclosureItem(presentationData: presentationData, title: text, label: "", sectionId: self.section, style: .blocks, action: { arguments.openDataSettings() }) - case let .dataSettingsInfo(theme, text): + case let .dataSettingsInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) } } @@ -726,7 +726,6 @@ public func privacyAndSecurityController(context: AccountContext, initialSetting } }) }, openTwoStepVerification: { data in - let intro = false if let data = data { switch data { case .set: @@ -737,28 +736,12 @@ public func privacyAndSecurityController(context: AccountContext, initialSetting pushControllerImpl?(controller, true) return - } else { - } } } - if intro { - var nextImpl: (() -> Void)? - let introController = PrivacyIntroController(context: context, mode: .twoStepVerification, proceedAction: { - nextImpl?() - }) - nextImpl = { [weak introController] in - guard let introController = introController, let navigationController = introController.navigationController as? NavigationController else { - return - } - let controller = twoStepVerificationUnlockSettingsController(context: context, mode: .access(intro: intro, data: data.flatMap({ Signal.single(.access(configuration: $0)) }))) - navigationController.replaceController(introController, with: controller, animated: true) - } - pushControllerImpl?(introController, true) - } else { - let controller = twoStepVerificationUnlockSettingsController(context: context, mode: .access(intro: intro, data: data.flatMap({ Signal.single(.access(configuration: $0)) }))) - pushControllerImpl?(controller, true) - } + + let controller = twoStepVerificationUnlockSettingsController(context: context, mode: .access(intro: false, data: data.flatMap({ Signal.single(.access(configuration: $0)) }))) + pushControllerImpl?(controller, true) }, openActiveSessions: { pushControllerImpl?(recentSessionsController(context: context, activeSessionsContext: activeSessionsContext, webSessionsContext: webSessionsContext, websitesOnly: true), true) }, toggleArchiveAndMuteNonContacts: { archiveValue in diff --git a/submodules/SettingsUI/Sources/Privacy and Security/Recent Sessions/RecentSessionsController.swift b/submodules/SettingsUI/Sources/Privacy and Security/Recent Sessions/RecentSessionsController.swift index b739dc8d07..b7671b73fe 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/Recent Sessions/RecentSessionsController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/Recent Sessions/RecentSessionsController.swift @@ -267,7 +267,7 @@ private enum RecentSessionsEntry: ItemListNodeEntry { switch self { case let .currentSessionHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .currentSession(_, strings, dateTimeFormat, session): + case let .currentSession(_, _, dateTimeFormat, session): return ItemListRecentSessionItem(presentationData: presentationData, dateTimeFormat: dateTimeFormat, session: session, enabled: true, editable: false, editing: false, revealed: false, sectionId: self.section, setSessionIdWithRevealedOptions: { _, _ in }, removeSession: { _ in }) @@ -512,6 +512,7 @@ public func recentSessionsController(context: AccountContext, activeSessionsCont |> deliverOnMainQueue).start(next: { _ in dismissImpl?() }) + actionsDisposable.add(autoDismissDisposable) } let mode = ValuePromise(websitesOnly ? .websites : .sessions) @@ -593,12 +594,8 @@ public func recentSessionsController(context: AccountContext, activeSessionsCont removeSessionDisposable.set(((webSessionsContext.remove(hash: sessionId) |> mapToSignal { _ -> Signal in - return .complete() }) |> deliverOnMainQueue).start(error: { _ in - updateState { - return $0.withUpdatedRemovingSessionId(nil) - } }, completed: { updateState { return $0.withUpdatedRemovingSessionId(nil) @@ -621,9 +618,6 @@ public func recentSessionsController(context: AccountContext, activeSessionsCont terminateOtherSessionsDisposable.set((webSessionsContext.removeAll() |> deliverOnMainQueue).start(error: { _ in - updateState { - return $0.withUpdatedTerminatingOtherSessions(false) - } }, completed: { updateState { return $0.withUpdatedTerminatingOtherSessions(false) diff --git a/submodules/SettingsUI/Sources/Privacy and Security/SelectivePrivacySettingsController.swift b/submodules/SettingsUI/Sources/Privacy and Security/SelectivePrivacySettingsController.swift index 76a093fb66..d878a8953c 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/SelectivePrivacySettingsController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/SelectivePrivacySettingsController.swift @@ -347,81 +347,81 @@ private enum SelectivePrivacySettingsEntry: ItemListNodeEntry { func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem { let arguments = arguments as! SelectivePrivacySettingsControllerArguments switch self { - case let .forwardsPreviewHeader(theme, text): + case let .forwardsPreviewHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, multiline: true, sectionId: self.section) case let .forwardsPreview(theme, wallpaper, fontSize, chatBubbleCorners, strings, dateTimeFormat, nameDisplayOrder, peerName, linkEnabled, tooltipText): return ForwardPrivacyChatPreviewItem(context: arguments.context, theme: theme, strings: strings, sectionId: self.section, fontSize: fontSize, chatBubbleCorners: chatBubbleCorners, wallpaper: wallpaper, dateTimeFormat: dateTimeFormat, nameDisplayOrder: nameDisplayOrder, peerName: peerName, linkEnabled: linkEnabled, tooltipText: tooltipText) - case let .settingHeader(theme, text): + case let .settingHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, multiline: true, sectionId: self.section) - case let .everybody(theme, text, value): + case let .everybody(_, text, value): return ItemListCheckboxItem(presentationData: presentationData, title: text, style: .left, checked: value, zeroSeparatorInsets: false, sectionId: self.section, action: { arguments.updateType(.everybody) }) - case let .contacts(theme, text, value): + case let .contacts(_, text, value): return ItemListCheckboxItem(presentationData: presentationData, title: text, style: .left, checked: value, zeroSeparatorInsets: false, sectionId: self.section, action: { arguments.updateType(.contacts) }) - case let .nobody(theme, text, value): + case let .nobody(_, text, value): return ItemListCheckboxItem(presentationData: presentationData, title: text, style: .left, checked: value, zeroSeparatorInsets: false, sectionId: self.section, action: { arguments.updateType(.nobody) }) - case let .settingInfo(theme, text): + case let .settingInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) - case let .exceptionsHeader(theme, text): + case let .exceptionsHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .disableFor(theme, title, value): + case let .disableFor(_, title, value): return ItemListDisclosureItem(presentationData: presentationData, title: title, label: value, sectionId: self.section, style: .blocks, action: { arguments.openSelective(.main, false) }) - case let .enableFor(theme, title, value): + case let .enableFor(_, title, value): return ItemListDisclosureItem(presentationData: presentationData, title: title, label: value, sectionId: self.section, style: .blocks, action: { arguments.openSelective(.main, true) }) - case let .peersInfo(theme, text): + case let .peersInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) - case let .callsP2PHeader(theme, text): + case let .callsP2PHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .callsP2PAlways(theme, text, value): + case let .callsP2PAlways(_, text, value): return ItemListCheckboxItem(presentationData: presentationData, title: text, style: .left, checked: value, zeroSeparatorInsets: false, sectionId: self.section, action: { arguments.updateCallP2PMode?(.everybody) }) - case let .callsP2PContacts(theme, text, value): + case let .callsP2PContacts(_, text, value): return ItemListCheckboxItem(presentationData: presentationData, title: text, style: .left, checked: value, zeroSeparatorInsets: false, sectionId: self.section, action: { arguments.updateCallP2PMode?(.contacts) }) - case let .callsP2PNever(theme, text, value): + case let .callsP2PNever(_, text, value): return ItemListCheckboxItem(presentationData: presentationData, title: text, style: .left, checked: value, zeroSeparatorInsets: false, sectionId: self.section, action: { arguments.updateCallP2PMode?(.nobody) }) - case let .callsP2PInfo(theme, text): + case let .callsP2PInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) - case let .callsP2PDisableFor(theme, title, value): + case let .callsP2PDisableFor(_, title, value): return ItemListDisclosureItem(presentationData: presentationData, title: title, label: value, sectionId: self.section, style: .blocks, action: { arguments.openSelective(.callP2P, false) }) - case let .callsP2PEnableFor(theme, title, value): + case let .callsP2PEnableFor(_, title, value): return ItemListDisclosureItem(presentationData: presentationData, title: title, label: value, sectionId: self.section, style: .blocks, action: { arguments.openSelective(.callP2P, true) }) - case let .callsP2PPeersInfo(theme, text): + case let .callsP2PPeersInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) - case let .callsIntegrationEnabled(theme, text, value): + case let .callsIntegrationEnabled(_, text, value): return ItemListSwitchItem(presentationData: presentationData, title: text, value: value, sectionId: self.section, style: .blocks, updated: { value in arguments.updateCallIntegrationEnabled?(value) }) - case let .callsIntegrationInfo(theme, text): + case let .callsIntegrationInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) - case let .phoneDiscoveryHeader(theme, text): + case let .phoneDiscoveryHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .phoneDiscoveryEverybody(theme, text, value): + case let .phoneDiscoveryEverybody(_, text, value): return ItemListCheckboxItem(presentationData: presentationData, title: text, style: .left, checked: value, zeroSeparatorInsets: false, sectionId: self.section, action: { arguments.updatePhoneDiscovery?(true) }) - case let .phoneDiscoveryMyContacts(theme, text, value): + case let .phoneDiscoveryMyContacts(_, text, value): return ItemListCheckboxItem(presentationData: presentationData, title: text, style: .left, checked: value, zeroSeparatorInsets: false, sectionId: self.section, action: { arguments.updatePhoneDiscovery?(false) }) - case let .phoneDiscoveryInfo(theme, text): + case let .phoneDiscoveryInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) } } @@ -694,13 +694,11 @@ func selectivePrivacySettingsController(context: AccountContext, kind: Selective let updateState: ((SelectivePrivacySettingsControllerState) -> SelectivePrivacySettingsControllerState) -> Void = { f in statePromise.set(stateValue.modify { f($0) }) } - - var dismissImpl: (() -> Void)? + var pushControllerImpl: ((ViewController, Bool) -> Void)? var presentControllerImpl: ((ViewController, Any?) -> Void)? let actionsDisposable = DisposableSet() - let updateSettingsDisposable = MetaDisposable() let addPeerDisposable = MetaDisposable() actionsDisposable.add(addPeerDisposable) @@ -804,7 +802,7 @@ func selectivePrivacySettingsController(context: AccountContext, kind: Selective controller?.dismiss() updateState { state in - var state = state + let state = state if enable { switch target { case .main: @@ -1080,9 +1078,6 @@ func selectivePrivacySettingsController(context: AccountContext, kind: Selective presentControllerImpl = { [weak controller] c, a in controller?.present(c, in: .window(.root), with: a) } - dismissImpl = { [weak controller] in - let _ = (controller?.navigationController as? NavigationController)?.popViewController(animated: true) - } return controller } diff --git a/submodules/SettingsUI/Sources/Privacy and Security/SelectivePrivacySettingsPeersController.swift b/submodules/SettingsUI/Sources/Privacy and Security/SelectivePrivacySettingsPeersController.swift index 7fb0f87d32..a3a4c368d7 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/SelectivePrivacySettingsPeersController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/SelectivePrivacySettingsPeersController.swift @@ -37,32 +37,6 @@ private enum SelectivePrivacyPeersSection: Int32 { private enum SelectivePrivacyPeersEntryStableId: Hashable { case add case peer(PeerId) - - var hashValue: Int { - switch self { - case let .peer(peerId): - return peerId.hashValue - case .add: - return 1 - } - } - - static func ==(lhs: SelectivePrivacyPeersEntryStableId, rhs: SelectivePrivacyPeersEntryStableId) -> Bool { - switch lhs { - case let .peer(peerId): - if case .peer(peerId) = rhs { - return true - } else { - return false - } - case .add: - if case .add = rhs { - return true - } else { - return false - } - } - } } private enum SelectivePrivacyPeersEntry: ItemListNodeEntry { @@ -150,7 +124,7 @@ private enum SelectivePrivacyPeersEntry: ItemListNodeEntry { func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem { let arguments = arguments as! SelectivePrivacyPeersControllerArguments switch self { - case let .peerItem(_, theme, strings, dateTimeFormat, nameDisplayOrder, peer, editing, enabled): + case let .peerItem(_, _, strings, dateTimeFormat, nameDisplayOrder, peer, editing, enabled): var text: ItemListPeerItemText = .none if let group = peer.peer as? TelegramGroup { text = .text(strings.Conversation_StatusMembers(Int32(group.participantCount)), .secondary) diff --git a/submodules/SettingsUI/Sources/Privacy and Security/TwoStepVerificationUnlockController.swift b/submodules/SettingsUI/Sources/Privacy and Security/TwoStepVerificationUnlockController.swift index 117c00bcb9..aad0182437 100644 --- a/submodules/SettingsUI/Sources/Privacy and Security/TwoStepVerificationUnlockController.swift +++ b/submodules/SettingsUI/Sources/Privacy and Security/TwoStepVerificationUnlockController.swift @@ -129,7 +129,7 @@ private enum TwoStepVerificationUnlockSettingsEntry: ItemListNodeEntry { func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem { let arguments = arguments as! TwoStepVerificationUnlockSettingsControllerArguments switch self { - case let .passwordEntry(theme, strings, text, value): + case let .passwordEntry(theme, _, text, value): return ItemListSingleLineInputItem(presentationData: presentationData, title: NSAttributedString(string: text, textColor: theme.list.itemPrimaryTextColor), text: value, placeholder: "", type: .password, spacing: 10.0, tag: TwoStepVerificationUnlockSettingsEntryTag.password, sectionId: self.section, textUpdated: { updatedText in arguments.updatePasswordText(updatedText) }, action: { @@ -377,8 +377,8 @@ public func twoStepVerificationUnlockSettingsController(context: AccountContext, switch data { case .access: dataPromise.set(.single(TwoStepVerificationUnlockSettingsControllerData.access(configuration: .notSet(pendingEmail: nil)))) - case let .manage(manage): - dataPromise.set(.single(TwoStepVerificationUnlockSettingsControllerData.manage(password: manage.password, emailSet: false, pendingEmail: nil, hasSecureValues: manage.hasSecureValues))) + case let .manage(password, _, _, hasSecureValues): + dataPromise.set(.single(TwoStepVerificationUnlockSettingsControllerData.manage(password: password, emailSet: false, pendingEmail: nil, hasSecureValues: hasSecureValues))) } updateState { state in @@ -406,8 +406,8 @@ public func twoStepVerificationUnlockSettingsController(context: AccountContext, dataPromise.set(.single(.access(configuration: nil)) |> then(context.engine.auth.twoStepVerificationConfiguration() |> map { TwoStepVerificationUnlockSettingsControllerData.access(configuration: TwoStepVerificationAccessConfiguration(configuration: $0, password: pendingEmail.password)) })) } - case let .manage(manage): - dataPromise.set(.single(TwoStepVerificationUnlockSettingsControllerData.manage(password: manage.password, emailSet: true, pendingEmail: nil, hasSecureValues: manage.hasSecureValues))) + case let .manage(password, _, _, hasSecureValues): + dataPromise.set(.single(TwoStepVerificationUnlockSettingsControllerData.manage(password: password, emailSet: true, pendingEmail: nil, hasSecureValues: hasSecureValues))) } updateState { state in @@ -448,8 +448,8 @@ public func twoStepVerificationUnlockSettingsController(context: AccountContext, } |> map { configuration in var pendingEmail: TwoStepVerificationPendingEmail? - if case let .set(configuration) = configuration { - pendingEmail = configuration.pendingEmail + if case let .set(_, _, pendingEmailValue, _, _) = configuration { + pendingEmail = pendingEmailValue } return (settings, pendingEmail) } @@ -646,7 +646,7 @@ public func twoStepVerificationUnlockSettingsController(context: AccountContext, break } } - case let .manage(password, hasRecovery, pendingEmail, hasSecureValues): + case let .manage(password, hasRecovery, _, hasSecureValues): let controller = SetupTwoStepVerificationController(context: context, initialState: .updatePassword(current: password, hasRecoveryEmail: hasRecovery, hasSecureValues: hasSecureValues), stateUpdated: { update, shouldDismiss, controller in switch update { case .pendingPasswordReset: @@ -697,7 +697,7 @@ public func twoStepVerificationUnlockSettingsController(context: AccountContext, if disablePassword { setupDisposable.set((dataPromise.get() |> take(1) - |> mapError { _ -> UpdateTwoStepVerificationPasswordError in return .generic } + |> mapError { _ -> UpdateTwoStepVerificationPasswordError in } |> mapToSignal { data -> Signal in switch data { case .access: @@ -953,12 +953,12 @@ public func twoStepVerificationUnlockSettingsController(context: AccountContext, } else { emptyStateItem = ItemListLoadingIndicatorEmptyStateItem(theme: presentationData.theme) } - case let .manage(manage): + case let .manage(_, _, pendingEmail, _): title = presentationData.strings.PrivacySettings_TwoStepAuth if state.checking { rightNavigationButton = ItemListNavigationButton(content: .none, style: .activity, enabled: true, action: {}) } else { - if let _ = manage.pendingEmail { + if let _ = pendingEmail { rightNavigationButton = ItemListNavigationButton(content: .text(presentationData.strings.Common_Next), style: .bold, enabled: !state.emailCode.isEmpty, action: { checkEmailConfirmation() }) diff --git a/submodules/SettingsUI/Sources/Search/SettingsSearchItem.swift b/submodules/SettingsUI/Sources/Search/SettingsSearchItem.swift index a63dcee4ab..745c267742 100644 --- a/submodules/SettingsUI/Sources/Search/SettingsSearchItem.swift +++ b/submodules/SettingsUI/Sources/Search/SettingsSearchItem.swift @@ -240,24 +240,6 @@ private func preparedSettingsSearchContainerTransition(theme: PresentationTheme, private enum SettingsSearchRecentEntryStableId: Hashable { case recent(SettingsSearchableItemId) - - static func ==(lhs: SettingsSearchRecentEntryStableId, rhs: SettingsSearchRecentEntryStableId) -> Bool { - switch lhs { - case let .recent(id): - if case .recent(id) = rhs { - return true - } else { - return false - } - } - } - - var hashValue: Int { - switch self { - case let .recent(id): - return id.hashValue - } - } } private enum SettingsSearchRecentEntry: Comparable, Identifiable { diff --git a/submodules/SettingsUI/Sources/Search/SettingsSearchRecentQueries.swift b/submodules/SettingsUI/Sources/Search/SettingsSearchRecentQueries.swift index a13843c491..32317752fb 100644 --- a/submodules/SettingsUI/Sources/Search/SettingsSearchRecentQueries.swift +++ b/submodules/SettingsUI/Sources/Search/SettingsSearchRecentQueries.swift @@ -8,7 +8,12 @@ private struct SettingsSearchRecentQueryItemId { public let rawValue: MemoryBuffer var value: Int64 { - return self.rawValue.makeData().withUnsafeBytes { $0.pointee } as Int64 + return self.rawValue.makeData().withUnsafeBytes { buffer -> Int64 in + guard let bytes = buffer.baseAddress?.assumingMemoryBound(to: Int64.self) else { + return 0 + } + return bytes.pointee + } } init(_ rawValue: MemoryBuffer) { diff --git a/submodules/SettingsUI/Sources/SettingsController.swift b/submodules/SettingsUI/Sources/SettingsController.swift index 8338d432df..71484a7b62 100644 --- a/submodules/SettingsUI/Sources/SettingsController.swift +++ b/submodules/SettingsUI/Sources/SettingsController.swift @@ -6,7 +6,7 @@ import Postbox import TelegramCore import AccountContext -public protocol SettingsController: class { +public protocol SettingsController: AnyObject { func updateContext(context: AccountContext) } diff --git a/submodules/SettingsUI/Sources/Stickers/ArchivedStickerPacksController.swift b/submodules/SettingsUI/Sources/Stickers/ArchivedStickerPacksController.swift index 3818ec06c1..bd86306f87 100644 --- a/submodules/SettingsUI/Sources/Stickers/ArchivedStickerPacksController.swift +++ b/submodules/SettingsUI/Sources/Stickers/ArchivedStickerPacksController.swift @@ -43,32 +43,6 @@ private enum ArchivedStickerPacksSection: Int32 { private enum ArchivedStickerPacksEntryId: Hashable { case index(Int32) case pack(ItemCollectionId) - - var hashValue: Int { - switch self { - case let .index(index): - return index.hashValue - case let .pack(id): - return id.hashValue - } - } - - static func ==(lhs: ArchivedStickerPacksEntryId, rhs: ArchivedStickerPacksEntryId) -> Bool { - switch lhs { - case let .index(index): - if case .index(index) = rhs { - return true - } else { - return false - } - case let .pack(id): - if case .pack(id) = rhs { - return true - } else { - return false - } - } - } } private enum ArchivedStickerPacksEntry: ItemListNodeEntry { @@ -157,9 +131,9 @@ private enum ArchivedStickerPacksEntry: ItemListNodeEntry { func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem { let arguments = arguments as! ArchivedStickerPacksControllerArguments switch self { - case let .info(theme, text): + case let .info(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) - case let .pack(_, theme, strings, info, topItem, count, animatedStickers, enabled, editing): + case let .pack(_, _, _, info, topItem, count, animatedStickers, enabled, editing): return ItemListStickerPackItem(presentationData: presentationData, account: arguments.account, packInfo: info, itemCount: count, topItem: topItem, unread: false, control: .installation(installed: false), editing: editing, enabled: enabled, playAnimatedStickers: animatedStickers, sectionId: self.section, action: { arguments.openStickerPack(info) }, setPackIdWithRevealedOptions: { current, previous in diff --git a/submodules/SettingsUI/Sources/Stickers/FeaturedStickerPacksController.swift b/submodules/SettingsUI/Sources/Stickers/FeaturedStickerPacksController.swift index 6c57829354..3d17794f75 100644 --- a/submodules/SettingsUI/Sources/Stickers/FeaturedStickerPacksController.swift +++ b/submodules/SettingsUI/Sources/Stickers/FeaturedStickerPacksController.swift @@ -31,24 +31,6 @@ private enum FeaturedStickerPacksSection: Int32 { private enum FeaturedStickerPacksEntryId: Hashable { case pack(ItemCollectionId) - - var hashValue: Int { - switch self { - case let .pack(id): - return id.hashValue - } - } - - static func ==(lhs: FeaturedStickerPacksEntryId, rhs: FeaturedStickerPacksEntryId) -> Bool { - switch lhs { - case let .pack(id): - if case .pack(id) = rhs { - return true - } else { - return false - } - } - } } private enum FeaturedStickerPacksEntry: ItemListNodeEntry { @@ -119,7 +101,7 @@ private enum FeaturedStickerPacksEntry: ItemListNodeEntry { func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem { let arguments = arguments as! FeaturedStickerPacksControllerArguments switch self { - case let .pack(_, theme, strings, info, unread, topItem, count, playAnimatedStickers, installed): + case let .pack(_, _, _, info, unread, topItem, count, playAnimatedStickers, installed): return ItemListStickerPackItem(presentationData: presentationData, account: arguments.account, packInfo: info, itemCount: count, topItem: topItem, unread: unread, control: .installation(installed: installed), editing: ItemListStickerPackItemEditing(editable: false, editing: false, revealed: false, reorderable: false, selectable: false), enabled: true, playAnimatedStickers: playAnimatedStickers, sectionId: self.section, action: { arguments.openStickerPack(info) }, setPackIdWithRevealedOptions: { _, _ in @@ -202,8 +184,7 @@ public func featuredStickerPacksController(context: AccountContext) -> ViewContr let featured = Promise<[FeaturedStickerPackItem]>() featured.set(context.account.viewTracker.featuredStickerPacks()) - - var previousPackCount: Int? + var initialUnreadPacks: [ItemCollectionId: Bool] = [:] let signal = combineLatest(context.sharedContext.presentationData, statePromise.get() |> deliverOnMainQueue, stickerPacks.get() |> deliverOnMainQueue, featured.get() |> deliverOnMainQueue, context.sharedContext.accountManager.sharedData(keys: [ApplicationSpecificSharedDataKeys.stickerSettings]) |> deliverOnMainQueue) @@ -214,8 +195,6 @@ public func featuredStickerPacksController(context: AccountContext) -> ViewContr stickerSettings = value } - let packCount: Int? = featured.count - for item in featured { if initialUnreadPacks[item.info.id] == nil { initialUnreadPacks[item.info.id] = item.unread @@ -223,8 +202,6 @@ public func featuredStickerPacksController(context: AccountContext) -> ViewContr } let rightNavigationButton: ItemListNavigationButton? = nil - let previous = previousPackCount - previousPackCount = packCount let controllerState = ItemListControllerState(presentationData: ItemListPresentationData(presentationData), title: .text(presentationData.strings.FeaturedStickerPacks_Title), leftNavigationButton: nil, rightNavigationButton: rightNavigationButton, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back), animateChanges: true) diff --git a/submodules/SettingsUI/Sources/Stickers/InstalledStickerPacksController.swift b/submodules/SettingsUI/Sources/Stickers/InstalledStickerPacksController.swift index 2bf1143f04..bf40f089ae 100644 --- a/submodules/SettingsUI/Sources/Stickers/InstalledStickerPacksController.swift +++ b/submodules/SettingsUI/Sources/Stickers/InstalledStickerPacksController.swift @@ -65,32 +65,6 @@ public enum InstalledStickerPacksEntryTag: ItemListItemTag { private enum InstalledStickerPacksEntryId: Hashable { case index(Int32) case pack(ItemCollectionId) - - var hashValue: Int { - switch self { - case let .index(index): - return index.hashValue - case let .pack(id): - return id.hashValue - } - } - - static func ==(lhs: InstalledStickerPacksEntryId, rhs: InstalledStickerPacksEntryId) -> Bool { - switch lhs { - case let .index(index): - if case .index(index) = rhs { - return true - } else { - return false - } - case let .pack(id): - if case .pack(id) = rhs { - return true - } else { - return false - } - } - } } private indirect enum InstalledStickerPacksEntry: ItemListNodeEntry { @@ -848,8 +822,8 @@ public func installedStickerPacksController(context: AccountContext, mode: Insta var currentIds: [ItemCollectionId] = [] for entry in entries { switch entry { - case let .pack(pack): - currentIds.append(pack.3.id) + case let .pack(_, _, _, info, _, _, _, _, _, _): + currentIds.append(info.id) default: break } @@ -902,14 +876,14 @@ public func installedStickerPacksController(context: AccountContext, mode: Insta var currentIds: [ItemCollectionId] = [] for entry in entries { switch entry { - case let .pack(pack): - currentIds.append(pack.3.id) + case let .pack(_, _, _, info, _, _, _, _, _, _): + currentIds.append(info.id) default: break } } let _ = (context.account.postbox.transaction { transaction -> Void in - var infos = transaction.getItemCollectionsInfos(namespace: namespaceForMode(mode)) + let infos = transaction.getItemCollectionsInfos(namespace: namespaceForMode(mode)) var packDict: [ItemCollectionId: Int] = [:] for i in 0 ..< infos.count { diff --git a/submodules/SettingsUI/Sources/Terms of Service/TermsOfServiceController.swift b/submodules/SettingsUI/Sources/Terms of Service/TermsOfServiceController.swift index 1fda1a5129..4e4db063d1 100644 --- a/submodules/SettingsUI/Sources/Terms of Service/TermsOfServiceController.swift +++ b/submodules/SettingsUI/Sources/Terms of Service/TermsOfServiceController.swift @@ -113,7 +113,6 @@ public class TermsOfServiceController: ViewController, StandalonePresentableCont text = strongSelf.presentationData.strings.PrivacyPolicy_DeclineMessage declineTitle = strongSelf.presentationData.strings.PrivacyPolicy_DeclineDeclineAndDelete } - let theme: PresentationTheme = strongSelf.presentationData.theme strongSelf.present(standardTextAlertController(theme: AlertControllerTheme(presentationData: strongSelf.presentationData), title: strongSelf.presentationData.strings.PrivacyPolicy_Decline, text: text, actions: [TextAlertAction(type: .destructiveAction, title: declineTitle, action: { self?.decline() }), TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_Cancel, action: { diff --git a/submodules/SettingsUI/Sources/Terms of Service/TermsOfServiceControllerNode.swift b/submodules/SettingsUI/Sources/Terms of Service/TermsOfServiceControllerNode.swift index fe3797b498..5e1058e9de 100644 --- a/submodules/SettingsUI/Sources/Terms of Service/TermsOfServiceControllerNode.swift +++ b/submodules/SettingsUI/Sources/Terms of Service/TermsOfServiceControllerNode.swift @@ -137,7 +137,6 @@ final class TermsOfServiceControllerNode: ViewControllerTracingNode { guard let strongSelf = self else { return } - let theme: PresentationTheme = strongSelf.presentationData.theme let actionSheet = ActionSheetController(presentationData: strongSelf.presentationData) actionSheet.setItemGroups([ActionSheetItemGroup(items: [ ActionSheetTextItem(title: strongSelf.presentationData.strings.Login_TermsOfService_ProceedBot(mention).string), @@ -169,7 +168,6 @@ final class TermsOfServiceControllerNode: ViewControllerTracingNode { return } if let url = attributes[NSAttributedString.Key(rawValue: TelegramTextAttributes.URL)] as? String { - let theme: PresentationTheme = strongSelf.presentationData.theme let actionSheet = ActionSheetController(presentationData: strongSelf.presentationData) actionSheet.setItemGroups([ActionSheetItemGroup(items: [ ActionSheetTextItem(title: url), diff --git a/submodules/SettingsUI/Sources/Text Size/TextSizeSelectionController.swift b/submodules/SettingsUI/Sources/Text Size/TextSizeSelectionController.swift index 5fd07b038f..ceefe04ed2 100644 --- a/submodules/SettingsUI/Sources/Text Size/TextSizeSelectionController.swift +++ b/submodules/SettingsUI/Sources/Text Size/TextSizeSelectionController.swift @@ -227,7 +227,6 @@ private final class TextSizeSelectionControllerNode: ASDisplayNode, UIScrollView let peer4 = TelegramUser(id: PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt32Value(4)), accessHash: nil, firstName: self.presentationData.strings.Appearance_ThemePreview_ChatList_4_Name, lastName: nil, username: nil, phone: nil, photo: [], botInfo: nil, restrictionInfo: nil, flags: []) let peer5 = TelegramChannel(id: PeerId(namespace: Namespaces.Peer.CloudChannel, id: PeerId.Id._internalFromInt32Value(5)), accessHash: nil, title: self.presentationData.strings.Appearance_ThemePreview_ChatList_5_Name, username: nil, photo: [], creationDate: 0, version: 0, participationStatus: .member, info: .broadcast(.init(flags: [])), flags: [], restrictionInfo: nil, adminRights: nil, bannedRights: nil, defaultBannedRights: nil) let peer6 = TelegramUser(id: PeerId(namespace: Namespaces.Peer.SecretChat, id: PeerId.Id._internalFromInt32Value(5)), accessHash: nil, firstName: self.presentationData.strings.Appearance_ThemePreview_ChatList_6_Name, lastName: nil, username: nil, phone: nil, photo: [], botInfo: nil, restrictionInfo: nil, flags: []) - let peer7 = TelegramUser(id: PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt32Value(6)), accessHash: nil, firstName: self.presentationData.strings.Appearance_ThemePreview_ChatList_7_Name, lastName: nil, username: nil, phone: nil, photo: [], botInfo: nil, restrictionInfo: nil, flags: []) let timestamp = self.referenceTimestamp diff --git a/submodules/SettingsUI/Sources/Themes/EditThemeController.swift b/submodules/SettingsUI/Sources/Themes/EditThemeController.swift index 2b6b8237eb..7d1c27992f 100644 --- a/submodules/SettingsUI/Sources/Themes/EditThemeController.swift +++ b/submodules/SettingsUI/Sources/Themes/EditThemeController.swift @@ -147,7 +147,7 @@ private enum EditThemeControllerEntry: ItemListNodeEntry { func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem { let arguments = arguments as! EditThemeControllerArguments switch self { - case let .title(theme, strings, title, text, _): + case let .title(_, _, title, text, _): return ItemListSingleLineInputItem(presentationData: presentationData, title: NSAttributedString(), text: text, placeholder: title, type: .regular(capitalization: true, autocorrection: false), returnKeyType: .default, clearType: .onFocus, tag: EditThemeEntryTag.title, sectionId: self.section, textUpdated: { value in arguments.updateState { current in var state = current @@ -157,8 +157,8 @@ private enum EditThemeControllerEntry: ItemListNodeEntry { }, action: { }) - case let .slug(theme, strings, title, text, enabled): - return ItemListSingleLineInputItem(presentationData: presentationData, title: NSAttributedString(string: "t.me/addtheme/", textColor: theme.list.itemPrimaryTextColor), text: text, placeholder: title, type: .username, clearType: .onFocus, enabled: enabled, tag: EditThemeEntryTag.slug, sectionId: self.section, textUpdated: { value in + case let .slug(_, _, title, text, enabled): + return ItemListSingleLineInputItem(presentationData: presentationData, title: NSAttributedString(string: "t.me/addtheme/", textColor: presentationData.theme.list.itemPrimaryTextColor), text: text, placeholder: title, type: .username, clearType: .onFocus, enabled: enabled, tag: EditThemeEntryTag.slug, sectionId: self.section, textUpdated: { value in arguments.updateState { current in var state = current state.slug = value @@ -167,21 +167,21 @@ private enum EditThemeControllerEntry: ItemListNodeEntry { }, action: { }) - case let .slugInfo(theme, text): + case let .slugInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .markdown(text), sectionId: self.section) - case let .chatPreviewHeader(theme, text): + case let .chatPreviewHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) case let .chatPreview(theme, componentTheme, wallpaper, fontSize, chatBubbleCorners, strings, dateTimeFormat, nameDisplayOrder, items): return ThemeSettingsChatPreviewItem(context: arguments.context, theme: theme, componentTheme: componentTheme, strings: strings, sectionId: self.section, fontSize: fontSize, chatBubbleCorners: chatBubbleCorners, wallpaper: wallpaper, dateTimeFormat: dateTimeFormat, nameDisplayOrder: nameDisplayOrder, messageItems: items) - case let .changeColors(theme, text): + case let .changeColors(_, text): return ItemListActionItem(presentationData: presentationData, title: text, kind: .generic, alignment: .natural, sectionId: self.section, style: .blocks, action: { arguments.openColors() }) - case let .uploadTheme(theme, text): + case let .uploadTheme(_, text): return ItemListActionItem(presentationData: presentationData, title: text, kind: .generic, alignment: .natural, sectionId: self.section, style: .blocks, action: { arguments.openFile() }) - case let .uploadInfo(theme, text): + case let .uploadInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .markdown(text), sectionId: self.section) } } diff --git a/submodules/SettingsUI/Sources/Themes/GenerateGradientColors.swift b/submodules/SettingsUI/Sources/Themes/GenerateGradientColors.swift index edd2dce252..48d4c93dc9 100644 --- a/submodules/SettingsUI/Sources/Themes/GenerateGradientColors.swift +++ b/submodules/SettingsUI/Sources/Themes/GenerateGradientColors.swift @@ -325,12 +325,12 @@ func generateGradientColors(color: UIColor) -> (UIColor, UIColor) { } if let colors = nearest?.colors { - var colorHsb = color.hsb - var similarColorHsb = UIColor(rgb: colors.0).hsb - var complementingColorHsb = UIColor(rgb: colors.1).hsb + let colorHsb = color.hsb + let similarColorHsb = UIColor(rgb: colors.0).hsb + let complementingColorHsb = UIColor(rgb: colors.1).hsb - var correction = (similarColorHsb.0 > 0.0 ? colorHsb.0 / similarColorHsb.0 : 1.0, similarColorHsb.1 > 0.0 ? colorHsb.1 / similarColorHsb.1 : 1.0, similarColorHsb.2 > 0.0 ? colorHsb.2 / similarColorHsb.2 : 1.0) - var correctedComplementingColor = UIColor(hue: min(1.0, complementingColorHsb.0 * correction.0), saturation: min(1.0, complementingColorHsb.1 * correction.1), brightness: min(1.0, complementingColorHsb.2 * correction.2), alpha: 1.0) + let correction = (similarColorHsb.0 > 0.0 ? colorHsb.0 / similarColorHsb.0 : 1.0, similarColorHsb.1 > 0.0 ? colorHsb.1 / similarColorHsb.1 : 1.0, similarColorHsb.2 > 0.0 ? colorHsb.2 / similarColorHsb.2 : 1.0) + let correctedComplementingColor = UIColor(hue: min(1.0, complementingColorHsb.0 * correction.0), saturation: min(1.0, complementingColorHsb.1 * correction.1), brightness: min(1.0, complementingColorHsb.2 * correction.2), alpha: 1.0) return (color, correctedComplementingColor) } else { return (color, color) diff --git a/submodules/SettingsUI/Sources/Themes/SettingsThemeWallpaperNode.swift b/submodules/SettingsUI/Sources/Themes/SettingsThemeWallpaperNode.swift index 641ede3a5c..6ed9876771 100644 --- a/submodules/SettingsUI/Sources/Themes/SettingsThemeWallpaperNode.swift +++ b/submodules/SettingsUI/Sources/Themes/SettingsThemeWallpaperNode.swift @@ -117,8 +117,8 @@ final class SettingsThemeWallpaperNode: ASDisplayNode { var colors: [UInt32] = [] var intensity: CGFloat = 0.5 - if case let .gradient(_, value, _) = wallpaper { - colors = value + if case let .gradient(gradient) = wallpaper { + colors = gradient.colors } else if case let .file(file) = wallpaper { colors = file.settings.colors intensity = CGFloat(file.settings.intensity ?? 50) / 100.0 @@ -210,7 +210,6 @@ final class SettingsThemeWallpaperNode: ASDisplayNode { let convertedFullRepresentations = [ImageRepresentationWithReference(representation: .init(dimensions: fullDimensions, resource: file.file.resource, progressiveSizes: [], immediateThumbnailData: nil), reference: .wallpaper(wallpaper: .slug(file.slug), resource: file.file.resource))] let imageSignal: Signal<(TransformImageArguments) -> DrawingContext?, NoError> - var placeholder: UIImage? if wallpaper.isPattern { var patternIntensity: CGFloat = 0.5 if !file.settings.colors.isEmpty { @@ -220,7 +219,6 @@ final class SettingsThemeWallpaperNode: ASDisplayNode { } if patternIntensity < 0.0 { - placeholder = blackColorImage self.imageNode.alpha = 1.0 self.arguments = PatternWallpaperArguments(colors: [.clear], rotation: nil, customPatternColor: UIColor(white: 0.0, alpha: 1.0 + patternIntensity)) } else { diff --git a/submodules/SettingsUI/Sources/Themes/ThemeAccentColorController.swift b/submodules/SettingsUI/Sources/Themes/ThemeAccentColorController.swift index 34479b9e34..10bc360375 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeAccentColorController.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeAccentColorController.swift @@ -34,8 +34,6 @@ enum ThemeAccentColorControllerMode { return themeReference case let .edit(_, _, _, defaultThemeReference, _, _): return defaultThemeReference - default: - return nil } } } @@ -68,7 +66,7 @@ final class ThemeAccentColorController: ViewController { self.mode = mode self.presentationData = context.sharedContext.currentPresentationData.with { $0 } - var section: ThemeColorSection = .background + let section: ThemeColorSection = .background self.section = section self.segmentedTitleView = ThemeColorSegmentedTitleView(theme: self.presentationData.theme, strings: self.presentationData.strings, selectedSection: section) @@ -163,15 +161,12 @@ final class ThemeAccentColorController: ViewController { if let patternWallpaper = state.patternWallpaper { coloredWallpaper = patternWallpaper.withUpdatedSettings(WallpaperSettings(colors: state.backgroundColors, intensity: state.patternIntensity, rotation: state.rotation)) } else if state.backgroundColors.count >= 2 { - coloredWallpaper = .gradient(nil, state.backgroundColors, WallpaperSettings(rotation: state.rotation)) + coloredWallpaper = .gradient(TelegramWallpaper.Gradient(id: nil, colors: state.backgroundColors, settings: WallpaperSettings(rotation: state.rotation))) } else { coloredWallpaper = .color(state.backgroundColors[0]) } } - - let apply: Signal - let prepareWallpaper: Signal if let patternWallpaper = state.patternWallpaper, case let .file(file) = patternWallpaper, !state.backgroundColors.isEmpty { let resource = file.file.resource @@ -193,10 +188,9 @@ final class ThemeAccentColorController: ViewController { prepareWallpaper = .complete() } - if case let .edit(theme, initialWallpaper, generalThemeReference, themeReference, _, completion) = strongSelf.mode { + if case let .edit(theme, _, generalThemeReference, _, _, completion) = strongSelf.mode { let _ = (prepareWallpaper - |> deliverOnMainQueue).start(completed: { [weak self] in - let updatedTheme: PresentationTheme + |> deliverOnMainQueue).start(completed: { let updatedTheme: PresentationTheme var settings: TelegramThemeSettings? var hasSettings = false @@ -217,11 +211,6 @@ final class ThemeAccentColorController: ViewController { } if hasSettings, let baseTheme = baseTheme { - var messageColors: (Int32, Int32)? - if let colors = state.messagesColors { - messageColors = (Int32(bitPattern: colors.0.argb), Int32(bitPattern: colors.1?.argb ?? colors.0.argb)) - } - settings = TelegramThemeSettings(baseTheme: baseTheme, accentColor: state.accentColor, messageColors: state.messagesColors, wallpaper: coloredWallpaper) } @@ -390,9 +379,8 @@ final class ThemeAccentColorController: ViewController { var backgroundColors: [UInt32] = [] var patternWallpaper: TelegramWallpaper? var patternIntensity: Int32 = 50 - var motion = false let messageColors: (UIColor, UIColor?)? - var defaultMessagesColor: UIColor? + let defaultMessagesColor: UIColor? = nil var rotation: Int32 = 0 func extractWallpaperParameters(_ wallpaper: TelegramWallpaper?) { @@ -400,27 +388,19 @@ final class ThemeAccentColorController: ViewController { return } if case let .file(file) = wallpaper, wallpaper.isPattern { - var patternColor = UIColor(rgb: 0xd6e2ee, alpha: 0.4) - var bottomColor: UIColor? if !file.settings.colors.isEmpty { if let intensity = file.settings.intensity { patternIntensity = intensity } - patternColor = UIColor(rgb: file.settings.colors[0]) - if file.settings.colors.count >= 2 { - bottomColor = UIColor(rgb: file.settings.colors[1]) - } } patternWallpaper = wallpaper backgroundColors = file.settings.colors - motion = file.settings.motion rotation = file.settings.rotation ?? 0 } else if case let .color(color) = wallpaper { backgroundColors = [color] - } else if case let .gradient(_, colors, settings) = wallpaper { - backgroundColors = colors - motion = settings.motion - rotation = settings.rotation ?? 0 + } else if case let .gradient(gradient) = wallpaper { + backgroundColors = gradient.colors + rotation = gradient.settings.rotation ?? 0 } else { if let image = chatControllerBackgroundImage(theme: nil, wallpaper: wallpaper, mediaBox: strongSelf.context.sharedContext.accountManager.mediaBox, knockoutMode: false) { backgroundColors = [averageColor(from: image).rgb] @@ -559,8 +539,6 @@ final class ThemeAccentColorController: ViewController { } } } else { - let themeSpecificAccentColor = settings.themeSpecificAccentColors[themeReference.index] - let theme = makePresentationTheme(mediaBox: strongSelf.context.sharedContext.accountManager.mediaBox, themeReference: themeReference)! accentColor = theme.rootController.navigationBar.accentTextColor @@ -582,7 +560,7 @@ final class ThemeAccentColorController: ViewController { } } } - } else if case let .edit(theme, wallpaper, _, themeReference, _, _) = strongSelf.mode { + } else if case let .edit(theme, wallpaper, _, _, _, _) = strongSelf.mode { accentColor = theme.rootController.navigationBar.accentTextColor let wallpaper = wallpaper ?? theme.chat.defaultWallpaper diff --git a/submodules/SettingsUI/Sources/Themes/ThemeAccentColorControllerNode.swift b/submodules/SettingsUI/Sources/Themes/ThemeAccentColorControllerNode.swift index bd1850236f..2569a513a4 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeAccentColorControllerNode.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeAccentColorControllerNode.swift @@ -205,7 +205,7 @@ final class ThemeAccentColorControllerNode: ASDisplayNode, UIScrollViewDelegate switch self.wallpaper { case .image, .builtin: return true - case let .file(file): + case .file: return !self.wallpaper.isPattern default: return false @@ -457,7 +457,7 @@ final class ThemeAccentColorControllerNode: ASDisplayNode, UIScrollViewDelegate } convertedRepresentations.append(ImageRepresentationWithReference(representation: .init(dimensions: dimensions, resource: file.file.resource, progressiveSizes: [], immediateThumbnailData: nil), reference: .wallpaper(wallpaper: .slug(file.slug), resource: file.file.resource))) } else if backgroundColors.count >= 2 { - wallpaper = .gradient(nil, backgroundColors, WallpaperSettings(rotation: state.rotation)) + wallpaper = .gradient(TelegramWallpaper.Gradient(id: nil, colors: backgroundColors, settings: WallpaperSettings(rotation: state.rotation))) } else { wallpaper = .color(backgroundColors.first ?? 0xffffff) } @@ -467,7 +467,7 @@ final class ThemeAccentColorControllerNode: ASDisplayNode, UIScrollViewDelegate case .dayClassic: let topColor = accentColor.withMultiplied(hue: 1.010, saturation: 0.414, brightness: 0.957) let bottomColor = accentColor.withMultiplied(hue: 1.019, saturation: 0.867, brightness: 0.965) - suggestedWallpaper = .gradient(nil, [topColor.rgb, bottomColor.rgb], WallpaperSettings()) + suggestedWallpaper = .gradient(TelegramWallpaper.Gradient(id: nil, colors: [topColor.rgb, bottomColor.rgb], settings: WallpaperSettings())) backgroundColors = [topColor.rgb, bottomColor.rgb] case .nightAccent: let color = accentColor.withMultiplied(hue: 1.024, saturation: 0.573, brightness: 0.18) @@ -980,8 +980,6 @@ final class ThemeAccentColorControllerNode: ASDisplayNode, UIScrollViewDelegate } func containerLayoutUpdated(_ layout: ContainerViewLayout, navigationBarHeight: CGFloat, transition: ContainedViewLayoutTransition) { - let isFirstLayout = self.validLayout == nil - let bounds = CGRect(origin: CGPoint(), size: layout.size) let chatListPreviewAvailable = self.state.section == .accent @@ -1022,8 +1020,8 @@ final class ThemeAccentColorControllerNode: ASDisplayNode, UIScrollViewDelegate transition.updateFrame(node: self.colorPanelNode, frame: colorPanelFrame) self.colorPanelNode.updateLayout(size: colorPanelFrame.size, transition: transition) - var patternPanelAlpha: CGFloat = self.state.displayPatternPanel ? 1.0 : 0.0 - var patternPanelFrame = colorPanelFrame + let patternPanelAlpha: CGFloat = self.state.displayPatternPanel ? 1.0 : 0.0 + let patternPanelFrame = colorPanelFrame transition.updateFrame(node: self.patternPanelNode, frame: patternPanelFrame) self.patternPanelNode.updateLayout(size: patternPanelFrame.size, transition: transition) self.patternPanelNode.isUserInteractionEnabled = self.state.displayPatternPanel diff --git a/submodules/SettingsUI/Sources/Themes/ThemeAutoNightTimeSelectionActionSheet.swift b/submodules/SettingsUI/Sources/Themes/ThemeAutoNightTimeSelectionActionSheet.swift index b71ed79464..b357293898 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeAutoNightTimeSelectionActionSheet.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeAutoNightTimeSelectionActionSheet.swift @@ -19,7 +19,6 @@ final class ThemeAutoNightTimeSelectionActionSheet: ActionSheetController { init(context: AccountContext, currentValue: Int32, emptyTitle: String? = nil, applyValue: @escaping (Int32?) -> Void) { let presentationData = context.sharedContext.currentPresentationData.with { $0 } - let theme = presentationData.theme let strings = presentationData.strings super.init(theme: ActionSheetControllerTheme(presentationData: presentationData)) diff --git a/submodules/SettingsUI/Sources/Themes/ThemeColorsGridControllerNode.swift b/submodules/SettingsUI/Sources/Themes/ThemeColorsGridControllerNode.swift index e531bbb151..bb37b5bdfa 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeColorsGridControllerNode.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeColorsGridControllerNode.swift @@ -142,7 +142,7 @@ final class ThemeColorsGridControllerNode: ASDisplayNode { self.controllerInteraction = interaction var wallpapers: [TelegramWallpaper] = [] - wallpapers.append(contentsOf: gradients.map { TelegramWallpaper.gradient(nil, $0, WallpaperSettings()) }) + wallpapers.append(contentsOf: gradients.map { TelegramWallpaper.gradient(TelegramWallpaper.Gradient(id: nil, colors: $0, settings: WallpaperSettings())) }) wallpapers.append(contentsOf: colors.map { TelegramWallpaper.color($0) }) let transition = context.sharedContext.presentationData |> map { presentationData -> (ThemeColorsGridEntryTransition, Bool) in diff --git a/submodules/SettingsUI/Sources/Themes/ThemeGridController.swift b/submodules/SettingsUI/Sources/Themes/ThemeGridController.swift index 355a2be23d..b39af5c582 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeGridController.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeGridController.swift @@ -343,13 +343,13 @@ final class ThemeGridController: ViewController { for wallpaper in wallpapers { var item: String? switch wallpaper { - case let .file(_, _, _, _, isPattern, _, slug, _, settings): + case let .file(file): var options: [String] = [] - if isPattern { - if settings.colors.count >= 1 { - options.append("bg_color=\(UIColor(rgb: settings.colors[0]).hexString)") + if file.isPattern { + if file.settings.colors.count >= 1 { + options.append("bg_color=\(UIColor(rgb: file.settings.colors[0]).hexString)") } - if let intensity = settings.intensity { + if let intensity = file.settings.intensity { options.append("intensity=\(intensity)") } } @@ -358,7 +358,7 @@ final class ThemeGridController: ViewController { if !options.isEmpty { optionsString = "?\(options.joined(separator: "&"))" } - item = slug + optionsString + item = file.slug + optionsString case let .color(color): item = "\(UIColor(rgb: color).hexString)" default: diff --git a/submodules/SettingsUI/Sources/Themes/ThemeGridControllerNode.swift b/submodules/SettingsUI/Sources/Themes/ThemeGridControllerNode.swift index 733c7b4174..762f26a144 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeGridControllerNode.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeGridControllerNode.swift @@ -60,10 +60,10 @@ struct ThemeGridControllerEntry: Comparable, Identifiable { return .builtin case let .color(color): return .color(color) - case let .gradient(_, colors, _): - return .gradient(colors) - case let .file(id, _, _, _, _, _, _, _, settings): - return .file(id, settings.colors, settings.intensity ?? 0) + case let .gradient(gradient): + return .gradient(gradient.colors) + case let .file(file): + return .file(file.id, file.settings.colors, file.settings.intensity ?? 0) case let .image(representations, _): if let largest = largestImageRepresentation(representations) { return .image(largest.resource.id.uniqueId) @@ -240,8 +240,6 @@ final class ThemeGridControllerNode: ASDisplayNode { self.currentState = ThemeGridControllerNodeState(editing: false, selectedIds: Set()) self.statePromise = ValuePromise(self.currentState, ignoreRepeated: true) - let defaultWallpaper = presentationData.theme.chat.defaultWallpaper - let wallpapersPromise = Promise<[Wallpaper]>() self.wallpapersPromise = wallpapersPromise @@ -344,13 +342,7 @@ final class ThemeGridControllerNode: ASDisplayNode { |> map { wallpapers, deletedWallpaperIds, presentationData -> (ThemeGridEntryTransition, Bool) in var entries: [ThemeGridControllerEntry] = [] var index = 1 - - var isSelectedEditable = true - if case .builtin = presentationData.chatWallpaper { - isSelectedEditable = false - } else if presentationData.chatWallpaper.isBasicallyEqual(to: presentationData.theme.chat.defaultWallpaper) { - isSelectedEditable = false - } + entries.insert(ThemeGridControllerEntry(index: 0, wallpaper: presentationData.chatWallpaper, isEditable: false, isSelected: true), at: 0) var defaultWallpaper: TelegramWallpaper? diff --git a/submodules/SettingsUI/Sources/Themes/ThemeGridSearchContentNode.swift b/submodules/SettingsUI/Sources/Themes/ThemeGridSearchContentNode.swift index 17c57e9400..f1d1fa9b66 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeGridSearchContentNode.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeGridSearchContentNode.swift @@ -180,32 +180,6 @@ final class ThemeGridSearchInteraction { private enum ThemeGridRecentEntryStableId: Hashable { case colors case query(String) - - static func ==(lhs: ThemeGridRecentEntryStableId, rhs: ThemeGridRecentEntryStableId) -> Bool { - switch lhs { - case .colors: - if case .colors = rhs { - return true - } else { - return false - } - case let .query(query): - if case .query(query) = rhs { - return true - } else { - return false - } - } - } - - var hashValue: Int { - switch self { - case .colors: - return 0 - case let .query(query): - return query.hashValue - } - } } private enum ThemeGridRecentEntry: Comparable, Identifiable { diff --git a/submodules/SettingsUI/Sources/Themes/ThemePreviewController.swift b/submodules/SettingsUI/Sources/Themes/ThemePreviewController.swift index 162f11d443..6551db9c2c 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemePreviewController.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemePreviewController.swift @@ -423,7 +423,7 @@ public final class ThemePreviewController: ViewController { Queue.mainQueue().after(0.3) { if layout.size.width >= 375.0 { let navigationController = strongSelf.navigationController as? NavigationController - if let (previousDefaultTheme, previousAccentColor, autoNightMode, theme, existing) = previousDefaultTheme { + if let (previousDefaultTheme, previousAccentColor, autoNightMode, theme, _) = previousDefaultTheme { let _ = (ApplicationSpecificNotice.getThemeChangeTip(accountManager: strongSelf.context.sharedContext.accountManager) |> deliverOnMainQueue).start(next: { [weak self] displayed in guard let strongSelf = self, !displayed else { @@ -485,7 +485,7 @@ public final class ThemePreviewController: ViewController { let subject: ShareControllerSubject let preferredAction: ShareControllerPreferredAction switch self.source { - case let .settings(reference): + case .settings: return case let .theme(theme): subject = .url("https://t.me/addtheme/\(theme.slug)") diff --git a/submodules/SettingsUI/Sources/Themes/ThemePreviewControllerNode.swift b/submodules/SettingsUI/Sources/Themes/ThemePreviewControllerNode.swift index c07a304420..3cf8104a6d 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemePreviewControllerNode.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemePreviewControllerNode.swift @@ -125,7 +125,7 @@ final class ThemePreviewControllerNode: ASDisplayNode, UIScrollViewDelegate { self.toolbarNode = WallpaperGalleryToolbarNode(theme: self.previewTheme, strings: self.presentationData.strings, doneButtonType: .set) - if case let .file(file) = previewTheme.chat.defaultWallpaper { + if case .file = previewTheme.chat.defaultWallpaper { self.toolbarNode.setDoneEnabled(false) } @@ -191,8 +191,8 @@ final class ThemePreviewControllerNode: ASDisplayNode, UIScrollViewDelegate { if file.settings.blur { self.chatContainerNode.insertSubnode(self.blurredNode, belowSubnode: self.messagesContainerNode) } - } else if case let .gradient(_, colors, _) = self.wallpaper { - gradientColors = colors + } else if case let .gradient(gradient) = self.wallpaper { + gradientColors = gradient.colors } if gradientColors.count >= 3 { @@ -247,7 +247,6 @@ final class ThemePreviewControllerNode: ASDisplayNode, UIScrollViewDelegate { convertedRepresentations.append(ImageRepresentationWithReference(representation: .init(dimensions: dimensions, resource: file.file.resource, progressiveSizes: [], immediateThumbnailData: nil), reference: .wallpaper(wallpaper: .slug(file.slug), resource: file.file.resource))) let signal: Signal<(TransformImageArguments) -> DrawingContext?, NoError> - let fileReference = FileMediaReference.standalone(media: file.file) if wallpaper.isPattern { signal = .complete() } else { diff --git a/submodules/SettingsUI/Sources/Themes/ThemeSettingsAccentColorItem.swift b/submodules/SettingsUI/Sources/Themes/ThemeSettingsAccentColorItem.swift index d3a27127ca..515d129297 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeSettingsAccentColorItem.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeSettingsAccentColorItem.swift @@ -24,7 +24,7 @@ private enum ThemeSettingsColorEntry: Comparable, Identifiable { var stableId: ThemeSettingsColorEntryId { switch self { - case let .color(index, _, themeReference, accentColor, _): + case let .color(_, _, themeReference, accentColor, _): return .color(themeReference.index &+ Int64(accentColor?.index ?? 0)) case let .theme(_, _, _, theme, _): return .theme(theme.index) @@ -555,8 +555,6 @@ private final class ThemeSettingsAccentColorPickerItemNode : ListViewItemNode { } func asyncLayout() -> (ThemeSettingsAccentColorPickerItem, ListViewItemLayoutParams) -> (ListViewItemNodeLayout, (Bool) -> Void) { - let currentItem = self.item - return { [weak self] item, params in let itemLayout = ListViewItemNodeLayout(contentSize: CGSize(width: 60.0, height: 60.0), insets: UIEdgeInsets()) return (itemLayout, { animated in @@ -767,7 +765,7 @@ class ThemeSettingsAccentColorItemNode: ListViewItemNode, ItemListItemNode { } self.enqueuedTransitions.remove(at: 0) - var options = ListViewDeleteAndInsertOptions() + let options = ListViewDeleteAndInsertOptions() var scrollToItem: ListViewScrollToItem? if !self.initialized || transition.updatePosition { if let index = item.colors.firstIndex(where: { $0.index == item.currentColor?.index }) { @@ -776,7 +774,7 @@ class ThemeSettingsAccentColorItemNode: ListViewItemNode, ItemListItemNode { } } - self.listNode.transaction(deleteIndices: transition.deletions, insertIndicesAndItems: transition.insertions, updateIndicesAndItems: transition.updates, options: options, scrollToItem: scrollToItem, updateSizeAndInsets: nil, updateOpaqueState: nil, completion: { [weak self] _ in + self.listNode.transaction(deleteIndices: transition.deletions, insertIndicesAndItems: transition.insertions, updateIndicesAndItems: transition.updates, options: options, scrollToItem: scrollToItem, updateSizeAndInsets: nil, updateOpaqueState: nil, completion: { _ in }) } @@ -789,11 +787,6 @@ class ThemeSettingsAccentColorItemNode: ListViewItemNode, ItemListItemNode { themeUpdated = true } - var colorUpdated: Bool - if currentItem?.currentColor != item.currentColor { - colorUpdated = true - } - let contentSize: CGSize let insets: UIEdgeInsets let separatorHeight = UIScreenPixel @@ -927,10 +920,10 @@ class ThemeSettingsAccentColorItemNode: ListViewItemNode, ItemListItemNode { } else { item.updated(color) } - ensureColorVisible(listNode: strongSelf.listNode, accentColor: color, animated: true) + let _ = ensureColorVisible(listNode: strongSelf.listNode, accentColor: color, animated: true) } } - let contextAction: ((ThemeSettingsColorOption?, Bool, ASDisplayNode, ContextGesture?) -> Void)? = { [weak item] color, selected, node, gesture in + let contextAction: ((ThemeSettingsColorOption?, Bool, ASDisplayNode, ContextGesture?) -> Void)? = { color, selected, node, gesture in if let strongSelf = self, let item = strongSelf.item { item.contextAction?(selected, item.generalThemeReference, color, node, gesture) } diff --git a/submodules/SettingsUI/Sources/Themes/ThemeSettingsAppIconItem.swift b/submodules/SettingsUI/Sources/Themes/ThemeSettingsAppIconItem.swift index e6ff3204de..566acd8dbb 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeSettingsAppIconItem.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeSettingsAppIconItem.swift @@ -206,8 +206,6 @@ class ThemeSettingsAppIconItemNode: ListViewItemNode, ItemListItemNode { } func asyncLayout() -> (_ item: ThemeSettingsAppIconItem, _ params: ListViewItemLayoutParams, _ neighbors: ItemListNeighbors) -> (ListViewItemNodeLayout, () -> Void) { - let currentItem = self.item - return { item, params, neighbors in let contentSize: CGSize let insets: UIEdgeInsets diff --git a/submodules/SettingsUI/Sources/Themes/ThemeSettingsController.swift b/submodules/SettingsUI/Sources/Themes/ThemeSettingsController.swift index b36f14acef..6c082bd9ff 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeSettingsController.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeSettingsController.swift @@ -214,8 +214,8 @@ private enum ThemeSettingsControllerEntry: ItemListNodeEntry { } else { return false } - case let .accentColor(lhsTheme, lhsGeneralTheme, lhsCurrentTheme, lhsThemes, lhsColor): - if case let .accentColor(rhsTheme, rhsGeneralTheme, rhsCurrentTheme, rhsThemes, rhsColor) = rhs, lhsTheme === rhsTheme, lhsCurrentTheme == rhsCurrentTheme, lhsThemes == rhsThemes, lhsColor == rhsColor { + case let .accentColor(lhsTheme, _, lhsCurrentTheme, lhsThemes, lhsColor): + if case let .accentColor(rhsTheme, _, rhsCurrentTheme, rhsThemes, rhsColor) = rhs, lhsTheme === rhsTheme, lhsCurrentTheme == rhsCurrentTheme, lhsThemes == rhsThemes, lhsColor == rhsColor { return true } else { return false @@ -308,7 +308,7 @@ private enum ThemeSettingsControllerEntry: ItemListNodeEntry { func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem { let arguments = arguments as! ThemeSettingsControllerArguments switch self { - case let .fontSizeHeader(theme, text): + case let .fontSizeHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) case let .fontSize(theme, fontSize): return ThemeSettingsFontSizeItem(theme: theme, fontSize: fontSize, sectionId: self.section, updated: { value in @@ -316,7 +316,7 @@ private enum ThemeSettingsControllerEntry: ItemListNodeEntry { }, tag: ThemeSettingsEntryTag.fontSize) case let .chatPreview(theme, wallpaper, fontSize, chatBubbleCorners, strings, dateTimeFormat, nameDisplayOrder, items): return ThemeSettingsChatPreviewItem(context: arguments.context, theme: theme, componentTheme: theme, strings: strings, sectionId: self.section, fontSize: fontSize, chatBubbleCorners: chatBubbleCorners, wallpaper: wallpaper, dateTimeFormat: dateTimeFormat, nameDisplayOrder: nameDisplayOrder, messageItems: items) - case let .wallpaper(theme, text): + case let .wallpaper(_, text): return ItemListDisclosureItem(presentationData: presentationData, title: text, label: "", sectionId: self.section, style: .blocks, action: { arguments.openWallpaperSettings() }) @@ -403,19 +403,19 @@ private enum ThemeSettingsControllerEntry: ItemListNodeEntry { }, openColorPicker: { create in arguments.openAccentColorPicker(currentTheme, create) }, tag: ThemeSettingsEntryTag.accentColor) - case let .autoNightTheme(theme, text, value): + case let .autoNightTheme(_, text, value): return ItemListDisclosureItem(presentationData: presentationData, icon: nil, title: text, label: value, labelStyle: .text, sectionId: self.section, style: .blocks, disclosureStyle: .arrow, action: { arguments.openAutoNightTheme() }) - case let .textSize(theme, text, value): + case let .textSize(_, text, value): return ItemListDisclosureItem(presentationData: presentationData, icon: nil, title: text, label: value, labelStyle: .text, sectionId: self.section, style: .blocks, disclosureStyle: .arrow, action: { arguments.openTextSize() }) - case let .bubbleSettings(theme, text, value): + case let .bubbleSettings(_, text, value): return ItemListDisclosureItem(presentationData: presentationData, icon: nil, title: text, label: value, labelStyle: .text, sectionId: self.section, style: .blocks, disclosureStyle: .arrow, action: { arguments.openBubbleSettings() }) - case let .themeListHeader(theme, text): + case let .themeListHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) case let .themeItem(theme, strings, themes, allThemes, currentTheme, themeSpecificAccentColors, themeSpecificChatWallpapers, _): return ThemeSettingsThemeItem(context: arguments.context, theme: theme, strings: strings, sectionId: self.section, themes: themes, allThemes: allThemes, displayUnsupported: true, themeSpecificAccentColors: themeSpecificAccentColors, themeSpecificChatWallpapers: themeSpecificChatWallpapers, currentTheme: currentTheme, updatedTheme: { theme in @@ -429,23 +429,23 @@ private enum ThemeSettingsControllerEntry: ItemListNodeEntry { }, contextAction: { theme, node, gesture in arguments.themeContextAction(theme.index == currentTheme.index, theme, node, gesture) }, tag: ThemeSettingsEntryTag.theme) - case let .iconHeader(theme, text): + case let .iconHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) case let .iconItem(theme, strings, icons, value): return ThemeSettingsAppIconItem(theme: theme, strings: strings, sectionId: self.section, icons: icons, currentIconName: value, updated: { iconName in arguments.selectAppIcon(iconName) }) - case let .otherHeader(theme, text): + case let .otherHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .largeEmoji(theme, title, value): + case let .largeEmoji(_, title, value): return ItemListSwitchItem(presentationData: presentationData, title: title, value: value, sectionId: self.section, style: .blocks, updated: { value in arguments.toggleLargeEmoji(value) }, tag: ThemeSettingsEntryTag.largeEmoji) - case let .animations(theme, title, value): + case let .animations(_, title, value): return ItemListSwitchItem(presentationData: presentationData, title: title, value: value, sectionId: self.section, style: .blocks, updated: { value in arguments.disableAnimations(value) }, tag: ThemeSettingsEntryTag.animations) - case let .animationsInfo(theme, text): + case let .animationsInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) } } @@ -486,7 +486,7 @@ private func themeSettingsControllerEntries(presentationData: PresentationData, } var colorOption: ThemeSettingsColorOption? - if case let .builtin(theme) = themeReference { + if case .builtin = themeReference { colorOption = presentationThemeSettings.themeSpecificAccentColors[themeReference.index].flatMap { .accentColor($0) } } else { colorOption = .theme(themeReference) @@ -656,7 +656,7 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The if case let .file(file) = wallpaper, file.id == 0 { return cachedWallpaper(account: context.account, slug: file.slug, settings: file.settings) |> map { cachedWallpaper in - if let wallpaper = cachedWallpaper?.wallpaper, case let .file(file) = wallpaper { + if let wallpaper = cachedWallpaper?.wallpaper, case .file = wallpaper { return (accentColor, wallpaper) } else { return (accentColor, .builtin(WallpaperSettings())) @@ -826,7 +826,7 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The return (accentColor, wallpaper) } |> mapToSignal { accentColor, wallpaper -> Signal<(PresentationTheme?, PresentationThemeReference, Bool, TelegramWallpaper?), NoError> in let generalThemeReference: PresentationThemeReference - if let accentColor = accentColor, case let .cloud(theme) = reference, let settings = theme.theme.settings { + if let _ = accentColor, case let .cloud(theme) = reference, let settings = theme.theme.settings { generalThemeReference = .builtin(PresentationBuiltinThemeReference(baseTheme: settings.baseTheme)) } else { generalThemeReference = reference @@ -998,7 +998,7 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The if isCurrent, let settings = cloudTheme.theme.settings { let colorThemes = themes.filter { theme in - if let settings = theme.settings { + if let _ = theme.settings { return true } else { return false @@ -1007,7 +1007,6 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The if let currentThemeIndex = colorThemes.firstIndex(where: { $0.id == cloudTheme.theme.id }) { let previousThemeIndex = themes.prefix(upTo: currentThemeIndex).reversed().firstIndex(where: { $0.file != nil }) - let newTheme: PresentationThemeReference if let previousThemeIndex = previousThemeIndex { let theme = themes[themes.index(before: previousThemeIndex.base)] selectThemeImpl?(.cloud(PresentationCloudTheme(theme: theme, resolvedWallpaper: nil, creatorAccountId: theme.isCreator ? context.account.id : nil))) @@ -1254,8 +1253,6 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The wallpaperSignal = cachedWallpaper(account: context.account, slug: file.slug, settings: colorWallpaper.settings) |> mapToSignal { cachedWallpaper in if let wallpaper = cachedWallpaper?.wallpaper, case let .file(file) = wallpaper { - let resource = file.file.resource - let _ = fetchedMediaResource(mediaBox: context.account.postbox.mediaBox, reference: .wallpaper(wallpaper: .slug(file.slug), resource: file.file.resource)).start() return .single(wallpaper) @@ -1292,7 +1289,7 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The updatedTheme = generalThemeReference } - guard let theme = makePresentationTheme(mediaBox: context.sharedContext.accountManager.mediaBox, themeReference: generalThemeReference, accentColor: accentColor?.color, wallpaper: presetWallpaper, baseColor: accentColor?.baseColor) else { + guard let _ = makePresentationTheme(mediaBox: context.sharedContext.accountManager.mediaBox, themeReference: generalThemeReference, accentColor: accentColor?.color, wallpaper: presetWallpaper, baseColor: accentColor?.baseColor) else { return current } @@ -1300,7 +1297,7 @@ public func themeSettingsController(context: AccountContext, focusOnItemTag: The var themeSpecificAccentColors = current.themeSpecificAccentColors themeSpecificAccentColors[generalThemeReference.index] = accentColor?.withUpdatedWallpaper(presetWallpaper) - if case let .builtin(theme) = generalThemeReference { + if case .builtin = generalThemeReference { let index = coloredThemeIndex(reference: currentTheme, accentColor: accentColor) if let wallpaper = current.themeSpecificChatWallpapers[index] { if wallpaper.isColorOrGradient || wallpaper.isPattern || wallpaper.isBuiltin { diff --git a/submodules/SettingsUI/Sources/Themes/ThemeSettingsThemeItem.swift b/submodules/SettingsUI/Sources/Themes/ThemeSettingsThemeItem.swift index 31869598e4..2844e935cd 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeSettingsThemeItem.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeSettingsThemeItem.swift @@ -268,7 +268,7 @@ private final class ThemeSettingsThemeItemIconNode : ListViewItemNode { } let title = NSAttributedString(string: item.title, font: item.selected ? selectedTextFont : textFont, textColor: item.selected ? item.theme.list.itemAccentColor : item.theme.list.itemPrimaryTextColor) - let (titleLayout, titleApply) = makeTitleLayout(TextNodeLayoutArguments(attributedString: title, backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: params.width, height: CGFloat.greatestFiniteMagnitude), alignment: .center, cutout: nil, insets: UIEdgeInsets())) + let (_, titleApply) = makeTitleLayout(TextNodeLayoutArguments(attributedString: title, backgroundColor: nil, maximumNumberOfLines: 1, truncationType: .end, constrainedSize: CGSize(width: params.width, height: CGFloat.greatestFiniteMagnitude), alignment: .center, cutout: nil, insets: UIEdgeInsets())) let itemLayout = ListViewItemNodeLayout(contentSize: CGSize(width: 116.0, height: 116.0), insets: UIEdgeInsets()) return (itemLayout, { animated in @@ -533,8 +533,6 @@ class ThemeSettingsThemeItemNode: ListViewItemNode, ItemListItemNode { } func asyncLayout() -> (_ item: ThemeSettingsThemeItem, _ params: ListViewItemLayoutParams, _ neighbors: ItemListNeighbors) -> (ListViewItemNodeLayout, () -> Void) { - let currentItem = self.item - return { item, params, neighbors in let contentSize: CGSize let insets: UIEdgeInsets @@ -614,14 +612,14 @@ class ThemeSettingsThemeItemNode: ListViewItemNode, ItemListItemNode { var entries: [ThemeSettingsThemeEntry] = [] var index: Int = 0 - for var theme in item.themes { + for theme in item.themes { if case let .cloud(theme) = theme { if !item.displayUnsupported && theme.theme.file == nil { continue } } let title = themeDisplayName(strings: item.strings, reference: theme) - var accentColor = item.themeSpecificAccentColors[theme.generalThemeReference.index] + let accentColor = item.themeSpecificAccentColors[theme.generalThemeReference.index] /*if let customThemeIndex = accentColor?.themeIndex { if let customTheme = themes[customThemeIndex] { theme = customTheme diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperColorPanelNode.swift b/submodules/SettingsUI/Sources/Themes/WallpaperColorPanelNode.swift index 7d1f6b29c5..65aa51cdb6 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperColorPanelNode.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperColorPanelNode.swift @@ -567,20 +567,15 @@ final class WallpaperColorPanelNode: ASDisplayNode { let fieldHeight: CGFloat = 33.0 let leftInset: CGFloat let rightInset: CGFloat - let fieldSpacing: CGFloat if condensedLayout { leftInset = 6.0 rightInset = 6.0 - fieldSpacing = 40.0 } else { leftInset = 15.0 rightInset = 15.0 - fieldSpacing = 45.0 } - let rightInsetWithButton: CGFloat = 42.0 let buttonSize = CGSize(width: 26.0, height: 26.0) - let buttonOffset: CGFloat = (rightInsetWithButton - 13.0) / 2.0 //let middleButtonFrame = CGRect(origin: CGPoint(x: self.state.secondColor != nil ? floor((size.width - 26.0) / 2.0) : (self.state.secondColorAvailable ? size.width - rightInsetWithButton + floor((rightInsetWithButton - buttonSize.width) / 2.0) : size.width + buttonOffset), y: floor((topPanelHeight - buttonSize.height) / 2.0)), size: buttonSize) //transition.updateFrame(node: self.rotateButton, frame: middleButtonFrame) diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift index 2182bc581b..d9e2e886ad 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryController.swift @@ -153,7 +153,7 @@ private func updatedFileWallpaper(id: Int64? = nil, accessHash: Int64? = nil, sl intensityValue = 50 } - return .file(id: id ?? 0, accessHash: accessHash ?? 0, isCreator: false, isDefault: false, isPattern: isPattern, isDark: false, slug: slug, file: file, settings: WallpaperSettings(colors: colorValues, intensity: intensityValue, rotation: rotation)) + return .file(TelegramWallpaper.File(id: id ?? 0, accessHash: accessHash ?? 0, isCreator: false, isDefault: false, isPattern: isPattern, isDark: false, slug: slug, file: file, settings: WallpaperSettings(colors: colorValues, intensity: intensityValue, rotation: rotation))) } public class WallpaperGalleryController: ViewController { @@ -400,8 +400,8 @@ public class WallpaperGalleryController: ViewController { var doneButtonType: WallpaperGalleryToolbarDoneButtonType = .set switch self.source { - case let .wallpaper(wallpaper): - switch wallpaper.0 { + case let .wallpaper(wallpaper, _, _, _, _, _): + switch wallpaper { case let .file(file): if file.id == 0 { doneButtonType = .none @@ -426,7 +426,6 @@ public class WallpaperGalleryController: ViewController { dismissed = true if let centralItemNode = strongSelf.galleryNode.pager.centralItemNode() as? WallpaperGalleryItemNode { let options = centralItemNode.options - let gradientColors = centralItemNode.colors if !strongSelf.entries.isEmpty { let entry = strongSelf.entries[centralItemNode.index] switch entry { @@ -514,7 +513,7 @@ public class WallpaperGalleryController: ViewController { } } } else if case let .file(file) = wallpaper, let resource = resource { - if wallpaper.isPattern, !file.settings.colors.isEmpty, let intensity = file.settings.intensity { + if wallpaper.isPattern, !file.settings.colors.isEmpty, let _ = file.settings.intensity { var data: Data? var thumbnailData: Data? if let path = strongSelf.context.account.postbox.mediaBox.completedResourcePath(resource), let maybeData = try? Data(contentsOf: URL(fileURLWithPath: path), options: .mappedRead) { @@ -633,8 +632,8 @@ public class WallpaperGalleryController: ViewController { switch initialWallpaper { case let .color(color): strongSelf.patternPanelNode?.backgroundColors = ([color], nil, nil) - case let .gradient(_, colors, settings): - strongSelf.patternPanelNode?.backgroundColors = (colors, settings.rotation, nil) + case let .gradient(gradient): + strongSelf.patternPanelNode?.backgroundColors = (gradient.colors, gradient.settings.rotation, nil) case let .file(file) where file.isPattern: strongSelf.patternPanelNode?.backgroundColors = (file.settings.colors, file.settings.rotation, file.settings.intensity) default: @@ -653,7 +652,7 @@ public class WallpaperGalleryController: ViewController { case let .file(file): if !file.settings.colors.isEmpty { if file.settings.colors.count >= 2 { - strongSelf.updateEntries(wallpaper: .gradient(nil, file.settings.colors, WallpaperSettings(rotation: file.settings.rotation))) + strongSelf.updateEntries(wallpaper: .gradient(TelegramWallpaper.Gradient(id: nil, colors: file.settings.colors, settings: WallpaperSettings(rotation: file.settings.rotation)))) } else { strongSelf.updateEntries(wallpaper: .color(file.settings.colors[0])) } @@ -703,16 +702,6 @@ public class WallpaperGalleryController: ViewController { settings.rotation = angle strongSelf.updateEntries(wallpaper: wallpaper.withUpdatedSettings(settings)) } - - if let entry = self.currentEntry(), case let .wallpaper(wallpaper, _) = entry, case let .file(_, _, _, _, true, _, _, _ , settings) = wallpaper, !settings.colors.isEmpty { - /*if self.patternPanelNode?.backgroundColors != nil, let snapshotView = self.patternPanelNode?.scrollNode.view.snapshotContentTree() { - self.patternPanelNode?.view.addSubview(snapshotView) - snapshotView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3, removeOnCompletion: false) { [weak snapshotView] _ in - snapshotView?.removeFromSuperview() - } - }*/ - //self.patternPanelNode?.backgroundColors = ([settings.colors[0]], nil) - } if updated { if self.colorsPanelEnabled || self.patternPanelEnabled { @@ -788,22 +777,22 @@ public class WallpaperGalleryController: ViewController { entryColors = [color] } else if case let .file(file) = wallpaper, file.isPattern { entryColors = file.settings.colors - } else if case let .gradient(_, colors, _) = wallpaper { - entryColors = colors + } else if case let .gradient(gradient) = wallpaper { + entryColors = gradient.colors } } if !entryColors.isEmpty { if let pattern = pattern, case let .file(file) = pattern { let newSettings = WallpaperSettings(blur: file.settings.blur, motion: file.settings.motion, colors: entryColors, intensity: intensity) - let newWallpaper = TelegramWallpaper.file(id: file.id, accessHash: file.accessHash, isCreator: file.isCreator, isDefault: file.isDefault, isPattern: pattern.isPattern, isDark: file.isDark, slug: file.slug, file: file.file, settings: newSettings) + let newWallpaper = TelegramWallpaper.file(TelegramWallpaper.File(id: file.id, accessHash: file.accessHash, isCreator: file.isCreator, isDefault: file.isDefault, isPattern: pattern.isPattern, isDark: file.isDark, slug: file.slug, file: file.file, settings: newSettings)) updatedEntries.append(.wallpaper(newWallpaper, nil)) } else { if entryColors.count == 1 { let newWallpaper = TelegramWallpaper.color(entryColors[0]) updatedEntries.append(.wallpaper(newWallpaper, nil)) } else { - let newWallpaper = TelegramWallpaper.gradient(nil, entryColors, WallpaperSettings(rotation: nil)) + let newWallpaper = TelegramWallpaper.gradient(TelegramWallpaper.Gradient(id: nil, colors: entryColors, settings: WallpaperSettings(rotation: nil))) updatedEntries.append(.wallpaper(newWallpaper, nil)) } } @@ -853,9 +842,9 @@ public class WallpaperGalleryController: ViewController { case let .file(file): colors = file.settings.colors rotation = file.settings.rotation - case let .gradient(_, colorsValue, settings): - colors = colorsValue - rotation = settings.rotation + case let .gradient(gradient): + colors = gradient.colors + rotation = gradient.settings.rotation default: break } @@ -863,7 +852,7 @@ public class WallpaperGalleryController: ViewController { case .color, .file, .gradient: if let pattern = pattern, case let .file(file) = pattern { let newSettings = WallpaperSettings(blur: file.settings.blur, motion: file.settings.motion, colors: colors, intensity: intensity) - let newWallpaper = TelegramWallpaper.file(id: file.id, accessHash: file.accessHash, isCreator: file.isCreator, isDefault: file.isDefault, isPattern: pattern.isPattern, isDark: file.isDark, slug: file.slug, file: file.file, settings: newSettings) + let newWallpaper = TelegramWallpaper.file(TelegramWallpaper.File(id: file.id, accessHash: file.accessHash, isCreator: file.isCreator, isDefault: file.isDefault, isPattern: pattern.isPattern, isDark: file.isDark, slug: file.slug, file: file.file, settings: newSettings)) strongSelf.savedPatternWallpaper = newWallpaper strongSelf.savedPatternIntensity = intensity @@ -899,7 +888,7 @@ public class WallpaperGalleryController: ViewController { return } - var wallpaper: TelegramWallpaper = .gradient(nil, colors, WallpaperSettings(blur: false, motion: false, colors: [], intensity: nil, rotation: nil)) + var wallpaper: TelegramWallpaper = .gradient(TelegramWallpaper.Gradient(id: nil, colors: colors, settings: WallpaperSettings(blur: false, motion: false, colors: [], intensity: nil, rotation: nil))) if case let .file(file) = currentWallpaper { wallpaper = currentWallpaper.withUpdatedSettings(WallpaperSettings(blur: false, motion: false, colors: colors, intensity: file.settings.intensity, rotation: file.settings.rotation)) @@ -983,14 +972,14 @@ public class WallpaperGalleryController: ViewController { self?.present(shareController, in: .window(.root), blockInteraction: true) } }) - case let .file(_, _, _, _, isPattern, _, slug, _, settings): - if isPattern { - if !settings.colors.isEmpty { - if settings.colors.count == 2 { - options.append("bg_color=\(UIColor(rgb: settings.colors[0]).hexString)-\(UIColor(rgb: settings.colors[1]).hexString)") - } else if settings.colors.count >= 3 { + case let .file(file): + if file.isPattern { + if !file.settings.colors.isEmpty { + if file.settings.colors.count == 2 { + options.append("bg_color=\(UIColor(rgb: file.settings.colors[0]).hexString)-\(UIColor(rgb: file.settings.colors[1]).hexString)") + } else if file.settings.colors.count >= 3 { var colorsString = "" - for color in settings.colors { + for color in file.settings.colors { if !colorsString.isEmpty { colorsString.append("~") } @@ -998,13 +987,13 @@ public class WallpaperGalleryController: ViewController { } options.append("bg_color=\(colorsString)") } else { - options.append("bg_color=\(UIColor(rgb: settings.colors[0]).hexString)") + options.append("bg_color=\(UIColor(rgb: file.settings.colors[0]).hexString)") } } - if let intensity = settings.intensity { + if let intensity = file.settings.intensity { options.append("intensity=\(intensity)") } - if let rotation = settings.rotation { + if let rotation = file.settings.rotation { options.append("rotation=\(rotation)") } } @@ -1014,15 +1003,15 @@ public class WallpaperGalleryController: ViewController { optionsString = "?\(options.joined(separator: "&"))" } - controller = ShareController(context: context, subject: .url("https://t.me/bg/\(slug)\(optionsString)")) + controller = ShareController(context: context, subject: .url("https://t.me/bg/\(file.slug)\(optionsString)")) case let .color(color): controller = ShareController(context: context, subject: .url("https://t.me/bg/\(UIColor(rgb: color).hexString)")) - case let .gradient(_, colors, _): + case let .gradient(gradient): var colorsString = "" - for color in colors { + for color in gradient.colors { if !colorsString.isEmpty { - if colors.count >= 3 { + if gradient.colors.count >= 3 { colorsString.append("~") } else { colorsString.append("-") @@ -1031,7 +1020,7 @@ public class WallpaperGalleryController: ViewController { colorsString.append(UIColor(rgb: color).hexString) } - controller = ShareController(context: context, subject:. url("https://t.me/bg/\(colorsString)")) + controller = ShareController(context: context, subject: .url("https://t.me/bg/\(colorsString)")) default: break } diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift index 2d85647375..a2ffa742fa 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperGalleryItem.swift @@ -301,21 +301,21 @@ final class WallpaperGalleryItemNode: GalleryItemNode { case let .wallpaper(wallpaper, _): self.nativeNode.update(wallpaper: wallpaper) - if case let .file(_, _, _, _, isPattern, _, _, _, settings) = wallpaper, isPattern { + if case let .file(file) = wallpaper, file.isPattern { self.nativeNode.isHidden = false - self.patternButtonNode.isSelected = isPattern + self.patternButtonNode.isSelected = file.isPattern - if isPattern && settings.colors.count >= 3 { + if file.isPattern && file.settings.colors.count >= 3 { self.playButtonNode.setImage(self.playButtonPlayImage, for: []) } else { self.playButtonNode.setImage(self.playButtonRotateImage, for: []) } - } else if case let .gradient(_, colors, _) = wallpaper { + } else if case let .gradient(gradient) = wallpaper { self.nativeNode.isHidden = false self.nativeNode.update(wallpaper: wallpaper) self.patternButtonNode.isSelected = false - if colors.count >= 3 { + if gradient.colors.count >= 3 { self.playButtonNode.setImage(self.playButtonPlayImage, for: []) } else { self.playButtonNode.setImage(self.playButtonRotateImage, for: []) @@ -354,7 +354,7 @@ final class WallpaperGalleryItemNode: GalleryItemNode { subtitleSignal = .single(nil) colorSignal = chatServiceBackgroundColor(wallpaper: wallpaper, mediaBox: self.context.account.postbox.mediaBox) isBlurrable = false - case let .color(color): + case .color: displaySize = CGSize(width: 1.0, height: 1.0) contentSize = displaySize signal = .single({ _ in nil }) @@ -364,7 +364,7 @@ final class WallpaperGalleryItemNode: GalleryItemNode { actionSignal = .single(defaultAction) colorSignal = chatServiceBackgroundColor(wallpaper: wallpaper, mediaBox: self.context.account.postbox.mediaBox) isBlurrable = false - case let .gradient(_, colors, settings): + case .gradient: displaySize = CGSize(width: 1.0, height: 1.0) contentSize = displaySize signal = .single({ _ in nil }) @@ -776,18 +776,18 @@ final class WallpaperGalleryItemNode: GalleryItemNode { switch entry { case let .wallpaper(wallpaper, _): switch wallpaper { - case let .file(_, _, _, _, isPattern, _, _, _, settings): - if isPattern { - if settings.colors.isEmpty { + case let .file(file): + if file.isPattern { + if file.settings.colors.isEmpty { return nil } else { - return settings.colors.map(UIColor.init(rgb:)) + return file.settings.colors.map(UIColor.init(rgb:)) } } else { return nil } - case let .gradient(_, colors, _): - return colors.map(UIColor.init(rgb:)) + case let .gradient(gradient): + return gradient.colors.map(UIColor.init(rgb:)) case let .color(color): return [UIColor(rgb: color)] default: @@ -810,11 +810,11 @@ final class WallpaperGalleryItemNode: GalleryItemNode { return } switch wallpaper { - case let .gradient(_, colors, settings): - if colors.count >= 3 { + case let .gradient(gradient): + if gradient.colors.count >= 3 { self.nativeNode.animateEvent(transition: .animated(duration: 0.5, curve: .spring)) } else { - let rotation = settings.rotation ?? 0 + let rotation = gradient.settings.rotation ?? 0 self.requestRotateGradient?((rotation + 90) % 360) } case let .file(file): @@ -952,11 +952,11 @@ final class WallpaperGalleryItemNode: GalleryItemNode { blurFrame = leftButtonFrame motionAlpha = 1.0 motionFrame = rightButtonFrame - case let .gradient(_, colors, _): + case let .gradient(gradient): motionAlpha = 0.0 patternAlpha = 1.0 - if colors.count >= 2 { + if gradient.colors.count >= 2 { playAlpha = 1.0 patternFrame = leftButtonFrame.offsetBy(dx: -centerOffset, dy: 0.0) colorsFrame = colorsFrame.offsetBy(dx: centerOffset, dy: 0.0) @@ -1022,7 +1022,7 @@ final class WallpaperGalleryItemNode: GalleryItemNode { } private func updateMessagesLayout(layout: ContainerViewLayout, offset: CGPoint, transition: ContainedViewLayoutTransition) { - var bottomInset: CGFloat = 115.0 + let bottomInset: CGFloat = 115.0 if self.patternButtonNode.isSelected || self.colorsButtonNode.isSelected { //bottomInset = 350.0 @@ -1055,8 +1055,8 @@ final class WallpaperGalleryItemNode: GalleryItemNode { if file.settings.colors.count >= 3 { hasAnimatableGradient = true } - case let .gradient(_, colors, _): - if colors.count >= 3 { + case let .gradient(gradient): + if gradient.colors.count >= 3 { hasAnimatableGradient = true } default: @@ -1077,8 +1077,8 @@ final class WallpaperGalleryItemNode: GalleryItemNode { if file.settings.colors.count >= 3 { hasAnimatableGradient = true } - case let .gradient(_, colors, _): - if colors.count >= 3 { + case let .gradient(gradient): + if gradient.colors.count >= 3 { hasAnimatableGradient = true } default: diff --git a/submodules/SettingsUI/Sources/Themes/WallpaperPatternPanelNode.swift b/submodules/SettingsUI/Sources/Themes/WallpaperPatternPanelNode.swift index b9027cbba3..40ef3d92ad 100644 --- a/submodules/SettingsUI/Sources/Themes/WallpaperPatternPanelNode.swift +++ b/submodules/SettingsUI/Sources/Themes/WallpaperPatternPanelNode.swift @@ -142,19 +142,7 @@ private final class WallpaperPatternItemNode : ListViewItemNode { } func asyncLayout() -> (WallpaperPatternItem, ListViewItemLayoutParams) -> (ListViewItemNodeLayout, (Bool) -> Void) { - let currentItem = self.item - return { [weak self] item, params in - var updatedWallpaper = false - var updatedSelected = false - - if currentItem?.wallpaper != item.wallpaper { - updatedWallpaper = true - } - if currentItem?.selected != item.selected { - updatedSelected = true - } - let itemLayout = ListViewItemNodeLayout(contentSize: CGSize(width: 112.0, height: 112.0), insets: UIEdgeInsets()) return (itemLayout, { animated in if let strongSelf = self { @@ -365,7 +353,7 @@ final class WallpaperPatternPanelNode: ASDisplayNode { var updatedWallpaper = wallpaper if case let .file(file) = updatedWallpaper { let settings = WallpaperSettings(colors: backgroundColors.0, intensity: intensity, rotation: backgroundColors.1) - updatedWallpaper = .file(id: file.id, accessHash: file.accessHash, isCreator: file.isCreator, isDefault: file.isDefault, isPattern: updatedWallpaper.isPattern, isDark: file.isDark, slug: file.slug, file: file.file, settings: settings) + updatedWallpaper = .file(TelegramWallpaper.File(id: file.id, accessHash: file.accessHash, isCreator: file.isCreator, isDefault: file.isDefault, isPattern: updatedWallpaper.isPattern, isDark: file.isDark, slug: file.slug, file: file.file, settings: settings)) } var selected = false @@ -432,8 +420,9 @@ final class WallpaperPatternPanelNode: ASDisplayNode { let wallpaper: TelegramWallpaper? switch initialWallpaper { - case let .file(id, accessHash, isCreator, isDefault, isPattern, isDark, slug, file, _): - wallpaper = .file(id: id, accessHash: accessHash, isCreator: isCreator, isDefault: isDefault, isPattern: isPattern, isDark: isDark, slug: slug, file: file, settings: self.wallpapers[0].settings ?? WallpaperSettings()) + case var .file(file): + file.settings = self.wallpapers[0].settings ?? WallpaperSettings() + wallpaper = .file(file) default: wallpaper = self.wallpapers.first } @@ -503,9 +492,9 @@ final class WallpaperPatternPanelNode: ASDisplayNode { transition.updateFrame(node: self.scrollNode, frame: scrollViewFrame) let labelSize = self.labelNode.updateLayout(self.bounds.size) - var combinedHeight = labelSize.height + 34.0 + let combinedHeight = labelSize.height + 34.0 - var originY: CGFloat = scrollViewFrame.maxY + floor((size.height - scrollViewFrame.maxY - combinedHeight) / 2.0) + let originY: CGFloat = scrollViewFrame.maxY + floor((size.height - scrollViewFrame.maxY - combinedHeight) / 2.0) transition.updateFrame(node: self.labelNode, frame: CGRect(origin: CGPoint(x: 14.0, y: originY), size: labelSize)) self.sliderView?.frame = CGRect(origin: CGPoint(x: 15.0, y: originY + 8.0), size: CGSize(width: size.width - 15.0 * 2.0, height: 44.0)) diff --git a/submodules/SettingsUI/Sources/UsernameSetupController.swift b/submodules/SettingsUI/Sources/UsernameSetupController.swift index 7deddbc21e..11a86a6b54 100644 --- a/submodules/SettingsUI/Sources/UsernameSetupController.swift +++ b/submodules/SettingsUI/Sources/UsernameSetupController.swift @@ -94,12 +94,12 @@ private enum UsernameSetupEntry: ItemListNodeEntry { func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem { let arguments = arguments as! UsernameSetupControllerArguments switch self { - case let .editablePublicLink(theme, strings, prefix, currentText, text): + case let .editablePublicLink(theme, _, prefix, currentText, text): return ItemListSingleLineInputItem(presentationData: presentationData, title: NSAttributedString(string: prefix, textColor: theme.list.itemPrimaryTextColor), text: text, placeholder: "", type: .username, spacing: 10.0, clearType: .always, tag: UsernameEntryTag.username, sectionId: self.section, textUpdated: { updatedText in arguments.updatePublicLinkText(currentText, updatedText) }, action: { }) - case let .publicLinkInfo(theme, text): + case let .publicLinkInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .markdown(text), sectionId: self.section, linkAction: { action in if case .tap = action { arguments.shareLink() diff --git a/submodules/SettingsUI/Sources/Watch/WatchSettingsController.swift b/submodules/SettingsUI/Sources/Watch/WatchSettingsController.swift index 6327a204fe..3584a1b00d 100644 --- a/submodules/SettingsUI/Sources/Watch/WatchSettingsController.swift +++ b/submodules/SettingsUI/Sources/Watch/WatchSettingsController.swift @@ -77,13 +77,13 @@ private enum WatchSettingsControllerEntry: ItemListNodeEntry { func item(presentationData: ItemListPresentationData, arguments: Any) -> ListViewItem { let arguments = arguments as! WatchSettingsControllerArguments switch self { - case let .replyPresetsHeader(theme, text): + case let .replyPresetsHeader(_, text): return ItemListSectionHeaderItem(presentationData: presentationData, text: text, sectionId: self.section) - case let .replyPreset(theme, strings, identifier, placeholder, value, _): + case let .replyPreset(_, _, identifier, placeholder, value, _): return ItemListSingleLineInputItem(presentationData: presentationData, title: NSAttributedString(string: ""), text: value, placeholder: placeholder, type: .regular(capitalization: true, autocorrection: true), spacing: 0.0, sectionId: self.section, textUpdated: { updatedText in arguments.updatePreset(identifier, updatedText.trimmingCharacters(in: .whitespacesAndNewlines)) }, action: {}) - case let .replyPresetsInfo(theme, text): + case let .replyPresetsInfo(_, text): return ItemListTextItem(presentationData: presentationData, text: .plain(text), sectionId: self.section) } } @@ -113,9 +113,6 @@ private func watchSettingsControllerEntries(presentationData: PresentationData, } public func watchSettingsController(context: AccountContext) -> ViewController { - var pushControllerImpl: ((ViewController) -> Void)? - var presentControllerImpl: ((ViewController) -> Void)? - let updateDisposable = MetaDisposable() let arguments = WatchSettingsControllerArguments(updatePreset: { identifier, text in updateDisposable.set((.complete() |> delay(1.0, queue: Queue.mainQueue()) |> then(updateWatchPresetSettingsInteractively(accountManager: context.sharedContext.accountManager, { current in @@ -141,12 +138,6 @@ public func watchSettingsController(context: AccountContext) -> ViewController { } let controller = ItemListController(context: context, state: signal) - pushControllerImpl = { [weak controller] c in - (controller?.navigationController as? NavigationController)?.pushViewController(c) - } - presentControllerImpl = { [weak controller] c in - controller?.present(c, in: .window(.root)) - } return controller } diff --git a/submodules/TelegramCore/Sources/ApiUtils/Wallpaper.swift b/submodules/TelegramCore/Sources/ApiUtils/Wallpaper.swift index d535d5fd15..91badb59b0 100644 --- a/submodules/TelegramCore/Sources/ApiUtils/Wallpaper.swift +++ b/submodules/TelegramCore/Sources/ApiUtils/Wallpaper.swift @@ -71,7 +71,7 @@ extension TelegramWallpaper { } else { wallpaperSettings = WallpaperSettings() } - self = .file(id: id, accessHash: accessHash, isCreator: (flags & 1 << 0) != 0, isDefault: (flags & 1 << 1) != 0, isPattern: (flags & 1 << 3) != 0, isDark: (flags & 1 << 4) != 0, slug: slug, file: file, settings: wallpaperSettings) + self = .file(TelegramWallpaper.File(id: id, accessHash: accessHash, isCreator: (flags & 1 << 0) != 0, isDefault: (flags & 1 << 1) != 0, isPattern: (flags & 1 << 3) != 0, isDark: (flags & 1 << 4) != 0, slug: slug, file: file, settings: wallpaperSettings)) } else { //assertionFailure() self = .color(0xffffff) @@ -82,7 +82,7 @@ extension TelegramWallpaper { return color.flatMap(UInt32.init(bitPattern:)) }) if colors.count > 1 { - self = .gradient(id, colors, WallpaperSettings(rotation: rotation)) + self = .gradient(TelegramWallpaper.Gradient(id: id, colors: colors, settings: WallpaperSettings(rotation: rotation))) } else if colors.count == 1 { self = .color(UInt32(bitPattern: colors[0])) } else { @@ -99,12 +99,12 @@ extension TelegramWallpaper { switch self { case .builtin: return nil - case let .file(_, _, _, _, _, _, slug, _, settings): - return (.inputWallPaperSlug(slug: slug), apiWallpaperSettings(settings)) + case let .file(file): + return (.inputWallPaperSlug(slug: file.slug), apiWallpaperSettings(file.settings)) case let .color(color): return (.inputWallPaperNoFile(id: 0), apiWallpaperSettings(WallpaperSettings(colors: [color]))) - case let .gradient(id, colors, settings): - return (.inputWallPaperNoFile(id: id ?? 0), apiWallpaperSettings(WallpaperSettings(colors: colors, rotation: settings.rotation))) + case let .gradient(gradient): + return (.inputWallPaperNoFile(id: gradient.id ?? 0), apiWallpaperSettings(WallpaperSettings(colors: gradient.colors, rotation: gradient.settings.rotation))) default: return nil } diff --git a/submodules/TelegramCore/Sources/Network/FetchedMediaResource.swift b/submodules/TelegramCore/Sources/Network/FetchedMediaResource.swift index 22dd00e4a1..08bbca5c45 100644 --- a/submodules/TelegramCore/Sources/Network/FetchedMediaResource.swift +++ b/submodules/TelegramCore/Sources/Network/FetchedMediaResource.swift @@ -676,8 +676,8 @@ func revalidateMediaResourceReference(postbox: Postbox, network: Network, revali return .single(RevalidatedMediaResource(updatedResource: representation.resource, updatedReference: nil)) } } - case let .file(_, _, _, _, _, _, _, file, _): - if let updatedResource = findUpdatedMediaResource(media: file, previousMedia: nil, resource: resource) { + case let .file(file): + if let updatedResource = findUpdatedMediaResource(media: file.file, previousMedia: nil, resource: resource) { return .single(RevalidatedMediaResource(updatedResource: updatedResource, updatedReference: nil)) } default: diff --git a/submodules/TelegramCore/Sources/SyncCore/SyncCore_TelegramWallpaper.swift b/submodules/TelegramCore/Sources/SyncCore/SyncCore_TelegramWallpaper.swift index baf2a7aba0..05e7b0224d 100644 --- a/submodules/TelegramCore/Sources/SyncCore/SyncCore_TelegramWallpaper.swift +++ b/submodules/TelegramCore/Sources/SyncCore/SyncCore_TelegramWallpaper.swift @@ -69,11 +69,61 @@ public struct WallpaperSettings: PostboxCoding, Equatable { } public enum TelegramWallpaper: OrderedItemListEntryContents, Equatable { + public struct Gradient: Equatable { + public var id: Int64? + public var colors: [UInt32] + public var settings: WallpaperSettings + + public init( + id: Int64?, + colors: [UInt32], + settings: WallpaperSettings + ) { + self.id = id + self.colors = colors + self.settings = settings + } + } + + public struct File: Equatable { + public var id: Int64 + public var accessHash: Int64 + public var isCreator: Bool + public var isDefault: Bool + public var isPattern: Bool + public var isDark: Bool + public var slug: String + public var file: TelegramMediaFile + public var settings: WallpaperSettings + + public init( + id: Int64, + accessHash: Int64, + isCreator: Bool, + isDefault: Bool, + isPattern: Bool, + isDark: Bool, + slug: String, + file: TelegramMediaFile, + settings: WallpaperSettings + ) { + self.id = id + self.accessHash = accessHash + self.isCreator = isCreator + self.isDefault = isDefault + self.isPattern = isPattern + self.isDark = isDark + self.slug = slug + self.file = file + self.settings = settings + } + } + case builtin(WallpaperSettings) case color(UInt32) - case gradient(Int64?, [UInt32], WallpaperSettings) + case gradient(Gradient) case image([TelegramMediaImageRepresentation], WallpaperSettings) - case file(id: Int64, accessHash: Int64, isCreator: Bool, isDefault: Bool, isPattern: Bool, isDark: Bool, slug: String, file: TelegramMediaFile, settings: WallpaperSettings) + case file(File) public init(decoder: PostboxDecoder) { switch decoder.decodeInt32ForKey("v", orElse: 0) { @@ -88,7 +138,7 @@ public enum TelegramWallpaper: OrderedItemListEntryContents, Equatable { case 3: let settings = decoder.decodeObjectForKey("settings", decoder: { WallpaperSettings(decoder: $0) }) as? WallpaperSettings ?? WallpaperSettings() if let file = decoder.decodeObjectForKey("file", decoder: { TelegramMediaFile(decoder: $0) }) as? TelegramMediaFile { - self = .file(id: decoder.decodeInt64ForKey("id", orElse: 0), accessHash: decoder.decodeInt64ForKey("accessHash", orElse: 0), isCreator: decoder.decodeInt32ForKey("isCreator", orElse: 0) != 0, isDefault: decoder.decodeInt32ForKey("isDefault", orElse: 0) != 0, isPattern: decoder.decodeInt32ForKey("isPattern", orElse: 0) != 0, isDark: decoder.decodeInt32ForKey("isDark", orElse: 0) != 0, slug: decoder.decodeStringForKey("slug", orElse: ""), file: file, settings: settings) + self = .file(File(id: decoder.decodeInt64ForKey("id", orElse: 0), accessHash: decoder.decodeInt64ForKey("accessHash", orElse: 0), isCreator: decoder.decodeInt32ForKey("isCreator", orElse: 0) != 0, isDefault: decoder.decodeInt32ForKey("isDefault", orElse: 0) != 0, isPattern: decoder.decodeInt32ForKey("isPattern", orElse: 0) != 0, isDark: decoder.decodeInt32ForKey("isDark", orElse: 0) != 0, slug: decoder.decodeStringForKey("slug", orElse: ""), file: file, settings: settings)) } else { self = .color(0xffffff) } @@ -106,7 +156,7 @@ public enum TelegramWallpaper: OrderedItemListEntryContents, Equatable { colors = decoder.decodeInt32ArrayForKey("colors").map(UInt32.init(bitPattern:)) } - self = .gradient(decoder.decodeOptionalInt64ForKey("id"), colors, settings) + self = .gradient(Gradient(id: decoder.decodeOptionalInt64ForKey("id"), colors: colors, settings: settings)) default: assertionFailure() self = .color(0xffffff) @@ -130,30 +180,30 @@ public enum TelegramWallpaper: OrderedItemListEntryContents, Equatable { case let .color(color): encoder.encodeInt32(1, forKey: "v") encoder.encodeInt32(Int32(bitPattern: color), forKey: "c") - case let .gradient(id, colors, settings): + case let .gradient(gradient): encoder.encodeInt32(4, forKey: "v") - if let id = id { + if let id = gradient.id { encoder.encodeInt64(id, forKey: "id") } else { encoder.encodeNil(forKey: "id") } - encoder.encodeInt32Array(colors.map(Int32.init(bitPattern:)), forKey: "colors") - encoder.encodeObject(settings, forKey: "settings") + encoder.encodeInt32Array(gradient.colors.map(Int32.init(bitPattern:)), forKey: "colors") + encoder.encodeObject(gradient.settings, forKey: "settings") case let .image(representations, settings): encoder.encodeInt32(2, forKey: "v") encoder.encodeObjectArray(representations, forKey: "i") encoder.encodeObject(settings, forKey: "settings") - case let .file(id, accessHash, isCreator, isDefault, isPattern, isDark, slug, file, settings): + case let .file(file): encoder.encodeInt32(3, forKey: "v") - encoder.encodeInt64(id, forKey: "id") - encoder.encodeInt64(accessHash, forKey: "accessHash") - encoder.encodeInt32(isCreator ? 1 : 0, forKey: "isCreator") - encoder.encodeInt32(isDefault ? 1 : 0, forKey: "isDefault") - encoder.encodeInt32(isPattern ? 1 : 0, forKey: "isPattern") - encoder.encodeInt32(isDark ? 1 : 0, forKey: "isDark") - encoder.encodeString(slug, forKey: "slug") - encoder.encodeObject(file, forKey: "file") - encoder.encodeObject(settings, forKey: "settings") + encoder.encodeInt64(file.id, forKey: "id") + encoder.encodeInt64(file.accessHash, forKey: "accessHash") + encoder.encodeInt32(file.isCreator ? 1 : 0, forKey: "isCreator") + encoder.encodeInt32(file.isDefault ? 1 : 0, forKey: "isDefault") + encoder.encodeInt32(file.isPattern ? 1 : 0, forKey: "isPattern") + encoder.encodeInt32(file.isDark ? 1 : 0, forKey: "isDark") + encoder.encodeString(file.slug, forKey: "slug") + encoder.encodeObject(file.file, forKey: "file") + encoder.encodeObject(file.settings, forKey: "settings") } } @@ -171,8 +221,8 @@ public enum TelegramWallpaper: OrderedItemListEntryContents, Equatable { } else { return false } - case let .gradient(id, colors, settings): - if case .gradient(id, colors, settings) = rhs { + case let .gradient(gradient): + if case .gradient(gradient) = rhs { return true } else { return false @@ -183,8 +233,8 @@ public enum TelegramWallpaper: OrderedItemListEntryContents, Equatable { } else { return false } - case let .file(lhsId, _, lhsIsCreator, lhsIsDefault, lhsIsPattern, lhsIsDark, lhsSlug, lhsFile, lhsSettings): - if case let .file(rhsId, _, rhsIsCreator, rhsIsDefault, rhsIsPattern, rhsIsDark, rhsSlug, rhsFile, rhsSettings) = rhs, lhsId == rhsId, lhsIsCreator == rhsIsCreator, lhsIsDefault == rhsIsDefault, lhsIsPattern == rhsIsPattern, lhsIsDark == rhsIsDark, lhsSlug == rhsSlug, lhsFile.id == rhsFile.id, lhsSettings == rhsSettings { + case let .file(file): + if case .file(file) = rhs { return true } else { return false @@ -206,8 +256,8 @@ public enum TelegramWallpaper: OrderedItemListEntryContents, Equatable { } else { return false } - case let .gradient(_, colors, _): - if case .gradient(_, colors, _) = wallpaper { + case let .gradient(lhsGradient): + if case let .gradient(rhsGradient) = wallpaper, lhsGradient.colors == rhsGradient.colors { return true } else { return false @@ -218,8 +268,8 @@ public enum TelegramWallpaper: OrderedItemListEntryContents, Equatable { } else { return false } - case let .file(_, _, _, _, _, _, lhsSlug, _, lhsSettings): - if case let .file(_, _, _, _, _, _, rhsSlug, _, rhsSettings) = wallpaper, lhsSlug == rhsSlug, lhsSettings.colors == rhsSettings.colors && lhsSettings.intensity == rhsSettings.intensity { + case let .file(lhsFile): + if case let .file(rhsFile) = wallpaper, lhsFile.slug == rhsFile.slug, lhsFile.settings.colors == rhsFile.settings.colors, lhsFile.settings.intensity == rhsFile.settings.intensity { return true } else { return false @@ -229,25 +279,31 @@ public enum TelegramWallpaper: OrderedItemListEntryContents, Equatable { public var settings: WallpaperSettings? { switch self { - case let .builtin(settings), let .gradient(_, _, settings), let .image(_, settings), let .file(_, _, _, _, _, _, _, _, settings): - return settings - default: - return nil + case let .builtin(settings), let .image(_, settings): + return settings + case let .file(file): + return file.settings + case let .gradient(gradient): + return gradient.settings + default: + return nil } } public func withUpdatedSettings(_ settings: WallpaperSettings) -> TelegramWallpaper { switch self { - case .builtin: - return .builtin(settings) - case .color: - return self - case let .gradient(id, colors, _): - return .gradient(id, colors, settings) - case let .image(representations, _): - return .image(representations, settings) - case let .file(id, accessHash, isCreator, isDefault, isPattern, isDark, slug, file, _): - return .file(id: id, accessHash: accessHash, isCreator: isCreator, isDefault: isDefault, isPattern: isPattern, isDark: isDark, slug: slug, file: file, settings: settings) + case .builtin: + return .builtin(settings) + case .color: + return self + case var .gradient(gradient): + gradient.settings = settings + return .gradient(gradient) + case let .image(representations, _): + return .image(representations, settings) + case var .file(file): + file.settings = settings + return .file(file) } } } diff --git a/submodules/TelegramCore/Sources/Wallpapers.swift b/submodules/TelegramCore/Sources/Wallpapers.swift index eab0ab7c11..56c724eadc 100644 --- a/submodules/TelegramCore/Sources/Wallpapers.swift +++ b/submodules/TelegramCore/Sources/Wallpapers.swift @@ -148,10 +148,10 @@ public func deleteWallpaper(account: Account, wallpaper: TelegramWallpaper) -> S } private func saveUnsaveWallpaper(account: Account, wallpaper: TelegramWallpaper, unsave: Bool) -> Signal { - guard case let .file(_, _, _, _, _, _, slug, _, settings) = wallpaper else { + guard case let .file(file) = wallpaper else { return .complete() } - return account.network.request(Api.functions.account.saveWallPaper(wallpaper: Api.InputWallPaper.inputWallPaperSlug(slug: slug), unsave: unsave ? Api.Bool.boolTrue : Api.Bool.boolFalse, settings: apiWallpaperSettings(settings))) + return account.network.request(Api.functions.account.saveWallPaper(wallpaper: Api.InputWallPaper.inputWallPaperSlug(slug: file.slug), unsave: unsave ? Api.Bool.boolTrue : Api.Bool.boolFalse, settings: apiWallpaperSettings(file.settings))) |> `catch` { _ -> Signal in return .complete() } @@ -161,16 +161,16 @@ private func saveUnsaveWallpaper(account: Account, wallpaper: TelegramWallpaper, } public func installWallpaper(account: Account, wallpaper: TelegramWallpaper) -> Signal { - guard case let .file(id, accessHash, _, _, _, _, slug, _, settings) = wallpaper else { + guard case let .file(file) = wallpaper else { return .complete() } let inputWallpaper: Api.InputWallPaper - if id != 0 && accessHash != 0 { - inputWallpaper = .inputWallPaper(id: id, accessHash: accessHash) + if file.id != 0 && file.accessHash != 0 { + inputWallpaper = .inputWallPaper(id: file.id, accessHash: file.accessHash) } else { - inputWallpaper = .inputWallPaperSlug(slug: slug) + inputWallpaper = .inputWallPaperSlug(slug: file.slug) } - return account.network.request(Api.functions.account.installWallPaper(wallpaper: inputWallpaper, settings: apiWallpaperSettings(settings))) + return account.network.request(Api.functions.account.installWallPaper(wallpaper: inputWallpaper, settings: apiWallpaperSettings(file.settings))) |> `catch` { _ -> Signal in return .complete() } diff --git a/submodules/TelegramPresentationData/Sources/ChatControllerBackgroundNode.swift b/submodules/TelegramPresentationData/Sources/ChatControllerBackgroundNode.swift index 7f339b778f..f8fc943be9 100644 --- a/submodules/TelegramPresentationData/Sources/ChatControllerBackgroundNode.swift +++ b/submodules/TelegramPresentationData/Sources/ChatControllerBackgroundNode.swift @@ -42,19 +42,19 @@ public func chatControllerBackgroundImage(theme: PresentationTheme?, wallpaper i context.setFillColor(UIColor(argb: color).withAlphaComponent(1.0).cgColor) context.fill(CGRect(origin: CGPoint(), size: size)) }) - case let .gradient(_, colors, settings): + case let .gradient(gradient): backgroundImage = generateImage(CGSize(width: 640.0, height: 1280.0), rotatedContext: { size, context in - let gradientColors = [UIColor(argb: colors.count >= 1 ? colors[0] : 0).cgColor, UIColor(argb: colors.count >= 2 ? colors[1] : 0).cgColor] as CFArray + let gradientColors = [UIColor(argb: gradient.colors.count >= 1 ? gradient.colors[0] : 0).cgColor, UIColor(argb: gradient.colors.count >= 2 ? gradient.colors[1] : 0).cgColor] as CFArray var locations: [CGFloat] = [0.0, 1.0] let colorSpace = CGColorSpaceCreateDeviceRGB() - let gradient = CGGradient(colorsSpace: colorSpace, colors: gradientColors, locations: &locations)! + let cgGradient = CGGradient(colorsSpace: colorSpace, colors: gradientColors, locations: &locations)! context.translateBy(x: 320.0, y: 640.0) - context.rotate(by: CGFloat(settings.rotation ?? 0) * CGFloat.pi / 180.0) + context.rotate(by: CGFloat(gradient.settings.rotation ?? 0) * CGFloat.pi / 180.0) context.translateBy(x: -320.0, y: -640.0) - context.drawLinearGradient(gradient, start: CGPoint(x: 0.0, y: 0.0), end: CGPoint(x: 0.0, y: size.height), options: [.drawsBeforeStartLocation, .drawsAfterEndLocation]) + context.drawLinearGradient(cgGradient, start: CGPoint(x: 0.0, y: 0.0), end: CGPoint(x: 0.0, y: size.height), options: [.drawsBeforeStartLocation, .drawsAfterEndLocation]) }) case let .image(representations, settings): if let largest = largestImageRepresentation(representations) { @@ -72,20 +72,20 @@ public func chatControllerBackgroundImage(theme: PresentationTheme?, wallpaper i backgroundImage = UIImage(contentsOfFile: path)?.precomposed() } } - case let .file(_, _, _, _, _, _, _, file, settings): + case let .file(file): if wallpaper.isPattern { backgroundImage = nil } else { - if settings.blur && composed { + if file.settings.blur && composed { var image: UIImage? - let _ = mediaBox.cachedResourceRepresentation(file.resource, representation: CachedBlurredWallpaperRepresentation(), complete: true, fetch: true, attemptSynchronously: true).start(next: { data in + let _ = mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedBlurredWallpaperRepresentation(), complete: true, fetch: true, attemptSynchronously: true).start(next: { data in if data.complete { image = UIImage(contentsOfFile: data.path)?.precomposed() } }) backgroundImage = image } - if backgroundImage == nil, let path = mediaBox.completedResourcePath(file.resource) { + if backgroundImage == nil, let path = mediaBox.completedResourcePath(file.file.resource) { succeed = false backgroundImage = UIImage(contentsOfFile: path)?.precomposed() } @@ -128,19 +128,19 @@ public func chatControllerBackgroundImageSignal(wallpaper: TelegramWallpaper, me |> afterNext { image in cacheWallpaper(image?.0) } - case let .gradient(_, colors, settings): + case let .gradient(gradient): return .single((generateImage(CGSize(width: 640.0, height: 1280.0).fitted(CGSize(width: 100.0, height: 100.0)), rotatedContext: { size, context in - let gradientColors = [UIColor(rgb: colors.count >= 1 ? colors[0] : 0).cgColor, UIColor(rgb: colors.count >= 2 ? colors[1] : 0).cgColor] as CFArray + let gradientColors = [UIColor(rgb: gradient.colors.count >= 1 ? gradient.colors[0] : 0).cgColor, UIColor(rgb: gradient.colors.count >= 2 ? gradient.colors[1] : 0).cgColor] as CFArray var locations: [CGFloat] = [0.0, 1.0] let colorSpace = CGColorSpaceCreateDeviceRGB() - let gradient = CGGradient(colorsSpace: colorSpace, colors: gradientColors, locations: &locations)! + let cgGradient = CGGradient(colorsSpace: colorSpace, colors: gradientColors, locations: &locations)! context.translateBy(x: size.width / 2.0, y: size.height / 2.0) - context.rotate(by: CGFloat(settings.rotation ?? 0) * CGFloat.pi / 180.0) + context.rotate(by: CGFloat(gradient.settings.rotation ?? 0) * CGFloat.pi / 180.0) context.translateBy(x: -size.width / 2.0, y: -size.height / 2.0) - context.drawLinearGradient(gradient, start: CGPoint(x: 0.0, y: 0.0), end: CGPoint(x: 0.0, y: size.height), options: [.drawsBeforeStartLocation, .drawsAfterEndLocation]) + context.drawLinearGradient(cgGradient, start: CGPoint(x: 0.0, y: 0.0), end: CGPoint(x: 0.0, y: size.height), options: [.drawsBeforeStartLocation, .drawsAfterEndLocation]) }), true)) |> afterNext { image in cacheWallpaper(image?.0) @@ -166,17 +166,17 @@ public func chatControllerBackgroundImageSignal(wallpaper: TelegramWallpaper, me } } } - case let .file(_, _, _, _, _, _, slug, file, settings): + case let .file(file): if wallpaper.isPattern { return .single((nil, true)) } else { - if settings.blur { + if file.settings.blur { let representation = CachedBlurredWallpaperRepresentation() - if FileManager.default.fileExists(atPath: mediaBox.cachedRepresentationCompletePath(file.resource.id, representation: representation)) { + if FileManager.default.fileExists(atPath: mediaBox.cachedRepresentationCompletePath(file.file.resource.id, representation: representation)) { let effectiveMediaBox = mediaBox - return effectiveMediaBox.cachedResourceRepresentation(file.resource, representation: representation, complete: true, fetch: true, attemptSynchronously: true) + return effectiveMediaBox.cachedResourceRepresentation(file.file.resource, representation: representation, complete: true, fetch: true, attemptSynchronously: true) |> map { data -> (UIImage?, Bool)? in if data.complete { return (UIImage(contentsOfFile: data.path)?.precomposed(), true) @@ -189,17 +189,17 @@ public func chatControllerBackgroundImageSignal(wallpaper: TelegramWallpaper, me } } else { return Signal { subscriber in - let fetch = fetchedMediaResource(mediaBox: accountMediaBox, reference: MediaResourceReference.wallpaper(wallpaper: WallpaperReference.slug(slug), resource: file.resource)).start() + let fetch = fetchedMediaResource(mediaBox: accountMediaBox, reference: MediaResourceReference.wallpaper(wallpaper: WallpaperReference.slug(file.slug), resource: file.file.resource)).start() var didOutputBlurred = false - let data = accountMediaBox.cachedResourceRepresentation(file.resource, representation: representation, complete: true, fetch: true, attemptSynchronously: true).start(next: { data in + let data = accountMediaBox.cachedResourceRepresentation(file.file.resource, representation: representation, complete: true, fetch: true, attemptSynchronously: true).start(next: { data in if data.complete { if let image = UIImage(contentsOfFile: data.path)?.precomposed() { - mediaBox.copyResourceData(file.resource.id, fromTempPath: data.path) + mediaBox.copyResourceData(file.file.resource.id, fromTempPath: data.path) subscriber.putNext((image, true)) } } else if !didOutputBlurred { didOutputBlurred = true - if let immediateThumbnailData = file.immediateThumbnailData, let decodedData = decodeTinyThumbnail(data: immediateThumbnailData) { + if let immediateThumbnailData = file.file.immediateThumbnailData, let decodedData = decodeTinyThumbnail(data: immediateThumbnailData) { if let image = UIImage(data: decodedData)?.precomposed() { subscriber.putNext((image, false)) } @@ -215,9 +215,9 @@ public func chatControllerBackgroundImageSignal(wallpaper: TelegramWallpaper, me } } else { var path: String? - if let maybePath = mediaBox.completedResourcePath(file.resource) { + if let maybePath = mediaBox.completedResourcePath(file.file.resource) { path = maybePath - } else if let maybePath = accountMediaBox.completedResourcePath(file.resource) { + } else if let maybePath = accountMediaBox.completedResourcePath(file.file.resource) { path = maybePath } if let path = path { @@ -227,17 +227,17 @@ public func chatControllerBackgroundImageSignal(wallpaper: TelegramWallpaper, me } } else { return Signal { subscriber in - let fetch = fetchedMediaResource(mediaBox: accountMediaBox, reference: MediaResourceReference.wallpaper(wallpaper: WallpaperReference.slug(slug), resource: file.resource)).start() + let fetch = fetchedMediaResource(mediaBox: accountMediaBox, reference: MediaResourceReference.wallpaper(wallpaper: WallpaperReference.slug(file.slug), resource: file.file.resource)).start() var didOutputBlurred = false - let data = accountMediaBox.resourceData(file.resource).start(next: { data in + let data = accountMediaBox.resourceData(file.file.resource).start(next: { data in if data.complete { if let image = UIImage(contentsOfFile: data.path)?.precomposed() { - mediaBox.copyResourceData(file.resource.id, fromTempPath: data.path) + mediaBox.copyResourceData(file.file.resource.id, fromTempPath: data.path) subscriber.putNext((image, true)) } } else if !didOutputBlurred { didOutputBlurred = true - if let immediateThumbnailData = file.immediateThumbnailData, let decodedData = decodeTinyThumbnail(data: immediateThumbnailData) { + if let immediateThumbnailData = file.file.immediateThumbnailData, let decodedData = decodeTinyThumbnail(data: immediateThumbnailData) { if let image = UIImage(data: decodedData)?.precomposed() { subscriber.putNext((image, false)) } diff --git a/submodules/TelegramPresentationData/Sources/DefaultDarkPresentationTheme.swift b/submodules/TelegramPresentationData/Sources/DefaultDarkPresentationTheme.swift index cca43e6c1b..f1ced61ca5 100644 --- a/submodules/TelegramPresentationData/Sources/DefaultDarkPresentationTheme.swift +++ b/submodules/TelegramPresentationData/Sources/DefaultDarkPresentationTheme.swift @@ -132,7 +132,7 @@ public func customizeDefaultDarkPresentationTheme(theme: PresentationTheme, edit defaultWallpaper = defaultBuiltinWallpaper(data: variant, colors: colors, intensity: intensity) } else if !backgroundColors.isEmpty { if backgroundColors.count >= 2 { - defaultWallpaper = .gradient(nil, backgroundColors, WallpaperSettings()) + defaultWallpaper = .gradient(TelegramWallpaper.Gradient(id: nil, colors: backgroundColors, settings: WallpaperSettings())) } else { defaultWallpaper = .color(backgroundColors[0]) } diff --git a/submodules/TelegramPresentationData/Sources/DefaultDarkTintedPresentationTheme.swift b/submodules/TelegramPresentationData/Sources/DefaultDarkTintedPresentationTheme.swift index 7ded181b4b..23341096d1 100644 --- a/submodules/TelegramPresentationData/Sources/DefaultDarkTintedPresentationTheme.swift +++ b/submodules/TelegramPresentationData/Sources/DefaultDarkTintedPresentationTheme.swift @@ -260,7 +260,7 @@ public func customizeDefaultDarkTintedPresentationTheme(theme: PresentationTheme defaultWallpaper = forcedWallpaper } else if !backgroundColors.isEmpty { if backgroundColors.count >= 2 { - defaultWallpaper = .gradient(nil, backgroundColors, WallpaperSettings()) + defaultWallpaper = .gradient(TelegramWallpaper.Gradient(id: nil, colors: backgroundColors, settings: WallpaperSettings())) } else { defaultWallpaper = .color(backgroundColors[0]) } diff --git a/submodules/TelegramPresentationData/Sources/DefaultDayPresentationTheme.swift b/submodules/TelegramPresentationData/Sources/DefaultDayPresentationTheme.swift index 0a261f4621..c0adf9e41d 100644 --- a/submodules/TelegramPresentationData/Sources/DefaultDayPresentationTheme.swift +++ b/submodules/TelegramPresentationData/Sources/DefaultDayPresentationTheme.swift @@ -20,8 +20,8 @@ public func dateFillNeedsBlur(theme: PresentationTheme, wallpaper: TelegramWallp return false } else if case .color = wallpaper { return false - } else if case let .file(_, _, _, _, isPattern, _, _, _, settings) = wallpaper { - if isPattern, let intensity = settings.intensity, intensity < 0 { + } else if case let .file(file) = wallpaper { + if file.isPattern, let intensity = file.settings.intensity, intensity < 0 { return false } else { return true @@ -66,10 +66,10 @@ public func customizeDefaultDayTheme(theme: PresentationTheme, editing: Bool, ti outgoingAccent = accentColor } - suggestedWallpaper = .gradient(nil, defaultBuiltinWallpaperGradientColors.map(\.rgb), WallpaperSettings()) + suggestedWallpaper = .gradient(TelegramWallpaper.Gradient(id: nil, colors: defaultBuiltinWallpaperGradientColors.map(\.rgb), settings: WallpaperSettings())) } else { bubbleColors = (UIColor(rgb: 0xe1ffc7), nil) - suggestedWallpaper = .gradient(nil, defaultBuiltinWallpaperGradientColors.map(\.rgb), WallpaperSettings()) + suggestedWallpaper = .gradient(TelegramWallpaper.Gradient(id: nil, colors: defaultBuiltinWallpaperGradientColors.map(\.rgb), settings: WallpaperSettings())) } } } @@ -228,7 +228,7 @@ public func customizeDefaultDayTheme(theme: PresentationTheme, editing: Bool, ti defaultWallpaper = forcedWallpaper } else if !backgroundColors.isEmpty { if backgroundColors.count >= 2 { - defaultWallpaper = .gradient(nil, backgroundColors, WallpaperSettings()) + defaultWallpaper = .gradient(TelegramWallpaper.Gradient(id: nil, colors: backgroundColors, settings: WallpaperSettings())) } else { defaultWallpaper = .color(backgroundColors[0]) } @@ -1013,19 +1013,19 @@ public extension BuiltinWallpaperData { signals.append(getWallpaper(network: account.network, slug: slug) |> map { wallpaper -> String? in switch wallpaper { - case let .file(id, accessHash, _, _, _, _, _, file, _): - guard let resource = file.resource as? CloudDocumentMediaResource else { + case let .file(file): + guard let resource = file.file.resource as? CloudDocumentMediaResource else { return nil } - guard let size = file.size else { + guard let size = file.file.size else { return nil } return """ static let \(name) = BuiltinWallpaperData( - wallpaperId: \(id), - wallpaperAccessHash: \(accessHash), + wallpaperId: \(file.id), + wallpaperAccessHash: \(file.accessHash), slug: "\(slug)", - fileId: \(file.fileId.id), + fileId: \(file.file.fileId.id), fileAccessHash: \(resource.accessHash), datacenterId: \(resource.datacenterId), fileSize: \(size) @@ -1055,7 +1055,7 @@ static let \(name) = BuiltinWallpaperData( } public func defaultBuiltinWallpaper(data: BuiltinWallpaperData, colors: [UInt32], intensity: Int32 = 50, rotation: Int32? = nil) -> TelegramWallpaper { - return .file( + return .file(TelegramWallpaper.File( id: data.wallpaperId, accessHash: data.wallpaperAccessHash, isCreator: false, @@ -1098,5 +1098,5 @@ public func defaultBuiltinWallpaper(data: BuiltinWallpaperData, colors: [UInt32] ] ), settings: WallpaperSettings(colors: colors, intensity: intensity, rotation: rotation) - ) + )) } diff --git a/submodules/TelegramPresentationData/Sources/PresentationData.swift b/submodules/TelegramPresentationData/Sources/PresentationData.swift index 726ddce651..1c84b844d6 100644 --- a/submodules/TelegramPresentationData/Sources/PresentationData.swift +++ b/submodules/TelegramPresentationData/Sources/PresentationData.swift @@ -444,9 +444,9 @@ public func serviceColor(for wallpaper: (TelegramWallpaper, UIImage?)) -> UIColo return UIColor(rgb: 0x748391, alpha: 0.45) case let .color(color): return serviceColor(with: UIColor(argb: color)) - case let .gradient(_, colors, _): - if colors.count == 2 { - let mixedColor = UIColor(argb: colors[0]).mixedWith(UIColor(argb: colors[1]), alpha: 0.5) + case let .gradient(gradient): + if gradient.colors.count == 2 { + let mixedColor = UIColor(argb: gradient.colors[0]).mixedWith(UIColor(argb: gradient.colors[1]), alpha: 0.5) return serviceColor(with: mixedColor) } else { return UIColor(rgb: 0x000000, alpha: 0.3) @@ -457,12 +457,12 @@ public func serviceColor(for wallpaper: (TelegramWallpaper, UIImage?)) -> UIColo } else { return UIColor(rgb: 0x000000, alpha: 0.3) } - case let .file(_, _, _, _, _, _, _, _, settings): + case let .file(file): if wallpaper.0.isPattern { - if settings.colors.count >= 1 && settings.colors.count <= 2 { - var mixedColor = UIColor(argb: settings.colors[0]) - if settings.colors.count >= 2 { - mixedColor = mixedColor.mixedWith(UIColor(argb: settings.colors[1]), alpha: 0.5) + if file.settings.colors.count >= 1 && file.settings.colors.count <= 2 { + var mixedColor = UIColor(argb: file.settings.colors[0]) + if file.settings.colors.count >= 2 { + mixedColor = mixedColor.mixedWith(UIColor(argb: file.settings.colors[1]), alpha: 0.5) } return serviceColor(with: mixedColor) } else { @@ -503,9 +503,9 @@ public func chatServiceBackgroundColor(wallpaper: TelegramWallpaper, mediaBox: M return .single(UIColor(rgb: 0x000000, alpha: 0.2)) case let .color(color): return .single(serviceColor(with: UIColor(argb: color))) - case let .gradient(_, colors, _): - if colors.count == 2 { - let mixedColor = UIColor(argb: colors[0]).mixedWith(UIColor(argb: colors[1]), alpha: 0.5) + case let .gradient(gradient): + if gradient.colors.count == 2 { + let mixedColor = UIColor(argb: gradient.colors[0]).mixedWith(UIColor(argb: gradient.colors[1]), alpha: 0.5) return .single( serviceColor(with: mixedColor)) } else { @@ -531,12 +531,12 @@ public func chatServiceBackgroundColor(wallpaper: TelegramWallpaper, mediaBox: M } else { return .single(UIColor(rgb: 0x000000, alpha: 0.3)) } - case let .file(_, _, _, _, _, _, _, file, settings): + case let .file(file): if wallpaper.isPattern { - if settings.colors.count >= 1 && settings.colors.count <= 2 { - var mixedColor = UIColor(argb: settings.colors[0]) - if settings.colors.count >= 2 { - mixedColor = mixedColor.mixedWith(UIColor(argb: settings.colors[1]), alpha: 0.5) + if file.settings.colors.count >= 1 && file.settings.colors.count <= 2 { + var mixedColor = UIColor(argb: file.settings.colors[0]) + if file.settings.colors.count >= 2 { + mixedColor = mixedColor.mixedWith(UIColor(argb: file.settings.colors[1]), alpha: 0.5) } return .single(serviceColor(with: mixedColor)) } else { @@ -544,7 +544,7 @@ public func chatServiceBackgroundColor(wallpaper: TelegramWallpaper, mediaBox: M } } else { return Signal { subscriber in - let data = serviceColor(for: mediaBox.resourceData(file.resource)).start(next: { next in + let data = serviceColor(for: mediaBox.resourceData(file.file.resource)).start(next: { next in subscriber.putNext(next) }, completed: { subscriber.putCompletion() diff --git a/submodules/TelegramPresentationData/Sources/PresentationThemeCodable.swift b/submodules/TelegramPresentationData/Sources/PresentationThemeCodable.swift index a9a4a31a22..1a04568e4a 100644 --- a/submodules/TelegramPresentationData/Sources/PresentationThemeCodable.swift +++ b/submodules/TelegramPresentationData/Sources/PresentationThemeCodable.swift @@ -64,7 +64,7 @@ extension TelegramWallpaper: Codable { } } - self = .gradient(nil, [topColor.argb, bottomColor.argb], WallpaperSettings(blur: blur, motion: motion, rotation: rotation)) + self = .gradient(TelegramWallpaper.Gradient(id: nil, colors: [topColor.argb, bottomColor.argb], settings: WallpaperSettings(blur: blur, motion: motion, rotation: rotation))) } else { var slug: String? var colors: [UInt32] = [] @@ -98,7 +98,7 @@ extension TelegramWallpaper: Codable { } } if let slug = slug { - self = .file(id: 0, accessHash: 0, isCreator: false, isDefault: false, isPattern: !colors.isEmpty, isDark: false, slug: slug, file: TelegramMediaFile(fileId: MediaId(namespace: 0, id: 0), partialReference: nil, resource: WallpaperDataResource(slug: slug), previewRepresentations: [], videoThumbnails: [], immediateThumbnailData: nil, mimeType: "", size: nil, attributes: []), settings: WallpaperSettings(blur: blur, motion: motion, colors: colors, intensity: intensity, rotation: rotation)) + self = .file(TelegramWallpaper.File(id: 0, accessHash: 0, isCreator: false, isDefault: false, isPattern: !colors.isEmpty, isDark: false, slug: slug, file: TelegramMediaFile(fileId: MediaId(namespace: 0, id: 0), partialReference: nil, resource: WallpaperDataResource(slug: slug), previewRepresentations: [], videoThumbnails: [], immediateThumbnailData: nil, mimeType: "", size: nil, attributes: []), settings: WallpaperSettings(blur: blur, motion: motion, colors: colors, intensity: intensity, rotation: rotation))) } else { throw PresentationThemeDecodingError.generic } @@ -117,48 +117,48 @@ extension TelegramWallpaper: Codable { try container.encode("builtin") case let .color(color): try container.encode(String(format: "%06x", color)) - case let .gradient(_, colors, settings): + case let .gradient(gradient): var components: [String] = [] - for color in colors { + for color in gradient.colors { components.append(String(format: "%06x", color)) } - if let rotation = settings.rotation { + if let rotation = gradient.settings.rotation { components.append("\(rotation)") } - if settings.motion { + if gradient.settings.motion { components.append("motion") } - if settings.blur { + if gradient.settings.blur { components.append("blur") } try container.encode(components.joined(separator: " ")) - case let .file(_, _, _, _, _, _, slug, _, settings): + case let .file(file): var components: [String] = [] - components.append(slug) + components.append(file.slug) if self.isPattern { - if settings.colors.count >= 1 { - components.append(String(format: "%06x", settings.colors[0])) + if file.settings.colors.count >= 1 { + components.append(String(format: "%06x", file.settings.colors[0])) } - if let intensity = settings.intensity { + if let intensity = file.settings.intensity { components.append("\(intensity)") } - if settings.colors.count >= 2 { - components.append(String(format: "%06x", settings.colors[1])) + if file.settings.colors.count >= 2 { + components.append(String(format: "%06x", file.settings.colors[1])) } - if settings.colors.count >= 3 { - components.append(String(format: "%06x", settings.colors[2])) + if file.settings.colors.count >= 3 { + components.append(String(format: "%06x", file.settings.colors[2])) } - if settings.colors.count >= 4 { - components.append(String(format: "%06x", settings.colors[3])) + if file.settings.colors.count >= 4 { + components.append(String(format: "%06x", file.settings.colors[3])) } - if let rotation = settings.rotation, rotation != 0 { + if let rotation = file.settings.rotation, rotation != 0 { components.append("\(rotation)") } } - if settings.motion { + if file.settings.motion { components.append("motion") } - if settings.blur { + if file.settings.blur { components.append("blur") } try container.encode(components.joined(separator: " ")) diff --git a/submodules/TelegramPresentationData/Sources/WallpaperUtils.swift b/submodules/TelegramPresentationData/Sources/WallpaperUtils.swift index e2e8423c67..e077993a22 100644 --- a/submodules/TelegramPresentationData/Sources/WallpaperUtils.swift +++ b/submodules/TelegramPresentationData/Sources/WallpaperUtils.swift @@ -7,8 +7,8 @@ public extension TelegramWallpaper { switch self { case .image: return false - case let .file(_, _, _, _, _, _, _, _, settings): - if self.isPattern, settings.colors.count == 1 && (settings.colors[0] == 0xffffff || settings.colors[0] == 0xffffffff) { + case let .file(file): + if self.isPattern, file.settings.colors.count == 1 && (file.settings.colors[0] == 0xffffff || file.settings.colors[0] == 0xffffffff) { return true } else { return false @@ -31,8 +31,8 @@ public extension TelegramWallpaper { var isPattern: Bool { switch self { - case let .file(_, _, _, _, isPattern, _, _, file, _): - return isPattern || file.mimeType == "application/x-tgwallpattern" + case let .file(file): + return file.isPattern || file.file.mimeType == "application/x-tgwallpattern" default: return false } @@ -48,8 +48,8 @@ public extension TelegramWallpaper { } var dimensions: CGSize? { - if case let .file(_, _, _, _, _, _, _, file, _) = self { - return file.dimensions?.cgSize + if case let .file(file) = self { + return file.file.dimensions?.cgSize } else { return nil } diff --git a/submodules/TelegramUI/Sources/ChatControllerNode.swift b/submodules/TelegramUI/Sources/ChatControllerNode.swift index 34fc8fcffc..c2feb9e879 100644 --- a/submodules/TelegramUI/Sources/ChatControllerNode.swift +++ b/submodules/TelegramUI/Sources/ChatControllerNode.swift @@ -372,12 +372,12 @@ class ChatControllerNode: ASDisplayNode, UIScrollViewDelegate { var backgroundColors: [UInt32] = [] switch chatPresentationInterfaceState.chatWallpaper { - case let .file(_, _, _, _, isPattern, _, _, _, settings): - if isPattern { - backgroundColors = settings.colors + case let .file(file): + if file.isPattern { + backgroundColors = file.settings.colors } - case let .gradient(_, colors, _): - backgroundColors = colors + case let .gradient(gradient): + backgroundColors = gradient.colors case let .color(color): backgroundColors = [color] default: diff --git a/submodules/TelegramUI/Sources/ChatMessageBubbleItemNode.swift b/submodules/TelegramUI/Sources/ChatMessageBubbleItemNode.swift index ae3f0cc1a0..ef39095ec0 100644 --- a/submodules/TelegramUI/Sources/ChatMessageBubbleItemNode.swift +++ b/submodules/TelegramUI/Sources/ChatMessageBubbleItemNode.swift @@ -1396,8 +1396,8 @@ class ChatMessageBubbleItemNode: ChatMessageItemView, ChatMessagePreviewItemNode switch item.presentationData.theme.wallpaper { case .color: hasSolidWallpaper = true - case let .gradient(_, colors, _): - hasSolidWallpaper = colors.count <= 2 + case let .gradient(gradient): + hasSolidWallpaper = gradient.colors.count <= 2 default: break } diff --git a/submodules/TelegramUI/Sources/OpenChatMessage.swift b/submodules/TelegramUI/Sources/OpenChatMessage.swift index a379d9859f..c705e9bbcb 100644 --- a/submodules/TelegramUI/Sources/OpenChatMessage.swift +++ b/submodules/TelegramUI/Sources/OpenChatMessage.swift @@ -262,7 +262,7 @@ func openChatWallpaper(context: AccountContext, message: Message, present: @esca case let .color(color): source = .wallpaper(.color(color.argb), nil, [], nil, nil, message) case let .gradient(colors, rotation): - source = .wallpaper(.gradient(nil, colors, WallpaperSettings(rotation: rotation)), nil, [], nil, rotation, message) + source = .wallpaper(.gradient(TelegramWallpaper.Gradient(id: nil, colors: colors, settings: WallpaperSettings(rotation: rotation))), nil, [], nil, rotation, message) } let controller = WallpaperGalleryController(context: context, source: source) diff --git a/submodules/TelegramUI/Sources/OpenResolvedUrl.swift b/submodules/TelegramUI/Sources/OpenResolvedUrl.swift index f7a2fe8dfc..ff61025692 100644 --- a/submodules/TelegramUI/Sources/OpenResolvedUrl.swift +++ b/submodules/TelegramUI/Sources/OpenResolvedUrl.swift @@ -299,7 +299,7 @@ func openResolvedUrlImpl(_ resolvedUrl: ResolvedUrl, context: AccountContext, ur case let .color(color): signal = .single(.color(color.argb)) case let .gradient(colors, rotation): - signal = .single(.gradient(nil, colors, WallpaperSettings(rotation: rotation))) + signal = .single(.gradient(TelegramWallpaper.Gradient(id: nil, colors: colors, settings: WallpaperSettings(rotation: rotation)))) } let _ = (signal diff --git a/submodules/TelegramUI/Sources/ThemeUpdateManager.swift b/submodules/TelegramUI/Sources/ThemeUpdateManager.swift index 7a9d169ea1..cc9014cef7 100644 --- a/submodules/TelegramUI/Sources/ThemeUpdateManager.swift +++ b/submodules/TelegramUI/Sources/ThemeUpdateManager.swift @@ -90,8 +90,8 @@ final class ThemeUpdateManagerImpl: ThemeUpdateManager { } let resolvedWallpaper: Signal - if case let .file(id, _, _, _, _, _, slug, _, settings) = presentationTheme.chat.defaultWallpaper, id == 0 { - resolvedWallpaper = cachedWallpaper(account: account, slug: slug, settings: settings) + if case let .file(file) = presentationTheme.chat.defaultWallpaper, file.id == 0 { + resolvedWallpaper = cachedWallpaper(account: account, slug: file.slug, settings: file.settings) |> map { wallpaper in return wallpaper?.wallpaper } @@ -101,15 +101,15 @@ final class ThemeUpdateManagerImpl: ThemeUpdateManager { return resolvedWallpaper |> mapToSignal { wallpaper -> Signal<(PresentationThemeReference, PresentationTheme?), NoError> in - if let wallpaper = wallpaper, case let .file(_, _, _, _, _, _, slug, file, _) = wallpaper { + if let wallpaper = wallpaper, case let .file(file) = wallpaper { var convertedRepresentations: [ImageRepresentationWithReference] = [] - convertedRepresentations.append(ImageRepresentationWithReference(representation: TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: 100, height: 100), resource: file.resource, progressiveSizes: [], immediateThumbnailData: nil), reference: .wallpaper(wallpaper: .slug(slug), resource: file.resource))) - return wallpaperDatas(account: account, accountManager: accountManager, fileReference: .standalone(media: file), representations: convertedRepresentations, alwaysShowThumbnailFirst: false, thumbnail: false, onlyFullSize: true, autoFetchFullSize: true, synchronousLoad: false) + convertedRepresentations.append(ImageRepresentationWithReference(representation: TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: 100, height: 100), resource: file.file.resource, progressiveSizes: [], immediateThumbnailData: nil), reference: .wallpaper(wallpaper: .slug(file.slug), resource: file.file.resource))) + return wallpaperDatas(account: account, accountManager: accountManager, fileReference: .standalone(media: file.file), representations: convertedRepresentations, alwaysShowThumbnailFirst: false, thumbnail: false, onlyFullSize: true, autoFetchFullSize: true, synchronousLoad: false) |> mapToSignal { _, fullSizeData, complete -> Signal<(PresentationThemeReference, PresentationTheme?), NoError> in guard complete, let fullSizeData = fullSizeData else { return .complete() } - accountManager.mediaBox.storeResourceData(file.resource.id, data: fullSizeData, synchronous: true) + accountManager.mediaBox.storeResourceData(file.file.resource.id, data: fullSizeData, synchronous: true) return .single((.cloud(PresentationCloudTheme(theme: theme, resolvedWallpaper: wallpaper, creatorAccountId: theme.isCreator ? account.id : nil)), presentationTheme)) } } else { diff --git a/submodules/TelegramUI/Sources/WallpaperUploadManager.swift b/submodules/TelegramUI/Sources/WallpaperUploadManager.swift index 7e9ffe3c48..c7f6af8c19 100644 --- a/submodules/TelegramUI/Sources/WallpaperUploadManager.swift +++ b/submodules/TelegramUI/Sources/WallpaperUploadManager.swift @@ -94,9 +94,9 @@ final class WallpaperUploadManagerImpl: WallpaperUploadManager { |> map { result -> UploadWallpaperStatus in switch result { case let .complete(wallpaper): - if case let .file(_, _, _, _, _, _, _, file, _) = wallpaper { - sharedContext.accountManager.mediaBox.moveResourceData(from: currentResource.id, to: file.resource.id) - account.postbox.mediaBox.moveResourceData(from: currentResource.id, to: file.resource.id) + if case let .file(file) = wallpaper { + sharedContext.accountManager.mediaBox.moveResourceData(from: currentResource.id, to: file.file.resource.id) + account.postbox.mediaBox.moveResourceData(from: currentResource.id, to: file.file.resource.id) } default: break @@ -133,10 +133,10 @@ final class WallpaperUploadManagerImpl: WallpaperUploadManager { })).start() } - if case let .file(_, _, _, _, _, _, _, file, settings) = wallpaper, settings.blur { - let _ = account.postbox.mediaBox.cachedResourceRepresentation(file.resource, representation: CachedBlurredWallpaperRepresentation(), complete: true, fetch: true).start(completed: { + if case let .file(file) = wallpaper, file.settings.blur { + let _ = account.postbox.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedBlurredWallpaperRepresentation(), complete: true, fetch: true).start(completed: { }) - let _ = sharedContext.accountManager.mediaBox.cachedResourceRepresentation(file.resource, representation: CachedBlurredWallpaperRepresentation(), complete: true, fetch: true).start(completed: { + let _ = sharedContext.accountManager.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedBlurredWallpaperRepresentation(), complete: true, fetch: true).start(completed: { updateWallpaper(wallpaper) }) } else { diff --git a/submodules/TelegramUIPreferences/Sources/PresentationThemeSettings.swift b/submodules/TelegramUIPreferences/Sources/PresentationThemeSettings.swift index 1e6418db67..8f5d568e00 100644 --- a/submodules/TelegramUIPreferences/Sources/PresentationThemeSettings.swift +++ b/submodules/TelegramUIPreferences/Sources/PresentationThemeSettings.swift @@ -573,10 +573,10 @@ public struct PresentationThemeSettings: PreferencesEntry { switch wallpaper { case let .image(representations, _): return representations.map { $0.resource.id } - case let .file(_, _, _, _, _, _, _, file, _): + case let .file(file): var resources: [MediaResourceId] = [] - resources.append(file.resource.id) - resources.append(contentsOf: file.previewRepresentations.map { $0.resource.id }) + resources.append(file.file.resource.id) + resources.append(contentsOf: file.file.previewRepresentations.map { $0.resource.id }) return resources default: return [] diff --git a/submodules/WallpaperBackgroundNode/Sources/WallpaperBackgroundNode.swift b/submodules/WallpaperBackgroundNode/Sources/WallpaperBackgroundNode.swift index e7ab2e6551..d6ae34201c 100644 --- a/submodules/WallpaperBackgroundNode/Sources/WallpaperBackgroundNode.swift +++ b/submodules/WallpaperBackgroundNode/Sources/WallpaperBackgroundNode.swift @@ -116,13 +116,13 @@ public final class WallpaperBackgroundNode: ASDisplayNode { var isInvertedGradient = false var hasComplexGradient = false switch wallpaper { - case let .file(_, _, _, _, _, _, _, _, settings): - hasComplexGradient = settings.colors.count >= 3 - if let intensity = settings.intensity, intensity < 0 { + case let .file(file): + hasComplexGradient = file.settings.colors.count >= 3 + if let intensity = file.settings.intensity, intensity < 0 { isInvertedGradient = true } - case let .gradient(_, colors, _): - hasComplexGradient = colors.count >= 3 + case let .gradient(gradient): + hasComplexGradient = gradient.colors.count >= 3 default: break } @@ -417,13 +417,13 @@ public final class WallpaperBackgroundNode: ASDisplayNode { if case let .color(color) = wallpaper { gradientColors = [color] self._isReady.set(true) - } else if case let .gradient(_, colors, settings) = wallpaper { - gradientColors = colors - gradientAngle = settings.rotation ?? 0 + } else if case let .gradient(gradient) = wallpaper { + gradientColors = gradient.colors + gradientAngle = gradient.settings.rotation ?? 0 self._isReady.set(true) - } else if case let .file(_, _, _, _, isPattern, _, _, _, settings) = wallpaper, isPattern { - gradientColors = settings.colors - gradientAngle = settings.rotation ?? 0 + } else if case let .file(file) = wallpaper, file.isPattern { + gradientColors = file.settings.colors + gradientAngle = file.settings.rotation ?? 0 } if gradientColors.count >= 3 { @@ -526,11 +526,11 @@ public final class WallpaperBackgroundNode: ASDisplayNode { } switch wallpaper { - case let .file(_, _, _, _, isPattern, _, _, _, settings) where isPattern: - let brightness = UIColor.average(of: settings.colors.map(UIColor.init(rgb:))).hsb.b + case let .file(file) where file.isPattern: + let brightness = UIColor.average(of: file.settings.colors.map(UIColor.init(rgb:))).hsb.b let patternIsBlack = brightness <= 0.01 - let intensity = CGFloat(settings.intensity ?? 50) / 100.0 + let intensity = CGFloat(file.settings.intensity ?? 50) / 100.0 if intensity < 0 { self.patternImageNode.alpha = 1.0 self.patternImageNode.layer.compositingFilter = nil @@ -580,14 +580,14 @@ public final class WallpaperBackgroundNode: ASDisplayNode { var patternIsLight: Bool = false switch wallpaper { - case let .file(_, _, _, _, isPattern, _, slug, file, settings) where isPattern: + case let .file(file) where file.isPattern: var updated = true - let brightness = UIColor.average(of: settings.colors.map(UIColor.init(rgb:))).hsb.b + let brightness = UIColor.average(of: file.settings.colors.map(UIColor.init(rgb:))).hsb.b patternIsLight = brightness > 0.3 if let previousWallpaper = self.validPatternImage?.wallpaper { switch previousWallpaper { - case let .file(_, _, _, _, _, _, _, previousFile, _): - if file.id == previousFile.id { + case let .file(previousFile): + if file.file.id == previousFile.file.id { updated = false } default: @@ -606,15 +606,15 @@ public final class WallpaperBackgroundNode: ASDisplayNode { if let message = message { return .media(media: .message(message: MessageReference(message), media: media), resource: resource) } - return .wallpaper(wallpaper: .slug(slug), resource: resource) + return .wallpaper(wallpaper: .slug(file.slug), resource: resource) } var convertedRepresentations: [ImageRepresentationWithReference] = [] - for representation in file.previewRepresentations { - convertedRepresentations.append(ImageRepresentationWithReference(representation: representation, reference: reference(for: representation.resource, media: file, message: nil))) + for representation in file.file.previewRepresentations { + convertedRepresentations.append(ImageRepresentationWithReference(representation: representation, reference: reference(for: representation.resource, media: file.file, message: nil))) } - let dimensions = file.dimensions ?? PixelDimensions(width: 2000, height: 4000) - convertedRepresentations.append(ImageRepresentationWithReference(representation: .init(dimensions: dimensions, resource: file.resource, progressiveSizes: [], immediateThumbnailData: nil), reference: reference(for: file.resource, media: file, message: nil))) + let dimensions = file.file.dimensions ?? PixelDimensions(width: 2000, height: 4000) + convertedRepresentations.append(ImageRepresentationWithReference(representation: .init(dimensions: dimensions, resource: file.file.resource, progressiveSizes: [], immediateThumbnailData: nil), reference: reference(for: file.file.resource, media: file.file, message: nil))) let signal = patternWallpaperImage(account: self.context.account, accountManager: self.context.sharedContext.accountManager, representations: convertedRepresentations, mode: .screen, autoFetchFullSize: true) self.patternImageDisposable.set((signal @@ -636,7 +636,7 @@ public final class WallpaperBackgroundNode: ASDisplayNode { })) } } - let intensity = CGFloat(settings.intensity ?? 50) / 100.0 + let intensity = CGFloat(file.settings.intensity ?? 50) / 100.0 invertPattern = intensity < 0 default: self.updatePatternPresentation() diff --git a/submodules/WallpaperResources/Sources/WallpaperCache.swift b/submodules/WallpaperResources/Sources/WallpaperCache.swift index fd4f6bef3e..3a0a933cd7 100644 --- a/submodules/WallpaperResources/Sources/WallpaperCache.swift +++ b/submodules/WallpaperResources/Sources/WallpaperCache.swift @@ -48,8 +48,8 @@ public func cachedWallpaper(account: Account, slug: String, settings: WallpaperS let id = ItemCacheEntryId(collectionId: ApplicationSpecificItemCacheCollectionId.cachedWallpapers, key: key) if var wallpaper = wallpaper { switch wallpaper { - case let .file(id, accessHash, isCreator, isDefault, isPattern, isDark, slug, file, settings): - wallpaper = .file(id: id, accessHash: accessHash, isCreator: isCreator, isDefault: isDefault, isPattern: isPattern, isDark: isDark, slug: slug, file: file.withUpdatedResource(WallpaperDataResource(slug: slug)), settings: settings) + case let .file(file): + wallpaper = .file(TelegramWallpaper.File(id: file.id, accessHash: file.accessHash, isCreator: file.isCreator, isDefault: file.isDefault, isPattern: file.isPattern, isDark: file.isDark, slug: file.slug, file: file.file.withUpdatedResource(WallpaperDataResource(slug: slug)), settings: file.settings)) default: break } @@ -71,12 +71,12 @@ public func cachedWallpaper(account: Account, slug: String, settings: WallpaperS } public func updateCachedWallpaper(account: Account, wallpaper: TelegramWallpaper) { - guard case let .file(id, _, _, _, _, _, slug, _, _) = wallpaper, id != 0 else { + guard case let .file(file) = wallpaper, file.id != 0 else { return } let _ = (account.postbox.transaction { transaction in let key = ValueBoxKey(length: 8) - key.setInt64(0, value: Int64(bitPattern: slug.persistentHashValue)) + key.setInt64(0, value: Int64(bitPattern: file.slug.persistentHashValue)) let id = ItemCacheEntryId(collectionId: ApplicationSpecificItemCacheCollectionId.cachedWallpapers, key: key) transaction.putItemCacheEntry(id: id, entry: CachedWallpaper(wallpaper: wallpaper), collectionSpec: collectionSpec) }).start() diff --git a/submodules/WallpaperResources/Sources/WallpaperResources.swift b/submodules/WallpaperResources/Sources/WallpaperResources.swift index 84466da289..d27283c899 100644 --- a/submodules/WallpaperResources/Sources/WallpaperResources.swift +++ b/submodules/WallpaperResources/Sources/WallpaperResources.swift @@ -918,25 +918,25 @@ public func drawThemeImage(context c: CGContext, theme: PresentationTheme, wallp case let .color(color): c.setFillColor(UIColor(rgb: color).cgColor) c.fill(drawingRect) - case let .gradient(_, colors, _): - if colors.count >= 3 { - let image = GradientBackgroundNode.generatePreview(size: CGSize(width: 60.0, height: 60.0), colors: colors.map(UIColor.init(rgb:))) + case let .gradient(gradient): + if gradient.colors.count >= 3 { + let image = GradientBackgroundNode.generatePreview(size: CGSize(width: 60.0, height: 60.0), colors: gradient.colors.map(UIColor.init(rgb:))) c.draw(image.cgImage!, in: drawingRect) - } else if colors.count >= 2 { - let gradientColors = colors.map({ UIColor(rgb: $0).cgColor }) as CFArray + } else if gradient.colors.count >= 2 { + let gradientColors = gradient.colors.map({ UIColor(rgb: $0).cgColor }) as CFArray var locations: [CGFloat] = [0.0, 1.0] let colorSpace = CGColorSpaceCreateDeviceRGB() - let gradient = CGGradient(colorsSpace: colorSpace, colors: gradientColors, locations: &locations)! - c.drawLinearGradient(gradient, start: CGPoint(x: 0.0, y: drawingRect.height), end: CGPoint(x: 0.0, y: 0.0), options: [.drawsBeforeStartLocation, .drawsAfterEndLocation]) - } else if colors.count >= 1 { - let gradientColors = [UIColor(rgb: colors[0]), UIColor(rgb: colors[0])] as CFArray + let cgGradient = CGGradient(colorsSpace: colorSpace, colors: gradientColors, locations: &locations)! + c.drawLinearGradient(cgGradient, start: CGPoint(x: 0.0, y: drawingRect.height), end: CGPoint(x: 0.0, y: 0.0), options: [.drawsBeforeStartLocation, .drawsAfterEndLocation]) + } else if gradient.colors.count >= 1 { + let gradientColors = [UIColor(rgb: gradient.colors[0]), UIColor(rgb: gradient.colors[0])] as CFArray var locations: [CGFloat] = [0.0, 1.0] let colorSpace = CGColorSpaceCreateDeviceRGB() - let gradient = CGGradient(colorsSpace: colorSpace, colors: gradientColors, locations: &locations)! - c.drawLinearGradient(gradient, start: CGPoint(x: 0.0, y: drawingRect.height), end: CGPoint(x: 0.0, y: 0.0), options: [.drawsBeforeStartLocation, .drawsAfterEndLocation]) + let cgGradient = CGGradient(colorsSpace: colorSpace, colors: gradientColors, locations: &locations)! + c.drawLinearGradient(cgGradient, start: CGPoint(x: 0.0, y: drawingRect.height), end: CGPoint(x: 0.0, y: 0.0), options: [.drawsBeforeStartLocation, .drawsAfterEndLocation]) } - case let .file(_, _, _, _, isPattern, _, _, _, settings): - if isPattern, let intensity = settings.intensity, intensity < 0 { + case let .file(file): + if file.isPattern, let intensity = file.settings.intensity, intensity < 0 { c.setFillColor(UIColor.black.cgColor) c.fill(CGRect(origin: CGPoint(), size: size)) } else { @@ -1143,31 +1143,31 @@ public func themeImage(account: Account, accountManager: AccountManager, source: let data = theme |> mapToSignal { (theme, thumbnailData) -> Signal<(PresentationTheme?, WallpaperImage?, Data?), NoError> in if let theme = theme { - if case let .file(_, _, _, _, _, _, slug, _, settings) = theme.chat.defaultWallpaper { - return cachedWallpaper(account: account, slug: slug, settings: settings) + if case let .file(file) = theme.chat.defaultWallpaper { + return cachedWallpaper(account: account, slug: file.slug, settings: file.settings) |> mapToSignal { wallpaper -> Signal<(PresentationTheme?, WallpaperImage?, Data?), NoError> in - if let wallpaper = wallpaper, case let .file(_, _, _, _, _, _, slug, file, settings) = wallpaper.wallpaper { + if let wallpaper = wallpaper, case let .file(file) = wallpaper.wallpaper { var convertedRepresentations: [ImageRepresentationWithReference] = [] - convertedRepresentations.append(ImageRepresentationWithReference(representation: TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: 100, height: 100), resource: file.resource, progressiveSizes: [], immediateThumbnailData: nil), reference: .wallpaper(wallpaper: .slug(slug), resource: file.resource))) - return wallpaperDatas(account: account, accountManager: accountManager, fileReference: .standalone(media: file), representations: convertedRepresentations, alwaysShowThumbnailFirst: false, thumbnail: false, onlyFullSize: true, autoFetchFullSize: true, synchronousLoad: false) + convertedRepresentations.append(ImageRepresentationWithReference(representation: TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: 100, height: 100), resource: file.file.resource, progressiveSizes: [], immediateThumbnailData: nil), reference: .wallpaper(wallpaper: .slug(file.slug), resource: file.file.resource))) + return wallpaperDatas(account: account, accountManager: accountManager, fileReference: .standalone(media: file.file), representations: convertedRepresentations, alwaysShowThumbnailFirst: false, thumbnail: false, onlyFullSize: true, autoFetchFullSize: true, synchronousLoad: false) |> mapToSignal { _, fullSizeData, complete -> Signal<(PresentationTheme?, WallpaperImage?, Data?), NoError> in guard complete, let fullSizeData = fullSizeData else { return .complete() } - accountManager.mediaBox.storeResourceData(file.resource.id, data: fullSizeData) - let _ = accountManager.mediaBox.cachedResourceRepresentation(file.resource, representation: CachedScaledImageRepresentation(size: CGSize(width: 720.0, height: 720.0), mode: .aspectFit), complete: true, fetch: true).start() + accountManager.mediaBox.storeResourceData(file.file.resource.id, data: fullSizeData) + let _ = accountManager.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedScaledImageRepresentation(size: CGSize(width: 720.0, height: 720.0), mode: .aspectFit), complete: true, fetch: true).start() - if wallpaper.wallpaper.isPattern, !settings.colors.isEmpty, let intensity = settings.intensity { - return accountManager.mediaBox.resourceData(file.resource) + if wallpaper.wallpaper.isPattern, !file.settings.colors.isEmpty, let intensity = file.settings.intensity { + return accountManager.mediaBox.resourceData(file.file.resource) |> mapToSignal { data in if data.complete, let imageData = try? Data(contentsOf: URL(fileURLWithPath: data.path)) { - return .single((theme, .pattern(data: imageData, colors: settings.colors, intensity: intensity), thumbnailData)) + return .single((theme, .pattern(data: imageData, colors: file.settings.colors, intensity: intensity), thumbnailData)) } else { return .complete() } } - } else if settings.blur { - return accountManager.mediaBox.cachedResourceRepresentation(file.resource, representation: CachedBlurredWallpaperRepresentation(), complete: true, fetch: true) + } else if file.settings.blur { + return accountManager.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedBlurredWallpaperRepresentation(), complete: true, fetch: true) |> mapToSignal { data in if data.complete, let data = try? Data(contentsOf: URL(fileURLWithPath: data.path)), let image = UIImage(data: data) { return .single((theme, .image(image), thumbnailData)) @@ -1327,52 +1327,52 @@ public func themeIconImage(account: Account, accountManager: AccountManager, the backgroundColor = (UIColor(rgb: 0xd6e2ee), nil, []) case let .color(color): backgroundColor = (UIColor(rgb: color), nil, []) - case let .gradient(_, colors, settings): - if colors.count >= 2 { - backgroundColor = (UIColor(rgb: colors[0]), UIColor(rgb: colors[1]), colors) + case let .gradient(gradient): + if gradient.colors.count >= 2 { + backgroundColor = (UIColor(rgb: gradient.colors[0]), UIColor(rgb: gradient.colors[1]), gradient.colors) } else { backgroundColor = (.white, nil, []) } - rotation = settings.rotation + rotation = gradient.settings.rotation case .image: backgroundColor = (.black, nil, []) - case let .file(_, _, _, _, isPattern, _, slug, _, settings): - rotation = settings.rotation - if isPattern, let intensity = settings.intensity, intensity < 0 { + case let .file(file): + rotation = file.settings.rotation + if file.isPattern, let intensity = file.settings.intensity, intensity < 0 { backgroundColor = (.black, nil, []) - } else if !settings.colors.isEmpty { + } else if !file.settings.colors.isEmpty { var bottomColor: UIColor? - if settings.colors.count >= 2 { - bottomColor = UIColor(rgb: settings.colors[1]) + if file.settings.colors.count >= 2 { + bottomColor = UIColor(rgb: file.settings.colors[1]) } - backgroundColor = (UIColor(rgb: settings.colors[0]), bottomColor, settings.colors) + backgroundColor = (UIColor(rgb: file.settings.colors[0]), bottomColor, file.settings.colors) } else { backgroundColor = (theme.chatList.backgroundColor, nil, []) } - wallpaperSignal = cachedWallpaper(account: account, slug: slug, settings: settings) + wallpaperSignal = cachedWallpaper(account: account, slug: file.slug, settings: file.settings) |> mapToSignal { wallpaper in - if let wallpaper = wallpaper, case let .file(_, _, _, _, _, _, _, file, settings) = wallpaper.wallpaper { + if let wallpaper = wallpaper, case let .file(file) = wallpaper.wallpaper { var effectiveBackgroundColor = backgroundColor - if !settings.colors.isEmpty { + if !file.settings.colors.isEmpty { var bottomColor: UIColor? - if settings.colors.count >= 2 { - bottomColor = UIColor(rgb: settings.colors[1]) + if file.settings.colors.count >= 2 { + bottomColor = UIColor(rgb: file.settings.colors[1]) } - effectiveBackgroundColor = (UIColor(rgb: settings.colors[0]), bottomColor, settings.colors) + effectiveBackgroundColor = (UIColor(rgb: file.settings.colors[0]), bottomColor, file.settings.colors) } var convertedRepresentations: [ImageRepresentationWithReference] = [] - convertedRepresentations.append(ImageRepresentationWithReference(representation: TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: 100, height: 100), resource: file.resource, progressiveSizes: [], immediateThumbnailData: nil), reference: .wallpaper(wallpaper: .slug(slug), resource: file.resource))) - return wallpaperDatas(account: account, accountManager: accountManager, fileReference: .standalone(media: file), representations: convertedRepresentations, alwaysShowThumbnailFirst: false, thumbnail: false, onlyFullSize: true, autoFetchFullSize: true, synchronousLoad: false) + convertedRepresentations.append(ImageRepresentationWithReference(representation: TelegramMediaImageRepresentation(dimensions: PixelDimensions(width: 100, height: 100), resource: file.file.resource, progressiveSizes: [], immediateThumbnailData: nil), reference: .wallpaper(wallpaper: .slug(file.slug), resource: file.file.resource))) + return wallpaperDatas(account: account, accountManager: accountManager, fileReference: .standalone(media: file.file), representations: convertedRepresentations, alwaysShowThumbnailFirst: false, thumbnail: false, onlyFullSize: true, autoFetchFullSize: true, synchronousLoad: false) |> mapToSignal { _, fullSizeData, complete -> Signal<((UIColor, UIColor?, [UInt32]), (UIColor, UIColor), (UIColor, UIColor), UIImage?, Int32?), NoError> in guard complete, let fullSizeData = fullSizeData else { return .complete() } - accountManager.mediaBox.storeResourceData(file.resource.id, data: fullSizeData) - let _ = accountManager.mediaBox.cachedResourceRepresentation(file.resource, representation: CachedScaledImageRepresentation(size: CGSize(width: 720.0, height: 720.0), mode: .aspectFit), complete: true, fetch: true).start() + accountManager.mediaBox.storeResourceData(file.file.resource.id, data: fullSizeData) + let _ = accountManager.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedScaledImageRepresentation(size: CGSize(width: 720.0, height: 720.0), mode: .aspectFit), complete: true, fetch: true).start() if wallpaper.wallpaper.isPattern { - if !settings.colors.isEmpty, let intensity = settings.intensity { + if !file.settings.colors.isEmpty, let intensity = file.settings.intensity { if intensity < 0 { return .single(((.black, nil, []), incomingColor, outgoingColor, nil, rotation)) } else { @@ -1381,8 +1381,8 @@ public func themeIconImage(account: Account, accountManager: AccountManager, the } else { return .complete() } - } else if settings.blur { - return accountManager.mediaBox.cachedResourceRepresentation(file.resource, representation: CachedBlurredWallpaperRepresentation(), complete: true, fetch: true) + } else if file.settings.blur { + return accountManager.mediaBox.cachedResourceRepresentation(file.file.resource, representation: CachedBlurredWallpaperRepresentation(), complete: true, fetch: true) |> mapToSignal { _ in if let image = UIImage(data: fullSizeData) { return .single((backgroundColor, incomingColor, outgoingColor, image, rotation)) @@ -1480,8 +1480,8 @@ public func themeIconImage(account: Account, accountManager: AccountManager, the public func wallpaperThumbnail(account: Account, accountManager: AccountManager, fileReference: FileMediaReference, wallpaper: TelegramWallpaper, synchronousLoad: Bool) -> Signal<(TransformImageArguments) -> DrawingContext?, NoError> { switch wallpaper { - case let .file(_, _, _, _, _, _, _, file, settings): - guard let thumbnail = smallestImageRepresentation(file.previewRepresentations) else { + case let .file(file): + guard let thumbnail = smallestImageRepresentation(file.file.previewRepresentations) else { return .single({ _ in nil }) } let signal: Signal = Signal { subscriber in @@ -1514,12 +1514,12 @@ public func wallpaperThumbnail(account: Account, accountManager: AccountManager, let context = DrawingContext(size: arguments.boundingSize, clear: true) context.withFlippedContext { c in - let colors = settings.colors.map(UIColor.init(rgb:)) + let colors = file.settings.colors.map(UIColor.init(rgb:)) if colors.count == 1 { c.setFillColor(colors[0].cgColor) c.fill(arguments.drawingRect) - } else if settings.colors.count >= 3 { + } else if file.settings.colors.count >= 3 { let image = GradientBackgroundNode.generatePreview(size: CGSize(width: 60.0, height: 60.0), colors: colors) c.translateBy(x: drawingRect.midX, y: drawingRect.midY) c.scaleBy(x: 1.0, y: -1.0) @@ -1528,12 +1528,12 @@ public func wallpaperThumbnail(account: Account, accountManager: AccountManager, c.translateBy(x: drawingRect.midX, y: drawingRect.midY) c.scaleBy(x: 1.0, y: -1.0) c.translateBy(x: -drawingRect.midX, y: -drawingRect.midY) - } else if settings.colors.count >= 2 { - let gradientColors = settings.colors.map { UIColor(rgb: $0).cgColor } as CFArray - let delta: CGFloat = 1.0 / (CGFloat(settings.colors.count) - 1.0) + } else if file.settings.colors.count >= 2 { + let gradientColors = file.settings.colors.map { UIColor(rgb: $0).cgColor } as CFArray + let delta: CGFloat = 1.0 / (CGFloat(file.settings.colors.count) - 1.0) var locations: [CGFloat] = [] - for i in 0 ..< settings.colors.count { + for i in 0 ..< file.settings.colors.count { locations.append(delta * CGFloat(i)) } let colorSpace = CGColorSpaceCreateDeviceRGB() @@ -1541,7 +1541,7 @@ public func wallpaperThumbnail(account: Account, accountManager: AccountManager, c.saveGState() c.translateBy(x: arguments.drawingSize.width / 2.0, y: arguments.drawingSize.height / 2.0) - c.rotate(by: CGFloat(settings.rotation ?? 0) * CGFloat.pi / -180.0) + c.rotate(by: CGFloat(file.settings.rotation ?? 0) * CGFloat.pi / -180.0) c.translateBy(x: -arguments.drawingSize.width / 2.0, y: -arguments.drawingSize.height / 2.0) c.drawLinearGradient(gradient, start: CGPoint(x: 0.0, y: 0.0), end: CGPoint(x: 0.0, y: arguments.drawingSize.height), options: [.drawsBeforeStartLocation, .drawsAfterEndLocation])