mirror of
https://github.com/yattee/yattee.git
synced 2024-12-22 21:43:41 +00:00
Add setting to show/hide recents and limit number of recents shown
This commit is contained in:
parent
7b34c7e72b
commit
5559e78bc0
@ -225,6 +225,9 @@ extension Defaults.Keys {
|
|||||||
|
|
||||||
static let saveRecents = Key<Bool>("saveRecents", default: true)
|
static let saveRecents = Key<Bool>("saveRecents", default: true)
|
||||||
static let saveHistory = Key<Bool>("saveHistory", default: true)
|
static let saveHistory = Key<Bool>("saveHistory", default: true)
|
||||||
|
static let showRecents = Key<Bool>("showRecents", default: true)
|
||||||
|
static let limitRecents = Key<Bool>("limitRecents", default: false)
|
||||||
|
static let limitRecentsAmount = Key<Int>("limitRecentsAmount", default: 10)
|
||||||
static let showWatchingProgress = Key<Bool>("showWatchingProgress", default: true)
|
static let showWatchingProgress = Key<Bool>("showWatchingProgress", default: true)
|
||||||
static let saveLastPlayed = Key<Bool>("saveLastPlayed", default: false)
|
static let saveLastPlayed = Key<Bool>("saveLastPlayed", default: false)
|
||||||
|
|
||||||
|
@ -5,12 +5,14 @@ struct AppSidebarRecents: View {
|
|||||||
var recents = RecentsModel.shared
|
var recents = RecentsModel.shared
|
||||||
|
|
||||||
@Default(.recentlyOpened) private var recentItems
|
@Default(.recentlyOpened) private var recentItems
|
||||||
|
@Default(.limitRecents) private var limitRecents
|
||||||
|
@Default(.limitRecentsAmount) private var limitRecentsAmount
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Group {
|
Group {
|
||||||
if !recentItems.isEmpty {
|
if !recentItems.isEmpty {
|
||||||
Section(header: Text("Recents")) {
|
Section(header: Text("Recents")) {
|
||||||
ForEach(recentItems.reversed()) { recent in
|
ForEach(recentItems.reversed().prefix(limitRecents ? limitRecentsAmount : recentItems.count)) { recent in
|
||||||
Group {
|
Group {
|
||||||
switch recent.type {
|
switch recent.type {
|
||||||
case .channel:
|
case .channel:
|
||||||
|
@ -13,6 +13,7 @@ struct Sidebar: View {
|
|||||||
@Default(.showDocuments) private var showDocuments
|
@Default(.showDocuments) private var showDocuments
|
||||||
#endif
|
#endif
|
||||||
@Default(.showUnwatchedFeedBadges) private var showUnwatchedFeedBadges
|
@Default(.showUnwatchedFeedBadges) private var showUnwatchedFeedBadges
|
||||||
|
@Default(.showRecents) private var showRecents
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
ScrollViewReader { scrollView in
|
ScrollViewReader { scrollView in
|
||||||
@ -20,8 +21,10 @@ struct Sidebar: View {
|
|||||||
mainNavigationLinks
|
mainNavigationLinks
|
||||||
|
|
||||||
if !accounts.isEmpty {
|
if !accounts.isEmpty {
|
||||||
|
if showRecents {
|
||||||
AppSidebarRecents()
|
AppSidebarRecents()
|
||||||
.id("recentlyOpened")
|
.id("recentlyOpened")
|
||||||
|
}
|
||||||
|
|
||||||
if accounts.api.signedIn {
|
if accounts.api.signedIn {
|
||||||
if visibleSections.contains(.subscriptions), accounts.app.supportsSubscriptions {
|
if visibleSections.contains(.subscriptions), accounts.app.supportsSubscriptions {
|
||||||
|
@ -10,6 +10,9 @@ struct HistorySettings: View {
|
|||||||
@Default(.saveRecents) private var saveRecents
|
@Default(.saveRecents) private var saveRecents
|
||||||
@Default(.saveLastPlayed) private var saveLastPlayed
|
@Default(.saveLastPlayed) private var saveLastPlayed
|
||||||
@Default(.saveHistory) private var saveHistory
|
@Default(.saveHistory) private var saveHistory
|
||||||
|
@Default(.showRecents) private var showRecents
|
||||||
|
@Default(.limitRecents) private var limitRecents
|
||||||
|
@Default(.limitRecentsAmount) private var limitRecentsAmount
|
||||||
@Default(.showWatchingProgress) private var showWatchingProgress
|
@Default(.showWatchingProgress) private var showWatchingProgress
|
||||||
@Default(.watchedThreshold) private var watchedThreshold
|
@Default(.watchedThreshold) private var watchedThreshold
|
||||||
@Default(.watchedVideoStyle) private var watchedVideoStyle
|
@Default(.watchedVideoStyle) private var watchedVideoStyle
|
||||||
@ -56,6 +59,26 @@ struct HistorySettings: View {
|
|||||||
Section(header: SettingsHeader(text: "History".localized())) {
|
Section(header: SettingsHeader(text: "History".localized())) {
|
||||||
Toggle("Save history of searches, channels and playlists", isOn: $saveRecents)
|
Toggle("Save history of searches, channels and playlists", isOn: $saveRecents)
|
||||||
Toggle("Save history of played videos", isOn: $saveHistory)
|
Toggle("Save history of played videos", isOn: $saveHistory)
|
||||||
|
Toggle("Show recents in sidebar", isOn: $showRecents)
|
||||||
|
#if os(macOS)
|
||||||
|
HStack {
|
||||||
|
Toggle("Limit recents shown", isOn: $limitRecents)
|
||||||
|
.frame(minWidth: 140, alignment: .leading)
|
||||||
|
.disabled(!showRecents)
|
||||||
|
Spacer()
|
||||||
|
counterButtons(for: $limitRecentsAmount)
|
||||||
|
.disabled(!limitRecents)
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
Toggle("Limit recents shown", isOn: $limitRecents)
|
||||||
|
.disabled(!showRecents)
|
||||||
|
HStack {
|
||||||
|
Text("Recents shown")
|
||||||
|
Spacer()
|
||||||
|
counterButtons(for: $limitRecentsAmount)
|
||||||
|
.disabled(!limitRecents)
|
||||||
|
}
|
||||||
|
#endif
|
||||||
Toggle("Show progress of watching on thumbnails", isOn: $showWatchingProgress)
|
Toggle("Show progress of watching on thumbnails", isOn: $showWatchingProgress)
|
||||||
.disabled(!saveHistory)
|
.disabled(!saveHistory)
|
||||||
Toggle("Keep last played video in the queue after restart", isOn: $saveLastPlayed)
|
Toggle("Keep last played video in the queue after restart", isOn: $saveLastPlayed)
|
||||||
@ -169,6 +192,71 @@ struct HistorySettings: View {
|
|||||||
.foregroundColor(.red)
|
.foregroundColor(.red)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func counterButtons(for _value: Binding<Int>) -> some View {
|
||||||
|
var value: Binding<Int> {
|
||||||
|
Binding(
|
||||||
|
get: { return _value.wrappedValue },
|
||||||
|
set: {
|
||||||
|
if $0 < 1 {
|
||||||
|
_value.wrappedValue = 1
|
||||||
|
} else {
|
||||||
|
_value.wrappedValue = $0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
return HStack {
|
||||||
|
#if !os(tvOS)
|
||||||
|
Label("Minus", systemImage: "minus")
|
||||||
|
.imageScale(.large)
|
||||||
|
.labelStyle(.iconOnly)
|
||||||
|
.padding(7)
|
||||||
|
.foregroundColor(limitRecents ? .accentColor : .gray)
|
||||||
|
.accessibilityAddTraits(.isButton)
|
||||||
|
#if os(iOS)
|
||||||
|
.frame(minHeight: 35)
|
||||||
|
.background(RoundedRectangle(cornerRadius: 4).strokeBorder(lineWidth: 1).foregroundColor(.accentColor))
|
||||||
|
#endif
|
||||||
|
.contentShape(Rectangle())
|
||||||
|
.onTapGesture {
|
||||||
|
value.wrappedValue -= 1
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if os(tvOS)
|
||||||
|
let textFieldWidth = 100.00
|
||||||
|
#else
|
||||||
|
let textFieldWidth = 30.00
|
||||||
|
#endif
|
||||||
|
|
||||||
|
TextField("Duration", value: value, formatter: NumberFormatter())
|
||||||
|
.frame(width: textFieldWidth, alignment: .trailing)
|
||||||
|
.multilineTextAlignment(.center)
|
||||||
|
.labelsHidden()
|
||||||
|
.foregroundColor(limitRecents ? .accentColor : .gray)
|
||||||
|
#if !os(macOS)
|
||||||
|
.keyboardType(.numberPad)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if !os(tvOS)
|
||||||
|
Label("Plus", systemImage: "plus")
|
||||||
|
.imageScale(.large)
|
||||||
|
.labelStyle(.iconOnly)
|
||||||
|
.padding(7)
|
||||||
|
.foregroundColor(limitRecents ? .accentColor : .gray)
|
||||||
|
.accessibilityAddTraits(.isButton)
|
||||||
|
#if os(iOS)
|
||||||
|
.background(RoundedRectangle(cornerRadius: 4).strokeBorder(lineWidth: 1).foregroundColor(.accentColor))
|
||||||
|
#endif
|
||||||
|
.contentShape(Rectangle())
|
||||||
|
.onTapGesture {
|
||||||
|
value.wrappedValue += 1
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct HistorySettings_Previews: PreviewProvider {
|
struct HistorySettings_Previews: PreviewProvider {
|
||||||
|
Loading…
Reference in New Issue
Block a user