Browse Source

Restore edit state after device orientation change

cooperku_kdanmobile 5 năm trước cách đây
mục cha
commit
6069849453

+ 23 - 1
reader/src/main/java/com/kdanmobile/reader/ReaderViewModel.kt

@@ -261,6 +261,7 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
     }
 
     fun setReaderView(readerView: KMPDFReaderView) {
+        val isFirst = kmpdfFactory?.readerView == null
         kmpdfFactory?.readerView = readerView
         kmpdfDocumentController = kmpdfFactory?.getController(KMPDFFactory.ControllerType.DOCUMENT) as KMPDFDocumentController
         updateViewDirection()
@@ -288,10 +289,31 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
         kmpdfFactory?.kmpdfAnnotEditModeChangeListener = KMPDFAnnotEditModeChangeListener {
             annotationEitModeLiveData.postValue(it)
         }
+
+        if (!isFirst) {
+            restoreStateBeforeDestroy()
+        }
+    }
+
+    private fun restoreStateBeforeDestroy() {
+        if (isCopyModeLiveData.value == true) {
+            startCopyTextMode()
+        } else {
+            val annotationEditMode = when (annotationModeLiveData.value) {
+                AnnotationMode.None, null -> KMPDFAnnotationBean.AnnotationType.NULL
+                AnnotationMode.Highlight -> KMPDFAnnotationBean.AnnotationType.HIGH_LIGHT
+                AnnotationMode.Strike -> KMPDFAnnotationBean.AnnotationType.STRIKE_OUT
+                AnnotationMode.Underline -> KMPDFAnnotationBean.AnnotationType.UNDER_LINE
+                AnnotationMode.Ink -> KMPDFAnnotationBean.AnnotationType.INK
+            }
+            kmpdfFactory?.setAnnotationEditMode(annotationEditMode)
+            kmpdfFactory?.kmpdfAnnotEditMode?.pdfAnnotEditMode = KMPDFAnnotEditMode.Mode.NULL
+            annotationEitModeLiveData.postValue(KMPDFAnnotEditMode.Mode.NULL)
+        }
     }
 
     fun saveModifyingAnnotationBeforeDestroy() {
-        stopAnnotationMode()
+        kmpdfFactory?.setAnnotationEditMode(KMPDFAnnotationBean.AnnotationType.NULL)
     }
 
     fun setPageIndex(pageIndex: Int){