From a7d9efdd9dd3ffa2a82da9197005c2433052dbf2 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Fri, 5 Nov 2021 20:57:22 +0100 Subject: [PATCH] Add setting for saving videos history --- Model/Player/PlayerQueue.swift | 2 +- Shared/Defaults.swift | 2 ++ Shared/Player/PlayerQueueView.swift | 7 ++++++- Shared/Player/VideoDetails.swift | 2 +- Shared/Settings/PlaybackSettings.swift | 9 +++++++++ tvOS/NowPlayingView.swift | 5 ++++- 6 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Model/Player/PlayerQueue.swift b/Model/Player/PlayerQueue.swift index 35bd7737..70545351 100644 --- a/Model/Player/PlayerQueue.swift +++ b/Model/Player/PlayerQueue.swift @@ -149,7 +149,7 @@ extension PlayerModel { } func addCurrentItemToHistory() { - if let item = currentItem { + if let item = currentItem, Defaults[.saveHistory] { addItemToHistory(item) } } diff --git a/Shared/Defaults.swift b/Shared/Defaults.swift index 8a25a06c..c84b5621 100644 --- a/Shared/Defaults.swift +++ b/Shared/Defaults.swift @@ -53,6 +53,8 @@ extension Defaults.Keys { static let history = Key<[PlayerQueueItem]>("history", default: []) static let lastPlayed = Key("lastPlayed") + static let saveHistory = Key("saveHistory", default: true) + static let trendingCategory = Key("trendingCategory", default: .default) static let trendingCountry = Key("trendingCountry", default: .us) } diff --git a/Shared/Player/PlayerQueueView.swift b/Shared/Player/PlayerQueueView.swift index e8eb99ae..aa44e365 100644 --- a/Shared/Player/PlayerQueueView.swift +++ b/Shared/Player/PlayerQueueView.swift @@ -1,3 +1,4 @@ +import Defaults import Foundation import SwiftUI @@ -7,6 +8,8 @@ struct PlayerQueueView: View { @EnvironmentObject private var player + @Default(.saveHistory) private var saveHistory + var body: some View { List { Group { @@ -14,7 +17,9 @@ struct PlayerQueueView: View { if sidebarQueue { related } - playedPreviously + if saveHistory { + playedPreviously + } } #if !os(iOS) .padding(.vertical, 5) diff --git a/Shared/Player/VideoDetails.swift b/Shared/Player/VideoDetails.swift index cf0506e5..077df8f4 100644 --- a/Shared/Player/VideoDetails.swift +++ b/Shared/Player/VideoDetails.swift @@ -105,7 +105,7 @@ struct VideoDetails: View { } .padding(.top, inNavigationView && fullScreen ? 10 : 0) .onAppear { - if video.isNil { + if video.isNil && !sidebarQueue { currentPage = .queue } diff --git a/Shared/Settings/PlaybackSettings.swift b/Shared/Settings/PlaybackSettings.swift index e6b68cc1..1f678e79 100644 --- a/Shared/Settings/PlaybackSettings.swift +++ b/Shared/Settings/PlaybackSettings.swift @@ -7,6 +7,7 @@ struct PlaybackSettings: View { @Default(.quality) private var quality @Default(.playerSidebar) private var playerSidebar @Default(.showKeywords) private var showKeywords + @Default(.saveHistory) private var saveHistory #if os(iOS) private var idiom: UIUserInterfaceIdiom { @@ -20,10 +21,13 @@ struct PlaybackSettings: View { Section(header: SettingsHeader(text: "Player")) { sourcePicker qualityPicker + if idiom == .pad { sidebarPicker } + keywordsToggle + saveHistoryToggle } #else Section(header: SettingsHeader(text: "Source")) { @@ -41,6 +45,7 @@ struct PlaybackSettings: View { #endif keywordsToggle + saveHistoryToggle #endif } @@ -104,6 +109,10 @@ struct PlaybackSettings: View { private var keywordsToggle: some View { Toggle("Show video keywords", isOn: $showKeywords) } + + private var saveHistoryToggle: some View { + Toggle("Save history of played videos", isOn: $saveHistory) + } } struct PlaybackSettings_Previews: PreviewProvider { diff --git a/tvOS/NowPlayingView.swift b/tvOS/NowPlayingView.swift index 42fdbd03..63e78b26 100644 --- a/tvOS/NowPlayingView.swift +++ b/tvOS/NowPlayingView.swift @@ -1,3 +1,4 @@ +import Defaults import SwiftUI struct NowPlayingView: View { @@ -10,6 +11,8 @@ struct NowPlayingView: View { @EnvironmentObject private var player + @Default(.saveHistory) private var saveHistory + var body: some View { if inInfoViewController { content @@ -80,7 +83,7 @@ struct NowPlayingView: View { } } - if sections.contains(.playedPreviously), !player.history.isEmpty { + if sections.contains(.playedPreviously), saveHistory, !player.history.isEmpty { Section(header: Text("Played Previously")) { ForEach(player.history) { item in Button {