refs #5442
This commit is contained in:
parent
8fc79a4d5d
commit
a63cbb8f08
|
@ -4,35 +4,40 @@ import android.content.Context
|
|||
import android.graphics.drawable.Drawable
|
||||
import android.os.Build
|
||||
import android.view.View
|
||||
import android.view.inputmethod.EditorInfo
|
||||
import android.widget.ImageView
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import es.verdnatura.R
|
||||
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.common.OnCollectionSelectedListener
|
||||
import es.verdnatura.presentation.common.OnOptionsSelectedListener
|
||||
import es.verdnatura.presentation.common.TAG
|
||||
import es.verdnatura.presentation.common.ToolBarAdapterTooltip
|
||||
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.model.CollectionVO
|
||||
|
||||
|
||||
class SacadorFragment :
|
||||
class SacadorFragment(
|
||||
var type: String
|
||||
) :
|
||||
BaseFragment<FragmentSacadorBinding, SacadorViewModel>(SacadorViewModel::class) {
|
||||
|
||||
private var onCollectionSelectedListener: OnCollectionSelectedListener? = null
|
||||
private var goBack: Boolean = false
|
||||
private var goBack2: Boolean = false
|
||||
private lateinit var customDialog: CustomDialog
|
||||
private lateinit var customDialogInput: CustomDialogInput
|
||||
private var collectionsList: ArrayList<CollectionVO> = ArrayList()
|
||||
private var adapter: CollectionAdapter? = null
|
||||
private var resultTagMode: String? = ""
|
||||
|
||||
|
||||
companion object {
|
||||
fun newInstance() = SacadorFragment()
|
||||
fun newInstance(type: String) = SacadorFragment(type)
|
||||
}
|
||||
|
||||
override fun onAttach(context: Context) {
|
||||
|
@ -43,17 +48,30 @@ class SacadorFragment :
|
|||
override fun getLayoutId(): Int = R.layout.fragment_sacador
|
||||
|
||||
override fun init() {
|
||||
|
||||
customDialog = CustomDialog(requireContext())
|
||||
binding.splashProgress.visibility = View.VISIBLE
|
||||
binding.splashProgressTwo.visibility = View.GONE
|
||||
customDialogInput = CustomDialogInput(requireContext())
|
||||
binding.mainToolbar.toolbarTitle.text = getString(R.string.getcollection)
|
||||
setToolBar()
|
||||
setEvents()
|
||||
viewModel.collectionGetSalix()
|
||||
callBack(type)
|
||||
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() {
|
||||
goBack = true
|
||||
goBack2 = true
|
||||
|
@ -63,7 +81,6 @@ class SacadorFragment :
|
|||
private fun setToolBar() {
|
||||
|
||||
ma.hideBottomNavigation(View.VISIBLE)
|
||||
|
||||
binding.mainToolbar.backButton.setOnClickListener {
|
||||
requireActivity().onBackPressed()
|
||||
}
|
||||
|
@ -73,15 +90,22 @@ class SacadorFragment :
|
|||
iconAdd.setImageResource(R.drawable.ic_add_black_24dp)
|
||||
val iconVehicleIn = ImageView(context)
|
||||
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) {
|
||||
|
||||
iconAdd.tooltipText = getTooltip(R.drawable.ic_add_black_24dp)
|
||||
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)
|
||||
|
||||
binding.mainToolbar.toolbarIcons.adapter =
|
||||
|
@ -92,22 +116,84 @@ class SacadorFragment :
|
|||
|
||||
iconAdd.drawable -> {
|
||||
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)
|
||||
}
|
||||
|
||||
iconPrint.drawable -> {
|
||||
showPrintPrevious()
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
binding.mainToolbar.toolbarIcons.layoutManager =
|
||||
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() {
|
||||
binding.sacadorSwipe.setOnRefreshListener {
|
||||
viewModel.collectionGet()
|
||||
callBack(type)
|
||||
binding.sacadorSwipe.isRefreshing = false
|
||||
}
|
||||
}
|
||||
|
@ -115,7 +201,7 @@ class SacadorFragment :
|
|||
override fun observeViewModel() {
|
||||
|
||||
with(viewModel) {
|
||||
|
||||
binding.splashProgress.visibility = View.GONE
|
||||
collectionList.observe(viewLifecycleOwner, Observer {
|
||||
if (!goBack2) binding.splashProgress.visibility = View.GONE
|
||||
createCollectionList(it.list)
|
||||
|
@ -124,7 +210,6 @@ class SacadorFragment :
|
|||
})
|
||||
|
||||
response.observe(viewLifecycleOwner, Observer {
|
||||
binding.splashProgressTwo.visibility = View.GONE
|
||||
binding.splashProgress.visibility = View.GONE
|
||||
if (it.isError) {
|
||||
ma.messageWithSound(it.errorMessage, true, false)
|
||||
|
@ -133,7 +218,7 @@ class SacadorFragment :
|
|||
if (goBack) addCollectionToList(it.response.toInt())
|
||||
}
|
||||
goBack = false
|
||||
viewModel.collectionGetSalix()
|
||||
callBack(type)
|
||||
})
|
||||
|
||||
}
|
||||
|
@ -145,7 +230,7 @@ class SacadorFragment :
|
|||
collectionsList.add(it)
|
||||
}
|
||||
val lm = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
|
||||
adapter = CollectionAdapter(collectionsList, onCollectionSelectedListener!!,SACADOR)
|
||||
adapter = CollectionAdapter(collectionsList, onCollectionSelectedListener!!, type)
|
||||
binding.fragmentSacadorCollections.layoutManager = lm
|
||||
binding.fragmentSacadorCollections.adapter = adapter
|
||||
|
||||
|
@ -176,15 +261,6 @@ class SacadorFragment :
|
|||
customDialog.dismiss()
|
||||
}.show()
|
||||
}
|
||||
//sergio:para asegurarnos que se actualiza pantalla.
|
||||
adapter?.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
private fun navigateToCollectionList(collection: CollectionVO) {
|
||||
collectionsList.add(collection)
|
||||
adapter?.notifyDataSetChanged()
|
||||
onCollectionSelectedListener?.onCollectionSelected(collection, SACADOR)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue