mirror of
https://github.com/yattee/yattee.git
synced 2025-08-09 20:24:06 +00:00
Channels layout improvements, other UI fixes
This commit is contained in:
@@ -3,20 +3,41 @@ import Defaults
|
||||
import Foundation
|
||||
import SwiftyJSON
|
||||
|
||||
struct Channel: Codable, Identifiable, Defaults.Serializable {
|
||||
struct Channel: Identifiable, Hashable {
|
||||
var id: String
|
||||
var name: String
|
||||
var subscriptionsCount: String
|
||||
var videos = [Video]()
|
||||
|
||||
private var subscriptionsCount: Int?
|
||||
private var subscriptionsText: String?
|
||||
|
||||
init(json: JSON) {
|
||||
id = json["authorId"].stringValue
|
||||
name = json["author"].stringValue
|
||||
subscriptionsCount = json["subCountText"].stringValue
|
||||
subscriptionsCount = json["subCount"].int
|
||||
subscriptionsText = json["subCountText"].string
|
||||
|
||||
if let channelVideos = json.dictionaryValue["latestVideos"] {
|
||||
videos = channelVideos.arrayValue.map(Video.init)
|
||||
}
|
||||
}
|
||||
|
||||
init(id: String, name: String, subscriptionsCount: String) {
|
||||
init(id: String, name: String, subscriptionsCount: Int? = nil, videos: [Video] = []) {
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.subscriptionsCount = subscriptionsCount
|
||||
self.videos = videos
|
||||
}
|
||||
|
||||
var subscriptionsString: String? {
|
||||
if subscriptionsCount != nil {
|
||||
return subscriptionsCount!.formattedAsAbbreviation()
|
||||
}
|
||||
|
||||
return subscriptionsText
|
||||
}
|
||||
|
||||
func hash(into hasher: inout Hasher) {
|
||||
hasher.combine(id)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user