Преглед на файлове

Change column number of Signature in MediaBox to depend on dimens.xml

cooperku_kdanmobile преди 5 години
родител
ревизия
ddd8bb1ef3

+ 5 - 1
reader/src/main/java/com/kdanmobile/reader/screen/reader/mediabox/signature/SignatureRecyclerViewItemDecoration.kt

@@ -1,6 +1,7 @@
 package com.kdanmobile.reader.screen.reader.mediabox.signature
 
 import android.graphics.Rect
+import android.support.v7.widget.GridLayoutManager
 import android.support.v7.widget.RecyclerView
 import android.view.View
 
@@ -10,7 +11,10 @@ class SignatureRecyclerViewItemDecoration(private val space: Int, private val ad
     override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
         val position = parent.getChildAdapterPosition(view)
         val childCount = parent.adapter?.itemCount ?: 0
-        outRect.bottom = when (position == childCount - 1) {
+        val layoutManager = parent.layoutManager as GridLayoutManager
+        val currentRow = (position / layoutManager.spanCount)
+        val lastRow = ((childCount - 1) / layoutManager.spanCount)
+        outRect.bottom = when (currentRow == lastRow) {
             true -> space + additionalPadding
             false -> space
         }

+ 7 - 1
reader/src/main/java/com/kdanmobile/reader/screen/reader/mediabox/signature/SignatureTabView.kt

@@ -43,7 +43,7 @@ class SignatureTabView : ConstraintLayout {
         updateSignaturePaths()
         updateSignatureMessage()
 
-        recyclerView_signature.layoutManager = GridLayoutManager(context, 1)
+        recyclerView_signature.layoutManager = GridLayoutManager(context, resources.getInteger(R.integer.mediaBox_signature_columnCount))
         val adapter = SignatureAdapter(context, signaturePaths)
         adapter.setOnSignatureClickListener(object : OnSignatureClickListener {
             override fun onSignatureClick(path: String) {
@@ -54,6 +54,12 @@ class SignatureTabView : ConstraintLayout {
         adapter.setOnSignatureRemoveListener(object : OnSignatureRemoveListener {
             override fun onSignatureRemove(path: String) {
                 val position = signaturePaths.indexOf(path)
+
+                val layoutManager = recyclerView_signature.layoutManager as GridLayoutManager
+                val updateRow = (position - 1) / layoutManager.spanCount
+                val positionStart = updateRow * layoutManager.spanCount
+                adapter.notifyItemRangeChanged(positionStart, adapter.itemCount - positionStart)
+
                 signaturePaths.removeAt(position)
                 adapter.notifyItemRemoved(position)
                 File(path).delete()

+ 2 - 0
reader/src/main/res/values-land/dimens.xml

@@ -1,5 +1,7 @@
 <resources>
     <dimen name="reader_media_box_height">0dp</dimen>
 
+    <integer name="mediaBox_signature_columnCount">2</integer>
+
     <integer name="mediaBox_standardStamp_columnCount">3</integer>
 </resources>

+ 2 - 0
reader/src/main/res/values/dimens.xml

@@ -10,5 +10,7 @@
 
     <dimen name="reader_media_box_height">336dp</dimen>
 
+    <integer name="mediaBox_signature_columnCount">1</integer>
+
     <integer name="mediaBox_standardStamp_columnCount">2</integer>
 </resources>