ReaderHive/ReaderHive/Class/Novel/M/NRReadChapterModel.swift

111 lines
3.3 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
@IgnoredKey
var recommandPage: NRReadPageModel?
@IgnoredKey
var finishPage: NRReadPageModel?
static func mappingForKey() -> [SmartKeyTransformer]? {
return [
CodingKeys.nr_description <--- ["description"],
]
}
///
func parser() {
let tempAttributes = NRNovelReadSetManager.manager.textAttributes()
guard !NSDictionary(dictionary: attributes).isEqual(to: tempAttributes) else { return }
attributes = tempAttributes
fullContent = fullContentAttrString()
pageList = NRReadParser.pageing(attrString: fullContent, rect: NRNovelReadSetManager.manager.readRect)
pageCount = pageList?.count ?? 0
if let pageModel = self.recommandPage {
let pagePoint = pageModel.pagePoint ?? 0
let page = Int(CGFloat(pageCount) * pagePoint)
pageList?.insert(pageModel, at: page)
}
if let pageModel = self.finishPage {
pageList?.append(pageModel)
}
}
///
func parserText(attributes: [NSAttributedString.Key : Any] = NRNovelReadSetManager.manager.textAttributes()) {
self.fullContent = NSMutableAttributedString(string: novel_txt ?? "", attributes: attributes)
pageList = NRReadParser.pageing(attrString: fullContent, rect: NRNovelReadSetManager.manager.readRect)
}
///
func parserEmpty(_ text: String) {
fullContent = NSMutableAttributedString(string: "\n\n\n\n\n\n\n" + text, attributes: NRNovelReadSetManager.manager.emptyAttributes())
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.titleAttributes())
let contentString = NSMutableAttributedString(string: novel_txt ?? "", attributes: NRNovelReadSetManager.manager.textAttributes())
titleString.append(contentString)
return titleString
}
}