mirror of
https://github.com/yattee/yattee.git
synced 2025-08-04 01:34:10 +00:00
Fix updating watch history
This commit is contained in:
67
Shared/Videos/WatchView.swift
Normal file
67
Shared/Videos/WatchView.swift
Normal file
@@ -0,0 +1,67 @@
|
||||
import Defaults
|
||||
import Foundation
|
||||
import SwiftUI
|
||||
|
||||
struct WatchView: View {
|
||||
var watch: Watch?
|
||||
var videoID: Video.ID
|
||||
var duration: Double
|
||||
|
||||
@Default(.watchedVideoBadgeColor) private var watchedVideoBadgeColor
|
||||
|
||||
var backgroundContext = PersistenceController.shared.container.newBackgroundContext()
|
||||
|
||||
var body: some View {
|
||||
#if os(tvOS)
|
||||
if finished {
|
||||
image
|
||||
}
|
||||
#else
|
||||
Button(action: toggleWatch) {
|
||||
image
|
||||
}
|
||||
.opacity(finished ? 1 : 0.4)
|
||||
.buttonStyle(.plain)
|
||||
#endif
|
||||
}
|
||||
|
||||
var image: some View {
|
||||
Image(systemName: imageSystemName)
|
||||
.foregroundColor(Color(
|
||||
watchedVideoBadgeColor == .colorSchemeBased ? "WatchProgressBarColor" :
|
||||
watchedVideoBadgeColor == .red ? "AppRedColor" : "AppBlueColor"
|
||||
))
|
||||
.background(backgroundColor)
|
||||
.clipShape(Circle())
|
||||
.imageScale(.large)
|
||||
}
|
||||
|
||||
func toggleWatch() {
|
||||
if finished, let watch {
|
||||
PlayerModel.shared.removeWatch(watch)
|
||||
} else {
|
||||
Watch.markAsWatched(videoID: watch?.videoID ?? videoID, account: AccountsModel.shared.current, duration: watch?.videoDuration ?? duration, context: backgroundContext)
|
||||
}
|
||||
|
||||
FeedModel.shared.calculateUnwatchedFeed()
|
||||
}
|
||||
|
||||
var imageSystemName: String {
|
||||
finished ? "checkmark.circle.fill" : "circle"
|
||||
}
|
||||
|
||||
var backgroundColor: Color {
|
||||
finished ? .white : .clear
|
||||
}
|
||||
|
||||
var finished: Bool {
|
||||
guard let watch else { return false }
|
||||
return watch.finished
|
||||
}
|
||||
}
|
||||
|
||||
struct WatchView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
WatchView(videoID: "abc", duration: 10)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user