diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/adapter/AutomaticAdapterTEST.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/adapter/AutomaticAdapterTEST.kt new file mode 100644 index 00000000..25bf7054 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/adapter/AutomaticAdapterTEST.kt @@ -0,0 +1,43 @@ +package es.verdnatura.presentation.view.feature.ubicador.adapter + +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import es.verdnatura.databinding.ItemEscanerRowBinding +import es.verdnatura.presentation.common.OnAutomaticItemClickListener +import es.verdnatura.presentation.view.feature.ubicador.model.ItemEscanerVO + +class AutomaticAdapterTEST ( + private val items: List, + private val onAutomaticItemClickListener: OnAutomaticItemClickListener +): RecyclerView.Adapter () { + + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder { + return ItemHolder( + ItemEscanerRowBinding.inflate(LayoutInflater.from(parent.context),parent,false) + ) + } + + override fun getItemCount() =items.size + + override fun onBindViewHolder(holder: ItemHolder, position: Int) { + holder.bind(items[position]) + holder.binding.root.setOnClickListener { + onAutomaticItemClickListener.onAutomaticItemClickListener(position) + } + } + + inner class ItemHolder( + val binding: ItemEscanerRowBinding + ) : RecyclerView.ViewHolder(binding.root){ + private val res = binding.root.context.resources + fun bind(item: Long) { + binding.itemfkText.text = item.toString() + + /* binding.apply { + this.item = item + }*/ + } + } +} \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/AutomaticAddItemFragmentTEST.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/AutomaticAddItemFragmentTEST.kt new file mode 100644 index 00000000..4b00712b --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/AutomaticAddItemFragmentTEST.kt @@ -0,0 +1,156 @@ +package es.verdnatura.presentation.view.feature.ubicador.fragment + +import android.view.KeyEvent +import android.view.View +import android.view.inputmethod.EditorInfo +import androidx.lifecycle.Observer +import androidx.recyclerview.widget.LinearLayoutManager +import es.verdnatura.R +import es.verdnatura.databinding.FragmentAutomaticAddItemBinding +import es.verdnatura.presentation.base.BaseFragment +import es.verdnatura.presentation.common.OnAutomaticItemClickListener +import es.verdnatura.presentation.common.itemScanValue +import es.verdnatura.presentation.view.feature.ubicador.adapter.AutomaticAdapter +import es.verdnatura.presentation.view.feature.ubicador.adapter.AutomaticAdapterTEST +import es.verdnatura.presentation.view.feature.ubicador.model.ItemEscanerVO +import java.lang.Boolean.TRUE + + +@Suppress("UNUSED_ANONYMOUS_PARAMETER") +class AutomaticAddItemFragmentTEST( + var shelvingFk: String = "", + var titleAction: String? = null +) : BaseFragment( + AutomaticAddItemViewModel::class +) { + + private var adapter: AutomaticAdapterTEST? = null + private var listItems: ArrayList = ArrayList() + private var contador = 0 + + companion object { + fun newInstance(entryPoint: String, titleAction: String) = + AutomaticAddItemFragmentTEST(entryPoint, titleAction) + } + + override fun getLayoutId(): Int = R.layout.fragment_automatic_add_item + + override fun init() { + ma.hideBottomNavigation(View.GONE) + binding.mainToolbar.toolbarTitle.text = titleAction + setEvents() + setViews() + setToolBar() + super.init() + } + + private fun setToolBar() { + binding.mainToolbar.toolbarSubtitle.visibility = View.VISIBLE + } + + private fun setSubtitle() { + binding.mainToolbar.toolbarSubtitle.text = getString(R.string.labels) + contador + } + + private fun setViews() { + adapter = AutomaticAdapterTEST(listItems, object : OnAutomaticItemClickListener { + override fun onAutomaticItemClickListener(position: Int) { + contador -= 1 + setSubtitle() + if (listItems.size > position) { + listItems.removeAt(position) + } + + adapter!!.notifyDataSetChanged() + } + }) + binding.itemsRecyclerview.adapter = adapter + binding.itemsRecyclerview.layoutManager = + LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) + } + + private fun setEvents() { + binding.editMatricula.requestFocus() + binding.editMatricula.setOnEditorActionListener { v, actionId, event -> + + if (actionId == 0 || actionId == 5 || actionId == 6 ) { + var l1= System.currentTimeMillis() + if (!binding.editMatricula.text.toString().isNullOrEmpty()) { + try { + listItems.add( + 0, + itemScanValue( + textScanned_filterDouble(binding.editMatricula.text.toString()), + "buy", + "more" + ).toString().toLong() + + ) + + + contador += 1 + setSubtitle() + adapter!!.notifyItemInserted(0) + } catch (ex: Exception) { + ma.messageWithSound(ex.message.toString(), true, true) + } + } + var l2=System.currentTimeMillis() + println("Lectura diferencia:${l2-l1}") + binding.editMatricula.setText("") + ma.hideKeyboard(binding.editMatricula) + return@setOnEditorActionListener true + }else{ + ma.messageWithSound("ACTION ID DIFERENTE", true, true) + + } + + return@setOnEditorActionListener false + } + + binding.buttonFinalizar.setOnClickListener { + val listString: ArrayList = ArrayList() + val listInt: ArrayList = ArrayList() + listItems.forEach { + listString.add(it) + listInt.add(it) + } + binding.splashProgress.visibility = View.VISIBLE + + if (binding.mainToolbar.toolbarTitle.text.equals(getString(R.string.titleChecker))) { + + viewModel.itemShelving_addList( + shelvingFk, + "" + listInt + "", + TRUE, + getDataInt(WAREHOUSEFK) + ) + } else { + + viewModel.itemShelvingMake_multi( + shelvingFk, + listString, + getDataInt(WAREHOUSEFK) + ) + } + } + + binding.mainToolbar.backButton.setOnClickListener { + requireActivity().onBackPressed() + } + } + + override fun observeViewModel() { + with(viewModel) { + response.observe(viewLifecycleOwner, Observer { + binding.splashProgress.visibility = View.GONE + if (it.isError) { + ma.messageWithSound(it.errorMessage, true, false) + } else { + requireActivity().onBackPressed() + } + }) + } + } + +}