diff --git a/submodules/Display/Source/GenerateImage.swift b/submodules/Display/Source/GenerateImage.swift index 97cd118f4d..59c4234b5c 100644 --- a/submodules/Display/Source/GenerateImage.swift +++ b/submodules/Display/Source/GenerateImage.swift @@ -351,7 +351,7 @@ public func generateGradientTintedImage(image: UIImage?, colors: [UIColor]) -> U let t = CGFloat(i) / CGFloat(colors.count - 1) locations.append(t) } - let colorSpace = CGColorSpaceCreateDeviceRGB() + let colorSpace = DeviceGraphicsContextSettings.shared.colorSpace let gradient = CGGradient(colorsSpace: colorSpace, colors: gradientColors, locations: &locations)! context.drawLinearGradient(gradient, start: CGPoint(x: 0.0, y: imageRect.height), end: CGPoint(x: 0.0, y: 0.0), options: CGGradientDrawingOptions()) @@ -381,7 +381,7 @@ public func generateGradientImage(size: CGSize, colors: [UIColor], locations: [C UIGraphicsBeginImageContextWithOptions(size, false, 0.0) if let context = UIGraphicsGetCurrentContext() { let gradientColors = colors.map { $0.cgColor } as CFArray - let colorSpace = CGColorSpaceCreateDeviceRGB() + let colorSpace = DeviceGraphicsContextSettings.shared.colorSpace var locations = locations let gradient = CGGradient(colorsSpace: colorSpace, colors: gradientColors, locations: &locations)! @@ -403,7 +403,7 @@ public func generateGradientFilledCircleImage(diameter: CGFloat, colors: NSArray context.clip() var locations: [CGFloat] = [0.0, 1.0] - let colorSpace = CGColorSpaceCreateDeviceRGB() + let colorSpace = DeviceGraphicsContextSettings.shared.colorSpace let gradient = CGGradient(colorsSpace: colorSpace, colors: colors, locations: &locations)! context.drawLinearGradient(gradient, start: CGPoint(), end: CGPoint(x: 0.0, y: bounds.size.height), options: CGGradientDrawingOptions()) diff --git a/submodules/Display/Source/NavigationBar.swift b/submodules/Display/Source/NavigationBar.swift index c2ac67ea80..7752442d25 100644 --- a/submodules/Display/Source/NavigationBar.swift +++ b/submodules/Display/Source/NavigationBar.swift @@ -1190,6 +1190,7 @@ open class NavigationBar: ASDisplayNode { self.badgeNode.updateTheme(fillColor: self.presentationData.theme.buttonColor, strokeColor: self.presentationData.theme.buttonColor, textColor: self.presentationData.theme.badgeTextColor) + self.updateLeftButton(animated: false) self.requestLayout() } } diff --git a/submodules/MediaPickerUI/Sources/MediaGroupsAlbumGridItem.swift b/submodules/MediaPickerUI/Sources/MediaGroupsAlbumGridItem.swift index c6df8e16aa..7b1f98b574 100644 --- a/submodules/MediaPickerUI/Sources/MediaGroupsAlbumGridItem.swift +++ b/submodules/MediaPickerUI/Sources/MediaGroupsAlbumGridItem.swift @@ -140,7 +140,7 @@ private final class MediaGroupsGridAlbumItemNode : ListViewItemNode { override func didLoad() { super.didLoad() - self.imageNode.cornerRadius = 10.0 + self.imageNode.cornerRadius = 5.0 if #available(iOS 13.0, *) { self.imageNode.layer.cornerCurve = .continuous } @@ -221,11 +221,11 @@ private func preparedTransition(action: @escaping (PHAssetCollection) -> Void, f } final class MediaGroupsAlbumGridItem: ListViewItem { - let presentationData: ItemListPresentationData + let presentationData: PresentationData let collections: [PHAssetCollection] let action: (PHAssetCollection) -> Void - public init(presentationData: ItemListPresentationData, collections: [PHAssetCollection], action: @escaping (PHAssetCollection) -> Void) { + public init(presentationData: PresentationData, collections: [PHAssetCollection], action: @escaping (PHAssetCollection) -> Void) { self.presentationData = presentationData self.collections = collections self.action = action @@ -347,7 +347,8 @@ private class MediaGroupsAlbumGridItemNode: ListViewItemNode { firstItem = result.firstObject } if let firstItem = firstItem { - entries.append(MediaGroupsGridAlbumEntry(theme: item.presentationData.theme, index: index, collection: collection, firstItem: firstItem, count: presentationStringsFormattedNumber(Int32(result.count)))) + let count = presentationStringsFormattedNumber(Int32(result.count), item.presentationData.dateTimeFormat.groupingSeparator) + entries.append(MediaGroupsGridAlbumEntry(theme: item.presentationData.theme, index: index, collection: collection, firstItem: firstItem, count: count)) index += 1 } } diff --git a/submodules/MediaPickerUI/Sources/MediaGroupsScreen.swift b/submodules/MediaPickerUI/Sources/MediaGroupsScreen.swift index 0f9337ae58..bf94a0446c 100644 --- a/submodules/MediaPickerUI/Sources/MediaGroupsScreen.swift +++ b/submodules/MediaPickerUI/Sources/MediaGroupsScreen.swift @@ -91,7 +91,7 @@ private enum MediaGroupsEntry: Comparable, Identifiable { case let .albumsHeader(_, text), let .smartAlbumsHeader(_, text): return MediaGroupsHeaderItem(presentationData: ItemListPresentationData(presentationData), title: text) case let .albums(_, collections): - return MediaGroupsAlbumGridItem(presentationData: ItemListPresentationData(presentationData), collections: collections, action: { collection in + return MediaGroupsAlbumGridItem(presentationData: presentationData, collections: collections, action: { collection in openGroup(collection) }) case let .smartAlbum(_, _, collection, count): diff --git a/submodules/SettingsUI/Sources/Language Selection/LocalizationListControllerNode.swift b/submodules/SettingsUI/Sources/Language Selection/LocalizationListControllerNode.swift index c7adeb131a..92a77ffb9a 100644 --- a/submodules/SettingsUI/Sources/Language Selection/LocalizationListControllerNode.swift +++ b/submodules/SettingsUI/Sources/Language Selection/LocalizationListControllerNode.swift @@ -612,7 +612,18 @@ final class LocalizationListControllerNode: ViewControllerTracingNode { } func updatePresentationData(_ presentationData: PresentationData) { + let stringsUpdated = self.presentationData.strings !== presentationData.strings self.presentationData = presentationData + + if stringsUpdated { + if let snapshotView = self.view.snapshotView(afterScreenUpdates: false) { + self.view.addSubview(snapshotView) + snapshotView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false, completion: { [weak snapshotView] _ in + snapshotView?.removeFromSuperview() + }) + } + } + self.presentationDataValue.set(.single(presentationData)) self.backgroundColor = presentationData.theme.list.blocksBackgroundColor self.listNode.keepTopItemOverscrollBackground = ListViewKeepTopItemOverscrollBackground(color: presentationData.theme.list.blocksBackgroundColor, direction: true) diff --git a/submodules/TelegramUI/Sources/AppDelegate.swift b/submodules/TelegramUI/Sources/AppDelegate.swift index 9e064fa2cb..ab73b00203 100644 --- a/submodules/TelegramUI/Sources/AppDelegate.swift +++ b/submodules/TelegramUI/Sources/AppDelegate.swift @@ -319,6 +319,7 @@ private func extractAccountManagerState(records: AccountRecordsView (cleanSize: CGSize, apparentHeight: CGFloat) { - let constrainedSize = CGSize(width: min(260.0, constrainedWidth), height: min(604.0, maxHeight)) + let constrainedSize = CGSize(width: min(220.0, constrainedWidth), height: min(604.0, maxHeight)) var topContentHeight: CGFloat = 0.0 if let backButtonNode = self.backButtonNode { diff --git a/submodules/TelegramUI/Sources/SharedMediaPlayer.swift b/submodules/TelegramUI/Sources/SharedMediaPlayer.swift index 0e20d9d467..5fd209ea2a 100644 --- a/submodules/TelegramUI/Sources/SharedMediaPlayer.swift +++ b/submodules/TelegramUI/Sources/SharedMediaPlayer.swift @@ -9,6 +9,7 @@ import TelegramAudio import AccountContext import TelegramUniversalVideoContent import DeviceProximity +import RaiseToListen private enum SharedMediaPlaybackItem: Equatable { case audio(MediaPlayer) @@ -120,7 +121,9 @@ final class SharedMediaPlayer { private var playbackRate: AudioPlaybackRate - private var proximityManagerIndex: Int? + //private var proximityManagerIndex: Int? + private var raiseToListen: RaiseToListenManager? + private let controlPlaybackWithProximity: Bool private var forceAudioToSpeaker = false @@ -346,9 +349,10 @@ final class SharedMediaPlayer { } else { strongSelf.playbackStateValue.set(.single(nil)) if !state.loading { - if let proximityManagerIndex = strongSelf.proximityManagerIndex { - DeviceProximityManager.shared().remove(proximityManagerIndex) - } + strongSelf.raiseToListen = nil +// if let proximityManagerIndex = strongSelf.proximityManagerIndex { +// DeviceProximityManager.shared().remove(proximityManagerIndex) +// } } } } @@ -362,18 +366,44 @@ final class SharedMediaPlayer { }) if controlPlaybackWithProximity { - self.proximityManagerIndex = DeviceProximityManager.shared().add { [weak self] value in - let forceAudioToSpeaker = !value - if let strongSelf = self, strongSelf.forceAudioToSpeaker != forceAudioToSpeaker { - strongSelf.forceAudioToSpeaker = forceAudioToSpeaker - strongSelf.playbackItem?.setForceAudioToSpeaker(forceAudioToSpeaker) - if !forceAudioToSpeaker { - strongSelf.control(.playback(.play)) - } else { - strongSelf.control(.playback(.pause)) + self.raiseToListen = RaiseToListenManager(shouldActivate: { + return true + }, activate: { [weak self] in + if let strongSelf = self { + let forceAudioToSpeaker = false + if strongSelf.forceAudioToSpeaker != forceAudioToSpeaker { + strongSelf.forceAudioToSpeaker = forceAudioToSpeaker + strongSelf.playbackItem?.setForceAudioToSpeaker(forceAudioToSpeaker) + if !forceAudioToSpeaker { + strongSelf.control(.playback(.play)) + } } } - } + }, deactivate: { [weak self] in + if let strongSelf = self { + let forceAudioToSpeaker = true + if strongSelf.forceAudioToSpeaker != forceAudioToSpeaker { + strongSelf.forceAudioToSpeaker = forceAudioToSpeaker + strongSelf.playbackItem?.setForceAudioToSpeaker(forceAudioToSpeaker) + if forceAudioToSpeaker { + strongSelf.control(.playback(.pause)) + } + } + } + }) + self.raiseToListen?.enabled = true +// self.proximityManagerIndex = DeviceProximityManager.shared().add { [weak self] value in +// let forceAudioToSpeaker = !value +// if let strongSelf = self, strongSelf.forceAudioToSpeaker != forceAudioToSpeaker { +// strongSelf.forceAudioToSpeaker = forceAudioToSpeaker +// strongSelf.playbackItem?.setForceAudioToSpeaker(forceAudioToSpeaker) +// if !forceAudioToSpeaker { +// strongSelf.control(.playback(.play)) +// } else { +// strongSelf.control(.playback(.pause)) +// } +// } +// } } } @@ -384,9 +414,9 @@ final class SharedMediaPlayer { self.playbackStateValueDisposable?.dispose() self.prefetchDisposable.dispose() - if let proximityManagerIndex = self.proximityManagerIndex { - DeviceProximityManager.shared().remove(proximityManagerIndex) - } +// if let proximityManagerIndex = self.proximityManagerIndex { +// DeviceProximityManager.shared().remove(proximityManagerIndex) +// } if let playbackItem = self.playbackItem { switch playbackItem { diff --git a/submodules/TranslateUI/Sources/ChatTranslation.swift b/submodules/TranslateUI/Sources/ChatTranslation.swift index 1a869e8512..c43060353b 100644 --- a/submodules/TranslateUI/Sources/ChatTranslation.swift +++ b/submodules/TranslateUI/Sources/ChatTranslation.swift @@ -222,14 +222,24 @@ public func chatTranslationState(context: AccountContext, peerId: EnginePeer.Id) let hypotheses = languageRecognizer.languageHypotheses(withMaximum: 4) languageRecognizer.reset() - let filteredLanguages = hypotheses.filter { supportedTranslationLanguages.contains($0.key.rawValue) }.sorted(by: { $0.value > $1.value }) - if let language = filteredLanguages.first(where: { supportedTranslationLanguages.contains($0.key.rawValue) }) { - let fromLang = language.key.rawValue + func normalize(_ code: String) -> String { + if code.contains("-") { + return code.components(separatedBy: "-").first ?? code + } else if code == "nb" { + return "no" + } else { + return code + } + } + + let filteredLanguages = hypotheses.filter { supportedTranslationLanguages.contains(normalize($0.key.rawValue)) }.sorted(by: { $0.value > $1.value }) + if let language = filteredLanguages.first { + let fromLang = normalize(language.key.rawValue) fromLangs[fromLang] = (fromLangs[fromLang] ?? 0) + message.text.count count += 1 } } - if count >= 10 { + if count >= 16 { break } } diff --git a/submodules/TranslateUI/Sources/Translate.swift b/submodules/TranslateUI/Sources/Translate.swift index 80bdd32879..5a70f375ce 100644 --- a/submodules/TranslateUI/Sources/Translate.swift +++ b/submodules/TranslateUI/Sources/Translate.swift @@ -25,9 +25,6 @@ public var supportedTranslationLanguages = [ "ca", "ceb", "zh", -// "zh-Hant", -// "zh-CN", "zh" -// "zh-TW" "co", "hr", "cs", @@ -168,9 +165,20 @@ public func canTranslateText(context: AccountContext, text: String, showTranslat supportedTranslationLanguages = ["uk", "ru"] } - let filteredLanguages = hypotheses.filter { supportedTranslationLanguages.contains($0.key.rawValue) }.sorted(by: { $0.value > $1.value }) - if let language = filteredLanguages.first(where: { supportedTranslationLanguages.contains($0.key.rawValue) }) { - return (!dontTranslateLanguages.contains(language.key.rawValue), language.key.rawValue) + func normalize(_ code: String) -> String { + if code.contains("-") { + return code.components(separatedBy: "-").first ?? code + } else if code == "nb" { + return "no" + } else { + return code + } + } + + let filteredLanguages = hypotheses.filter { supportedTranslationLanguages.contains(normalize($0.key.rawValue)) }.sorted(by: { $0.value > $1.value }) + if let language = filteredLanguages.first { + let languageCode = normalize(language.key.rawValue) + return (!dontTranslateLanguages.contains(languageCode), languageCode) } else { return (false, nil) } diff --git a/submodules/WebSearchUI/Sources/WebSearchControllerNode.swift b/submodules/WebSearchUI/Sources/WebSearchControllerNode.swift index fc840cb691..666a768400 100644 --- a/submodules/WebSearchUI/Sources/WebSearchControllerNode.swift +++ b/submodules/WebSearchUI/Sources/WebSearchControllerNode.swift @@ -245,9 +245,9 @@ class WebSearchControllerNode: ASDisplayNode { self.addSubnode(self.segmentedContainerNode) self.segmentedContainerNode.addSubnode(self.segmentedBackgroundNode) self.segmentedContainerNode.addSubnode(self.segmentedSeparatorNode) - if case .media = mode { - self.segmentedContainerNode.addSubnode(self.segmentedControlNode) - } +// if case .media = mode { +// self.segmentedContainerNode.addSubnode(self.segmentedControlNode) +// } if !attachment { self.addSubnode(self.toolbarBackgroundNode) self.addSubnode(self.toolbarSeparatorNode)