refs #5764 modify dayOfSale

This commit is contained in:
Sergio De la torre 2023-09-15 11:10:10 +02:00
parent cfe7a23ccd
commit eed96ea4eb
2 changed files with 82 additions and 64 deletions

View File

@ -10,50 +10,65 @@ import es.verdnatura.presentation.common.OnPasillerosItemClickListener
import es.verdnatura.presentation.view.feature.diadeventa.model.ItemShelvingSaleDate
import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO
import java.text.SimpleDateFormat
import java.util.*
import java.util.Date
class DayOfSaleAdapter (
private val items: List<ItemShelvingSaleDate>,
private val onPasillerosItemClickListener: OnPasillerosItemClickListener
): RecyclerView.Adapter<DayOfSaleAdapter.ItemHolder>() {
class DayOfSaleAdapter(
private val items: List<ItemShelvingSaleDate>,
private val onPasillerosItemClickListener: OnPasillerosItemClickListener?
) : RecyclerView.Adapter<DayOfSaleAdapter.ItemHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder {
return ItemHolder(
ItemShelvingdayofsaleRowBinding.inflate(LayoutInflater.from(parent.context),parent,false)
)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder {
return ItemHolder(
ItemShelvingdayofsaleRowBinding.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])
}
override fun onBindViewHolder(holder: ItemHolder, position: Int) {
holder.bind(items[position])
}
inner class ItemHolder(
val binding: ItemShelvingdayofsaleRowBinding
) : RecyclerView.ViewHolder(binding.root){
private val res = binding.root.context.resources
fun bind(item: ItemShelvingSaleDate) {
binding.apply {
this.item = item
val sdf = SimpleDateFormat(res.getString(R.string.dateFormat))
val currentDate = sdf.format(Date())
if (currentDate == item.dated){
saledate.setBackgroundColor(
ContextCompat.getColor(historicoDate.context,
R.color.verdnatura_pumpkin_orange))
}else{
saledate.setBackgroundColor(
ContextCompat.getColor(historicoDate.context,
R.color.verdnatura_black_5))
}
historicoDate.setOnClickListener {
onPasillerosItemClickListener.onPasillerosItemClickListener(
PasillerosItemVO(title = res.getString(
R.string.titleItemSearch)),item.itemFk.toString())
}
inner class ItemHolder(
val binding: ItemShelvingdayofsaleRowBinding
) : RecyclerView.ViewHolder(binding.root) {
private val res = binding.root.context.resources
fun bind(item: ItemShelvingSaleDate) {
binding.apply {
this.item = item
val sdf = SimpleDateFormat(res.getString(R.string.dateFormat))
val currentDate = sdf.format(Date())
if (currentDate == item.dated) {
saledate.setBackgroundColor(
ContextCompat.getColor(
historicoDate.context,
R.color.verdnatura_pumpkin_orange
)
)
} else {
saledate.setBackgroundColor(
ContextCompat.getColor(
historicoDate.context,
R.color.verdnatura_black_5
)
)
}
historicoDate.setOnClickListener {
onPasillerosItemClickListener!!.onPasillerosItemClickListener(
PasillerosItemVO(
title = res.getString(
R.string.titleItemConsult
)
), item.itemFk
)
}
}
}
}
}

View File

@ -1,5 +1,6 @@
package es.verdnatura.presentation.view.feature.diadeventa.fragment
import android.content.Context
import android.graphics.drawable.Drawable
import android.os.Build
import android.view.View
@ -9,7 +10,6 @@ import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import es.verdnatura.R
import es.verdnatura.databinding.FragmentItemdayofsaleCardBinding
import es.verdnatura.domain.notNull
import es.verdnatura.presentation.base.BaseFragment
import es.verdnatura.presentation.common.OnOptionsSelectedListener
import es.verdnatura.presentation.common.OnPasillerosItemClickListener
@ -34,6 +34,10 @@ class DayOfSaleFragment(
fun newInstance(entryPoint: String) = DayOfSaleFragment(entryPoint)
}
override fun onAttach(context: Context) {
if (context is OnPasillerosItemClickListener) pasillerosItemClickListener = context
super.onAttach(context)
}
override fun getLayoutId(): Int = R.layout.fragment_itemdayofsale_card
@ -110,37 +114,36 @@ class DayOfSaleFragment(
override fun observeViewModel() {
with(viewModel) {
loadItemShelvingSaleDateList.observe(viewLifecycleOwner, Observer { event ->
event.getContentIfNotHandled().notNull {
binding.splashProgress.visibility = View.GONE
adapter = DayOfSaleAdapter(
it.list,
onPasillerosItemClickListener = pasillerosItemClickListener!!
)
itemShelvingSaleDateList.observe(viewLifecycleOwner, Observer {
binding.splashProgress.visibility = View.GONE
adapter = DayOfSaleAdapter(
it.list,
onPasillerosItemClickListener = pasillerosItemClickListener!!
)
binding.itemexpeditionstateRecyclerview.adapter = adapter
binding.itemexpeditionstateRecyclerview.layoutManager =
LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
binding.itemexpeditionstateRecyclerview.adapter = adapter
binding.itemexpeditionstateRecyclerview.layoutManager =
LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
if (it.list.isEmpty()) {
customDialog.setTitle(getString(R.string.noResults))
.setDescription(getString(R.string.wagoonNoSaleToday))
.setOkButton(getString(R.string.close)) {
customDialog.dismiss()
}.show()
} else {
if (it.list.isEmpty()) {
customDialog.setTitle(getString(R.string.noResults))
.setDescription(getString(R.string.wagoonNoSaleToday))
.setOkButton(getString(R.string.close)) {
customDialog.dismiss()
}.show()
} else {
if (it.list.get(0).isError) {
ma.messageWithSound(
it.list.get(0).errorMessage,
it.list.get(0).isError,
isPlayed = false
)
}
if (it.list.get(0).isError) {
ma.messageWithSound(
it.list.get(0).errorMessage,
it.list.get(0).isError,
isPlayed = false
)
}
}
})
response.observe(viewLifecycleOwner, Observer {
if (it.isError) {