KMConvertSettingView.swift 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. //
  2. // KMConvertSettingView.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2023/5/9.
  6. //
  7. import KMComponentLibrary
  8. let kKMConvertLanugageSelectedIndex: String = "KMConvertLanugageSelectedIndex"
  9. typealias KMConvertSettingViewPageRangeDidChangeCallback = (_ pageRange: KMPageRange) -> Void
  10. typealias KMConvertSettingViewPageRangeDidInputFinishCallback = (_ pageRangeString: String) -> ()
  11. // 转档 设置视图 基类
  12. class KMConvertSettingView: KMConvertBaseView {
  13. private var _currentLanguage: String?
  14. var currentLanguage: String? {
  15. get {
  16. return self._currentLanguage
  17. }
  18. set {
  19. self._currentLanguage = newValue
  20. if let indexString = UserDefaults.standard.string(forKey: kKMConvertLanugageSelectedIndex), let index = Int(indexString) {
  21. self.ocrLanuguageIndex = index
  22. return
  23. }
  24. }
  25. }
  26. var ocrLanuguageIndex: Int = 3 {
  27. didSet {
  28. self.ocrItemView?.languageIndex = self.ocrLanuguageIndex
  29. }
  30. }
  31. var pageRangeSelectedIndex: Int = 0
  32. var pageRangeDidChange: KMConvertSettingViewPageRangeDidChangeCallback?
  33. var pageRangeDidInputFinishCallback: KMConvertSettingViewPageRangeDidInputFinishCallback?
  34. var lanugageDidSelected: KMValueDidChangeBlock?
  35. private var _ocrItemView: KMConvertOCRSettingItemView?
  36. var ocrItemView: KMConvertOCRSettingItemView? {
  37. get {
  38. return self._ocrItemView
  39. }
  40. set {
  41. if (self._ocrItemView != newValue) {
  42. self._ocrItemView = newValue
  43. newValue?.lanugageDidSelected = { [weak self] value, change in
  44. guard let callback = self?.lanugageDidSelected else {
  45. return
  46. }
  47. callback(value, change)
  48. }
  49. }
  50. }
  51. }
  52. private var _pageRangeItemView: KMConvertPageRangeSettingItemView?
  53. var pageRangeItemView: KMConvertPageRangeSettingItemView? {
  54. get {
  55. return self._pageRangeItemView
  56. }
  57. set {
  58. if (self._pageRangeItemView != newValue) {
  59. self._pageRangeItemView = newValue
  60. newValue?.isTextDidEndCallback = true
  61. newValue?.itemClick = { [weak self] index, _ in
  62. self?.pageRangeSelectedIndex = index
  63. guard let callback = self?.pageRangeDidChange else {
  64. return
  65. }
  66. var value: KMPageRange = .all
  67. if index == 1 {
  68. value = .current
  69. } else if index == 2 {
  70. value = .odd
  71. } else if index == 3 {
  72. value = .even
  73. } else if index == 4 {
  74. value = .custom
  75. }
  76. callback(value)
  77. }
  78. newValue?.textDidEndEditingCallback = { [unowned self] textString in
  79. let pageRange = KMPageRange(rawValue: self.pageRangeSelectedIndex)
  80. if (pageRange != .custom) {
  81. return
  82. }
  83. guard let callback = self.pageRangeDidInputFinishCallback else {
  84. return
  85. }
  86. callback(textString)
  87. }
  88. }
  89. }
  90. }
  91. var tipView: KMConvertSettingLimitTipView?
  92. override func initSubViews() {
  93. super.initSubViews()
  94. }
  95. override func layout() {
  96. super.layout()
  97. }
  98. var pageCount = 0 {
  99. didSet {
  100. self.pageRangeItemView?.pageCount = self.pageCount
  101. }
  102. }
  103. var ocrEnabled: Bool {
  104. get {
  105. guard let state = self.ocrItemView?.checkView.properties.checkboxType else {
  106. return false
  107. }
  108. return state == .selected
  109. }
  110. }
  111. func getPageRangeString() -> String {
  112. if let view = self.pageRangeItemView {
  113. return view.pageRangeValue
  114. }
  115. return ""
  116. }
  117. override func updateViewColor() {
  118. super.updateViewColor()
  119. KMMainThreadExecute {
  120. self.ocrItemView?.titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
  121. self.pageRangeItemView?.titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
  122. }
  123. }
  124. }