-
-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
User Profile Image Selection (#1061)
- Loading branch information
Showing
37 changed files
with
949 additions
and
155 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// 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 SwiftUI | ||
|
||
struct RedrawOnNotificationView<Content: View>: View { | ||
|
||
@State | ||
private var id = 0 | ||
|
||
private let name: NSNotification.Name | ||
private let content: () -> Content | ||
|
||
init(name: NSNotification.Name, @ViewBuilder content: @escaping () -> Content) { | ||
self.name = name | ||
self.content = content | ||
} | ||
|
||
init(_ swiftfinNotification: Notifications.Key, @ViewBuilder content: @escaping () -> Content) { | ||
self.name = swiftfinNotification.underlyingNotification.name | ||
self.content = content | ||
} | ||
|
||
var body: some View { | ||
content() | ||
.id(id) | ||
.onNotification(name) { _ in | ||
id += 1 | ||
} | ||
} | ||
} |
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
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,40 @@ | ||
// | ||
// 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 Stinsen | ||
import SwiftUI | ||
|
||
final class UserProfileImageCoordinator: NavigationCoordinatable { | ||
|
||
let stack = Stinsen.NavigationStack(initial: \UserProfileImageCoordinator.start) | ||
|
||
@Root | ||
var start = makeStart | ||
|
||
@Route(.push) | ||
var cropImage = makeCropImage | ||
|
||
func makeCropImage(image: UIImage) -> some View { | ||
#if os(iOS) | ||
UserProfileImagePicker.SquareImageCropView( | ||
image: image | ||
) | ||
#else | ||
AssertionFailureView("not implemented") | ||
#endif | ||
} | ||
|
||
@ViewBuilder | ||
func makeStart() -> some View { | ||
#if os(iOS) | ||
UserProfileImagePicker() | ||
#else | ||
AssertionFailureView("not implemented") | ||
#endif | ||
} | ||
} |
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,16 @@ | ||
// | ||
// 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 Foundation | ||
|
||
extension Hashable { | ||
|
||
var hashString: String { | ||
"\(hashValue)" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// | ||
// 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 CoreStore | ||
import Foundation | ||
import Nuke | ||
|
||
// TODO: when `Storage` is implemented, could allow limits on sizes | ||
|
||
// Note: For better support with multi-url servers, ignore the | ||
// host and only use path + query which has ids and tags | ||
|
||
extension DataCache { | ||
enum Swiftfin {} | ||
} | ||
|
||
extension DataCache.Swiftfin { | ||
|
||
static let `default`: DataCache? = { | ||
let dataCache = try? DataCache(name: "org.jellyfin.swiftfin") { name in | ||
URL(string: name)?.pathAndQuery() ?? name | ||
} | ||
|
||
dataCache?.sizeLimit = 1024 * 1024 * 500 // 500 MB | ||
|
||
return dataCache | ||
}() | ||
|
||
/// The `DataCache` used for images that should have longer lifetimes, usable without a | ||
/// connection, and not affected by other caching size limits. | ||
/// | ||
/// Current 150 MB is more than necessary. | ||
static let branding: DataCache? = { | ||
guard let root = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first else { | ||
return nil | ||
} | ||
|
||
let path = root.appendingPathComponent("Cache/org.jellyfin.swiftfin.branding", isDirectory: true) | ||
|
||
let dataCache = try? DataCache(path: path) { name in | ||
|
||
// this adds some latency, but fine since | ||
// this DataCache is special | ||
if name.range(of: "Splashscreen") != nil { | ||
|
||
// TODO: potential issue where url ends with `/`, if | ||
// not found, retry with `/` appended | ||
let prefix = name.trimmingSuffix("/Branding/Splashscreen?") | ||
|
||
// can assume that we are only requesting a server with | ||
// the key same as the current url | ||
guard let prefixURL = URL(string: prefix) else { return name } | ||
guard let server = try? SwiftfinStore.dataStack.fetchOne( | ||
From<ServerModel>() | ||
.where(\.$currentURL == prefixURL) | ||
) else { return name } | ||
|
||
return "\(server.id)-splashscreen" | ||
} else { | ||
return URL(string: name)?.pathAndQuery() ?? name | ||
} | ||
} | ||
|
||
return dataCache | ||
}() | ||
} |
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,29 @@ | ||
// | ||
// 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 Foundation | ||
import Nuke | ||
|
||
extension ImagePipeline { | ||
enum Swiftfin {} | ||
} | ||
|
||
extension ImagePipeline.Swiftfin { | ||
|
||
/// The default `ImagePipeline` to use for images that should be used | ||
/// during normal usage with an active connection. | ||
static let `default`: ImagePipeline = ImagePipeline { | ||
$0.dataCache = DataCache.Swiftfin.default | ||
} | ||
|
||
/// The `ImagePipeline` used for images that should have longer lifetimes and usable | ||
/// without a connection, like user profile images and server splashscreens. | ||
static let branding: ImagePipeline = ImagePipeline { | ||
$0.dataCache = DataCache.Swiftfin.branding | ||
} | ||
} |
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.