refs #5313 fix errors

This commit is contained in:
Sergio De la torre 2023-10-31 10:41:37 +01:00
parent e4f5cc6786
commit 622d2eeae3
5 changed files with 83 additions and 400 deletions

View File

@ -1,343 +0,0 @@
package es.verdnatura.presentation.view.feature.collection.fragment
import android.app.AlertDialog
import android.content.Context
import android.graphics.drawable.Drawable
import android.os.Build
import android.os.Bundle
import android.view.View
import android.view.View.GONE
import android.view.View.VISIBLE
import android.view.inputmethod.EditorInfo
import android.widget.ImageView
import android.widget.Toast
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import es.verdnatura.R
import es.verdnatura.databinding.FragmentCollectionBinding
import es.verdnatura.domain.ConstAndValues.VERTICKET
import es.verdnatura.domain.toast
import es.verdnatura.presentation.base.BaseFragment
import es.verdnatura.presentation.common.*
import es.verdnatura.presentation.view.component.CustomDialog
import es.verdnatura.presentation.view.feature.collection.adapter.SaleAdapter
import es.verdnatura.presentation.view.feature.sacador.model.CollectionVO
import es.verdnatura.presentation.view.feature.sacador.model.SaleVO
class CollectionShowTicketFragment(
var collection: CollectionVO = CollectionVO(0),
var type: String = ""
) : BaseFragment<FragmentCollectionBinding, CollectionViewModel>(CollectionViewModel::class) {
private var sales: List<SaleVO> = listOf()
private var saleAdapter: SaleAdapter? = null
private var lm: LinearLayoutManager? = null
private var pasillerosItemClickListener: OnPasillerosItemClickListener? = null
private lateinit var customDialog: CustomDialog
private var tickets: ArrayList<String> = ArrayList()
private var lastScanned: Int = 0
private var buttonPushedGetCollection = false
companion object {
fun newInstance(collection: CollectionVO, type: String) =
CollectionShowTicketFragment(collection, type)
}
override fun onAttach(context: Context) {
if (context is OnPasillerosItemClickListener) pasillerosItemClickListener = context
super.onAttach(context)
}
override fun getLayoutId(): Int = R.layout.fragment_collection
override fun onCreate(savedInstanceState: Bundle?) {
if (collection.tickets.isEmpty()) {
viewModel.collectionTicketGet(
collection.collectionFk,
getDataInt(SECTORFK),
print = "0",
type
)
}
super.onCreate(savedInstanceState)
}
override fun init() {
customDialog = CustomDialog(requireContext())
//84ma.hideBottomNavigation(GONE)
binding.splashProgress.visibility = VISIBLE
setEvents()
setToolBarIcon()
binding.mainToolbar.toolbarSubtitle.visibility = VISIBLE
if (collection.tickets.isNotEmpty()) {
createCollectionList()
}
super.init()
}
private fun setToolBarIcon() {
binding.mainToolbar.toolbarSubtitle.visibility = VISIBLE
val listIcons: ArrayList<ImageView> = ArrayList()
val iconPrint = ImageView(context)
val iconViewCollection = ImageView(context)
iconViewCollection.setImageResource(R.drawable.ic_collection)
iconPrint.setImageResource(R.drawable.ic_print_black_24dp)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
iconPrint.tooltipText = getTooltip(R.drawable.ic_print_black_24dp)
}
listIcons.add(iconPrint)
listIcons.add(iconViewCollection)
binding.mainToolbar.toolbarIcons.adapter =
ToolBarAdapterTooltip(listIcons, object : OnOptionsSelectedListener {
override fun onOptionsItemSelected(item: Drawable) {
when (item) {
iconPrint.drawable -> print()
iconViewCollection.drawable -> getCollection()
}
}
})
binding.mainToolbar.toolbarIcons.layoutManager =
LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)
}
private fun getCollection() {
binding.splashProgress.visibility = VISIBLE
if (!buttonPushedGetCollection) {
viewModel.collection_get(
collection.collectionFk,
getDataInt(SECTORFK),
print = "0",
type
)
buttonPushedGetCollection = true
} else {
viewModel.collectionTicketGet(
lastScanned,
getDataInt(SECTORFK),
print = "0",
type
)
buttonPushedGetCollection = false
}
lastScanned = collection.collectionFk
}
private fun print() {
//tarea#4672
var isTicket = false
for (t in collection.tickets) {
if (t.ticketFk.toInt() == (collection.collectionFk)) {
isTicket = true
}
}
if (isTicket) {
val builder = AlertDialog.Builder(context)
builder.setTitle(getString(R.string.selectLabeltoPrint))
val labelCount = arrayOf("1", "2", "3", "4", "5", "6", "7", "8", "9", "10")
builder.setItems(labelCount) { dialog, which ->
viewModel.collectionStickerPrint(
collectionFk = collection.collectionFk,
labelCount = (which + 1)
)
}
val dialog = builder.create()
dialog.show()
} else {
viewModel.collectionStickerPrint(
collectionFk = collection.collectionFk,
labelCount = null
)
}
}
private fun setEvents() {
binding.mainToolbar.backButton.setOnClickListener {
requireActivity().onBackPressed()
}
binding.scanInput.setOnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) {//ID=0 ACTION_NEXT ID=5 ACTION_UNESPECEFIED)
if (!binding.scanInput.text.toString().isNullOrEmpty()) {
binding.splashProgress.visibility = VISIBLE
viewModel.collectionTicketGet(
binding.scanInput.text.toString().toInt(),
getDataInt(SECTORFK),
print = "0",
type
)
}
binding.scanInput.setText("")
hideKeyboards()
return@setOnEditorActionListener true
}
true
}
hideKeyboards()
binding.collectionSwipe.setOnRefreshListener {
binding.collectionSwipe.isRefreshing = false
binding.splashProgress.visibility = VISIBLE
viewModel.collectionTicketGet(
collection.collectionFk,
getDataInt(SECTORFK),
print = "0",
type
)
binding.collectionSwipe.isRefreshing = false
}
}
private fun hideKeyboards() {
try {
requireActivity().hideKeyboard()
} catch (e: Exception) {
}
}
override fun observeViewModel() {
with(viewModel) {
binding.splashProgress.visibility = GONE
collectionTicketList.observe(viewLifecycleOwner, Observer {
if (!it.isError) {
if (it.tickets.isNotEmpty()) {
collection = it
createCollectionList()
} else {
binding.mainToolbar.toolbarSubtitle.text = "0/0"
}
} else {
ma.messageWithSound(it.errorMessage, it.isError, false)
if (activity != null) requireActivity().onBackPressed()
}
})
responsePrint.observe(viewLifecycleOwner, Observer {
binding.splashProgress.visibility = GONE
if (it.isError) {
ma.messageWithSound(
it.errorMessage,
it.isError, true
)
} else {
(getString(R.string.Imprimiendo) + getData(PRINTERNAME)).toast(requireContext())
}
})
}
}
private fun createCollectionList() {
binding.mainToolbar.toolbarTitle.text = collection.collectionFk.toString()
binding.splashProgress.visibility = View.GONE
var salesList: ArrayList<SaleVO> = ArrayList()
tickets = ArrayList()
var observations = ""
collection.tickets.forEach { ticket ->
ticket.sales.forEach { saleVO ->
if (type == VERTICKET) {
salesList.add(saleVO)
if (tickets.firstOrNull { it == saleVO.ticketFk }.isNullOrEmpty())
tickets.add(saleVO.ticketFk)
}
observations = observations + " " + ticket.observations
}
}
sales = salesList.sortedWith(compareBy({ it.saleOrder }))
saleAdapter =
SaleAdapter(sales, pasillerosItemClickListener!!, object : OnQuantityClickListener {
override fun onQuantityClick(sale: SaleVO) {
}
}, object : OnSaleClickListener {
override fun onSaleClick(sale: SaleVO) {
}
}, object : OnMistakeClickListener {
override fun onMistakeClickListener(sale: SaleVO) {
}
}, object : onPackingClickListener {
override fun onPackingClick(sale: SaleVO) {
}
}
)
lm = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false)
binding.fragmentSacadorCollections.adapter = saleAdapter
binding.fragmentSacadorCollections.layoutManager = lm
setTotalLines()
printObservations(observations)
binding.scanInput.requestFocus()
}
private fun printObservations(observations: String) {
if (observations.trim().isNotEmpty()) {
customDialog.setTitle(getString(R.string.observations)).setDescription(observations)
.setOkButton(getString(R.string.accept)) {
customDialog.hide()
customDialog.dismiss()
}.show()
}
}
private fun setTotalLines() {
var totalMark = 0
sales.forEach {
if (it.isControlled == "1")
totalMark += 1
}
binding.mainToolbar.toolbarTitle.text =
collection.collectionFk.toString()
binding.mainToolbar.toolbarSubtitle.text =
"" + totalMark + "/" + sales.size
if (totalMark == sales.size) {
getString(R.string.Coleccióncompleta).toast(this.context, Toast.LENGTH_SHORT)
}
}
}

View File

@ -128,19 +128,26 @@ class LoadUnloadFragment(
ToolBarAdapterTooltip(listIcons, object : OnOptionsSelectedListener { ToolBarAdapterTooltip(listIcons, object : OnOptionsSelectedListener {
override fun onOptionsItemSelected(item: Drawable) { override fun onOptionsItemSelected(item: Drawable) {
try {
when (item) { when (item) {
iconConfirm.drawable -> { iconConfirm.drawable -> {
saveLoaded() saveLoaded()
setExpeditionsState(myList, state) setExpeditionsState(myList, state)
} }
iconSign.drawable -> { iconSign.drawable -> {
setExpeditionsState(myList, state) setExpeditionsState(myList, state)
//openSignActivity() //openSignActivity()
}
} }
} catch (ex:Exception){
//Tarea 5313
getString(R.string.errorNotData).toast(requireContext())
} }
} }
}) })
binding.mainToolbar.toolbarIcons.layoutManager = binding.mainToolbar.toolbarIcons.layoutManager =

View File

@ -123,12 +123,23 @@ class InventaryFragment :
ToolBarAdapterTooltip(listIcons, object : OnOptionsSelectedListener { ToolBarAdapterTooltip(listIcons, object : OnOptionsSelectedListener {
override fun onOptionsItemSelected(item: Drawable) { override fun onOptionsItemSelected(item: Drawable) {
if (item == iconReload.drawable) { if (item == iconReload.drawable) {
binding.splashProgress.visibility = View.VISIBLE
firstVisiblePosition = layoutManager?.findFirstVisibleItemPosition() ?: 0 firstVisiblePosition = layoutManager?.findFirstVisibleItemPosition() ?: 0
viewModel.getInventory( if (buyerId.isNotBlank()) {
buyerId.toInt(), viewModel.getInventory(
getDataInt(WAREHOUSEFK) buyerId.toInt(),
) getDataInt(WAREHOUSEFK)
)
binding.splashProgress.visibility = View.VISIBLE
} else {
ma.messageWithSound(
getString(R.string.selectBuyer),
true,
isPlayed = true,
isToasted = true
)
}
} }

View File

@ -3,11 +3,8 @@ package es.verdnatura.presentation.view.feature.pasillero.fragment
import android.content.Context import android.content.Context
import android.graphics.Color import android.graphics.Color
import android.os.Bundle import android.os.Bundle
import android.util.Log.d
import android.view.LayoutInflater
import android.view.MotionEvent
import android.view.View import android.view.View
import android.view.ViewGroup import androidx.core.content.res.ResourcesCompat
import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import es.verdnatura.R import es.verdnatura.R
@ -18,10 +15,13 @@ import es.verdnatura.presentation.view.feature.pasillero.adapter.PasillerosAdapt
class PasilleroFragment( class PasilleroFragment(
var tagName: String = "", private var tagName: String = "",
var isInitMenu: Boolean var isInitMenu: Boolean
) : BaseFragment<FragmentPasilleroBinding, PasilleroViewModel>(PasilleroViewModel::class) { ) : BaseFragment<FragmentPasilleroBinding, PasilleroViewModel>(PasilleroViewModel::class) {
//Tarea 5313
constructor() : this("", false)
private var pasillerosItemClickListener: OnPasillerosItemClickListener? = null private var pasillerosItemClickListener: OnPasillerosItemClickListener? = null
companion object { companion object {
@ -40,39 +40,31 @@ class PasilleroFragment(
override fun init() { override fun init() {
ma.hideBottomNavigation(View.VISIBLE) ma.hideBottomNavigation(View.VISIBLE)
when (tagName) {
getString(R.string.main) -> {
if (getData(WORKFORMSELECTED) != "Producción") {
binding.mainToolbarDesign.toolbarTitle.setBackgroundColor(Color.RED)
"En modo " + getData(WORKFORMSELECTED)
binding.mainToolbarDesign.toolbarTitle.text =
"En modo " + getData(WORKFORMSELECTED)
binding.mainToolbarDesign.backButton.visibility = View.GONE
} else {
binding.mainToolbarDesign.imageViewMenu.visibility = View.VISIBLE
binding.mainToolbarDesign.backButton.visibility = View.GONE
}
}
tagName -> { if (getString(R.string.main) == tagName) {
if (tagName == getString(R.string.titleCorridors)) { if (getData(WORKFORMSELECTED) != "Producción") {
binding.mainToolbarDesign.backButton.visibility = View.GONE binding.mainToolbarDesign.toolbarTitle.setBackgroundColor(Color.RED)
} binding.mainToolbarDesign.toolbarTitle.text =
binding.mainToolbarDesign.backButton.visibility = View.VISIBLE String.format(getString(R.string.mode, getData(WORKFORMSELECTED)))
binding.mainToolbarDesign.toolbarTitle.text = tagName binding.mainToolbarDesign.backButton.visibility = View.GONE
binding.mainToolbarDesign.imageViewMenu.visibility = View.GONE } else {
binding.mainToolbarDesign.imageViewMenu.visibility = View.VISIBLE
binding.mainToolbarDesign.backButton.visibility = View.GONE
} }
} else {
if (tagName == getString(R.string.titleCorridors)) {
binding.mainToolbarDesign.backButton.visibility = View.GONE
}
binding.mainToolbarDesign.backButton.visibility = View.VISIBLE
binding.mainToolbarDesign.toolbarTitle.text = tagName
binding.mainToolbarDesign.imageViewMenu.visibility = View.GONE
} }
binding.mainToolbarDesign.backButton.setOnClickListener { binding.mainToolbarDesign.backButton.setOnClickListener {
requireActivity().onBackPressed() requireActivity().onBackPressed()
} }
super.init() super.init()
} }
@ -82,13 +74,21 @@ class PasilleroFragment(
getString(R.string.titleCorridors) -> { getString(R.string.titleCorridors) -> {
viewModel.inititializeDefaultData() viewModel.inititializeDefaultData()
} }
getString(R.string.titlePalletizers) -> viewModel.inititializeDefaultPallet() getString(R.string.titlePalletizers) -> viewModel.inititializeDefaultPallet()
getString(R.string.titleBufferManegement) -> viewModel.inititializeDefaultBuffer() getString(R.string.titleBufferManegement) -> viewModel.inititializeDefaultBuffer()
getString(R.string.main) -> viewModel.inititializeDefaultDataInit() getString(R.string.main) -> viewModel.inititializeDefaultDataInit()
getString(R.string.titleClaims) -> viewModel.inititializeDefaultClaim() getString(R.string.titleClaims) -> viewModel.inititializeDefaultClaim()
getString(R.string.titleDelivery) -> viewModel.inititializeDefaultDelivery() getString(R.string.titleDelivery) -> viewModel.inititializeDefaultDelivery()
getString(R.string.titlePrevious) -> viewModel.inititializeDefaultPrevia()
getString(R.string.titleControllers) -> viewModel.inititializeDefaultChecker()
getString(R.string.titleOther) -> viewModel.inititializeDefaultOther()
getString(R.string.historicals) -> viewModel.inititializeDefaultHistorical()
else -> {
//Tarea 5313
viewModel.inititializeDefaultDataInit()
}
} }
@ -98,11 +98,6 @@ class PasilleroFragment(
override fun observeViewModel() { override fun observeViewModel() {
with(viewModel) { with(viewModel) {
/* val mLayoutManager: RecyclerView.LayoutManager = GridLayoutManager(
activity,
requireActivity()!!.resources.getInteger(R.integer.number_of_grid_items)
)*/
binding.pasillerosItems.adapter = binding.pasillerosItems.adapter =
PasillerosAdapter(pasillerositem, pasillerosItemClickListener!!, isInitMenu) PasillerosAdapter(pasillerositem, pasillerosItemClickListener!!, isInitMenu)
binding.pasillerosItems.layoutManager = binding.pasillerosItems.layoutManager =
@ -115,10 +110,12 @@ class PasilleroFragment(
LinearLayoutManager.VERTICAL LinearLayoutManager.VERTICAL
) )
dividerItemDecoration.setDrawable( dividerItemDecoration.setDrawable(
requireContext().resources.getDrawable(
ResourcesCompat.getDrawable(
requireContext().resources,
R.drawable.list_divider_items, R.drawable.list_divider_items,
requireContext().theme requireContext().theme
) )!!
) )
binding.pasillerosItems.addItemDecoration(dividerItemDecoration) binding.pasillerosItems.addItemDecoration(dividerItemDecoration)
} }

View File

@ -2,6 +2,7 @@ package es.verdnatura.presentation.view.feature.sacador.fragment.showticket
import android.content.Context import android.content.Context
import android.os.Bundle import android.os.Bundle
import android.text.InputType.TYPE_CLASS_NUMBER
import android.view.View import android.view.View
import android.view.inputmethod.EditorInfo import android.view.inputmethod.EditorInfo
import es.verdnatura.R import es.verdnatura.R
@ -67,19 +68,29 @@ class ShowTicketFragment(var menuOrigin: String) :
} }
binding.scanInput.requestFocus() binding.scanInput.requestFocus()
binding.scanInput.setRawInputType(TYPE_CLASS_NUMBER)
binding.scanInput.setOnEditorActionListener { v, actionId, event -> binding.scanInput.setOnEditorActionListener { v, actionId, event ->
if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) { if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) {
goBack = false goBack = false
if (!binding.scanInput.text.isNullOrEmpty()) { if (!binding.scanInput.text.isNullOrEmpty()) {
binding.splashProgress.visibility = View.VISIBLE
viewModel.collectionTicketGet( try {
sectorFk = getDataInt(SECTORFK),
collectionFk = binding.scanInput.text.toString().toInt(),
print="0",
type = type
) viewModel.collectionTicketGet(
sectorFk = getDataInt(SECTORFK),
collectionFk = binding.scanInput.text.toString().toInt(),
print = "0",
type = type
)
binding.splashProgress.visibility = View.VISIBLE
} catch (ex: Exception) {
ma.messageWithSound(
getString(R.string.errorReviewItem),
true,
isPlayed = true,
isToasted = true
)
}
} }
binding.scanInput.setText("") binding.scanInput.setText("")
ma.hideKeyboard(binding.scanInput) ma.hideKeyboard(binding.scanInput)