2022-01-06 15:02:53 +00:00
|
|
|
import Defaults
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct SponsorBlockSettings: View {
|
|
|
|
@Default(.sponsorBlockInstance) private var sponsorBlockInstance
|
|
|
|
@Default(.sponsorBlockCategories) private var sponsorBlockCategories
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
Group {
|
|
|
|
#if os(macOS)
|
|
|
|
sections
|
|
|
|
|
|
|
|
Spacer()
|
|
|
|
#else
|
|
|
|
List {
|
|
|
|
sections
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#if os(tvOS)
|
|
|
|
.frame(maxWidth: 1000)
|
2022-11-11 18:53:52 +00:00
|
|
|
#else
|
|
|
|
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
|
2022-01-06 15:02:53 +00:00
|
|
|
#endif
|
|
|
|
.navigationTitle("SponsorBlock")
|
|
|
|
}
|
|
|
|
|
|
|
|
private var sections: some View {
|
|
|
|
Group {
|
|
|
|
Section(header: SettingsHeader(text: "SponsorBlock API")) {
|
|
|
|
TextField(
|
|
|
|
"SponsorBlock API Instance",
|
|
|
|
text: $sponsorBlockInstance
|
|
|
|
)
|
|
|
|
.labelsHidden()
|
|
|
|
#if !os(macOS)
|
|
|
|
.autocapitalization(.none)
|
|
|
|
.keyboardType(.URL)
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2022-09-04 15:28:30 +00:00
|
|
|
Section(header: SettingsHeader(text: "Categories to Skip".localized()), footer: categoriesDetails) {
|
2022-01-06 15:02:53 +00:00
|
|
|
#if os(macOS)
|
|
|
|
let list = ForEach(SponsorBlockAPI.categories, id: \.self) { category in
|
2022-08-13 14:12:45 +00:00
|
|
|
MultiselectRow(
|
2022-01-06 15:02:53 +00:00
|
|
|
title: SponsorBlockAPI.categoryDescription(category) ?? "Unknown",
|
|
|
|
selected: sponsorBlockCategories.contains(category)
|
|
|
|
) { value in
|
|
|
|
toggleCategory(category, value: value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Group {
|
|
|
|
if #available(macOS 12.0, *) {
|
|
|
|
list
|
|
|
|
.listStyle(.inset(alternatesRowBackgrounds: true))
|
|
|
|
} else {
|
|
|
|
list
|
|
|
|
.listStyle(.inset)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Spacer()
|
|
|
|
#else
|
|
|
|
ForEach(SponsorBlockAPI.categories, id: \.self) { category in
|
2022-08-13 14:12:45 +00:00
|
|
|
MultiselectRow(
|
2022-01-06 15:02:53 +00:00
|
|
|
title: SponsorBlockAPI.categoryDescription(category) ?? "Unknown",
|
|
|
|
selected: sponsorBlockCategories.contains(category)
|
|
|
|
) { value in
|
|
|
|
toggleCategory(category, value: value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-07 18:46:47 +00:00
|
|
|
private var categoriesDetails: some View {
|
|
|
|
VStack(alignment: .leading) {
|
|
|
|
ForEach(SponsorBlockAPI.categories, id: \.self) { category in
|
|
|
|
Text(SponsorBlockAPI.categoryDescription(category) ?? "Category")
|
|
|
|
.fontWeight(.bold)
|
|
|
|
#if os(tvOS)
|
|
|
|
.focusable()
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Text(SponsorBlockAPI.categoryDetails(category) ?? "Details")
|
|
|
|
.padding(.bottom, 3)
|
|
|
|
.fixedSize(horizontal: false, vertical: true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
.padding(.top, 3)
|
|
|
|
}
|
|
|
|
|
2022-01-06 15:02:53 +00:00
|
|
|
func toggleCategory(_ category: String, value: Bool) {
|
|
|
|
if let index = sponsorBlockCategories.firstIndex(where: { $0 == category }), !value {
|
|
|
|
sponsorBlockCategories.remove(at: index)
|
|
|
|
} else if value {
|
|
|
|
sponsorBlockCategories.insert(category)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-07 18:46:47 +00:00
|
|
|
struct SponsorBlockSettings_Previews: PreviewProvider {
|
2022-01-06 15:02:53 +00:00
|
|
|
static var previews: some View {
|
|
|
|
VStack {
|
|
|
|
SponsorBlockSettings()
|
|
|
|
}
|
2022-11-11 18:53:52 +00:00
|
|
|
.frame(maxHeight: 600)
|
2022-01-06 15:02:53 +00:00
|
|
|
}
|
|
|
|
}
|