diff --git a/app/src/main/java/es/verdnatura/domain/GetUbicadorUserCase.kt b/app/src/main/java/es/verdnatura/domain/GetUbicadorUserCase.kt index a7d38b1d..91054c07 100644 --- a/app/src/main/java/es/verdnatura/domain/GetUbicadorUserCase.kt +++ b/app/src/main/java/es/verdnatura/domain/GetUbicadorUserCase.kt @@ -12,4 +12,19 @@ class GetUbicadorUserCase : RestClient() { return restClient!!.itemShelvingList("json","1",usuario,password,"application/json",params)!! } + + fun itemShelvingMake(usuario:String,password:String,shelving:String,item:String,deep:String,quantity:String,packing:String,warehouse:String,level:String) : Call { + val params:ArrayList = ArrayList(); + params.add(shelving) + params.add(item) + params.add(deep) + params.add(quantity) + params.add(packing) + params.add(warehouse) + params.add(level) + + return restClient!!.itemShelvingMake("json","1",usuario,password,"application/json",params)!! + } } + + diff --git a/app/src/main/java/es/verdnatura/domain/VerdnaturaService.kt b/app/src/main/java/es/verdnatura/domain/VerdnaturaService.kt index dafbef26..6046cdd8 100644 --- a/app/src/main/java/es/verdnatura/domain/VerdnaturaService.kt +++ b/app/src/main/java/es/verdnatura/domain/VerdnaturaService.kt @@ -171,5 +171,14 @@ interface VerdnaturaService { @Body params: List): Call> + @POST("almacenv2/itemShelvingMake") + fun itemShelvingMake(@Header("aplicacion") aplicacion: String, + @Header("version") version: String, + @Header("user") user: String, + @Header("pass") pass: String, + @Header("Content-Type") content_type: String, + @Body params: List): + Call + } \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/presentation/view/component/CustomDialogUbicador.kt b/app/src/main/java/es/verdnatura/presentation/view/component/CustomDialogUbicador.kt new file mode 100644 index 00000000..d878c07c --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/component/CustomDialogUbicador.kt @@ -0,0 +1,97 @@ +package es.verdnatura.presentation.view.component + +import android.app.Dialog +import android.content.Context +import android.view.View +import com.google.android.material.textfield.TextInputEditText +import es.verdnatura.R +import kotlinx.android.synthetic.main.component_custom_ubicador_dialog.* + +class CustomDialogUbicador (context: Context) : Dialog(context, R.style.DialogTheme) { + + init { + setContentView(R.layout.component_custom_ubicador_dialog) + } + + + fun setTitle(title: String): CustomDialogUbicador { + custom_dialog_title.visibility = View.VISIBLE + custom_dialog_title.text = title + return this + } + + + fun setItemValue(value : String) : CustomDialogUbicador{ + custom_dialog_item.setText(value) + custom_dialog_item.visibility = View.VISIBLE + return this + } + + fun getItemValue() : String{ + return custom_dialog_item.text.toString() + } + + fun getEditItem() : TextInputEditText { + return custom_dialog_item + } + + + fun setEtiquetaValue(value : String) : CustomDialogUbicador{ + custom_dialog_etiquetas.setText(value) + custom_dialog_etiquetas.visibility = View.VISIBLE + return this + } + + fun getEtiquetaValue() : String{ + return custom_dialog_etiquetas.text.toString() + } + + fun getEtiquetaItem() : TextInputEditText { + return custom_dialog_etiquetas + } + + + fun setPackingValue(value : String) : CustomDialogUbicador{ + custom_dialog_packing.setText(value) + custom_dialog_packing.visibility = View.VISIBLE + return this + } + + fun getPackingValue() : String{ + return custom_dialog_packing.text.toString() + } + + fun getPackingItem() : TextInputEditText { + return custom_dialog_packing + } + + fun setVisibleValue(value : String) : CustomDialogUbicador{ + custom_dialog_visible.setText(value) + custom_dialog_visible.visibility = View.VISIBLE + return this + } + + fun getVisibleValue() : String{ + return custom_dialog_visible.text.toString() + } + + fun getVisibleItem() : TextInputEditText { + return custom_dialog_visible + } + + + fun setOkButton(text: String, onButtonClicked: () -> Unit): CustomDialogUbicador { + custom_dialog_button_ok.visibility = View.VISIBLE + custom_dialog_button_ok.text = text + custom_dialog_button_ok.setOnClickListener { onButtonClicked() } + return this + } + + fun setKoButton(text: String, onButtonClicked: () -> Unit): CustomDialogUbicador { + custom_dialog_button_ko.visibility = View.VISIBLE + custom_dialog_button_ko.text = text + custom_dialog_button_ko.setOnClickListener { onButtonClicked() } + return this + } + +} \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorFragment.kt index 46686003..1e75d8ad 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorFragment.kt @@ -4,20 +4,24 @@ import android.content.SharedPreferences import android.graphics.drawable.Drawable import android.view.View import android.view.inputmethod.EditorInfo +import android.widget.Toast import androidx.lifecycle.Observer import androidx.recyclerview.widget.LinearLayoutManager import es.verdnatura.R import es.verdnatura.databinding.FragmentUbicadorBinding import es.verdnatura.domain.notNull +import es.verdnatura.domain.toast import es.verdnatura.presentation.base.BaseFragment import es.verdnatura.presentation.common.OnOptionsSelectedListener import es.verdnatura.presentation.view.component.CustomDialog import es.verdnatura.presentation.view.component.CustomDialogInput +import es.verdnatura.presentation.view.component.CustomDialogUbicador import es.verdnatura.presentation.view.feature.inventario.adapter.ToolBarAdapter import es.verdnatura.presentation.view.feature.inventario.model.ItemInventaryVO import es.verdnatura.presentation.view.feature.main.activity.MainActivity import es.verdnatura.presentation.view.feature.shelvingparking.adapter.ShelvingParkingAdapter import es.verdnatura.presentation.view.feature.ubicador.adapter.UbicadorAdapter +import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicadorVO import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.fragment_buscar_item.* @@ -37,9 +41,10 @@ class UbicadorFragment( private var warehouseFk = "" private var adapter : UbicadorAdapter? = null private lateinit var customDialogInput: CustomDialogInput - private var listInvetory:ArrayList = ArrayList() - private var listInvetoryAux:ArrayList = ArrayList() + private lateinit var customDialogUbicador : CustomDialogUbicador + private var listItems:ArrayList = ArrayList() private lateinit var customDialog: CustomDialog + private var deep:Int = 1 companion object { @@ -58,6 +63,7 @@ class UbicadorFragment( warehouseFk = prefs.getInt(WAREHOUSEFK,1).toString() customDialogInput = CustomDialogInput(requireContext()) customDialog = CustomDialog(requireContext()) + customDialogUbicador = CustomDialogUbicador(requireContext()) activity!!.main_bottom_navigation.visibility = View.GONE toolbar_title.text = "itemShelvingList" setEvents() @@ -72,12 +78,17 @@ class UbicadorFragment( private fun setToolBar(){ val listIcons:ArrayList = ArrayList() - val iconReload : Drawable = resources.getDrawable(R.drawable.ic_add_black_24dp,resources.newTheme()) + val iconAdd : Drawable = resources.getDrawable(R.drawable.ic_add_black_24dp,resources.newTheme()) + val iconReload : Drawable = resources.getDrawable(R.drawable.ic_autorenew_black_24dp,resources.newTheme()) + listIcons.add(iconAdd) listIcons.add(iconReload) toolbar_icons.adapter = ToolBarAdapter(listIcons,object: OnOptionsSelectedListener { override fun onOptionsItemSelected(item: Drawable) { - if (item == iconReload){ - + if (item == iconAdd){ + showAddItem() + }else if(item == iconReload){ + splash_progress.visibility = View.VISIBLE + viewModel.itemShelvingList(user,password,shelvingFk) } } @@ -95,6 +106,7 @@ class UbicadorFragment( if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { if (!edit_matricula.text.toString().isNullOrEmpty()){ toolbar_title.text = edit_matricula.text.toString() + shelvingFk = edit_matricula.text.toString() splash_progress.visibility = View.VISIBLE viewModel.itemShelvingList(user,password,edit_matricula.text.toString()) } @@ -114,14 +126,83 @@ class UbicadorFragment( with(viewModel){ loadShelvingList.observe(viewLifecycleOwner, Observer { event -> event.getContentIfNotHandled().notNull { + deep = it.list.size + listItems = ArrayList() + it.list.forEach { item -> + listItems.add(item) + } splash_progress.visibility = View.GONE - adapter = UbicadorAdapter(it.list) + adapter = UbicadorAdapter(listItems) location_recyclerview.adapter = adapter location_recyclerview.layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) } }) + + response.observe(viewLifecycleOwner, Observer { + if (it.isError){ + customDialog.setTitle("Error").setDescription(it.errorMessage).setOkButton("Cerrar"){ + customDialog.hide() + }.show() + } + }) } } + private fun showAddItem(){ + customDialogUbicador.setTitle("Nuevo item").setItemValue("").setPackingValue("").setEtiquetaValue("").setVisibleValue("").setOkButton("Guardar"){ + saveNewItem(customDialogUbicador.getItemValue(),customDialogUbicador.getEtiquetaValue(),customDialogUbicador.getPackingValue(),customDialogUbicador.getVisibleValue()) + }.setKoButton("Cerrar"){ + customDialogUbicador.hide() + }.show() + + customDialogUbicador.getEditItem().requestFocus() + (activity as MainActivity).hideKeyboard(customDialogUbicador.getEditItem()) + + customDialogUbicador.getVisibleItem().setOnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0) { + saveNewItem(customDialogUbicador.getItemValue(),customDialogUbicador.getEtiquetaValue(),customDialogUbicador.getPackingValue(),customDialogUbicador.getVisibleValue()) + return@setOnEditorActionListener true + } + false + } + + customDialogUbicador.getEtiquetaItem().setOnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0) { + saveNewItem(customDialogUbicador.getItemValue(),customDialogUbicador.getEtiquetaValue(),customDialogUbicador.getPackingValue(),customDialogUbicador.getVisibleValue()) + return@setOnEditorActionListener true + } + false + } + + + } + + private fun saveNewItem(itemFk:String,etiquetas:String,packing:String,visible:String){ + if (!packing.isNullOrEmpty()){ + if (!itemFk.isNullOrEmpty() && !visible.isNullOrEmpty()){ + viewModel.itemShelvingMake(user,password,shelvingFk,itemFk,deep.toString(),visible,packing,warehouseFk,"1") + changeOfflineValue(ItemUbicadorVO(item = itemFk,visible = visible,packing = packing)) + customDialogUbicador.setItemValue("").setPackingValue("").setEtiquetaValue("").setVisibleValue("") + customDialogUbicador.getEditItem().requestFocus() + (activity as MainActivity).hideKeyboard(customDialogUbicador.getEditItem()) + }else if(!itemFk.isNullOrEmpty() && !etiquetas.isNullOrEmpty()){ + val visible_calc = (etiquetas.toInt() * packing.toInt()).toString() + viewModel.itemShelvingMake(user,password,shelvingFk,itemFk,deep.toString(),visible_calc,packing,warehouseFk,"1") + changeOfflineValue(ItemUbicadorVO(item = itemFk,visible = visible_calc,packing = packing,stickers = etiquetas)) + customDialogUbicador.setItemValue("").setPackingValue("").setEtiquetaValue("").setVisibleValue("") + customDialogUbicador.getEditItem().requestFocus() + (activity as MainActivity).hideKeyboard(customDialogUbicador.getEditItem()) + }else{ + "Rellena campos obligatorios".toast((activity as MainActivity), Toast.LENGTH_LONG) + } + }else{ + "Packing obligatorio".toast((activity as MainActivity), Toast.LENGTH_LONG) + } + } + + private fun changeOfflineValue(item:ItemUbicadorVO){ + listItems.add(item) + adapter?.notifyDataSetChanged() + } } \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorViewModel.kt index ec24ea90..617b438d 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorViewModel.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/UbicadorViewModel.kt @@ -8,6 +8,7 @@ import es.verdnatura.domain.GetShelvingParkingUserCase import es.verdnatura.domain.GetUbicadorUserCase import es.verdnatura.presentation.base.BaseViewModel import es.verdnatura.presentation.common.Event +import es.verdnatura.presentation.common.ResponseItemVO import es.verdnatura.presentation.view.feature.shelvingparking.model.ItemShelvingParkingListVO import es.verdnatura.presentation.view.feature.shelvingparking.model.ItemShelvingParkingVO import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicadorListVO @@ -21,12 +22,14 @@ class UbicadorViewModel : BaseViewModel() { private val getUbicadorUserCase: GetUbicadorUserCase = GetUbicadorUserCase() - - private val _shelvingList by lazy { MutableLiveData() } val shelvingList: LiveData get() = _shelvingList + private val _response by lazy { MutableLiveData() } + val response: LiveData + get() = _response + val loadShelvingList = Transformations.map(_shelvingList) { Event(it) } @@ -57,6 +60,23 @@ class UbicadorViewModel : BaseViewModel() { } + fun itemShelvingMake(usuario:String,password:String,shelving:String,item:String,deep:String,quantity:String,packing:String,warehouse:String,level:String){ + getUbicadorUserCase.itemShelvingMake(usuario,password,shelving,item,deep,quantity,packing,warehouse,level).enqueue(object : Callback{ + override fun onFailure(call: Call, t: Throwable) { + _response.value = ResponseItemVO(isError = true,errorMessage ="Error al guardar item: "+item+ " Respuesta:"+t.message!!) + } + + override fun onResponse(call: Call, response: Response) { + if (response.body() == null){ + _response.value = ResponseItemVO(isError = true,errorMessage = "Error en la llamada itemShelvingMake") + }else{ + _response.value = ResponseItemVO(isError = false,response = response.body()!!) + } + + } + + }) + } } diff --git a/app/src/main/res/layout/component_custom_ubicador_dialog.xml b/app/src/main/res/layout/component_custom_ubicador_dialog.xml new file mode 100644 index 00000000..52d205b9 --- /dev/null +++ b/app/src/main/res/layout/component_custom_ubicador_dialog.xml @@ -0,0 +1,140 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +