mirror of
https://github.com/yattee/yattee.git
synced 2025-04-28 07:50:33 +05:30
make chapters collapsible
Chapters are now collapsible by default only the first two chapters are shown. The second will be shown opaque to indicate more chapters.
This commit is contained in:
parent
eb1dfe69cd
commit
e436dec4ba
@ -4,6 +4,7 @@ import SwiftUI
|
|||||||
|
|
||||||
struct ChaptersView: View {
|
struct ChaptersView: View {
|
||||||
@ObservedObject private var player = PlayerModel.shared
|
@ObservedObject private var player = PlayerModel.shared
|
||||||
|
@Binding var expand: Bool
|
||||||
|
|
||||||
var chapters: [Chapter] {
|
var chapters: [Chapter] {
|
||||||
player.videoForDisplay?.chapters ?? []
|
player.videoForDisplay?.chapters ?? []
|
||||||
@ -14,7 +15,7 @@ struct ChaptersView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
if !chapters.isEmpty {
|
if expand && !chapters.isEmpty {
|
||||||
#if os(tvOS)
|
#if os(tvOS)
|
||||||
List {
|
List {
|
||||||
Section {
|
Section {
|
||||||
@ -45,15 +46,22 @@ struct ChaptersView: View {
|
|||||||
.padding(.horizontal)
|
.padding(.horizontal)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else if !chapters.isEmpty {
|
||||||
NoCommentsView(text: "No chapters information available".localized(), systemImage: "xmark.circle.fill")
|
Section {
|
||||||
|
ChapterView(chapter: chapters[0])
|
||||||
|
if chapters.count > 1 {
|
||||||
|
ChapterView(chapter: chapters[1])
|
||||||
|
.opacity(0.3)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(.horizontal)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ChaptersView_Previews: PreviewProvider {
|
struct ChaptersView_Previews: PreviewProvider {
|
||||||
static var previews: some View {
|
static var previews: some View {
|
||||||
ChaptersView()
|
ChaptersView(expand: .constant(false))
|
||||||
.injectFixtureEnvironmentObjects()
|
.injectFixtureEnvironmentObjects()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,6 +169,7 @@ struct VideoDetails: View {
|
|||||||
@State private var subscriptionToggleButtonDisabled = false
|
@State private var subscriptionToggleButtonDisabled = false
|
||||||
@State private var page = DetailsPage.info
|
@State private var page = DetailsPage.info
|
||||||
@State private var descriptionExpanded = false
|
@State private var descriptionExpanded = false
|
||||||
|
@State private var chaptersExpanded = false
|
||||||
|
|
||||||
@Environment(\.navigationStyle) private var navigationStyle
|
@Environment(\.navigationStyle) private var navigationStyle
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
@ -317,10 +318,9 @@ struct VideoDetails: View {
|
|||||||
if player.videoBeingOpened.isNil {
|
if player.videoBeingOpened.isNil {
|
||||||
if showChapters,
|
if showChapters,
|
||||||
!video.isLocal,
|
!video.isLocal,
|
||||||
!video.chapters.isEmpty
|
!video.chapters.isEmpty {
|
||||||
{
|
|
||||||
Section(header: chaptersHeader) {
|
Section(header: chaptersHeader) {
|
||||||
ChaptersView()
|
ChaptersView(expand: $chaptersExpanded)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -331,8 +331,7 @@ struct VideoDetails: View {
|
|||||||
|
|
||||||
if showRelated,
|
if showRelated,
|
||||||
!sidebarQueue,
|
!sidebarQueue,
|
||||||
!(player.videoForDisplay?.related.isEmpty ?? true)
|
!(player.videoForDisplay?.related.isEmpty ?? true) {
|
||||||
{
|
|
||||||
RelatedView()
|
RelatedView()
|
||||||
.padding(.horizontal)
|
.padding(.horizontal)
|
||||||
.padding(.top, 20)
|
.padding(.top, 20)
|
||||||
@ -390,8 +389,7 @@ struct VideoDetails: View {
|
|||||||
if showScrollToTopInComments,
|
if showScrollToTopInComments,
|
||||||
page == .comments,
|
page == .comments,
|
||||||
comments.loaded,
|
comments.loaded,
|
||||||
comments.all.count > 3
|
comments.all.count > 3 {
|
||||||
{
|
|
||||||
Button {
|
Button {
|
||||||
withAnimation {
|
withAnimation {
|
||||||
proxy.scrollTo(Self.pageMenuID)
|
proxy.scrollTo(Self.pageMenuID)
|
||||||
@ -441,10 +439,17 @@ struct VideoDetails: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var chaptersHeader: some View {
|
var chaptersHeader: some View {
|
||||||
Text("Chapters".localized())
|
HStack {
|
||||||
.padding(.horizontal)
|
Text("Chapters".localized())
|
||||||
.font(.caption)
|
Spacer()
|
||||||
.foregroundColor(.secondary)
|
Button(action: { chaptersExpanded.toggle() }) {
|
||||||
|
Image(systemName: chaptersExpanded ? "chevron.up" : "chevron.down")
|
||||||
|
.imageScale(.small)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(.horizontal)
|
||||||
|
.font(.caption)
|
||||||
|
.foregroundColor(.secondary)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,7 +282,7 @@ struct PlayerSettings: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private var showChaptersToggle: some View {
|
private var showChaptersToggle: some View {
|
||||||
Toggle("Chapters", isOn: $showChapters)
|
Toggle("Chapters (if available)", isOn: $showChapters)
|
||||||
}
|
}
|
||||||
|
|
||||||
private var showRelatedToggle: some View {
|
private var showRelatedToggle: some View {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user