diff --git a/app/src/main/java/es/verdnatura/di/viewModelModule.kt b/app/src/main/java/es/verdnatura/di/viewModelModule.kt index ec036349..450145aa 100644 --- a/app/src/main/java/es/verdnatura/di/viewModelModule.kt +++ b/app/src/main/java/es/verdnatura/di/viewModelModule.kt @@ -8,6 +8,7 @@ import es.verdnatura.presentation.view.feature.inventario.fragment.InventaryView import es.verdnatura.presentation.view.feature.login.fragment.LoginViewModel import es.verdnatura.presentation.view.feature.pasillero.fragment.PasilleroViewModel import es.verdnatura.presentation.view.feature.shelvingparking.fragment.ShelvingParkingViewModel +import es.verdnatura.presentation.view.feature.ubicador.fragment.AutomaticAddItemViewModel import es.verdnatura.presentation.view.feature.ubicador.fragment.UbicadorViewModel import org.koin.androidx.viewmodel.dsl.viewModel import org.koin.dsl.module @@ -52,6 +53,11 @@ val viewModelModule = module{ UbicadorViewModel() } + // Ubicador // Automatic + viewModel { + AutomaticAddItemViewModel() + } + // Ajustes viewModel { AjustesViewModel() diff --git a/app/src/main/java/es/verdnatura/domain/GetUbicadorUserCase.kt b/app/src/main/java/es/verdnatura/domain/GetUbicadorUserCase.kt index 91054c07..7f2568ad 100644 --- a/app/src/main/java/es/verdnatura/domain/GetUbicadorUserCase.kt +++ b/app/src/main/java/es/verdnatura/domain/GetUbicadorUserCase.kt @@ -3,6 +3,8 @@ package es.verdnatura.domain import es.verdnatura.presentation.view.feature.shelvingparking.model.ItemShelvingParkingVO import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicadorVO import retrofit2.Call +import java.util.* +import kotlin.collections.ArrayList class GetUbicadorUserCase : RestClient() { @@ -25,6 +27,17 @@ class GetUbicadorUserCase : RestClient() { return restClient!!.itemShelvingMake("json","1",usuario,password,"application/json",params)!! } + + fun itemShelvingMake_multi(usuario:String,password:String,shelving:String,items:List,deep:String,warehouse:String,level:String) : Call { + val params:ArrayList = ArrayList(); + params.add(shelving) + params.add(items) + params.add(deep) + params.add(warehouse) + params.add(level) + + return restClient!!.itemShelvingMake_multi("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 6046cdd8..dc32e155 100644 --- a/app/src/main/java/es/verdnatura/domain/VerdnaturaService.kt +++ b/app/src/main/java/es/verdnatura/domain/VerdnaturaService.kt @@ -1,7 +1,7 @@ package es.verdnatura.domain -import es.verdnatura.databinding.ItemUbicationRowBinding + import es.verdnatura.presentation.view.feature.ajustes.model.SectorItemVO import es.verdnatura.presentation.view.feature.articulo.model.ItemCardVO import es.verdnatura.presentation.view.feature.buscaritem.model.ItemLocationVO @@ -14,6 +14,8 @@ import retrofit2.http.Body import retrofit2.http.Header import retrofit2.http.POST + +@JvmSuppressWildcards interface VerdnaturaService { //LOGIN ========================================================================> @@ -180,5 +182,14 @@ interface VerdnaturaService { @Body params: List): Call + @POST("almacenv2/itemShelvingMake_multi") + fun itemShelvingMake_multi(@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/common/UICallbacks.kt b/app/src/main/java/es/verdnatura/presentation/common/UICallbacks.kt index 493d5bd9..c453ccd1 100644 --- a/app/src/main/java/es/verdnatura/presentation/common/UICallbacks.kt +++ b/app/src/main/java/es/verdnatura/presentation/common/UICallbacks.kt @@ -8,6 +8,7 @@ import es.verdnatura.presentation.view.feature.buscaritem.model.ItemLocationVO import es.verdnatura.presentation.view.feature.faltas.model.ItemFaltasVO import es.verdnatura.presentation.view.feature.inventario.model.ItemInventaryVO import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO +import es.verdnatura.presentation.view.feature.ubicador.model.ItemEscanerVO interface OnOptionsSelectedListener { fun onOptionsItemSelected(item: Drawable) @@ -41,6 +42,11 @@ interface OnInvetoryNichoClickListener { interface OnFaltasNichoClickListener { fun onFaltasNichoClickListener(item: ItemFaltasVO) } + interface OnFaltasReviewClickListener { fun onFaltasReviewClickListener(item: ItemFaltasVO) +} + +interface OnAutomaticItemClickListener { + fun onAutomaticItemClickListener(position: Int) } \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/main/activity/MainActivity.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/main/activity/MainActivity.kt index f784ab7c..827ed94a 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/main/activity/MainActivity.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/main/activity/MainActivity.kt @@ -23,6 +23,7 @@ import es.verdnatura.presentation.view.feature.main.model.ItemMenuVO import es.verdnatura.presentation.view.feature.pasillero.fragment.PasilleroFragment import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO import es.verdnatura.presentation.view.feature.shelvingparking.fragment.ShelvingParkingFragment +import es.verdnatura.presentation.view.feature.ubicador.fragment.AutomaticAddItemFragment import es.verdnatura.presentation.view.feature.ubicador.fragment.UbicadorFragment import kotlinx.android.synthetic.main.activity_main.* import kotlinx.coroutines.Dispatchers @@ -159,6 +160,9 @@ class MainActivity : BaseActivity() , OnPasillerosItemClick "Ubicador" -> { addFragmentOnTop(UbicadorFragment.newInstance(entryPoint)) } + "Automatic" -> { + addFragmentOnTop(AutomaticAddItemFragment.newInstance(entryPoint)) + } } Log.i("Item: ",item.title) } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/adapter/AutomaticAdapter.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/adapter/AutomaticAdapter.kt new file mode 100644 index 00000000..73cad3db --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/adapter/AutomaticAdapter.kt @@ -0,0 +1,44 @@ +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.databinding.ItemUbicationRowBinding +import es.verdnatura.presentation.common.OnAutomaticItemClickListener +import es.verdnatura.presentation.common.loadUrl +import es.verdnatura.presentation.view.feature.ubicador.model.ItemEscanerVO +import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicadorVO + +class AutomaticAdapter ( + 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: ItemEscanerVO) { + 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/AutomaticAddItemFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/AutomaticAddItemFragment.kt new file mode 100644 index 00000000..888774b3 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/AutomaticAddItemFragment.kt @@ -0,0 +1,122 @@ +package es.verdnatura.presentation.view.feature.ubicador.fragment + +import android.content.SharedPreferences +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.domain.notNull +import es.verdnatura.presentation.base.BaseFragment +import es.verdnatura.presentation.common.OnAutomaticItemClickListener +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.main.activity.MainActivity +import es.verdnatura.presentation.view.feature.ubicador.adapter.AutomaticAdapter +import es.verdnatura.presentation.view.feature.ubicador.adapter.UbicadorAdapter +import es.verdnatura.presentation.view.feature.ubicador.model.ItemEscanerVO +import kotlinx.android.synthetic.main.activity_main.* +import kotlinx.android.synthetic.main.fragment_automatic_add_item.* +import kotlinx.android.synthetic.main.fragment_automatic_add_item.edit_matricula +import kotlinx.android.synthetic.main.fragment_automatic_add_item.splash_progress +import kotlinx.android.synthetic.main.fragment_ubicador.* +import kotlinx.android.synthetic.main.toolbar.* + +class AutomaticAddItemFragment( + var shelvingFk : String = "" +) : BaseFragment(AutomaticAddItemViewModel::class) { + + private var user = "" + private var password = "" + private var sectorFk = "" + private var warehouseFk = "" + private var adapter : AutomaticAdapter? = null + private lateinit var customDialogInput: CustomDialogInput + private lateinit var customDialogUbicador : CustomDialogUbicador + private var listItems:ArrayList = ArrayList() + private lateinit var customDialog: CustomDialog + private var deep:Int = 1 + + companion object { + fun newInstance(entryPoint:String) = AutomaticAddItemFragment(entryPoint) + } + + override fun getLayoutId(): Int = R.layout.fragment_automatic_add_item + + override fun init() { + + val prefs: SharedPreferences = activity!!.getSharedPreferences(PREFS_USER,0) + user = prefs.getString(USER,"").toString() + password = prefs.getString(PASSWORD,"").toString() + sectorFk = prefs.getInt(SECTORFK,1).toString() + 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 = "itemShelvingMake" + setEvents() + setViews() + super.init() + } + + private fun setViews(){ + adapter = AutomaticAdapter(listItems,object: OnAutomaticItemClickListener{ + override fun onAutomaticItemClickListener(position: Int) { + listItems.removeAt(position) + adapter!!.notifyDataSetChanged() + } + }) + items_recyclerview.adapter = adapter + items_recyclerview.layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) + } + + private fun setEvents(){ + edit_matricula.requestFocus() + edit_matricula.setOnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { + if (!edit_matricula.text.toString().isNullOrEmpty()){ + listItems.add(ItemEscanerVO(edit_matricula.text.toString())) + adapter!!.notifyDataSetChanged() + } + edit_matricula.setText("") + (activity as MainActivity).hideKeyboard(edit_matricula) + return@setOnEditorActionListener true + } + + return@setOnEditorActionListener false + } + + button_finalizar.setOnClickListener { + val listString:ArrayList = ArrayList() + listItems.forEach { + listString.add(it.item) + } + listItems = ArrayList() + splash_progress.visibility = View.VISIBLE + viewModel.itemShelvingMake_multi(user,password,shelvingFk,listString,deep.toString(),warehouseFk,"1") + } + + backButton.setOnClickListener { + activity!!.onBackPressed() + } + } + + override fun observeViewModel() { + with(viewModel){ + response.observe(viewLifecycleOwner, Observer { + splash_progress.visibility = View.GONE + if (it.isError){ + customDialog.setTitle("Error").setDescription(it.errorMessage).setOkButton("Cerrar"){ + customDialog.hide() + }.show() + }else{ + activity!!.onBackPressed() + } + }) + } + } + +} diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/AutomaticAddItemViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/AutomaticAddItemViewModel.kt new file mode 100644 index 00000000..f13a1879 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/fragment/AutomaticAddItemViewModel.kt @@ -0,0 +1,39 @@ +package es.verdnatura.presentation.view.feature.ubicador.fragment + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import es.verdnatura.domain.GetUbicadorUserCase +import es.verdnatura.presentation.base.BaseViewModel +import es.verdnatura.presentation.common.ResponseItemVO +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response + +class AutomaticAddItemViewModel : BaseViewModel() { + + + private val getUbicadorUserCase: GetUbicadorUserCase = GetUbicadorUserCase() + private val _response by lazy { MutableLiveData() } + val response: LiveData + get() = _response + + + fun itemShelvingMake_multi(usuario:String,password:String,shelving:String,items:List,deep:String,warehouse:String,level:String){ + getUbicadorUserCase.itemShelvingMake_multi(usuario,password,shelving,items,deep,warehouse,level).enqueue(object : + Callback { + override fun onFailure(call: Call, t: Throwable) { + _response.value = ResponseItemVO(isError = true,errorMessage ="Error al guardar items. 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 multiple") + }else{ + _response.value = ResponseItemVO(isError = false,response = response.body()!!) + } + + } + }) + } + +} 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 1e75d8ad..b4db1bf7 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 @@ -19,6 +19,7 @@ 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.pasillero.model.PasillerosItemVO 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 @@ -120,6 +121,13 @@ class UbicadorFragment( } + automatic_img.setOnClickListener { + if (!shelvingFk.isNullOrEmpty()) + (activity as MainActivity).onPasillerosItemClickListener(PasillerosItemVO(title = "Automatic"),entryPoint = shelvingFk) + else + "Escanea una matrĂ­cula".toast(activity!!,Toast.LENGTH_SHORT) + } + } override fun observeViewModel() { 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 617b438d..6a23014a 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 @@ -23,8 +23,6 @@ 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 @@ -79,4 +77,5 @@ class UbicadorViewModel : BaseViewModel() { } + } diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/model/ItemUbicadorVO.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/model/ItemUbicadorVO.kt index 7c22a1a9..9ee2978e 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/model/ItemUbicadorVO.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/ubicador/model/ItemUbicadorVO.kt @@ -15,6 +15,10 @@ class ItemUbicadorVO ( var errorMessage:String = "" ) +class ItemEscanerVO( + var item:String = "" +) + class ItemUbicadorListVO( var list:List = listOf() ) diff --git a/app/src/main/res/layout/fragment_automatic_add_item.xml b/app/src/main/res/layout/fragment_automatic_add_item.xml new file mode 100644 index 00000000..2987f77e --- /dev/null +++ b/app/src/main/res/layout/fragment_automatic_add_item.xml @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + +