uh?
Some checks are pending
Build and Release IPA / Build IPA and Mac Catalyst (push) Waiting to run

This commit is contained in:
cranci1 2024-12-28 21:13:55 +01:00
parent 67894ade21
commit 6cd4df40b9
3 changed files with 29 additions and 2 deletions

View file

@ -32,7 +32,7 @@ class LibraryManager: ObservableObject {
} }
func addToLibrary(_ item: LibraryItem) { func addToLibrary(_ item: LibraryItem) {
if !libraryItems.contains(where: { $0.anilistID == item.anilistID }) { if !libraryItems.contains(where: { $0.id == item.id }) {
libraryItems.append(item) libraryItems.append(item)
saveLibrary() saveLibrary()
Logger.shared.log("Added to library: \(item.title)") Logger.shared.log("Added to library: \(item.title)")

View file

@ -26,6 +26,7 @@ struct MediaView: View {
@State private var selectedEpisodeNumber: Int = 0 @State private var selectedEpisodeNumber: Int = 0
@AppStorage("externalPlayer") private var externalPlayer: String = "Default" @AppStorage("externalPlayer") private var externalPlayer: String = "Default"
@StateObject private var libraryManager = LibraryManager.shared
var body: some View { var body: some View {
Group { Group {
@ -119,8 +120,13 @@ struct MediaView: View {
} }
Button(action: { Button(action: {
if isItemInLibrary() {
removeFromLibrary()
} else {
addToLibrary()
}
}) { }) {
Image(systemName: "bookmark") Image(systemName: isItemInLibrary() ? "bookmark.fill" : "bookmark")
.resizable() .resizable()
.frame(width: 20, height: 27) .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) { func playStream(urlString: String?, fullURL: String) {
guard let streamUrl = urlString else { return } guard let streamUrl = urlString else { return }