* ItemViewModel Trailers * iOS done. * Sections >>> Divider * tvOS kind of. * Button/Menu cleanup * Huge ActionButton overhaul * Error Handling, ActionButton/Menu standardization, and ActionButtonLayout cleanup part 1. * cleanup * cleanup * Combine ActionButton logic. Complete ActionButton rework and animation/style rework. Should this be 3 files?? * Dumb sizing error. Get size from WIDTH not HEIGHT! Height is always 100 and Width is larger. * Pressed buttons are but focused buttons but slight less. Pressed buttons are still bigger than default, unfocused buttons. TIL. * Cleanup / Structure * Remove Test. * New Setting. Version on PlayButton Row. Complete TrailerMenu revamp. Make ActionButtonLayout a single row. * Spacing & remove test logic * VERY WIP * Fix the compact-ness * Linting. * Remove Testing logic. * Pre-Cleanup - WIP * Finalized. Moved ScrollingText to tvOS Only. * MediaURL? = nil but it's already nil by default. * Error on the View not the button. This was NOT showing for the button since it lived on the Menu. This resolves this. * wip * Update VersionMenu.swift * Remove scrollingText from this PR. * Remove labels & iOS Action Button cleanup / no foregroundStyle on de-selected. * ActionButtonScaling * .card all buttons in ActionButton * Slow and less bounce-i-fy the menu animations. Also, slight padding * Wait, don't add this padding this isn't needed. * localize --------- Co-authored-by: Ethan Pippin <ethanpippin2343@gmail.com>
128 lines
3.8 KiB
Swift
128 lines
3.8 KiB
Swift
//
|
|
// Swiftfin is subject to the terms of the Mozilla Public
|
|
// License, v2.0. If a copy of the MPL was not distributed with this
|
|
// file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
|
//
|
|
// Copyright (c) 2025 Jellyfin & Jellyfin Contributors
|
|
//
|
|
|
|
import Defaults
|
|
import Factory
|
|
import JellyfinAPI
|
|
import SwiftUI
|
|
|
|
// TODO: replace `equalSpacing` handling with a `Layout`
|
|
|
|
extension ItemView {
|
|
|
|
struct ActionButtonHStack: View {
|
|
|
|
@Default(.accentColor)
|
|
private var accentColor
|
|
|
|
@StoredValue(.User.enabledTrailers)
|
|
private var enabledTrailers: TrailerSelection
|
|
|
|
@ObservedObject
|
|
private var viewModel: ItemViewModel
|
|
|
|
private let equalSpacing: Bool
|
|
|
|
// MARK: - Has Trailers
|
|
|
|
private var hasTrailers: Bool {
|
|
if enabledTrailers.contains(.local), viewModel.localTrailers.isNotEmpty {
|
|
return true
|
|
}
|
|
|
|
if enabledTrailers.contains(.external), viewModel.item.remoteTrailers?.isNotEmpty == true {
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
// MARK: - Initializer
|
|
|
|
init(viewModel: ItemViewModel, equalSpacing: Bool = true) {
|
|
self.viewModel = viewModel
|
|
self.equalSpacing = equalSpacing
|
|
}
|
|
|
|
// MARK: - Body
|
|
|
|
var body: some View {
|
|
HStack(alignment: .center, spacing: 15) {
|
|
|
|
// MARK: Toggle Played
|
|
|
|
let isCheckmarkSelected = viewModel.item.userData?.isPlayed == true
|
|
|
|
ActionButton(
|
|
L10n.played,
|
|
icon: "checkmark.circle",
|
|
selectedIcon: "checkmark.circle.fill"
|
|
) {
|
|
UIDevice.impact(.light)
|
|
viewModel.send(.toggleIsPlayed)
|
|
}
|
|
.environment(\.isSelected, isCheckmarkSelected)
|
|
.if(isCheckmarkSelected) { item in
|
|
item
|
|
.foregroundStyle(
|
|
.primary,
|
|
accentColor
|
|
)
|
|
}
|
|
.if(equalSpacing) { view in
|
|
view.frame(maxWidth: .infinity)
|
|
}
|
|
|
|
// MARK: Toggle Favorite
|
|
|
|
let isHeartSelected = viewModel.item.userData?.isFavorite == true
|
|
|
|
ActionButton(
|
|
L10n.favorited,
|
|
icon: "heart",
|
|
selectedIcon: "heart.fill"
|
|
) {
|
|
UIDevice.impact(.light)
|
|
viewModel.send(.toggleIsFavorite)
|
|
}
|
|
.environment(\.isSelected, isHeartSelected)
|
|
.if(isHeartSelected) { item in
|
|
item
|
|
.foregroundStyle(Color.red)
|
|
}
|
|
.if(equalSpacing) { view in
|
|
view.frame(maxWidth: .infinity)
|
|
}
|
|
|
|
// MARK: Select a Version
|
|
|
|
if let mediaSources = viewModel.playButtonItem?.mediaSources,
|
|
mediaSources.count > 1
|
|
{
|
|
VersionMenu(viewModel: viewModel, mediaSources: mediaSources)
|
|
.if(equalSpacing) { view in
|
|
view.frame(maxWidth: .infinity)
|
|
}
|
|
}
|
|
|
|
// MARK: Watch a Trailer
|
|
|
|
if hasTrailers {
|
|
TrailerMenu(
|
|
localTrailers: viewModel.localTrailers,
|
|
externalTrailers: viewModel.item.remoteTrailers ?? []
|
|
)
|
|
.if(equalSpacing) { view in
|
|
view.frame(maxWidth: .infinity)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|