refs #6574 feat:ui

This commit is contained in:
Sergio De la torre 2024-03-28 08:54:35 +01:00
parent ea305d5812
commit b91712ea9e
1 changed files with 19 additions and 12 deletions

View File

@ -10,18 +10,17 @@ import es.verdnatura.presentation.view.feature.historicoarticulo.model.ItemHisto
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.Date import java.util.Date
class HistoricoAdapter ( class HistoricoAdapter(
private val items: List<ItemHistoricoVO> private val items: List<ItemHistoricoVO>
): RecyclerView.Adapter<HistoricoAdapter.ItemHolder> () { ) : RecyclerView.Adapter<HistoricoAdapter.ItemHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder {
return ItemHolder( return ItemHolder(
ItemHistoricoRowBinding.inflate(LayoutInflater.from(parent.context),parent,false) ItemHistoricoRowBinding.inflate(LayoutInflater.from(parent.context), parent, false)
) )
} }
override fun getItemCount() =items.size override fun getItemCount() = items.size
override fun onBindViewHolder(holder: ItemHolder, position: Int) { override fun onBindViewHolder(holder: ItemHolder, position: Int) {
holder.bind(items[position]) holder.bind(items[position])
@ -29,7 +28,7 @@ class HistoricoAdapter (
inner class ItemHolder( inner class ItemHolder(
val binding: ItemHistoricoRowBinding val binding: ItemHistoricoRowBinding
) : RecyclerView.ViewHolder(binding.root){ ) : RecyclerView.ViewHolder(binding.root) {
private val res = binding.root.context.resources private val res = binding.root.context.resources
fun bind(item: ItemHistoricoVO) { fun bind(item: ItemHistoricoVO) {
binding.apply { binding.apply {
@ -38,14 +37,22 @@ class HistoricoAdapter (
val sdf = SimpleDateFormat(res.getString(R.string.dateFormat)) val sdf = SimpleDateFormat(res.getString(R.string.dateFormat))
val currentDate = sdf.format(Date()) val currentDate = sdf.format(Date())
historicoDate.setBackgroundColor(ContextCompat.getColor(historicoDate.context, if (currentDate == item.shipped){R.color.verdnatura_pumpkin_orange}else{ historicoDate.setBackgroundColor(
R.color.verdnatura_black_5 ContextCompat.getColor(
})) historicoDate.context, if (currentDate == item.shipped) {
R.color.verdnatura_pumpkin_orange
} else {
R.color.verdnatura_black_5
}
)
)
item?.invalue?.let { val color = if (item.invalue != null && item.invalue!! > 0) {
inQuantity.setBackgroundColor(ContextCompat.getColor(historicoDate.context, R.color.verdnatura_dark_green_verdnatura
if (it > 0) R.color.verdnatura_dark_green_verdnatura else R.color.verdnatura_white)) } else {
R.color.verdnatura_black_5
} }
inQuantity.setBackgroundColor(ContextCompat.getColor(historicoDate.context, color))
} }
} }