diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardViewModel.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardViewModel.kt index 8dfb042e..806a376a 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardViewModel.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/articulo/fragment/ItemCardViewModel.kt @@ -34,6 +34,10 @@ class ItemCardViewModel(var context: Context) : BaseViewModel(context) { val response: LiveData get() = _response + private val _responseCode by lazy { MutableLiveData() } + val responseCode: LiveData + get() = _responseCode + private val _itemspackinglist by lazy { MutableLiveData() } val itemspackinglist: LiveData get() = _itemspackinglist @@ -221,6 +225,23 @@ class ItemCardViewModel(var context: Context) : BaseViewModel(context) { }) } + fun getIdFromCodeSalix(code: String) { + salix.barcodes_toitem(code) + .enqueue(object : SalixCallback(context) { + + override fun onSuccess(response: Response) { + _responseCode.value = + ResponseItemVO( + isError = false, + response = if (response.body() == null) "" else { + response!!.body().toString() + } + ) + + } + }) + } + fun barcodesEdit( itemFk: Int, value: String, diff --git a/app/src/main/java/es/verdnatura/presentation/view/feature/photos/fragment/PhotosFragment.kt b/app/src/main/java/es/verdnatura/presentation/view/feature/photos/fragment/PhotosFragment.kt index 924a0c6d..1fc788ac 100644 --- a/app/src/main/java/es/verdnatura/presentation/view/feature/photos/fragment/PhotosFragment.kt +++ b/app/src/main/java/es/verdnatura/presentation/view/feature/photos/fragment/PhotosFragment.kt @@ -39,7 +39,7 @@ class PhotosFragment( private val PICK_IMAGE_REQUEST = 1 private val REQUEST_IMAGE_CAPTURE = 2 private val imageUri: Uri? = null - private var originalItem: Number = 0 + private var originalItem: String = "" override fun getLayoutId(): Int = R.layout.fragment_photos @@ -108,20 +108,17 @@ class PhotosFragment( binding.editItemFk.setOnEditorActionListener { _, actionId, _ -> if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { if (!binding.editItemFk.text.toString().isEmpty()) { - - originalItem = itemScanValue( - binding.editItemFk.text.toString(), - "buy", - "more" - ).toString().toLong() - try { - viewModel.getItemCard( - originalItem, mobileApplication.dataStoreApp.readDataStoreKey(WAREHOUSEFK) - ) + originalItem = itemScanValue( + binding.editItemFk.text.toString(), + "buy", + "more" + ).toString() - } catch (Ex: Exception) { - ma.messageWithSound(Ex.message.toString(), true, true) + viewModel.getIdFromCodeSalix(originalItem) + + } catch (ex: Exception) { + ma.messageWithSound(ex.message.toString(), true, true) } } binding.editItemFk.setText("") @@ -177,9 +174,22 @@ class PhotosFragment( } } - + responseCode.observe(viewLifecycleOwner) { + if (it.response.isNotBlank()) { + viewModel.getItemCard( + it.response.toLong(), + mobileApplication.dataStoreApp.readDataStoreKey(WAREHOUSEFK) + ) + } else { + ma.messageWithSound( + getString(R.string.itemScanetNotFound), + true, + false, + getString(R.string.noResults) + ) + } + } } - } private fun upLoadPhoto() { @@ -191,7 +201,7 @@ class PhotosFragment( if (drawable is BitmapDrawable) { val bitmap = drawable.bitmap viewModel.uploadPhoto( - itemFK = originalItem, + itemFK = originalItem.toLong(), urlImage = saveBitmapAsTempFile(requireContext(), bitmap) ) }