diff --git a/app/src/main/java/es/verdnatura/domain/GetClaimUserCase.kt b/app/src/main/java/es/verdnatura/domain/GetClaimUserCase.kt new file mode 100644 index 00000000..2733b0c0 --- /dev/null +++ b/app/src/main/java/es/verdnatura/domain/GetClaimUserCase.kt @@ -0,0 +1,24 @@ +package es.verdnatura.domain + +import android.content.Context +import retrofit2.Call + +class GetClaimUserCase(context: Context) : RestClient(context) { + + fun itemShelving_addByClaim(usuario: String, password: String,claimFK:String, shelvingFk: String): Call { + val params: ArrayList = ArrayList() + params.add(claimFK) + params.add(shelvingFk) + return restClient!!.itemShelving_addByClaim( + "json", + "1", + usuario, + password, + "application/json", + params + ) + } + + + +} \ No newline at end of file diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/claim/fragment/ClaimFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/claim/fragment/ClaimFragment.kt new file mode 100644 index 00000000..1c854515 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/claim/fragment/ClaimFragment.kt @@ -0,0 +1,220 @@ +package es.verdnatura.presentation.view.feature.claim.fragment + + +import android.view.View +import android.view.View.GONE +import android.view.View.VISIBLE +import android.view.inputmethod.EditorInfo +import androidx.lifecycle.Observer +import androidx.recyclerview.widget.LinearLayoutManager +import es.verdnatura.R +import es.verdnatura.databinding.FragmentGeneralBlackBinding +import es.verdnatura.presentation.base.BaseFragment +import es.verdnatura.presentation.common.GeneralAdapter +import es.verdnatura.presentation.common.GeneralItem +import es.verdnatura.presentation.common.OnGeneralItemRowClickListener +import es.verdnatura.presentation.common.hideKeyboard +import es.verdnatura.presentation.view.component.CustomDialog +import es.verdnatura.presentation.view.component.CustomDialogList +import es.verdnatura.presentation.view.feature.smarttag.model.SmartTag + +class ClaimFragment( + var entryPoint: String = "" +) : BaseFragment( + ClaimViewModel::class +) { + + private var goBack: Boolean = false + + override fun getLayoutId(): Int = R.layout.fragment_general_black + private lateinit var customDialog: CustomDialog + private lateinit var customDialogList: CustomDialogList + private var listClaims: ArrayList = ArrayList() + private var claimAdapter: GeneralAdapter? = null + + + + companion object { + fun newInstance(entryPoint: String) = ClaimFragment(entryPoint) + } + + + override fun init() { + + customDialog = CustomDialog(requireContext()) + customDialogList = CustomDialogList(requireContext()) + goBack = false + ma.hideBottomNavigation(GONE) + binding.splashProgress.visibility = GONE + + setEvents() + setToolBar() + setAdapter() + showInputClaim() + super.init() + } + + override fun onPause() { + goBack = true + super.onPause() + } + + private fun setToolBar() { + + binding.mainToolbar.toolbarTitle.text = entryPoint + + } +private fun setAdapter(){ + claimAdapter = GeneralAdapter(listClaims, object : OnGeneralItemRowClickListener { + + override fun OnGeneralItemRowClickListener(item: GeneralItem) { + + } + }) + customDialogList.getRecyclerView().adapter = claimAdapter + customDialogList.getRecyclerView().layoutManager = + LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) +} + + private fun itemShelving_addByClaim(shelvingOrSmarttag: String) { + + binding.splashProgress.visibility = VISIBLE + viewModel.itemShelving_addByClaim(getData(USER),getData(PASSWORD),listClaims.first().toString(),shelvingOrSmarttag) + customDialogList.dismiss() + } + + + private fun hideKeyboards() { + try { + requireActivity().hideKeyboard() + } catch (e: Exception) { + } + } + + private fun setEvents() { + + binding.mainToolbar.backButton.setOnClickListener { + + customDialogList.dismiss() + requireActivity().onBackPressed() + + } + + } + + + override fun observeViewModel() { + + + with(viewModel) { + binding.splashProgress.visibility = GONE + + + responseadd.observe(viewLifecycleOwner, Observer { + + if (it.isError) { + customDialogList.dismiss() + listClaims.clear() + claimAdapter!!.notifyDataSetChanged() + showInputClaim() + ma.messageWithSound(it.errorMessage,true,false) + } else { + customDialogList.dismiss() + ma.messageWithSound("Reclamación ${listClaims.first().code} guardada con matrícula ${listClaims.get(1).code}",false,true) + listClaims.clear() + claimAdapter!!.notifyDataSetChanged() + showInputClaim() + + + } + binding.splashProgress.visibility = GONE + }) + + } + + } + + private fun getTextToPosition(TagsScaned: Int): String { + var message = "Datos completos" + + when (TagsScaned) { + 1 -> message = "Escanea matrícula" + + } + + + return message + + } + + private fun getTextScaned(TagScaned: Int): String { + var message = "" + + when (TagScaned) { + 1 -> message = "Reclamación:" + 2 -> message = "Matrícula:" + + } + + return message + + } + + private fun add_item(itemScaned:String){ + var nameClaim: String + + nameClaim = + getTextScaned(listClaims.size + 1) + itemScaned + customDialogList.setTitle(getTextToPosition(listClaims.size + 1)) + + listClaims.add(GeneralItem(itemScaned, nameClaim)) + claimAdapter!!.notifyDataSetChanged() + //customDialogList.setValue("") + + } + + private fun showInputClaim() { + + customDialogList.setTitle("Inserta el código de reclamación.") + .setOkButton("Finalizar") { + + ma.hideKeyboard(customDialogList.getEditText()) + + customDialogList.dismiss() + requireActivity().onBackPressed() + + + }.setValue("").show() + + customDialogList.getEditText().requestFocus() + ma.hideKeyboard(customDialogList.getEditText()) + + customDialogList.getEditText().setOnEditorActionListener { v, actionId, event -> + if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5 || actionId == 6) { + if (!customDialogList.getValue().isNullOrEmpty()) { + + //listClaims.add(GeneralItem(customDialogList.getValue(),customDialogList.getValue())) + add_item(customDialogList.getValue()) + + if (listClaims.size >1) { + + itemShelving_addByClaim(customDialogList.getValue().uppercase()) + } + + } + customDialogList.setValue("") + ma.hideKeyboard(customDialogList.getEditText()) + return@setOnEditorActionListener true + } + false + } + + hideKeyboard() + + } + + +} + + + diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/claim/fragment/ClaimViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/claim/fragment/ClaimViewModel.kt new file mode 100644 index 00000000..5bc18335 --- /dev/null +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/claim/fragment/ClaimViewModel.kt @@ -0,0 +1,60 @@ +package es.verdnatura.presentation.view.feature.claim.fragment + + + import android.content.Context + import androidx.lifecycle.LiveData + import androidx.lifecycle.MutableLiveData + import es.verdnatura.domain.GetClaimUserCase + import es.verdnatura.presentation.base.BaseViewModel + import es.verdnatura.presentation.base.getMessageFromAllResponse + import es.verdnatura.presentation.base.nameofFunction + import es.verdnatura.presentation.common.ResponseItemVO + import retrofit2.Call + import retrofit2.Callback + import retrofit2.Response + +class ClaimViewModel(context: Context) : BaseViewModel() { + + private val GetClaimUserCase: GetClaimUserCase = GetClaimUserCase(context) + + + private val _responseadd by lazy { MutableLiveData() } + val responseadd: LiveData + get() = _responseadd + + + + fun itemShelving_addByClaim(usuario:String,password:String,claimFK:String,shelvingFK:String){ + GetClaimUserCase.itemShelving_addByClaim(usuario,password,claimFK,shelvingFK).enqueue(object : Callback{ + override fun onFailure(call: Call, t: Throwable) { + + _responseadd.value = ResponseItemVO(isError = true,errorMessage = getMessageFromAllResponse( + nameofFunction(this),t.message!!) + ) + } + + override fun onResponse(call: Call, response: Response) { + + if (!response.isSuccessful){ + _responseadd.value = ResponseItemVO(isError = true,errorMessage = getMessageFromAllResponse(nameofFunction(this),response.message())) + }else{ + _responseadd.value = ResponseItemVO(isError = false,errorMessage = getMessageFromAllResponse(nameofFunction(this),response.message())) + } + + + } + + + + }) + } + + fun messageError(message: String,call: String ): ResponseItemVO? { + return ResponseItemVO( + isError = true, + errorMessage = "Error al llamar a " + call + " . Descripción del error:" + message + ) + } + + + } diff --git a/app/src/main/res/drawable/custom_ripple.xml b/app/src/main/res/drawable/custom_ripple.xml new file mode 100644 index 00000000..0abf391a --- /dev/null +++ b/app/src/main/res/drawable/custom_ripple.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_claims.xml b/app/src/main/res/drawable/ic_claims.xml new file mode 100644 index 00000000..dc524243 --- /dev/null +++ b/app/src/main/res/drawable/ic_claims.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/fragment_general_black.xml b/app/src/main/res/layout/fragment_general_black.xml new file mode 100644 index 00000000..e4c7b3b7 --- /dev/null +++ b/app/src/main/res/layout/fragment_general_black.xml @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file