From 785297cd2ae630c2bf41ca4b5ee180ef0ab50781 Mon Sep 17 00:00:00 2001 From: Seiike <122684677+Seeike@users.noreply.github.com> Date: Mon, 9 Jun 2025 07:55:44 +0200 Subject: [PATCH] =?UTF-8?q?POP=20THE=20CHAMPAGNE=20=F0=9F=8D=BE=20(#161)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sora/Views/LibraryView/LibraryView.swift | 22 +++++++++----- Sora/Views/MediaInfoView/MediaInfoView.swift | 30 ++++++++++++++++++- .../SettingsSubViews/SettingsViewModule.swift | 2 +- 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/Sora/Views/LibraryView/LibraryView.swift b/Sora/Views/LibraryView/LibraryView.swift index 3858110..030f142 100644 --- a/Sora/Views/LibraryView/LibraryView.swift +++ b/Sora/Views/LibraryView/LibraryView.swift @@ -12,6 +12,7 @@ import SwiftUI struct LibraryView: View { @EnvironmentObject private var libraryManager: LibraryManager @EnvironmentObject private var moduleManager: ModuleManager + @Environment(\.scenePhase) private var scenePhase @AppStorage("mediaColumnsPortrait") private var mediaColumnsPortrait: Int = 2 @AppStorage("mediaColumnsLandscape") private var mediaColumnsLandscape: Int = 4 @@ -165,6 +166,11 @@ struct LibraryView: View { .onAppear { fetchContinueWatching() } + .onChange(of: scenePhase) { newPhase in + if newPhase == .active { + fetchContinueWatching() + } + } } } .navigationViewStyle(StackNavigationViewStyle()) @@ -237,8 +243,8 @@ struct ContinueWatchingCell: View { var markAsWatched: () -> Void var removeItem: () -> Void - @State private - var currentProgress: Double = 0.0 + @State private var currentProgress: Double = 0.0 + @Environment(\.scenePhase) private var scenePhase var body: some View { Button(action: { @@ -292,7 +298,7 @@ struct ContinueWatchingCell: View { RoundedRectangle(cornerRadius: 10) .fill(Color.gray.opacity(0.3)) .frame(width: 280, height: 157.03) - .shimmering() + .redacted(reason: .placeholder) } } .overlay( @@ -388,11 +394,11 @@ struct ContinueWatchingCell: View { .onAppear { updateProgress() } - .onReceive(NotificationCenter.default.publisher( - for: UIApplication.didBecomeActiveNotification)) { - _ in + .onChange(of: scenePhase) { newPhase in + if newPhase == .active { updateProgress() } + } } private func updateProgress() { @@ -547,8 +553,8 @@ struct BookmarkItemView: View { } else { RoundedRectangle(cornerRadius: 12) .fill(Color.gray.opacity(0.3)) - .aspectRatio(2 / 3, contentMode: .fit) - .shimmering() + .aspectRatio(2/3, contentMode: .fit) + .redacted(reason: .placeholder) } } .overlay( diff --git a/Sora/Views/MediaInfoView/MediaInfoView.swift b/Sora/Views/MediaInfoView/MediaInfoView.swift index 39ec350..1393194 100644 --- a/Sora/Views/MediaInfoView/MediaInfoView.swift +++ b/Sora/Views/MediaInfoView/MediaInfoView.swift @@ -60,7 +60,7 @@ struct MediaInfoView: View { @State private var isMatchingPresented = false @State private var matchedTitle: String? = nil - @StateObject private var jsController = JSController.shared + @ObservedObject private var jsController = JSController.shared @EnvironmentObject var moduleManager: ModuleManager @EnvironmentObject private var libraryManager: LibraryManager @EnvironmentObject var tabBarController: TabBarController @@ -166,6 +166,34 @@ struct MediaInfoView: View { .onDisappear(){ tabBarController.showTabBar() } + .task { + guard !hasFetched else { return } + + let savedCustomID = UserDefaults.standard.integer(forKey: "custom_anilist_id_\(href)") + if savedCustomID != 0 { customAniListID = savedCustomID } + if let savedPoster = UserDefaults.standard.string(forKey: "tmdbPosterURL_\(href)") { + imageUrl = savedPoster + } + DropManager.shared.showDrop( + title: "Fetching Data", + subtitle: "Please wait while fetching.", + duration: 0.5, + icon: UIImage(systemName: "arrow.triangle.2.circlepath") + ) + fetchDetails() + + if savedCustomID != 0 { + itemID = savedCustomID + } else { + fetchMetadataIDIfNeeded() + } + + hasFetched = true + AnalyticsManager.shared.sendEvent( + event: "MediaInfoView", + additionalData: ["title": title] + ) + } .alert("Loading Stream", isPresented: $showLoadingAlert) { Button("Cancel", role: .cancel) { activeFetchID = nil diff --git a/Sora/Views/SettingsView/SettingsSubViews/SettingsViewModule.swift b/Sora/Views/SettingsView/SettingsSubViews/SettingsViewModule.swift index 82787fb..58ffe02 100644 --- a/Sora/Views/SettingsView/SettingsSubViews/SettingsViewModule.swift +++ b/Sora/Views/SettingsView/SettingsSubViews/SettingsViewModule.swift @@ -219,7 +219,7 @@ struct SettingsViewModule: View { .navigationTitle("Modules") .navigationBarItems(trailing: HStack(spacing: 16) { - if didReceiveDefaultPageLink && !moduleManager.modules.isEmpty { + if didReceiveDefaultPageLink { Button(action: { showLibrary = true }) {