From 21c012ab92aab06df06edc9db7312faf12d96d42 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Tue, 3 Sep 2019 22:20:37 +0300 Subject: [PATCH] Various UI fixes --- .../TelegramInitializeLegacyComponents.swift | 3 +- ...emeAutoNightTimeSelectionActionSheet.swift | 2 +- .../Themes/ThemePreviewController.swift | 39 +++++++++++++++---- .../Themes/ThemePreviewControllerNode.swift | 19 ++++++++- .../ChatScheduleTimeControllerNode.swift | 2 +- 5 files changed, 53 insertions(+), 12 deletions(-) diff --git a/submodules/LegacyUI/Sources/TelegramInitializeLegacyComponents.swift b/submodules/LegacyUI/Sources/TelegramInitializeLegacyComponents.swift index c456274e06..61511afe1b 100644 --- a/submodules/LegacyUI/Sources/TelegramInitializeLegacyComponents.swift +++ b/submodules/LegacyUI/Sources/TelegramInitializeLegacyComponents.swift @@ -340,8 +340,9 @@ private final class LegacyComponentsGlobalsProviderImpl: NSObject, LegacyCompone let theme = presentationTheme.list let navigationBar = presentationTheme.rootController.navigationBar + let tabBar = presentationTheme.rootController.tabBar - return TGMediaAssetsPallete(dark: presentationTheme.overallDarkAppearance, backgroundColor: theme.plainBackgroundColor, selectionColor: theme.itemHighlightedBackgroundColor, separatorColor: theme.itemPlainSeparatorColor, textColor: theme.itemPrimaryTextColor, secondaryTextColor: theme.controlSecondaryColor, accentColor: theme.itemAccentColor, barBackgroundColor: navigationBar.backgroundColor, barSeparatorColor: navigationBar.separatorColor, navigationTitleColor: navigationBar.primaryTextColor, badge: generateStretchableFilledCircleImage(diameter: 22.0, color: navigationBar.accentTextColor), badgeTextColor: navigationBar.backgroundColor, sendIconImage: PresentationResourcesChat.chatInputPanelSendButtonImage(presentationTheme), maybeAccentColor: navigationBar.accentTextColor) + return TGMediaAssetsPallete(dark: presentationTheme.overallDarkAppearance, backgroundColor: theme.plainBackgroundColor, selectionColor: theme.itemHighlightedBackgroundColor, separatorColor: theme.itemPlainSeparatorColor, textColor: theme.itemPrimaryTextColor, secondaryTextColor: theme.controlSecondaryColor, accentColor: theme.itemAccentColor, barBackgroundColor: tabBar.backgroundColor, barSeparatorColor: tabBar.separatorColor, navigationTitleColor: navigationBar.primaryTextColor, badge: generateStretchableFilledCircleImage(diameter: 22.0, color: navigationBar.accentTextColor), badgeTextColor: navigationBar.backgroundColor, sendIconImage: PresentationResourcesChat.chatInputPanelSendButtonImage(presentationTheme), maybeAccentColor: navigationBar.accentTextColor) } func checkButtonPallete() -> TGCheckButtonPallete! { diff --git a/submodules/SettingsUI/Sources/Themes/ThemeAutoNightTimeSelectionActionSheet.swift b/submodules/SettingsUI/Sources/Themes/ThemeAutoNightTimeSelectionActionSheet.swift index 28d287d72f..099743aaa1 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemeAutoNightTimeSelectionActionSheet.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemeAutoNightTimeSelectionActionSheet.swift @@ -101,7 +101,7 @@ private final class ThemeAutoNightTimeSelectionActionSheetItemNode: ActionSheetI self.pickerView.datePickerMode = .time self.pickerView.timeZone = TimeZone(secondsFromGMT: 0) self.pickerView.date = Date(timeIntervalSince1970: Double(currentValue)) - self.pickerView.locale = localeWithStrings(strings) + self.pickerView.locale = Locale.current self.pickerView.setValue(theme.primaryTextColor, forKey: "textColor") diff --git a/submodules/SettingsUI/Sources/Themes/ThemePreviewController.swift b/submodules/SettingsUI/Sources/Themes/ThemePreviewController.swift index d06533defc..e154ea0f28 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemePreviewController.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemePreviewController.swift @@ -24,13 +24,12 @@ public final class ThemePreviewController: ViewController { private let previewTheme: PresentationTheme private let source: ThemePreviewSource private let theme = Promise() + private let presentationTheme = Promise() private var controllerNode: ThemePreviewControllerNode { return self.displayNode as! ThemePreviewControllerNode } - - private let titleView: CounterContollerTitleView - + private var didPlayPresentationAnimation = false private var presentationData: PresentationData @@ -45,8 +44,11 @@ public final class ThemePreviewController: ViewController { self.source = source self.presentationData = context.sharedContext.currentPresentationData.with { $0 } + self.presentationTheme.set(.single(previewTheme)) - self.titleView = CounterContollerTitleView(theme: self.previewTheme) + let titleView = CounterContollerTitleView(theme: self.previewTheme) + titleView.title = CounterContollerTitle(title: themeName, counter: " ") + strongSelf.titleView = titleView super.init(navigationBarPresentationData: NavigationBarPresentationData(presentationTheme: self.previewTheme, presentationStrings: self.presentationData.strings)) @@ -61,12 +63,29 @@ public final class ThemePreviewController: ViewController { return .single(nil) }) themeName = previewTheme.name.string + + self.presentationTheme.set(.single(self.previewTheme) + |> then( + self.theme.get() + |> mapToSignal { theme in + if let file = theme?.file { + return telegramThemeData(account: context.account, accountManager: context.sharedContext.accountManager, resource: file.resource) + |> mapToSignal { data -> Signal in + guard let data = data, let presentationTheme = makePresentationTheme(data: data) else { + return .complete() + } + return .single(presentationTheme) + } + } else { + return .complete() + } + } + )) } else { self.theme.set(.single(nil)) themeName = previewTheme.name.string } - self.titleView.title = CounterContollerTitle(title: themeName, counter: " ") self.navigationItem.titleView = titleView self.statusBar.statusBarStyle = self.previewTheme.rootController.statusBarStyle.style @@ -74,10 +93,14 @@ public final class ThemePreviewController: ViewController { self.navigationItem.rightBarButtonItem = UIBarButtonItem(image: generateTintedImage(image: UIImage(bundleImageName: "Chat/Input/Accessory Panels/MessageSelectionAction"), color: self.previewTheme.rootController.navigationBar.accentTextColor), style: .plain, target: self, action: #selector(self.actionPressed)) - self.disposable = (self.theme.get() - |> deliverOnMainQueue).start(next: { [weak self] theme in + self.disposable = (combineLatest(self.theme.get(), self.presentationTheme.get()) + |> deliverOnMainQueue).start(next: { [weak self] theme, presentationTheme in if let strongSelf = self, let theme = theme { - strongSelf.titleView.title = CounterContollerTitle(title: themeName, counter: strongSelf.presentationData.strings.Theme_UsersCount(max(1, theme.installCount))) + let titleView = CounterContollerTitleView(theme: strongSelf.previewTheme) + titleView.title = CounterContollerTitle(title: themeName, counter: strongSelf.presentationData.strings.Theme_UsersCount(max(1, theme.installCount))) + strongSelf.titleView = titleView + strongSelf.navigationItem.titleView = titleView + strongSelf.navigationBar?.updatePresentationData(NavigationBarPresentationData(presentationTheme: presentationTheme, presentationStrings: strongSelf.presentationData.strings)) } }) diff --git a/submodules/SettingsUI/Sources/Themes/ThemePreviewControllerNode.swift b/submodules/SettingsUI/Sources/Themes/ThemePreviewControllerNode.swift index fd3627c7f6..dfe1798b62 100644 --- a/submodules/SettingsUI/Sources/Themes/ThemePreviewControllerNode.swift +++ b/submodules/SettingsUI/Sources/Themes/ThemePreviewControllerNode.swift @@ -29,7 +29,7 @@ private func generateMaskImage(color: UIColor) -> UIImage? { final class ThemePreviewControllerNode: ASDisplayNode, UIScrollViewDelegate { private let context: AccountContext - private let previewTheme: PresentationTheme + private var previewTheme: PresentationTheme private var presentationData: PresentationData public let wallpaperPromise = Promise() @@ -266,6 +266,23 @@ final class ThemePreviewControllerNode: ASDisplayNode, UIScrollViewDelegate { self.pageControlNode.setPage(0.0) } + func updateTheme(_ theme: PresentationTheme) { + self.previewTheme = theme + + self.backgroundColor = self.previewTheme.list.plainBackgroundColor + self.chatListBackgroundNode.backgroundColor = self.previewTheme.chatList.backgroundColor + self.maskNode.image = generateMaskImage(color: self.previewTheme.chatList.backgroundColor) + if case let .color(value) = self.previewTheme.chat.defaultWallpaper { + self.instantChatBackgroundNode.backgroundColor = UIColor(rgb: UInt32(bitPattern: value)) + } + + self.toolbarNode.updateThemeAndStrings(theme: self.previewTheme, strings: self.presentationData.strings) + + if let (layout, navigationBarHeight) = self.validLayout { + self.containerLayoutUpdated(layout, navigationBarHeight: navigationBarHeight, transition: .immediate) + } + } + func scrollViewDidScroll(_ scrollView: UIScrollView) { let bounds = scrollView.bounds if !bounds.width.isZero { diff --git a/submodules/TelegramUI/TelegramUI/ChatScheduleTimeControllerNode.swift b/submodules/TelegramUI/TelegramUI/ChatScheduleTimeControllerNode.swift index 2a3a2ea7f5..b3fb49ae6f 100644 --- a/submodules/TelegramUI/TelegramUI/ChatScheduleTimeControllerNode.swift +++ b/submodules/TelegramUI/TelegramUI/ChatScheduleTimeControllerNode.swift @@ -125,7 +125,7 @@ class ChatScheduleTimeControllerNode: ViewControllerTracingNode, UIScrollViewDel let pickerView = UIDatePicker() pickerView.timeZone = TimeZone(secondsFromGMT: 0) pickerView.datePickerMode = .dateAndTime - pickerView.locale = localeWithStrings(self.presentationData.strings) + pickerView.locale = Locale.current pickerView.timeZone = TimeZone.current pickerView.minuteInterval = 1 pickerView.setValue(self.presentationData.theme.actionSheet.primaryTextColor, forKey: "textColor")