|
@@ -16,6 +16,7 @@ import com.kdanmobile.kmpdfkit.pdfcommon.KMPDFReaderView
|
|
|
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.reader.screen.handler.*
|
|
|
|
|
|
class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMsg: String) : ViewModel() {
|
|
@@ -35,15 +36,10 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
|
|
|
}
|
|
|
|
|
|
companion object {
|
|
|
- val DEFAULT_HIGHLIGHT_COLOR = Color.parseColor("#ffdc1b")
|
|
|
- val DEFAULT_STRIKE_COLOR = Color.parseColor("#dd0202")
|
|
|
- val DEFAULT_UNDERLINE_COLOR = Color.parseColor("#dd0202")
|
|
|
- val DEFAULT_INK_COLOR = Color.parseColor("#dd0202")
|
|
|
- const val DEFAULT_HIGHLIGHT_ALPHA = 127
|
|
|
- const val DEFAULT_STRIKE_ALPHA = 255
|
|
|
- const val DEFAULT_UNDERLINE_ALPHA = 255
|
|
|
- const val DEFAULT_INK_ALPHA = 255
|
|
|
- const val DEFAULT_INK_WIDTH = 1f
|
|
|
+ val DEFAULT_HIGHLIGHT_ATTR = AnnotationAttribute(Color.parseColor("#ffdc1b"), 127)
|
|
|
+ val DEFAULT_STRIKE_ATTR = AnnotationAttribute(Color.parseColor("#dd0202"), 255)
|
|
|
+ val DEFAULT_UNDERLINE_ATTR = AnnotationAttribute(Color.parseColor("#dd0202"), 255)
|
|
|
+ val DEFAULT_INK_ATTR = InkAttribute(Color.parseColor("#dd0202"), 255, 1f, Brush.Fountain)
|
|
|
}
|
|
|
|
|
|
var viewDirection = ViewDirection.VerticalSinglePageContinues
|
|
@@ -56,18 +52,10 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
|
|
|
field = value
|
|
|
updateCrop()
|
|
|
}
|
|
|
- val highLightAttributeLiveData = MutableLiveData<AnnotationAttribute>().apply {
|
|
|
- value = AnnotationAttribute(DEFAULT_HIGHLIGHT_COLOR, DEFAULT_HIGHLIGHT_ALPHA)
|
|
|
- }
|
|
|
- val strikeAttributeLiveData = MutableLiveData<AnnotationAttribute>().apply {
|
|
|
- value = AnnotationAttribute(DEFAULT_STRIKE_COLOR, DEFAULT_STRIKE_ALPHA)
|
|
|
- }
|
|
|
- var underLineAttributeLiveData = MutableLiveData<AnnotationAttribute>().apply {
|
|
|
- value = AnnotationAttribute(DEFAULT_UNDERLINE_COLOR, DEFAULT_UNDERLINE_ALPHA)
|
|
|
- }
|
|
|
- var inkAttributeLiveData = MutableLiveData<InkAttribute>().apply {
|
|
|
- value = InkAttribute(DEFAULT_INK_COLOR, DEFAULT_INK_ALPHA, DEFAULT_INK_WIDTH)
|
|
|
- }
|
|
|
+ val highLightAttributeLiveData = MutableLiveData<AnnotationAttribute>().apply { value = DEFAULT_HIGHLIGHT_ATTR }
|
|
|
+ val strikeAttributeLiveData = MutableLiveData<AnnotationAttribute>().apply { value = DEFAULT_STRIKE_ATTR }
|
|
|
+ var underLineAttributeLiveData = MutableLiveData<AnnotationAttribute>().apply { value = DEFAULT_UNDERLINE_ATTR }
|
|
|
+ var inkAttributeLiveData = MutableLiveData<InkAttribute>().apply { value = DEFAULT_INK_ATTR }
|
|
|
|
|
|
private var isVerified = false
|
|
|
|
|
@@ -197,12 +185,12 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
|
|
|
isCopyModeLiveData.postValue(false)
|
|
|
}
|
|
|
|
|
|
- fun setHighLightAttributes(color: Int, alpha: Int) {
|
|
|
- highLightAttributeLiveData.postValue(AnnotationAttribute(color, alpha))
|
|
|
- kmpdfFactory?.setAnnotationAttribute(KMPDFHighlightAnnotationBean("", color, alpha))
|
|
|
+ fun setHighLightAttributes(annotationAttribute: AnnotationAttribute) {
|
|
|
+ highLightAttributeLiveData.postValue(annotationAttribute)
|
|
|
+ kmpdfFactory?.setAnnotationAttribute(KMPDFHighlightAnnotationBean("", annotationAttribute.color, annotationAttribute.alpha))
|
|
|
kmpdfFactory?.annotConfig?.apply {
|
|
|
- markerPenColor_hightlight = color
|
|
|
- markerPenAlpha_hightlight = alpha
|
|
|
+ markerPenColor_hightlight = annotationAttribute.color
|
|
|
+ markerPenAlpha_hightlight = annotationAttribute.alpha
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -211,12 +199,12 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
|
|
|
annotationModeLiveData.postValue(AnnotationMode.Highlight)
|
|
|
}
|
|
|
|
|
|
- fun setStrikeOutAttributes(color: Int, alpha: Int) {
|
|
|
- strikeAttributeLiveData.postValue(AnnotationAttribute(color, alpha))
|
|
|
- kmpdfFactory?.setAnnotationAttribute(KMPDFStrikeoutAnnotationBean("", color, alpha))
|
|
|
+ fun setStrikeOutAttributes(annotationAttribute: AnnotationAttribute) {
|
|
|
+ strikeAttributeLiveData.postValue(annotationAttribute)
|
|
|
+ kmpdfFactory?.setAnnotationAttribute(KMPDFStrikeoutAnnotationBean("",annotationAttribute.color, annotationAttribute.alpha))
|
|
|
kmpdfFactory?.annotConfig?.apply {
|
|
|
- markerPenColor_strikeout = color
|
|
|
- markerPenAlpha_strikeout = alpha
|
|
|
+ markerPenColor_strikeout = annotationAttribute.color
|
|
|
+ markerPenAlpha_strikeout = annotationAttribute.alpha
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -225,12 +213,12 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
|
|
|
annotationModeLiveData.postValue(AnnotationMode.Strike)
|
|
|
}
|
|
|
|
|
|
- fun setUnderLineAttributes(color: Int, alpha: Int) {
|
|
|
- underLineAttributeLiveData.postValue(AnnotationAttribute(color, alpha))
|
|
|
- kmpdfFactory?.setAnnotationAttribute(KMPDFUnderlineAnnotationBean("", color, alpha))
|
|
|
+ fun setUnderLineAttributes(annotationAttribute: AnnotationAttribute) {
|
|
|
+ underLineAttributeLiveData.postValue(annotationAttribute)
|
|
|
+ kmpdfFactory?.setAnnotationAttribute(KMPDFUnderlineAnnotationBean("", annotationAttribute.color, annotationAttribute.alpha))
|
|
|
kmpdfFactory?.annotConfig?.apply {
|
|
|
- markerPenColor_underline = color
|
|
|
- markerPenAlpha_underline = alpha
|
|
|
+ markerPenColor_underline = annotationAttribute.color
|
|
|
+ markerPenAlpha_underline = annotationAttribute.alpha
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -239,14 +227,14 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
|
|
|
annotationModeLiveData.postValue(AnnotationMode.Underline)
|
|
|
}
|
|
|
|
|
|
- fun setInkAttributes(color: Int, alpha: Int, width: Float) {
|
|
|
- inkAttributeLiveData.postValue(InkAttribute(color, alpha, width))
|
|
|
+ fun setInkAttributes(inkAttribute: InkAttribute) {
|
|
|
+ inkAttributeLiveData.postValue(inkAttribute)
|
|
|
kmpdfFactory?.apply {
|
|
|
- setAnnotationAttribute(KMPDFInkAnnotationBean("", color, width, alpha))
|
|
|
+ setAnnotationAttribute(KMPDFInkAnnotationBean("", inkAttribute.color, inkAttribute.width, inkAttribute.alpha))
|
|
|
annotConfig?.apply {
|
|
|
- markerPenColor_ink = color
|
|
|
- markerPenAlpha_ink = alpha
|
|
|
- markerPenSize_ink = width
|
|
|
+ markerPenColor_ink = inkAttribute.color
|
|
|
+ markerPenAlpha_ink = inkAttribute.alpha
|
|
|
+ markerPenSize_ink = inkAttribute.width
|
|
|
}
|
|
|
}
|
|
|
}
|