refs #6530 feat:refactorOnBackPressed

This commit is contained in:
Sergio De la torre 2024-05-22 17:12:33 +02:00
parent 51d5bcf6ae
commit 387905e89c
3 changed files with 136 additions and 94 deletions

View File

@ -6,6 +6,7 @@ import es.verdnatura.presentation.view.feature.articulo.model.BarcodeVO
import es.verdnatura.presentation.view.feature.articulo.model.ItemCardRowVO
import es.verdnatura.presentation.view.feature.articulo.model.ItemProposal
import es.verdnatura.presentation.view.feature.buscaritem.model.ItemLocationVO
import es.verdnatura.presentation.view.feature.claim.fragment.reubication.model.Reubication
import es.verdnatura.presentation.view.feature.delivery.model.ClientTicketSalix
import es.verdnatura.presentation.view.feature.delivery.model.ExpeditionInfoSummary
import es.verdnatura.presentation.view.feature.delivery.model.RouteInfo
@ -18,12 +19,15 @@ import es.verdnatura.presentation.view.feature.paletizador.model.ItemExpeditionS
import es.verdnatura.presentation.view.feature.paletizador.model.ItemExpeditionTruckVO
import es.verdnatura.presentation.view.feature.paletizador.model.ItemPalletVO
import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO
import es.verdnatura.presentation.view.feature.claim.fragment.reubication.model.Reubication
import es.verdnatura.presentation.view.feature.sacador.model.CollectionTicket
import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO
import es.verdnatura.presentation.view.feature.sacador.model.Sale
import es.verdnatura.presentation.view.feature.sacador.model.SaleVO
import es.verdnatura.presentation.view.feature.smarttag.model.SmartTag
import es.verdnatura.presentation.view.feature.truck.model.RoadMapTruck
import es.verdnatura.presentation.view.feature.truck.model.StopMapTruck
import es.verdnatura.presentation.view.feature.truck.model.StopMapTruckPallet
import es.verdnatura.presentation.view.feature.truck.model.TruckAction
import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicador
import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicadorVO
import es.verdnatura.presentation.view.feature.workermistake.model.WorkerFromMistake
@ -152,6 +156,23 @@ interface OnMoreClickListenerNew {
interface OnTruckClickListener {
fun onTruckClickListener(item: ItemExpeditionTruckVO, entryPoint: String)
}
interface OnRoadMapClickListener {
fun onRoadMapClickListener(item: RoadMapTruck, entryPoint: String)
}
interface OnStopMapClickListener {
fun onStopMapClickListener(item: StopMapTruck, entryPoint: String, action:TruckAction)
}
interface OnStopMapLoadClickListener {
fun onStopMapClickListener(item: StopMapTruck, entryPoint: String)
}
interface OnStopMapUnloadClickListener {
fun onStopMapClickListener(item: StopMapTruck, entryPoint: String)
}
interface OnPrintClickListener {
fun onPrintClickListener(item: StopMapTruckPallet, entryPoint: String)
}
interface OnPalletClickListener {
fun onPalletClickListener(itemTruck: ItemExpeditionTruckVO, itemPallet: ItemPalletVO)
@ -246,4 +267,8 @@ interface LoginListener {
interface SignListener {
fun onApplicationEventAnimation(visibility: Int)
}
interface OnBackPressedListener {
fun onBackPressedHandled(): Boolean
}

View File

@ -17,8 +17,10 @@ import es.verdnatura.domain.toDateString
import es.verdnatura.domain.toast
import es.verdnatura.presentation.base.BaseFragment
import es.verdnatura.presentation.base.database
import es.verdnatura.presentation.common.OnBackPressedListener
import es.verdnatura.presentation.common.OnOptionsSelectedListener
import es.verdnatura.presentation.common.ToolBarAdapterTooltip
import es.verdnatura.presentation.view.component.CustomDialog
import es.verdnatura.presentation.view.feature.delivery.activity.SignedActivity
import es.verdnatura.presentation.view.feature.delivery.adapters.ExpeditionLoadUnloadAdapter
import es.verdnatura.presentation.view.feature.delivery.model.ClientTicketSalix
@ -41,7 +43,7 @@ class LoadUnloadFragment(
) : BaseFragment<FragmentExpeditionLoadunloadDeliveryBinding, DeliveryViewModel>(
DeliveryViewModel::class
) {
), OnBackPressedListener {
private var adapter: ExpeditionLoadUnloadAdapter? = null
private var originalItem: Int = 0
@ -508,4 +510,23 @@ class LoadUnloadFragment(
}
adapter!!.notifyDataSetChanged()
}
override fun onBackPressedHandled(): Boolean {
if (scanned) {
var customDialog = CustomDialog(requireContext())
customDialog.setTitle(getString(R.string.packagesNotScanned))
.setDescription(getString(R.string.savePackages))
.setOkButton(getString(R.string.yes)) {
customDialog.dismiss()
}.setKoButton(getString(R.string.no)) {
customDialog.dismiss()
ma.onMyBackPressed()
}.show()
} else {
return false
}
return true
}
}

View File

@ -1,6 +1,5 @@
package es.verdnatura.presentation.view.feature.main.activity
import es.verdnatura.presentation.view.feature.photos.fragment.PhotosFragment
import android.content.Context
import android.content.Intent
import android.media.MediaPlayer
@ -11,6 +10,7 @@ import android.view.Menu
import android.view.View
import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.activity.OnBackPressedDispatcherOwner
import androidx.annotation.RequiresApi
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
@ -36,11 +36,14 @@ import es.verdnatura.domain.toast
import es.verdnatura.presentation.base.BaseActivity
import es.verdnatura.presentation.common.MainActivityListener
import es.verdnatura.presentation.common.NetworkUtilsApp
import es.verdnatura.presentation.common.OnBackPressedListener
import es.verdnatura.presentation.common.OnCollectionSelectedListener
import es.verdnatura.presentation.common.OnCollectionTicketSelectedListener
import es.verdnatura.presentation.common.OnComprobarPalletViewClickListener
import es.verdnatura.presentation.common.OnPalletClickListener
import es.verdnatura.presentation.common.OnPasillerosItemClickListener
import es.verdnatura.presentation.common.OnRoadMapClickListener
import es.verdnatura.presentation.common.OnStopMapClickListener
import es.verdnatura.presentation.common.OnTruckClickListener
import es.verdnatura.presentation.common.TAG
import es.verdnatura.presentation.common.addFragment
@ -51,6 +54,10 @@ import es.verdnatura.presentation.view.feature.articulo.fragment.ItemProposalFra
import es.verdnatura.presentation.view.feature.buffer.fragment.BufferFragment
import es.verdnatura.presentation.view.feature.buffer.fragment.BufferLoadFragment
import es.verdnatura.presentation.view.feature.buscaritem.fragment.BuscarItemFragment
import es.verdnatura.presentation.view.feature.category.ChangeCategoryFragment
import es.verdnatura.presentation.view.feature.claim.fragment.reubication.fragment.ReubicationCollectionFragment
import es.verdnatura.presentation.view.feature.claim.fragment.reubication.fragment.ReubicationFragment
import es.verdnatura.presentation.view.feature.claim.fragment.reubication.model.Reubication
import es.verdnatura.presentation.view.feature.claim.fragment.ubication.ClaimUbicationFragment
import es.verdnatura.presentation.view.feature.collection.fragment.CollectionFragment
import es.verdnatura.presentation.view.feature.collection.fragment.CollectionFragmentPicker
@ -97,13 +104,11 @@ import es.verdnatura.presentation.view.feature.paletizador.model.ItemPalletVO
import es.verdnatura.presentation.view.feature.parking.fragment.ParkingFragment
import es.verdnatura.presentation.view.feature.pasillero.fragment.PasilleroFragment
import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO
import es.verdnatura.presentation.view.feature.photos.fragment.PhotosFragment
import es.verdnatura.presentation.view.feature.precontrol.PreControladorFragment
import es.verdnatura.presentation.view.feature.presacador.fragment.EndSacadorFragment
import es.verdnatura.presentation.view.feature.presacador.fragment.SectorCollectionReserveFragment
import es.verdnatura.presentation.view.feature.qr.QrFragment
import es.verdnatura.presentation.view.feature.claim.fragment.reubication.fragment.ReubicationCollectionFragment
import es.verdnatura.presentation.view.feature.claim.fragment.reubication.fragment.ReubicationFragment
import es.verdnatura.presentation.view.feature.claim.fragment.reubication.model.Reubication
import es.verdnatura.presentation.view.feature.sacador.fragment.PickerHelperFragment
import es.verdnatura.presentation.view.feature.sacador.fragment.SacadorFragment
import es.verdnatura.presentation.view.feature.sacador.fragment.SacadorFragmentNew
@ -111,6 +116,12 @@ import es.verdnatura.presentation.view.feature.sacador.fragment.showticket.ShowT
import es.verdnatura.presentation.view.feature.sacador.model.CollectionTicket
import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO
import es.verdnatura.presentation.view.feature.ticket.fragment.TicketAdvanceFragment
import es.verdnatura.presentation.view.feature.truck.fragment.RoadMapListFragment
import es.verdnatura.presentation.view.feature.truck.fragment.StopMapListFragment
import es.verdnatura.presentation.view.feature.truck.fragment.StopMapPalletListFragment
import es.verdnatura.presentation.view.feature.truck.model.RoadMapTruck
import es.verdnatura.presentation.view.feature.truck.model.StopMapTruck
import es.verdnatura.presentation.view.feature.truck.model.TruckAction
import es.verdnatura.presentation.view.feature.ubicador.fragment.AutomaticAddItemFragment
import es.verdnatura.presentation.view.feature.ubicador.fragment.UbicadorFragmentNew
import es.verdnatura.presentation.view.feature.workermistake.fragment.PackingMistakeFragment
@ -129,7 +140,8 @@ import java.util.concurrent.TimeUnit
class MainActivity : BaseActivity<ActivityMainBinding>(), OnPasillerosItemClickListener,
OnTruckClickListener, OnPalletClickListener, OnComprobarPalletViewClickListener,
OnCollectionSelectedListener, OnCollectionTicketSelectedListener, MainActivityListener {
OnRoadMapClickListener, OnStopMapClickListener, OnCollectionSelectedListener,
OnCollectionTicketSelectedListener, MainActivityListener, OnBackPressedDispatcherOwner {
private var lastBottomMenuItemSelected: ItemMenuVO? = null
private lateinit var customDialog: CustomDialogMainActivity
@ -169,8 +181,13 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), OnPasillerosItemClickL
override fun onCreateView(name: String, context: Context, attrs: AttributeSet): View? {
backDispatcher.addCallback(object : OnBackPressedCallback(true) {
backDispatcher.addCallback(object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
val fragment = supportFragmentManager.findFragmentById(R.id.main_frame_layout)
if (fragment is OnBackPressedListener && fragment.onBackPressedHandled()) {
return
}
onMyBackPressed()
}
})
@ -508,6 +525,12 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), OnPasillerosItemClickL
)
}
getString(R.string.titleChangeCategory) -> {
addFragmentOnTop(
ChangeCategoryFragment.newInstance(item.title),
)
}
getString(R.string.titleChecker) -> {/* mainActivityViewmodel.workerActivityAdd(
WorkerActionSalix(
workerFk = mobileApplication!!.userId!!,
@ -752,11 +775,17 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), OnPasillerosItemClickL
}
getString(R.string.titleDeliveryTruck) -> {
addFragmentOnTop(
RoadMapListFragment.newInstance(getString(R.string.titleDeliveryTruck)),
getString(R.string.titleDeliveryTruck)
)
}
getString(R.string.titleInfo) -> {
addFragmentOnTop(
InfoFragment.newInstance(item.title),
getString(R.string.titleInfo)
InfoFragment.newInstance(item.title), getString(R.string.titleInfo)
)
}
@ -764,8 +793,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), OnPasillerosItemClickL
getString(R.string.titleLog) -> {
addFragmentOnTop(
LogExpeditionFragment.newInstance(item.title),
getString(R.string.titleLog)
LogExpeditionFragment.newInstance(item.title), getString(R.string.titleLog)
)
}
@ -773,7 +801,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), OnPasillerosItemClickL
getString(R.string.titleLoadTruck) -> {
addFragmentOnTop(
LoadUnloadFragment.newInstance(item.title, "ON DELIVERY", entryPoint),
getString(R.string.titleLoadTruck)
getString(R.string.titleLoadTruck)
)
@ -788,9 +816,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), OnPasillerosItemClickL
} else {
null
}
),
getString(R.string.titleUnLoadTruck)
, delete = true
), getString(R.string.titleUnLoadTruck), delete = true
)
}
@ -799,7 +825,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), OnPasillerosItemClickL
addFragmentOnTop(
SummaryFragment.newInstance(item.title, "ON DELIVERY", entryPoint.toInt()),
getString(R.string.titleDeliverySummary)
getString(R.string.titleDeliverySummary)
)
}
@ -807,8 +833,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), OnPasillerosItemClickL
getString(R.string.titleDeliveryRoute) -> {
addFragmentOnTop(
RoutesFragment.newInstance(item.title),
getString(R.string.titleDeliverySummary)
RoutesFragment.newInstance(item.title), getString(R.string.titleDeliverySummary)
)
}
@ -874,81 +899,33 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), OnPasillerosItemClickL
}
fun onMyBackPressed() {
val index = supportFragmentManager.backStackEntryCount - 1
var backEntry = ""
if (index >= 0) {
backEntry = supportFragmentManager.getBackStackEntryAt(index).name.toString()
/* println("onback LOadUnload $backEntry")
if (backEntry.contains("itemShelvingLog")){
}*/
if (backEntry.contains(getString(R.string.titleLoadTruck)) || backEntry.contains(
getString(R.string.titleUnLoadTruck)
)
) {
if (LoadUnloadFragment.scanned) {
customDialog.setTitle(getString(R.string.packagesNotScanned))
.setDescription(getString(R.string.savePackages))
.setOkButton(getString(R.string.yes)) {
customDialog.dismiss()
}.setKoButton(getString(R.string.no)) {
backStackFragments(backEntry)
customDialog.dismiss()
}.show()
} else {
backStackFragments(backEntry)
}
} else {
backStackFragments(backEntry)
}
} else {
backStackFragments(backEntry)
}
}
private fun backStackFragments(backEntry: String) {
try {
fm.executePendingTransactions()
if (fm.backStackEntryCount > 0) {
fm.popBackStackImmediate()
} else {
showCloseSesion()
}
} catch (ex: Exception) {
d("$ex")
}
if (fm.backStackEntryCount > 0) {
}
fm.popBackStackImmediate()
if (!backEntry.isNullOrBlank())
if (backEntry.contains("fragment.ExpeditionPalletDetailFragment.Companion")) {
addFragmentOnTop(ExpeditionTruckListFragment.newInstance())
}
/* if (backEntry.contains(getString(R.string.titleLog)) || backEntry.contains(
getString(
R.string.titleInfo
)
)
) {
println("backk finish ?? ")
private fun showCloseSesion() {
customDialog.setTitle(getString(R.string.closeSession))
.setDescription(getString(R.string.sureCloseSession))
.setOkButton(getString(R.string.exit)) {
customDialog.dismiss()
//Borrar Token
runBlocking { mobileApplication.dataStoreApp.editDataStoreKey(TOKEN, "") }
finish()
}*/
} else {
customDialog.setTitle(getString(R.string.closeSession))
.setDescription(getString(R.string.sureCloseSession))
.setOkButton(getString(R.string.exit)) {
customDialog.dismiss()
//Borrar Token
runBlocking { mobileApplication.dataStoreApp.editDataStoreKey(TOKEN, "") }
finish()
}.setKoButton(getString(R.string.cancel)) {
customDialog.dismiss()
}.show()
}
}.setKoButton(getString(R.string.cancel)) {
customDialog.dismiss()
}.show()
}
override fun onTruckClickListener(item: ItemExpeditionTruckVO, entryPoint: String) {
@ -956,6 +933,10 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), OnPasillerosItemClickL
}
override fun onRoadMapClickListener(item: RoadMapTruck, entryPoint: String) {
addFragmentOnTop(StopMapListFragment.newInstance(getString(R.string.stops), item))
}
override fun onPalletClickListener(
itemTruck: ItemExpeditionTruckVO, itemPallet: ItemPalletVO
) {
@ -986,9 +967,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), OnPasillerosItemClickL
}
override fun onCollectionSelected(
collection: CollectionTicket,
type: String,
hasPicking: Boolean
collection: CollectionTicket, type: String, hasPicking: Boolean
) {
when (type) {
"PREITEMPICKERTEST" -> {
@ -996,8 +975,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), OnPasillerosItemClickL
//addFragmentOnTop(EndSacadorFragment.newInstance(collection, type))
addFragmentOnTop(
SectorCollectionReserveFragment.newInstance(
"PREITEMPICKERTEST",
collection.collectionFk
"PREITEMPICKERTEST", collection.collectionFk
)
)
@ -1006,9 +984,7 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), OnPasillerosItemClickL
else -> {
addFragmentOnTop(
CollectionFragmentPickerNew.newInstance(
collection,
type,
hasPicking
collection, type, hasPicking
)
)
}
@ -1108,6 +1084,12 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), OnPasillerosItemClickL
}
fun openFragmentTruckFragment() {
onMyBackPressed()
addFragmentOnTop(ExpeditionTruckListFragment.newInstance())
}
fun hideBottomNavigation(visible: Int) {
binding.mainBottomNavigation.visibility = visible
}
@ -1189,4 +1171,18 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), OnPasillerosItemClickL
binding.splashAnimation.visibility = visibility
}
override fun onStopMapClickListener(
item: StopMapTruck, entryPoint: String, action: TruckAction
) {
println("stopMapList ${item.description}")
println("stopMapList id ${item.id}")
println("action $action")
addFragmentOnTop(
StopMapPalletListFragment.newInstance(
title = item.description ?: "", item, action
)
)
}
}