mirror of
https://github.com/cranci1/Sora.git
synced 2026-03-11 17:45:37 +00:00
uh?
Some checks are pending
Build and Release IPA / Build IPA and Mac Catalyst (push) Waiting to run
Some checks are pending
Build and Release IPA / Build IPA and Mac Catalyst (push) Waiting to run
This commit is contained in:
parent
67894ade21
commit
6cd4df40b9
3 changed files with 29 additions and 2 deletions
Binary file not shown.
|
|
@ -32,7 +32,7 @@ class LibraryManager: ObservableObject {
|
|||
}
|
||||
|
||||
func addToLibrary(_ item: LibraryItem) {
|
||||
if !libraryItems.contains(where: { $0.anilistID == item.anilistID }) {
|
||||
if !libraryItems.contains(where: { $0.id == item.id }) {
|
||||
libraryItems.append(item)
|
||||
saveLibrary()
|
||||
Logger.shared.log("Added to library: \(item.title)")
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ struct MediaView: View {
|
|||
@State private var selectedEpisodeNumber: Int = 0
|
||||
|
||||
@AppStorage("externalPlayer") private var externalPlayer: String = "Default"
|
||||
@StateObject private var libraryManager = LibraryManager.shared
|
||||
|
||||
var body: some View {
|
||||
Group {
|
||||
|
|
@ -119,8 +120,13 @@ struct MediaView: View {
|
|||
}
|
||||
|
||||
Button(action: {
|
||||
if isItemInLibrary() {
|
||||
removeFromLibrary()
|
||||
} else {
|
||||
addToLibrary()
|
||||
}
|
||||
}) {
|
||||
Image(systemName: "bookmark")
|
||||
Image(systemName: isItemInLibrary() ? "bookmark.fill" : "bookmark")
|
||||
.resizable()
|
||||
.frame(width: 20, height: 27)
|
||||
}
|
||||
|
|
@ -170,6 +176,27 @@ struct MediaView: View {
|
|||
}
|
||||
}
|
||||
|
||||
func isItemInLibrary() -> Bool {
|
||||
return libraryManager.libraryItems.contains(where: { $0.url == item.href })
|
||||
}
|
||||
|
||||
func addToLibrary() {
|
||||
let libraryItem = LibraryItem(
|
||||
anilistID: itemID ?? 0,
|
||||
title: item.name,
|
||||
image: item.imageUrl,
|
||||
url: item.href,
|
||||
dateAdded: Date()
|
||||
)
|
||||
libraryManager.addToLibrary(libraryItem)
|
||||
}
|
||||
|
||||
func removeFromLibrary() {
|
||||
if let libraryItem = libraryManager.libraryItems.first(where: { $0.url == item.href }) {
|
||||
libraryManager.removeFromLibrary(libraryItem)
|
||||
}
|
||||
}
|
||||
|
||||
func playStream(urlString: String?, fullURL: String) {
|
||||
guard let streamUrl = urlString else { return }
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue