From 7dd09dabc84dd70ddf269e8972d5f70296eff5cd Mon Sep 17 00:00:00 2001 From: cranci1 <100066266+cranci1@users.noreply.github.com> Date: Fri, 14 Feb 2025 14:25:29 +0100 Subject: [PATCH] =?UTF-8?q?idk=20doesnt=20build=20for=20me=20=F0=9F=98=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DetailsView/AniList-DetailsView.swift | 52 +++++++++++++------ 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/Sora/Tracking Services/AniList/HomePage/DetailsView/AniList-DetailsView.swift b/Sora/Tracking Services/AniList/HomePage/DetailsView/AniList-DetailsView.swift index 2e40836..87e06e0 100644 --- a/Sora/Tracking Services/AniList/HomePage/DetailsView/AniList-DetailsView.swift +++ b/Sora/Tracking Services/AniList/HomePage/DetailsView/AniList-DetailsView.swift @@ -8,6 +8,18 @@ import SwiftUI import Kingfisher +extension String { + var strippedHTML: String { + guard let data = self.data(using: .utf8) else { return self } + let options: [NSAttributedString.DocumentReadingOptionKey: Any] = [ + .documentType: NSAttributedString.DocumentType.html, + .characterEncoding: String.Encoding.utf8.rawValue + ] + let attributedString = try? NSAttributedString(data: data, options: options, documentAttributes: nil) + return attributedString?.string ?? self + } +} + struct MediaDetailItem: View { var title: String var value: String @@ -102,7 +114,6 @@ struct AniListDetailsView: View { let month = endDate["month"] as? Int, let day = endDate["day"] as? Int { MediaDetailItem(title: "End Date", value: "\(year)-\(month)-\(day)") - Divider() } } } @@ -123,7 +134,7 @@ struct AniListDetailsView: View { } if let synopsis = media["description"] as? String { - Text(synopsis) + Text(synopsis.strippedHTML) .padding(.horizontal) .foregroundColor(.secondary) .font(.system(size: 14)) @@ -174,20 +185,29 @@ struct AniListDetailsView: View { if let stats = media["stats"] as? [String: Any], let scoreDistribution = stats["scoreDistribution"] as? [[String: Any]] { - VStack(alignment: .center) { - Text("Score Distribution") - .font(.headline) - HStack(alignment: .bottom, spacing: 8) { - let maxValue = scoreDistribution.compactMap { $0["amount"] as? Int }.max() ?? 1 - ForEach(Array(scoreDistribution.enumerated()), id: \.offset) { _, dataPoint in - if let score = dataPoint["score"] as? Int, - let amount = dataPoint["amount"] as? Int { - VStack { - Rectangle() - .fill(Color.accentColor) - .frame(width: 20, height: CGFloat(amount) / CGFloat(maxValue) * 100) - Text("\(score)") - .font(.caption) + + let maxValue: Int = scoreDistribution.compactMap { $0["amount"] as? Int }.max() ?? 1 + + HStack(alignment: .center) { + if let averageScore = media["averageScore"] as? Double { + Text("Average Score: \(String(format: "%.1f", averageScore))") + .font(.headline) + .frame(width: 120, alignment: .leading) + } + VStack(alignment: .center) { + Text("Score Distribution") + .font(.headline) + HStack(alignment: .bottom, spacing: 8) { + ForEach(Array(scoreDistribution.enumerated()), id: \.offset) { _, dataPoint in + if let score = dataPoint["score"] as? Int, + let amount = dataPoint["amount"] as? Int { + VStack { + Rectangle() + .fill(Color.accentColor) + .frame(width: 20, height: CGFloat(amount) / CGFloat(maxValue) * 100) + Text("\(score)") + .font(.caption) + } } } }