Fixes spacing and dimension issues

blinds
Laurent 5 years ago
parent 4044cee176
commit ab3ad228dd
  1. 6
      app/src/main/java/net/pokeranalytics/android/ui/view/GridSpacingItemDecoration.kt
  2. 34
      app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt
  3. 38
      app/src/main/java/net/pokeranalytics/android/ui/view/SpacesItemDecoration.kt
  4. 1
      app/src/main/res/layout/cell_calendar_grid.xml

@ -7,7 +7,11 @@ import androidx.recyclerview.widget.RecyclerView
/** /**
* Manage spacing for recycler view & grid layout manager * Manage spacing for recycler view & grid layout manager
*/ */
class GridSpacingItemDecoration(val spanCount: Int, val spacing: Int, val includeEdge: Boolean) : class GridSpacingItemDecoration(
private val spanCount: Int,
private val spacing: Int,
private val includeEdge: Boolean
) :
RecyclerView.ItemDecoration() { RecyclerView.ItemDecoration() {
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) { override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {

@ -599,25 +599,29 @@ enum class RowViewType(private var layoutRes: Int) : ViewIdentifier {
itemView.findViewById<RecyclerView?>(R.id.recyclerView)?.let { recyclerView -> itemView.findViewById<RecyclerView?>(R.id.recyclerView)?.let { recyclerView ->
setLayoutManager(this.spanCount)
// val spanCount = row.unit.spanCount // val spanCount = row.unit.spanCount
val spacing = 4.px val spacing = 2.px
val includeEdge = true val includeEdge = true
//
val viewManager = object : GridLayoutManager(itemView.context, spanCount) { // val viewManager = object : GridLayoutManager(itemView.context, spanCount) {
override fun checkLayoutParams(lp: RecyclerView.LayoutParams?): Boolean { // override fun checkLayoutParams(lp: RecyclerView.LayoutParams?): Boolean {
val side = width / this.spanCount - 4.px // val side = width / this.spanCount - 4.px
lp?.let { params -> // lp?.let { params ->
params.width = side // params.width = side
params.height = side // params.height = side
} // }
return true // return true
} // }
} // }
recyclerView.apply { recyclerView.apply {
setHasFixedSize(true) setHasFixedSize(true)
layoutManager = viewManager addItemDecoration(ItemOffsetDecoration(spacing))
addItemDecoration(GridSpacingItemDecoration(spanCount, spacing, includeEdge))
// layoutManager = viewManager
// addItemDecoration(GridSpacingItemDecoration(spanCount, spacing, includeEdge))
} }
} }
@ -628,7 +632,7 @@ enum class RowViewType(private var layoutRes: Int) : ViewIdentifier {
val viewManager = object : GridLayoutManager(itemView.context, spanCount) { val viewManager = object : GridLayoutManager(itemView.context, spanCount) {
override fun checkLayoutParams(lp: RecyclerView.LayoutParams?): Boolean { override fun checkLayoutParams(lp: RecyclerView.LayoutParams?): Boolean {
val side = width / spanCount - 4.px val side = width / spanCount - 3.px
lp?.let { params -> lp?.let { params ->
params.width = side params.width = side
params.height = side params.height = side

@ -0,0 +1,38 @@
package net.pokeranalytics.android.ui.view
import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.ItemDecoration
class SpacesItemDecoration(private val space: Int) : ItemDecoration() {
override fun getItemOffsets(
outRect: Rect,
view: View,
parent: RecyclerView,
state: RecyclerView.State
) {
outRect.left = space
outRect.right = space
outRect.bottom = space
// Add top margin only for the first item to avoid double space between items
if (parent.getChildLayoutPosition(view) == 0) {
outRect.top = space
} else {
outRect.top = 0
}
}
}
class ItemOffsetDecoration(private val mItemOffset: Int) : ItemDecoration() {
override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView,
state: RecyclerView.State) {
super.getItemOffsets(outRect, view, parent, state)
outRect[mItemOffset, mItemOffset, mItemOffset] = mItemOffset
}
}

@ -20,6 +20,7 @@
android:id="@+id/recyclerView" android:id="@+id/recyclerView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="4dp"
app:layout_constraintTop_toBottomOf="@id/title" app:layout_constraintTop_toBottomOf="@id/title"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"

Loading…
Cancel
Save