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