feat printerEmergency refs #7539
This commit is contained in:
parent
687bd6fc4b
commit
54b7907866
|
@ -319,7 +319,7 @@ interface SalixService {
|
||||||
fun getprinters(
|
fun getprinters(
|
||||||
@Query("filter") filter: Any?
|
@Query("filter") filter: Any?
|
||||||
):
|
):
|
||||||
Call<List<Printers>>
|
Call<MutableList<Printers>>
|
||||||
|
|
||||||
@GET("Collections/getSales")
|
@GET("Collections/getSales")
|
||||||
fun getSalesFromTicketOrCollection(
|
fun getSalesFromTicketOrCollection(
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
package es.verdnatura.presentation.view.feature.ajustes.fragment
|
package es.verdnatura.presentation.view.feature.ajustes.fragment
|
||||||
|
|
||||||
import android.app.AlertDialog
|
import android.app.AlertDialog
|
||||||
|
import android.graphics.Color
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.widget.ArrayAdapter
|
||||||
|
import android.widget.TextView
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import es.verdnatura.MobileApplication
|
import es.verdnatura.MobileApplication
|
||||||
import es.verdnatura.R
|
import es.verdnatura.R
|
||||||
|
@ -38,7 +42,7 @@ class AjustesFragment :
|
||||||
|
|
||||||
private lateinit var customDialog: CustomDialog
|
private lateinit var customDialog: CustomDialog
|
||||||
private var sectorListVO: List<SectorItemVO> = listOf()
|
private var sectorListVO: List<SectorItemVO> = listOf()
|
||||||
private var printersList: List<Printers> = listOf()
|
private var printersList: MutableList<Printers> = mutableListOf()
|
||||||
private var trainsList: List<Train> = listOf()
|
private var trainsList: List<Train> = listOf()
|
||||||
private var settingsAdapter: SettingsAdapter? = null
|
private var settingsAdapter: SettingsAdapter? = null
|
||||||
private var isWorkerAllowed: Boolean = false
|
private var isWorkerAllowed: Boolean = false
|
||||||
|
@ -274,7 +278,28 @@ class AjustesFragment :
|
||||||
val builder = AlertDialog.Builder(this.context)
|
val builder = AlertDialog.Builder(this.context)
|
||||||
builder.setTitle(title)
|
builder.setTitle(title)
|
||||||
|
|
||||||
builder.setItems(array) { _, which ->
|
val adapter = object :
|
||||||
|
ArrayAdapter<String>(requireContext(), android.R.layout.simple_list_item_1, array) {
|
||||||
|
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
||||||
|
val view = super.getView(position, convertView, parent)
|
||||||
|
val textView = view.findViewById<TextView>(android.R.id.text1)
|
||||||
|
|
||||||
|
val positionPrinterEmergency =
|
||||||
|
printersList.indexOfFirst { printer -> printer.sector?.backupPrinterFk == printer.id }
|
||||||
|
|
||||||
|
if (position == positionPrinterEmergency) {
|
||||||
|
textView.setTextColor(Color.RED)
|
||||||
|
} else {
|
||||||
|
textView.setTextColor(Color.BLACK)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return view
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
builder.setAdapter(adapter) { _, which ->
|
||||||
val selected = array[which]
|
val selected = array[which]
|
||||||
when (title) {
|
when (title) {
|
||||||
getString(R.string.settingsTitleItemPacking) -> {
|
getString(R.string.settingsTitleItemPacking) -> {
|
||||||
|
@ -377,28 +402,15 @@ class AjustesFragment :
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
printersList.forEach {
|
val printer = printersList.find { it.name == selected }
|
||||||
if (it.name == selected) {
|
if (printer != null) {
|
||||||
|
if (printer.sector?.backupPrinterFk == printer.id) {
|
||||||
runBlocking {
|
showWarningPrinter(printer.name, printer.id)
|
||||||
mobileApplication.dataStoreApp.editDataStoreKey(
|
} else {
|
||||||
PRINTERNAME, it.name
|
savePrinter(printer.name, printer.id)
|
||||||
)
|
|
||||||
mobileApplication.dataStoreApp.editDataStoreKey(PRINTERFK, it.id)
|
|
||||||
}
|
|
||||||
|
|
||||||
viewModel.settingsItem[2].selected = it.name
|
|
||||||
viewModel.workerUpdateOperatorSalix(
|
|
||||||
entity = "printer",
|
|
||||||
workerFk = mobileApplication.userId!!,
|
|
||||||
sectorFk = mobileApplication.dataStoreApp.readDataStoreKey(SECTORFK),
|
|
||||||
labelerFk = it.id
|
|
||||||
)
|
|
||||||
settingsAdapter!!.notifyItemChanged(2)
|
|
||||||
|
|
||||||
return@forEach
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
printersList.clear()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -407,4 +419,47 @@ class AjustesFragment :
|
||||||
dialog.show()
|
dialog.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun savePrinter(name: String, id: Int) {
|
||||||
|
runBlocking {
|
||||||
|
mobileApplication.dataStoreApp.editDataStoreKey(
|
||||||
|
PRINTERNAME, name
|
||||||
|
)
|
||||||
|
mobileApplication.dataStoreApp.editDataStoreKey(
|
||||||
|
PRINTERFK,
|
||||||
|
id
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
viewModel.settingsItem[2].selected = name
|
||||||
|
viewModel.workerUpdateOperatorSalix(
|
||||||
|
entity = "printer",
|
||||||
|
workerFk = mobileApplication.userId!!,
|
||||||
|
sectorFk = mobileApplication.dataStoreApp.readDataStoreKey(
|
||||||
|
SECTORFK
|
||||||
|
),
|
||||||
|
labelerFk = id
|
||||||
|
)
|
||||||
|
settingsAdapter!!.notifyItemChanged(2)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showWarningPrinter(name: String, id: Int) {
|
||||||
|
val customWarningPrinter = CustomDialog(requireContext())
|
||||||
|
|
||||||
|
customWarningPrinter.setTitle(getString(R.string.confirm))
|
||||||
|
.setDescription(
|
||||||
|
"La impresora seleccionada es solo para emergencias. ¿Estás seguro?"
|
||||||
|
)
|
||||||
|
|
||||||
|
.setOkButton(getString(R.string.yes)) {
|
||||||
|
customWarningPrinter.dismiss()
|
||||||
|
savePrinter(name, id)
|
||||||
|
|
||||||
|
}.setKoButton(getString(R.string.no)) {
|
||||||
|
customWarningPrinter.dismiss()
|
||||||
|
|
||||||
|
}
|
||||||
|
.show()
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -173,9 +173,9 @@ class AjustesViewModel(val context: Context) : BaseViewModel(context) {
|
||||||
|
|
||||||
fun printerGet(sectorFk: Int) {
|
fun printerGet(sectorFk: Int) {
|
||||||
salix.getprinters(
|
salix.getprinters(
|
||||||
"""{"fields":["id","name"],"where":{"sectorFk":$sectorFk,"isLabeler":{"neq":false}}}"""
|
"""{"fields":["id","name","sectorFk"],"where":{"sectorFk":$sectorFk,"isLabeler":{"neq":false}},"include": [ { "relation": "sector", "scope": { "fields": ["backupPrinterFk"]}}]}"""
|
||||||
).enqueue(object : SalixCallback<List<Printers>>(context) {
|
).enqueue(object : SalixCallback<MutableList<Printers>>(context) {
|
||||||
override fun onSuccess(response: Response<List<Printers>>) {
|
override fun onSuccess(response: Response<MutableList<Printers>>) {
|
||||||
_printerList.value = response.body()?.let { PrintersList(it) }
|
_printerList.value = response.body()?.let { PrintersList(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package es.verdnatura.presentation.view.feature.ajustes.model
|
package es.verdnatura.presentation.view.feature.ajustes.model
|
||||||
|
|
||||||
|
import es.verdnatura.presentation.view.feature.login.model.Sector
|
||||||
|
|
||||||
class AjustesItemVO(
|
class AjustesItemVO(
|
||||||
var id: Int,
|
var id: Int,
|
||||||
var title: String = "",
|
var title: String = "",
|
||||||
|
@ -21,12 +23,14 @@ class SectorListVO(
|
||||||
)
|
)
|
||||||
|
|
||||||
class PrintersList(
|
class PrintersList(
|
||||||
var list: List<Printers> = listOf()
|
var list: MutableList<Printers> = mutableListOf()
|
||||||
)
|
)
|
||||||
|
|
||||||
class Printers(
|
class Printers(
|
||||||
var id: Int,
|
var id: Int,
|
||||||
var name: String
|
var name: String,
|
||||||
|
var sector:Sector?
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
class WorkerPrintersList(
|
class WorkerPrintersList(
|
||||||
|
|
|
@ -10,12 +10,12 @@ class LoginSalixVO(
|
||||||
var errorMessage: String = ""
|
var errorMessage: String = ""
|
||||||
)
|
)
|
||||||
data class LoginApp(
|
data class LoginApp(
|
||||||
val user: String ,
|
val user: String,
|
||||||
val password: String,
|
val password: String,
|
||||||
val deviceId: Int?,
|
val deviceId: Int?,
|
||||||
val androidId:String,
|
val androidId: String,
|
||||||
val versionApp:String,
|
val versionApp: String,
|
||||||
val nameApp:String
|
val nameApp: String
|
||||||
|
|
||||||
)
|
)
|
||||||
data class LoginAppData(
|
data class LoginAppData(
|
||||||
|
@ -35,7 +35,7 @@ data class LoginAppData(
|
||||||
val version: String,
|
val version: String,
|
||||||
val vIsAuthorized: String,
|
val vIsAuthorized: String,
|
||||||
val vMessage: String,
|
val vMessage: String,
|
||||||
)
|
)
|
||||||
|
|
||||||
class DataUserSalix(
|
class DataUserSalix(
|
||||||
val id: Int? = null,
|
val id: Int? = null,
|
||||||
|
@ -77,7 +77,12 @@ class OperatorSalix(
|
||||||
var errorMessage: String = ""
|
var errorMessage: String = ""
|
||||||
)
|
)
|
||||||
|
|
||||||
data class Sector(val id: Int, val description: String, val warehouseFk: Int)
|
data class Sector(
|
||||||
|
val id: Int=0,
|
||||||
|
val description: String="",
|
||||||
|
val warehouseFk: Int=0,
|
||||||
|
val backupPrinterFk: Int?
|
||||||
|
)
|
||||||
data class Printer(val id: Int, val name: String)
|
data class Printer(val id: Int, val name: String)
|
||||||
data class Train(val id: Int, val name: String)
|
data class Train(val id: Int, val name: String)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue