Prechádzať zdrojové kódy

hide toolbars when EditMode is MODIFY, and show toolbars after modifying

cooperku_kdanmobile 5 rokov pred
rodič
commit
ff54addc10

+ 20 - 5
reader/src/main/java/com/kdanmobile/reader/ReaderActivity.kt

@@ -25,6 +25,7 @@ import android.view.View
 import android.widget.EditText
 import android.widget.LinearLayout
 import android.widget.TextView
+import com.kdanmobile.kmpdfkit.globaldata.KMPDFAnnotEditMode
 import com.kdanmobile.reader.annotationattribute.AnnotationAttribute
 import com.kdanmobile.reader.annotationattribute.AnnotationColor
 import com.kdanmobile.reader.annotationattribute.InkAttribute
@@ -99,6 +100,7 @@ abstract class ReaderActivity : AppCompatActivity() {
         viewModel.isOpenedFileLiveData.observe(this, Observer(this::onIsOpenedFileUpdate))
         viewModel.fileNameLiveData.observe(this, Observer { tv_readerActivity_title.text = it })
         viewModel.annotationModeLiveData.observe(this, Observer(this::onAnnotationModeUpdate))
+        viewModel.annotationEitModeLiveData.observe(this, Observer(this::onAnnotationEditModeUpdate))
         viewModel.isCopyModeLiveData.observe(this, Observer (this::onIsCopyModeUpdate))
         viewModel.highLightAttributeLiveData.observe(this, Observer(this::onHighlightAttributeUpdate))
         viewModel.strikeAttributeLiveData.observe(this, Observer(this::onStrikeAttributeUpdate))
@@ -239,6 +241,15 @@ abstract class ReaderActivity : AppCompatActivity() {
         }
     }
 
+    private fun onAnnotationEditModeUpdate(mode: KMPDFAnnotEditMode.Mode?) {
+        println("onAnnotationEditModeUpdate KMPDFAnnotEditMode.Mode.$mode")
+        when (mode) {
+            KMPDFAnnotEditMode.Mode.NULL -> showAllToolbars()
+            KMPDFAnnotEditMode.Mode.FREETEXT_MODIFY, KMPDFAnnotEditMode.Mode.STAMP_MODIFY, KMPDFAnnotEditMode.Mode.SIGN_MODIFY, KMPDFAnnotEditMode.Mode.SHAPE_MODIFY -> hideAllToolbars()
+            else -> {}
+        }
+    }
+
     private fun onIsOpenedFileUpdate(isOpened: Boolean?) {
         if (isOpened == null) return
         val container = viewGroup_readerActivity_container
@@ -275,7 +286,10 @@ abstract class ReaderActivity : AppCompatActivity() {
             }
 
             override fun onScroll(e1: MotionEvent?, e2: MotionEvent?, distanceX: Float, distanceY: Float): Boolean {
-                if (!isHideToolbar) {
+                val isEditMode = viewModel.annotationModeLiveData.value != ReaderViewModel.AnnotationMode.None
+                val isCopyMode = viewModel.isCopyModeLiveData.value != false
+
+                if (!isEditMode && !isCopyMode && !isHideToolbar) {
                     hideAllToolbars()
                     isHideToolbar = true
                 }
@@ -283,6 +297,7 @@ abstract class ReaderActivity : AppCompatActivity() {
             }
         }
         viewModel.setReaderView(readerView)
+        viewModel.pdfInfoHandler.setCurrentPage(viewModel.pageIndexLiveData.value ?: 0)
         container.addView(readerView)
     }
 
@@ -463,22 +478,22 @@ abstract class ReaderActivity : AppCompatActivity() {
             onDismissListener = Runnable { onMediaBoxDismissed() }
             onViewerEditTabAddButtonClickListener = object : ViewerEditView.OnViewerEditTabAddButtonClickListener {
                 override fun onTabTextBoxAddButtonClick(textBoxTabView: TextBoxTabView) {
-                    dismiss()
+                    dismiss(false)
                     viewModel.setTextBoxAttribute(textBoxTabView.getTextBoxAttribute())
                 }
 
                 override fun onTabSignatureAddButtonClick(signatureTabView: SignatureTabView) {
-                    dismiss()
+                    dismiss(false)
                     viewModel.setSignatureAttribute(signatureTabView.getSignatureAttribute())
                 }
 
                 override fun onTabStampAddButtonClick(stampTabView: StampTabView) {
-                    dismiss()
+                    dismiss(false)
                     viewModel.setStampAttribute(stampTabView.getStampAttribute())
                 }
 
                 override fun onTabShapeAddButtonClick(shapeTabView: ShapeTabView) {
-                    dismiss()
+                    dismiss(false)
                     viewModel.setShapeAttribute(shapeTabView.getShapeAttribute())
                 }
             }

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

@@ -22,7 +22,7 @@ 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.pdfcommon.*
+import com.kdanmobile.kmpdfkit.manager.listener.KMPDFAnnotEditModeChangeListener
 import com.kdanmobile.reader.screen.data.ShapeAttribute
 import com.kdanmobile.reader.screen.data.SignatureAttribute
 import com.kdanmobile.reader.screen.data.StampAttribute
@@ -74,6 +74,7 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
     val isOpenedFileLiveData = MutableLiveData<Boolean>().apply { value = false }
     val fileNameLiveData = MutableLiveData<String>()
     val annotationModeLiveData = MutableLiveData<AnnotationMode>().apply { value = AnnotationMode.None }
+    val annotationEitModeLiveData = MutableLiveData<KMPDFAnnotEditMode.Mode>().apply { value = KMPDFAnnotEditMode.Mode.NULL }
     var isCopyModeLiveData = MutableLiveData<Boolean>().apply { value = false }
 
     val pageIndexLiveData: LiveData<Int>
@@ -283,6 +284,10 @@ class ReaderViewModel(private val pdfSdkLicense: String, private val pdfSdkRsaMs
                 }
             }
         }
+
+        kmpdfFactory?.kmpdfAnnotEditModeChangeListener = KMPDFAnnotEditModeChangeListener {
+            annotationEitModeLiveData.postValue(it)
+        }
     }
 
     fun setPageIndex(pageIndex: Int){

+ 5 - 3
reader/src/main/java/com/kdanmobile/reader/screen/view/ViewerEditView.kt

@@ -59,7 +59,7 @@ class ViewerEditView @JvmOverloads constructor(
 
     fun show() {
         visibility = View.VISIBLE
-        setOnClickListener { dismiss() }
+        setOnClickListener { dismiss(true) }
         post {
             showMaskWithAnimation()
             showMediaBoxWithAnimation()
@@ -67,11 +67,13 @@ class ViewerEditView @JvmOverloads constructor(
         onShowListener?.run()
     }
 
-    fun dismiss() {
+    fun dismiss(fromUser: Boolean = true) {
         setOnClickListener(null)
         hideMaskWithAnimation()
         hideMediaBoxWithAnimation()
-        onDismissListener?.run()
+        if (fromUser) {
+            onDismissListener?.run()
+        }
     }
 
     private fun showMaskWithAnimation() {