ReaderHive/ReaderHive/Class/Novel/M/NRReadChapterModel.swift
2025-12-09 13:31:07 +08:00

99 lines
2.8 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// NRReadChapterModel.swift
// ReaderHive
//
// Created by 鸿 on 2025/11/28.
//
import UIKit
import SmartCodable
class NRReadChapterModel: NSObject, SmartCodable {
required override init() { }
var id: String?
///id
var short_play_video_id: String?
///id
var short_play_id: String?
var episode: String?
var name: String?
//
var duration: Int?
var coins: Int?
var status: Int?
var nr_description: String?
///
var novel_txt: String?
///
@IgnoredKey
var fullContent:NSAttributedString!
/// ()
@IgnoredKey
private var attributes:[NSAttributedString.Key:Any]! = [:]
@IgnoredKey
var pageList: [NRReadPageModel]?
@IgnoredKey
var pageCount: Int = 0
static func mappingForKey() -> [SmartKeyTransformer]? {
return [
CodingKeys.nr_description <--- ["description"],
]
}
///
func parser() {
let tempAttributes = NRNovelReadSetManager.manager.attributes(isTitle: false, isPageing: true)
guard !NSDictionary(dictionary: attributes).isEqual(to: tempAttributes) else { return }
attributes = tempAttributes
fullContent = fullContentAttrString()
var tempPageModel: NRReadPageModel?
if pageList?.last?.pageType != .textPart {
tempPageModel = pageList?.last
}
pageList = NRReadParser.pageing(attrString: fullContent, rect: NRNovelReadSetManager.manager.readRect)
pageCount = pageList?.count ?? 0
if let model = tempPageModel {
pageList?.append(model)
}
}
///
func parserEmpty(_ text: String) {
fullContent = NSMutableAttributedString(string: "\n\n\n\n\n" + text, attributes: NRNovelReadSetManager.manager.attributes(isTitle: true))
let pageModel = NRReadPageModel()
pageModel.content = fullContent
pageList = [pageModel]
pageCount = 1
}
///
private func fullContentAttrString() ->NSMutableAttributedString {
let name = "\n\(self.name ?? "")\n\n"
let titleString = NSMutableAttributedString(string: name, attributes: NRNovelReadSetManager.manager.attributes(isTitle: true))
let contentString = NSMutableAttributedString(string: novel_txt ?? "", attributes: NRNovelReadSetManager.manager.attributes(isTitle: false))
titleString.append(contentString)
return titleString
}
}