// // KMConvertSettingView.swift // PDF Reader Pro // // Created by tangchao on 2023/5/9. // import KMComponentLibrary let kKMConvertLanugageSelectedIndex: String = "KMConvertLanugageSelectedIndex" typealias KMConvertSettingViewPageRangeDidChangeCallback = (_ pageRange: KMPageRange) -> Void typealias KMConvertSettingViewPageRangeDidInputFinishCallback = (_ pageRangeString: String) -> () // 转档 设置视图 基类 class KMConvertSettingView: KMConvertBaseView { private var _currentLanguage: String? var currentLanguage: String? { get { return self._currentLanguage } set { self._currentLanguage = newValue if let indexString = UserDefaults.standard.string(forKey: kKMConvertLanugageSelectedIndex), let index = Int(indexString) { self.ocrLanuguageIndex = index return } } } var ocrLanuguageIndex: Int = 3 { didSet { self.ocrItemView?.languageIndex = self.ocrLanuguageIndex } } var pageRangeSelectedIndex: Int = 0 var pageRangeDidChange: KMConvertSettingViewPageRangeDidChangeCallback? var pageRangeDidInputFinishCallback: KMConvertSettingViewPageRangeDidInputFinishCallback? var lanugageDidSelected: KMValueDidChangeBlock? private var _ocrItemView: KMConvertOCRSettingItemView? var ocrItemView: KMConvertOCRSettingItemView? { get { return self._ocrItemView } set { if (self._ocrItemView != newValue) { self._ocrItemView = newValue newValue?.lanugageDidSelected = { [weak self] value, change in guard let callback = self?.lanugageDidSelected else { return } callback(value, change) } } } } private var _pageRangeItemView: KMConvertPageRangeSettingItemView? var pageRangeItemView: KMConvertPageRangeSettingItemView? { get { return self._pageRangeItemView } set { if (self._pageRangeItemView != newValue) { self._pageRangeItemView = newValue newValue?.isTextDidEndCallback = true newValue?.itemClick = { [weak self] index, _ in self?.pageRangeSelectedIndex = index guard let callback = self?.pageRangeDidChange else { return } var value: KMPageRange = .all if index == 1 { value = .current } else if index == 2 { value = .odd } else if index == 3 { value = .even } else if index == 4 { value = .custom } callback(value) } newValue?.textDidEndEditingCallback = { [unowned self] textString in let pageRange = KMPageRange(rawValue: self.pageRangeSelectedIndex) if (pageRange != .custom) { return } guard let callback = self.pageRangeDidInputFinishCallback else { return } callback(textString) } } } } var tipView: KMConvertSettingLimitTipView? override func initSubViews() { super.initSubViews() } override func layout() { super.layout() } var pageCount = 0 { didSet { self.pageRangeItemView?.pageCount = self.pageCount } } var ocrEnabled: Bool { get { guard let state = self.ocrItemView?.checkView.properties.checkboxType else { return false } return state == .selected } } func getPageRangeString() -> String { if let view = self.pageRangeItemView { return view.pageRangeValue } return "" } override func updateViewColor() { super.updateViewColor() KMMainThreadExecute { self.ocrItemView?.titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2") self.pageRangeItemView?.titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2") } } }