mirror of
https://github.com/yattee/yattee.git
synced 2024-11-10 00:08:21 +00:00
Fix timeline view time padding
This commit is contained in:
parent
1cf37e5a00
commit
5b785cc9c2
@ -1,7 +1,7 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
extension Double {
|
extension Double {
|
||||||
func formattedAsPlaybackTime(allowZero: Bool = false) -> String? {
|
func formattedAsPlaybackTime(allowZero: Bool = false, forceHours: Bool = false) -> String? {
|
||||||
guard allowZero || !isZero, isFinite else {
|
guard allowZero || !isZero, isFinite else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -9,7 +9,7 @@ extension Double {
|
|||||||
let formatter = DateComponentsFormatter()
|
let formatter = DateComponentsFormatter()
|
||||||
|
|
||||||
formatter.unitsStyle = .positional
|
formatter.unitsStyle = .positional
|
||||||
formatter.allowedUnits = self >= (60 * 60) ? [.hour, .minute, .second] : [.minute, .second]
|
formatter.allowedUnits = self >= (60 * 60) || forceHours ? [.hour, .minute, .second] : [.minute, .second]
|
||||||
formatter.zeroFormattingBehavior = [.pad]
|
formatter.zeroFormattingBehavior = [.pad]
|
||||||
|
|
||||||
return formatter.string(from: self)
|
return formatter.string(from: self)
|
||||||
|
@ -9,12 +9,16 @@ final class PlayerTimeModel: ObservableObject {
|
|||||||
|
|
||||||
var player: PlayerModel?
|
var player: PlayerModel?
|
||||||
|
|
||||||
|
var forceHours: Bool {
|
||||||
|
duration.seconds >= 60 * 60
|
||||||
|
}
|
||||||
|
|
||||||
var currentPlaybackTime: String {
|
var currentPlaybackTime: String {
|
||||||
if player?.currentItem.isNil ?? true || duration.seconds.isZero {
|
if player?.currentItem.isNil ?? true || duration.seconds.isZero {
|
||||||
return Self.timePlaceholder
|
return Self.timePlaceholder
|
||||||
}
|
}
|
||||||
|
|
||||||
return currentTime.seconds.formattedAsPlaybackTime(allowZero: true) ?? Self.timePlaceholder
|
return currentTime.seconds.formattedAsPlaybackTime(allowZero: true, forceHours: forceHours) ?? Self.timePlaceholder
|
||||||
}
|
}
|
||||||
|
|
||||||
var durationPlaybackTime: String {
|
var durationPlaybackTime: String {
|
||||||
@ -30,17 +34,7 @@ final class PlayerTimeModel: ObservableObject {
|
|||||||
return Self.timePlaceholder
|
return Self.timePlaceholder
|
||||||
}
|
}
|
||||||
|
|
||||||
return withoutSegmentsDuration.formattedAsPlaybackTime() ?? Self.timePlaceholder
|
return withoutSegmentsDuration.formattedAsPlaybackTime(forceHours: forceHours) ?? Self.timePlaceholder
|
||||||
}
|
|
||||||
|
|
||||||
var durationAndWithoutSegmentsPlaybackTime: String {
|
|
||||||
var durationAndWithoutSegmentsPlaybackTime = "\(durationPlaybackTime)"
|
|
||||||
|
|
||||||
if withoutSegmentsPlaybackTime != durationPlaybackTime {
|
|
||||||
durationAndWithoutSegmentsPlaybackTime += " (\(withoutSegmentsPlaybackTime))"
|
|
||||||
}
|
|
||||||
|
|
||||||
return durationAndWithoutSegmentsPlaybackTime
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func reset() {
|
func reset() {
|
||||||
|
@ -77,7 +77,7 @@ struct TimelineView: View {
|
|||||||
.fixedSize()
|
.fixedSize()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Text((dragging ? projectedValue : current).formattedAsPlaybackTime(allowZero: true) ?? PlayerTimeModel.timePlaceholder)
|
Text((dragging ? projectedValue : current).formattedAsPlaybackTime(allowZero: true, forceHours: playerTime.forceHours) ?? PlayerTimeModel.timePlaceholder)
|
||||||
.font(.system(size: 11).monospacedDigit())
|
.font(.system(size: 11).monospacedDigit())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +107,7 @@ struct TimelineView: View {
|
|||||||
.opacity(dragging ? 1 : 0)
|
.opacity(dragging ? 1 : 0)
|
||||||
.animation(.easeOut, value: thumbTooltipOffset)
|
.animation(.easeOut, value: thumbTooltipOffset)
|
||||||
HStack(spacing: 4) {
|
HStack(spacing: 4) {
|
||||||
Text((dragging ? projectedValue : nil)?.formattedAsPlaybackTime(allowZero: true) ?? playerTime.currentPlaybackTime)
|
Text((dragging ? projectedValue : nil)?.formattedAsPlaybackTime(allowZero: true, forceHours: playerTime.forceHours) ?? playerTime.currentPlaybackTime)
|
||||||
.opacity(player.liveStreamInAVPlayer ? 0 : 1)
|
.opacity(player.liveStreamInAVPlayer ? 0 : 1)
|
||||||
.frame(minWidth: 35)
|
.frame(minWidth: 35)
|
||||||
#if os(tvOS)
|
#if os(tvOS)
|
||||||
|
Loading…
Reference in New Issue
Block a user