add stepper for previewed line (broken on macOS)

This commit is contained in:
Toni Förster 2023-11-23 15:41:33 +01:00
parent 84fdc22861
commit 5d78946320
No known key found for this signature in database
GPG Key ID: 292F3E5086C83FC7
3 changed files with 22 additions and 5 deletions

View File

@ -147,6 +147,7 @@ extension Defaults.Keys {
static let expandVideoDescriptionDefault = true static let expandVideoDescriptionDefault = true
#endif #endif
static let expandVideoDescription = Key<Bool>("expandVideoDescription", default: expandVideoDescriptionDefault) static let expandVideoDescription = Key<Bool>("expandVideoDescription", default: expandVideoDescriptionDefault)
static let collapsedLinesDescription = Key<Int>("collapsedLinesDescription", default: 5)
static let showChannelAvatarInChannelsLists = Key<Bool>("showChannelAvatarInChannelsLists", default: true) static let showChannelAvatarInChannelsLists = Key<Bool>("showChannelAvatarInChannelsLists", default: true)
static let showChannelAvatarInVideosListing = Key<Bool>("showChannelAvatarInVideosListing", default: true) static let showChannelAvatarInVideosListing = Key<Bool>("showChannelAvatarInVideosListing", default: true)

View File

@ -6,11 +6,10 @@ import Foundation
import SwiftUI import SwiftUI
struct VideoDescription: View { struct VideoDescription: View {
static let collapsedLines = 5
private var search: SearchModel { .shared } private var search: SearchModel { .shared }
@Default(.showKeywords) private var showKeywords @Default(.showKeywords) private var showKeywords
@Default(.expandVideoDescription) private var expandVideoDescription @Default(.expandVideoDescription) private var expandVideoDescription
@Default(.collapsedLinesDescription) private var collapsedLinesDescription
var video: Video var video: Video
var detailsSize: CGSize? var detailsSize: CGSize?
@ -51,14 +50,14 @@ struct VideoDescription: View {
if #available(macOS 12, *) { if #available(macOS 12, *) {
DescriptionWithLinks(description: description, detailsSize: detailsSize) DescriptionWithLinks(description: description, detailsSize: detailsSize)
.frame(maxWidth: .infinity, alignment: .leading) .frame(maxWidth: .infinity, alignment: .leading)
.lineLimit(shouldExpand ? 500 : Self.collapsedLines) .lineLimit(shouldExpand ? 500 : collapsedLinesDescription)
#if !os(tvOS) #if !os(tvOS)
.textSelection(.enabled) .textSelection(.enabled)
#endif #endif
} else { } else {
Text(description) Text(description)
.frame(maxWidth: .infinity, alignment: .leading) .frame(maxWidth: .infinity, alignment: .leading)
.lineLimit(shouldExpand ? 500 : Self.collapsedLines) .lineLimit(shouldExpand ? 500 : collapsedLinesDescription)
} }
} }
.multilineTextAlignment(.leading) .multilineTextAlignment(.leading)
@ -142,6 +141,8 @@ struct VideoDescription: View {
@Environment(\.openURL) private var openURL @Environment(\.openURL) private var openURL
@Default(.collapsedLinesDescription) private var collapsedLinesDescription
var player = PlayerModel.shared var player = PlayerModel.shared
func makeUIView(context _: Context) -> some UIView { func makeUIView(context _: Context) -> some UIView {
@ -175,7 +176,7 @@ struct VideoDescription: View {
} }
func updateNumberOfLines() { func updateNumberOfLines() {
label.numberOfLines = expand ? 0 : VideoDescription.collapsedLines label.numberOfLines = expand ? 0 : collapsedLinesDescription
} }
func urlTapHandler(_ url: URL) { func urlTapHandler(_ url: URL) {

View File

@ -12,6 +12,7 @@ struct PlayerSettings: View {
@Default(.showScrollToTopInComments) private var showScrollToTopInComments @Default(.showScrollToTopInComments) private var showScrollToTopInComments
#endif #endif
@Default(.expandVideoDescription) private var expandVideoDescription @Default(.expandVideoDescription) private var expandVideoDescription
@Default(.collapsedLinesDescription) private var collapsedLinesDescription
@Default(.pauseOnHidingPlayer) private var pauseOnHidingPlayer @Default(.pauseOnHidingPlayer) private var pauseOnHidingPlayer
@Default(.closeVideoOnEOF) private var closeVideoOnEOF @Default(.closeVideoOnEOF) private var closeVideoOnEOF
#if os(iOS) #if os(iOS)
@ -77,6 +78,7 @@ struct PlayerSettings: View {
#if !os(tvOS) #if !os(tvOS)
Section(header: SettingsHeader(text: "Info".localized())) { Section(header: SettingsHeader(text: "Info".localized())) {
expandVideoDescriptionToggle expandVideoDescriptionToggle
collapsedLineDescriptionStepper
showChaptersToggle showChaptersToggle
showRelatedToggle showRelatedToggle
#if os(macOS) #if os(macOS)
@ -194,6 +196,19 @@ struct PlayerSettings: View {
Toggle("Open video description expanded", isOn: $expandVideoDescription) Toggle("Open video description expanded", isOn: $expandVideoDescription)
} }
private var collapsedLineDescriptionStepper: some View {
Stepper(value: $collapsedLinesDescription, in: 0 ... 10) {
Text("Description preview")
if collapsedLinesDescription == 0 {
Text("No preview")
} else if collapsedLinesDescription == 1 {
Text("\(collapsedLinesDescription) line")
} else {
Text("\(collapsedLinesDescription) lines")
}
}
}
private var returnYouTubeDislikeToggle: some View { private var returnYouTubeDislikeToggle: some View {
Toggle("Enable Return YouTube Dislike", isOn: $enableReturnYouTubeDislike) Toggle("Enable Return YouTube Dislike", isOn: $enableReturnYouTubeDislike)
} }