From f8efe73da78ec04bb460fd9e5853ee1b33998d82 Mon Sep 17 00:00:00 2001 From: Sergio De la torre Date: Tue, 28 Mar 2023 08:26:39 +0200 Subject: [PATCH] refs #4940 packingHolland --- .../es/verdnatura/domain/VerdnaturaService.kt | 6 + .../fragment/PackingHollandFragment.kt | 143 ++++++++++++++++++ .../fragment/PackingHollandViewModel.kt | 43 ++++++ 3 files changed, 192 insertions(+) create mode 100644 app/src/main/java/es/verdnatura/presentation/view/feature/packingHolland/fragment/PackingHollandFragment.kt create mode 100644 app/src/main/java/es/verdnatura/presentation/view/feature/packingHolland/fragment/PackingHollandViewModel.kt diff --git a/app/src/main/java/es/verdnatura/domain/VerdnaturaService.kt b/app/src/main/java/es/verdnatura/domain/VerdnaturaService.kt index fc06fdfb..eee45132 100644 --- a/app/src/main/java/es/verdnatura/domain/VerdnaturaService.kt +++ b/app/src/main/java/es/verdnatura/domain/VerdnaturaService.kt @@ -639,6 +639,12 @@ interface VerdnaturaService { ): Call + @POST("almacennew/travel_updatePacking")//REVISADA + fun travel_updatePacking( + @Body vararg params: Any + ): + Call + @POST("almacennew/itemShelvingDelete")//REVISADA fun itemShelvingDelete( @Body vararg params: Any diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/packingHolland/fragment/PackingHollandFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/packingHolland/fragment/PackingHollandFragment.kt new file mode 100644 index 00000000..afeba179 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/packingHolland/fragment/PackingHollandFragment.kt @@ -0,0 +1,143 @@ +package es.verdnatura.presentation.view.feature.packingHolland.fragment + +import android.view.View.GONE +import android.view.View.VISIBLE +import android.view.inputmethod.EditorInfo +import es.verdnatura.R +import es.verdnatura.databinding.FragmentGeneralBlackBinding +import es.verdnatura.domain.toast +import es.verdnatura.presentation.base.BaseFragment +import es.verdnatura.presentation.common.itemScanValue +import es.verdnatura.presentation.view.component.CustomDialogInput + +//Tarea #4940 +class PackingHollandFragment(var entrypoint: String) : + BaseFragment( + PackingHollandViewModel::class + ) { + + override fun getLayoutId(): Int = R.layout.fragment_general_black + private var shelvingScaned: Int = 0 + private lateinit var customDialogInput: CustomDialogInput + + companion object { + fun newInstance(entrypoint: String) = PackingHollandFragment(entrypoint = entrypoint) + } + + override fun init() { + + customDialogInput = CustomDialogInput(requireContext()) + binding.mainToolbar.toolbarTitle.text = entrypoint + binding.splashProgress.visibility = GONE + binding.scanInput.visibility = VISIBLE + setEvents() + + super.init() + } + + private fun setEvents() { + + binding.mainToolbar.backButton.setOnClickListener { + requireActivity().onBackPressed() + } + + binding.scanInput.requestFocus() + binding.scanInput.setOnEditorActionListener { _, actionId, _ -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { + if (!binding.scanInput.text.isNullOrEmpty()) { + binding.splashProgress.visibility = VISIBLE + try { + + binding.scanInput.setText( + itemScanValue( + binding.scanInput.text.toString(), + "buy", + "more" + ).toString() + ) + shelvingScaned = binding.scanInput.text.toString().toInt() + + } catch (ex: Exception) { + ex.message!!.toast(requireActivity()) + } + + } + + binding.scanInput.setText("") + ma.hideKeyboard(binding.scanInput) + return@setOnEditorActionListener true + } + false + } + } + + override fun observeViewModel() { + with(viewModel) { + response.observe(viewLifecycleOwner) { + binding.splashProgress.visibility = GONE + if (it.isError) { + ma.messageWithSound(it.errorMessage, true, false) + } else { + showQuantityPacking() + } + + } + + } + } + + + private fun showQuantityPacking() { + + customDialogInput.setInputText() + customDialogInput.setTitle(getString(R.string.titlePackingHolland)) + customDialogInput.setDescription(getString(R.string.packingQuantity) + shelvingScaned) + .setValue("") + .setOkButton(getString(R.string.modify)) { + + if (customDialogInput.getValue().isNotEmpty() + ) { + callPacking(customDialogInput.getValue()) + } + + + }.setKoButton(getString(R.string.cancel)) { + customDialogInput.dismiss() + }.show() + customDialogInput.setFocusText() + + + customDialogInput.setFocusText() + ma.hideKeyboard(customDialogInput.getEditText()) + + customDialogInput.getEditText().setOnEditorActionListener { _, actionId, _ -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5 || actionId == 6) { + + if (customDialogInput.getValue().isNotEmpty()) { + callPacking(customDialogInput.getValue()) + } + + return@setOnEditorActionListener true + } + false + } + + + } + + private fun callPacking(value: String) { + try { + binding.splashProgress.visibility = VISIBLE + viewModel.travel_updatePacking( + itemFk = shelvingScaned, + packingFk = value.toInt() + ) + + } catch (ex: Exception) { + getString(R.string.errorInput).toast(requireActivity()) + } + customDialogInput.setValue("") + } +} + + diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/packingHolland/fragment/PackingHollandViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/packingHolland/fragment/PackingHollandViewModel.kt new file mode 100644 index 00000000..9bb6e733 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/packingHolland/fragment/PackingHollandViewModel.kt @@ -0,0 +1,43 @@ +package es.verdnatura.presentation.view.feature.packingHolland.fragment + + +import android.content.Context +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import es.verdnatura.domain.SilexCallback +import es.verdnatura.presentation.base.BaseViewModel +import es.verdnatura.presentation.base.getMessageFromAllResponse +import es.verdnatura.presentation.base.nameofFunction +import es.verdnatura.presentation.common.ResponseItemVO +import retrofit2.Response + +class PackingHollandViewModel(val context: Context) : BaseViewModel(context) { + + private val _response by lazy { MutableLiveData() } + val response: LiveData + get() = _response + + + fun travel_updatePacking( + itemFk: Int, + packingFk: Int + ) { + silex.travel_updatePacking(itemFk, packingFk) + .enqueue(object : SilexCallback(context) { + override fun onError(t: Throwable) { + _response.value = ResponseItemVO( + isError = true, + errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!) + ) + } + + override fun onSuccess(response: Response) { + _response.value = + ResponseItemVO(isError = false, response = response.message()!!) + } + + }) + } + + +}