refs #4940 packingHolland

This commit is contained in:
Sergio De la torre 2023-03-28 08:26:39 +02:00
parent 4c63845dca
commit f8efe73da7
3 changed files with 192 additions and 0 deletions

View File

@ -639,6 +639,12 @@ interface VerdnaturaService {
): ):
Call<Any> Call<Any>
@POST("almacennew/travel_updatePacking")//REVISADA
fun travel_updatePacking(
@Body vararg params: Any
):
Call<Any>
@POST("almacennew/itemShelvingDelete")//REVISADA @POST("almacennew/itemShelvingDelete")//REVISADA
fun itemShelvingDelete( fun itemShelvingDelete(
@Body vararg params: Any @Body vararg params: Any

View File

@ -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<FragmentGeneralBlackBinding, PackingHollandViewModel>(
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("")
}
}

View File

@ -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<ResponseItemVO>() }
val response: LiveData<ResponseItemVO>
get() = _response
fun travel_updatePacking(
itemFk: Int,
packingFk: Int
) {
silex.travel_updatePacking(itemFk, packingFk)
.enqueue(object : SilexCallback<Any>(context) {
override fun onError(t: Throwable) {
_response.value = ResponseItemVO(
isError = true,
errorMessage = getMessageFromAllResponse(nameofFunction(this), t.message!!)
)
}
override fun onSuccess(response: Response<Any>) {
_response.value =
ResponseItemVO(isError = false, response = response.message()!!)
}
})
}
}