Explorar o código

Show UNDO snackber after clicking add button on MediaBox

cooperku_kdanmobile %!s(int64=5) %!d(string=hai) anos
pai
achega
8c0ec8f3de

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

@@ -9,6 +9,7 @@ import android.os.Build
 import android.os.Bundle
 import android.support.constraint.ConstraintLayout
 import android.support.constraint.ConstraintSet
+import android.support.design.widget.Snackbar
 import android.support.v4.content.ContextCompat
 import android.support.v7.app.AlertDialog
 import android.support.v7.app.AppCompatActivity
@@ -72,6 +73,8 @@ abstract class ReaderActivity : AppCompatActivity() {
 
     private var oldLeftToolbarType = ReaderViewModel.LeftToolbarType.NONE
 
+    private var snackbarMediaBox: Snackbar? = null
+
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
         setContentView(R.layout.activity_reader)
@@ -233,10 +236,23 @@ 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()
+            KMPDFAnnotEditMode.Mode.NULL -> {
+                showAllToolbars()
+                isHideToolbar = false
+                snackbarMediaBox?.dismiss()
+                snackbarMediaBox = null
+            }
+            KMPDFAnnotEditMode.Mode.SIGN_MODIFY -> {
+                hideAllToolbars()
+                isHideToolbar = true
+            }
+            KMPDFAnnotEditMode.Mode.FREETEXT_MODIFY, KMPDFAnnotEditMode.Mode.STAMP_MODIFY, KMPDFAnnotEditMode.Mode.SHAPE_MODIFY -> {
+                hideAllToolbars()
+                isHideToolbar = true
+                snackbarMediaBox?.dismiss()
+                snackbarMediaBox = null
+            }
             else -> {}
         }
     }
@@ -505,13 +521,37 @@ abstract class ReaderActivity : AppCompatActivity() {
     }
 
     private fun setupMediaBoxView() {
+
+        fun showSnackbar(title: String, btnText: String) {
+            snackbarMediaBox = Snackbar.make(mediaBoxView, title, Snackbar.LENGTH_INDEFINITE)
+                    .setAction(btnText) {
+                        viewModel.clearSelection()
+                        mediaBoxView.post {
+                            mediaBoxView.show()
+                            snackbarMediaBox?.dismiss()
+                            snackbarMediaBox = null
+                        }
+                    }
+            snackbarMediaBox?.setActionTextColor(ContextCompat.getColor(this, R.color.bright_blue))
+            snackbarMediaBox?.show()
+        }
+
         mediaBoxView.apply {
-            onShowListener = Runnable { onMediaBoxShown() }
-            onDismissListener = Runnable { onMediaBoxDismissed() }
+            onShowListener = Runnable {
+                onMediaBoxShown()
+                snackbarMediaBox?.dismiss()
+                snackbarMediaBox = null
+            }
+            onDismissListener = Runnable {
+                onMediaBoxDismissed()
+                snackbarMediaBox?.dismiss()
+                snackbarMediaBox = null
+            }
             onClickAddButtonListener = object : MediaBoxView.OnClickHeaderButtonListener {
                 override fun onClickTextBoxAddButton(textBoxTabView: TextBoxTabView) {
                     dismiss(false)
                     viewModel.setTextBoxAttribute(textBoxTabView.getTextBoxAttribute())
+                    showSnackbar(resources.getString(R.string.mediaBox_snakebar_textBox), resources.getString(R.string.mediaBox_snakebar_undo))
                 }
 
                 override fun onClickTextBoxStyleApplyButton(textBoxTabView: TextBoxTabView) {
@@ -522,16 +562,19 @@ abstract class ReaderActivity : AppCompatActivity() {
                 override fun onClickSignatureAddButton(signatureTabView: SignatureTabView) {
                     dismiss(false)
                     viewModel.setSignatureAttribute(signatureTabView.getSignatureAttribute())
+                    showSnackbar(resources.getString(R.string.mediaBox_snakebar_signature), resources.getString(R.string.mediaBox_snakebar_undo))
                 }
 
                 override fun onClickStampAddButton(stampTabView: StampTabView) {
                     dismiss(false)
                     viewModel.setStampAttribute(stampTabView.getStampAttribute())
+                    showSnackbar(resources.getString(R.string.mediaBox_snakebar_stamp), resources.getString(R.string.mediaBox_snakebar_undo))
                 }
 
                 override fun onClickShapeAddButton(shapeTabView: ShapeTabView) {
                     dismiss(false)
                     viewModel.setShapeAttribute(shapeTabView.getShapeAttribute())
+                    showSnackbar(resources.getString(R.string.mediaBox_snakebar_shape), resources.getString(R.string.mediaBox_snakebar_undo))
                 }
             }
         }
@@ -667,10 +710,12 @@ abstract class ReaderActivity : AppCompatActivity() {
 
     private fun onMediaBoxShown() {
         hideAllToolbars()
+        isHideToolbar = true
     }
 
     private fun onMediaBoxDismissed() {
         showAllToolbars()
+        isHideToolbar = false
         viewModel.clearSelection()
     }
 

+ 6 - 0
reader/src/main/res/values/strings.xml

@@ -77,4 +77,10 @@
     <string name="mediaBox_shape_unitSeekBarOpacity">%</string>
     <string name="mediaBox_shape_titleSeekBarThickness">Thickness</string>
     <string name="mediaBox_shape_unitSeekBarThickness">px</string>
+
+    <string name="mediaBox_snakebar_textBox">點擊你要新增文字的位置</string>
+    <string name="mediaBox_snakebar_signature">選擇你要新增簽名的位置</string>
+    <string name="mediaBox_snakebar_stamp">點擊你要新增圖章的位置</string>
+    <string name="mediaBox_snakebar_shape">點擊你要新增圖形的位置</string>
+    <string name="mediaBox_snakebar_undo">UNDO</string>
 </resources>