1
0
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:
Arkadiusz Fal 2022-11-15 12:22:27 +01:00
parent 8727fb1e30
commit 78ff495927
5 changed files with 43 additions and 16 deletions

View File

@ -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()

View File

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

View File

@ -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,27 +83,45 @@ 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 {
Text("History") HStack {
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)
#else #else
.padding(.horizontal, 15) .padding(.horizontal, 15)
#endif #endif
.font(.title3.bold()) .font(.title3.bold())
.frame(maxWidth: .infinity, alignment: .leading) .frame(maxWidth: .infinity, alignment: .leading)
.foregroundColor(.secondary) .foregroundColor(.secondary)
HistoryView(limit: homeHistoryItems) HistoryView(limit: homeHistoryItems)
.id(historyID)
} }
} }

View File

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

View File

@ -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()
) )
) )