-
-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'jellyfin:main' into iOSSettingsUpdate
- Loading branch information
Showing
44 changed files
with
753 additions
and
363 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
Shared/Components/UserProfileImage/UserProfileHeroImage.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// | ||
// 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) 2024 Jellyfin & Jellyfin Contributors | ||
// | ||
|
||
import Defaults | ||
import Factory | ||
import JellyfinAPI | ||
import Nuke | ||
import SwiftUI | ||
|
||
struct UserProfileHeroImage: View { | ||
|
||
// MARK: - Accent Color | ||
|
||
@Default(.accentColor) | ||
private var accentColor | ||
|
||
// MARK: - User Session | ||
|
||
@Injected(\.currentUserSession) | ||
private var userSession | ||
|
||
// MARK: - User Variables | ||
|
||
private let user: UserDto | ||
private let source: ImageSource | ||
private let pipeline: ImagePipeline | ||
|
||
// MARK: - User Actions | ||
|
||
private let onUpdate: () -> Void | ||
private let onDelete: () -> Void | ||
|
||
// MARK: - Dialog State | ||
|
||
@State | ||
private var isPresentingOptions: Bool = false | ||
|
||
// MARK: - Initializer | ||
|
||
init( | ||
user: UserDto, | ||
source: ImageSource, | ||
pipeline: ImagePipeline = .Swiftfin.posters, | ||
onUpdate: @escaping () -> Void, | ||
onDelete: @escaping () -> Void | ||
) { | ||
self.user = user | ||
self.source = source | ||
self.pipeline = pipeline | ||
self.onUpdate = onUpdate | ||
self.onDelete = onDelete | ||
} | ||
|
||
// MARK: - Body | ||
|
||
var body: some View { | ||
Section { | ||
VStack(alignment: .center) { | ||
Button { | ||
isPresentingOptions = true | ||
} label: { | ||
ZStack(alignment: .bottomTrailing) { | ||
UserProfileImage( | ||
userID: user.id, | ||
source: source, | ||
pipeline: userSession?.user.id == user.id ? .Swiftfin.local : .Swiftfin.posters | ||
) | ||
.frame(width: 150, height: 150) | ||
|
||
Image(systemName: "pencil.circle.fill") | ||
.resizable() | ||
.frame(width: 30, height: 30) | ||
.shadow(radius: 10) | ||
.symbolRenderingMode(.palette) | ||
.foregroundStyle(accentColor.overlayColor, accentColor) | ||
} | ||
} | ||
|
||
Text(user.name ?? L10n.unknown) | ||
.fontWeight(.semibold) | ||
.font(.title2) | ||
} | ||
.frame(maxWidth: .infinity) | ||
.listRowBackground(Color.clear) | ||
} | ||
.confirmationDialog( | ||
L10n.profileImage, | ||
isPresented: $isPresentingOptions, | ||
titleVisibility: .visible | ||
) { | ||
Button(L10n.selectImage, action: onUpdate) | ||
|
||
Button(L10n.delete, role: .destructive, action: onDelete) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// | ||
// 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) 2024 Jellyfin & Jellyfin Contributors | ||
// | ||
|
||
import Defaults | ||
import Factory | ||
import JellyfinAPI | ||
import Nuke | ||
import SwiftUI | ||
|
||
struct UserProfileImage<Placeholder: View>: View { | ||
|
||
// MARK: - Inject Logger | ||
|
||
@Injected(\.logService) | ||
private var logger | ||
|
||
// MARK: - User Variables | ||
|
||
private let userID: String? | ||
private let source: ImageSource | ||
private let pipeline: ImagePipeline | ||
private let placeholder: Placeholder | ||
|
||
// MARK: - Body | ||
|
||
var body: some View { | ||
RedrawOnNotificationView( | ||
.didChangeUserProfile, | ||
filter: { | ||
$0 == userID | ||
} | ||
) { | ||
ImageView(source) | ||
.pipeline(pipeline) | ||
.image { | ||
$0.posterBorder(ratio: 1 / 2, of: \.width) | ||
} | ||
.placeholder { _ in | ||
placeholder | ||
} | ||
.failure { | ||
placeholder | ||
} | ||
.posterShadow() | ||
.aspectRatio(1, contentMode: .fill) | ||
.clipShape(Circle()) | ||
.shadow(radius: 5) | ||
} | ||
} | ||
} | ||
|
||
// MARK: - Initializer | ||
|
||
extension UserProfileImage { | ||
|
||
init( | ||
userID: String?, | ||
source: ImageSource, | ||
pipeline: ImagePipeline = .Swiftfin.posters, | ||
@ViewBuilder placeholder: @escaping () -> Placeholder | ||
) { | ||
self.userID = userID | ||
self.source = source | ||
self.pipeline = pipeline | ||
self.placeholder = placeholder() | ||
} | ||
} | ||
|
||
extension UserProfileImage where Placeholder == SystemImageContentView { | ||
|
||
init( | ||
userID: String?, | ||
source: ImageSource, | ||
pipeline: ImagePipeline = .Swiftfin.posters | ||
) { | ||
self.userID = userID | ||
self.source = source | ||
self.pipeline = pipeline | ||
self.placeholder = SystemImageContentView(systemName: "person.fill", ratio: 0.5) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.