insert item fast

This commit is contained in:
Enrique Blasco 2020-05-13 21:16:12 +02:00
parent db2cfb0aab
commit d37a253ccc
14 changed files with 442 additions and 3 deletions

View File

@ -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.login.fragment.LoginViewModel
import es.verdnatura.presentation.view.feature.pasillero.fragment.PasilleroViewModel import es.verdnatura.presentation.view.feature.pasillero.fragment.PasilleroViewModel
import es.verdnatura.presentation.view.feature.shelvingparking.fragment.ShelvingParkingViewModel 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 es.verdnatura.presentation.view.feature.ubicador.fragment.UbicadorViewModel
import org.koin.androidx.viewmodel.dsl.viewModel import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.dsl.module import org.koin.dsl.module
@ -52,6 +53,11 @@ val viewModelModule = module{
UbicadorViewModel() UbicadorViewModel()
} }
// Ubicador // Automatic
viewModel {
AutomaticAddItemViewModel()
}
// Ajustes // Ajustes
viewModel { viewModel {
AjustesViewModel() AjustesViewModel()

View File

@ -3,6 +3,8 @@ package es.verdnatura.domain
import es.verdnatura.presentation.view.feature.shelvingparking.model.ItemShelvingParkingVO import es.verdnatura.presentation.view.feature.shelvingparking.model.ItemShelvingParkingVO
import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicadorVO import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicadorVO
import retrofit2.Call import retrofit2.Call
import java.util.*
import kotlin.collections.ArrayList
class GetUbicadorUserCase : RestClient() { class GetUbicadorUserCase : RestClient() {
@ -25,6 +27,17 @@ class GetUbicadorUserCase : RestClient() {
return restClient!!.itemShelvingMake("json","1",usuario,password,"application/json",params)!! return restClient!!.itemShelvingMake("json","1",usuario,password,"application/json",params)!!
} }
fun itemShelvingMake_multi(usuario:String,password:String,shelving:String,items:List<String>,deep:String,warehouse:String,level:String) : Call<String> {
val params:ArrayList<Any> = 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)!!
}
} }

View File

@ -1,7 +1,7 @@
package es.verdnatura.domain package es.verdnatura.domain
import es.verdnatura.databinding.ItemUbicationRowBinding
import es.verdnatura.presentation.view.feature.ajustes.model.SectorItemVO import es.verdnatura.presentation.view.feature.ajustes.model.SectorItemVO
import es.verdnatura.presentation.view.feature.articulo.model.ItemCardVO import es.verdnatura.presentation.view.feature.articulo.model.ItemCardVO
import es.verdnatura.presentation.view.feature.buscaritem.model.ItemLocationVO import es.verdnatura.presentation.view.feature.buscaritem.model.ItemLocationVO
@ -14,6 +14,8 @@ import retrofit2.http.Body
import retrofit2.http.Header import retrofit2.http.Header
import retrofit2.http.POST import retrofit2.http.POST
@JvmSuppressWildcards
interface VerdnaturaService { interface VerdnaturaService {
//LOGIN ========================================================================> //LOGIN ========================================================================>
@ -180,5 +182,14 @@ interface VerdnaturaService {
@Body params: List<String>): @Body params: List<String>):
Call<String> Call<String>
@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<Any>):
Call<String>
} }

View File

@ -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.faltas.model.ItemFaltasVO
import es.verdnatura.presentation.view.feature.inventario.model.ItemInventaryVO import es.verdnatura.presentation.view.feature.inventario.model.ItemInventaryVO
import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO
import es.verdnatura.presentation.view.feature.ubicador.model.ItemEscanerVO
interface OnOptionsSelectedListener { interface OnOptionsSelectedListener {
fun onOptionsItemSelected(item: Drawable) fun onOptionsItemSelected(item: Drawable)
@ -41,6 +42,11 @@ interface OnInvetoryNichoClickListener {
interface OnFaltasNichoClickListener { interface OnFaltasNichoClickListener {
fun onFaltasNichoClickListener(item: ItemFaltasVO) fun onFaltasNichoClickListener(item: ItemFaltasVO)
} }
interface OnFaltasReviewClickListener { interface OnFaltasReviewClickListener {
fun onFaltasReviewClickListener(item: ItemFaltasVO) fun onFaltasReviewClickListener(item: ItemFaltasVO)
}
interface OnAutomaticItemClickListener {
fun onAutomaticItemClickListener(position: Int)
} }

View File

@ -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.fragment.PasilleroFragment
import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO
import es.verdnatura.presentation.view.feature.shelvingparking.fragment.ShelvingParkingFragment 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 es.verdnatura.presentation.view.feature.ubicador.fragment.UbicadorFragment
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@ -159,6 +160,9 @@ class MainActivity : BaseActivity<ActivityMainBinding>() , OnPasillerosItemClick
"Ubicador" -> { "Ubicador" -> {
addFragmentOnTop(UbicadorFragment.newInstance(entryPoint)) addFragmentOnTop(UbicadorFragment.newInstance(entryPoint))
} }
"Automatic" -> {
addFragmentOnTop(AutomaticAddItemFragment.newInstance(entryPoint))
}
} }
Log.i("Item: ",item.title) Log.i("Item: ",item.title)
} }

View File

@ -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<ItemEscanerVO>,
private val onAutomaticItemClickListener: OnAutomaticItemClickListener
): RecyclerView.Adapter<AutomaticAdapter.ItemHolder> () {
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
}
}
}
}

View File

@ -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<FragmentAutomaticAddItemBinding,AutomaticAddItemViewModel>(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<ItemEscanerVO> = 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<String> = 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()
}
})
}
}
}

View File

@ -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<ResponseItemVO>() }
val response: LiveData<ResponseItemVO>
get() = _response
fun itemShelvingMake_multi(usuario:String,password:String,shelving:String,items:List<String>,deep:String,warehouse:String,level:String){
getUbicadorUserCase.itemShelvingMake_multi(usuario,password,shelving,items,deep,warehouse,level).enqueue(object :
Callback<String> {
override fun onFailure(call: Call<String>, t: Throwable) {
_response.value = ResponseItemVO(isError = true,errorMessage ="Error al guardar items. Respuesta:"+t.message!!)
}
override fun onResponse(call: Call<String>, response: Response<String>) {
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()!!)
}
}
})
}
}

View File

@ -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.adapter.ToolBarAdapter
import es.verdnatura.presentation.view.feature.inventario.model.ItemInventaryVO import es.verdnatura.presentation.view.feature.inventario.model.ItemInventaryVO
import es.verdnatura.presentation.view.feature.main.activity.MainActivity 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.shelvingparking.adapter.ShelvingParkingAdapter
import es.verdnatura.presentation.view.feature.ubicador.adapter.UbicadorAdapter import es.verdnatura.presentation.view.feature.ubicador.adapter.UbicadorAdapter
import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicadorVO 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() { override fun observeViewModel() {

View File

@ -23,8 +23,6 @@ class UbicadorViewModel : BaseViewModel() {
private val getUbicadorUserCase: GetUbicadorUserCase = GetUbicadorUserCase() private val getUbicadorUserCase: GetUbicadorUserCase = GetUbicadorUserCase()
private val _shelvingList by lazy { MutableLiveData<ItemUbicadorListVO>() } private val _shelvingList by lazy { MutableLiveData<ItemUbicadorListVO>() }
val shelvingList: LiveData<ItemUbicadorListVO>
get() = _shelvingList
private val _response by lazy { MutableLiveData<ResponseItemVO>() } private val _response by lazy { MutableLiveData<ResponseItemVO>() }
val response: LiveData<ResponseItemVO> val response: LiveData<ResponseItemVO>
@ -79,4 +77,5 @@ class UbicadorViewModel : BaseViewModel() {
} }
} }

View File

@ -15,6 +15,10 @@ class ItemUbicadorVO (
var errorMessage:String = "" var errorMessage:String = ""
) )
class ItemEscanerVO(
var item:String = ""
)
class ItemUbicadorListVO( class ItemUbicadorListVO(
var list:List<ItemUbicadorVO> = listOf() var list:List<ItemUbicadorVO> = listOf()
) )

View File

@ -0,0 +1,119 @@
<?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.ubicador.model.ItemUbicadorVO"/>
</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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textinputlayout_matricula"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColorHint="@android:color/darker_gray">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_matricula"
style="@style/InputLineTextSearch"
android:layout_width="match_parent"
android:backgroundTint="@android:color/white"
android:hint="Escanea matricula"
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>
<Button
android:id="@+id/button_finalizar"
style="@style/DefaultButton"
android:layout_width="match_parent"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_weight="1"
android:background="@drawable/btn_orange"
android:text="Finalizar"
android:textColor="@color/verdnatura_white"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/textview_remember_user" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/items_recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
tools:listitem="@layout/item_escaner_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

@ -64,6 +64,7 @@
android:src="@drawable/ic_local_parking_black_24dp" android:src="@drawable/ic_local_parking_black_24dp"
android:padding="@dimen/options_image_padding"/> android:padding="@dimen/options_image_padding"/>
<ImageView <ImageView
android:id="@+id/automatic_img"
android:layout_width="@dimen/options_image_width" android:layout_width="@dimen/options_image_width"
android:layout_height="match_parent" android:layout_height="match_parent"
android:src="@drawable/ic_flash_auto_black_24dp" android:src="@drawable/ic_flash_auto_black_24dp"

View File

@ -0,0 +1,63 @@
<?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.ubicador.model.ItemEscanerVO" />
</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/pasilleros_margin_main_menu"
android:paddingRight="@dimen/pasilleros_margin_main_menu"
android:paddingTop="@dimen/pasilleros_margin_main_menu"
android:paddingBottom="@dimen/pasilleros_margin_main_menu">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:gravity="center"
android:layout_marginRight="@dimen/layout_margin_min">
<TextView
android:id="@+id/itemfk_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textSize="@dimen/h5"
android:textColor="@color/verdnatura_white"
android:text="@{item.item}"
tool:text="45532"
android:textStyle="bold"
android:gravity="center_vertical"/>
<ImageView
android:layout_width="@dimen/item_image_width"
android:layout_height="@dimen/item_image_width"
android:src="@drawable/ic_delete_black_24dp"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/verdnatura_black_9"/>
</LinearLayout>
</layout>