Ver Fonte

Refactor MediaBox MediaBoxTabView

Wayne há 5 anos atrás
pai
commit
5315479ccb

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

@@ -27,7 +27,7 @@ import com.kdanmobile.reader.annotationattribute.AnnotationAttribute
 import com.kdanmobile.reader.annotationattribute.AnnotationColor
 import com.kdanmobile.reader.annotationattribute.InkAttribute
 import com.kdanmobile.reader.screen.ViewerSettingActivity
-import com.kdanmobile.reader.screen.reader.mediabox.ViewerEditView
+import com.kdanmobile.reader.screen.reader.mediabox.MediaBoxView
 import com.kdanmobile.reader.screen.reader.mediabox.shape.ShapeTabView
 import com.kdanmobile.reader.screen.reader.mediabox.signature.SignatureTabView
 import com.kdanmobile.reader.screen.reader.mediabox.stamp.StampTabView
@@ -470,23 +470,23 @@ abstract class ReaderActivity : AppCompatActivity() {
         viewerEditView.apply {
             onShowListener = Runnable { onMediaBoxShown() }
             onDismissListener = Runnable { onMediaBoxDismissed() }
-            onViewerEditTabAddButtonClickListener = object : ViewerEditView.OnViewerEditTabAddButtonClickListener {
-                override fun onTabTextBoxAddButtonClick(textBoxTabView: TextBoxTabView) {
+            onClickAddButtonListener = object : MediaBoxView.OnClickAddButtonListener {
+                override fun onClickTextBoxAddButton(textBoxTabView: TextBoxTabView) {
                     hideAllToolbars()
                     viewModel.setTextBoxAttribute(textBoxTabView.getTextBoxAttribute())
                 }
 
-                override fun onTabSignatureAddButtonClick(signatureTabView: SignatureTabView) {
+                override fun onClickSignatureAddButton(signatureTabView: SignatureTabView) {
                     hideAllToolbars()
                     viewModel.setSignatureAttribute(signatureTabView.getSignatureAttribute())
                 }
 
-                override fun onTabStampAddButtonClick(stampTabView: StampTabView) {
+                override fun onClickStampAddButton(stampTabView: StampTabView) {
                     hideAllToolbars()
                     viewModel.setStampAttribute(stampTabView.getStampAttribute())
                 }
 
-                override fun onTabShapeAddButtonClick(shapeTabView: ShapeTabView) {
+                override fun onClickShapeAddButton(shapeTabView: ShapeTabView) {
                     hideAllToolbars()
                     viewModel.setShapeAttribute(shapeTabView.getShapeAttribute())
                 }

+ 8 - 8
reader/src/main/java/com/kdanmobile/reader/screen/reader/mediabox/ViewerEditTabView.kt

@@ -5,38 +5,38 @@ import android.support.constraint.ConstraintLayout
 import android.util.AttributeSet
 import android.view.LayoutInflater
 import com.kdanmobile.reader.R
-import kotlinx.android.synthetic.main.view_viewer_edit_tab.view.*
+import kotlinx.android.synthetic.main.view_media_box_tab.view.*
 
-class ViewerEditTabView : ConstraintLayout {
+class MediaBoxTabView : ConstraintLayout {
 
     var onClickListenerTabTextBox: OnClickListener? = null
         set(value) {
             field = value
-            viewerEdit_tab_textBox?.setOnClickListener(value)
+            ib_mediaBoxTab_textBox?.setOnClickListener(value)
         }
 
     var onClickListenerTabSignature: OnClickListener? = null
         set(value) {
             field = value
-            viewerEdit_tab_signature?.setOnClickListener(value)
+            ib_mediaBoxTab_signature?.setOnClickListener(value)
         }
 
     var onClickListenerTabStamp: OnClickListener? = null
         set(value) {
             field = value
-            viewerEdit_tab_stamp?.setOnClickListener(value)
+            ib_mediaBoxTab_stamp?.setOnClickListener(value)
         }
 
     var onClickListenerTabShape: OnClickListener? = null
         set(value) {
             field = value
-            viewerEdit_tab_shape?.setOnClickListener(value)
+            ib_mediaBoxTab_shape?.setOnClickListener(value)
         }
 
     var onClickListenerTabForm: OnClickListener? = null
         set(value) {
             field = value
-            viewerEdit_tab_form?.setOnClickListener(value)
+            ib_mediaBoxTab_form?.setOnClickListener(value)
         }
 
     constructor(context: Context) : super(context) {
@@ -52,6 +52,6 @@ class ViewerEditTabView : ConstraintLayout {
     }
 
     private fun initView() {
-        LayoutInflater.from(context).inflate(R.layout.view_viewer_edit_tab, this)
+        LayoutInflater.from(context).inflate(R.layout.view_media_box_tab, this)
     }
 }

+ 31 - 31
reader/src/main/java/com/kdanmobile/reader/screen/reader/mediabox/ViewerEditView.kt

@@ -17,10 +17,10 @@ import com.kdanmobile.reader.screen.reader.mediabox.shape.ShapeTabView
 import com.kdanmobile.reader.screen.reader.mediabox.signature.SignatureTabView
 import com.kdanmobile.reader.screen.reader.mediabox.stamp.StampTabView
 import com.kdanmobile.reader.screen.reader.mediabox.textbox.TextBoxTabView
-import kotlinx.android.synthetic.main.view_viewer_edit.view.*
-import kotlinx.android.synthetic.main.view_viewer_edit_tab.view.*
+import kotlinx.android.synthetic.main.view_media_box.view.*
+import kotlinx.android.synthetic.main.view_media_box_tab.view.*
 
-class ViewerEditView @JvmOverloads constructor(
+class MediaBoxView @JvmOverloads constructor(
         context: Context,
         attrs: AttributeSet? = null,
         defStyleAttr: Int = 0
@@ -44,19 +44,19 @@ class ViewerEditView @JvmOverloads constructor(
     private var maskAnimator: ValueAnimator? = null
     private var tabType = ViewerEditTabType.NONE
     private var selected: ImageButton? = null
-    var onViewerEditTabAddButtonClickListener: OnViewerEditTabAddButtonClickListener? = null
+    var onClickAddButtonListener: OnClickAddButtonListener? = null
 
     init {
-        LayoutInflater.from(context).inflate(R.layout.view_viewer_edit, this)
+        LayoutInflater.from(context).inflate(R.layout.view_media_box, this)
         visibility = View.INVISIBLE
         setupTabView()
 
         /** Set empty listener to prevent dismissing by clicking box **/
-        view_viewEdit_content.setOnClickListener {}
+        view_mediaBox_dialog.setOnClickListener {}
 
         /** Move media box view to bottom of parent(hide it) **/
         val size = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
-        val v = view_viewEdit_content
+        val v = view_mediaBox_dialog
         v.measure(size, size)
         v.y = v.top + v.measuredHeight.toFloat()
     }
@@ -108,7 +108,7 @@ class ViewerEditView @JvmOverloads constructor(
 
     private fun showMediaBoxWithAnimation() {
         mediaBoxAnimator?.cancel()
-        val v = view_viewEdit_content
+        val v = view_mediaBox_dialog
         v.visibility = View.VISIBLE
         val from = v.y
         val to = v.top.toFloat()
@@ -128,7 +128,7 @@ class ViewerEditView @JvmOverloads constructor(
 
     private fun hideMediaBoxWithAnimation() {
         mediaBoxAnimator?.cancel()
-        val v = view_viewEdit_content
+        val v = view_mediaBox_dialog
         val from = v.y
         val to = v.top.toFloat() + v.height
         val holder = PropertyValuesHolder.ofFloat("Y", from, to)
@@ -140,7 +140,7 @@ class ViewerEditView @JvmOverloads constructor(
                     super.onAnimationEnd(animation)
                     removeListener(this)
                     v.visibility = View.INVISIBLE
-                    this@ViewerEditView.visibility = View.GONE
+                    this@MediaBoxView.visibility = View.GONE
                 }
             })
             start()
@@ -148,13 +148,13 @@ class ViewerEditView @JvmOverloads constructor(
     }
 
     private fun setupTabView() {
-        viewerEdit_tab.onClickListenerTabTextBox = OnClickListener(this::setupTextBoxView)
-        viewerEdit_tab.onClickListenerTabSignature = OnClickListener(this::setupSignatureView)
-        viewerEdit_tab.onClickListenerTabStamp = OnClickListener(this::setupStampView)
-        viewerEdit_tab.onClickListenerTabShape = OnClickListener(this::setupShapeView)
-        viewerEdit_tab.onClickListenerTabForm = OnClickListener(this::setupFormView)
+        mediaBoxTabView_mediaBox_tab.onClickListenerTabTextBox = OnClickListener(this::setupTextBoxView)
+        mediaBoxTabView_mediaBox_tab.onClickListenerTabSignature = OnClickListener(this::setupSignatureView)
+        mediaBoxTabView_mediaBox_tab.onClickListenerTabStamp = OnClickListener(this::setupStampView)
+        mediaBoxTabView_mediaBox_tab.onClickListenerTabShape = OnClickListener(this::setupShapeView)
+        mediaBoxTabView_mediaBox_tab.onClickListenerTabForm = OnClickListener(this::setupFormView)
 
-        setupTextBoxView(viewerEdit_tab_textBox)
+        setupTextBoxView(ib_mediaBoxTab_textBox)
     }
 
     private fun getButtonDrawable(tabType: ViewerEditTabType, isSelected: Boolean): Int {
@@ -180,7 +180,7 @@ class ViewerEditView @JvmOverloads constructor(
             selected = button
             button.setImageDrawable(ContextCompat.getDrawable(context, getButtonDrawable(this.tabType, true)))
 
-            viewEdit_layout_tab_content.removeAllViews()
+            viewGroup_mediaBox_pageContainer.removeAllViews()
             changed = true
         }
         return changed
@@ -191,10 +191,10 @@ class ViewerEditView @JvmOverloads constructor(
         if (changed) {
             val textBoxTabView = TextBoxTabView(context)
             val params = ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.MATCH_PARENT, ConstraintLayout.LayoutParams.MATCH_PARENT)
-            viewEdit_layout_tab_content.addView(textBoxTabView, params)
+            viewGroup_mediaBox_pageContainer.addView(textBoxTabView, params)
             textBoxTabView.onMediaBoxHeaderClickListener = object: MediaBoxHeader.OnTitleButtonClickListener {
                 override fun onTitleButtonClick() {
-                    onViewerEditTabAddButtonClickListener?.onTabTextBoxAddButtonClick(textBoxTabView)
+                    onClickAddButtonListener?.onClickTextBoxAddButton(textBoxTabView)
                 }
             }
         }
@@ -205,10 +205,10 @@ class ViewerEditView @JvmOverloads constructor(
         if (changed) {
             val signatureTabView = SignatureTabView(context)
             val params = ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.MATCH_PARENT, ConstraintLayout.LayoutParams.MATCH_PARENT)
-            viewEdit_layout_tab_content.addView(signatureTabView, params)
+            viewGroup_mediaBox_pageContainer.addView(signatureTabView, params)
             signatureTabView.onMediaBoxHeaderClickListener = object: MediaBoxHeader.OnTitleButtonClickListener {
                 override fun onTitleButtonClick() {
-                    onViewerEditTabAddButtonClickListener?.onTabSignatureAddButtonClick(signatureTabView)
+                    onClickAddButtonListener?.onClickSignatureAddButton(signatureTabView)
                 }
             }
         }
@@ -219,10 +219,10 @@ class ViewerEditView @JvmOverloads constructor(
         if (changed) {
             val stampTabView = StampTabView(context)
             val params = ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.MATCH_PARENT, ConstraintLayout.LayoutParams.MATCH_PARENT)
-            viewEdit_layout_tab_content.addView(stampTabView, params)
+            viewGroup_mediaBox_pageContainer.addView(stampTabView, params)
             stampTabView.onMediaBoxHeaderClickListener = object: MediaBoxHeader.OnTitleButtonClickListener {
                 override fun onTitleButtonClick() {
-                    onViewerEditTabAddButtonClickListener?.onTabStampAddButtonClick(stampTabView)
+                    onClickAddButtonListener?.onClickStampAddButton(stampTabView)
                 }
             }
         }
@@ -233,10 +233,10 @@ class ViewerEditView @JvmOverloads constructor(
         if (changed) {
             val shapeTabView = ShapeTabView(context)
             val params = ConstraintLayout.LayoutParams(ConstraintLayout.LayoutParams.MATCH_PARENT, ConstraintLayout.LayoutParams.MATCH_PARENT)
-            viewEdit_layout_tab_content.addView(shapeTabView, params)
+            viewGroup_mediaBox_pageContainer.addView(shapeTabView, params)
             shapeTabView.onMediaBoxHeaderClickListener = object: MediaBoxHeader.OnTitleButtonClickListener {
                 override fun onTitleButtonClick() {
-                    onViewerEditTabAddButtonClickListener?.onTabShapeAddButtonClick(shapeTabView)
+                    onClickAddButtonListener?.onClickShapeAddButton(shapeTabView)
                 }
             }
         }
@@ -246,14 +246,14 @@ class ViewerEditView @JvmOverloads constructor(
         //TODO implements tab view and add to viewEdit_layout_tab_content
         val changed = setupContent(view as ImageButton, ViewerEditTabType.FORM)
         if (changed) {
-            LayoutInflater.from(context).inflate(R.layout.view_viewer_edit_tab, viewEdit_layout_tab_content)
+            LayoutInflater.from(context).inflate(R.layout.view_media_box_tab, viewGroup_mediaBox_pageContainer)
         }
     }
 
-    interface OnViewerEditTabAddButtonClickListener {
-        fun onTabTextBoxAddButtonClick(textBoxTabView: TextBoxTabView)
-        fun onTabSignatureAddButtonClick(signatureTabView: SignatureTabView)
-        fun onTabStampAddButtonClick(stampTabView: StampTabView)
-        fun onTabShapeAddButtonClick(shapeTabView: ShapeTabView)
+    interface OnClickAddButtonListener {
+        fun onClickTextBoxAddButton(textBoxTabView: TextBoxTabView)
+        fun onClickSignatureAddButton(signatureTabView: SignatureTabView)
+        fun onClickStampAddButton(stampTabView: StampTabView)
+        fun onClickShapeAddButton(shapeTabView: ShapeTabView)
     }
 }

+ 1 - 1
reader/src/main/res/layout/activity_reader.xml

@@ -293,7 +293,7 @@
             />
     </android.support.constraint.ConstraintLayout>
 
-    <com.kdanmobile.reader.screen.reader.mediabox.ViewerEditView
+    <com.kdanmobile.reader.screen.reader.mediabox.MediaBoxView
         android:id="@+id/viewerEditView"
         android:layout_width="match_parent"
         android:layout_height="match_parent" />

+ 9 - 9
reader/src/main/res/layout/view_viewer_edit.xml

@@ -8,7 +8,7 @@
 
     <android.support.constraint.ConstraintLayout
         style="@style/MediaBoxStyle"
-        android:id="@+id/view_viewEdit_content"
+        android:id="@+id/view_mediaBox_dialog"
         tools:visibility="visible"
         tools:background="#AA00CC"
         android:visibility="invisible"
@@ -19,29 +19,29 @@
         app:layout_constraintLeft_toLeftOf="parent"
         app:layout_constraintRight_toRightOf="parent">
 
-        <com.kdanmobile.reader.screen.reader.mediabox.ViewerEditTabView
-            android:id="@+id/viewerEdit_tab"
+        <com.kdanmobile.reader.screen.reader.mediabox.MediaBoxTabView
+            android:id="@+id/mediaBoxTabView_mediaBox_tab"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_marginLeft="4dp"
             android:layout_marginStart="4dp"
             app:layout_constraintLeft_toLeftOf="parent"
-            app:layout_constraintRight_toRightOf="@id/view_viewerEdit_divider"
+            app:layout_constraintRight_toRightOf="@id/view_mediaBox_divider"
             app:layout_constraintBottom_toBottomOf="parent"
             app:layout_constraintTop_toTopOf="parent" />
 
         <View
-            android:id="@+id/view_viewerEdit_divider"
+            android:id="@+id/view_mediaBox_divider"
             android:background="#1e000000"
-            app:layout_constraintLeft_toRightOf="@+id/viewerEdit_tab"
-            app:layout_constraintRight_toLeftOf="@id/viewEdit_layout_tab_content"
+            app:layout_constraintLeft_toRightOf="@+id/mediaBoxTabView_mediaBox_tab"
+            app:layout_constraintRight_toLeftOf="@id/viewGroup_mediaBox_pageContainer"
             app:layout_constraintTop_toTopOf="parent"
             app:layout_constraintBottom_toBottomOf="parent"
             android:layout_width="1dp"
             android:layout_height="0dp" />
 
         <android.support.constraint.ConstraintLayout
-            android:id="@+id/viewEdit_layout_tab_content"
+            android:id="@+id/viewGroup_mediaBox_pageContainer"
             android:layout_width="0dp"
             android:layout_height="0dp"
             android:layout_marginEnd="8dp"
@@ -49,7 +49,7 @@
             android:layout_marginTop="12dp"
             android:background="@android:color/darker_gray"
             app:layout_constraintBottom_toBottomOf="parent"
-            app:layout_constraintLeft_toRightOf="@+id/view_viewerEdit_divider"
+            app:layout_constraintLeft_toRightOf="@+id/view_mediaBox_divider"
             app:layout_constraintRight_toRightOf="parent"
             app:layout_constraintTop_toTopOf="parent" />
 

+ 9 - 9
reader/src/main/res/layout/view_viewer_edit_tab.xml

@@ -5,46 +5,46 @@
     android:layout_height="match_parent">
 
     <ImageButton
-        android:id="@+id/viewerEdit_tab_textBox"
+        android:id="@+id/ib_mediaBoxTab_textBox"
         android:layout_width="48dp"
         android:layout_height="48dp"
         android:background="@null"
         android:src="@drawable/ic_textbox" />
 
     <ImageButton
-        android:id="@+id/viewerEdit_tab_signature"
+        android:id="@+id/ib_mediaBoxTab_signature"
         android:layout_width="48dp"
         android:layout_height="48dp"
         android:layout_marginTop="8dp"
         android:background="@null"
         android:src="@drawable/ic_signature"
-        app:layout_constraintTop_toBottomOf="@+id/viewerEdit_tab_textBox" />
+        app:layout_constraintTop_toBottomOf="@+id/ib_mediaBoxTab_textBox" />
 
     <ImageButton
-        android:id="@+id/viewerEdit_tab_stamp"
+        android:id="@+id/ib_mediaBoxTab_stamp"
         android:layout_width="48dp"
         android:layout_height="48dp"
         android:layout_marginTop="8dp"
         android:background="@null"
         android:src="@drawable/ic_stamp"
-        app:layout_constraintTop_toBottomOf="@id/viewerEdit_tab_signature" />
+        app:layout_constraintTop_toBottomOf="@id/ib_mediaBoxTab_signature" />
 
     <ImageButton
-        android:id="@+id/viewerEdit_tab_shape"
+        android:id="@+id/ib_mediaBoxTab_shape"
         android:layout_width="48dp"
         android:layout_height="48dp"
         android:layout_marginTop="8dp"
         android:background="@null"
         android:src="@drawable/ic_shape"
-        app:layout_constraintTop_toBottomOf="@+id/viewerEdit_tab_stamp" />
+        app:layout_constraintTop_toBottomOf="@+id/ib_mediaBoxTab_stamp" />
 
     <ImageButton
-        android:id="@+id/viewerEdit_tab_form"
+        android:id="@+id/ib_mediaBoxTab_form"
         android:layout_width="48dp"
         android:layout_height="48dp"
         android:layout_marginTop="8dp"
         android:background="@null"
         android:src="@drawable/ic_form"
-        app:layout_constraintTop_toBottomOf="@+id/viewerEdit_tab_shape" />
+        app:layout_constraintTop_toBottomOf="@+id/ib_mediaBoxTab_shape" />
 
 </android.support.constraint.ConstraintLayout>