From 0e8c1a84eebbcb1b1fa94b9d632058fc8e2102eb Mon Sep 17 00:00:00 2001 From: Enrique Blasco Date: Sun, 10 May 2020 08:28:59 +0200 Subject: [PATCH] Search item location --- .../java/es/verdnatura/di/viewModelModule.kt | 6 + .../domain/GetBuscarItemUserCase.kt | 14 ++ .../es/verdnatura/domain/VerdnaturaService.kt | 13 ++ .../presentation/common/UICallbacks.kt | 5 + .../articulo/fragment/ItemCardFragment.kt | 3 +- .../buscaritem/adapter/LocationAdapter.kt | 42 ++++++ .../buscaritem/fragment/BuscarItemFragment.kt | 104 +++++++++++++ .../fragment/BuscarItemViewModel.kt | 51 +++++++ .../buscaritem/model/ItemLocationVO.kt | 18 +++ .../feature/main/activity/MainActivity.kt | 4 + .../main/res/layout/fragment_buscar_item.xml | 138 ++++++++++++++++++ app/src/main/res/layout/item_location_row.xml | 67 +++++++++ 12 files changed, 463 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/es/verdnatura/domain/GetBuscarItemUserCase.kt create mode 100644 app/src/main/java/es/verdnatura/presentation/view/feature/buscaritem/adapter/LocationAdapter.kt create mode 100644 app/src/main/java/es/verdnatura/presentation/view/feature/buscaritem/fragment/BuscarItemFragment.kt create mode 100644 app/src/main/java/es/verdnatura/presentation/view/feature/buscaritem/fragment/BuscarItemViewModel.kt create mode 100644 app/src/main/java/es/verdnatura/presentation/view/feature/buscaritem/model/ItemLocationVO.kt create mode 100644 app/src/main/res/layout/fragment_buscar_item.xml create mode 100644 app/src/main/res/layout/item_location_row.xml diff --git a/app/src/main/java/es/verdnatura/di/viewModelModule.kt b/app/src/main/java/es/verdnatura/di/viewModelModule.kt index 5ecb7367..7e29ad70 100644 --- a/app/src/main/java/es/verdnatura/di/viewModelModule.kt +++ b/app/src/main/java/es/verdnatura/di/viewModelModule.kt @@ -2,6 +2,7 @@ package es.verdnatura.di import es.verdnatura.presentation.view.feature.ajustes.fragment.AjustesViewModel import es.verdnatura.presentation.view.feature.articulo.fragment.ItemCardViewModel +import es.verdnatura.presentation.view.feature.buscaritem.fragment.BuscarItemViewModel import es.verdnatura.presentation.view.feature.login.fragment.LoginViewModel import es.verdnatura.presentation.view.feature.pasillero.fragment.PasilleroViewModel import org.koin.androidx.viewmodel.dsl.viewModel @@ -23,6 +24,11 @@ val viewModelModule = module{ ItemCardViewModel() } + // Pasilleros / Buscar Item + viewModel { + BuscarItemViewModel() + } + // Ajustes viewModel { AjustesViewModel() diff --git a/app/src/main/java/es/verdnatura/domain/GetBuscarItemUserCase.kt b/app/src/main/java/es/verdnatura/domain/GetBuscarItemUserCase.kt new file mode 100644 index 00000000..e4e9c5d5 --- /dev/null +++ b/app/src/main/java/es/verdnatura/domain/GetBuscarItemUserCase.kt @@ -0,0 +1,14 @@ +package es.verdnatura.domain + +import es.verdnatura.presentation.view.feature.buscaritem.model.ItemLocationVO +import retrofit2.Call + +class GetBuscarItemUserCase : RestClient() { + + fun searchItemsUbicador(usuario:String,password:String,itemFk:String) : Call> { + val params:ArrayList = ArrayList(); + params.add(itemFk) + return restClient!!.searchItemsUbicador("json","1",usuario,password,"application/json",params = params)!! + } + +} \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/domain/VerdnaturaService.kt b/app/src/main/java/es/verdnatura/domain/VerdnaturaService.kt index c12e1c19..8ab3ced6 100644 --- a/app/src/main/java/es/verdnatura/domain/VerdnaturaService.kt +++ b/app/src/main/java/es/verdnatura/domain/VerdnaturaService.kt @@ -3,6 +3,7 @@ package es.verdnatura.domain 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 import retrofit2.Call import retrofit2.http.Body import retrofit2.http.Header @@ -41,6 +42,8 @@ interface VerdnaturaService { //PASILLEROS ========================================================================> + + //CONSULTAR ARTICULO ========================================================================> @POST("almacenv2/item_card") fun getItemCard(@Header("aplicacion") aplicacion: String, @Header("version") version: String, @@ -105,4 +108,14 @@ interface VerdnaturaService { @Body params: List): Call + //BUSCAR ITEM ========================================================================> + @POST("almacenv2/getItemUbication") + fun searchItemsUbicador(@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 aa0965f9..163b0769 100644 --- a/app/src/main/java/es/verdnatura/presentation/common/UICallbacks.kt +++ b/app/src/main/java/es/verdnatura/presentation/common/UICallbacks.kt @@ -3,6 +3,7 @@ package es.verdnatura.presentation.common import es.verdnatura.presentation.view.feature.ajustes.model.AjustesItemVO import es.verdnatura.presentation.view.feature.articulo.model.BarcodeVO import es.verdnatura.presentation.view.feature.articulo.model.ItemCardRowVO +import es.verdnatura.presentation.view.feature.buscaritem.model.ItemLocationVO import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO interface OnPasillerosItemClickListener { @@ -20,4 +21,8 @@ interface OnItemCardRowClickListener { interface OnBarcodeRowClickListener { fun onBarcodeRowClickListener(item: BarcodeVO) +} + +interface OnLocationRowClickListener { + fun onLocationRowClickListener(item: ItemLocationVO) } \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardFragment.kt index 9756a410..87f7bf11 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardFragment.kt @@ -65,7 +65,7 @@ class ItemCardFragment : BaseFragment private fun setEvents(){ edit_itemFk.requestFocus() edit_itemFk.setOnEditorActionListener { v, actionId, event -> - if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0) { + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { if (!edit_itemFk.text.toString().isNullOrEmpty()) getItemCard(edit_itemFk.text.toString()) edit_itemFk.setText("") @@ -267,7 +267,6 @@ class ItemCardFragment : BaseFragment customDialogList.getRecyclerView().layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) } - private fun updateBarcode(code:String,delete:String,item:ItemCardRowVO){ if (delete == "1"){ var i = 0 diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/buscaritem/adapter/LocationAdapter.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/buscaritem/adapter/LocationAdapter.kt new file mode 100644 index 00000000..ac68f12e --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/buscaritem/adapter/LocationAdapter.kt @@ -0,0 +1,42 @@ +package es.verdnatura.presentation.view.feature.buscaritem.adapter + +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import es.verdnatura.databinding.ItemLocationRowBinding +import es.verdnatura.presentation.common.OnLocationRowClickListener +import es.verdnatura.presentation.view.feature.buscaritem.model.ItemLocationVO + +class LocationAdapter ( + private val items: List, + private val onLocationRowClickListener: OnLocationRowClickListener +): RecyclerView.Adapter () { + + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemHolder { + return ItemHolder( + ItemLocationRowBinding.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 { + onLocationRowClickListener.onLocationRowClickListener(items[position]) + } + + } + + class ItemHolder( + val binding: ItemLocationRowBinding + ) : RecyclerView.ViewHolder(binding.root){ + private val res = binding.root.context.resources + fun bind(item: ItemLocationVO) { + binding.apply { + this.item = item + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/buscaritem/fragment/BuscarItemFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/buscaritem/fragment/BuscarItemFragment.kt new file mode 100644 index 00000000..617e9c14 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/buscaritem/fragment/BuscarItemFragment.kt @@ -0,0 +1,104 @@ +package es.verdnatura.presentation.view.feature.buscaritem.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.FragmentBuscarItemBinding +import es.verdnatura.domain.notNull +import es.verdnatura.presentation.base.BaseFragment +import es.verdnatura.presentation.common.OnLocationRowClickListener +import es.verdnatura.presentation.view.component.CustomDialog +import es.verdnatura.presentation.view.feature.buscaritem.adapter.LocationAdapter +import es.verdnatura.presentation.view.feature.buscaritem.model.ItemLocationVO +import es.verdnatura.presentation.view.feature.main.activity.MainActivity +import kotlinx.android.synthetic.main.activity_main.* +import kotlinx.android.synthetic.main.fragment_buscar_item.* +import kotlinx.android.synthetic.main.toolbar.* + +class BuscarItemFragment : BaseFragment(BuscarItemViewModel::class) { + + private var user = "" + private var password = "" + private var warehouseFk = "" + private var itemFk = "" + private var adapter : LocationAdapter? = null + private lateinit var customDialog: CustomDialog + + companion object { + fun newInstance() = BuscarItemFragment() + } + + override fun getLayoutId(): Int = R.layout.fragment_buscar_item + + override fun init() { + activity!!.main_bottom_navigation.visibility = View.GONE + toolbar_title.text = "getItemUbication" + customDialog = CustomDialog(requireContext()) + setEvents() + super.init() + } + + + private fun setEvents(){ + edit_itemFk.requestFocus() + edit_itemFk.setOnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { + if (!edit_itemFk.text.toString().isNullOrEmpty()) + getLocations(edit_itemFk.text.toString()) + edit_itemFk.setText("") + (activity as MainActivity).hideKeyboard(edit_itemFk) + return@setOnEditorActionListener true + } + false + } + + + backButton.setOnClickListener { + activity!!.onBackPressed() + } + + } + + private fun getLocations(itemFk:String){ + val prefs: SharedPreferences = activity!!.getSharedPreferences(PREFS_USER,0) + user = prefs.getString(USER,"").toString() + password = prefs.getString(PASSWORD,"").toString() + warehouseFk = prefs.getInt(WAREHOUSEFK,1).toString() + this.itemFk = itemFk + splash_progress.visibility = View.VISIBLE + viewModel.getLocations(user,password,itemFk) + } + + override fun observeViewModel() { + with(viewModel){ + loadLocationList.observe(viewLifecycleOwner, Observer { event -> + splash_progress.visibility = View.GONE + event.getContentIfNotHandled().notNull { + + adapter = LocationAdapter(it.list,object: OnLocationRowClickListener{ + override fun onLocationRowClickListener(item: ItemLocationVO) { + TODO("Not yet implemented") + } + + }) + + location_recyclerview.adapter = adapter + location_recyclerview.layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) + + var totalVisible:Int = 0 + it.list.forEach { + if (!it.visible.isNullOrEmpty()) + totalVisible += it.visible.toInt() + } + toolbar_title.text = "Item: "+itemFk+ " Total visible: "+totalVisible + + + } + }) + } + } + +} diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/buscaritem/fragment/BuscarItemViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/buscaritem/fragment/BuscarItemViewModel.kt new file mode 100644 index 00000000..fa396ac2 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/buscaritem/fragment/BuscarItemViewModel.kt @@ -0,0 +1,51 @@ +package es.verdnatura.presentation.view.feature.buscaritem.fragment + +import androidx.lifecycle.LiveData +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.Transformations +import es.verdnatura.domain.GetBuscarItemUserCase +import es.verdnatura.presentation.base.BaseViewModel +import es.verdnatura.presentation.common.Event +import es.verdnatura.presentation.view.feature.buscaritem.model.ItemLocationVO +import es.verdnatura.presentation.view.feature.buscaritem.model.LocationListVO +import retrofit2.Call +import retrofit2.Callback +import retrofit2.Response + +class BuscarItemViewModel : BaseViewModel() { + private val getBuscarItemUserCase: GetBuscarItemUserCase = GetBuscarItemUserCase() + + + private val _locationList by lazy { MutableLiveData() } + val locationList: LiveData + get() = _locationList + + + val loadLocationList = Transformations.map(_locationList) { Event(it) } + + + fun getLocations(user:String,password:String,itemFk:String){ + getBuscarItemUserCase.searchItemsUbicador(user,password,itemFk).enqueue(object : Callback> { + override fun onFailure(call: Call>, t: Throwable) { + val listError:ArrayList = ArrayList() + listError.add(ItemLocationVO(isError = true,errorMessage = t.message!!)) + _locationList.value = LocationListVO(listError) + } + + override fun onResponse( + call: Call>, + response: Response> + ) { + if (response.body() != null){ + _locationList.value = response.body()?.let { LocationListVO(it) } + }else{ + val listError:ArrayList = ArrayList() + listError.add(ItemLocationVO(isError = true,errorMessage = "Error en la llamada de searchItemsUbicador")) + _locationList.value = LocationListVO(listError) + } + } + + }) + } + +} diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/buscaritem/model/ItemLocationVO.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/buscaritem/model/ItemLocationVO.kt new file mode 100644 index 00000000..9b6e6ec7 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/buscaritem/model/ItemLocationVO.kt @@ -0,0 +1,18 @@ +package es.verdnatura.presentation.view.feature.buscaritem.model + + +class ItemLocationVO ( + var Parking:String = "", + var Matricula:String = "", + var visible:String = "", + var Disponible:String = "", + var level:String = "", + var created:String = "", + var itemFk:String = "", + val isError : Boolean = false, + var errorMessage : String = "" +) + +class LocationListVO ( + var list: List = listOf() +) \ 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 3f1e35b5..f947c943 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 @@ -16,6 +16,7 @@ import es.verdnatura.presentation.common.addFragment import es.verdnatura.presentation.view.component.CustomDialog import es.verdnatura.presentation.view.feature.ajustes.fragment.AjustesFragment import es.verdnatura.presentation.view.feature.articulo.fragment.ItemCardFragment +import es.verdnatura.presentation.view.feature.buscaritem.fragment.BuscarItemFragment 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 @@ -139,6 +140,9 @@ class MainActivity : BaseActivity() , OnPasillerosItemClick "Consultar artículo" -> { addFragmentOnTop(ItemCardFragment.newInstance()) } + "Buscar item" -> { + addFragmentOnTop(BuscarItemFragment.newInstance()) + } } Log.i("Item: ",item.title) } diff --git a/app/src/main/res/layout/fragment_buscar_item.xml b/app/src/main/res/layout/fragment_buscar_item.xml new file mode 100644 index 00000000..2c28fc75 --- /dev/null +++ b/app/src/main/res/layout/fragment_buscar_item.xml @@ -0,0 +1,138 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_location_row.xml b/app/src/main/res/layout/item_location_row.xml new file mode 100644 index 00000000..b7ae56e1 --- /dev/null +++ b/app/src/main/res/layout/item_location_row.xml @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file