Audio rate fixes

This commit is contained in:
Ilya Laktyushin 2023-03-02 11:04:50 +04:00
parent 30f9746d16
commit 1502134ca6
8 changed files with 100 additions and 62 deletions

View File

@ -2746,8 +2746,22 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode {
let presentationData = strongSelf.context.sharedContext.currentPresentationData.with { $0 } let presentationData = strongSelf.context.sharedContext.currentPresentationData.with { $0 }
let text: String? let text: String?
let rate: CGFloat? let rate: CGFloat?
if case let .sliderCommit(previousValue, newValue) = changeType {
let value = String(format: "%0.1f", baseRate.doubleValue)
if baseRate == .x1 { if baseRate == .x1 {
text = presentationData.strings.Conversation_AudioRateTooltipNormal text = presentationData.strings.Conversation_AudioRateTooltipNormal
} else {
text = presentationData.strings.Conversation_AudioRateTooltipCustom(value).string
}
if newValue > previousValue {
rate = .infinity
} else if newValue < previousValue {
rate = -.infinity
} else {
rate = nil
}
} else if baseRate == .x1 {
text = presentationData.strings.Conversation_AudioRateTooltipNormal
rate = 1.0 rate = 1.0
} else if baseRate == .x1_5 { } else if baseRate == .x1_5 {
text = presentationData.strings.Conversation_AudioRateTooltip15X text = presentationData.strings.Conversation_AudioRateTooltip15X
@ -2756,20 +2770,9 @@ final class ChatListSearchListPaneNode: ASDisplayNode, ChatListSearchPaneNode {
text = presentationData.strings.Conversation_AudioRateTooltipSpeedUp text = presentationData.strings.Conversation_AudioRateTooltipSpeedUp
rate = 2.0 rate = 2.0
} else { } else {
let value = String(format: "%0.1f", baseRate.doubleValue) text = nil
text = presentationData.strings.Conversation_AudioRateTooltipCustom(value).string
if case let .sliderCommit(previousValue, newValue) = changeType {
if newValue > previousValue {
rate = .infinity
} else if newValue < previousValue {
rate = -.infinity
} else {
rate = nil rate = nil
} }
} else {
rate = nil
}
}
var showTooltip = true var showTooltip = true
if case .sliderChange = changeType { if case .sliderChange = changeType {
showTooltip = false showTooltip = false

View File

@ -2629,6 +2629,7 @@ final class UniversalVideoGalleryItemNode: ZoomableContentGalleryItemNode {
guard let strongSelf = self else { guard let strongSelf = self else {
return return
} }
let newValue = normalizeValue(newValue)
strongSelf.updatePlaybackRate(newValue) strongSelf.updatePlaybackRate(newValue)
if finished { if finished {
//dismiss() //dismiss()
@ -2852,3 +2853,7 @@ final class HeaderContextReferenceContentSource: ContextReferenceContentSource {
return ContextControllerReferenceViewInfo(referenceView: self.sourceNode.view, contentAreaInScreenSpace: UIScreen.main.bounds) return ContextControllerReferenceViewInfo(referenceView: self.sourceNode.view, contentAreaInScreenSpace: UIScreen.main.bounds)
} }
} }
private func normalizeValue(_ value: CGFloat) -> CGFloat {
return round(value * 10.0) / 10.0
}

View File

@ -18,6 +18,10 @@ import SliderContextItem
private let titleFont = Font.regular(12.0) private let titleFont = Font.regular(12.0)
private let subtitleFont = Font.regular(10.0) private let subtitleFont = Font.regular(10.0)
private func normalizeValue(_ value: CGFloat) -> CGFloat {
return round(value * 10.0) / 10.0
}
private class MediaHeaderItemNode: ASDisplayNode { private class MediaHeaderItemNode: ASDisplayNode {
private let titleNode: TextNode private let titleNode: TextNode
private let subtitleNode: TextNode private let subtitleNode: TextNode
@ -528,6 +532,7 @@ public final class MediaNavigationAccessoryHeaderNode: ASDisplayNode, UIScrollVi
let previousValue = self.playbackBaseRate?.doubleValue ?? 1.0 let previousValue = self.playbackBaseRate?.doubleValue ?? 1.0
let sliderItem: ContextMenuItem = .custom(SliderContextItem(minValue: 0.5, maxValue: 2.5, value: previousValue, valueChanged: { [weak self] newValue, finished in let sliderItem: ContextMenuItem = .custom(SliderContextItem(minValue: 0.5, maxValue: 2.5, value: previousValue, valueChanged: { [weak self] newValue, finished in
let newValue = normalizeValue(newValue)
self?.setRate?(AudioPlaybackRate(newValue), .sliderChange) self?.setRate?(AudioPlaybackRate(newValue), .sliderChange)
if finished { if finished {
scheduleTooltip(.sliderCommit(previousValue, newValue)) scheduleTooltip(.sliderCommit(previousValue, newValue))

View File

@ -699,8 +699,22 @@ open class TelegramBaseController: ViewController, KeyShortcutResponder {
let presentationData = strongSelf.context.sharedContext.currentPresentationData.with { $0 } let presentationData = strongSelf.context.sharedContext.currentPresentationData.with { $0 }
let text: String? let text: String?
let rate: CGFloat? let rate: CGFloat?
if case let .sliderCommit(previousValue, newValue) = changeType {
let value = String(format: "%0.1f", baseRate.doubleValue)
if baseRate == .x1 { if baseRate == .x1 {
text = presentationData.strings.Conversation_AudioRateTooltipNormal text = presentationData.strings.Conversation_AudioRateTooltipNormal
} else {
text = presentationData.strings.Conversation_AudioRateTooltipCustom(value).string
}
if newValue > previousValue {
rate = .infinity
} else if newValue < previousValue {
rate = -.infinity
} else {
rate = nil
}
} else if baseRate == .x1 {
text = presentationData.strings.Conversation_AudioRateTooltipNormal
rate = 1.0 rate = 1.0
} else if baseRate == .x1_5 { } else if baseRate == .x1_5 {
text = presentationData.strings.Conversation_AudioRateTooltip15X text = presentationData.strings.Conversation_AudioRateTooltip15X
@ -709,20 +723,9 @@ open class TelegramBaseController: ViewController, KeyShortcutResponder {
text = presentationData.strings.Conversation_AudioRateTooltipSpeedUp text = presentationData.strings.Conversation_AudioRateTooltipSpeedUp
rate = 2.0 rate = 2.0
} else { } else {
let value = String(format: "%0.1f", baseRate.doubleValue) text = nil
text = presentationData.strings.Conversation_AudioRateTooltipCustom(value).string
if case let .sliderCommit(previousValue, newValue) = changeType {
if newValue > previousValue {
rate = .infinity
} else if newValue < previousValue {
rate = -.infinity
} else {
rate = nil rate = nil
} }
} else {
rate = nil
}
}
var showTooltip = true var showTooltip = true
if case .sliderChange = changeType { if case .sliderChange = changeType {
showTooltip = false showTooltip = false

View File

@ -1628,6 +1628,7 @@ public final class EntityKeyboardTopPanelComponent: Component {
} }
} }
private var didReorderItems = false
private func beginReordering(itemView: ComponentHostView<EntityKeyboardTopPanelItemEnvironment>) { private func beginReordering(itemView: ComponentHostView<EntityKeyboardTopPanelItemEnvironment>) {
if let currentReorderingItemView = self.currentReorderingItemView { if let currentReorderingItemView = self.currentReorderingItemView {
if let componentView = currentReorderingItemView.componentView { if let componentView = currentReorderingItemView.componentView {
@ -1702,7 +1703,9 @@ public final class EntityKeyboardTopPanelComponent: Component {
self.currentReorderingItemId = nil self.currentReorderingItemId = nil
self.temporaryReorderingOrderIndex = nil self.temporaryReorderingOrderIndex = nil
if self.didReorderItems {
self.component?.reorderItems(self.items) self.component?.reorderItems(self.items)
}
//self.state?.updated(transition: Transition(animation: .curve(duration: 0.3, curve: .spring))) //self.state?.updated(transition: Transition(animation: .curve(duration: 0.3, curve: .spring)))
} }
@ -1721,14 +1724,14 @@ public final class EntityKeyboardTopPanelComponent: Component {
let containerFrame = itemLayout.containerFrame(at: i) let containerFrame = itemLayout.containerFrame(at: i)
if containerFrame.intersects(localReorderingItemFrame) { if containerFrame.intersects(localReorderingItemFrame) {
let temporaryReorderingOrderIndex: (id: AnyHashable, index: Int) = (currentReorderingItemId, i) let temporaryReorderingOrderIndex: (id: AnyHashable, index: Int) = (currentReorderingItemId, i)
let hadPrevous = self.temporaryReorderingOrderIndex != nil let hadPrevious = self.temporaryReorderingOrderIndex != nil
if self.temporaryReorderingOrderIndex?.id != temporaryReorderingOrderIndex.id || self.temporaryReorderingOrderIndex?.index != temporaryReorderingOrderIndex.index { if self.temporaryReorderingOrderIndex?.id != temporaryReorderingOrderIndex.id || self.temporaryReorderingOrderIndex?.index != temporaryReorderingOrderIndex.index {
self.temporaryReorderingOrderIndex = temporaryReorderingOrderIndex self.temporaryReorderingOrderIndex = temporaryReorderingOrderIndex
if hadPrevous { if hadPrevious {
self.reorderingHapticFeedback.tap() self.reorderingHapticFeedback.tap()
} }
self.didReorderItems = true
self.state?.updated(transition: Transition(animation: .curve(duration: 0.3, curve: .spring))) self.state?.updated(transition: Transition(animation: .curve(duration: 0.3, curve: .spring)))
} }
break break

View File

@ -18,6 +18,10 @@ import ContextUI
import SliderContextItem import SliderContextItem
import UndoUI import UndoUI
private func normalizeValue(_ value: CGFloat) -> CGFloat {
return round(value * 10.0) / 10.0
}
private func generateBackground(theme: PresentationTheme) -> UIImage? { private func generateBackground(theme: PresentationTheme) -> UIImage? {
return generateImage(CGSize(width: 20.0, height: 10.0 + 8.0), rotatedContext: { size, context in return generateImage(CGSize(width: 20.0, height: 10.0 + 8.0), rotatedContext: { size, context in
context.clear(CGRect(origin: CGPoint(), size: size)) context.clear(CGRect(origin: CGPoint(), size: size))
@ -1031,6 +1035,7 @@ final class OverlayPlayerControlsNode: ASDisplayNode {
let previousValue = self.currentRate?.doubleValue ?? 1.0 let previousValue = self.currentRate?.doubleValue ?? 1.0
let sliderItem: ContextMenuItem = .custom(SliderContextItem(minValue: 0.5, maxValue: 2.5, value: previousValue, valueChanged: { [weak self] newValue, finished in let sliderItem: ContextMenuItem = .custom(SliderContextItem(minValue: 0.5, maxValue: 2.5, value: previousValue, valueChanged: { [weak self] newValue, finished in
let newValue = normalizeValue(newValue)
self?.control?(.setBaseRate(AudioPlaybackRate(newValue))) self?.control?(.setBaseRate(AudioPlaybackRate(newValue)))
if finished { if finished {
scheduleTooltip(.sliderCommit(previousValue, newValue)) scheduleTooltip(.sliderCommit(previousValue, newValue))
@ -1082,8 +1087,22 @@ final class OverlayPlayerControlsNode: ASDisplayNode {
let presentationData = self.presentationData let presentationData = self.presentationData
let text: String? let text: String?
let rate: CGFloat? let rate: CGFloat?
if case let .sliderCommit(previousValue, newValue) = changeType {
let value = String(format: "%0.1f", baseRate.doubleValue)
if baseRate == .x1 { if baseRate == .x1 {
text = presentationData.strings.Conversation_AudioRateTooltipNormal text = presentationData.strings.Conversation_AudioRateTooltipNormal
} else {
text = presentationData.strings.Conversation_AudioRateTooltipCustom(value).string
}
if newValue > previousValue {
rate = .infinity
} else if newValue < previousValue {
rate = -.infinity
} else {
rate = nil
}
} else if baseRate == .x1 {
text = presentationData.strings.Conversation_AudioRateTooltipNormal
rate = 1.0 rate = 1.0
} else if baseRate == .x1_5 { } else if baseRate == .x1_5 {
text = presentationData.strings.Conversation_AudioRateTooltip15X text = presentationData.strings.Conversation_AudioRateTooltip15X
@ -1092,20 +1111,9 @@ final class OverlayPlayerControlsNode: ASDisplayNode {
text = presentationData.strings.Conversation_AudioRateTooltipSpeedUp text = presentationData.strings.Conversation_AudioRateTooltipSpeedUp
rate = 2.0 rate = 2.0
} else { } else {
let value = String(format: "%0.1f", baseRate.doubleValue) text = nil
text = presentationData.strings.Conversation_AudioRateTooltipCustom(value).string
if case let .sliderCommit(previousValue, newValue) = changeType {
if newValue > previousValue {
rate = .infinity
} else if newValue < previousValue {
rate = -.infinity
} else {
rate = nil rate = nil
} }
} else {
rate = nil
}
}
var showTooltip = true var showTooltip = true
if case .sliderChange = changeType { if case .sliderChange = changeType {
showTooltip = false showTooltip = false

View File

@ -293,8 +293,22 @@ final class PeerInfoListPaneNode: ASDisplayNode, PeerInfoPaneNode {
let presentationData = strongSelf.context.sharedContext.currentPresentationData.with { $0 } let presentationData = strongSelf.context.sharedContext.currentPresentationData.with { $0 }
let text: String? let text: String?
let rate: CGFloat? let rate: CGFloat?
if case let .sliderCommit(previousValue, newValue) = changeType {
let value = String(format: "%0.1f", baseRate.doubleValue)
if baseRate == .x1 { if baseRate == .x1 {
text = presentationData.strings.Conversation_AudioRateTooltipNormal text = presentationData.strings.Conversation_AudioRateTooltipNormal
} else {
text = presentationData.strings.Conversation_AudioRateTooltipCustom(value).string
}
if newValue > previousValue {
rate = .infinity
} else if newValue < previousValue {
rate = -.infinity
} else {
rate = nil
}
} else if baseRate == .x1 {
text = presentationData.strings.Conversation_AudioRateTooltipNormal
rate = 1.0 rate = 1.0
} else if baseRate == .x1_5 { } else if baseRate == .x1_5 {
text = presentationData.strings.Conversation_AudioRateTooltip15X text = presentationData.strings.Conversation_AudioRateTooltip15X
@ -303,20 +317,9 @@ final class PeerInfoListPaneNode: ASDisplayNode, PeerInfoPaneNode {
text = presentationData.strings.Conversation_AudioRateTooltipSpeedUp text = presentationData.strings.Conversation_AudioRateTooltipSpeedUp
rate = 2.0 rate = 2.0
} else { } else {
let value = String(format: "%0.1f", baseRate.doubleValue) text = nil
text = presentationData.strings.Conversation_AudioRateTooltipCustom(value).string
if case let .sliderCommit(previousValue, newValue) = changeType {
if newValue > previousValue {
rate = .infinity
} else if newValue < previousValue {
rate = -.infinity
} else {
rate = nil rate = nil
} }
} else {
rate = nil
}
}
var showTooltip = true var showTooltip = true
if case .sliderChange = changeType { if case .sliderChange = changeType {
showTooltip = false showTooltip = false

View File

@ -11008,14 +11008,22 @@ private final class AccountPeerContextItemNode: ASDisplayNode, ContextMenuCustom
let textFrame = CGRect(origin: CGPoint(x: sideInset, y: verticalOrigin), size: textSize) let textFrame = CGRect(origin: CGPoint(x: sideInset, y: verticalOrigin), size: textSize)
transition.updateFrameAdditive(node: self.textNode, frame: textFrame) transition.updateFrameAdditive(node: self.textNode, frame: textFrame)
if case let .user(user) = self.item.peer, let emojiStatus = user.emojiStatus { var iconContent: EmojiStatusComponent.Content?
if case let .user(user) = self.item.peer {
if let emojiStatus = user.emojiStatus {
iconContent = .animation(content: .customEmoji(fileId: emojiStatus.fileId), size: CGSize(width: 28.0, height: 28.0), placeholderColor: self.presentationData.theme.list.mediaPlaceholderColor, themeColor: self.presentationData.theme.list.itemAccentColor, loopMode: .forever)
} else if user.isPremium {
iconContent = .premium(color: self.presentationData.theme.list.itemAccentColor)
}
}
if let iconContent {
let emojiStatusSize = self.emojiStatusView.update( let emojiStatusSize = self.emojiStatusView.update(
transition: .immediate, transition: .immediate,
component: AnyComponent(EmojiStatusComponent( component: AnyComponent(EmojiStatusComponent(
context: self.item.context, context: self.item.context,
animationCache: self.item.context.animationCache, animationCache: self.item.context.animationCache,
animationRenderer: self.item.context.animationRenderer, animationRenderer: self.item.context.animationRenderer,
content: .animation(content: .customEmoji(fileId: emojiStatus.fileId), size: CGSize(width: 28.0, height: 28.0), placeholderColor: self.presentationData.theme.list.mediaPlaceholderColor, themeColor: self.presentationData.theme.list.itemAccentColor, loopMode: .forever), content: iconContent,
isVisibleForAnimations: true, isVisibleForAnimations: true,
action: nil action: nil
)), )),