mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 20:24:06 +00:00
Improve history, resume videos, mark watched videos (fixes #42)
This commit is contained in:
@@ -4,8 +4,6 @@ import SwiftUI
|
||||
struct BrowsingSettings: View {
|
||||
@Default(.channelOnThumbnail) private var channelOnThumbnail
|
||||
@Default(.timeOnThumbnail) private var timeOnThumbnail
|
||||
@Default(.saveRecents) private var saveRecents
|
||||
@Default(.saveHistory) private var saveHistory
|
||||
@Default(.visibleSections) private var visibleSections
|
||||
|
||||
var body: some View {
|
||||
@@ -13,8 +11,6 @@ struct BrowsingSettings: View {
|
||||
Section(header: SettingsHeader(text: "Browsing")) {
|
||||
Toggle("Show channel name on thumbnail", isOn: $channelOnThumbnail)
|
||||
Toggle("Show video length on thumbnail", isOn: $timeOnThumbnail)
|
||||
Toggle("Save recent queries and channels", isOn: $saveRecents)
|
||||
Toggle("Save history of played videos", isOn: $saveHistory)
|
||||
}
|
||||
Section(header: SettingsHeader(text: "Sections")) {
|
||||
#if os(macOS)
|
||||
|
142
Shared/Settings/HistorySettings.swift
Normal file
142
Shared/Settings/HistorySettings.swift
Normal file
@@ -0,0 +1,142 @@
|
||||
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
|
||||
@Default(.saveHistory) private var saveHistory
|
||||
@Default(.showWatchingProgress) private var showWatchingProgress
|
||||
@Default(.watchedThreshold) private var watchedThreshold
|
||||
@Default(.watchedVideoStyle) private var watchedVideoStyle
|
||||
@Default(.watchedVideoPlayNowBehavior) private var watchedVideoPlayNowBehavior
|
||||
|
||||
var body: some View {
|
||||
Group {
|
||||
Section(header: SettingsHeader(text: "History")) {
|
||||
Toggle("Save recent queries and channels", isOn: $saveRecents)
|
||||
Toggle("Save history of played videos", isOn: $saveHistory)
|
||||
Toggle("Show progress of watching on thumbnails", isOn: $showWatchingProgress)
|
||||
.disabled(!saveHistory)
|
||||
|
||||
#if !os(tvOS)
|
||||
watchedThresholdPicker
|
||||
watchedVideoStylePicker
|
||||
watchedVideoPlayNowBehaviorPicker
|
||||
#endif
|
||||
}
|
||||
|
||||
#if os(tvOS)
|
||||
watchedThresholdPicker
|
||||
watchedVideoStylePicker
|
||||
watchedVideoPlayNowBehaviorPicker
|
||||
#endif
|
||||
|
||||
#if os(macOS)
|
||||
Spacer()
|
||||
#endif
|
||||
|
||||
clearHistoryButton
|
||||
}
|
||||
}
|
||||
|
||||
private var watchedThresholdPicker: some View {
|
||||
Section(header: header("Mark video as watched after playing")) {
|
||||
Picker("Mark video as watched after playing", selection: $watchedThreshold) {
|
||||
ForEach(Self.watchedThresholds, id: \.self) { threshold in
|
||||
Text("\(threshold)%").tag(threshold)
|
||||
}
|
||||
}
|
||||
.disabled(!saveHistory)
|
||||
.labelsHidden()
|
||||
|
||||
#if os(iOS)
|
||||
.pickerStyle(.automatic)
|
||||
#elseif os(tvOS)
|
||||
.pickerStyle(.inline)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
private var watchedVideoStylePicker: some View {
|
||||
Section(header: header("Mark watched videos with")) {
|
||||
Picker("Mark watched videos with", selection: $watchedVideoStyle) {
|
||||
Text("Nothing").tag(WatchedVideoStyle.nothing)
|
||||
Text("Badge").tag(WatchedVideoStyle.badge)
|
||||
Text("Decreased opacity").tag(WatchedVideoStyle.decreasedOpacity)
|
||||
}
|
||||
.disabled(!saveHistory)
|
||||
.labelsHidden()
|
||||
|
||||
#if os(iOS)
|
||||
.pickerStyle(.automatic)
|
||||
#elseif os(tvOS)
|
||||
.pickerStyle(.inline)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
private var watchedVideoPlayNowBehaviorPicker: some View {
|
||||
Section(header: header("When partially watched video is played")) {
|
||||
Picker("When partially watched video is played", selection: $watchedVideoPlayNowBehavior) {
|
||||
Text("Continue").tag(WatchedVideoPlayNowBehavior.continue)
|
||||
Text("Restart").tag(WatchedVideoPlayNowBehavior.restart)
|
||||
}
|
||||
.disabled(!saveHistory)
|
||||
.labelsHidden()
|
||||
|
||||
#if os(iOS)
|
||||
.pickerStyle(.automatic)
|
||||
#elseif os(tvOS)
|
||||
.pickerStyle(.inline)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
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(
|
||||
"This cannot be undone. You might need to switch between views or restart the app to see changes."
|
||||
),
|
||||
primaryButton: .destructive(Text("Clear All")) {
|
||||
player.removeAllWatches()
|
||||
presentingClearHistoryConfirmation = false
|
||||
},
|
||||
secondaryButton: .cancel()
|
||||
)
|
||||
}
|
||||
.foregroundColor(.red)
|
||||
.disabled(!saveHistory)
|
||||
}
|
||||
|
||||
private func header(_ text: String) -> some View {
|
||||
#if os(iOS)
|
||||
return EmptyView()
|
||||
#elseif os(macOS)
|
||||
return Text(text)
|
||||
.opacity(saveHistory ? 1 : 0.3)
|
||||
#else
|
||||
return Text(text)
|
||||
.foregroundColor(.secondary)
|
||||
.opacity(saveHistory ? 1 : 0.2)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
struct HistorySettings_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
HistorySettings()
|
||||
.injectFixtureEnvironmentObjects()
|
||||
}
|
||||
}
|
@@ -5,7 +5,7 @@ import SwiftUI
|
||||
struct SettingsView: View {
|
||||
#if os(macOS)
|
||||
private enum Tabs: Hashable {
|
||||
case instances, browsing, playback, services, updates
|
||||
case instances, browsing, history, playback, services, updates
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -42,6 +42,14 @@ struct SettingsView: View {
|
||||
}
|
||||
.tag(Tabs.browsing)
|
||||
|
||||
Form {
|
||||
HistorySettings()
|
||||
}
|
||||
.tabItem {
|
||||
Label("History", systemImage: "clock.arrow.circlepath")
|
||||
}
|
||||
.tag(Tabs.history)
|
||||
|
||||
Form {
|
||||
PlaybackSettings()
|
||||
}
|
||||
@@ -89,6 +97,7 @@ struct SettingsView: View {
|
||||
}
|
||||
|
||||
BrowsingSettings()
|
||||
HistorySettings()
|
||||
PlaybackSettings()
|
||||
ServicesSettings()
|
||||
}
|
||||
|
Reference in New Issue
Block a user