This commit is contained in:
Ethan Pippin 2022-01-12 13:21:31 -07:00
parent 5e9d3a1c9c
commit 2d16b2886b
11 changed files with 143 additions and 145 deletions

View File

@ -184,20 +184,20 @@ final class HomeViewModel: ViewModel {
})
.store(in: &cancellables)
}
func removeItemFromResume(_ item: BaseItemDto) {
guard let itemID = item.id, resumeItems.contains(where: { $0.id == itemID }) else { return }
PlaystateAPI.markUnplayedItem(userId: SessionManager.main.currentLogin.user.id,
itemId: item.id!)
.sink(receiveCompletion: { [weak self] completion in
self?.handleAPIRequestError(completion: completion)
}, receiveValue: { _ in
self.refreshResumeItems()
self.refreshNextUpItems()
})
.store(in: &cancellables)
}
func removeItemFromResume(_ item: BaseItemDto) {
guard let itemID = item.id, resumeItems.contains(where: { $0.id == itemID }) else { return }
PlaystateAPI.markUnplayedItem(userId: SessionManager.main.currentLogin.user.id,
itemId: item.id!)
.sink(receiveCompletion: { [weak self] completion in
self?.handleAPIRequestError(completion: completion)
}, receiveValue: { _ in
self.refreshResumeItems()
self.refreshNextUpItems()
})
.store(in: &cancellables)
}
// MARK: Next Up Items

View File

@ -24,7 +24,7 @@ final class CollectionItemViewModel: ItemViewModel {
private func getCollectionItems() {
ItemsAPI.getItems(userId: SessionManager.main.currentLogin.user.id,
parentId: item.id,
fields: [.primaryImageAspectRatio, .seriesPrimaryImage, .seasonUserData, .overview, .genres, .people])
fields: [.primaryImageAspectRatio, .seriesPrimaryImage, .seasonUserData, .overview, .genres, .people])
.trackActivity(loading)
.sink { [weak self] completion in
self?.handleAPIRequestError(completion: completion)

View File

@ -238,17 +238,17 @@ final class VideoPlayerViewModel: ViewModel {
// MARK: Injected Values
extension VideoPlayerViewModel {
// Injects custom values that override certain settings
func injectCustomValues(startFromBeginning: Bool = false) {
if startFromBeginning {
item.userData?.playbackPositionTicks = 0
item.userData?.playedPercentage = 0
sliderPercentage = 0
sliderPercentageChanged(newValue: 0)
}
}
// Injects custom values that override certain settings
func injectCustomValues(startFromBeginning: Bool = false) {
if startFromBeginning {
item.userData?.playbackPositionTicks = 0
item.userData?.playedPercentage = 0
sliderPercentage = 0
sliderPercentageChanged(newValue: 0)
}
}
}
// MARK: Adjacent Items

View File

@ -17,47 +17,47 @@ struct EpisodeRowCard: View {
let episode: BaseItemDto
var body: some View {
VStack {
Button {
itemRouter.route(to: \.item, episode)
} label: {
ImageView(src: episode.getBackdropImage(maxWidth: 550),
bh: episode.getBackdropImageBlurHash())
.mask(Rectangle().frame(width: 550, height: 308))
.frame(width: 550, height: 308)
}
.buttonStyle(CardButtonStyle())
VStack(alignment: .leading) {
VStack {
Button {
itemRouter.route(to: \.item, episode)
} label: {
ImageView(src: episode.getBackdropImage(maxWidth: 550),
bh: episode.getBackdropImageBlurHash())
.mask(Rectangle().frame(width: 550, height: 308))
.frame(width: 550, height: 308)
}
.buttonStyle(CardButtonStyle())
VStack(alignment: .leading) {
Text(episode.getEpisodeLocator() ?? "")
.font(.caption)
.foregroundColor(.secondary)
Text(episode.name ?? "")
.font(.footnote)
.padding(.bottom, 1)
VStack(alignment: .leading) {
if episode.unaired {
Text(episode.airDateLabel ?? L10n.noOverviewAvailable)
.font(.caption)
.foregroundColor(.secondary)
.fontWeight(.light)
.lineLimit(3)
} else {
Text(episode.overview ?? "")
.font(.caption)
.fontWeight(.light)
.lineLimit(4)
.fixedSize(horizontal: false, vertical: true)
}
}
VStack(alignment: .leading) {
Text(episode.getEpisodeLocator() ?? "")
.font(.caption)
.foregroundColor(.secondary)
Text(episode.name ?? "")
.font(.footnote)
.padding(.bottom, 1)
Spacer()
}
.padding()
.frame(width: 550)
}
.focusSection()
if episode.unaired {
Text(episode.airDateLabel ?? L10n.noOverviewAvailable)
.font(.caption)
.foregroundColor(.secondary)
.fontWeight(.light)
.lineLimit(3)
} else {
Text(episode.overview ?? "")
.font(.caption)
.fontWeight(.light)
.lineLimit(4)
.fixedSize(horizontal: false, vertical: true)
}
}
Spacer()
}
.padding()
.frame(width: 550)
}
.focusSection()
}
}

View File

@ -13,8 +13,8 @@ struct CinematicResumeCardView: View {
@EnvironmentObject
var homeRouter: HomeCoordinator.Router
@ObservedObject
var viewModel: HomeViewModel
@ObservedObject
var viewModel: HomeViewModel
let item: BaseItemDto
var body: some View {
@ -55,15 +55,15 @@ struct CinematicResumeCardView: View {
}
.frame(width: 350, height: 210)
}
.buttonStyle(CardButtonStyle())
.padding(.top)
.contextMenu {
Button(role: .destructive) {
viewModel.removeItemFromResume(item)
} label: {
L10n.removeFromResume.text
}
}
.buttonStyle(CardButtonStyle())
.padding(.top)
.contextMenu {
Button(role: .destructive) {
viewModel.removeItemFromResume(item)
} label: {
L10n.removeFromResume.text
}
}
}
.padding(.vertical)
}

View File

@ -33,8 +33,8 @@ struct HomeCinematicView: View {
@FocusState
var selectedItem: BaseItemDto?
@ObservedObject
var viewModel: HomeViewModel
@ObservedObject
var viewModel: HomeViewModel
@State
private var updatedSelectedItem: BaseItemDto?
@State
@ -43,8 +43,8 @@ struct HomeCinematicView: View {
private let items: [HomeCinematicViewItem]
private let backgroundViewModel = DynamicCinematicBackgroundViewModel()
init(viewModel: HomeViewModel, items: [HomeCinematicViewItem], forcedItemSubtitle: String? = nil) {
self.viewModel = viewModel
init(viewModel: HomeViewModel, items: [HomeCinematicViewItem], forcedItemSubtitle: String? = nil) {
self.viewModel = viewModel
self.items = items
self.forcedItemSubtitle = forcedItemSubtitle
}
@ -102,7 +102,7 @@ struct HomeCinematicView: View {
CinematicNextUpCardView(item: item.item, showOverlay: true)
.focused($selectedItem, equals: item.item)
case .resume:
CinematicResumeCardView(viewModel: viewModel, item: item.item)
CinematicResumeCardView(viewModel: viewModel, item: item.item)
.focused($selectedItem, equals: item.item)
case .plain:
CinematicNextUpCardView(item: item.item, showOverlay: false)

View File

@ -32,8 +32,8 @@ struct HomeView: View {
LazyVStack(alignment: .leading) {
if viewModel.resumeItems.isEmpty {
HomeCinematicView(viewModel: viewModel,
items: viewModel.latestAddedItems.map { .init(item: $0, type: .plain) },
HomeCinematicView(viewModel: viewModel,
items: viewModel.latestAddedItems.map { .init(item: $0, type: .plain) },
forcedItemSubtitle: L10n.recentlyAdded)
if !viewModel.nextUpItems.isEmpty {
@ -42,7 +42,7 @@ struct HomeView: View {
}
} else {
HomeCinematicView(viewModel: viewModel,
items: viewModel.resumeItems.map { .init(item: $0, type: .resume) })
items: viewModel.resumeItems.map { .init(item: $0, type: .resume) })
if !viewModel.nextUpItems.isEmpty {
NextUpView(items: viewModel.nextUpItems)

View File

@ -78,26 +78,24 @@ struct CinematicItemViewTopRow: View {
.cornerRadius(10)
}
.buttonStyle(CardButtonStyle())
.contextMenu {
if viewModel.playButtonItem != nil, viewModel.item.userData?.playbackPositionTicks ?? 0 > 0 {
Button {
if let itemVideoPlayerViewModel = viewModel.itemVideoPlayerViewModel {
itemVideoPlayerViewModel.injectCustomValues(startFromBeginning: true)
itemRouter.route(to: \.videoPlayer, itemVideoPlayerViewModel)
} else {
LogManager.shared.log.error("Attempted to play item but no playback information available")
}
} label: {
Label(L10n.playFromBeginning, systemImage: "gobackward")
}
Button(role: .cancel) {
} label: {
L10n.cancel.text
}
}
}
.contextMenu {
if viewModel.playButtonItem != nil, viewModel.item.userData?.playbackPositionTicks ?? 0 > 0 {
Button {
if let itemVideoPlayerViewModel = viewModel.itemVideoPlayerViewModel {
itemVideoPlayerViewModel.injectCustomValues(startFromBeginning: true)
itemRouter.route(to: \.videoPlayer, itemVideoPlayerViewModel)
} else {
LogManager.shared.log.error("Attempted to play item but no playback information available")
}
} label: {
Label(L10n.playFromBeginning, systemImage: "gobackward")
}
Button(role: .cancel) {} label: {
L10n.cancel.text
}
}
}
}
}

View File

@ -81,13 +81,13 @@ struct ContinueWatchingView: View {
}
}
}
.contextMenu {
Button(role: .destructive) {
viewModel.removeItemFromResume(item)
} label: {
L10n.removeFromResume.text
}
}
.contextMenu {
Button(role: .destructive) {
viewModel.removeItemFromResume(item)
} label: {
L10n.removeFromResume.text
}
}
}
}
.padding(.horizontal)

View File

@ -50,20 +50,20 @@ struct ItemLandscapeMainView: View {
.cornerRadius(10)
}
.disabled(viewModel.playButtonItem == nil || viewModel.itemVideoPlayerViewModel == nil)
.contextMenu {
if viewModel.playButtonItem != nil, viewModel.item.userData?.playbackPositionTicks ?? 0 > 0 {
Button {
if let itemVideoPlayerViewModel = viewModel.itemVideoPlayerViewModel {
itemVideoPlayerViewModel.injectCustomValues(startFromBeginning: true)
itemRouter.route(to: \.videoPlayer, itemVideoPlayerViewModel)
} else {
LogManager.shared.log.error("Attempted to play item but no playback information available")
}
} label: {
Label(L10n.playFromBeginning, systemImage: "gobackward")
}
}
}
.contextMenu {
if viewModel.playButtonItem != nil, viewModel.item.userData?.playbackPositionTicks ?? 0 > 0 {
Button {
if let itemVideoPlayerViewModel = viewModel.itemVideoPlayerViewModel {
itemVideoPlayerViewModel.injectCustomValues(startFromBeginning: true)
itemRouter.route(to: \.videoPlayer, itemVideoPlayerViewModel)
} else {
LogManager.shared.log.error("Attempted to play item but no playback information available")
}
} label: {
Label(L10n.playFromBeginning, systemImage: "gobackward")
}
}
}
Spacer()
}

View File

@ -90,11 +90,11 @@ struct PortraitHeaderOverlayView: View {
// MARK: Play
Button {
if let itemVideoPlayerViewModel = viewModel.itemVideoPlayerViewModel {
itemRouter.route(to: \.videoPlayer, itemVideoPlayerViewModel)
} else {
LogManager.shared.log.error("Attempted to play item but no playback information available")
}
if let itemVideoPlayerViewModel = viewModel.itemVideoPlayerViewModel {
itemRouter.route(to: \.videoPlayer, itemVideoPlayerViewModel)
} else {
LogManager.shared.log.error("Attempted to play item but no playback information available")
}
} label: {
HStack {
Image(systemName: "play.fill")
@ -109,21 +109,21 @@ struct PortraitHeaderOverlayView: View {
.background(viewModel.playButtonItem == nil ? Color(UIColor.secondarySystemFill) : Color.jellyfinPurple)
.cornerRadius(10)
}
.disabled(viewModel.playButtonItem == nil)
.contextMenu {
if viewModel.playButtonItem != nil, viewModel.item.userData?.playbackPositionTicks ?? 0 > 0 {
Button {
if let itemVideoPlayerViewModel = viewModel.itemVideoPlayerViewModel {
itemVideoPlayerViewModel.injectCustomValues(startFromBeginning: true)
itemRouter.route(to: \.videoPlayer, itemVideoPlayerViewModel)
} else {
LogManager.shared.log.error("Attempted to play item but no playback information available")
}
} label: {
Label(L10n.playFromBeginning, systemImage: "gobackward")
}
}
}
.disabled(viewModel.playButtonItem == nil)
.contextMenu {
if viewModel.playButtonItem != nil, viewModel.item.userData?.playbackPositionTicks ?? 0 > 0 {
Button {
if let itemVideoPlayerViewModel = viewModel.itemVideoPlayerViewModel {
itemVideoPlayerViewModel.injectCustomValues(startFromBeginning: true)
itemRouter.route(to: \.videoPlayer, itemVideoPlayerViewModel)
} else {
LogManager.shared.log.error("Attempted to play item but no playback information available")
}
} label: {
Label(L10n.playFromBeginning, systemImage: "gobackward")
}
}
}
Spacer()