|
@@ -17,6 +17,14 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
|
|
HorizontalSinglePage(Config.PDFViewMode.HORIZONTAL_SINGLE_PAGE)
|
|
HorizontalSinglePage(Config.PDFViewMode.HORIZONTAL_SINGLE_PAGE)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ enum class AnnotationMode {
|
|
|
|
+ None,
|
|
|
|
+ Highlight,
|
|
|
|
+ Strike,
|
|
|
|
+ Underline,
|
|
|
|
+ Ink,
|
|
|
|
+ }
|
|
|
|
+
|
|
var viewDirection = ViewDirection.VerticalSinglePageContinues
|
|
var viewDirection = ViewDirection.VerticalSinglePageContinues
|
|
set(value) {
|
|
set(value) {
|
|
field = value
|
|
field = value
|
|
@@ -27,8 +35,6 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
|
|
field = value
|
|
field = value
|
|
updateCrop()
|
|
updateCrop()
|
|
}
|
|
}
|
|
- var isCopyMode = false
|
|
|
|
- private set
|
|
|
|
|
|
|
|
private var isVerified = false
|
|
private var isVerified = false
|
|
|
|
|
|
@@ -36,6 +42,8 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
|
|
private var kmpdfDocumentController: KMPDFDocumentController? = null
|
|
private var kmpdfDocumentController: KMPDFDocumentController? = null
|
|
val isOpenedFileLiveData = MutableLiveData<Boolean>().apply { value = false }
|
|
val isOpenedFileLiveData = MutableLiveData<Boolean>().apply { value = false }
|
|
val fileNameLiveData = MutableLiveData<String>()
|
|
val fileNameLiveData = MutableLiveData<String>()
|
|
|
|
+ val annotationModeLiveData = MutableLiveData<AnnotationMode>().apply { value = AnnotationMode.None }
|
|
|
|
+ var isCopyModeLiveData = MutableLiveData<Boolean>().apply { value = false }
|
|
|
|
|
|
@JvmOverloads
|
|
@JvmOverloads
|
|
fun openPdfFile(context: Context, uri: Uri, type: String? = null): Boolean {
|
|
fun openPdfFile(context: Context, uri: Uri, type: String? = null): Boolean {
|
|
@@ -73,14 +81,59 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
|
|
return kmpdfDocumentController?.copySelection() ?: false
|
|
return kmpdfDocumentController?.copySelection() ?: false
|
|
}
|
|
}
|
|
|
|
|
|
- fun startCopyTextMode() {
|
|
|
|
|
|
+ fun onClickCopyBtn() {
|
|
|
|
+ if (annotationModeLiveData.value != AnnotationMode.None) stopAnnotationMode()
|
|
|
|
+ if (isCopyModeLiveData.value == true) {
|
|
|
|
+ stopCopyTextMode()
|
|
|
|
+ } else {
|
|
|
|
+ startCopyTextMode()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fun onClickHighlightBtn() {
|
|
|
|
+ if (isCopyModeLiveData.value == true) stopCopyTextMode()
|
|
|
|
+ if (annotationModeLiveData.value == AnnotationMode.Highlight) {
|
|
|
|
+ stopAnnotationMode()
|
|
|
|
+ } else {
|
|
|
|
+ startHighLightEditMode()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fun onClickStrikeBtn() {
|
|
|
|
+ if (isCopyModeLiveData.value == true) stopCopyTextMode()
|
|
|
|
+ if (annotationModeLiveData.value == AnnotationMode.Strike) {
|
|
|
|
+ stopAnnotationMode()
|
|
|
|
+ } else {
|
|
|
|
+ startStrikeOutEditMode()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fun onClickUnderlineBtn() {
|
|
|
|
+ if (isCopyModeLiveData.value == true) stopCopyTextMode()
|
|
|
|
+ if (annotationModeLiveData.value == AnnotationMode.Underline) {
|
|
|
|
+ stopAnnotationMode()
|
|
|
|
+ } else {
|
|
|
|
+ startUnderLineEditMode()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ fun onClickInkBtn() {
|
|
|
|
+ if (isCopyModeLiveData.value == true) stopCopyTextMode()
|
|
|
|
+ if (annotationModeLiveData.value == AnnotationMode.Ink) {
|
|
|
|
+ stopAnnotationMode()
|
|
|
|
+ } else {
|
|
|
|
+ startInkEditMode()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private fun startCopyTextMode() {
|
|
kmpdfDocumentController?.startCopyText()
|
|
kmpdfDocumentController?.startCopyText()
|
|
- isCopyMode = true
|
|
|
|
|
|
+ isCopyModeLiveData.postValue(true)
|
|
}
|
|
}
|
|
|
|
|
|
- fun stopCopyTextMode() {
|
|
|
|
|
|
+ private fun stopCopyTextMode() {
|
|
kmpdfDocumentController?.stopCopyText()
|
|
kmpdfDocumentController?.stopCopyText()
|
|
- isCopyMode = false
|
|
|
|
|
|
+ isCopyModeLiveData.postValue(false)
|
|
}
|
|
}
|
|
|
|
|
|
fun setHighLightAttributes(color: Int, alpha: Int) {
|
|
fun setHighLightAttributes(color: Int, alpha: Int) {
|
|
@@ -91,8 +144,9 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- fun startHighLightEditMode() {
|
|
|
|
|
|
+ private fun startHighLightEditMode() {
|
|
kmpdfFactory?.setAnnotationEditMode(KMPDFAnnotationBean.AnnotationType.HIGH_LIGHT)
|
|
kmpdfFactory?.setAnnotationEditMode(KMPDFAnnotationBean.AnnotationType.HIGH_LIGHT)
|
|
|
|
+ annotationModeLiveData.postValue(AnnotationMode.Highlight)
|
|
}
|
|
}
|
|
|
|
|
|
fun setStrikeOutAttributes(color: Int, alpha: Int) {
|
|
fun setStrikeOutAttributes(color: Int, alpha: Int) {
|
|
@@ -103,8 +157,9 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- fun startStrikeOutEditMode() {
|
|
|
|
|
|
+ private fun startStrikeOutEditMode() {
|
|
kmpdfFactory?.setAnnotationEditMode(KMPDFAnnotationBean.AnnotationType.STRIKE_OUT)
|
|
kmpdfFactory?.setAnnotationEditMode(KMPDFAnnotationBean.AnnotationType.STRIKE_OUT)
|
|
|
|
+ annotationModeLiveData.postValue(AnnotationMode.Strike)
|
|
}
|
|
}
|
|
|
|
|
|
fun setUnderLineAttributes(color: Int, alpha: Int) {
|
|
fun setUnderLineAttributes(color: Int, alpha: Int) {
|
|
@@ -115,8 +170,9 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- fun startUnderLineEditMode() {
|
|
|
|
|
|
+ private fun startUnderLineEditMode() {
|
|
kmpdfFactory?.setAnnotationEditMode(KMPDFAnnotationBean.AnnotationType.UNDER_LINE)
|
|
kmpdfFactory?.setAnnotationEditMode(KMPDFAnnotationBean.AnnotationType.UNDER_LINE)
|
|
|
|
+ annotationModeLiveData.postValue(AnnotationMode.Underline)
|
|
}
|
|
}
|
|
|
|
|
|
fun setInkAttributes(color: Int, alpha: Int, width: Float) {
|
|
fun setInkAttributes(color: Int, alpha: Int, width: Float) {
|
|
@@ -130,12 +186,14 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- fun startInkEditMode() {
|
|
|
|
|
|
+ private fun startInkEditMode() {
|
|
kmpdfFactory?.setAnnotationEditMode(KMPDFAnnotationBean.AnnotationType.INK)
|
|
kmpdfFactory?.setAnnotationEditMode(KMPDFAnnotationBean.AnnotationType.INK)
|
|
|
|
+ annotationModeLiveData.postValue(AnnotationMode.Ink)
|
|
}
|
|
}
|
|
|
|
|
|
- fun stopEditMode() {
|
|
|
|
|
|
+ private fun stopAnnotationMode() {
|
|
kmpdfFactory?.setAnnotationEditMode(KMPDFAnnotationBean.AnnotationType.NULL)
|
|
kmpdfFactory?.setAnnotationEditMode(KMPDFAnnotationBean.AnnotationType.NULL)
|
|
|
|
+ annotationModeLiveData.postValue(AnnotationMode.None)
|
|
}
|
|
}
|
|
|
|
|
|
fun setReaderView(readerView: KMPDFReaderView) {
|
|
fun setReaderView(readerView: KMPDFReaderView) {
|