This commit is contained in:
Sergio De la torre 2023-05-04 08:50:05 +02:00
parent 8fc79a4d5d
commit a63cbb8f08
1 changed files with 105 additions and 29 deletions

View File

@ -4,35 +4,40 @@ import android.content.Context
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import android.os.Build import android.os.Build
import android.view.View import android.view.View
import android.view.inputmethod.EditorInfo
import android.widget.ImageView import android.widget.ImageView
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import es.verdnatura.R import es.verdnatura.R
import es.verdnatura.databinding.FragmentSacadorBinding import es.verdnatura.databinding.FragmentSacadorBinding
import es.verdnatura.domain.ConstAndValues.SACADOR import es.verdnatura.domain.toast
import es.verdnatura.presentation.base.BaseFragment import es.verdnatura.presentation.base.BaseFragment
import es.verdnatura.presentation.common.OnCollectionSelectedListener import es.verdnatura.presentation.common.OnCollectionSelectedListener
import es.verdnatura.presentation.common.OnOptionsSelectedListener import es.verdnatura.presentation.common.OnOptionsSelectedListener
import es.verdnatura.presentation.common.TAG import es.verdnatura.presentation.common.TAG
import es.verdnatura.presentation.common.ToolBarAdapterTooltip import es.verdnatura.presentation.common.ToolBarAdapterTooltip
import es.verdnatura.presentation.view.component.CustomDialog import es.verdnatura.presentation.view.component.CustomDialog
import es.verdnatura.presentation.view.component.CustomDialogInput
import es.verdnatura.presentation.view.feature.sacador.adapter.CollectionAdapter import es.verdnatura.presentation.view.feature.sacador.adapter.CollectionAdapter
import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO
class SacadorFragment : class SacadorFragment(
var type: String
) :
BaseFragment<FragmentSacadorBinding, SacadorViewModel>(SacadorViewModel::class) { BaseFragment<FragmentSacadorBinding, SacadorViewModel>(SacadorViewModel::class) {
private var onCollectionSelectedListener: OnCollectionSelectedListener? = null private var onCollectionSelectedListener: OnCollectionSelectedListener? = null
private var goBack: Boolean = false private var goBack: Boolean = false
private var goBack2: Boolean = false private var goBack2: Boolean = false
private lateinit var customDialog: CustomDialog private lateinit var customDialog: CustomDialog
private lateinit var customDialogInput: CustomDialogInput
private var collectionsList: ArrayList<CollectionVO> = ArrayList() private var collectionsList: ArrayList<CollectionVO> = ArrayList()
private var adapter: CollectionAdapter? = null private var adapter: CollectionAdapter? = null
private var resultTagMode: String? = ""
companion object { companion object {
fun newInstance() = SacadorFragment() fun newInstance(type: String) = SacadorFragment(type)
} }
override fun onAttach(context: Context) { override fun onAttach(context: Context) {
@ -43,17 +48,30 @@ class SacadorFragment :
override fun getLayoutId(): Int = R.layout.fragment_sacador override fun getLayoutId(): Int = R.layout.fragment_sacador
override fun init() { override fun init() {
customDialog = CustomDialog(requireContext()) customDialog = CustomDialog(requireContext())
binding.splashProgress.visibility = View.VISIBLE customDialogInput = CustomDialogInput(requireContext())
binding.splashProgressTwo.visibility = View.GONE
binding.mainToolbar.toolbarTitle.text = getString(R.string.getcollection) binding.mainToolbar.toolbarTitle.text = getString(R.string.getcollection)
setToolBar() setToolBar()
setEvents() setEvents()
viewModel.collectionGetSalix() callBack(type)
super.init() super.init()
} }
private fun callBack(type: String) {
binding.splashProgress.visibility = View.VISIBLE
when (type) {
"PREPARED" -> {
viewModel.collectionGetSalix()
}
"PREITEMPICKER" -> {
viewModel.sectorCollection_get()
}
else -> {
binding.splashProgress.visibility = View.GONE
}
}
}
override fun onPause() { override fun onPause() {
goBack = true goBack = true
goBack2 = true goBack2 = true
@ -63,7 +81,6 @@ class SacadorFragment :
private fun setToolBar() { private fun setToolBar() {
ma.hideBottomNavigation(View.VISIBLE) ma.hideBottomNavigation(View.VISIBLE)
binding.mainToolbar.backButton.setOnClickListener { binding.mainToolbar.backButton.setOnClickListener {
requireActivity().onBackPressed() requireActivity().onBackPressed()
} }
@ -73,15 +90,22 @@ class SacadorFragment :
iconAdd.setImageResource(R.drawable.ic_add_black_24dp) iconAdd.setImageResource(R.drawable.ic_add_black_24dp)
val iconVehicleIn = ImageView(context) val iconVehicleIn = ImageView(context)
iconVehicleIn.setImageResource(R.drawable.car) iconVehicleIn.setImageResource(R.drawable.car)
val iconPrint = ImageView(context)
iconPrint.setImageResource(R.drawable.ic_print_black_24dp)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
iconAdd.tooltipText = getTooltip(R.drawable.ic_add_black_24dp) iconAdd.tooltipText = getTooltip(R.drawable.ic_add_black_24dp)
iconVehicleIn.tooltipText = getTooltip(R.drawable.car) iconVehicleIn.tooltipText = getTooltip(R.drawable.car)
iconAdd.tooltipText = getTooltip(R.drawable.ic_add_black_24dp)
iconPrint.tooltipText = getTooltip(R.drawable.ic_print_black_24dp)
} }
listIcons.add(iconVehicleIn) if (type == "PREPARED") {
listIcons.add(iconVehicleIn)
} else {
listIcons.add(iconPrint)
}
listIcons.add(iconAdd) listIcons.add(iconAdd)
binding.mainToolbar.toolbarIcons.adapter = binding.mainToolbar.toolbarIcons.adapter =
@ -92,22 +116,84 @@ class SacadorFragment :
iconAdd.drawable -> { iconAdd.drawable -> {
binding.splashProgress.visibility = View.VISIBLE binding.splashProgress.visibility = View.VISIBLE
viewModel.collection_assign( if (type == "PREPARED") {
) viewModel.collection_assign(
)
} else {
viewModel.sectorCollection_new(getDataInt(SECTORFK))
}
} }
iconVehicleIn.drawable -> ma.onVehicleSelected(SacadorFragment.TAG) iconVehicleIn.drawable -> ma.onVehicleSelected(SacadorFragment.TAG)
}
iconPrint.drawable -> {
showPrintPrevious()
}
}
} }
}) })
binding.mainToolbar.toolbarIcons.layoutManager = binding.mainToolbar.toolbarIcons.layoutManager =
LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false) LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)
} }
private fun showPrintPrevious() {
customDialogInput.setInputText()
customDialogInput.setTitle(getString(R.string.printTicket))
customDialogInput.setDescription(getString(R.string.printPreviousGroup))
.setValue("")
.setOkButton(getString(R.string.print)) {
try {
if (customDialogInput.getValue().isNotEmpty()
) {
print()
}
} catch (ex: Exception) {
getString(R.string.errorInput)
}
customDialogInput.setValue("")
}.setKoButton(getString(R.string.cancel)) {
customDialogInput.dismiss()
}.show()
customDialogInput.setFocusText()
customDialogInput.setFocusText()
ma.hideKeyboard(customDialogInput.getEditText())
customDialogInput.getEditText().setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5 || actionId == 6) {
if (customDialogInput.getValue().isNotEmpty()
) {
print()
}
return@setOnEditorActionListener true
}
false
}
}
private fun print() {
if (ma.havePrinter()) {
binding.splashProgress.visibility = View.VISIBLE
viewModel.ticket_printLabelPrevious(customDialogInput.getValue().toInt())
(getString(R.string.Imprimiendo) + getData(PRINTERNAME)).toast(
requireContext()
)
} else {
getString(R.string.selectPrinter).toast(requireContext())
}
}
private fun setEvents() { private fun setEvents() {
binding.sacadorSwipe.setOnRefreshListener { binding.sacadorSwipe.setOnRefreshListener {
viewModel.collectionGet() callBack(type)
binding.sacadorSwipe.isRefreshing = false binding.sacadorSwipe.isRefreshing = false
} }
} }
@ -115,7 +201,7 @@ class SacadorFragment :
override fun observeViewModel() { override fun observeViewModel() {
with(viewModel) { with(viewModel) {
binding.splashProgress.visibility = View.GONE
collectionList.observe(viewLifecycleOwner, Observer { collectionList.observe(viewLifecycleOwner, Observer {
if (!goBack2) binding.splashProgress.visibility = View.GONE if (!goBack2) binding.splashProgress.visibility = View.GONE
createCollectionList(it.list) createCollectionList(it.list)
@ -124,7 +210,6 @@ class SacadorFragment :
}) })
response.observe(viewLifecycleOwner, Observer { response.observe(viewLifecycleOwner, Observer {
binding.splashProgressTwo.visibility = View.GONE
binding.splashProgress.visibility = View.GONE binding.splashProgress.visibility = View.GONE
if (it.isError) { if (it.isError) {
ma.messageWithSound(it.errorMessage, true, false) ma.messageWithSound(it.errorMessage, true, false)
@ -133,7 +218,7 @@ class SacadorFragment :
if (goBack) addCollectionToList(it.response.toInt()) if (goBack) addCollectionToList(it.response.toInt())
} }
goBack = false goBack = false
viewModel.collectionGetSalix() callBack(type)
}) })
} }
@ -145,7 +230,7 @@ class SacadorFragment :
collectionsList.add(it) collectionsList.add(it)
} }
val lm = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) val lm = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
adapter = CollectionAdapter(collectionsList, onCollectionSelectedListener!!,SACADOR) adapter = CollectionAdapter(collectionsList, onCollectionSelectedListener!!, type)
binding.fragmentSacadorCollections.layoutManager = lm binding.fragmentSacadorCollections.layoutManager = lm
binding.fragmentSacadorCollections.adapter = adapter binding.fragmentSacadorCollections.adapter = adapter
@ -176,15 +261,6 @@ class SacadorFragment :
customDialog.dismiss() customDialog.dismiss()
}.show() }.show()
} }
//sergio:para asegurarnos que se actualiza pantalla.
adapter?.notifyDataSetChanged() adapter?.notifyDataSetChanged()
} }
private fun navigateToCollectionList(collection: CollectionVO) {
collectionsList.add(collection)
adapter?.notifyDataSetChanged()
onCollectionSelectedListener?.onCollectionSelected(collection, SACADOR)
}
} }