浏览代码

Merge branch 'fix-annotation-color'

Wayne 5 年之前
父节点
当前提交
11cf98a45d
共有 1 个文件被更改,包括 33 次插入6 次删除
  1. 33 6
      reader/src/main/java/com/kdanmobile/reader/ReaderViewModel.kt

+ 33 - 6
reader/src/main/java/com/kdanmobile/reader/ReaderViewModel.kt

@@ -4,8 +4,8 @@ import android.arch.lifecycle.LiveData
 import android.arch.lifecycle.MutableLiveData
 import android.arch.lifecycle.ViewModel
 import android.content.Context
-import android.graphics.Color
 import android.graphics.Bitmap
+import android.graphics.Color
 import android.graphics.RectF
 import android.net.Uri
 import com.kdanmobile.kmpdfkit.annotation.Annotation
@@ -17,14 +17,18 @@ import com.kdanmobile.kmpdfkit.globaldata.Config
 import com.kdanmobile.kmpdfkit.globaldata.KMPDFAnnotEditMode
 import com.kdanmobile.kmpdfkit.manager.KMPDFFactory
 import com.kdanmobile.kmpdfkit.manager.controller.KMPDFDocumentController
+import com.kdanmobile.kmpdfkit.manager.controller.KMPDFFreeTextController
+import com.kdanmobile.kmpdfkit.manager.controller.KMPDFLongPressCreateAnnotController
+import com.kdanmobile.kmpdfkit.manager.controller.KMPDFSignatureController
+import com.kdanmobile.kmpdfkit.manager.listener.KMPDFAddAnnotCallback
+import com.kdanmobile.kmpdfkit.manager.listener.KMPDFAnnotEditModeChangeListener
+import com.kdanmobile.kmpdfkit.pdfcommon.Bookmark
 import com.kdanmobile.kmpdfkit.pdfcommon.KMPDFReaderView
+import com.kdanmobile.kmpdfkit.pdfcommon.OutlineItem
+import com.kdanmobile.kmpdfkit.pdfcommon.TextWord
 import com.kdanmobile.reader.annotationattribute.AnnotationAttribute
-import com.kdanmobile.reader.annotationattribute.InkAttribute
-import com.kdanmobile.kmpdfkit.pdfcommon.*
 import com.kdanmobile.reader.annotationattribute.Brush
-import com.kdanmobile.kmpdfkit.manager.controller.*
-import com.kdanmobile.kmpdfkit.manager.listener.KMPDFAddAnnotCallback
-import com.kdanmobile.kmpdfkit.manager.listener.KMPDFAnnotEditModeChangeListener
+import com.kdanmobile.reader.annotationattribute.InkAttribute
 import com.kdanmobile.reader.screen.contextmenu.TextBoxContextMenuActionListener
 import com.kdanmobile.reader.screen.data.ShapeAttribute
 import com.kdanmobile.reader.screen.data.SignatureAttribute
@@ -222,6 +226,10 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
 
     fun setHighLightAttributes(annotationAttribute: AnnotationAttribute) {
         highLightAttributeLiveData.postValue(annotationAttribute)
+        setHighLightAttributesImp(annotationAttribute)
+    }
+
+    private fun setHighLightAttributesImp(annotationAttribute: AnnotationAttribute) {
         kmpdfFactory?.setAnnotationAttribute(KMPDFHighlightAnnotationBean("", annotationAttribute.color, annotationAttribute.alpha))
         kmpdfFactory?.annotConfig?.apply {
             markerPenColor_hightlight = annotationAttribute.color
@@ -236,6 +244,10 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
 
     fun setStrikeOutAttributes(annotationAttribute: AnnotationAttribute) {
         strikeAttributeLiveData.postValue(annotationAttribute)
+        setStrikeOutAttributesImp(annotationAttribute)
+    }
+
+    private fun setStrikeOutAttributesImp(annotationAttribute: AnnotationAttribute) {
         kmpdfFactory?.setAnnotationAttribute(KMPDFStrikeoutAnnotationBean("",annotationAttribute.color, annotationAttribute.alpha))
         kmpdfFactory?.annotConfig?.apply {
             markerPenColor_strikeout = annotationAttribute.color
@@ -250,6 +262,10 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
 
     fun setUnderLineAttributes(annotationAttribute: AnnotationAttribute) {
         underLineAttributeLiveData.postValue(annotationAttribute)
+        setUnderLineAttributesImp(annotationAttribute)
+    }
+
+    private fun setUnderLineAttributesImp(annotationAttribute: AnnotationAttribute) {
         kmpdfFactory?.setAnnotationAttribute(KMPDFUnderlineAnnotationBean("", annotationAttribute.color, annotationAttribute.alpha))
         kmpdfFactory?.annotConfig?.apply {
             markerPenColor_underline = annotationAttribute.color
@@ -264,6 +280,10 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
 
     fun setInkAttributes(inkAttribute: InkAttribute) {
         inkAttributeLiveData.postValue(inkAttribute)
+        setInkAttributesImp(inkAttribute)
+    }
+
+    fun setInkAttributesImp(inkAttribute: InkAttribute) {
         kmpdfFactory?.apply {
             setAnnotationAttribute(KMPDFInkAnnotationBean("", inkAttribute.color, inkAttribute.width, inkAttribute.alpha))
             annotConfig?.apply {
@@ -288,6 +308,13 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
         val isFirst = kmpdfFactory?.readerView == null
         kmpdfFactory?.readerView = readerView
         kmpdfDocumentController = kmpdfFactory?.getController(KMPDFFactory.ControllerType.DOCUMENT) as KMPDFDocumentController
+
+        /** init annotation color **/
+        highLightAttributeLiveData.value?.also { setHighLightAttributesImp(it) }
+        strikeAttributeLiveData.value?.also { setStrikeOutAttributesImp(it) }
+        underLineAttributeLiveData.value?.also { setUnderLineAttributesImp(it) }
+        inkAttributeLiveData.value?.also { setInkAttributesImp(it) }
+
         updateViewDirection()
 
         kmpdfFactory?.kmpdfAddAnnotCallback = object : KMPDFAddAnnotCallback {