edit item card row
This commit is contained in:
parent
c85e9e6a18
commit
853b20a7cd
|
@ -12,4 +12,13 @@ class GetItemCardUserCase : RestClient() {
|
|||
return restClient!!.getItemCard("json","1",usuario,password,"application/json",params = params)!!
|
||||
}
|
||||
|
||||
|
||||
fun itemStockUpdate(usuario:String,password:String,itemFk:String,warehouseFk:String,newVisible:String,isTrash:String ) : Call<String> {
|
||||
val params:ArrayList<String> = ArrayList();
|
||||
params.add(itemFk)
|
||||
params.add(warehouseFk)
|
||||
params.add(newVisible)
|
||||
params.add(isTrash)
|
||||
return restClient!!.itemStockUpdate("json","1",usuario,password,"application/json",params = params)!!
|
||||
}
|
||||
}
|
|
@ -50,4 +50,13 @@ interface VerdnaturaService {
|
|||
@Body params: List<String>):
|
||||
Call<ItemCardVO>
|
||||
|
||||
@POST("almacenv2/item_Stock_Update")
|
||||
fun itemStockUpdate(@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<String>
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package es.verdnatura.presentation.common
|
||||
|
||||
import es.verdnatura.presentation.view.feature.articulo.model.BarcodeVO
|
||||
|
||||
class ResponseItemVO (
|
||||
var response:String = "",
|
||||
var isError: Boolean = false,
|
||||
var errorMessage: String = ""
|
||||
)
|
|
@ -0,0 +1,62 @@
|
|||
package es.verdnatura.presentation.view.component
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import android.widget.EditText
|
||||
import com.google.android.material.textfield.TextInputEditText
|
||||
import es.verdnatura.R
|
||||
import kotlinx.android.synthetic.main.component_custom_dialog.*
|
||||
import kotlinx.android.synthetic.main.component_custom_dialog.custom_dialog_button_ko
|
||||
import kotlinx.android.synthetic.main.component_custom_dialog.custom_dialog_button_ok
|
||||
import kotlinx.android.synthetic.main.component_custom_dialog.custom_dialog_description
|
||||
import kotlinx.android.synthetic.main.component_custom_dialog.custom_dialog_title
|
||||
import kotlinx.android.synthetic.main.component_custom_edit_dialog.*
|
||||
|
||||
class CustomDialogInput (context: Context) : Dialog(context, R.style.DialogTheme) {
|
||||
|
||||
init {
|
||||
setContentView(R.layout.component_custom_edit_dialog)
|
||||
}
|
||||
|
||||
fun getEditText() : TextInputEditText {
|
||||
return custom_dialog_value
|
||||
}
|
||||
|
||||
fun getValue() : String {
|
||||
return custom_dialog_value.text.toString()
|
||||
}
|
||||
|
||||
fun setValue(value : String): CustomDialogInput{
|
||||
custom_dialog_value.setText(value)
|
||||
custom_dialog_value.visibility = View.VISIBLE
|
||||
return this
|
||||
}
|
||||
|
||||
fun setTitle(title: String): CustomDialogInput {
|
||||
custom_dialog_title.visibility = View.VISIBLE
|
||||
custom_dialog_title.text = title
|
||||
return this
|
||||
}
|
||||
|
||||
fun setDescription(description: String): CustomDialogInput {
|
||||
custom_dialog_description.visibility = View.VISIBLE
|
||||
custom_dialog_description.text = description
|
||||
return this
|
||||
}
|
||||
|
||||
fun setOkButton(text: String, onButtonClicked: () -> Unit): CustomDialogInput {
|
||||
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): CustomDialogInput {
|
||||
custom_dialog_button_ko.visibility = View.VISIBLE
|
||||
custom_dialog_button_ko.text = text
|
||||
custom_dialog_button_ko.setOnClickListener { onButtonClicked() }
|
||||
return this
|
||||
}
|
||||
|
||||
}
|
|
@ -3,7 +3,9 @@ package es.verdnatura.presentation.view.feature.articulo.fragment
|
|||
|
||||
|
||||
import android.content.Intent
|
||||
import android.content.LocusId
|
||||
import android.content.SharedPreferences
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import androidx.lifecycle.Observer
|
||||
|
@ -15,6 +17,7 @@ import es.verdnatura.presentation.common.OnItemCardRowClickListener
|
|||
import es.verdnatura.presentation.common.addFragment
|
||||
import es.verdnatura.presentation.common.loadUrl
|
||||
import es.verdnatura.presentation.view.component.CustomDialog
|
||||
import es.verdnatura.presentation.view.component.CustomDialogInput
|
||||
import es.verdnatura.presentation.view.feature.articulo.adapter.ItemCardAdapter
|
||||
import es.verdnatura.presentation.view.feature.articulo.model.ItemCardRowVO
|
||||
import es.verdnatura.presentation.view.feature.articulo.model.ItemCardVO
|
||||
|
@ -28,11 +31,16 @@ class ItemCardFragment : BaseFragment<FragmentItemCardBinding,ItemCardViewModel>
|
|||
|
||||
private var urlLarge:String = ""
|
||||
private var titleImage:String = ""
|
||||
private var user = ""
|
||||
private var password = ""
|
||||
private var warehouseFk = ""
|
||||
private var itemFk = ""
|
||||
|
||||
companion object {
|
||||
fun newInstance() = ItemCardFragment()
|
||||
}
|
||||
private lateinit var customDialog: CustomDialog
|
||||
private lateinit var customDialogInput: CustomDialogInput
|
||||
|
||||
override fun getLayoutId(): Int = R.layout.fragment_item_card
|
||||
|
||||
|
@ -42,6 +50,7 @@ class ItemCardFragment : BaseFragment<FragmentItemCardBinding,ItemCardViewModel>
|
|||
setEvents()
|
||||
toolbar_title.text = "ItemCard"
|
||||
customDialog = CustomDialog(requireContext())
|
||||
customDialogInput = CustomDialogInput(requireContext())
|
||||
super.init()
|
||||
}
|
||||
|
||||
|
@ -74,9 +83,10 @@ class ItemCardFragment : BaseFragment<FragmentItemCardBinding,ItemCardViewModel>
|
|||
|
||||
private fun getItemCard(itemFk:String){
|
||||
val prefs: SharedPreferences = activity!!.getSharedPreferences(PREFS_USER,0)
|
||||
val user = prefs.getString(USER,"")
|
||||
val password = prefs.getString(PASSWORD,"")
|
||||
val warehouseFk = prefs.getInt(WAREHOUSEFK,1).toString()
|
||||
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.getItemCard(itemFk,warehouseFk,user!!,password!!)
|
||||
}
|
||||
|
@ -105,6 +115,17 @@ class ItemCardFragment : BaseFragment<FragmentItemCardBinding,ItemCardViewModel>
|
|||
|
||||
}
|
||||
})
|
||||
|
||||
response.observe(viewLifecycleOwner, Observer {
|
||||
splash_progress.visibility = View.GONE
|
||||
if (it.isError){
|
||||
customDialog.setTitle("Error").setDescription(it.errorMessage).setOkButton("Cerrar"){
|
||||
customDialog.hide()
|
||||
}.show()
|
||||
}else{
|
||||
this@ItemCardFragment.getItemCard(itemFk)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,7 +145,7 @@ class ItemCardFragment : BaseFragment<FragmentItemCardBinding,ItemCardViewModel>
|
|||
listItemsRow.add(ItemCardRowVO(title = "Ubicado",value = itemInfo.enAltillo,isEditable = false))
|
||||
//EDITABLES
|
||||
|
||||
listItemsRow.add(ItemCardRowVO(title = "SIN UBICAR",value = itemInfo.enNicho,isEditable = true))
|
||||
listItemsRow.add(ItemCardRowVO(title = "SIN UBICAR",value = itemInfo.enNicho,isEditable = true, action = "itemStockUpdate"))
|
||||
listItemsRow.add(ItemCardRowVO(title = "NICHO",value = itemInfo.nicho,isEditable = true))
|
||||
listItemsRow.add(ItemCardRowVO(title = "RESERVA",value = itemInfo.reserva,isEditable = true))
|
||||
listItemsRow.add(ItemCardRowVO(title = "GROUPING",value = itemInfo.grouping,isEditable = true))
|
||||
|
@ -134,9 +155,27 @@ class ItemCardFragment : BaseFragment<FragmentItemCardBinding,ItemCardViewModel>
|
|||
|
||||
itemcard_recyclerview.adapter = ItemCardAdapter(listItemsRow,object: OnItemCardRowClickListener{
|
||||
override fun onItemCardRowClickListener(item: ItemCardRowVO) {
|
||||
customDialog.setTitle(item.title!!).setDescription(item.value!!).setOkButton("Cerrar"){
|
||||
customDialog.hide()
|
||||
}.show()
|
||||
customDialogInput.setTitle(item.title!!).setDescription("Valor actual: "+item.value!!).setOkButton("Guardar"){
|
||||
(activity as MainActivity).hideKeyboard(customDialogInput.getEditText())
|
||||
editItemCardRow(item.action!!,customDialogInput.getValue())
|
||||
customDialogInput.hide()
|
||||
|
||||
}.setKoButton("Cancelar"){
|
||||
(activity as MainActivity).hideKeyboard(customDialogInput.getEditText())
|
||||
customDialogInput.hide()
|
||||
}.setValue("").show()
|
||||
customDialogInput.getEditText().requestFocus()
|
||||
customDialogInput.getEditText().setOnEditorActionListener { v, actionId, event ->
|
||||
if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0) {
|
||||
if (!customDialogInput.getValue().isNullOrEmpty())
|
||||
editItemCardRow(item.action!!,customDialogInput.getValue())
|
||||
customDialogInput.setValue("")
|
||||
customDialogInput.hide()
|
||||
(activity as MainActivity).hideKeyboard(customDialogInput.getEditText())
|
||||
return@setOnEditorActionListener true
|
||||
}
|
||||
false
|
||||
}
|
||||
}
|
||||
})
|
||||
itemcard_recyclerview.layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
|
||||
|
@ -148,8 +187,14 @@ class ItemCardFragment : BaseFragment<FragmentItemCardBinding,ItemCardViewModel>
|
|||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
private fun editItemCardRow(action:String,value:String){
|
||||
splash_progress.visibility = View.VISIBLE
|
||||
when (action){
|
||||
"itemStockUpdate" -> viewModel.itemStockUpdate(itemFk = itemFk,warehouseFk = warehouseFk,user = user,password = password,newValue = value,isTrash = "0")
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import androidx.lifecycle.LiveData
|
|||
import androidx.lifecycle.MutableLiveData
|
||||
import es.verdnatura.domain.GetItemCardUserCase
|
||||
import es.verdnatura.presentation.base.BaseViewModel
|
||||
import es.verdnatura.presentation.common.ResponseItemVO
|
||||
import es.verdnatura.presentation.view.feature.articulo.model.ItemCardVO
|
||||
import retrofit2.Call
|
||||
import retrofit2.Callback
|
||||
|
@ -18,6 +19,10 @@ class ItemCardViewModel : BaseViewModel() {
|
|||
val itemcard: LiveData<ItemCardVO>
|
||||
get() = _itemcard
|
||||
|
||||
private val _response by lazy { MutableLiveData<ResponseItemVO>() }
|
||||
val response: LiveData<ResponseItemVO>
|
||||
get() = _response
|
||||
|
||||
|
||||
fun getItemCard(itemFk:String,warehouseFk:String,user:String,password:String) {
|
||||
getItemCardUserCase.getItemCard(user,password,itemFk,warehouseFk).enqueue(object :Callback<ItemCardVO>{
|
||||
|
@ -35,4 +40,22 @@ class ItemCardViewModel : BaseViewModel() {
|
|||
|
||||
})
|
||||
}
|
||||
|
||||
fun itemStockUpdate(itemFk:String,warehouseFk:String,user:String,password:String,newValue:String,isTrash:String){
|
||||
getItemCardUserCase.itemStockUpdate(user,password,itemFk,warehouseFk,newValue,isTrash).enqueue(object : Callback<String>{
|
||||
override fun onFailure(call: Call<String>, t: Throwable) {
|
||||
_response.value = ResponseItemVO(isError = true,errorMessage = 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 itemStockUpdate")
|
||||
}else{
|
||||
_response.value = ResponseItemVO(isError = false,response = response.body()!!)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -53,6 +53,9 @@ class LoginViewModel() : BaseViewModel() {
|
|||
}
|
||||
|
||||
fun loginSalix(user:String,password:String){
|
||||
val loginSalixVO = LoginSalixVO(user,password, "aaa")
|
||||
_loginsalixitem.value = loginSalixVO
|
||||
/*
|
||||
getLoginUserCase.salixLogin(user,password).enqueue(object : Callback<LoginSalixVO>{
|
||||
override fun onResponse(call: Call<LoginSalixVO>, response: Response<LoginSalixVO>) {
|
||||
|
||||
|
@ -70,7 +73,7 @@ class LoginViewModel() : BaseViewModel() {
|
|||
val loginSalixVO = LoginSalixVO(user,password, "",isError = true,errorMessage = t.message!!)
|
||||
_loginsalixitem.value = loginSalixVO
|
||||
}
|
||||
})
|
||||
})*/
|
||||
}
|
||||
|
||||
fun checkVersion(user:String,password:String,version:String){
|
||||
|
|
|
@ -39,19 +39,26 @@
|
|||
tools:text="Este cambio no podrá deshacerse a no ser que vuelvas a vincular el dispositivo"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<EditText
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:id="@+id/textinputlayout_username"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@color/verdnatura_white"
|
||||
android:textSize="@dimen/body1"
|
||||
android:visibility="gone"
|
||||
tools:hint="introduce valor"
|
||||
tools:visibility="visible"
|
||||
android:maxLines="1"
|
||||
android:background="@color/verdnatura_brown_grey"
|
||||
android:padding="@dimen/navigation_row_limit_padding"
|
||||
android:layout_marginTop="@dimen/default_layout_margin"/>
|
||||
android:textColorHint="@android:color/darker_gray"
|
||||
android:layout_marginTop="@dimen/default_layout_margin">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/custom_dialog_value"
|
||||
style="@style/InputLineTextSearch"
|
||||
android:layout_width="match_parent"
|
||||
android:backgroundTint="@android:color/white"
|
||||
android:hint="Nuevo valor"
|
||||
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/custom_dialog_button_ok"
|
||||
|
|
Loading…
Reference in New Issue