From 0ad4659d2cf9d8ab9c0728fabfcd29b77222e9cd Mon Sep 17 00:00:00 2001 From: Seiike <122684677+Seeike@users.noreply.github.com> Date: Sun, 20 Apr 2025 19:50:15 +0200 Subject: [PATCH] =?UTF-8?q?hello=20=F0=9F=91=8B=20=20(#95)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * bug fix dimming * improved the fetchEpisodeMetadata logic --- .../CustomPlayer/CustomPlayer.swift | 52 +++++++------------ .../EpisodeCell/EpisodeCell.swift | 34 +++++------- 2 files changed, 31 insertions(+), 55 deletions(-) diff --git a/Sora/Utils/MediaPlayer/CustomPlayer/CustomPlayer.swift b/Sora/Utils/MediaPlayer/CustomPlayer/CustomPlayer.swift index 4bcd995..d2671ad 100644 --- a/Sora/Utils/MediaPlayer/CustomPlayer/CustomPlayer.swift +++ b/Sora/Utils/MediaPlayer/CustomPlayer/CustomPlayer.swift @@ -1267,19 +1267,16 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele isPlaying = false playPauseButton.image = UIImage(systemName: "play.fill") - // Defer the UI animation so that it doesn't block the pause call DispatchQueue.main.async { if !self.isControlsVisible { self.isControlsVisible = true UIView.animate(withDuration: 0.1, animations: { self.controlsContainerView.alpha = 1.0 self.skip85Button.alpha = 0.8 - // Removed layoutIfNeeded() to avoid forcing a layout pass here }) } } } else { - // Play immediately player.play() isPlaying = true playPauseButton.image = UIImage(systemName: "pause.fill") @@ -1312,39 +1309,26 @@ class CustomMediaPlayerViewController: UIViewController, UIGestureRecognizerDele @objc private func dimTapped() { isDimmed.toggle() + dimButtonTimer?.invalidate() - if isDimmed { - originalHiddenStates = [:] - for view in controlsToHide { - originalHiddenStates[view] = view.isHidden - view.isHidden = true - } - - blackCoverView.alpha = 1.0 - - dimButtonToSlider.isActive = false - dimButtonToRight.isActive = true - - dimButton.isHidden = true - - dimButtonTimer?.invalidate() - } else { - for view in controlsToHide { - if let wasHidden = originalHiddenStates[view] { - view.isHidden = wasHidden - } - } - - blackCoverView.alpha = 0.4 - - dimButtonToRight.isActive = false - dimButtonToSlider.isActive = true - - dimButton.isHidden = false - dimButton.alpha = 1.0 - - dimButtonTimer?.invalidate() + // animate black overlay + UIView.animate(withDuration: 0.25) { + self.blackCoverView.alpha = self.isDimmed ? 1.0 : 0.4 } + + // fade controls instead of hiding + UIView.animate(withDuration: 0.25) { + for view in self.controlsToHide { + view.alpha = self.isDimmed ? 0 : 1 + } + // keep the dim button visible/in front + self.dimButton.alpha = self.isDimmed ? 0 : 1 + } + + // swap your trailing constraints on the dim‑button + dimButtonToSlider.isActive = !isDimmed + dimButtonToRight.isActive = isDimmed + UIView.animate(withDuration: 0.25) { self.view.layoutIfNeeded() } } func speedChangerMenu() -> UIMenu { diff --git a/Sora/Views/MediaInfoView/EpisodeCell/EpisodeCell.swift b/Sora/Views/MediaInfoView/EpisodeCell/EpisodeCell.swift index 1ddb47b..7c3638b 100644 --- a/Sora/Views/MediaInfoView/EpisodeCell/EpisodeCell.swift +++ b/Sora/Views/MediaInfoView/EpisodeCell/EpisodeCell.swift @@ -29,7 +29,7 @@ struct EpisodeCell: View { @State private var isLoading: Bool = true @State private var currentProgress: Double = 0.0 - init(episodeIndex: Int, episode: String, episodeID: Int, progress: Double, + init(episodeIndex: Int, episode: String, episodeID: Int, progress: Double, itemID: Int, onTap: @escaping (String) -> Void, onMarkAllPrevious: @escaping () -> Void) { self.episodeIndex = episodeIndex self.episode = episode @@ -92,13 +92,9 @@ struct EpisodeCell: View { } .onAppear { updateProgress() - - if UserDefaults.standard.object(forKey: "fetchEpisodeMetadata") == nil - || UserDefaults.standard.bool(forKey: "fetchEpisodeMetadata") { - fetchEpisodeDetails() - } + fetchEpisodeDetails() } - .onChange(of: progress) { newProgress in + .onChange(of: progress) { _ in updateProgress() } .onTapGesture { @@ -147,16 +143,12 @@ struct EpisodeCell: View { URLSession.custom.dataTask(with: url) { data, _, error in if let error = error { Logger.shared.log("Failed to fetch anime episode details: \(error)", type: "Error") - DispatchQueue.main.async { - self.isLoading = false - } + DispatchQueue.main.async { self.isLoading = false } return } guard let data = data else { - DispatchQueue.main.async { - self.isLoading = false - } + DispatchQueue.main.async { self.isLoading = false } return } @@ -168,21 +160,21 @@ struct EpisodeCell: View { let title = episodeDetails["title"] as? [String: String], let image = episodeDetails["image"] as? String else { Logger.shared.log("Invalid anime response format", type: "Error") - DispatchQueue.main.async { - self.isLoading = false - } + DispatchQueue.main.async { self.isLoading = false } return } DispatchQueue.main.async { - self.episodeTitle = title["en"] ?? "" - self.episodeImageUrl = image + // Always stop loading self.isLoading = false + // Only display metadata if enabled + if UserDefaults.standard.bool(forKey: "fetchEpisodeMetadata") { + self.episodeTitle = title["en"] ?? "" + self.episodeImageUrl = image + } } } catch { - DispatchQueue.main.async { - self.isLoading = false - } + DispatchQueue.main.async { self.isLoading = false } } }.resume() }