2021-12-26 21:14:46 +00:00
|
|
|
import Defaults
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct HistorySettings: View {
|
|
|
|
static let watchedThresholds = [50, 60, 70, 80, 90, 95, 100]
|
|
|
|
|
|
|
|
@State private var presentingClearHistoryConfirmation = false
|
|
|
|
|
|
|
|
@EnvironmentObject<PlayerModel> private var player
|
|
|
|
|
|
|
|
@Default(.saveRecents) private var saveRecents
|
2022-09-11 16:34:33 +00:00
|
|
|
@Default(.saveLastPlayed) private var saveLastPlayed
|
2021-12-26 21:14:46 +00:00
|
|
|
@Default(.saveHistory) private var saveHistory
|
|
|
|
@Default(.showWatchingProgress) private var showWatchingProgress
|
|
|
|
@Default(.watchedThreshold) private var watchedThreshold
|
|
|
|
@Default(.watchedVideoStyle) private var watchedVideoStyle
|
2022-01-02 19:39:19 +00:00
|
|
|
@Default(.watchedVideoBadgeColor) private var watchedVideoBadgeColor
|
2021-12-26 21:14:46 +00:00
|
|
|
@Default(.watchedVideoPlayNowBehavior) private var watchedVideoPlayNowBehavior
|
2022-01-02 19:39:19 +00:00
|
|
|
@Default(.resetWatchedStatusOnPlaying) private var resetWatchedStatusOnPlaying
|
2021-12-26 21:14:46 +00:00
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
Group {
|
2022-01-06 15:02:53 +00:00
|
|
|
#if os(macOS)
|
|
|
|
sections
|
|
|
|
#else
|
|
|
|
List {
|
|
|
|
sections
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#if os(tvOS)
|
|
|
|
.frame(maxWidth: 1000)
|
|
|
|
#elseif os(iOS)
|
|
|
|
.listStyle(.insetGrouped)
|
|
|
|
#endif
|
|
|
|
.navigationTitle("History")
|
|
|
|
}
|
|
|
|
|
|
|
|
private var sections: some View {
|
|
|
|
Group {
|
|
|
|
#if os(tvOS)
|
2022-09-04 15:28:30 +00:00
|
|
|
Section(header: SettingsHeader(text: "History".localized())) {
|
2022-01-06 15:02:53 +00:00
|
|
|
Toggle("Save history of searches, channels and playlists", isOn: $saveRecents)
|
|
|
|
Toggle("Save history of played videos", isOn: $saveHistory)
|
|
|
|
Toggle("Show progress of watching on thumbnails", isOn: $showWatchingProgress)
|
|
|
|
.disabled(!saveHistory)
|
|
|
|
|
|
|
|
watchedVideoPlayNowBehaviorPicker
|
2021-12-26 21:14:46 +00:00
|
|
|
|
|
|
|
watchedThresholdPicker
|
2022-01-06 15:02:53 +00:00
|
|
|
resetWatchedStatusOnPlayingToggle
|
2021-12-26 21:14:46 +00:00
|
|
|
watchedVideoStylePicker
|
2022-01-02 19:39:19 +00:00
|
|
|
watchedVideoBadgeColorPicker
|
2022-01-06 15:02:53 +00:00
|
|
|
}
|
|
|
|
#else
|
2022-09-04 15:28:30 +00:00
|
|
|
Section(header: SettingsHeader(text: "History".localized())) {
|
2022-01-06 15:02:53 +00:00
|
|
|
Toggle("Save history of searches, channels and playlists", isOn: $saveRecents)
|
|
|
|
Toggle("Save history of played videos", isOn: $saveHistory)
|
|
|
|
Toggle("Show progress of watching on thumbnails", isOn: $showWatchingProgress)
|
|
|
|
.disabled(!saveHistory)
|
2022-09-11 16:34:33 +00:00
|
|
|
Toggle("Keep last played video in the queue after restart", isOn: $saveLastPlayed)
|
2022-01-06 15:02:53 +00:00
|
|
|
}
|
|
|
|
|
2022-09-04 15:28:30 +00:00
|
|
|
Section(header: SettingsHeader(text: "Watched".localized())) {
|
2021-12-26 21:14:46 +00:00
|
|
|
watchedVideoPlayNowBehaviorPicker
|
2022-01-06 15:02:53 +00:00
|
|
|
#if os(macOS)
|
|
|
|
.padding(.top, 1)
|
|
|
|
#endif
|
|
|
|
watchedThresholdPicker
|
2022-01-02 19:39:19 +00:00
|
|
|
resetWatchedStatusOnPlayingToggle
|
2022-01-06 15:02:53 +00:00
|
|
|
}
|
2021-12-26 21:14:46 +00:00
|
|
|
|
2022-09-04 15:28:30 +00:00
|
|
|
Section(header: SettingsHeader(text: "Interface".localized())) {
|
2022-01-06 15:02:53 +00:00
|
|
|
watchedVideoStylePicker
|
|
|
|
#if os(macOS)
|
|
|
|
.padding(.top, 1)
|
|
|
|
#endif
|
|
|
|
watchedVideoBadgeColorPicker
|
|
|
|
}
|
2021-12-26 21:14:46 +00:00
|
|
|
|
2022-01-06 15:02:53 +00:00
|
|
|
#if os(macOS)
|
|
|
|
Spacer()
|
|
|
|
#endif
|
2021-12-26 21:14:46 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
clearHistoryButton
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private var watchedThresholdPicker: some View {
|
2022-09-04 15:28:30 +00:00
|
|
|
Section(header: SettingsHeader(text: "Mark video as watched after playing".localized(), secondary: true)) {
|
2021-12-26 21:14:46 +00:00
|
|
|
Picker("Mark video as watched after playing", selection: $watchedThreshold) {
|
|
|
|
ForEach(Self.watchedThresholds, id: \.self) { threshold in
|
|
|
|
Text("\(threshold)%").tag(threshold)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.disabled(!saveHistory)
|
2022-08-06 14:28:05 +00:00
|
|
|
.modifier(SettingsPickerModifier())
|
2021-12-26 21:14:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private var watchedVideoStylePicker: some View {
|
2022-09-04 15:28:30 +00:00
|
|
|
Section(header: SettingsHeader(text: "Mark watched videos with".localized(), secondary: true)) {
|
2021-12-26 21:14:46 +00:00
|
|
|
Picker("Mark watched videos with", selection: $watchedVideoStyle) {
|
|
|
|
Text("Nothing").tag(WatchedVideoStyle.nothing)
|
|
|
|
Text("Badge").tag(WatchedVideoStyle.badge)
|
|
|
|
Text("Decreased opacity").tag(WatchedVideoStyle.decreasedOpacity)
|
2022-01-02 19:39:19 +00:00
|
|
|
Text("Badge & Decreased opacity").tag(WatchedVideoStyle.both)
|
2021-12-26 21:14:46 +00:00
|
|
|
}
|
|
|
|
.disabled(!saveHistory)
|
2022-08-06 14:28:05 +00:00
|
|
|
.modifier(SettingsPickerModifier())
|
2021-12-26 21:14:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-02 19:39:19 +00:00
|
|
|
private var watchedVideoBadgeColorPicker: some View {
|
2022-09-04 15:28:30 +00:00
|
|
|
Section(header: SettingsHeader(text: "Badge color".localized(), secondary: true)) {
|
2022-01-02 19:39:19 +00:00
|
|
|
Picker("Badge color", selection: $watchedVideoBadgeColor) {
|
|
|
|
Text("Based on system color scheme").tag(WatchedVideoBadgeColor.colorSchemeBased)
|
|
|
|
Text("Blue").tag(WatchedVideoBadgeColor.blue)
|
|
|
|
Text("Red").tag(WatchedVideoBadgeColor.red)
|
|
|
|
}
|
|
|
|
.disabled(!saveHistory)
|
|
|
|
.disabled(watchedVideoStyle == .decreasedOpacity)
|
2022-01-06 15:02:53 +00:00
|
|
|
.disabled(watchedVideoStyle == .nothing)
|
2022-08-06 14:28:05 +00:00
|
|
|
.modifier(SettingsPickerModifier())
|
2022-01-02 19:39:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-26 21:14:46 +00:00
|
|
|
private var watchedVideoPlayNowBehaviorPicker: some View {
|
2022-09-04 15:28:30 +00:00
|
|
|
Section(header: SettingsHeader(text: "When partially watched video is played".localized(), secondary: true)) {
|
2021-12-26 21:14:46 +00:00
|
|
|
Picker("When partially watched video is played", selection: $watchedVideoPlayNowBehavior) {
|
|
|
|
Text("Continue").tag(WatchedVideoPlayNowBehavior.continue)
|
|
|
|
Text("Restart").tag(WatchedVideoPlayNowBehavior.restart)
|
|
|
|
}
|
|
|
|
.disabled(!saveHistory)
|
2022-08-06 14:28:05 +00:00
|
|
|
.modifier(SettingsPickerModifier())
|
2021-12-26 21:14:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-02 19:39:19 +00:00
|
|
|
private var resetWatchedStatusOnPlayingToggle: some View {
|
|
|
|
Toggle("Reset watched status when playing again", isOn: $resetWatchedStatusOnPlaying)
|
2022-01-06 15:02:53 +00:00
|
|
|
.disabled(!saveHistory)
|
2022-01-02 19:39:19 +00:00
|
|
|
}
|
|
|
|
|
2021-12-26 21:14:46 +00:00
|
|
|
private var clearHistoryButton: some View {
|
|
|
|
Button("Clear History") {
|
|
|
|
presentingClearHistoryConfirmation = true
|
|
|
|
}
|
|
|
|
.alert(isPresented: $presentingClearHistoryConfirmation) {
|
|
|
|
Alert(
|
|
|
|
title: Text(
|
|
|
|
"Are you sure you want to clear history of watched videos?"
|
|
|
|
),
|
|
|
|
message: Text(
|
2022-08-16 22:34:48 +00:00
|
|
|
"This cannot be reverted. You might need to switch between views or restart the app to see changes."
|
2021-12-26 21:14:46 +00:00
|
|
|
),
|
|
|
|
primaryButton: .destructive(Text("Clear All")) {
|
|
|
|
player.removeAllWatches()
|
|
|
|
presentingClearHistoryConfirmation = false
|
|
|
|
},
|
|
|
|
secondaryButton: .cancel()
|
|
|
|
)
|
|
|
|
}
|
|
|
|
.foregroundColor(.red)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct HistorySettings_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
HistorySettings()
|
|
|
|
.injectFixtureEnvironmentObjects()
|
|
|
|
}
|
|
|
|
}
|