refs #7042 feat:scanForSign

This commit is contained in:
Sergio De la torre 2024-04-19 09:48:48 +02:00
parent 92136fe797
commit daba43e915
1 changed files with 30 additions and 25 deletions

View File

@ -3,12 +3,10 @@ package es.verdnatura.presentation.view.feature.delivery.fragments
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.os.Build
import android.view.View import android.view.View
import android.view.inputmethod.EditorInfo import android.view.inputmethod.EditorInfo
import android.widget.ImageView import android.widget.ImageView
import android.widget.Toast import android.widget.Toast
import androidx.annotation.RequiresApi
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import es.verdnatura.R import es.verdnatura.R
@ -69,12 +67,12 @@ class LoadUnloadFragment(
override fun getLayoutId(): Int = R.layout.fragment_expedition_loadunload_delivery override fun getLayoutId(): Int = R.layout.fragment_expedition_loadunload_delivery
@RequiresApi(Build.VERSION_CODES.O)
override fun init() { override fun init() {
try { try {
route = JSONObject(entryPoint).get("route").toString().toInt() route = JSONObject(entryPoint).get("route").toString().toInt()
addressFk = JSONObject(entryPoint).get("address").toString().toInt() addressFk = JSONObject(entryPoint).get("address").toString().toInt()
} catch (ex: Exception) { } catch (ex: Exception) {
ex.message.toString().toast(requireContext())
} }
setEvents() setEvents()
setToolBar() setToolBar()
@ -89,7 +87,6 @@ class LoadUnloadFragment(
db = database(requireContext().applicationContext) db = database(requireContext().applicationContext)
} }
@RequiresApi(Build.VERSION_CODES.O)
private fun setToolBar() { private fun setToolBar() {
ma.hideBottomNavigation(View.GONE) ma.hideBottomNavigation(View.GONE)
binding.mainToolbar.toolbarTitle.visibility = View.VISIBLE binding.mainToolbar.toolbarTitle.visibility = View.VISIBLE
@ -110,10 +107,7 @@ class LoadUnloadFragment(
iconConfirm.setImageResource(R.drawable.ic_confirm) iconConfirm.setImageResource(R.drawable.ic_confirm)
iconSign.setImageResource(R.drawable.ic_sign) iconSign.setImageResource(R.drawable.ic_sign)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { iconConfirm.tooltipText = getTooltip(R.drawable.ic_confirm)
iconConfirm.tooltipText = getTooltip(R.drawable.ic_confirm)
}
listIcons.add( listIcons.add(
if (state == "DELIVERED") { if (state == "DELIVERED") {
iconSign iconSign
@ -162,7 +156,7 @@ class LoadUnloadFragment(
private fun setExpeditionsState(list: MutableList<ExpeditionInfoLoadUnload>, state: String) { private fun setExpeditionsState(list: MutableList<ExpeditionInfoLoadUnload>, state: String) {
scanning(false) scanning(false)
var mlist = mutableListOf<ExpeditionSalix>() val mlist = mutableListOf<ExpeditionSalix>()
for (l in list) { for (l in list) {
mlist.add( mlist.add(
ExpeditionSalix( ExpeditionSalix(
@ -174,8 +168,8 @@ class LoadUnloadFragment(
) )
) )
} }
var expeditionBack = hashMapOf("expeditions" to mlist as List<ExpeditionSalix>) val expeditionBack = hashMapOf("expeditions" to mlist as List<ExpeditionSalix>)
if (list.filter { it.code == state }.isNotEmpty()) { if (list.any { it.code == state }) {
if (list.filter { it.code == state }.size == list.size) { if (list.filter { it.code == state }.size == list.size) {
viewModel.expeditionStateAddSalix(expeditionBack) viewModel.expeditionStateAddSalix(expeditionBack)
counterCalls = 1 counterCalls = 1
@ -185,19 +179,27 @@ class LoadUnloadFragment(
alertDialog.setMessage(getString(R.string.expeditionTotal)) alertDialog.setMessage(getString(R.string.expeditionTotal))
alertDialog.setButton( alertDialog.setButton(
android.app.AlertDialog.BUTTON_NEUTRAL, getString(R.string.save) android.app.AlertDialog.BUTTON_NEUTRAL, getString(R.string.save)
) { dialog, which -> ) { _, _ ->
counterCalls = 1 counterCalls = 1
viewModel.expeditionStateAddSalix(expeditionBack) viewModel.expeditionStateAddSalix(expeditionBack)
} }
alertDialog.setButton( alertDialog.setButton(
android.app.AlertDialog.BUTTON_POSITIVE, getString(R.string.ordenar) android.app.AlertDialog.BUTTON_POSITIVE, getString(R.string.ordenar)
) { dialog, which -> ) { _, _ ->
createList(list.sortedByDescending { it.code } as MutableList<ExpeditionInfoLoadUnload>) createList(list.sortedByDescending { it.code } as MutableList<ExpeditionInfoLoadUnload>)
} }
alertDialog.show() alertDialog.show()
} }
} else { } else {
openSignActivity() val alertDialog = android.app.AlertDialog.Builder(requireContext()).create()
alertDialog.setTitle(getString(R.string.info))
alertDialog.setMessage(getString(R.string.scanForSign))
alertDialog.setButton(
android.app.AlertDialog.BUTTON_NEUTRAL, getString(R.string.accept)
) { _, _ ->
alertDialog.dismiss()
}
alertDialog.show()
} }
@ -222,7 +224,7 @@ class LoadUnloadFragment(
} }
binding.scanInput.setOnEditorActionListener { _, actionId, _ -> binding.scanInput.setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == EditorInfo.IME_ACTION_NEXT || actionId == EditorInfo.IME_ACTION_UNSPECIFIED) { if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == EditorInfo.IME_ACTION_NEXT) {
if (!binding.scanInput.text.isNullOrEmpty()) { if (!binding.scanInput.text.isNullOrEmpty()) {
@ -264,7 +266,7 @@ class LoadUnloadFragment(
var found = false var found = false
if (myList.filter { it.id == expedNumber }.filter { it.code == state }.isNotEmpty()) { if (myList.filter { it.id == expedNumber }.any { it.code == state }) {
ma.messageWithSound(getString(R.string.expeditionMarked), null, true) ma.messageWithSound(getString(R.string.expeditionMarked), null, true)
} else { } else {
for (exped in myList) { for (exped in myList) {
@ -275,10 +277,15 @@ class LoadUnloadFragment(
} }
} }
if (found) { if (found) {
ma.messageWithSound("", false, true, isToasted = false) ma.messageWithSound(
message = "",
isError = false,
isPlayed = true,
isToasted = false
)
scanning(true) scanning(true)
} else { } else {
ma.messageWithSound("", true, true, isToasted = null) ma.messageWithSound("", isError = true, isPlayed = true, isToasted = null)
} }
} }
@ -295,7 +302,6 @@ class LoadUnloadFragment(
} }
} }
@RequiresApi(Build.VERSION_CODES.O)
override fun observeViewModel() { override fun observeViewModel() {
with(viewModel) { with(viewModel) {
expeditionInfoLoadUnloadList.observe(viewLifecycleOwner) { expeditionInfoLoadUnloadList.observe(viewLifecycleOwner) {
@ -313,7 +319,7 @@ class LoadUnloadFragment(
} }
responseStateAdd.observe(viewLifecycleOwner) { responseStateAdd.observe(viewLifecycleOwner) {
if (!it.isError) { if (!it.isError) {
counterResponse = counterResponse + 1 counterResponse += 1
if (counterResponse == counterCalls) { if (counterResponse == counterCalls) {
if (!binding.mainToolbar.switchButton.isChecked) { if (!binding.mainToolbar.switchButton.isChecked) {
if (state == "DELIVERED") { if (state == "DELIVERED") {
@ -328,13 +334,13 @@ class LoadUnloadFragment(
counterCalls = 0 counterCalls = 0
} }
} else { } else {
ma.messageWithSound(it.errorMessage, true, true, "Error", true) ma.messageWithSound(it.errorMessage, isError = true, isPlayed = true, titleWithError = "Error", isToasted = true)
openSignActivity() openSignActivity()
} }
} }
responseStateList.observe(viewLifecycleOwner) { responseStateList.observe(viewLifecycleOwner) {
ma.messageWithSound(it.errorMessage, true, true, "", true) ma.messageWithSound(it.errorMessage, isError = true, isPlayed = true, titleWithError = "", isToasted = true)
savePendingExpeditions() savePendingExpeditions()
openSignActivity() openSignActivity()
} }
@ -349,7 +355,7 @@ class LoadUnloadFragment(
lifecycleScope.launch { lifecycleScope.launch {
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
var myListPending = myList.map { item -> val myListPending = myList.map { item ->
ExpeditionInfoPending( ExpeditionInfoPending(
id = item.id, id = item.id,
ticketFk = item.ticketFk, ticketFk = item.ticketFk,
@ -375,10 +381,9 @@ class LoadUnloadFragment(
} }
@RequiresApi(Build.VERSION_CODES.O)
private fun setSwitchButon() { private fun setSwitchButon() {
binding.mainToolbar.switchButton.tooltipText = getString(R.string.expeditionMarkLost) binding.mainToolbar.switchButton.tooltipText = getString(R.string.expeditionMarkLost)
binding.mainToolbar.switchButton.setOnCheckedChangeListener { buttonView, isChecked -> binding.mainToolbar.switchButton.setOnCheckedChangeListener { _, isChecked ->
binding.mainToolbar.switchButton.tooltipText = binding.mainToolbar.switchButton.tooltipText =
if (isChecked) getString(R.string.expeditionMarkFound) else getString(R.string.expeditionMarkLost) if (isChecked) getString(R.string.expeditionMarkFound) else getString(R.string.expeditionMarkLost)