From feaaed3f415fc6e6721f7713097e895f7d03cd35 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Wed, 12 Dec 2018 19:39:54 +0400 Subject: [PATCH] Small fixes --- TelegramUI.xcodeproj/project.pbxproj | 8 - TelegramUI/CallListController.swift | 22 +- .../ContactMultiselectionController.swift | 22 +- .../ContactMultiselectionControllerNode.swift | 22 +- TelegramUI/ContactSelectionController.swift | 22 +- TelegramUI/LanguageSelectionController.swift | 482 ----------------- .../LanguageSelectionControllerNode.swift | 33 -- .../NotificationExceptionControllerNode.swift | 82 +-- TelegramUI/NotificationExceptions.swift | 491 ------------------ .../PeerMediaCollectionController.swift | 24 +- TelegramUI/SettingsController.swift | 2 - TelegramUI/ShareController.swift | 14 +- TelegramUI/ShareControllerNode.swift | 3 + TelegramUI/StickerPackPreviewController.swift | 2 +- 14 files changed, 79 insertions(+), 1150 deletions(-) delete mode 100644 TelegramUI/LanguageSelectionController.swift delete mode 100644 TelegramUI/LanguageSelectionControllerNode.swift diff --git a/TelegramUI.xcodeproj/project.pbxproj b/TelegramUI.xcodeproj/project.pbxproj index 1492688262..a635eafae1 100644 --- a/TelegramUI.xcodeproj/project.pbxproj +++ b/TelegramUI.xcodeproj/project.pbxproj @@ -377,8 +377,6 @@ D0AEAE272080D6970013176E /* StickerPaneSearchBarNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0AEAE262080D6970013176E /* StickerPaneSearchBarNode.swift */; }; D0AEAE292080FD660013176E /* StickerPaneSearchGlobaltem.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0AEAE282080FD660013176E /* StickerPaneSearchGlobaltem.swift */; }; D0AF323A1FB1D8D60097362B /* ChatOverlayNavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0AF32391FB1D8D60097362B /* ChatOverlayNavigationBar.swift */; }; - D0AF7C461ED84BC500CD8E0F /* LanguageSelectionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0AF7C451ED84BC500CD8E0F /* LanguageSelectionController.swift */; }; - D0AF7C4A1ED84CE000CD8E0F /* LanguageSelectionControllerNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0AF7C491ED84CE000CD8E0F /* LanguageSelectionControllerNode.swift */; }; D0AFCC791F4C8D2C000720C6 /* InstantPageSlideshowItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0AFCC781F4C8D2C000720C6 /* InstantPageSlideshowItem.swift */; }; D0AFCC7B1F4C8D39000720C6 /* InstantPageSlideshowItemNode.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0AFCC7A1F4C8D39000720C6 /* InstantPageSlideshowItemNode.swift */; }; D0B2F76220506E2A00D3BFB9 /* MediaInputSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = D0B2F76120506E2A00D3BFB9 /* MediaInputSettings.swift */; }; @@ -1771,8 +1769,6 @@ D0AEAE262080D6970013176E /* StickerPaneSearchBarNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickerPaneSearchBarNode.swift; sourceTree = ""; }; D0AEAE282080FD660013176E /* StickerPaneSearchGlobaltem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickerPaneSearchGlobaltem.swift; sourceTree = ""; }; D0AF32391FB1D8D60097362B /* ChatOverlayNavigationBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatOverlayNavigationBar.swift; sourceTree = ""; }; - D0AF7C451ED84BC500CD8E0F /* LanguageSelectionController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LanguageSelectionController.swift; sourceTree = ""; }; - D0AF7C491ED84CE000CD8E0F /* LanguageSelectionControllerNode.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LanguageSelectionControllerNode.swift; sourceTree = ""; }; D0AFCC781F4C8D2C000720C6 /* InstantPageSlideshowItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstantPageSlideshowItem.swift; sourceTree = ""; }; D0AFCC7A1F4C8D39000720C6 /* InstantPageSlideshowItemNode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InstantPageSlideshowItemNode.swift; sourceTree = ""; }; D0B2F76120506E2A00D3BFB9 /* MediaInputSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaInputSettings.swift; sourceTree = ""; }; @@ -3443,8 +3439,6 @@ D0AF7C441ED84BB000CD8E0F /* Language Selection */ = { isa = PBXGroup; children = ( - D0AF7C451ED84BC500CD8E0F /* LanguageSelectionController.swift */, - D0AF7C491ED84CE000CD8E0F /* LanguageSelectionControllerNode.swift */, D05D8B392192FC460064586F /* LocalizationListController.swift */, D05D8B3E2192FC6E0064586F /* LocalizationListControllerNode.swift */, D05D8B402192FC8A0064586F /* LocalizationListItem.swift */, @@ -5032,7 +5026,6 @@ D0943B001FDAE852001522CC /* ChatFeedNavigationInputPanelNode.swift in Sources */, D0B37C601F8D286E004252DF /* ThemeSettingsFontSizeItem.swift in Sources */, D0EC6CC01EB9F58800EBF1C3 /* LegacyMediaPickers.swift in Sources */, - D0AF7C4A1ED84CE000CD8E0F /* LanguageSelectionControllerNode.swift in Sources */, D0EC6CC11EB9F58800EBF1C3 /* LegacyCamera.swift in Sources */, 0941A9A6210B822D00EBE194 /* OpenInOptions.swift in Sources */, D0754D1E1EEDDF6200884F6E /* ChatMessageAttachedContentNode.swift in Sources */, @@ -5264,7 +5257,6 @@ D0EC6D2C1EB9F58800EBF1C3 /* TouchDownGestureRecognizer.swift in Sources */, 09DD88FA21BFD70B000766BC /* ThemedTextAlertController.swift in Sources */, D0EC6D2D1EB9F58800EBF1C3 /* TapLongTapOrDoubleTapGestureRecognizer.swift in Sources */, - D0AF7C461ED84BC500CD8E0F /* LanguageSelectionController.swift in Sources */, D0B69C3C20EBD8C8003632C7 /* CheckDeviceAccess.swift in Sources */, 09C3466D2167D63A00B76780 /* Accessibility.swift in Sources */, D0FA08C020483F9600DD23FC /* ExtractVideoData.swift in Sources */, diff --git a/TelegramUI/CallListController.swift b/TelegramUI/CallListController.swift index e7fb079e1c..2d13a26c34 100644 --- a/TelegramUI/CallListController.swift +++ b/TelegramUI/CallListController.swift @@ -62,18 +62,18 @@ public final class CallListController: ViewController { } self.presentationDataDisposable = (account.telegramApplicationContext.presentationData - |> deliverOnMainQueue).start(next: { [weak self] presentationData in - if let strongSelf = self { - let previousTheme = strongSelf.presentationData.theme - let previousStrings = strongSelf.presentationData.strings - - strongSelf.presentationData = presentationData - - if previousTheme !== presentationData.theme || previousStrings !== presentationData.strings { - strongSelf.updateThemeAndStrings() - } + |> deliverOnMainQueue).start(next: { [weak self] presentationData in + if let strongSelf = self { + let previousTheme = strongSelf.presentationData.theme + let previousStrings = strongSelf.presentationData.strings + + strongSelf.presentationData = presentationData + + if previousTheme !== presentationData.theme || previousStrings !== presentationData.strings { + strongSelf.updateThemeAndStrings() } - }) + } + }) self.scrollToTop = { [weak self] in self?.controllerNode.scrollToLatest() diff --git a/TelegramUI/ContactMultiselectionController.swift b/TelegramUI/ContactMultiselectionController.swift index 63dd22d86c..10fc9d3c72 100644 --- a/TelegramUI/ContactMultiselectionController.swift +++ b/TelegramUI/ContactMultiselectionController.swift @@ -85,18 +85,18 @@ class ContactMultiselectionController: ViewController { } self.presentationDataDisposable = (account.telegramApplicationContext.presentationData - |> deliverOnMainQueue).start(next: { [weak self] presentationData in - if let strongSelf = self { - let previousTheme = strongSelf.presentationData.theme - let previousStrings = strongSelf.presentationData.strings - - strongSelf.presentationData = presentationData - - if previousTheme !== presentationData.theme || previousStrings !== presentationData.strings { - strongSelf.updateThemeAndStrings() - } + |> deliverOnMainQueue).start(next: { [weak self] presentationData in + if let strongSelf = self { + let previousTheme = strongSelf.presentationData.theme + let previousStrings = strongSelf.presentationData.strings + + strongSelf.presentationData = presentationData + + if previousTheme !== presentationData.theme || previousStrings !== presentationData.strings { + strongSelf.updateThemeAndStrings() } - }) + } + }) self.limitsConfigurationDisposable = (account.postbox.transaction { transaction -> LimitsConfiguration in return currentLimitsConfiguration(transaction: transaction) diff --git a/TelegramUI/ContactMultiselectionControllerNode.swift b/TelegramUI/ContactMultiselectionControllerNode.swift index 88758f3e27..e15580c23d 100644 --- a/TelegramUI/ContactMultiselectionControllerNode.swift +++ b/TelegramUI/ContactMultiselectionControllerNode.swift @@ -126,18 +126,18 @@ final class ContactMultiselectionControllerNode: ASDisplayNode { } self.presentationDataDisposable = (account.telegramApplicationContext.presentationData - |> deliverOnMainQueue).start(next: { [weak self] presentationData in - if let strongSelf = self { - let previousTheme = strongSelf.presentationData.theme - let previousStrings = strongSelf.presentationData.strings - - strongSelf.presentationData = presentationData - - if previousTheme !== presentationData.theme || previousStrings !== presentationData.strings { - strongSelf.updateThemeAndStrings() - } + |> deliverOnMainQueue).start(next: { [weak self] presentationData in + if let strongSelf = self { + let previousTheme = strongSelf.presentationData.theme + let previousStrings = strongSelf.presentationData.strings + + strongSelf.presentationData = presentationData + + if previousTheme !== presentationData.theme || previousStrings !== presentationData.strings { + strongSelf.updateThemeAndStrings() } - }) + } + }) } deinit { diff --git a/TelegramUI/ContactSelectionController.swift b/TelegramUI/ContactSelectionController.swift index 7f942a3b17..5c5a01d0b3 100644 --- a/TelegramUI/ContactSelectionController.swift +++ b/TelegramUI/ContactSelectionController.swift @@ -84,18 +84,18 @@ class ContactSelectionController: ViewController { } self.presentationDataDisposable = (account.telegramApplicationContext.presentationData - |> deliverOnMainQueue).start(next: { [weak self] presentationData in - if let strongSelf = self { - let previousTheme = strongSelf.presentationData.theme - let previousStrings = strongSelf.presentationData.strings - - strongSelf.presentationData = presentationData - - if previousTheme !== presentationData.theme || previousStrings !== presentationData.strings { - strongSelf.updateThemeAndStrings() - } + |> deliverOnMainQueue).start(next: { [weak self] presentationData in + if let strongSelf = self { + let previousTheme = strongSelf.presentationData.theme + let previousStrings = strongSelf.presentationData.strings + + strongSelf.presentationData = presentationData + + if previousTheme !== presentationData.theme || previousStrings !== presentationData.strings { + strongSelf.updateThemeAndStrings() } - }) + } + }) } required init(coder aDecoder: NSCoder) { diff --git a/TelegramUI/LanguageSelectionController.swift b/TelegramUI/LanguageSelectionController.swift deleted file mode 100644 index 21203960c2..0000000000 --- a/TelegramUI/LanguageSelectionController.swift +++ /dev/null @@ -1,482 +0,0 @@ -import Foundation -import Display -import AsyncDisplayKit -import SwiftSignalKit -import TelegramCore - -extension UISearchBar { - func setTextColor(_ color: UIColor) { - for view in self.subviews { - if let view = view as? UITextField { - view.textColor = color - return - } else { - for subview in view.subviews { - if let subview = subview as? UITextField { - subview.textColor = color - } - } - } - } - } -} - -private final class LanguageAccessoryView: UIView { - private let check: UIImageView - private let indicator: ActivityIndicator - - init(theme: PresentationTheme) { - self.check = UIImageView() - self.check.image = PresentationResourcesItemList.checkIconImage(theme) - - self.indicator = ActivityIndicator(type: .custom(theme.list.itemAccentColor, 22.0, 1.0, false)) - - super.init(frame: CGRect()) - - self.addSubview(self.check) - self.addSubnode(self.indicator) - } - - required init?(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - override func sizeToFit() { - self.frame = CGRect(origin: CGPoint(), size: self.check.image!.size) - - let size = self.bounds.size - - if let image = self.check.image { - let checkSize = image.size - self.check.frame = CGRect(origin: CGPoint(x: floor((size.width - checkSize.width) / 2.0), y: floor((size.height - checkSize.height) / 2.0)), size: checkSize) - } - - let indicatorSize = self.indicator.measure(CGSize(width: 100.0, height: 100.0)) - self.indicator.frame = CGRect(origin: CGPoint(x: floor((size.width - indicatorSize.width) / 2.0), y: floor((size.height - indicatorSize.height) / 2.0)), size: indicatorSize) - } - - func setType(_ type: Int) { - switch type { - case 0: - self.check.isHidden = true - self.indicator.isHidden = true - case 1: - self.check.isHidden = false - self.indicator.isHidden = true - case 2: - self.check.isHidden = true - self.indicator.isHidden = false - default: - break - } - } -} - -private final class InnerCoutrySearchResultsController: UIViewController, UITableViewDelegate, UITableViewDataSource { - private let tableView: UITableView - private var presentationData: PresentationData - - var searchResults: [LocalizationInfo] = [] { - didSet { - self.tableView.reloadData() - } - } - - var itemSelected: ((LocalizationInfo) -> Void)? - - init(presentationData : PresentationData) { - self.tableView = UITableView(frame: CGRect(), style: .plain) - self.presentationData = presentationData - - super.init(nibName: nil, bundle: nil) - } - - required init?(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - override func viewDidLoad() { - super.viewDidLoad() - - self.view.backgroundColor = .white - - self.view.addSubview(self.tableView) - if #available(iOSApplicationExtension 11.0, *) { - self.tableView.contentInsetAdjustmentBehavior = .never - } - self.tableView.frame = self.view.bounds - self.tableView.autoresizingMask = [.flexibleWidth, .flexibleHeight] - self.tableView.dataSource = self - self.tableView.delegate = self - - updateThemeAndStrings() - } - - func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return self.searchResults.count - } - - func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: UITableViewCell - if let currentCell = tableView.dequeueReusableCell(withIdentifier: "LanguageCell") { - cell = currentCell - } else { - cell = UITableViewCell(style: .subtitle, reuseIdentifier: "LanguageCell") - cell.selectedBackgroundView = UIView() - } - cell.textLabel?.text = self.searchResults[indexPath.row].title - cell.detailTextLabel?.text = self.searchResults[indexPath.row].localizedTitle - - cell.textLabel?.textColor = self.presentationData.theme.chatList.titleColor - cell.detailTextLabel?.textColor = self.presentationData.theme.chatList.titleColor - cell.backgroundColor = self.presentationData.theme.chatList.itemBackgroundColor - cell.selectedBackgroundView?.backgroundColor = self.presentationData.theme.chatList.itemHighlightedBackgroundColor - - return cell - } - - func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - self.itemSelected?(self.searchResults[indexPath.row]) - } - - func updatePresentationData(_ presentationData : PresentationData) { - let previousTheme = self.presentationData.theme - let previousStrings = self.presentationData.strings - - self.presentationData = presentationData - - if previousTheme !== presentationData.theme || previousStrings !== presentationData.strings { - self.updateThemeAndStrings() - } - } - - private func updateThemeAndStrings() { - self.view.backgroundColor = self.presentationData.theme.chatList.backgroundColor - self.tableView.backgroundColor = self.presentationData.theme.chatList.backgroundColor - self.tableView.separatorColor = self.presentationData.theme.chatList.itemSeparatorColor - - self.tableView.reloadData() - } -} - -private final class InnerLanguageSelectionController: UIViewController, UITableViewDelegate, UITableViewDataSource, UISearchResultsUpdating, UISearchBarDelegate { - private let account: Account - - private let tableView: UITableView - - private var languages: [LocalizationInfo] - - private var searchController: UISearchController! - private var searchResultsController: InnerCoutrySearchResultsController! - - var dismiss: (() -> Void)? - - private var languagesDisposable: Disposable? - - private var presentationData: PresentationData - private var presentationDataDisposable: Disposable? - - private var applyingLanguage: (LocalizationInfo, Disposable)? - - init(account: Account) { - self.account = account - self.presentationData = account.telegramApplicationContext.currentPresentationData.with { $0 } - - self.tableView = UITableView(frame: CGRect(), style: .plain) - - self.languages = [] - - super.init(nibName: nil, bundle: nil) - - self.title = self.presentationData.strings.Settings_AppLanguage - self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: self.presentationData.strings.Common_Done, style: .plain, target: self, action: #selector(self.cancelPressed)) - - self.definesPresentationContext = true - - self.presentationDataDisposable = (account.telegramApplicationContext.presentationData - |> deliverOnMainQueue).start(next: { [weak self] presentationData in - if let strongSelf = self { - let previousTheme = strongSelf.presentationData.theme - let previousStrings = strongSelf.presentationData.strings - - strongSelf.presentationData = presentationData - if strongSelf.searchResultsController != nil { - strongSelf.searchResultsController.updatePresentationData(presentationData) - } - - if previousTheme !== presentationData.theme || previousStrings !== presentationData.strings { - strongSelf.updateThemeAndStrings() - } - } - }) - - self.languagesDisposable = (availableLocalizations(postbox: account.postbox, network: account.network, allowCached: true) - |> deliverOnMainQueue).start(next: { [weak self] languages in - if let strongSelf = self { - strongSelf.languages = languages - if strongSelf.isViewLoaded { - strongSelf.tableView.reloadData() - } - } - }) - } - - required init?(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - deinit { - self.languagesDisposable?.dispose() - self.presentationDataDisposable?.dispose() - self.applyingLanguage?.1.dispose() - } - - private func updateThemeAndStrings() { - self.title = self.presentationData.strings.Settings_AppLanguage - self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: self.presentationData.strings.Common_Done, style: .plain, target: self, action: #selector(self.cancelPressed)) - - if self.isViewLoaded { - self.searchController.searchBar.placeholder = self.presentationData.strings.Common_Search - self.tableView.reloadData() - } - } - - override func viewDidLoad() { - super.viewDidLoad() - - self.view.backgroundColor = .white - - self.searchResultsController = InnerCoutrySearchResultsController(presentationData: self.presentationData) - self.searchResultsController.itemSelected = { [weak self] language in - if let strongSelf = self { - strongSelf.searchController.searchBar.resignFirstResponder() - strongSelf.applyLanguage(language) - } - } - - self.searchController = UISearchController(searchResultsController: self.searchResultsController) - self.searchController.searchResultsUpdater = self - self.searchController.dimsBackgroundDuringPresentation = true - self.searchController.searchBar.delegate = self - self.searchController.searchBar.searchTextPositionAdjustment = UIOffset(horizontal: 6.0, vertical: 0.0) - - self.tableView.autoresizingMask = [.flexibleWidth, .flexibleHeight] - self.view.addSubview(self.tableView) - self.tableView.tableHeaderView = self.searchController.searchBar - self.tableView.dataSource = self - self.tableView.delegate = self - self.tableView.backgroundColor = self.presentationData.theme.chatList.backgroundColor - self.tableView.separatorColor = self.presentationData.theme.chatList.itemSeparatorColor - self.tableView.backgroundView = UIView() - - self.tableView.frame = self.view.bounds - self.view.addSubview(self.tableView) - - self.searchController.searchBar.placeholder = self.presentationData.strings.Common_Search - self.searchController.searchBar.barTintColor = self.presentationData.theme.chatList.backgroundColor - self.searchController.searchBar.tintColor = self.presentationData.theme.rootController.navigationBar.accentTextColor - self.searchController.searchBar.backgroundColor = self.presentationData.theme.chatList.backgroundColor - self.searchController.searchBar.setTextColor(self.presentationData.theme.chatList.titleColor) - - let searchImage = generateImage(CGSize(width: 8.0, height: 28.0), rotatedContext: { size, context in - context.clear(CGRect(origin: CGPoint(), size: size)) - context.setFillColor(self.presentationData.theme.chatList.regularSearchBarColor.cgColor) - context.fillEllipse(in: CGRect(origin: CGPoint(), size: CGSize(width: size.width, height: size.width))) - context.fillEllipse(in: CGRect(origin: CGPoint(x: 0.0, y: size.height - size.width), size: CGSize(width: size.width, height: size.width))) - context.fill(CGRect(origin: CGPoint(x: 0.0, y: size.width / 2.0), size: CGSize(width: size.width, height: size.height - size.width))) - }) - self.searchController.searchBar.setSearchFieldBackgroundImage(searchImage, for: []) - self.searchController.searchBar.backgroundImage = UIImage() - - if let textFieldOfSearchBar = self.searchController.searchBar.value(forKey: "searchField") as? UITextField { - textFieldOfSearchBar.font = Font.regular(14.0) - textFieldOfSearchBar.keyboardAppearance = self.presentationData.theme.chatList.searchBarKeyboardColor == .light ? .default : .dark - } - } - - func numberOfSections(in tableView: UITableView) -> Int { - return 1 - } - - func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - return self.languages.count - } - - func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { - return nil - } - - func sectionIndexTitles(for tableView: UITableView) -> [String]? { - return nil - } - - func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: UITableViewCell - if let currentCell = tableView.dequeueReusableCell(withIdentifier: "LanguageCell") { - cell = currentCell - } else { - cell = UITableViewCell(style: .subtitle, reuseIdentifier: "LanguageCell") - cell.selectedBackgroundView = UIView() - cell.accessoryView = LanguageAccessoryView(theme: self.presentationData.theme) - cell.accessoryView?.sizeToFit() - } - cell.textLabel?.text = self.languages[indexPath.row].title - cell.textLabel?.textColor = self.presentationData.theme.chatList.titleColor - cell.detailTextLabel?.text = self.languages[indexPath.row].localizedTitle - cell.detailTextLabel?.textColor = self.presentationData.theme.chatList.titleColor - cell.backgroundColor = self.presentationData.theme.chatList.itemBackgroundColor - cell.selectedBackgroundView?.backgroundColor = self.presentationData.theme.chatList.itemHighlightedBackgroundColor - - var type: Int = 0 - if let (info, _) = self.applyingLanguage, info.languageCode == self.languages[indexPath.row].languageCode { - type = 2 - } else if self.presentationData.strings.primaryComponent.languageCode == self.languages[indexPath.row].languageCode { - type = 1 - } - - (cell.accessoryView as? LanguageAccessoryView)?.setType(type) - - return cell - } - - func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { - tableView.deselectRow(at: indexPath, animated: true) - self.applyLanguage(self.languages[indexPath.row]) - } - - func updateSearchResults(for searchController: UISearchController) { - guard let normalizedQuery = searchController.searchBar.text?.lowercased() else { - self.searchResultsController.searchResults = [] - return - } - - var results: [LocalizationInfo] = [] - for language in self.languages { - if language.title.lowercased().hasPrefix(normalizedQuery) || language.localizedTitle.lowercased().hasPrefix(normalizedQuery) { - results.append(language) - } - } - self.searchResultsController.searchResults = results - } - - @objc func cancelPressed() { - self.dismiss?() - } - - private func applyLanguage(_ language: LocalizationInfo) { - if let (info, disposable) = self.applyingLanguage { - if info.languageCode == language.languageCode { - return - } else { - disposable.dispose() - self.applyingLanguage = nil - self.tableView.reloadData() - } - } - if language.languageCode != self.presentationData.strings.primaryComponent.languageCode { - self.applyingLanguage = (language, (downloadAndApplyLocalization(postbox: self.account.postbox, network: self.account.network, languageCode: language.languageCode) - |> deliverOnMainQueue).start(completed: { [weak self] in - if let strongSelf = self { - strongSelf.applyingLanguage = nil - strongSelf.tableView.reloadData() - } - })) - self.tableView.reloadData() - } - } -} - -final class LanguageSelectionController: ViewController { - private var controllerNode: LanguageSelectionControllerNode { - return self.displayNode as! LanguageSelectionControllerNode - } - - private let innerNavigationController: UINavigationController - private let innerController: InnerLanguageSelectionController - - private var presentationData: PresentationData - private var presentationDataDisposable: Disposable? - - init(account: Account) { - self.presentationData = account.telegramApplicationContext.currentPresentationData.with { $0 } - - self.innerController = InnerLanguageSelectionController(account: account) - self.innerNavigationController = UINavigationController(rootViewController: self.innerController) - - super.init(navigationBarPresentationData: nil) - - self.statusBar.statusBarStyle = self.presentationData.theme.rootController.statusBar.style.style - self.innerNavigationController.navigationBar.barTintColor = self.presentationData.theme.rootController.navigationBar.backgroundColor - self.innerNavigationController.navigationBar.tintColor = self.presentationData.theme.rootController.navigationBar.accentTextColor - self.innerNavigationController.navigationBar.shadowImage = generateImage(CGSize(width: 1.0, height: 1.0), rotatedContext: { size, context in - context.clear(CGRect(origin: CGPoint(), size: size)) - context.setFillColor(self.presentationData.theme.rootController.navigationBar.separatorColor.cgColor) - context.fill(CGRect(origin: CGPoint(), size: CGSize(width: 1.0, height: UIScreenPixel))) - }) - self.innerNavigationController.navigationBar.isTranslucent = false - self.innerNavigationController.navigationBar.titleTextAttributes = [NSAttributedStringKey.font: Font.semibold(17.0), NSAttributedStringKey.foregroundColor: self.presentationData.theme.rootController.navigationBar.primaryTextColor] - - self.innerController.dismiss = { [weak self] in - self?.cancelPressed() - } - - self.presentationDataDisposable = (account.telegramApplicationContext.presentationData - |> deliverOnMainQueue).start(next: { [weak self] presentationData in - if let strongSelf = self { - let previousTheme = strongSelf.presentationData.theme - let previousStrings = strongSelf.presentationData.strings - - strongSelf.presentationData = presentationData - - if previousTheme !== presentationData.theme || previousStrings !== presentationData.strings { - strongSelf.updateThemeAndStrings() - } - } - }) - } - - required init(coder aDecoder: NSCoder) { - fatalError("init(coder:) has not been implemented") - } - - deinit { - self.presentationDataDisposable?.dispose() - } - - private func updateThemeAndStrings() { - self.statusBar.statusBarStyle = self.presentationData.theme.rootController.statusBar.style.style - } - - override public func loadDisplayNode() { - self.displayNode = LanguageSelectionControllerNode() - self.displayNodeDidLoad() - - self.innerNavigationController.willMove(toParentViewController: self) - self.addChildViewController(self.innerNavigationController) - self.displayNode.view.addSubview(self.innerNavigationController.view) - self.innerNavigationController.didMove(toParentViewController: self) - - self.controllerNode.dismiss = { [weak self] in - self?.presentingViewController?.dismiss(animated: true, completion: nil) - } - } - - override func viewDidAppear(_ animated: Bool) { - super.viewDidAppear(animated) - - self.innerNavigationController.viewWillAppear(false) - self.innerNavigationController.viewDidAppear(false) - - self.controllerNode.animateIn() - } - - override func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) { - super.containerLayoutUpdated(layout, transition: transition) - - self.innerNavigationController.view.frame = CGRect(origin: CGPoint(), size: layout.size) - } - - private func cancelPressed() { - self.controllerNode.animateOut() - } -} diff --git a/TelegramUI/LanguageSelectionControllerNode.swift b/TelegramUI/LanguageSelectionControllerNode.swift deleted file mode 100644 index 73ea7d8ad7..0000000000 --- a/TelegramUI/LanguageSelectionControllerNode.swift +++ /dev/null @@ -1,33 +0,0 @@ -import Foundation -import AsyncDisplayKit -import Display -import TelegramCore - -final class LanguageSelectionControllerNode: ASDisplayNode { - var dismiss: (() -> Void)? - - override init() { - super.init() - - self.setViewBlock({ - return UITracingLayerView() - }) - - self.backgroundColor = UIColor.white - } - - func containerLayoutUpdated(_ layout: ContainerViewLayout, navigationBarHeight: CGFloat, transition: ContainedViewLayoutTransition) { - } - - func animateIn() { - self.layer.animatePosition(from: CGPoint(x: self.layer.position.x, y: self.layer.position.y + self.layer.bounds.size.height), to: self.layer.position, duration: 0.5, timingFunction: kCAMediaTimingFunctionSpring) - } - - func animateOut() { - self.layer.animatePosition(from: self.layer.position, to: CGPoint(x: self.layer.position.x, y: self.layer.position.y + self.layer.bounds.size.height), duration: 0.2, timingFunction: kCAMediaTimingFunctionEaseInEaseOut, removeOnCompletion: false, completion: { [weak self] _ in - if let strongSelf = self { - strongSelf.dismiss?() - } - }) - } -} diff --git a/TelegramUI/NotificationExceptionControllerNode.swift b/TelegramUI/NotificationExceptionControllerNode.swift index 8332fe48d9..5c9cae2a7e 100644 --- a/TelegramUI/NotificationExceptionControllerNode.swift +++ b/TelegramUI/NotificationExceptionControllerNode.swift @@ -988,19 +988,19 @@ private final class NotificationExceptionsSearchContainerNode: SearchDisplayCont self.presentationDataDisposable = (account.telegramApplicationContext.presentationData - |> deliverOnMainQueue).start(next: { [weak self] presentationData in - if let strongSelf = self { - let previousTheme = strongSelf.presentationData.theme - let previousStrings = strongSelf.presentationData.strings - - strongSelf.presentationData = presentationData - - if previousTheme !== presentationData.theme || previousStrings !== presentationData.strings { - strongSelf.updateThemeAndStrings(theme: presentationData.theme, strings: presentationData.strings) - strongSelf.themeAndStringsPromise.set(.single((presentationData.theme, presentationData.strings))) - } + |> deliverOnMainQueue).start(next: { [weak self] presentationData in + if let strongSelf = self { + let previousTheme = strongSelf.presentationData.theme + let previousStrings = strongSelf.presentationData.strings + + strongSelf.presentationData = presentationData + + if previousTheme !== presentationData.theme || previousStrings !== presentationData.strings { + strongSelf.updateThemeAndStrings(theme: presentationData.theme, strings: presentationData.strings) + strongSelf.themeAndStringsPromise.set(.single((presentationData.theme, presentationData.strings))) } - }) + } + }) self.listNode.beganInteractiveDragging = { [weak self] in self?.dismissInput?() @@ -1101,61 +1101,3 @@ private final class NotificationExceptionsSearchContainerNode: SearchDisplayCont } } } - - -/* - - let globalSettings = globalValue.modify {$0} - - let isPrivateChat = peerId.namespace == Namespaces.Peer.CloudUser - - - let actionSheet = ActionSheetController(presentationTheme: presentationData.theme) - - var items: [ActionSheetItem] = [] - - - // ActionSheetButtonItem(title: isPrivateChat && globalSettings.privateChats.enabled || !isPrivateChat && globalSettings.groupChats.enabled ? presentationData.strings.UserInfo_NotificationsDefaultEnabled : presentationData.strings.UserInfo_NotificationsDefaultDisabled, color: .accent, action: { [weak actionSheet] in - // updatePeerNotificationInterval(peerId, nil) - // actionSheet?.dismissAnimated() - // }), - - items.append(ActionSheetButtonItem(title: presentationData.strings.UserInfo_NotificationsEnable, color: .accent, action: { [weak actionSheet] in - actionSheet?.dismissAnimated() - updatePeerNotificationInterval(peerId, 0) - })) - - items.append(ActionSheetButtonItem(title: presentationData.strings.Notification_Mute1h, color: .accent, action: { [weak actionSheet] in - actionSheet?.dismissAnimated() - updatePeerNotificationInterval(peerId, 60 * 60) - })) - - items.append(ActionSheetButtonItem(title: presentationData.strings.MuteFor_Days(2), color: .accent, action: { [weak actionSheet] in - actionSheet?.dismissAnimated() - updatePeerNotificationInterval(peerId, 60 * 60 * 24 * 2) - })) - items.append(ActionSheetButtonItem(title: presentationData.strings.UserInfo_NotificationsDisable, color: .accent, action: { [weak actionSheet] in - updatePeerNotificationInterval(peerId, Int32.max) - actionSheet?.dismissAnimated() - })) - - items.append(ActionSheetButtonItem(title: presentationData.strings.Notifications_ExceptionsChangeSound(localizedPeerNotificationSoundString(strings: presentationData.strings, sound: settings.messageSound)).0, color: .accent, action: { [weak actionSheet] in - let controller = notificationSoundSelectionController(account: account, isModal: true, currentSound: settings.messageSound, defaultSound: isPrivateChat ? globalSettings.privateChats.sound : globalSettings.groupChats.sound, completion: { value in - updatePeerSound(peerId, value) - }) - presentControllerImpl?(controller, ViewControllerPresentationArguments(presentationAnimation: .modalSheet)) - actionSheet?.dismissAnimated() - })) - items.append(ActionSheetButtonItem(title: presentationData.strings.Notifications_ExceptionsResetToDefaults, color: .destructive, action: { [weak actionSheet] in - updatePeerNotificationInterval(peerId, nil) - updatePeerSound(peerId, .default) - actionSheet?.dismissAnimated() - })) - - actionSheet.setItemGroups([ActionSheetItemGroup(items: items), ActionSheetItemGroup(items: [ - ActionSheetButtonItem(title: presentationData.strings.Common_Cancel, color: .accent, action: { [weak actionSheet] in - actionSheet?.dismissAnimated() - }) - ])]) - presentControllerImpl?(actionSheet, nil) - */ diff --git a/TelegramUI/NotificationExceptions.swift b/TelegramUI/NotificationExceptions.swift index 3e8bae31f7..f318551f59 100644 --- a/TelegramUI/NotificationExceptions.swift +++ b/TelegramUI/NotificationExceptions.swift @@ -4,9 +4,6 @@ import SwiftSignalKit import Postbox import TelegramCore - - - public class NotificationExceptionsController: ViewController { private let account: Account @@ -146,491 +143,3 @@ public class NotificationExceptionsController: ViewController { } } } - - - -// -// -//public func notificationExceptionsController(account: Account, mode: NotificationExceptionMode, updatedMode:@escaping(NotificationExceptionMode) -> Void) -> ViewController { -// -// -// var activateSearch:(()->Void)? -// -// -// -// -// let controller = NotificationExceptionsController(account: account, state: signal, addAction: { -// arguments.selectPeer() -// }) -// -//// let controller = ItemListController(account: account, state: signal |> afterDisposed { -//// actionsDisposable.dispose() -//// }) -// -// -// activateSearch = { [weak controller] in -//// updateState { state in -//// return state.withUpdatedSearchMode(true) -//// } -// controller?.activateSearch() -// } -// -// -// presentControllerImpl = { [weak controller] c, a in -// controller?.present(c, in: .window(.root), with: a) -// } -// return controller -//} - -// -// private final class NotificationExceptionsController: ViewController { -// private let account: Account -// -// private var presentationData: PresentationData -// private var presentationDataDisposable: Disposable? -// -// var peerSelected: ((PeerId) -> Void)? -// -// var inProgress: Bool = false { -// didSet { -// if self.inProgress != oldValue { -// if self.isNodeLoaded { -// self.controllerNode.inProgress = self.inProgress -// } -// -// if self.inProgress { -// self.navigationItem.rightBarButtonItem = UIBarButtonItem(customDisplayNode: ProgressNavigationButtonNode(theme: self.presentationData.theme)) -// } else { -// self.navigationItem.rightBarButtonItem = nil -// } -// } -// } -// } -// -// private var controllerNode: NotificationExceptionsControllerNode { -// return super.displayNode as! NotificationExceptionsControllerNode -// } -// -// -// private let _ready = Promise() -// override public var ready: Promise { -// return self._ready -// } -// private let addAction:()->Void -// -// private let state: Signal<(ItemListControllerState, (ItemListNodeState, NotificationExceptionEntry.ItemGenerationArguments)), NoError> -// -// public init(account: Account, state: Signal<(ItemListControllerState, (ItemListNodeState, NotificationExceptionEntry.ItemGenerationArguments)), NoError>, addAction: @escaping()->Void) { -// self.account = account -// self.state = state -// self.addAction = addAction -// self.presentationData = account.telegramApplicationContext.currentPresentationData.with { $0 } -// -// super.init(navigationBarPresentationData: NavigationBarPresentationData(presentationData: self.presentationData)) -// self.statusBar.statusBarStyle = self.presentationData.theme.rootController.statusBar.style.style -// -// self.title = self.presentationData.strings.Notifications_ExceptionsTitle -// -// -// self.scrollToTop = { [weak self] in -// if let strongSelf = self { -// strongSelf.controllerNode.scrollToTop() -// } -// } -// } -// -// required public init(coder aDecoder: NSCoder) { -// fatalError("init(coder:) has not been implemented") -// } -// -// deinit { -// } -// -// @objc private func addExceptionAction() { -// self.addAction() -// } -// -// override public func loadDisplayNode() { -// let image = PresentationResourcesRootController.navigationAddIcon(presentationData.theme) -// -// self.navigationItem.rightBarButtonItem = UIBarButtonItem(image: image, style: UIBarButtonItem.Style.plain, target: self, action: #selector(addExceptionAction)) -// -// let nodeState = self.state |> deliverOnMainQueue |> map { ($0.theme, $1) } -// -// self.displayNode = NotificationExceptionsControllerNode(account: self.account, navigationBar: self.navigationBar!, state: nodeState) -// self.displayNode.backgroundColor = .white -// -// self.controllerNode.navigationBar = self.navigationBar -// -// self.controllerNode.requestDeactivateSearch = { [weak self] in -// self?.deactivateSearch() -// } -// -// self.controllerNode.requestActivateSearch = { [weak self] in -// self?.activateSearch() -// } -// -// self.displayNodeDidLoad() -// -// self._ready.set(self.controllerNode.ready) -// } -// -// override public func viewWillAppear(_ animated: Bool) { -// super.viewWillAppear(animated) -// } -// -// override public func viewDidAppear(_ animated: Bool) { -// super.viewDidAppear(animated) -// -// // self.controllerNode.animateIn() -// } -// -// override public func viewDidDisappear(_ animated: Bool) { -// super.viewDidDisappear(animated) -// } -// -// override public func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) { -// super.containerLayoutUpdated(layout, transition: transition) -// -// self.controllerNode.containerLayoutUpdated(layout, navigationBarHeight: self.navigationHeight, transition: transition) -// } -// -// @objc func cancelPressed() { -// self.dismiss() -// } -// -// func activateSearch() { -// if self.displayNavigationBar { -// if let scrollToTop = self.scrollToTop { -// scrollToTop() -// } -// self.controllerNode.activateSearch() -// self.setDisplayNavigationBar(false, transition: .animated(duration: 0.5, curve: .spring)) -// } -// } -// -// private func deactivateSearch() { -// if !self.displayNavigationBar { -// self.setDisplayNavigationBar(true, transition: .animated(duration: 0.5, curve: .spring)) -// self.controllerNode.deactivateSearch() -// } -// } -//} -// -// -// -//private final class NotificationExceptionsControllerNode: ASDisplayNode { -// private let account: Account -// -// var inProgress: Bool = false { -// didSet { -// -// } -// } -// -// var navigationBar: NavigationBar? -// -// -// private let contentNode: ItemListControllerNode -// -// private var contactListActive = false -// -// private var searchDisplayController: SearchDisplayController? -// -// private var containerLayout: (ContainerViewLayout, CGFloat)? -// -// var requestActivateSearch: (() -> Void)? -// var requestDeactivateSearch: (() -> Void)? -// -// private var presentationData: PresentationData -// private var presentationDataDisposable: Disposable? -// -// private var readyValue = Promise() -// var ready: Signal { -// return self.readyValue.get() -// } -// -// private let state: Signal<(PresentationTheme, (ItemListNodeState, NotificationExceptionEntry.ItemGenerationArguments)), NoError> -// -// init(account: Account, navigationBar: NavigationBar, state: Signal<(PresentationTheme, (ItemListNodeState, NotificationExceptionEntry.ItemGenerationArguments)), NoError>) { -// self.account = account -// self.state = state -// self.presentationData = account.telegramApplicationContext.currentPresentationData.with { $0 } -// -// -// self.contentNode = ItemListControllerNode(navigationBar: navigationBar, updateNavigationOffset: { _ in -// -// }, state: state) -// -// contentNode.listNode.keepTopItemOverscrollBackground = ListViewKeepTopItemOverscrollBackground(color: presentationData.theme.chatList.backgroundColor, direction: true) -// contentNode.listNode.keepBottomItemOverscrollBackground = presentationData.theme.chatList.backgroundColor -// -// super.init() -// -// self.setViewBlock({ -// return UITracingLayerView() -// }) -// -// self.addSubnode(self.contentNode) -// self.presentationDataDisposable = (account.telegramApplicationContext.presentationData -// |> deliverOnMainQueue).start(next: { [weak self] presentationData in -// if let strongSelf = self { -// let previousTheme = strongSelf.presentationData.theme -// let previousStrings = strongSelf.presentationData.strings -// strongSelf.presentationData = presentationData -// if previousTheme !== presentationData.theme || previousStrings !== presentationData.strings { -// strongSelf.updateThemeAndStrings() -// } -// } -// }) -// -// self.readyValue.set(contentNode.ready) -// } -// -// deinit { -// self.presentationDataDisposable?.dispose() -// } -// -// private func updateThemeAndStrings() { -// self.searchDisplayController?.updateThemeAndStrings(theme: self.presentationData.theme, strings: self.presentationData.strings) -// } -// -// func containerLayoutUpdated(_ layout: ContainerViewLayout, navigationBarHeight: CGFloat, transition: ContainedViewLayoutTransition) { -// self.containerLayout = (layout, navigationBarHeight) -// -// let cleanInsets = layout.insets(options: []) -// -// -// var controlSize = CGSize(width: 0, height:0) -// controlSize.width = min(layout.size.width, max(200.0, controlSize.width)) -// -// var insets = layout.insets(options: [.input]) -// insets.top += max(navigationBarHeight, layout.insets(options: [.statusBar]).top) -// insets.bottom = max(insets.bottom, cleanInsets.bottom) -// insets.left += layout.safeInsets.left -// insets.right += layout.safeInsets.right -// -// self.contentNode.bounds = CGRect(x: 0.0, y: 0.0, width: layout.size.width, height: layout.size.height) -// self.contentNode.position = CGPoint(x: layout.size.width / 2.0, y: layout.size.height / 2.0) -// -// self.contentNode.containerLayoutUpdated(layout, navigationBarHeight: insets.top, transition: transition) -// -// if let searchDisplayController = self.searchDisplayController { -// searchDisplayController.containerLayoutUpdated(layout, navigationBarHeight: navigationBarHeight, transition: transition) -// } -// } -// -// func activateSearch() { -// guard let (containerLayout, navigationBarHeight) = self.containerLayout, let navigationBar = self.navigationBar else { -// return -// } -// -// if self.contentNode.supernode != nil { -// var maybePlaceholderNode: SearchBarPlaceholderNode? -// self.contentNode.listNode.forEachItemNode { node in -// if let node = node as? NotificationSearchItemNode { -// maybePlaceholderNode = node.searchBarNode -// } -// } -// -// if let _ = self.searchDisplayController { -// return -// } -// -// if let placeholderNode = maybePlaceholderNode { -// self.searchDisplayController = SearchDisplayController(theme: self.presentationData.theme, strings: self.presentationData.strings, contentNode: NotificationExceptionsSearchControllerContentNode(account: account, navigationBar: navigationBar, state: self.state), cancel: { [weak self] in -// self?.requestDeactivateSearch?() -// }) -// -// self.searchDisplayController?.containerLayoutUpdated(containerLayout, navigationBarHeight: navigationBarHeight, transition: .immediate) -// self.searchDisplayController?.activate(insertSubnode: { subnode in -// self.insertSubnode(subnode, belowSubnode: navigationBar) -// }, placeholder: placeholderNode) -// } -// } -// } -// -// func deactivateSearch() { -// if let searchDisplayController = self.searchDisplayController { -// if self.contentNode.supernode != nil { -// var maybePlaceholderNode: SearchBarPlaceholderNode? -// self.contentNode.listNode.forEachItemNode { node in -// if let node = node as? NotificationSearchItemNode { -// maybePlaceholderNode = node.searchBarNode -// } -// } -// -// searchDisplayController.deactivate(placeholder: maybePlaceholderNode) -// self.searchDisplayController = nil -// } -// } -// } -// -// func scrollToTop() { -// if self.contentNode.supernode != nil { -// self.contentNode.scrollToTop() -// } -// } -// -// -//} -// -// -// -// -// -// -//private final class NotificationExceptionsSearchControllerContentNode: SearchDisplayControllerContentNode { -// private let account: Account -// -// private let listNode: ItemListControllerNode -// private let dimNode: ASDisplayNode -// private var validLayout: ContainerViewLayout? -// -// -// private let searchQuery = Promise() -// private let searchDisposable = MetaDisposable() -// -// private var presentationData: PresentationData -// private var presentationDataDisposable: Disposable? -// -// private let presentationDataPromise: Promise -// -// private let _isSearching = ValuePromise(false, ignoreRepeated: true) -// override var isSearching: Signal { -// return self._isSearching.get() -// } -// -// private let state: Signal<(PresentationTheme, (ItemListNodeState, NotificationExceptionEntry.ItemGenerationArguments)), NoError> -// -// -// init(account: Account, navigationBar: NavigationBar, state: Signal<(PresentationTheme, (ItemListNodeState, NotificationExceptionEntry.ItemGenerationArguments)), NoError>) { -// self.account = account -// self.state = state -// -// self.presentationData = account.telegramApplicationContext.currentPresentationData.with { $0 } -// self.presentationDataPromise = Promise(ChatListPresentationData(theme: self.presentationData.theme, strings: self.presentationData.strings, dateTimeFormat: self.presentationData.dateTimeFormat, nameSortOrder: self.presentationData.nameSortOrder, nameDisplayOrder: self.presentationData.nameDisplayOrder, disableAnimations: self.presentationData.disableAnimations)) -// -// self.listNode = ItemListControllerNode(navigationBar: navigationBar, updateNavigationOffset: { _ in -// -// }, state: searchQuery.get() |> mapToSignal { query in -// return state |> map { values in -// var values = values -// let entries = values.1.0.entries.filter { entry in -// switch entry { -// case .search: -// return false -// case let .peer(_, peer, _, _, _, _, _): -// if let query = query { -// return !peer.displayTitle.components(separatedBy: " ").filter({$0.lowercased().hasPrefix(query.lowercased())}).isEmpty && !query.isEmpty -// } else { -// return false -// } -// } -// } -// values.1.0 = ItemListNodeState(entries: entries, style: values.1.0.style, focusItemTag: nil, emptyStateItem: nil, searchItem: nil, crossfadeState: false, animateChanges: false) -// return values -// } -// }) -// -// listNode.listNode.keepTopItemOverscrollBackground = ListViewKeepTopItemOverscrollBackground(color: presentationData.theme.chatList.backgroundColor, direction: true) -// listNode.listNode.keepBottomItemOverscrollBackground = presentationData.theme.chatList.backgroundColor -// -// -// self.dimNode = ASDisplayNode() -// self.dimNode.backgroundColor = UIColor.black.withAlphaComponent(0.5) -// -// super.init() -// -// -// self.addSubnode(self.dimNode) -// self.addSubnode(self.listNode) -// self.listNode.isHidden = true -// -// self.presentationDataDisposable = (account.telegramApplicationContext.presentationData -// |> deliverOnMainQueue).start(next: { [weak self] presentationData in -// if let strongSelf = self { -// let previousTheme = strongSelf.presentationData.theme -// -// strongSelf.presentationData = presentationData -// -// if previousTheme !== presentationData.theme { -// strongSelf.updateTheme(theme: presentationData.theme) -// } -// } -// }) -// -// } -// -// deinit { -// self.searchDisposable.dispose() -// self.presentationDataDisposable?.dispose() -// } -// -// private func updateTheme(theme: PresentationTheme) { -// self.backgroundColor = theme.chatList.backgroundColor -// } -// -// override func didLoad() { -// super.didLoad() -// -// self.dimNode.view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.dimTapGesture(_:)))) -// } -// -// @objc func dimTapGesture(_ recognizer: UITapGestureRecognizer) { -// if case .ended = recognizer.state { -// self.cancel?() -// } -// } -// -// override func searchTextUpdated(text: String) { -// if text.isEmpty { -// self.searchQuery.set(.single(nil)) -// self.listNode.isHidden = true -// } else { -// self.searchQuery.set(.single(text)) -// self.listNode.isHidden = false -// } -// -// } -// -// override func containerLayoutUpdated(_ layout: ContainerViewLayout, navigationBarHeight: CGFloat, transition: ContainedViewLayoutTransition) { -// super.containerLayoutUpdated(layout, navigationBarHeight: navigationBarHeight, transition: transition) -// -// let hadValidLayout = self.validLayout != nil -// self.validLayout = layout -// -// var duration: Double = 0.0 -// var curve: UInt = 0 -// switch transition { -// case .immediate: -// break -// case let .animated(animationDuration, animationCurve): -// duration = animationDuration -// switch animationCurve { -// case .easeInOut: -// break -// case .spring: -// curve = 7 -// } -// } -// -// -// let listViewCurve: ListViewAnimationCurve -// if curve == 7 { -// listViewCurve = .Spring(duration: duration) -// } else { -// listViewCurve = .Default(duration: duration) -// } -// -// self.listNode.containerLayoutUpdated(layout, navigationBarHeight: 0, transition: transition) -// -// let insets = UIEdgeInsets(top: navigationBarHeight - 30, left: layout.safeInsets.left, bottom: layout.insets(options: [.input]).bottom, right: layout.safeInsets.right) -// -// transition.updateFrame(node: self.dimNode, frame: CGRect(origin: CGPoint(x: 0.0, y: insets.top), size: CGSize(width: layout.size.width, height: layout.size.height - insets.top))) -// -// self.listNode.frame = CGRect(origin: CGPoint(), size: layout.size) -// self.listNode.listNode.transaction(deleteIndices: [], insertIndicesAndItems: [], updateIndicesAndItems: [], options: [.Synchronous], scrollToItem: nil, updateSizeAndInsets: ListViewUpdateSizeAndInsets(size: layout.size, insets: UIEdgeInsets(top: navigationBarHeight - 30, left: layout.safeInsets.left, bottom: layout.insets(options: [.input]).bottom, right: layout.safeInsets.right), duration: duration, curve: listViewCurve), stationaryItemRange: nil, updateOpaqueState: nil, completion: { _ in }) -// } -// -//} diff --git a/TelegramUI/PeerMediaCollectionController.swift b/TelegramUI/PeerMediaCollectionController.swift index f5b4d7e64d..6eb255411f 100644 --- a/TelegramUI/PeerMediaCollectionController.swift +++ b/TelegramUI/PeerMediaCollectionController.swift @@ -64,19 +64,19 @@ public class PeerMediaCollectionController: TelegramController { } self.presentationDataDisposable = (account.telegramApplicationContext.presentationData - |> deliverOnMainQueue).start(next: { [weak self] presentationData in - if let strongSelf = self { - let previousTheme = strongSelf.presentationData.theme - let previousStrings = strongSelf.presentationData.strings - let previousChatWallpaper = strongSelf.presentationData.chatWallpaper - - strongSelf.presentationData = presentationData - - if previousTheme !== presentationData.theme || previousStrings !== presentationData.strings || presentationData.chatWallpaper != previousChatWallpaper { - strongSelf.themeAndStringsUpdated() - } + |> deliverOnMainQueue).start(next: { [weak self] presentationData in + if let strongSelf = self { + let previousTheme = strongSelf.presentationData.theme + let previousStrings = strongSelf.presentationData.strings + let previousChatWallpaper = strongSelf.presentationData.chatWallpaper + + strongSelf.presentationData = presentationData + + if previousTheme !== presentationData.theme || previousStrings !== presentationData.strings || presentationData.chatWallpaper != previousChatWallpaper { + strongSelf.themeAndStringsUpdated() } - }) + } + }) let controllerInteraction = ChatControllerInteraction(openMessage: { [weak self] message, mode in if let strongSelf = self, strongSelf.isNodeLoaded, let galleryMessage = strongSelf.mediaCollectionDisplayNode.messageForGallery(message.id) { diff --git a/TelegramUI/SettingsController.swift b/TelegramUI/SettingsController.swift index a94e4d5b98..25c56d716a 100644 --- a/TelegramUI/SettingsController.swift +++ b/TelegramUI/SettingsController.swift @@ -528,8 +528,6 @@ public func settingsController(account: Account, accountManager: AccountManager) }, presentController: { controller in presentControllerImpl?(controller, nil) }, openLanguage: { - //let controller = LanguageSelectionController(account: account) - //presentControllerImpl?(controller, nil) pushControllerImpl?(LocalizationListController(account: account)) }, openPassport: { let controller = SecureIdAuthController(account: account, mode: .list) diff --git a/TelegramUI/ShareController.swift b/TelegramUI/ShareController.swift index 4dd796d2ec..7df2d2b6b9 100644 --- a/TelegramUI/ShareController.swift +++ b/TelegramUI/ShareController.swift @@ -201,13 +201,6 @@ public final class ShareController: ViewController { super.init(navigationBarPresentationData: nil) - self.presentationDataDisposable = (self.account.telegramApplicationContext.presentationData - |> deliverOnMainQueue).start(next: { [weak self] presentationData in - if let strongSelf = self { - strongSelf.controllerNode.updatePresentationData(presentationData) - } - }) - switch subject { case let .url(text): self.defaultAction = ShareControllerAction(title: self.presentationData.strings.ShareMenu_CopyShareLink, action: { [weak self] in @@ -303,6 +296,13 @@ public final class ShareController: ViewController { } return (peers, accountPeer) }) + + self.presentationDataDisposable = (self.account.telegramApplicationContext.presentationData + |> deliverOnMainQueue).start(next: { [weak self] presentationData in + if let strongSelf = self, strongSelf.isNodeLoaded { + strongSelf.controllerNode.updatePresentationData(presentationData) + } + }) } required public init(coder aDecoder: NSCoder) { diff --git a/TelegramUI/ShareControllerNode.swift b/TelegramUI/ShareControllerNode.swift index 4dd631c0b3..ec46e4487a 100644 --- a/TelegramUI/ShareControllerNode.swift +++ b/TelegramUI/ShareControllerNode.swift @@ -232,6 +232,9 @@ final class ShareControllerNode: ViewControllerTracingNode, UIScrollViewDelegate } func updatePresentationData(_ presentationData: PresentationData) { + guard self.presentationData !== presentationData else { + return + } self.presentationData = presentationData let roundedBackground = generateStretchableFilledCircleImage(radius: 16.0, color: self.presentationData.theme.actionSheet.opaqueItemBackgroundColor) diff --git a/TelegramUI/StickerPackPreviewController.swift b/TelegramUI/StickerPackPreviewController.swift index d27939a137..64a6317403 100644 --- a/TelegramUI/StickerPackPreviewController.swift +++ b/TelegramUI/StickerPackPreviewController.swift @@ -59,7 +59,7 @@ final class StickerPackPreviewController: ViewController { self.presentationDataDisposable = (self.account.telegramApplicationContext.presentationData |> deliverOnMainQueue).start(next: { [weak self] presentationData in - if let strongSelf = self { + if let strongSelf = self, strongSelf.isNodeLoaded { strongSelf.controllerNode.updatePresentationData(presentationData) } })