From eed96ea4eba5273b06a28b22ae2bb13c10fb27fd Mon Sep 17 00:00:00 2001 From: Sergio De la torre Date: Fri, 15 Sep 2023 11:10:10 +0200 Subject: [PATCH] refs #5764 modify dayOfSale --- .../diadeventa/adapter/DayOfSaleAdapter.kt | 89 +++++++++++-------- .../diadeventa/fragment/DayOfSaleFragment.kt | 57 ++++++------ 2 files changed, 82 insertions(+), 64 deletions(-) diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/diadeventa/adapter/DayOfSaleAdapter.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/diadeventa/adapter/DayOfSaleAdapter.kt index a7c94999..1b8ab623 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/diadeventa/adapter/DayOfSaleAdapter.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/diadeventa/adapter/DayOfSaleAdapter.kt @@ -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, - private val onPasillerosItemClickListener: OnPasillerosItemClickListener - ): RecyclerView.Adapter() { +class DayOfSaleAdapter( + private val items: List, + private val onPasillerosItemClickListener: OnPasillerosItemClickListener? +) : RecyclerView.Adapter() { - 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 + ) + } + } } } +} diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/diadeventa/fragment/DayOfSaleFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/diadeventa/fragment/DayOfSaleFragment.kt index c254a29a..2b8eeea7 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/diadeventa/fragment/DayOfSaleFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/diadeventa/fragment/DayOfSaleFragment.kt @@ -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) {