Add setting for saving videos history

This commit is contained in:
Arkadiusz Fal 2021-11-05 20:57:22 +01:00
parent 26f672ff4f
commit a7d9efdd9d
6 changed files with 23 additions and 4 deletions

View File

@ -149,7 +149,7 @@ extension PlayerModel {
}
func addCurrentItemToHistory() {
if let item = currentItem {
if let item = currentItem, Defaults[.saveHistory] {
addItemToHistory(item)
}
}

View File

@ -53,6 +53,8 @@ extension Defaults.Keys {
static let history = Key<[PlayerQueueItem]>("history", default: [])
static let lastPlayed = Key<PlayerQueueItem?>("lastPlayed")
static let saveHistory = Key<Bool>("saveHistory", default: true)
static let trendingCategory = Key<TrendingCategory>("trendingCategory", default: .default)
static let trendingCountry = Key<Country>("trendingCountry", default: .us)
}

View File

@ -1,3 +1,4 @@
import Defaults
import Foundation
import SwiftUI
@ -7,6 +8,8 @@ struct PlayerQueueView: View {
@EnvironmentObject<PlayerModel> 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)

View File

@ -105,7 +105,7 @@ struct VideoDetails: View {
}
.padding(.top, inNavigationView && fullScreen ? 10 : 0)
.onAppear {
if video.isNil {
if video.isNil && !sidebarQueue {
currentPage = .queue
}

View File

@ -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 {

View File

@ -1,3 +1,4 @@
import Defaults
import SwiftUI
struct NowPlayingView: View {
@ -10,6 +11,8 @@ struct NowPlayingView: View {
@EnvironmentObject<PlayerModel> 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 {