feat onBack #refs 6530

This commit is contained in:
Sergio De la torre 2024-06-18 12:17:33 +02:00
parent fcf91a18d8
commit 915aad5a32
2 changed files with 26 additions and 18 deletions

View File

@ -3,10 +3,13 @@ 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.Bundle
import android.view.KeyEvent
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.activity.OnBackPressedCallback
import androidx.activity.OnBackPressedDispatcher import androidx.activity.OnBackPressedDispatcher
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
@ -69,22 +72,20 @@ class LoadUnloadFragment(
} }
} }
/* override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
requireActivity().onBackPressedDispatcher.addCallback( requireActivity().onBackPressedDispatcher.addCallback(
viewLifecycleOwner, viewLifecycleOwner,
object : OnBackPressedCallback(true) { object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() { override fun handleOnBackPressed() {
*//* if (!onBackListenerPressed()) { if (!onBackPressedHandled()) {
isEnabled = true isEnabled = false
requireActivity().onBackPressedDispatcher requireActivity().onBackPressedDispatcher
} else {*//* }
println("backk UnLoadLoadFragment")
// }
} }
}) })
}*/ }
override fun getLayoutId(): Int = R.layout.fragment_expedition_loadunload_delivery override fun getLayoutId(): Int = R.layout.fragment_expedition_loadunload_delivery
@ -185,7 +186,7 @@ class LoadUnloadFragment(
"LOST" "LOST"
} else { } else {
l.code l.code
} }, isScanned = l.isScanned
) )
) )
} }
@ -244,11 +245,12 @@ class LoadUnloadFragment(
ma.onMyBackPressed() ma.onMyBackPressed()
} }
binding.scanInput.setOnEditorActionListener { _, actionId, _ -> binding.scanInput.setOnEditorActionListener { v, actionId, event ->
if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == EditorInfo.IME_ACTION_NEXT) { 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()) {
val isScanned =
event != null && event.action == KeyEvent.ACTION_DOWN && event.keyCode == KeyEvent.KEYCODE_ENTER
try { try {
markExpedition( markExpedition(
binding.scanInput.text.toString().toInt(), binding.scanInput.text.toString().toInt(),
@ -257,8 +259,8 @@ class LoadUnloadFragment(
} else { } else {
"FOUND" "FOUND"
}, },
isScanned = if (isScanned) 1 else 0
) )
if (state != "DELIVERED") { if (state != "DELIVERED") {
binding.mainToolbar.toolbarTitle.text = binding.mainToolbar.toolbarTitle.text =
@ -283,7 +285,7 @@ class LoadUnloadFragment(
binding.scanInput.requestFocus() binding.scanInput.requestFocus()
} }
private fun markExpedition(expedNumber: Int, state: String) { private fun markExpedition(expedNumber: Int, state: String, isScanned: Int) {
var found = false var found = false
@ -294,6 +296,7 @@ class LoadUnloadFragment(
if (exped.id == expedNumber) { if (exped.id == expedNumber) {
found = true found = true
exped.code = state exped.code = state
exped.isScanned = isScanned
break break
} }
} }
@ -314,7 +317,7 @@ class LoadUnloadFragment(
counterCalls = 1 counterCalls = 1
val pendingExpeditionSend = myList.map { l -> val pendingExpeditionSend = myList.map { l ->
ExpeditionSalix( ExpeditionSalix(
expeditionFk = l.id, stateCode = l.code expeditionFk = l.id, stateCode = l.code, isScanned = l.isScanned
) )
} }
viewModel.expeditionStateAddSalix(hashMapOf("expeditions" to pendingExpeditionSend.filter { it.stateCode == state })) viewModel.expeditionStateAddSalix(hashMapOf("expeditions" to pendingExpeditionSend.filter { it.stateCode == state }))
@ -527,6 +530,6 @@ class LoadUnloadFragment(
} else { } else {
return false return false
} }
return true return true
} }
} }

View File

@ -28,15 +28,20 @@
android:text="@string/itemData" android:text="@string/itemData"
android:textColor="@color/verdnatura_white" android:textColor="@color/verdnatura_white"
android:textSize="@dimen/bodyPicker" android:textSize="@dimen/bodyPicker"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/scan_input"/> app:layout_constraintTop_toBottomOf="@+id/scan_input"
/>
<LinearLayout <LinearLayout
android:id="@+id/itemDetails" android:id="@+id/itemDetails"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="40dp" android:layout_marginBottom="30dp"
android:layout_marginStart="40dp"
android:layout_marginEnd="40dp"
android:orientation="horizontal" android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"