refs #6952 feat:pickerHelper

This commit is contained in:
Sergio De la torre 2024-03-28 08:51:27 +01:00
parent 9fb40e3090
commit 84c1f0905e
6 changed files with 617 additions and 1 deletions

View File

@ -0,0 +1,598 @@
package es.verdnatura.presentation.view.feature.sacador.fragment
import android.annotation.SuppressLint
import android.content.Context
import android.graphics.drawable.Drawable
import android.os.Build
import android.text.InputType
import android.view.View.GONE
import android.view.View.VISIBLE
import android.view.inputmethod.EditorInfo
import android.widget.ImageView
import androidx.annotation.RequiresApi
import androidx.core.content.ContextCompat
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.google.gson.JsonArray
import com.google.gson.JsonObject
import es.verdnatura.R
import es.verdnatura.databinding.FragmentInventoryParkingBinding
import es.verdnatura.domain.toast
import es.verdnatura.presentation.base.BaseFragment
import es.verdnatura.presentation.common.OnBarcodeRowClickListener
import es.verdnatura.presentation.common.OnMoreClickListener
import es.verdnatura.presentation.common.OnOptionsSelectedListener
import es.verdnatura.presentation.common.OnPasillerosItemClickListener
import es.verdnatura.presentation.common.OnVisibleInventoryClickListener
import es.verdnatura.presentation.common.ToolBarAdapterTooltip
import es.verdnatura.presentation.common.itemScanValue
import es.verdnatura.presentation.view.component.CustomDialogInput
import es.verdnatura.presentation.view.component.CustomDialogList
import es.verdnatura.presentation.view.feature.articulo.adapter.BarcodeAdapter
import es.verdnatura.presentation.view.feature.articulo.model.BarcodeVO
import es.verdnatura.presentation.view.feature.inventario.adapter.InventoryParkingAdapter
import es.verdnatura.presentation.view.feature.inventario.model.ItemInventoryParking
import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicadorVO
@Suppress("UNUSED_ANONYMOUS_PARAMETER")
class PickerHelperFragment(
var title: String = "",
) : BaseFragment<FragmentInventoryParkingBinding, SacadorViewModel>(
SacadorViewModel::class
) {
private var adapter: InventoryParkingAdapter? = null
private lateinit var customDialogInput: CustomDialogInput
private lateinit var customDialogList: CustomDialogList
private var pasillerosItemClickListener: OnPasillerosItemClickListener? = null
private var isBack = false
private lateinit var myListInventory: MutableList<ItemInventoryParking>
private var listParkings: ArrayList<BarcodeVO> = ArrayList()
private var listWagonsAdapter: BarcodeAdapter? = null
private var positionShelvingChecking: Int = -1
private var positionItemChecking: Int = -1
private var scrollPosition = 0
private var parkingFrom = ""
private var parkingTo = ""
private var filterActivated = false
private var shelvingSaved = ""
val listIcons: ArrayList<ImageView> = ArrayList()
companion object {
fun newInstance(title: String) = PickerHelperFragment(title)
}
override fun getLayoutId(): Int = R.layout.fragment_inventory_parking
override fun onPause() {
try {
val layoutManager =
binding.inventoryParkingRecyclerview.layoutManager as LinearLayoutManager
scrollPosition = layoutManager.findFirstVisibleItemPosition()
} catch (exception: Exception) {
}
isBack = true
super.onPause()
}
override fun onAttach(context: Context) {
if (context is OnPasillerosItemClickListener) pasillerosItemClickListener = context
super.onAttach(context)
}
@RequiresApi(Build.VERSION_CODES.O)
override fun init() {
customDialogInput = CustomDialogInput(requireContext())
customDialogList = CustomDialogList(requireContext())
ma.hideBottomNavigation(GONE)
binding.mainToolbar.toolbarTitle.text = title
setEvents()
setViews()
setToolBar()
if (!isBack) {
setParkingFromTo()
}
super.init()
}
private fun setViews() {
binding.inventoryParkingRecyclerview.addOnScrollListener(object :
RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
scrollPosition =
(recyclerView.layoutManager as LinearLayoutManager).findFirstVisibleItemPosition()
super.onScrolled(recyclerView, dx, dy)
}
})
}
@RequiresApi(Build.VERSION_CODES.O)
private fun setToolBar() {
val iconAdd = ImageView(context)
iconAdd.setImageResource(R.drawable.ic_add_black_24dp)
val iconReload = ImageView(context)
iconReload.setImageResource(R.drawable.ic_autorenew_black_24dp)
val iconReset = ImageView(context)
iconReset.setImageResource(R.drawable.ic_remove_checks)
val iconFilter = ImageView(context)
iconFilter.setImageResource(R.drawable.ic_filter_inventory)
val iconParkingFrom = ImageView(context)
iconParkingFrom.setImageResource(R.drawable.ic_eye_inventory)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
iconParkingFrom.tooltipText = getTooltip(R.drawable.ic_eye_inventory)
iconReload.tooltipText = getTooltip(R.drawable.ic_autorenew_black_24dp)
iconAdd.tooltipText = getString(R.string.addItemShelving)
iconReset.tooltipText = getTooltip(R.drawable.ic_remove_checks)
iconFilter.tooltipText = getTooltip(R.drawable.ic_filter_inventory)
}
if (listIcons.isEmpty()) {
listIcons.add(iconParkingFrom)
listIcons.add(iconFilter)
listIcons.add(iconReset)
} else {
listIcons.clear()
listIcons.add(iconParkingFrom)
listIcons.add(iconFilter)
listIcons.add(iconReset)
}
binding.mainToolbar.toolbarIcons.adapter =
ToolBarAdapterTooltip(listIcons, object : OnOptionsSelectedListener {
override fun onOptionsItemSelected(item: Drawable) {
when (item) {
iconFilter.drawable -> {
try {
filterActivated = !filterActivated
adapter!!.setItems(if (filterActivated) {
myListInventory.filter { it.isChecked == null || it.isChecked == 0 }
} else {
myListInventory
})
iconFilter.drawable.setTint(
ContextCompat.getColor(
context!!,
if (filterActivated) R.color.verdnatura_pumpkin_orange else R.color.verdnatura_white
)
)
} catch (ex: Exception) {
}
}
iconReset.drawable -> {
if (!myListInventory.isNullOrEmpty()) {
binding.textinputlayoutMatricula.visibility = VISIBLE
showResetShelving()
} else {
getString(R.string.listInventoryEmpty).toast(requireContext())
}
}
iconParkingFrom.drawable -> {
setParkingFromTo()
}
}
}
})
chageListAdapter(listIcons.filter { it != iconReset })
binding.mainToolbar.toolbarIcons.layoutManager =
LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)
}
private fun chageListAdapter(filterList: List<ImageView>, removeReset: Boolean = false) {
if (!removeReset) {
(binding.mainToolbar.toolbarIcons.adapter as ToolBarAdapterTooltip).setItemsList(
filterList
)
} else {
(binding.mainToolbar.toolbarIcons.adapter as ToolBarAdapterTooltip).setItemsList(
filterList.filter {
it.drawable.constantState?.equals(
context?.getDrawable(
R.drawable.ic_remove_checks
)?.constantState
) != true
})
}
}
private fun showResetShelving() {
customDialogInput.setFocusText()
customDialogInput.setInputText(InputType.TYPE_CLASS_TEXT)
customDialogInput.setTitle(getString(R.string.checkItemShelvingDescrip))
.setDescription(getString(R.string.checkItemShelvingSelect))
.setOkButton(getString(R.string.cancel)) {
customDialogInput.dismiss()
}.setKoButton(getString(R.string.ok)) {
checkSelvingsForUpdate(customDialogInput.getValue())
}.show()
customDialogInput.getEditText().setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) {
if (customDialogInput.getValue().isNotEmpty()) {
checkSelvingsForUpdate(customDialogInput.getValue())
}
return@setOnEditorActionListener true
}
false
}
}
private fun checkSelvingsForUpdate(shelvingInput: String) {
val filter = JsonObject()
val inqValues = JsonArray()
for (item in myListInventory) {
if (item.shelvingFk == shelvingInput) {
inqValues.add(item.id)
}
}
if (inqValues.size() == 0) {
ma.messageWithSound("", true, true, "", null)
} else {
filter.add("id", JsonObject().apply { add("inq", inqValues) })
/* viewModel.itemShelvingsReset(
filter, ItemShelvingChecked(null, mobileApplication.userId!!)
)*/
}
ma.hideKeyboard(customDialogInput.getEditText())
customDialogInput.setValue("")
customDialogInput.dismiss()
binding.editMatricula.requestFocus()
}
private fun setParkingFromTo() {
binding.textinputlayoutMatricula.visibility = VISIBLE
customDialogList.setTitle("Parkings del almacén")
customDialogList.setDescription("Indica los parkings por los que voy a sacar")
.setKoButton(getString(R.string.cancel)) {
ma.hideKeyboard(customDialogList.getEditText())
listParkings = ArrayList()
customDialogList.dismiss()
}.setValue("").show()
customDialogList.getEditText().requestFocus()
ma.hideKeyboard(customDialogList.getEditText())
customDialogList.getEditText().setOnEditorActionListener { v, actionId, event ->
if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) {
if (customDialogList.getValue().isNotEmpty()) {
try {
if (listParkings.size == 2) {
callGetInventory(
listParkings.first().code!!.uppercase(),
customDialogList.getValue().uppercase()
)
ma.hideKeyboard(customDialogList.getEditText())
listParkings.clear()
customDialogList.dismiss()
binding.editMatricula.requestFocus()
} else {
customDialogList.setDescription(getString(R.string.selectParkingsTo))
listParkings.add(0, BarcodeVO(code = customDialogList.getValue()))
}
} catch (e: Exception) {
ma.messageWithSound(e.message.toString(), true, true, "", true)
}
listWagonsAdapter!!.notifyItemInserted(listParkings.size - 1)
}
customDialogList.setValue("")
ma.hideKeyboard(customDialogList.getEditText())
return@setOnEditorActionListener true
}
false
}
listWagonsAdapter = BarcodeAdapter(
listParkings, object : OnBarcodeRowClickListener {
override fun onBarcodeRowClickListener(item: BarcodeVO) {
}
}, showDelete = false
)
customDialogList.getRecyclerView().adapter = listWagonsAdapter
customDialogList.getRecyclerView().layoutManager =
LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
}
private fun callGetInventory(parkingFromScan: String, parkingToScan: String) {
parkingFrom = parkingFromScan
parkingTo = parkingToScan
/* viewModel.getInventoryParking(
parkingFromScan, parkingToScan
)*/
binding.mainToolbar.toolbarTitle.text = "$parkingFrom$parkingTo"
}
@RequiresApi(Build.VERSION_CODES.O)
@SuppressLint("SetTextI18n")
private fun setEvents() {
binding.mainToolbar.backButton.setOnClickListener {
isBack = true
if (shelvingSaved.isNullOrBlank()) {
ma.onMyBackPressed()
} else {
resetChecking()
}
}
binding.inventorySwipe.setOnRefreshListener {
positionShelvingChecking = -1
positionItemChecking = -1
shelvingSaved = ""
/* viewModel.getInventoryParking(
parkingFrom, parkingTo
)*/
binding.editMatricula.hint = getString(R.string.scanShelving)
chageListAdapter(listIcons.filter {
it.drawable.constantState?.equals(
context?.getDrawable(
R.drawable.ic_remove_checks
)?.constantState
) != true
})
binding.inventorySwipe.isRefreshing = false
}
binding.editMatricula.requestFocus()
binding.editMatricula.setOnEditorActionListener { v, actionId, event ->
if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) {
if (!binding.editMatricula.text.toString().isEmpty()) {
if (positionShelvingChecking == -1) {
try {
binding.editMatricula.setText(
itemScanValue(
binding.editMatricula.text.toString(), "buy", "more"
).toString().uppercase()
)
} catch (ex: Exception) {
ex.message!!.toast(requireContext())
}
positionShelvingChecking = myListInventory.indexOfFirst { item ->
item.shelvingFk.uppercase() == binding.editMatricula.text.toString()
}
if (positionShelvingChecking != -1) {
shelvingSaved = myListInventory[positionShelvingChecking].shelvingFk.uppercase()
}
var allChecked = if (positionShelvingChecking != -1) {
myListInventory.filter { it.shelvingFk.uppercase() == myListInventory[positionShelvingChecking].shelvingFk.uppercase() }
.all { item ->
item.isChecked != null && item.isChecked!! > 0
}
} else {
false
}
if (allChecked) {
ma.messageWithSound(
getString(R.string.plateChecked), false, true, "", isToasted = true
)
chageListAdapter(listIcons)
adapter!!.setItems(myListInventory.filter { it.shelvingFk.uppercase() == myListInventory[positionShelvingChecking].shelvingFk.uppercase() })
positionShelvingChecking = -1
positionItemChecking = -1
shelvingSaved = ""
binding.editMatricula.hint = getString(R.string.scanShelving)
binding.textinputlayoutMatricula.hint = getString(R.string.scanShelving)
} else {
if (positionShelvingChecking == -1) {
ma.messageWithSound(
getString(R.string.shelvingNotFound), true, true, "", true
)
} else {
chageListAdapter(listIcons)
adapter!!.setItems(myListInventory.filter { it.shelvingFk == myListInventory[positionShelvingChecking].shelvingFk })
binding.editMatricula.hint = getString(R.string.scanItemForChecking)
binding.textinputlayoutMatricula.hint =
getString(R.string.scanItemForChecking)
}
}
} else {
try {
/* viewModel.getIdFromCodeSalix(
code = itemScanValue(
binding.editMatricula.text.toString(), "buy", "more"
).toString()
)*/
} catch (ex: Exception) {
ma.messageWithSound(ex.message!!, true, true, "", null)
}
}
binding.editMatricula.setText("")
ma.hideKeyboard(binding.editMatricula)
}
return@setOnEditorActionListener true
}
return@setOnEditorActionListener false
}
}
private fun resetChecking() {
chageListAdapter(listIcons)
positionShelvingChecking = -1
positionItemChecking = -1
shelvingSaved = ""
binding.editMatricula.hint = getString(R.string.scanShelving)
binding.textinputlayoutMatricula.hint = getString(R.string.scanShelving)
callGetInventory(parkingFrom, parkingTo)
}
private fun checkItem(itemCode: String) {
positionItemChecking = myListInventory.indexOfFirst { item ->
item.itemFk == itemCode.toInt() && item.shelvingFk.uppercase() == myListInventory[positionShelvingChecking].shelvingFk.uppercase() && item.isChecked == null
}
if (positionItemChecking == -1) {
ma.messageWithSound(
getString(R.string.itemNotFoundScanAgain), true, true, "", true
)
positionShelvingChecking = -1
binding.editMatricula.hint = getString(R.string.scanShelvingAgain)
} else {
try {
/* viewModel.itemShelvingUpdate(
myListInventory[positionItemChecking].id,
ItemShelvingChecked(true, mobileApplication.userId!!)
)*/
myListInventory[positionItemChecking].isChecked = 1
adapter!!.notifyDataSetChanged()
binding.editMatricula.hint = getString(R.string.scanShelving)
var allChecked =
myListInventory.filter { it.shelvingFk.uppercase() == myListInventory[positionShelvingChecking].shelvingFk.uppercase() }
.all { item ->
item.isChecked != null && item.isChecked!! > 0
}
if (allChecked) {
shelvingSaved = ""
}
positionItemChecking = -1
positionShelvingChecking = -1
} catch (ex: Exception) {
}
}
}
@SuppressLint("SetTextI18n")
override fun observeViewModel() {
with(viewModel) {
response.observe(viewLifecycleOwner, Observer {
chageListAdapter(listIcons, true)
callGetInventory(
parkingFrom, parkingTo
)
})
}
}
private fun createListInventoryParking(
) {
adapter = InventoryParkingAdapter((if (filterActivated) {
if (!shelvingSaved.isNullOrEmpty()) {
myListInventory.filter { (it.isChecked == null || it.isChecked == 0) && it.shelvingFk.uppercase() == shelvingSaved.uppercase() }
} else {
myListInventory.filter { it.isChecked == null || it.isChecked == 0 }
}
} else {
if (!shelvingSaved.isNullOrEmpty()) {
myListInventory.filter { it.shelvingFk.uppercase() == shelvingSaved.uppercase() }
} else {
myListInventory
}
}),
onPasillerosItemClickListener = pasillerosItemClickListener!!,
onVisibleInventoryClickListener = object : OnVisibleInventoryClickListener {
override fun onVisibleInventoryClickListener(item: ItemInventoryParking) {
changeVisible(item)
}
},
onMoreClickListener = object : OnMoreClickListener {
override fun onMoreClickListener(item: ItemUbicadorVO) {
}
})
binding.inventoryParkingRecyclerview.adapter = adapter
binding.inventoryParkingRecyclerview.layoutManager = LinearLayoutManager(
requireContext(), LinearLayoutManager.VERTICAL, false
)
}
private fun changeVisible(item: ItemInventoryParking) {
customDialogInput.setInputText(InputType.TYPE_CLASS_NUMBER)
customDialogInput.setTitle(getString(R.string.quantity))
customDialogInput.setDescription(getString(R.string.quantityVisible)).setValue(item.visible.toString())
.setOkButton(getString(R.string.modify)) {
try {
if (customDialogInput.getValue().toInt() >= 0) {
/*viewModel.itemShelvingUpdate(
item.id, if (customDialogInput.getValue().toInt() == 0) {
ItemShelvingVisibleZero(customDialogInput.getValue().toInt(), true)
} else {
ItemShelvingVisible(customDialogInput.getValue().toInt())
}
)*/
} else {
throw Exception("")
}
} catch (err: Exception) {
(getString(R.string.errorQuantity).toast(requireContext()))
}
customDialogInput.setValue("")
customDialogInput.dismiss()
}.setKoButton(getString(R.string.cancel)) {
customDialogInput.dismiss()
}.show()
customDialogInput.setFocusText()
}
}

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
>
<path
android:fillColor="@android:color/white"
android:pathData="M80,920L80,840L880,840L880,920L80,920ZM160,800L160,560Q127,506 109,445.5Q91,385 91,322Q91,261 106.5,202Q122,143 143,86Q151,65 169,52.5Q187,40 209,40Q240,40 262,61Q284,82 280,111L269,202Q263,250 277.5,293Q292,336 321,368.5Q350,401 391,420.5Q432,440 480,440Q540,440 600.5,452.5Q661,465 706,488Q751,511 775.5,546.5Q800,582 800,634L800,800L160,800ZM240,720L720,720L720,634Q720,610 708,591.5Q696,573 674,562Q633,542 579,531Q525,520 480,520Q414,520 357.5,493Q301,466 261.5,420.5Q222,375 202,315.5Q182,256 190,192L190,192Q180,222 175.5,256Q171,290 171,322Q171,380 191.5,433.5Q212,487 240,538L240,720ZM480,400Q414,400 367,353Q320,306 320,240Q320,174 367,127Q414,80 480,80Q546,80 593,127Q640,174 640,240Q640,306 593,353Q546,400 480,400ZM480,320Q513,320 536.5,296.5Q560,273 560,240Q560,207 536.5,183.5Q513,160 480,160Q447,160 423.5,183.5Q400,207 400,240Q400,273 423.5,296.5Q447,320 480,320ZM320,800L320,763Q320,696 366.5,648Q413,600 480,600L640,600L640,680L480,680Q446,680 423,704.5Q400,729 400,763L400,800L320,800ZM480,720L480,720L480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720L480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720Q480,720 480,720L480,720ZM480,240Q480,240 480,240Q480,240 480,240Q480,240 480,240Q480,240 480,240Q480,240 480,240Q480,240 480,240Q480,240 480,240Q480,240 480,240Z"/>
</vector>

View File

@ -200,7 +200,7 @@
<string name="showFilter">Ver filtro </string> <string name="showFilter">Ver filtro </string>
<string name="showFaults">Ver movimientos de Faltas</string> <string name="showFaults">Ver movimientos de Faltas</string>
<string name="showTrash">Ver movimientos de Basura</string> <string name="showTrash">Ver movimientos de Basura</string>
<string name="filterFlower">Filtra por tipo de flor</string> <string name="filterFlower">Activa/desactiva filtro por familia</string>
<string name="noprinter">Sin impresora</string> <string name="noprinter">Sin impresora</string>
<string name="dateFormat">yyyy-MM-dd</string> <string name="dateFormat">yyyy-MM-dd</string>
<string name="cancel">Cancelar</string> <string name="cancel">Cancelar</string>
@ -751,6 +751,8 @@
<string name="warningEntry">Va a notificar la entrada al dpto de Logística</string> <string name="warningEntry">Va a notificar la entrada al dpto de Logística</string>
<string name="sendEntry">Enviar entrada embalajes</string> <string name="sendEntry">Enviar entrada embalajes</string>
<string name="attachImage">"Imágenes: "</string> <string name="attachImage">"Imágenes: "</string>
<string name="pickerHelper">Sacadores asistente</string>
<string name="pickerHelperDescrip">Permite sacar parte de la colección</string>
</resources> </resources>

View File

@ -751,5 +751,7 @@
<string name="warningEntry">Va a notificar la entrada al dpto de Logística</string> <string name="warningEntry">Va a notificar la entrada al dpto de Logística</string>
<string name="sendEntry">Enviar entrada embalajes</string> <string name="sendEntry">Enviar entrada embalajes</string>
<string name="attachImage">"Imágenes: "</string> <string name="attachImage">"Imágenes: "</string>
<string name="pickerHelper">Sacadores asistente</string>
<string name="pickerHelperDescrip">Permite sacar parte de la colección</string>
</resources> </resources>

View File

@ -751,5 +751,7 @@
<string name="warningEntry">Va a notificar la entrada al dpto de Logística</string> <string name="warningEntry">Va a notificar la entrada al dpto de Logística</string>
<string name="sendEntry">Enviar entrada embalajes</string> <string name="sendEntry">Enviar entrada embalajes</string>
<string name="attachImage">"Imágenes: "</string> <string name="attachImage">"Imágenes: "</string>
<string name="pickerHelper">Sacadores asistente</string>
<string name="pickerHelperDescrip">Permite sacar parte de la colección</string>
</resources> </resources>

View File

@ -751,5 +751,7 @@
<string name="warningEntry">Va a notificar la entrada al dpto de Logística</string> <string name="warningEntry">Va a notificar la entrada al dpto de Logística</string>
<string name="sendEntry">Enviar entrada embalajes</string> <string name="sendEntry">Enviar entrada embalajes</string>
<string name="attachImage">Imágenes: </string> <string name="attachImage">Imágenes: </string>
<string name="pickerHelper">Sacadores asistente</string>
<string name="pickerHelperDescrip">Permite sacar parte de la colección</string>
</resources> </resources>