mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 20:24:06 +00:00
Improve history, resume videos, mark watched videos (fixes #42)
This commit is contained in:
@@ -31,12 +31,12 @@ struct PlayerControlsView<Content: View>: View {
|
||||
}) {
|
||||
HStack {
|
||||
VStack(alignment: .leading, spacing: 3) {
|
||||
Text(model.currentItem?.video?.title ?? "Not playing")
|
||||
Text(model.currentVideo?.title ?? "Not playing")
|
||||
.font(.system(size: 14).bold())
|
||||
.foregroundColor(model.currentItem.isNil ? .secondary : .accentColor)
|
||||
.lineLimit(1)
|
||||
|
||||
Text(model.currentItem?.video?.author ?? "Yattee v\(appVersion) (build \(appBuild))")
|
||||
Text(model.currentVideo?.author ?? "Yattee v\(appVersion) (build \(appBuild))")
|
||||
.fontWeight(model.currentItem.isNil ? .light : .bold)
|
||||
.font(.system(size: 10))
|
||||
.foregroundColor(.secondary)
|
||||
|
@@ -1,3 +1,4 @@
|
||||
import CoreData
|
||||
import Defaults
|
||||
import SwiftUI
|
||||
|
||||
@@ -19,7 +20,35 @@ struct VideoContextMenuView: View {
|
||||
@EnvironmentObject<RecentsModel> private var recents
|
||||
@EnvironmentObject<SubscriptionsModel> private var subscriptions
|
||||
|
||||
@FetchRequest private var watchRequest: FetchedResults<Watch>
|
||||
|
||||
@Default(.saveHistory) private var saveHistory
|
||||
|
||||
private var viewContext: NSManagedObjectContext = PersistenceController.shared.container.viewContext
|
||||
|
||||
init(video: Video, playerNavigationLinkActive: Binding<Bool>) {
|
||||
self.video = video
|
||||
_playerNavigationLinkActive = playerNavigationLinkActive
|
||||
_watchRequest = video.watchFetchRequest
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
if saveHistory {
|
||||
Section {
|
||||
if let watchedAtString = watchedAtString {
|
||||
Text(watchedAtString)
|
||||
}
|
||||
|
||||
if !watch.isNil, !watch!.finished, !watchingNow {
|
||||
continueButton
|
||||
}
|
||||
|
||||
if !watch.isNil, !watchingNow {
|
||||
removeFromHistoryButton
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Section {
|
||||
playNowButton
|
||||
}
|
||||
@@ -54,19 +83,49 @@ struct VideoContextMenuView: View {
|
||||
#endif
|
||||
}
|
||||
|
||||
private var playNowButton: some View {
|
||||
Button {
|
||||
player.playNow(video)
|
||||
private var watch: Watch? {
|
||||
watchRequest.first
|
||||
}
|
||||
|
||||
guard !player.playingInPictureInPicture else {
|
||||
private var watchingNow: Bool {
|
||||
player.currentVideo == video
|
||||
}
|
||||
|
||||
private var watchedAtString: String? {
|
||||
if watchingNow {
|
||||
return "Watching now"
|
||||
}
|
||||
|
||||
if let watch = watch, let watchedAtString = watch.watchedAtString {
|
||||
return "Watched \(watchedAtString)"
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
private var continueButton: some View {
|
||||
Button {
|
||||
player.play(video, at: watch!.stoppedAt, inNavigationView: inNavigationView)
|
||||
} label: {
|
||||
Label("Continue from \(watch!.stoppedAt.formattedAsPlaybackTime() ?? "where I left off")", systemImage: "playpause")
|
||||
}
|
||||
}
|
||||
|
||||
var removeFromHistoryButton: some View {
|
||||
Button {
|
||||
guard let watch = watch else {
|
||||
return
|
||||
}
|
||||
|
||||
if inNavigationView {
|
||||
playerNavigationLinkActive = true
|
||||
} else {
|
||||
player.show()
|
||||
}
|
||||
player.removeWatch(watch)
|
||||
} label: {
|
||||
Label("Remove from history", systemImage: "delete.left.fill")
|
||||
}
|
||||
}
|
||||
|
||||
private var playNowButton: some View {
|
||||
Button {
|
||||
player.play(video, inNavigationView: inNavigationView)
|
||||
} label: {
|
||||
Label("Play Now", systemImage: "play")
|
||||
}
|
||||
|
Reference in New Issue
Block a user