元素adapter
This commit is contained in:
parent
ce0d5084ba
commit
2dc819f916
|
|
@ -7,7 +7,9 @@ import androidx.activity.viewModels
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.lifecycle.repeatOnLifecycle
|
import androidx.lifecycle.repeatOnLifecycle
|
||||||
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
import com.ama.core.architecture.appBase.AppViewsEmptyViewModelActivity
|
import com.ama.core.architecture.appBase.AppViewsEmptyViewModelActivity
|
||||||
|
import com.ama.core.architecture.util.CommonItemDecoration
|
||||||
import com.ama.core.architecture.util.setOnClickBatch
|
import com.ama.core.architecture.util.setOnClickBatch
|
||||||
import com.gamedog.vididin.R
|
import com.gamedog.vididin.R
|
||||||
import com.gamedog.vididin.beans.ZeroBuyResp
|
import com.gamedog.vididin.beans.ZeroBuyResp
|
||||||
|
|
@ -24,6 +26,9 @@ import com.gamedog.vididin.databinding.ActivityZerobuyBinding as ViewBinding
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class ZeroBuyActivity : AppViewsEmptyViewModelActivity<ViewBinding>() {
|
class ZeroBuyActivity : AppViewsEmptyViewModelActivity<ViewBinding>() {
|
||||||
private val viewModel: ZeroBuyViewModel by viewModels()
|
private val viewModel: ZeroBuyViewModel by viewModels()
|
||||||
|
private lateinit var mAdapter: ZeroItemAdapter
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
override fun inflateViewBinding(inflater: LayoutInflater) = ViewBinding.inflate(inflater)
|
override fun inflateViewBinding(inflater: LayoutInflater) = ViewBinding.inflate(inflater)
|
||||||
|
|
||||||
|
|
@ -46,6 +51,16 @@ class ZeroBuyActivity : AppViewsEmptyViewModelActivity<ViewBinding>() {
|
||||||
titlebar.addRightIcon(R.mipmap.icon_question_mark, {
|
titlebar.addRightIcon(R.mipmap.icon_question_mark, {
|
||||||
showHintInfo()
|
showHintInfo()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
with(recyclerView) {
|
||||||
|
mAdapter = ZeroItemAdapter()
|
||||||
|
adapter = mAdapter
|
||||||
|
layoutManager = GridLayoutManager(this@ZeroBuyActivity, 2)
|
||||||
|
addItemDecoration(
|
||||||
|
CommonItemDecoration.create(horizontalSpace = 45, verticalSpace = 45)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -95,7 +110,7 @@ class ZeroBuyActivity : AppViewsEmptyViewModelActivity<ViewBinding>() {
|
||||||
|
|
||||||
|
|
||||||
private fun updateUIs(data: ZeroBuyResp) {
|
private fun updateUIs(data: ZeroBuyResp) {
|
||||||
|
mAdapter.submitList(data.mCurrentList)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
package com.gamedog.vididin.features.zero
|
||||||
|
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.recyclerview.widget.DiffUtil
|
||||||
|
import androidx.recyclerview.widget.ListAdapter
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import com.gamedog.vididin.beans.ZeroBuyItem
|
||||||
|
import com.gamedog.vididin.databinding.LayoutItemZerobuyBinding as ViewBinding
|
||||||
|
|
||||||
|
class ZeroItemAdapter : ListAdapter<ZeroBuyItem, ZeroItemAdapter.ViewHolder>(DiffCallback()) {
|
||||||
|
|
||||||
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||||
|
val binding = ViewBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
|
return ViewHolder(binding)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
|
holder.bind(getItem(position))
|
||||||
|
}
|
||||||
|
|
||||||
|
inner class ViewHolder(private val binding: ViewBinding) : RecyclerView.ViewHolder(binding.root) {
|
||||||
|
fun bind(item: ZeroBuyItem) {
|
||||||
|
/*binding.tvDate.text = transaction.dateTime
|
||||||
|
binding.tvTitle.text = transaction.statusText
|
||||||
|
binding.tvDescription.text = transaction.description
|
||||||
|
binding.tvAmount.text = transaction.amount
|
||||||
|
binding.tvAmount.setTextColor(ContextCompat.getColor(binding.root.context, transaction.amountColor))
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class DiffCallback : DiffUtil.ItemCallback<ZeroBuyItem>() {
|
||||||
|
override fun areItemsTheSame(oldItem: ZeroBuyItem, newItem: ZeroBuyItem): Boolean {
|
||||||
|
return oldItem.id == newItem.id
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun areContentsTheSame(oldItem: ZeroBuyItem, newItem: ZeroBuyItem): Boolean {
|
||||||
|
return oldItem == newItem
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -89,138 +89,12 @@
|
||||||
>
|
>
|
||||||
|
|
||||||
<!--第一行两个-->
|
<!--第一行两个-->
|
||||||
<LinearLayout
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/recycler_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginHorizontal="15dp"
|
|
||||||
android:orientation="horizontal">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:gravity="center_horizontal"
|
|
||||||
android:background="@mipmap/zero_bg_item">
|
|
||||||
<androidx.appcompat.widget.AppCompatTextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="4.5dp"
|
|
||||||
android:textColor="@color/red_1b"
|
|
||||||
android:textSize="15sp"
|
|
||||||
android:text="@string/zero_buy_title"
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<FrameLayout
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="7.5dp">
|
|
||||||
<androidx.appcompat.widget.AppCompatImageView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:src="@mipmap/zero_bg_item_sub1"
|
|
||||||
/>
|
|
||||||
</FrameLayout>
|
|
||||||
|
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatTextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="4.5dp"
|
|
||||||
android:textColor="@color/gray9"
|
|
||||||
android:textSize="10sp"
|
|
||||||
android:text="@string/sorte"
|
|
||||||
/>
|
|
||||||
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="0.5dp"
|
|
||||||
android:orientation="horizontal">
|
|
||||||
<androidx.appcompat.widget.AppCompatTextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="4.5dp"
|
|
||||||
android:textColor="@color/red_28"
|
|
||||||
android:textSize="13sp"
|
|
||||||
android:textStyle="bold"
|
|
||||||
android:text="0"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatTextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="4.5dp"
|
|
||||||
android:textColor="@color/gray3"
|
|
||||||
android:textSize="13sp"
|
|
||||||
android:textStyle="bold"
|
|
||||||
android:text="/10"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatTextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="4.5dp"
|
|
||||||
android:textColor="@color/gray3"
|
|
||||||
android:layout_marginStart="5dp"
|
|
||||||
android:textSize="13sp"
|
|
||||||
android:text="@string/pessoas"
|
|
||||||
/>
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<FrameLayout
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="5dp">
|
|
||||||
<androidx.appcompat.widget.AppCompatImageView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:src="@mipmap/zero_bg_but"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:gravity="center"
|
|
||||||
android:layout_gravity="center_horizontal">
|
|
||||||
<androidx.appcompat.widget.AppCompatTextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textColor="@color/white"
|
|
||||||
android:layout_marginStart="5dp"
|
|
||||||
android:textSize="14sp"
|
|
||||||
android:text="@string/participar"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<androidx.appcompat.widget.AppCompatTextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:textColor="@color/white"
|
|
||||||
android:layout_marginStart="5dp"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:textSize="10sp"
|
|
||||||
android:text="0"
|
|
||||||
android:drawableStart="@mipmap/icon_gold_ss"
|
|
||||||
android:drawablePadding="3dp"
|
|
||||||
/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
</FrameLayout>
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_marginLeft="15dp"
|
|
||||||
android:background="@mipmap/zero_bg_item">
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<!--参加者-->
|
<!--参加者-->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,118 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:background="@mipmap/zero_bg_item">
|
||||||
|
<androidx.appcompat.widget.AppCompatTextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="4.5dp"
|
||||||
|
android:textColor="@color/red_1b"
|
||||||
|
android:textSize="15sp"
|
||||||
|
android:text="@string/zero_buy_title"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="7.5dp">
|
||||||
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:src="@mipmap/zero_bg_item_sub1"
|
||||||
|
/>
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatTextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="4.5dp"
|
||||||
|
android:textColor="@color/gray9"
|
||||||
|
android:textSize="10sp"
|
||||||
|
android:text="@string/sorte"
|
||||||
|
/>
|
||||||
|
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="0.5dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
<androidx.appcompat.widget.AppCompatTextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="4.5dp"
|
||||||
|
android:textColor="@color/red_28"
|
||||||
|
android:textSize="13sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:text="0"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatTextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="4.5dp"
|
||||||
|
android:textColor="@color/gray3"
|
||||||
|
android:textSize="13sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:text="/10"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatTextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="4.5dp"
|
||||||
|
android:textColor="@color/gray3"
|
||||||
|
android:layout_marginStart="5dp"
|
||||||
|
android:textSize="13sp"
|
||||||
|
android:text="@string/pessoas"
|
||||||
|
/>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="5dp">
|
||||||
|
<androidx.appcompat.widget.AppCompatImageView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:src="@mipmap/zero_bg_but"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:gravity="center"
|
||||||
|
android:layout_gravity="center_horizontal">
|
||||||
|
<androidx.appcompat.widget.AppCompatTextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:layout_marginStart="5dp"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:text="@string/participar"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatTextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:layout_marginStart="5dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:textSize="10sp"
|
||||||
|
android:text="0"
|
||||||
|
android:drawableStart="@mipmap/icon_gold_ss"
|
||||||
|
android:drawablePadding="3dp"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
</FrameLayout>
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -0,0 +1,171 @@
|
||||||
|
package com.ama.core.architecture.util
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.graphics.Rect
|
||||||
|
import android.view.View
|
||||||
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import androidx.recyclerview.widget.StaggeredGridLayoutManager
|
||||||
|
|
||||||
|
class CommonItemDecoration private constructor(
|
||||||
|
private val horizontalSpace: Int,
|
||||||
|
private val verticalSpace: Int,
|
||||||
|
private val includeEdge: Boolean
|
||||||
|
) : RecyclerView.ItemDecoration() {
|
||||||
|
|
||||||
|
override fun getItemOffsets(
|
||||||
|
outRect: Rect,
|
||||||
|
view: View,
|
||||||
|
parent: RecyclerView,
|
||||||
|
state: RecyclerView.State
|
||||||
|
) {
|
||||||
|
super.getItemOffsets(outRect, view, parent, state)
|
||||||
|
|
||||||
|
val position = parent.getChildAdapterPosition(view)
|
||||||
|
val adapter = parent.adapter ?: return
|
||||||
|
val itemCount = adapter.itemCount
|
||||||
|
|
||||||
|
when (val layoutManager = parent.layoutManager) {
|
||||||
|
is GridLayoutManager -> {
|
||||||
|
handleGridLayout(outRect, position, itemCount, layoutManager)
|
||||||
|
}
|
||||||
|
is LinearLayoutManager -> {
|
||||||
|
handleLinearLayout(outRect, position, itemCount, layoutManager)
|
||||||
|
}
|
||||||
|
is StaggeredGridLayoutManager -> {
|
||||||
|
handleStaggeredGridLayout(outRect, position, itemCount, layoutManager)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handleGridLayout(
|
||||||
|
outRect: Rect,
|
||||||
|
position: Int,
|
||||||
|
itemCount: Int,
|
||||||
|
layoutManager: GridLayoutManager
|
||||||
|
) {
|
||||||
|
val spanCount = layoutManager.spanCount
|
||||||
|
val orientation = layoutManager.orientation
|
||||||
|
|
||||||
|
if (orientation == GridLayoutManager.VERTICAL) {
|
||||||
|
// 垂直网格布局
|
||||||
|
val column = position % spanCount
|
||||||
|
|
||||||
|
if (includeEdge) {
|
||||||
|
outRect.left = horizontalSpace * (spanCount - column) / spanCount
|
||||||
|
outRect.right = horizontalSpace * (column + 1) / spanCount
|
||||||
|
|
||||||
|
if (position < spanCount) {
|
||||||
|
outRect.top = verticalSpace
|
||||||
|
}
|
||||||
|
outRect.bottom = verticalSpace
|
||||||
|
} else {
|
||||||
|
outRect.left = horizontalSpace * column / spanCount
|
||||||
|
outRect.right = horizontalSpace * (spanCount - 1 - column) / spanCount
|
||||||
|
|
||||||
|
if (position >= spanCount) {
|
||||||
|
outRect.top = verticalSpace
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 水平网格布局
|
||||||
|
val row = position % spanCount
|
||||||
|
|
||||||
|
if (includeEdge) {
|
||||||
|
outRect.top = verticalSpace * (spanCount - row) / spanCount
|
||||||
|
outRect.bottom = verticalSpace * (row + 1) / spanCount
|
||||||
|
|
||||||
|
if (position < spanCount) {
|
||||||
|
outRect.left = horizontalSpace
|
||||||
|
}
|
||||||
|
outRect.right = horizontalSpace
|
||||||
|
} else {
|
||||||
|
outRect.top = verticalSpace * row / spanCount
|
||||||
|
outRect.bottom = verticalSpace * (spanCount - 1 - row) / spanCount
|
||||||
|
|
||||||
|
if (position >= spanCount) {
|
||||||
|
outRect.left = horizontalSpace
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handleLinearLayout(
|
||||||
|
outRect: Rect,
|
||||||
|
position: Int,
|
||||||
|
itemCount: Int,
|
||||||
|
layoutManager: LinearLayoutManager
|
||||||
|
) {
|
||||||
|
when (layoutManager.orientation) {
|
||||||
|
LinearLayoutManager.VERTICAL -> {
|
||||||
|
// 垂直线性布局
|
||||||
|
outRect.left = horizontalSpace
|
||||||
|
outRect.right = horizontalSpace
|
||||||
|
|
||||||
|
if (position == 0 && includeEdge) {
|
||||||
|
outRect.top = verticalSpace
|
||||||
|
}
|
||||||
|
|
||||||
|
if (includeEdge) {
|
||||||
|
outRect.bottom = verticalSpace
|
||||||
|
} else {
|
||||||
|
outRect.bottom = if (position == itemCount - 1) 0 else verticalSpace
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LinearLayoutManager.HORIZONTAL -> {
|
||||||
|
// 水平线性布局
|
||||||
|
outRect.top = verticalSpace
|
||||||
|
outRect.bottom = verticalSpace
|
||||||
|
|
||||||
|
if (position == 0 && includeEdge) {
|
||||||
|
outRect.left = horizontalSpace
|
||||||
|
}
|
||||||
|
|
||||||
|
if (includeEdge) {
|
||||||
|
outRect.right = horizontalSpace
|
||||||
|
} else {
|
||||||
|
outRect.right = if (position == itemCount - 1) 0 else horizontalSpace
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handleStaggeredGridLayout(
|
||||||
|
outRect: Rect,
|
||||||
|
position: Int,
|
||||||
|
itemCount: Int,
|
||||||
|
layoutManager: StaggeredGridLayoutManager
|
||||||
|
) {
|
||||||
|
outRect.left = horizontalSpace / 2
|
||||||
|
outRect.right = horizontalSpace / 2
|
||||||
|
outRect.top = verticalSpace / 2
|
||||||
|
outRect.bottom = verticalSpace / 2
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun create(
|
||||||
|
horizontalSpace: Int,
|
||||||
|
verticalSpace: Int,
|
||||||
|
includeEdge: Boolean = true
|
||||||
|
): CommonItemDecoration {
|
||||||
|
return CommonItemDecoration(horizontalSpace, verticalSpace, includeEdge)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun createFromDp(
|
||||||
|
horizontalSpaceDp: Int,
|
||||||
|
verticalSpaceDp: Int,
|
||||||
|
context: Context,
|
||||||
|
includeEdge: Boolean = true
|
||||||
|
): CommonItemDecoration {
|
||||||
|
val horizontalSpacePx = dpToPx(horizontalSpaceDp, context)
|
||||||
|
val verticalSpacePx = dpToPx(verticalSpaceDp, context)
|
||||||
|
return CommonItemDecoration(horizontalSpacePx, verticalSpacePx, includeEdge)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun dpToPx(dp: Int, context: Context): Int {
|
||||||
|
val density = context.resources.displayMetrics.density
|
||||||
|
return (dp * density + 0.5f).toInt()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue