mirror of
https://github.com/yattee/yattee.git
synced 2024-12-14 14:20:32 +05:30
Add clear history button to home
This commit is contained in:
parent
8727fb1e30
commit
78ff495927
@ -94,6 +94,11 @@ extension PlayerModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func removeHistory() {
|
||||||
|
removeAllWatches()
|
||||||
|
CacheModel.shared.removeAll()
|
||||||
|
}
|
||||||
|
|
||||||
func removeWatch(_ watch: Watch) {
|
func removeWatch(_ watch: Watch) {
|
||||||
context.delete(watch)
|
context.delete(watch)
|
||||||
try? context.save()
|
try? context.save()
|
||||||
|
@ -3,13 +3,13 @@ import SwiftUI
|
|||||||
struct HistoryView: View {
|
struct HistoryView: View {
|
||||||
static let detailsPreloadLimit = 50
|
static let detailsPreloadLimit = 50
|
||||||
|
|
||||||
|
var limit = 10
|
||||||
|
|
||||||
@FetchRequest(sortDescriptors: [.init(key: "watchedAt", ascending: false)])
|
@FetchRequest(sortDescriptors: [.init(key: "watchedAt", ascending: false)])
|
||||||
var watches: FetchedResults<Watch>
|
var watches: FetchedResults<Watch>
|
||||||
|
|
||||||
@EnvironmentObject<PlayerModel> private var player
|
@EnvironmentObject<PlayerModel> private var player
|
||||||
|
|
||||||
var limit = 10
|
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
LazyVStack {
|
LazyVStack {
|
||||||
if visibleWatches.isEmpty {
|
if visibleWatches.isEmpty {
|
||||||
|
@ -12,6 +12,10 @@ struct HomeView: View {
|
|||||||
|
|
||||||
@State private var favoritesChanged = false
|
@State private var favoritesChanged = false
|
||||||
|
|
||||||
|
@FetchRequest(sortDescriptors: [.init(key: "watchedAt", ascending: false)])
|
||||||
|
var watches: FetchedResults<Watch>
|
||||||
|
@State private var historyID = UUID()
|
||||||
|
|
||||||
var favoritesObserver: Any?
|
var favoritesObserver: Any?
|
||||||
|
|
||||||
#if !os(tvOS)
|
#if !os(tvOS)
|
||||||
@ -79,16 +83,33 @@ struct HomeView: View {
|
|||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
.workaroundForVerticalScrollingBug()
|
.workaroundForVerticalScrollingBug()
|
||||||
#endif
|
#endif
|
||||||
#if os(iOS)
|
|
||||||
.padding(.top, item == first && RefreshControl.navigationBarTitleDisplayMode == .inline ? 10 : 0)
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if homeHistoryItems > 0 {
|
if homeHistoryItems > 0 {
|
||||||
VStack {
|
VStack {
|
||||||
|
HStack {
|
||||||
Text("History")
|
Text("History")
|
||||||
|
Spacer()
|
||||||
|
Button {
|
||||||
|
navigation.presentAlert(
|
||||||
|
Alert(
|
||||||
|
title: Text("Are you sure you want to clear history of watched videos?"),
|
||||||
|
message: Text("It cannot be reverted"),
|
||||||
|
primaryButton: .destructive(Text("Clear All")) {
|
||||||
|
PlayerModel.shared.removeHistory()
|
||||||
|
historyID = UUID()
|
||||||
|
},
|
||||||
|
secondaryButton: .cancel()
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} label: {
|
||||||
|
Label("Clear History", systemImage: "trash")
|
||||||
|
.font(.headline)
|
||||||
|
.labelStyle(.iconOnly)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#if os(tvOS)
|
#if os(tvOS)
|
||||||
.padding(.horizontal, 40)
|
.padding(.horizontal, 40)
|
||||||
@ -100,6 +121,7 @@ struct HomeView: View {
|
|||||||
.foregroundColor(.secondary)
|
.foregroundColor(.secondary)
|
||||||
|
|
||||||
HistoryView(limit: homeHistoryItems)
|
HistoryView(limit: homeHistoryItems)
|
||||||
|
.id(historyID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,9 +29,12 @@ struct PlayerQueueRow: View {
|
|||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
Button {
|
Button {
|
||||||
guard let video = item.video else {
|
guard let video = item.video else { return }
|
||||||
|
guard video != player.currentVideo else {
|
||||||
|
player.show()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
guard !video.localStreamIsDirectory else {
|
guard !video.localStreamIsDirectory else {
|
||||||
if let url = video.localStream?.localURL {
|
if let url = video.localStream?.localURL {
|
||||||
|
@ -151,10 +151,7 @@ struct HistorySettings: View {
|
|||||||
message: Text(
|
message: Text(
|
||||||
"This cannot be reverted. You might need to switch between views or restart the app to see changes."
|
"This cannot be reverted. You might need to switch between views or restart the app to see changes."
|
||||||
),
|
),
|
||||||
primaryButton: .destructive(Text("Clear All")) {
|
primaryButton: .destructive(Text("Clear All"), action: player.removeHistory),
|
||||||
player.removeAllWatches()
|
|
||||||
CacheModel.shared.removeAll()
|
|
||||||
},
|
|
||||||
secondaryButton: .cancel()
|
secondaryButton: .cancel()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user