feat: refs #5443 refactor

This commit is contained in:
Sergio De la torre 2024-10-16 11:39:23 +02:00
parent 02306e8351
commit abab532379
2 changed files with 125 additions and 100 deletions

View File

@ -146,7 +146,7 @@ class CollectionFragment(
mperror = MediaPlayer.create((activity as MainActivity), R.raw.error)
mpok = MediaPlayer.create((activity as MainActivity), R.raw.ok)
if (type.equals(CONTROLADOR)) {
if (type.equals(CONTROLADOR) && collection.collectionFk != 0) {
//sergio: comprueba si viene de la pantalla de controlador
//Tarea #4280
viewModel.ticketIsOutClosureZone(
@ -162,7 +162,7 @@ class CollectionFragment(
}
if (collection.tickets.isEmpty()) {
if (collection.tickets.isEmpty() && collection.collectionFk != 0) {
viewModel.collectionTicketGet(
collection.collectionFk,
mobileApplication.dataStoreApp.readDataStoreKey(SECTORFK),
@ -179,7 +179,6 @@ class CollectionFragment(
}
override fun init() {
customDialogList = CustomDialogList(requireContext())
customDialogInput = CustomDialogInput(requireContext())
customDialog = CustomDialog(requireContext())
@ -204,12 +203,15 @@ class CollectionFragment(
private fun setToolBar() {
binding.mainToolbar.toolbarSubtitle.visibility = VISIBLE
binding.mainToolbar.toolbarIcons.visibility = VISIBLE
binding.mainToolbar.toolbarIcons.visibility =
if (type == CONTROLADOR && collection.collectionFk == 0) GONE else VISIBLE
binding.mainToolbar.backButton.visibility = VISIBLE
collection.collectionFk.let {
binding.mainToolbar.toolbarTitle.text = collection.collectionFk.toString()
binding.mainToolbar.toolbarTitle.text =
if (collection.collectionFk != 0) collection.collectionFk.toString() else {
getString(R.string.controlticket)
}
}
val listIcons: ArrayList<ImageView> = ArrayList()
val iconPrint = ImageView(context)
iconPrint.setImageResource(R.drawable.ic_print_black_24dp)
@ -406,7 +408,7 @@ class CollectionFragment(
binding.scanInput.setOnEditorActionListener { v, actionId, event ->
if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) {//ID=0 ACTION_NEXT ID=5 ACTION_UNESPECEFIED)
if (!binding.scanInput.text.toString().isNullOrEmpty()) {
binding.mainToolbar.toolbarIcons.visibility = VISIBLE
//sergio:para ver si ha marcado dos veces el mismo ticket
binding.scanInput.setText(textScanned_filterDouble(binding.scanInput.text!!.toString()))
@ -438,7 +440,6 @@ class CollectionFragment(
}
buttonPushedGetCollection = false
}
binding.scanInput.setText("")
hideKeyboards()
@ -525,18 +526,19 @@ class CollectionFragment(
}
})
responseParking.observe(viewLifecycleOwner, Observer {
loadParking.observe(viewLifecycleOwner) { event ->
event.getContentIfNotHandled().notNull { it ->
if (!goBack) {
if (!goBack) {
ma.messageWithSound(
if (it.isError) it.errorMessage else getString(R.string.Aparcado),
it.isError,
true
)
ma.messageWithSound(
if (it.isError) it.errorMessage else getString(R.string.Aparcado),
it.isError,
true
)
}
}
})
}
responsePrint.observe(viewLifecycleOwner, Observer {
@ -575,22 +577,24 @@ class CollectionFragment(
}
responseSaleGroup.observe(viewLifecycleOwner, Observer {
loadResponseSaleGroup.observe(viewLifecycleOwner) { event ->
event.getContentIfNotHandled().notNull {
if (it.isError) {
if (it.isError) {
ma.messageWithSound(it.errorMessage, true, true)
} else {
ma.messageWithSound(getString(R.string.previousCollected), false, true)
ma.messageWithSound(it.errorMessage, true, true)
} else {
ma.messageWithSound(getString(R.string.previousCollected), false, true)
viewModel.collectionTicketGet(
collection.collectionFk,
mobileApplication.dataStoreApp.readDataStoreKey(SECTORFK),
print = "0",
type
)
viewModel.collectionTicketGet(
collection.collectionFk,
mobileApplication.dataStoreApp.readDataStoreKey(SECTORFK),
print = "0",
type
)
}
}
})
}
placementSuppleyList.observe(viewLifecycleOwner, Observer {
if (!goBack) printShelvingResult(it)
@ -603,33 +607,34 @@ class CollectionFragment(
goBack = false
})
responseNew.observe(viewLifecycleOwner, Observer {
loadAddNew.observe(viewLifecycleOwner) { event ->
event.getContentIfNotHandled().notNull { it ->
// if (!goBack) {
if (it.isError) {
customDialog.setTitle(getString(R.string.disponibility))
.setDescription(getString(R.string.errorCollectionNew) + it.errorMessage)
.setKoButton(getString(R.string.close)) {
scanRequest()
customDialog.dismiss()
}.show()
} else {
// if (!goBack) {
if (it.isError) {
customDialog.setTitle(getString(R.string.disponibility))
.setDescription(getString(R.string.errorCollectionNew) + it.errorMessage)
.setKoButton(getString(R.string.close)) {
scanRequest()
customDialog.dismiss()
}.show()
} else {
if (!goBack) {
if (!goBack) {
viewModel.collectionTicketGet(
collection.collectionFk,
mobileApplication.dataStoreApp.readDataStoreKey(SECTORFK),
print = "0",
type
)
viewModel.collectionTicketGet(
collection.collectionFk,
mobileApplication.dataStoreApp.readDataStoreKey(SECTORFK),
print = "0",
type
)
}
}
goBack = false
}
goBack = false
})
}
responseCode.observe(viewLifecycleOwner, Observer {
@ -655,71 +660,76 @@ class CollectionFragment(
goBack2 = false
})
responseTicketState.observe(viewLifecycleOwner) {
loadTicketState.observe(viewLifecycleOwner) { event ->
event.getContentIfNotHandled().notNull { it ->
if (!goBack) {
if ((it.code == "ON_CHECKING" || it.code == "CHECKED") && it.user.id != mobileApplication.userId) {
var customDialogWarningChecking = CustomDialog(requireContext())
customDialogWarningChecking.setTitle(getString(R.string.info))
customDialogWarningChecking.setDescription(
if (it.code == "ON_CHECKING") {
getString(R.string.checkingByUser, it.user.username)
} else {
getString(R.string.checkedByUser, it.user.username)
}
).setOkButton(getString(R.string.aware)) {
customDialogWarningChecking.dismiss()
}.show()
if (!goBack) {
if ((it.code == "ON_CHECKING" || it.code == "CHECKED") && it.user.id != mobileApplication.userId) {
var customDialogWarningChecking = CustomDialog(requireContext())
customDialogWarningChecking.setTitle(getString(R.string.info))
customDialogWarningChecking.setDescription(
if (it.code == "ON_CHECKING") {
getString(R.string.checkingByUser, it.user.username)
} else {
getString(R.string.checkedByUser, it.user.username)
}
).setOkButton(getString(R.string.aware)) {
customDialogWarningChecking.dismiss()
}.show()
}
}
}
}
responseTicketClosure.observe(viewLifecycleOwner, Observer {
loadTicketClousure.observe(viewLifecycleOwner) { event ->
event.getContentIfNotHandled().notNull { it ->
if (!goBack) {
if (it.response.toBoolean()) {
var customDialogWarning = CustomDialog(requireContext())
customDialogWarning.setTitle(getString(R.string.urgentWarning))
customDialogWarning.setDescription(getString(R.string.ticketWarning))
.setOkButton(getString(R.string.aware)) {
customDialogWarning.dismiss()
}.show()
}
}
})
responseIncQuantity.observe(viewLifecycleOwner, Observer {
if (it.isError) {
ma.messageWithSound(it.errorMessage, isError = true, true)
} else {
if (!goBack) {
incresaseSuccesful()
} else {
goBack = false
if (it.response.toBoolean()) {
var customDialogWarning = CustomDialog(requireContext())
customDialogWarning.setTitle(getString(R.string.urgentWarning))
customDialogWarning.setDescription(getString(R.string.ticketWarning))
.setOkButton(getString(R.string.aware)) {
customDialogWarning.dismiss()
}.show()
}
}
}
}
})
loadIncQuantity.observe(viewLifecycleOwner) { event ->
event.getContentIfNotHandled().notNull { it ->
responseSaleMistakeAdd.observe(viewLifecycleOwner, Observer {
if (!goBack) {
if (it.isError) {
ma.messageWithSound(it.errorMessage, isError = true, true)
} else {
ma.messageWithSound(
getString(R.string.errorRegistered), isError = false, false
)
goBack = true
if (!goBack) {
incresaseSuccesful()
} else {
goBack = false
}
}
}
})
}
loadSaleMistakeAdd.observe(viewLifecycleOwner) { event ->
event.getContentIfNotHandled().notNull { it ->
if (!goBack) {
if (it.isError) {
ma.messageWithSound(it.errorMessage, isError = true, true)
} else {
ma.messageWithSound(
getString(R.string.errorRegistered), isError = false, false
)
goBack = true
}
}
}
}
mistakeList.observe(viewLifecycleOwner, Observer {

View File

@ -6,6 +6,8 @@ import android.graphics.drawable.Drawable
import android.media.MediaPlayer
import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.os.Parcelable
import android.text.InputType
import android.util.Log
@ -123,6 +125,7 @@ class CollectionFragmentPicker(
private var itemShelvingTracking_mark: Int = 0
private var recylerViewState: Parcelable? = null
private var isScanned: Boolean? = null
private var myPosition: Int = 0
private lateinit var myGroupList: List<SaleVO>
private var canChangeState = true
@ -288,6 +291,9 @@ class CollectionFragmentPicker(
when (type) {
CONTROLADOR -> markLine(indice, type)
SACADOR -> {
//jose antonio
myPosition = myGroupList.indexOfFirst { it.saleGroupFk == saleGroupScanned }
println("previa $saleGroupScanned posicion $myPosition")
viewModel.saleTrackingAddPreparedSaleGroup(
saleGroupScanned.toInt()
)
@ -546,7 +552,7 @@ class CollectionFragmentPicker(
ma.messageWithSound(it.errorMessage, true, true)
} else {
ma.messageWithSound(getString(R.string.previousCollected), false, true)
viewModel.collectionTicketGet(
collection.collectionFk,
mobileApplication.dataStoreApp.readDataStoreKey(SECTORFK),
@ -835,6 +841,7 @@ class CollectionFragmentPicker(
} else {
// pintar línea
saleAdapter!!.notifyDataSetChanged()
myPosition = storedPosition
ReviewQuantityForRefreshingAndSorting(
sales[storedPosition].quantity!!.toInt(),
@ -1378,6 +1385,13 @@ class CollectionFragmentPicker(
}
isMarking = true
setTotalLines()
val handler = Handler(Looper.getMainLooper())
handler.postDelayed({
val inputMethodManager =
requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow(binding.scanInput.windowToken, 0)
}, 300L)
}
private fun checkStateParent() {
@ -1415,7 +1429,7 @@ class CollectionFragmentPicker(
}
private fun setListPosition(position: Int, isFromBack: Boolean) {
lm!!.scrollToPositionWithOffset(storedBackPosition, 0)
lm!!.scrollToPositionWithOffset(myPosition, 0)
// lm!!.scrollToPositionWithOffset(position, 0)
/* storedPosition = position
@ -1523,6 +1537,7 @@ class CollectionFragmentPicker(
}
}
storedBackPosition = position
myPosition = position
setListPosition(position, false)
if (type != PRECHECKER) {