From e29982454bc8d9099685264ff8c2ac75c2f2b035 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sun, 2 Jan 2022 20:39:19 +0100 Subject: [PATCH] Add options for history: badge color and reset watched status on playing --- Model/HistoryModel.swift | 5 +++ Model/Watch.swift | 5 +++ .../AppBlueColor.colorset/Contents.json | 38 +++++++++++++++++++ .../AppRedColor.colorset/Contents.json | 38 +++++++++++++++++++ .../Contents.json | 6 +-- Shared/Defaults.swift | 8 +++- Shared/Settings/HistorySettings.swift | 30 +++++++++++++++ Shared/Settings/SettingsView.swift | 2 +- Shared/Videos/VideoCell.swift | 12 ++++-- 9 files changed, 135 insertions(+), 9 deletions(-) create mode 100644 Shared/Assets.xcassets/AppBlueColor.colorset/Contents.json create mode 100644 Shared/Assets.xcassets/AppRedColor.colorset/Contents.json diff --git a/Model/HistoryModel.swift b/Model/HistoryModel.swift index de237450..5624b91c 100644 --- a/Model/HistoryModel.swift +++ b/Model/HistoryModel.swift @@ -1,5 +1,6 @@ import CoreData import CoreMedia +import Defaults import Foundation extension PlayerModel { @@ -42,6 +43,10 @@ extension PlayerModel { watch.videoID = id } else { watch = results?.first + + if !Defaults[.resetWatchedStatusOnPlaying], watch.finished { + return + } } if let seconds = playerItemDuration?.seconds { diff --git a/Model/Watch.swift b/Model/Watch.swift index b92ece65..cddfd6e7 100644 --- a/Model/Watch.swift +++ b/Model/Watch.swift @@ -24,6 +24,11 @@ extension Watch { } let progress = (stoppedAt / videoDuration) * 100 + + if progress >= Double(watchedThreshold) { + return 100 + } + return min(max(progress, 0), 100) } diff --git a/Shared/Assets.xcassets/AppBlueColor.colorset/Contents.json b/Shared/Assets.xcassets/AppBlueColor.colorset/Contents.json new file mode 100644 index 00000000..f927febf --- /dev/null +++ b/Shared/Assets.xcassets/AppBlueColor.colorset/Contents.json @@ -0,0 +1,38 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "display-p3", + "components" : { + "alpha" : "1.000", + "blue" : "0.361", + "green" : "0.200", + "red" : "0.129" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "display-p3", + "components" : { + "alpha" : "1.000", + "blue" : "0.361", + "green" : "0.200", + "red" : "0.129" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Shared/Assets.xcassets/AppRedColor.colorset/Contents.json b/Shared/Assets.xcassets/AppRedColor.colorset/Contents.json new file mode 100644 index 00000000..c6a4334a --- /dev/null +++ b/Shared/Assets.xcassets/AppRedColor.colorset/Contents.json @@ -0,0 +1,38 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "display-p3", + "components" : { + "alpha" : "1.000", + "blue" : "0.263", + "green" : "0.290", + "red" : "0.859" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "display-p3", + "components" : { + "alpha" : "1.000", + "blue" : "0.263", + "green" : "0.290", + "red" : "0.859" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/Shared/Assets.xcassets/WatchProgressBarColor.colorset/Contents.json b/Shared/Assets.xcassets/WatchProgressBarColor.colorset/Contents.json index c6a4334a..db492b7d 100644 --- a/Shared/Assets.xcassets/WatchProgressBarColor.colorset/Contents.json +++ b/Shared/Assets.xcassets/WatchProgressBarColor.colorset/Contents.json @@ -5,9 +5,9 @@ "color-space" : "display-p3", "components" : { "alpha" : "1.000", - "blue" : "0.263", - "green" : "0.290", - "red" : "0.859" + "blue" : "0.361", + "green" : "0.200", + "red" : "0.129" } }, "idiom" : "universal" diff --git a/Shared/Defaults.swift b/Shared/Defaults.swift index 668d1562..cbaa7a51 100644 --- a/Shared/Defaults.swift +++ b/Shared/Defaults.swift @@ -63,7 +63,9 @@ extension Defaults.Keys { static let showWatchingProgress = Key("showWatchingProgress", default: true) static let watchedThreshold = Key("watchedThreshold", default: 90) static let watchedVideoStyle = Key("watchedVideoStyle", default: .badge) + static let watchedVideoBadgeColor = Key("WatchedVideoBadgeColor", default: .red) static let watchedVideoPlayNowBehavior = Key("watchedVideoPlayNowBehavior", default: .continue) + static let resetWatchedStatusOnPlaying = Key("resetWatchedStatusOnPlaying", default: false) static let saveRecents = Key("saveRecents", default: true) static let trendingCategory = Key("trendingCategory", default: .default) @@ -153,7 +155,11 @@ enum VisibleSection: String, CaseIterable, Comparable, Defaults.Serializable { } enum WatchedVideoStyle: String, Defaults.Serializable { - case nothing, badge, decreasedOpacity + case nothing, badge, decreasedOpacity, both +} + +enum WatchedVideoBadgeColor: String, Defaults.Serializable { + case colorSchemeBased, red, blue } enum WatchedVideoPlayNowBehavior: String, Defaults.Serializable { diff --git a/Shared/Settings/HistorySettings.swift b/Shared/Settings/HistorySettings.swift index 3ae2cc4a..b918570c 100644 --- a/Shared/Settings/HistorySettings.swift +++ b/Shared/Settings/HistorySettings.swift @@ -13,7 +13,9 @@ struct HistorySettings: View { @Default(.showWatchingProgress) private var showWatchingProgress @Default(.watchedThreshold) private var watchedThreshold @Default(.watchedVideoStyle) private var watchedVideoStyle + @Default(.watchedVideoBadgeColor) private var watchedVideoBadgeColor @Default(.watchedVideoPlayNowBehavior) private var watchedVideoPlayNowBehavior + @Default(.resetWatchedStatusOnPlaying) private var resetWatchedStatusOnPlaying var body: some View { Group { @@ -26,14 +28,18 @@ struct HistorySettings: View { #if !os(tvOS) watchedThresholdPicker watchedVideoStylePicker + watchedVideoBadgeColorPicker watchedVideoPlayNowBehaviorPicker + resetWatchedStatusOnPlayingToggle #endif } #if os(tvOS) watchedThresholdPicker watchedVideoStylePicker + watchedVideoBadgeColorPicker watchedVideoPlayNowBehaviorPicker + resetWatchedStatusOnPlayingToggle #endif #if os(macOS) @@ -68,6 +74,7 @@ struct HistorySettings: View { Text("Nothing").tag(WatchedVideoStyle.nothing) Text("Badge").tag(WatchedVideoStyle.badge) Text("Decreased opacity").tag(WatchedVideoStyle.decreasedOpacity) + Text("Badge & Decreased opacity").tag(WatchedVideoStyle.both) } .disabled(!saveHistory) .labelsHidden() @@ -80,6 +87,25 @@ struct HistorySettings: View { } } + private var watchedVideoBadgeColorPicker: some View { + Section(header: header("Badge color")) { + 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) + .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) { @@ -97,6 +123,10 @@ struct HistorySettings: View { } } + private var resetWatchedStatusOnPlayingToggle: some View { + Toggle("Reset watched status when playing again", isOn: $resetWatchedStatusOnPlaying) + } + private var clearHistoryButton: some View { Button("Clear History") { presentingClearHistoryConfirmation = true diff --git a/Shared/Settings/SettingsView.swift b/Shared/Settings/SettingsView.swift index 48d6a9af..8d3f91d1 100644 --- a/Shared/Settings/SettingsView.swift +++ b/Shared/Settings/SettingsView.swift @@ -75,7 +75,7 @@ struct SettingsView: View { .tag(Tabs.updates) } .padding(20) - .frame(width: 400, height: 380) + .frame(width: 400, height: 400) #else NavigationView { List { diff --git a/Shared/Videos/VideoCell.swift b/Shared/Videos/VideoCell.swift index d6ba3309..00264faf 100644 --- a/Shared/Videos/VideoCell.swift +++ b/Shared/Videos/VideoCell.swift @@ -21,6 +21,7 @@ struct VideoCell: View { @Default(.saveHistory) private var saveHistory @Default(.showWatchingProgress) private var showWatchingProgress @Default(.watchedVideoStyle) private var watchedVideoStyle + @Default(.watchedVideoBadgeColor) private var watchedVideoBadgeColor @Default(.watchedVideoPlayNowBehavior) private var watchedVideoPlayNowBehavior @FetchRequest private var watchRequest: FetchedResults @@ -112,7 +113,7 @@ struct VideoCell: View { private var contentOpacity: Double { guard saveHistory, !watch.isNil, - watchedVideoStyle == .decreasedOpacity + watchedVideoStyle == .decreasedOpacity || watchedVideoStyle == .both else { return 1 } @@ -290,7 +291,7 @@ struct VideoCell: View { thumbnailImage if saveHistory, showWatchingProgress, watch?.progress ?? 0 > 0 { ProgressView(value: watch!.progress, total: 100) - .progressViewStyle(LinearProgressViewStyle(tint: Color("WatchProgressBarColor"))) + .progressViewStyle(LinearProgressViewStyle(tint: Color("AppRedColor"))) #if os(tvOS) .padding(.horizontal, 16) #else @@ -328,11 +329,14 @@ struct VideoCell: View { HStack(alignment: .center) { if saveHistory, - watchedVideoStyle == .badge, + watchedVideoStyle == .badge || watchedVideoStyle == .both, watch?.finished ?? false { Image(systemName: "checkmark.circle.fill") - .foregroundColor(Color("WatchProgressBarColor")) + .foregroundColor(Color( + watchedVideoBadgeColor == .colorSchemeBased ? "WatchProgressBarColor" : + watchedVideoBadgeColor == .red ? "AppRedColor" : "AppBlueColor" + )) .background(Color.white) .clipShape(Circle()) #if os(tvOS)