From b91712ea9ed4fa30d8796b9a11fa61de0b9ae362 Mon Sep 17 00:00:00 2001 From: Sergio De la torre Date: Thu, 28 Mar 2024 08:54:35 +0100 Subject: [PATCH] refs #6574 feat:ui --- .../adapter/HistoricoAdapter.kt | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/historicoarticulo/adapter/HistoricoAdapter.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/historicoarticulo/adapter/HistoricoAdapter.kt index f90023eb..1de0d8d9 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/historicoarticulo/adapter/HistoricoAdapter.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/historicoarticulo/adapter/HistoricoAdapter.kt @@ -10,18 +10,17 @@ import es.verdnatura.presentation.view.feature.historicoarticulo.model.ItemHisto import java.text.SimpleDateFormat import java.util.Date -class HistoricoAdapter ( +class HistoricoAdapter( private val items: List -): RecyclerView.Adapter () { - +) : RecyclerView.Adapter() { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): 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) { holder.bind(items[position]) @@ -29,7 +28,7 @@ class HistoricoAdapter ( inner class ItemHolder( val binding: ItemHistoricoRowBinding - ) : RecyclerView.ViewHolder(binding.root){ + ) : RecyclerView.ViewHolder(binding.root) { private val res = binding.root.context.resources fun bind(item: ItemHistoricoVO) { binding.apply { @@ -38,14 +37,22 @@ class HistoricoAdapter ( val sdf = SimpleDateFormat(res.getString(R.string.dateFormat)) val currentDate = sdf.format(Date()) - historicoDate.setBackgroundColor(ContextCompat.getColor(historicoDate.context, if (currentDate == item.shipped){R.color.verdnatura_pumpkin_orange}else{ - R.color.verdnatura_black_5 - })) + historicoDate.setBackgroundColor( + ContextCompat.getColor( + historicoDate.context, if (currentDate == item.shipped) { + R.color.verdnatura_pumpkin_orange + } else { + R.color.verdnatura_black_5 + } + ) + ) - item?.invalue?.let { - inQuantity.setBackgroundColor(ContextCompat.getColor(historicoDate.context, - if (it > 0) R.color.verdnatura_dark_green_verdnatura else R.color.verdnatura_white)) + val color = if (item.invalue != null && item.invalue!! > 0) { + R.color.verdnatura_dark_green_verdnatura + } else { + R.color.verdnatura_black_5 } + inQuantity.setBackgroundColor(ContextCompat.getColor(historicoDate.context, color)) } }