feat roadMap #refs 7195

This commit is contained in:
Sergio De la torre 2024-05-28 10:57:21 +02:00
parent d996f06fd4
commit 3d878d50c6
7 changed files with 218 additions and 84 deletions

View File

@ -1,12 +1,18 @@
package es.verdnatura.presentation.view.feature.packaging.fragment
import android.content.Context
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Color
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.net.Uri
import android.os.Build
import android.os.Environment
import android.util.Log.d
import android.view.View
import android.widget.ImageView
import androidx.core.graphics.drawable.toBitmap
import androidx.recyclerview.widget.LinearLayoutManager
import com.esafirm.imagepicker.features.ImagePickerConfig
import com.esafirm.imagepicker.features.registerImagePicker
@ -18,14 +24,27 @@ import es.verdnatura.domain.ConstAndValues.ENTRYNUMBERIMAGES
import es.verdnatura.domain.ConstAndValues.ENTRYOBSERVATIONS
import es.verdnatura.domain.ConstAndValues.ENTRYTYPE
import es.verdnatura.domain.ConstAndValues.SUPPLIERNAME
import es.verdnatura.domain.ConstAndValues.WAREHOUSEFK
import es.verdnatura.presentation.base.BaseFragment
import es.verdnatura.presentation.common.*
import es.verdnatura.presentation.common.OnImageTrashClickListener
import es.verdnatura.presentation.common.OnImageUpdateClickListener
import es.verdnatura.presentation.common.OnOptionsSelectedListener
import es.verdnatura.presentation.common.OnPasillerosItemClickListener
import es.verdnatura.presentation.common.ToolBarAdapterTooltip
import es.verdnatura.presentation.view.component.CustomDialog
import es.verdnatura.presentation.view.component.CustomDialogList
import es.verdnatura.presentation.view.feature.packaging.adapter.ListImageAdapter
import es.verdnatura.presentation.view.feature.packaging.fragment.ObservFragment.ImageUtils.getDrawableFromImageUri
import es.verdnatura.presentation.view.feature.packaging.fragment.PackagingViewModel.PackagingViewModel
import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO
import kotlinx.coroutines.runBlocking
import java.io.File
import java.io.FileOutputStream
import java.io.IOException
import java.io.InputStream
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
@Suppress("UNUSED_ANONYMOUS_PARAMETER")
class ObservFragment(
@ -82,23 +101,30 @@ class ObservFragment(
when (item) {
iconNext.drawable -> {
runBlocking {
mobileApplication.dataStoreApp.editDataStoreKey(ENTRYNUMBERIMAGES,
mobileApplication.dataStoreApp.editDataStoreKey(
ENTRYNUMBERIMAGES,
if (listImages.isNullOrEmpty()) 0 else {
listImages!!.size
} )
mobileApplication.dataStoreApp.editDataStoreKey(ENTRYOBSERVATIONS,binding.observations.text.toString())
}
viewModel.entry_updateObserv(mobileApplication.dataStoreApp.readDataStoreKey(ENTRYID),binding.observations.text.toString())
)
mobileApplication.dataStoreApp.editDataStoreKey(
ENTRYOBSERVATIONS,
binding.observations.text.toString()
)
}
viewModel.entry_updateObserv(
mobileApplication.dataStoreApp.readDataStoreKey(
ENTRYID
), binding.observations.text.toString()
)
ma.onPasillerosItemClickListener(
PasillerosItemVO(title = getString(R.string.titlePackagingSummary)),
getString(R.string.titlePackagingSummary)
)
}
}
}
})
@ -152,7 +178,6 @@ class ObservFragment(
launcher.launch(config)
}
}
override fun observeViewModel() {
@ -167,19 +192,30 @@ class ObservFragment(
//http://localhost:3000/api/Entries/1/uploadFile?warehouseId=1&companyId=442&dmsTypeId=21&reference=1&description
// ="Example description"&hasFile=false (tiene que ser de tipo Multipart y llevar adjunto un fichero)
override fun OnImageUpdateClickListener(item: Any) {
println("a subir imagen")
/* viewModel.entry_uploadPhotoSalix(
val drawable = getDrawableFromImageUri(requireContext(), (item as Image).uri)
val bitmap = drawable!!.toBitmap()
viewModel.entry_uploadPhotoSalix(
idEntry = mobileApplication.dataStoreApp.readDataStoreKey<Int>("ENTRYID"),
warehouseId = mobileApplication.dataStoreApp.readDataStoreKey<Int>(
WAREHOUSEFK),
WAREHOUSEFK
),
companyId = 442,
dmsTypeId = 21,
reference = mobileApplication.dataStoreApp.readDataStoreKey<String>(ENTRYID).toString(),
dmsTypeId = 27,
reference = mobileApplication.dataStoreApp.readDataStoreKey<Int>(
ENTRYID
).toString(),
description = "Entry id",
hasFile = false,
file= MultipartBody.Part
)*/
urlImage = saveBitmapAsTempFile(requireContext(), bitmap)
)
}
}, object : OnImageTrashClickListener {
override fun OnImageTrashClickListener(item: Any) {
d("VERDNATURA::", "Seleccionado trash" + (item as Image).name)
@ -194,5 +230,55 @@ class ObservFragment(
LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
binding.listImagesRecycler.layoutManager = layoutManager
}
private fun saveBitmapAsTempFile(context: Context, bitmap: Bitmap): String {
val timeStamp = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(Date())
val fileName = "IMG_$timeStamp"
println("urlImage tmp fileName ${fileName}")
val storageDir = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES)
val tempFile = File.createTempFile(fileName, ".jpg", storageDir)
println("urlImage tmp ${tempFile}")
return try {
val fileOutputStream = FileOutputStream(tempFile)
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream)
fileOutputStream.close()
println("urlImage tmp Absol ${tempFile.absolutePath}")
tempFile.absolutePath
} catch (e: IOException) {
e.printStackTrace()
""
}
}
object ImageUtils {
fun getDrawableFromImageUri(context: Context, imageUri: Uri): Drawable? {
return try {
// Obtener el InputStream de la URI
val inputStream: InputStream? = context.contentResolver.openInputStream(imageUri)
// Convertir el InputStream a un Bitmap
val bitmap: Bitmap? = BitmapFactory.decodeStream(inputStream)
// Convertir el Bitmap a un Drawable
val drawable = bitmap?.let { BitmapDrawable(context.resources, it) }
// Cerrar el InputStream
inputStream?.close()
// Retornar el Drawable
drawable
} catch (e: Exception) {
e.printStackTrace()
null
}
}
}
}

View File

@ -8,6 +8,7 @@ import android.widget.ImageView
import androidx.recyclerview.widget.LinearLayoutManager
import es.verdnatura.R
import es.verdnatura.databinding.FragmentPackagingCountBinding
import es.verdnatura.domain.notNull
import es.verdnatura.presentation.base.BaseFragment
import es.verdnatura.presentation.common.OnEditSubQuantityListener
import es.verdnatura.presentation.common.OnImageTrashClickListener
@ -42,11 +43,11 @@ class PackagingCountFragment(
override fun getLayoutId(): Int = R.layout.fragment_packaging_count
override fun init() {
viewModel.getItemsPackaging(
mobileApplication.dataStoreApp.readDataStoreKey("SUPPLIERID"), mobileApplication.dataStoreApp.readDataStoreKey("ENTRYID")
mobileApplication.dataStoreApp.readDataStoreKey("SUPPLIERID"),
mobileApplication.dataStoreApp.readDataStoreKey("ENTRYID")
)
customDialogInput = CustomDialogInput(requireContext())
customDialog = CustomDialog(requireContext())
@ -98,19 +99,24 @@ class PackagingCountFragment(
}
override fun observeViewModel() {
with(viewModel) {
entryAdd.observe(viewLifecycleOwner) {
loadEntryAdd.observe(viewLifecycleOwner) { event ->
event.getContentIfNotHandled().notNull {
//entryAdd.observe(viewLifecycleOwner) {
if (it.isError) {
ma.messageWithSound(it.errorMessage, true, true)
} else {
ma.messageWithSound(it.errorMessage, false, true)
ma.messageWithSound(it.errorMessage, false, true, isToasted = false)
viewModel.getItemsPackaging(
mobileApplication.dataStoreApp.readDataStoreKey("SUPPLIERID"), mobileApplication.dataStoreApp.readDataStoreKey("ENTRYID"))
mobileApplication.dataStoreApp.readDataStoreKey("SUPPLIERID"),
mobileApplication.dataStoreApp.readDataStoreKey("ENTRYID")
)
}
}
}
@ -121,7 +127,6 @@ class PackagingCountFragment(
override fun OnImageUpdateClickListener(item: Any) {
showCustomDialog("quantity", item as ItemSupplier)
}
}, object : OnImageTrashClickListener {
@ -157,7 +162,8 @@ class PackagingCountFragment(
requireActivity().hideKeyboard()
}
viewModel.entry_addFromBuy(
mobileApplication.dataStoreApp.readDataStoreKey<Int>("ENTRYID"), item = item.id!!.toInt(),
mobileApplication.dataStoreApp.readDataStoreKey<Int>("ENTRYID"),
item = item.id!!.toInt(),
(if (mobileApplication.dataStoreApp.readDataStoreKey<String>("ENTRYTYPE") == "Rec") {
(item.printedStickers.plus(customDialogInput.getValue().toInt()))
} else {
@ -178,6 +184,7 @@ class PackagingCountFragment(
customDialogInput.currentFocus
customDialogInput.setFocusText()
}
"delete" -> {
customDialog.setTitle(getString(R.string.deleteEntryReviewed))
.setDescription(getString(R.string.sure))
@ -189,9 +196,13 @@ class PackagingCountFragment(
) {
customDialog.cancel()
customDialog.dismiss()
println("entryID - ")
println("entryID ${item.id}")
viewModel.entry_addFromBuy(
mobileApplication.dataStoreApp.readDataStoreKey("ENTRYID"), item = item.id!!.toInt(),
0
mobileApplication.dataStoreApp.readDataStoreKey<Int>("ENTRYID"),
item = item.id!!.toInt(),
printedStickers = 0
)
}
@ -199,7 +210,6 @@ class PackagingCountFragment(
customDialog.cancel()
customDialog.dismiss()
}
.show()
}

View File

@ -103,7 +103,7 @@ class PackagingSummaryFragment(
itemSupplierList.observe(viewLifecycleOwner) {
var mySummaryList = it.list.filter { it.quantity > 0 }
var mySummaryList = it.list.filter { it.printedStickers > 0 }
adapteritemsupplier =
ItemSupplierAdapter(mySummaryList, null, null, null, showItems = false)
binding.itemsupplierRecyclerview.adapter = adapteritemsupplier

View File

@ -4,6 +4,7 @@ import android.content.Context
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.map
import es.verdnatura.domain.SalixCallback
import es.verdnatura.domain.SilexCallback
import es.verdnatura.presentation.base.BaseViewModel
import es.verdnatura.presentation.base.getMessageFromAllResponse
@ -18,8 +19,11 @@ import es.verdnatura.presentation.view.feature.packaging.model.SupplierList
import es.verdnatura.presentation.view.feature.packaging.model.itemSupplierList
import es.verdnatura.presentation.view.feature.packaging.model.notificationQueue
import es.verdnatura.presentation.view.feature.packaging.model.obervationEntry
import okhttp3.MediaType
import okhttp3.MultipartBody
import okhttp3.RequestBody
import retrofit2.Response
import java.io.File
class PackagingViewModel(val context: Context) : BaseViewModel(context) {
@ -97,7 +101,7 @@ class PackagingViewModel(val context: Context) : BaseViewModel(context) {
fun uploadFile(entry: EntrySalix) {
salix.add_entry(entry)
.enqueue(object :
SilexCallback<EntrySalix>(context) {
SalixCallback<EntrySalix>(context) {
override fun onError(t: Throwable) {
_entry.value = EntrySalix(
isError = true,
@ -126,7 +130,13 @@ class PackagingViewModel(val context: Context) : BaseViewModel(context) {
}
fun getEntries_fromSupplier(supplier: Int) {
salix.getEntries_fromSupplier("""{"where": {"supplierFk": "$supplier"},"limit":5, "order":"created DESC"}""")
/* salix.getEntries_fromSupplier("""{"where": {
"supplierFk": "$supplier",
"created": { "gte": "$yesterday" }
},"limit":5, "order":"created DESC"}""".trimMargin())*/
salix.getEntries_fromSupplier("""{"where": {"supplierFk": "$supplier"},"limit":5, "order":"created ASC"}""")
.enqueue(object :
SilexCallback<List<EntrySalix>>(context) {
override fun onError(t: Throwable) {
@ -267,8 +277,19 @@ class PackagingViewModel(val context: Context) : BaseViewModel(context) {
reference: String,
description: String,
hasFile: Boolean,
file: MultipartBody.Part
urlImage: String,
) {
println("urlImage + $urlImage")
println("urlImage + ${File(urlImage)}")
val file = File(urlImage)
println("urlImage + ${file.name}")
val fileRequestBody: RequestBody = RequestBody.create(MediaType.parse("image/jpeg"), file)
salix.uploadEntryPhoto(
idEntry,
warehouseId,
@ -277,14 +298,17 @@ class PackagingViewModel(val context: Context) : BaseViewModel(context) {
reference,
description,
hasFile,
file
file = MultipartBody.Part.createFormData(
"file", file.name, fileRequestBody
)
)
.enqueue(object : SilexCallback<Any>(context) {})
}
fun entry_addFromBuy(id: Number, item: Number, printedStickers: Number) {
println("entryID -- addFromBuy")
salix.addFromBuy(id, item, printedStickers)
.enqueue(object : SilexCallback<EntrySalix>(context) {
.enqueue(object : SalixCallback<EntrySalix>(context) {
override fun onError(t: Throwable) {
_entryAdd.value = EntrySalix(
isError = true,
@ -341,7 +365,7 @@ class PackagingViewModel(val context: Context) : BaseViewModel(context) {
fun entry_addFromPackaging(supplier: Int, isPackaging: Boolean) {
salix.addFromPackaging(supplier, isPackaging)
.enqueue(object : SilexCallback<EntrySalix>(context) {
.enqueue(object : SalixCallback<EntrySalix>(context) {
override fun onError(t: Throwable) {
_entryAdd.value = EntrySalix(
isError = true,

View File

@ -6,10 +6,10 @@ import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import es.verdnatura.R
import es.verdnatura.databinding.FragmentPackagingBinding
import es.verdnatura.domain.isoToString
import es.verdnatura.domain.notNull
import es.verdnatura.presentation.base.BaseFragment
import es.verdnatura.presentation.common.OnPasillerosItemClickListener
import es.verdnatura.presentation.common.convertToDateString
import es.verdnatura.presentation.view.component.CustomDialog
import es.verdnatura.presentation.view.feature.inventario.fragment.SearchSupplierModel
import es.verdnatura.presentation.view.feature.packaging.fragment.PackagingViewModel.PackagingViewModel
@ -273,7 +273,7 @@ class SupplierFragment(
try {
entries.add(
SearchSupplierModel(
entry.id.toString() + "->" + convertToDateString(entry.created),
entry.id.toString() + "->" + (entry.created).isoToString(returnOnlyDate = true),
id = entry.id.toString()
)
)

View File

@ -57,12 +57,20 @@ class PalletScanFragment(
with(viewModel) {
responsePalletGet.observe(viewLifecycleOwner) {
ma.messageWithSound(message = "", isError = false, isPlayed = true, isToasted = false)
if (it.truckFk == 0) {
ma.messageWithSound(
message = getString(R.string.palletNotFound),
isError = true,
isPlayed = true,
isToasted = false
)
}else{
ma.onComprobarPalletFromPalletScan(
ItemExpeditionTruckVO(it.truckFk), ItemPalletVO(Pallet = itemScaned)
)
customDialogList.dismiss()
}
}
}

View File

@ -6,6 +6,7 @@ import androidx.lifecycle.MutableLiveData
import es.verdnatura.domain.SalixCallback
import es.verdnatura.domain.formatWithQuotes
import es.verdnatura.presentation.base.BaseViewModel
import es.verdnatura.presentation.view.feature.paletizador.model.ItemExpedition
import es.verdnatura.presentation.view.feature.paletizador.model.ItemExpeditionTruckSalix
import retrofit2.Response
@ -35,8 +36,13 @@ class PalletScanViewModel(val context: Context) : BaseViewModel(context) {
.enqueue(object : SalixCallback<List<ItemExpeditionTruckSalix>>(context) {
override fun onSuccess(response: Response<List<ItemExpeditionTruckSalix>>) {
if (response.body()!!.isNotEmpty()) {
_responsePalletGet.value =
response.body()?.get(0)
} else {
_responsePalletGet.value = ItemExpeditionTruckSalix(0, ItemExpedition(0))
}
}
})