Search item location

This commit is contained in:
Enrique Blasco 2020-05-10 08:28:59 +02:00
parent e115da9370
commit 0e8c1a84ee
12 changed files with 463 additions and 2 deletions

View File

@ -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()

View File

@ -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<List<ItemLocationVO>> {
val params:ArrayList<String> = ArrayList();
params.add(itemFk)
return restClient!!.searchItemsUbicador("json","1",usuario,password,"application/json",params = params)!!
}
}

View File

@ -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<String>):
Call<String>
//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<String>):
Call<List<ItemLocationVO>>
}

View File

@ -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)
}

View File

@ -65,7 +65,7 @@ class ItemCardFragment : BaseFragment<FragmentItemCardBinding,ItemCardViewModel>
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<FragmentItemCardBinding,ItemCardViewModel>
customDialogList.getRecyclerView().layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
}
private fun updateBarcode(code:String,delete:String,item:ItemCardRowVO){
if (delete == "1"){
var i = 0

View File

@ -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<ItemLocationVO>,
private val onLocationRowClickListener: OnLocationRowClickListener
): RecyclerView.Adapter<LocationAdapter.ItemHolder> () {
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
}
}
}
}

View File

@ -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<FragmentBuscarItemBinding,BuscarItemViewModel>(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
}
})
}
}
}

View File

@ -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<LocationListVO>() }
val locationList: LiveData<LocationListVO>
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<List<ItemLocationVO>> {
override fun onFailure(call: Call<List<ItemLocationVO>>, t: Throwable) {
val listError:ArrayList<ItemLocationVO> = ArrayList()
listError.add(ItemLocationVO(isError = true,errorMessage = t.message!!))
_locationList.value = LocationListVO(listError)
}
override fun onResponse(
call: Call<List<ItemLocationVO>>,
response: Response<List<ItemLocationVO>>
) {
if (response.body() != null){
_locationList.value = response.body()?.let { LocationListVO(it) }
}else{
val listError:ArrayList<ItemLocationVO> = ArrayList()
listError.add(ItemLocationVO(isError = true,errorMessage = "Error en la llamada de searchItemsUbicador"))
_locationList.value = LocationListVO(listError)
}
}
})
}
}

View File

@ -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<ItemLocationVO> = listOf()
)

View File

@ -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<ActivityMainBinding>() , OnPasillerosItemClick
"Consultar artículo" -> {
addFragmentOnTop(ItemCardFragment.newInstance())
}
"Buscar item" -> {
addFragmentOnTop(BuscarItemFragment.newInstance())
}
}
Log.i("Item: ",item.title)
}

View File

@ -0,0 +1,138 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="viewModel"
type="es.verdnatura.presentation.view.feature.buscaritem.model.ItemLocationVO" />
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:paddingTop="@dimen/toolbar_height">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textinputlayout_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="@android:color/darker_gray">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_itemFk"
style="@style/InputLineTextSearch"
android:layout_width="match_parent"
android:backgroundTint="@android:color/white"
android:hint="Escanea etiqueta"
android:inputType="text"
android:lines="1"
android:maxLines="1"
android:textColor="@color/verdnatura_white"
android:textColorHint="@android:color/darker_gray" />
</com.google.android.material.textfield.TextInputLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="@dimen/layout_margin_min"
android:layout_marginBottom="@dimen/layout_margin_1"
android:paddingLeft="@dimen/layout_margin_min"
android:paddingRight="@dimen/layout_margin_min">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Parking"
android:textSize="@dimen/body2"
android:textColor="@color/verdnatura_white"
android:layout_weight="1"
android:gravity="center"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Matrícula"
android:textSize="@dimen/body2"
android:textColor="@color/verdnatura_white"
android:layout_weight="1"
android:gravity="center"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Visible"
android:textSize="@dimen/body2"
android:textColor="@color/verdnatura_white"
android:layout_weight="1"
android:gravity="center"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Fecha"
android:textSize="@dimen/body2"
android:textColor="@color/verdnatura_white"
android:layout_weight="1"
android:gravity="center"/>
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/location_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
tools:listitem="@layout/item_location_row"/>
</LinearLayout>
<include
android:id="@+id/main_toolbar"
layout="@layout/toolbar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="@+id/splash_progress"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@color/verdnatura_black_8_alpha_6"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:gravity="center">
<com.airbnb.lottie.LottieAnimationView
android:layout_width="wrap_content"
android:layout_height="@dimen/verdnatura_logo_large_height"
app:lottie_autoPlay="true"
app:lottie_loop="true"
app:lottie_rawRes="@raw/orange_loading"
app:lottie_speed="2" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>

View File

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tool="http://schemas.android.com/tools">
<data>
<variable
name="item"
type="es.verdnatura.presentation.view.feature.buscaritem.model.ItemLocationVO" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:id="@+id/item_row_layout"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/verdnatura_black_5"
android:paddingLeft="@dimen/layout_margin_min"
android:paddingRight="@dimen/layout_margin_min"
android:paddingTop="@dimen/pasilleros_margin_main_menu"
android:paddingBottom="@dimen/pasilleros_margin_main_menu">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{item.parking}"
android:textSize="@dimen/body2"
android:textColor="@color/verdnatura_white"
android:layout_weight="1"
android:gravity="center"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{item.matricula}"
android:textSize="@dimen/body2"
android:textColor="@color/verdnatura_white"
android:layout_weight="1"
android:gravity="center"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{item.visible}"
android:textSize="@dimen/body2"
android:textColor="@color/verdnatura_white"
android:layout_weight="1"
android:gravity="center"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{item.created}"
android:textSize="@dimen/body2"
android:textColor="@color/verdnatura_white"
android:layout_weight="1"
android:gravity="center"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/verdnatura_black_9"/>
</LinearLayout>
</layout>