99 lines
2.8 KiB
Swift
99 lines
2.8 KiB
Swift
//
|
||
// 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
|
||
}
|
||
|
||
}
|