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() { func addCurrentItemToHistory() {
if let item = currentItem { if let item = currentItem, Defaults[.saveHistory] {
addItemToHistory(item) addItemToHistory(item)
} }
} }

View File

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

View File

@ -1,3 +1,4 @@
import Defaults
import Foundation import Foundation
import SwiftUI import SwiftUI
@ -7,6 +8,8 @@ struct PlayerQueueView: View {
@EnvironmentObject<PlayerModel> private var player @EnvironmentObject<PlayerModel> private var player
@Default(.saveHistory) private var saveHistory
var body: some View { var body: some View {
List { List {
Group { Group {
@ -14,7 +17,9 @@ struct PlayerQueueView: View {
if sidebarQueue { if sidebarQueue {
related related
} }
playedPreviously if saveHistory {
playedPreviously
}
} }
#if !os(iOS) #if !os(iOS)
.padding(.vertical, 5) .padding(.vertical, 5)

View File

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

View File

@ -7,6 +7,7 @@ struct PlaybackSettings: View {
@Default(.quality) private var quality @Default(.quality) private var quality
@Default(.playerSidebar) private var playerSidebar @Default(.playerSidebar) private var playerSidebar
@Default(.showKeywords) private var showKeywords @Default(.showKeywords) private var showKeywords
@Default(.saveHistory) private var saveHistory
#if os(iOS) #if os(iOS)
private var idiom: UIUserInterfaceIdiom { private var idiom: UIUserInterfaceIdiom {
@ -20,10 +21,13 @@ struct PlaybackSettings: View {
Section(header: SettingsHeader(text: "Player")) { Section(header: SettingsHeader(text: "Player")) {
sourcePicker sourcePicker
qualityPicker qualityPicker
if idiom == .pad { if idiom == .pad {
sidebarPicker sidebarPicker
} }
keywordsToggle keywordsToggle
saveHistoryToggle
} }
#else #else
Section(header: SettingsHeader(text: "Source")) { Section(header: SettingsHeader(text: "Source")) {
@ -41,6 +45,7 @@ struct PlaybackSettings: View {
#endif #endif
keywordsToggle keywordsToggle
saveHistoryToggle
#endif #endif
} }
@ -104,6 +109,10 @@ struct PlaybackSettings: View {
private var keywordsToggle: some View { private var keywordsToggle: some View {
Toggle("Show video keywords", isOn: $showKeywords) Toggle("Show video keywords", isOn: $showKeywords)
} }
private var saveHistoryToggle: some View {
Toggle("Save history of played videos", isOn: $saveHistory)
}
} }
struct PlaybackSettings_Previews: PreviewProvider { struct PlaybackSettings_Previews: PreviewProvider {

View File

@ -1,3 +1,4 @@
import Defaults
import SwiftUI import SwiftUI
struct NowPlayingView: View { struct NowPlayingView: View {
@ -10,6 +11,8 @@ struct NowPlayingView: View {
@EnvironmentObject<PlayerModel> private var player @EnvironmentObject<PlayerModel> private var player
@Default(.saveHistory) private var saveHistory
var body: some View { var body: some View {
if inInfoViewController { if inInfoViewController {
content 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")) { Section(header: Text("Played Previously")) {
ForEach(player.history) { item in ForEach(player.history) { item in
Button { Button {