feat: refs#6659 DayOfSaleScreen
This commit is contained in:
parent
889dcd1fe8
commit
ad370ba09a
|
@ -0,0 +1,137 @@
|
||||||
|
package es.verdnatura.presentation.view.feature.diadeventa.fragment
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.view.inputmethod.EditorInfo
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.ui.platform.ComposeView
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
|
import es.verdnatura.R
|
||||||
|
import es.verdnatura.presentation.common.OnPasillerosItemClickListener
|
||||||
|
import es.verdnatura.presentation.composable.IconToolBar
|
||||||
|
import es.verdnatura.presentation.view.component.CustomDialog
|
||||||
|
import es.verdnatura.presentation.view.component.CustomDialogList
|
||||||
|
import es.verdnatura.presentation.view.feature.diadeventa.adapter.DayOfSaleAdapter
|
||||||
|
import es.verdnatura.presentation.view.feature.main.activity.MainActivity
|
||||||
|
import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO
|
||||||
|
import org.koin.androidx.viewmodel.ext.android.viewModel
|
||||||
|
|
||||||
|
class DayOfSaleFragmentCompose(
|
||||||
|
var title: String = ""
|
||||||
|
) : Fragment() {
|
||||||
|
private val viewModel: DayOfSaleViewModelCompose by viewModel()
|
||||||
|
|
||||||
|
private lateinit var customDialogList: CustomDialogList
|
||||||
|
private lateinit var customDialog: CustomDialog
|
||||||
|
private var adapter: DayOfSaleAdapter? = null
|
||||||
|
private var itemScan = ""
|
||||||
|
private var pasillerosItemClickListener: OnPasillerosItemClickListener? = null
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun newInstance(title: String) = DayOfSaleFragmentCompose(title)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onAttach(context: Context) {
|
||||||
|
if (context is OnPasillerosItemClickListener) pasillerosItemClickListener = context
|
||||||
|
super.onAttach(context)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateView(
|
||||||
|
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||||
|
): View {
|
||||||
|
return ComposeView(requireContext()).apply {
|
||||||
|
setContent {
|
||||||
|
SetView()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun SetView() {
|
||||||
|
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
|
||||||
|
|
||||||
|
val columnActions = listOf<(List<String>) -> Unit>(
|
||||||
|
// { item -> println("Producto seleccionado: ${item[0]}") }, // Acción para la primera columna
|
||||||
|
// { item -> println("Stock: ${item[1]}") }, // Acción para la segunda columna
|
||||||
|
// { item -> println("Visible: ${item[2]}") } // Acción para la tercera columna
|
||||||
|
)
|
||||||
|
|
||||||
|
GenericListScreen(
|
||||||
|
uiState.items.map { item ->
|
||||||
|
listOf(
|
||||||
|
item.itemFk?.toString() ?: "",
|
||||||
|
item.longName ?: "",
|
||||||
|
item.dated,
|
||||||
|
item.visible?.toString() ?: "",
|
||||||
|
item.stock?.toString() ?: ""
|
||||||
|
)
|
||||||
|
},
|
||||||
|
columnActions = columnActions,
|
||||||
|
headers = listOf(
|
||||||
|
getString(R.string.itemfk),
|
||||||
|
getString(R.string.name),
|
||||||
|
getString(R.string.date),
|
||||||
|
getString(R.string.visible),
|
||||||
|
getString(R.string.stock)
|
||||||
|
),
|
||||||
|
onTextChange = { input ->
|
||||||
|
viewModel.itemShelvingGetSaleDate(input)
|
||||||
|
},
|
||||||
|
titleToolBar =
|
||||||
|
if (uiState.shelvingCode.isNullOrEmpty()) title else title + " " + uiState.shelvingCode,
|
||||||
|
onBackClick = { (context as MainActivity).onMyBackPressed() },
|
||||||
|
onLongClick = { },
|
||||||
|
onClick = { item -> openSearchItemFragment(item[0]) },
|
||||||
|
listIconToolBar = listOf(
|
||||||
|
IconToolBar(
|
||||||
|
idRes = R.drawable.ic_local_parking_black_24dp,
|
||||||
|
toolTip = getString(R.string.allowParking),
|
||||||
|
onClickIcon = { showParking() },
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun showParking() {
|
||||||
|
|
||||||
|
customDialogList = CustomDialogList(requireContext())
|
||||||
|
customDialogList.setTitle(getString(R.string.showParking))
|
||||||
|
.setOkButton(getString(R.string.close)) {
|
||||||
|
|
||||||
|
customDialogList.dismiss()
|
||||||
|
}.setValue("").show()
|
||||||
|
|
||||||
|
customDialogList.getEditText().requestFocus()
|
||||||
|
customDialogList.getEditText().setOnEditorActionListener { _, actionId, _ ->
|
||||||
|
if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_DONE || actionId == 0 || actionId == 5) {
|
||||||
|
if (customDialogList.getValue().isNotEmpty()) {
|
||||||
|
viewModel.setParking(
|
||||||
|
parking = customDialogList.getValue(),
|
||||||
|
scanItem = itemScan
|
||||||
|
)
|
||||||
|
|
||||||
|
customDialogList.dismiss()
|
||||||
|
}
|
||||||
|
customDialogList.setValue("")
|
||||||
|
return@setOnEditorActionListener true
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun openSearchItemFragment(item: String) {
|
||||||
|
pasillerosItemClickListener!!.onPasillerosItemClickListener(
|
||||||
|
PasillerosItemVO(
|
||||||
|
title =
|
||||||
|
R.string.titleItemConsult
|
||||||
|
), item
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
package es.verdnatura.presentation.view.feature.diadeventa.fragment
|
||||||
|
|
||||||
|
import es.verdnatura.domain.SalixCallback
|
||||||
|
import es.verdnatura.domain.formatWithQuotes
|
||||||
|
import es.verdnatura.presentation.base.BaseViewModelCompose
|
||||||
|
import es.verdnatura.presentation.view.feature.diadeventa.model.ItemShelvingSaleDate
|
||||||
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
|
import kotlinx.coroutines.flow.update
|
||||||
|
import retrofit2.Response
|
||||||
|
|
||||||
|
data class UiState(
|
||||||
|
val shelvingCode: String? = null,
|
||||||
|
val items: List<ItemShelvingSaleDate> = emptyList()
|
||||||
|
)
|
||||||
|
|
||||||
|
class DayOfSaleViewModelCompose(var application: android.app.Application) :
|
||||||
|
BaseViewModelCompose(application) {
|
||||||
|
|
||||||
|
private val _uiState = MutableStateFlow(UiState())
|
||||||
|
val uiState = _uiState.asStateFlow()
|
||||||
|
|
||||||
|
fun itemShelvingGetSaleDate(vShelvingFK: String) {
|
||||||
|
_uiState.update { it.copy(shelvingCode = vShelvingFK) }
|
||||||
|
salix.itemShelvingGetSaleDate(params = listOf(vShelvingFK).formatWithQuotes())
|
||||||
|
.enqueue(object :
|
||||||
|
SalixCallback<List<ItemShelvingSaleDate>>(application.applicationContext) {
|
||||||
|
|
||||||
|
override fun onSuccess(response: Response<List<ItemShelvingSaleDate>>) {
|
||||||
|
|
||||||
|
response.body()?.let { list ->
|
||||||
|
_uiState.update { it.copy(items = list) }
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setParking(scanItem: String, parking: String) {
|
||||||
|
salix.setParking(arrayListOf(scanItem, parking).formatWithQuotes())
|
||||||
|
.enqueue(object : SalixCallback<Any>(application.applicationContext) {})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue