diff options
| author | Dustin Mierau <dustin@mierau.me> | 2023-12-16 09:16:15 -0800 |
|---|---|---|
| committer | Dustin Mierau <dustin@mierau.me> | 2023-12-16 09:16:15 -0800 |
| commit | 3e4fbdfcab4a4d2435aed27a16131a6ca26d7408 (patch) | |
| tree | a1aec47c2de30074257dec14e3b2615a8b178033 /Hotline/Models/NewsInfo.swift | |
| parent | a428e3e28fb851cec65ff27f212c19bce08e5369 (diff) | |
Implemented basic news reading support. Various UI tweaks.
Diffstat (limited to 'Hotline/Models/NewsInfo.swift')
| -rw-r--r-- | Hotline/Models/NewsInfo.swift | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/Hotline/Models/NewsInfo.swift b/Hotline/Models/NewsInfo.swift new file mode 100644 index 0000000..ad6bfcd --- /dev/null +++ b/Hotline/Models/NewsInfo.swift @@ -0,0 +1,58 @@ +import SwiftUI + +enum NewsInfoType { + case bundle + case category + case article +} + +@Observable class NewsInfo: Identifiable, Hashable { + let id: UUID = UUID() + + let name: String + let count: UInt + let type: NewsInfoType + + let categoryID: UUID? + let articleID: UInt? + + let path: [String] + var children: [NewsInfo] = [] + + var articleFlavors: [String]? + + init(hotlineNewsCategory: HotlineNewsCategory) { + self.categoryID = hotlineNewsCategory.id + self.articleID = nil + self.name = hotlineNewsCategory.name + self.count = UInt(hotlineNewsCategory.count) + self.path = hotlineNewsCategory.path + + if hotlineNewsCategory.type == 2 { + self.type = .bundle + } + else { + self.type = .category + } + } + + init(hotlineNewsArticle: HotlineNewsArticle) { + self.articleID = UInt(hotlineNewsArticle.id) + self.categoryID = nil + self.name = hotlineNewsArticle.title + self.count = 0 +// self.count = UInt(hotlineNewsArticle.count) + self.path = hotlineNewsArticle.path + self.type = .article + + self.articleFlavors = hotlineNewsArticle.flavors.map { $0.0 } + } + + func hash(into hasher: inout Hasher) { + hasher.combine(self.id) + } + + static func == (lhs: NewsInfo, rhs: NewsInfo) -> Bool { + return lhs.id == rhs.id + } +} |