feat: refs#7823 selectPrinterFreely

This commit is contained in:
Sergio De la torre 2025-03-24 11:58:12 +01:00
parent 5153bf62a2
commit 983043382d
4 changed files with 52 additions and 33 deletions

View File

@ -304,11 +304,7 @@ class AjustesFragment :
getString(R.string.closeSession) -> ma.onMyBackPressed()
getString(R.string.printerLabel) -> {
messagePrinter = getString(R.string.SelectPrinter)
viewModel.printerGet(
mobileApplication.dataStoreApp.readDataStoreKey(
SECTORFK
)
)
viewModel.printerGet()
}
getString(R.string.vehicleControl) -> ma.onPasillerosItemClickListener(
@ -352,7 +348,7 @@ class AjustesFragment :
event.getContentIfNotHandled().notNull {
messagePrinter =
getString(R.string.SelectPrinter) + "\n" + getString(R.string.printerRemoved)
viewModel.printerGet(mobileApplication.dataStoreApp.readDataStoreKey(SECTORFK))
viewModel.printerGet()
}
}
@ -440,23 +436,23 @@ class AjustesFragment :
}
val array = arrayOfNulls<String>(listPrinters.size)
showDialogForAll(listPrinters.toArray(array), messagePrinter ?: "")
// showDialogForAll(listPrinters.toArray(array), messagePrinter ?: "")
//Tarea7823
/* val listColorsElements = printersList.mapIndexed { _, printer ->
if (printer.sector?.id == mobileApplication.dataStoreApp.readDataStoreKey<Int>(
SECTORFK
)
) printer.id else null
}.filterNotNull()
val listColorsElements = printersList.mapIndexed { _, printer ->
if (printer.sector?.id == mobileApplication.dataStoreApp.readDataStoreKey<Int>(
SECTORFK
)
) printer.id else null
}.filterNotNull()
setSearchable(printersList.map {
NameWithId(
id = it.id,
name = it.name
)
} as MutableList<NameWithId>,
type = "printer",
listColorsElements = listColorsElements)*/
setSearchable(printersList.map {
NameWithId(
id = it.id,
name = it.name
)
} as MutableList<NameWithId>,
type = "printer",
listColorsElements = listColorsElements)
} else {
viewModel.settingsItem[2].selected = getString(R.string.noprinter)

View File

@ -156,14 +156,11 @@ class AjustesViewModel(val context: Context) : BaseViewModel(context) {
})
}
fun printerGet(sectorFk: Int) {
fun printerGet() {
//Tarea 7823*/
salix.getprinters(
"""{"fields":["id","name","sectorFk"],"where":{"sectorFk":$sectorFk,"isLabeler":{"neq":false}},"include": [ { "relation": "sector", "scope": { "fields": ["backupPrinterFk"]}}]}"""
"""{"fields":["id","name","sectorFk"],"where":{"isLabeler":{"neq":false}},"include": [ { "relation": "sector", "scope": { "fields": ["backupPrinterFk"]}}]}"""
).enqueue(object : SalixCallback<MutableList<Printers>>(context) {
//Tarea 7823
/* salix.getprinters(
"""{"fields":["id","name","sectorFk"],"where":{"isLabeler":{"neq":false}},"include": [ { "relation": "sector", "scope": { "fields": ["backupPrinterFk"]}}]}"""
).enqueue(object : SalixCallback<MutableList<Printers>>(context) {*/
override fun onSuccess(response: Response<MutableList<Printers>>) {
_printerList.value = response.body()?.let { PrintersList(it) }
}

View File

@ -41,6 +41,7 @@ import es.verdnatura.presentation.view.feature.articulo.model.ItemCardRowVO
import es.verdnatura.presentation.view.feature.articulo.model.ItemCardVO
import es.verdnatura.presentation.view.feature.articulo.model.ItemPackingType
import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO
import kotlinx.coroutines.runBlocking
import org.json.JSONObject
class ItemCardFragment(
@ -140,15 +141,21 @@ class ItemCardFragment(
},
onPrintChange = { text ->
if (itemScanIsQr(text)) {
val labeler = itemScanValue(
text,
arrayOf("printer"),
"id"
).toString().toInt()
viewModel.operatorUpdate(
workerFk = mobileApplication.userId!!,
labelerFK = itemScanValue(
text,
arrayOf("printer"),
"id"
).toString().toLong()
labelerFK = labeler
)
runBlocking {
mobileApplication.dataStoreApp.editDataStoreKey(
PRINTERFK,
labeler
)
}
} else {
ma.messageWithSound(
getString(R.string.qrPrinterNotvalid),
@ -364,6 +371,17 @@ class ItemCardFragment(
buyToPrint = it
}
}
loadChangePrinterResponse.observe(viewLifecycleOwner) { event ->
event.getContentIfNotHandled().notNull {
runBlocking {
mobileApplication.dataStoreApp.editDataStoreKey(
PRINTERFK,
it
)
}
}
}
}
}

View File

@ -56,6 +56,10 @@ class ItemCardViewModel(var context: Context) : BaseViewModel(context) {
val buyUltimateResponse: LiveData<Long> = _buyUltimateResponse
val loadBuyUltimateResponse: LiveData<Event<Long>> = _buyUltimateResponse.map { Event(it) }
private val _changePrinterResponse by lazy { MutableLiveData<Int>() }
val changePrinterResponse: LiveData<Int> = _changePrinterResponse
val loadChangePrinterResponse: LiveData<Event<Int>> = _changePrinterResponse.map { Event(it) }
fun getItemCard(
itemFk: Number,
warehouseFk: Int,
@ -75,6 +79,10 @@ class ItemCardViewModel(var context: Context) : BaseViewModel(context) {
operatorUseCase.updateOperator(workerFk = workerFk, hashMapOf("labelerFk" to labelerFK))
.enqueue(object : SalixCallback<Unit>(context) {
override fun onSuccess(response: Response<Unit>) {
super.onSuccess(response)
_changePrinterResponse.value = labelerFK.toInt()
}
})
}