feat: refs #8176 refactorSearchDialog

This commit is contained in:
Sergio De la torre 2024-11-20 07:55:47 +01:00
parent 7837a11254
commit 61e6aa2a5a
5 changed files with 94 additions and 108 deletions

View File

@ -40,7 +40,7 @@ class SearchableRecyclerView @JvmOverloads constructor(
}
override fun onQueryTextChange(newText: String?): Boolean {
adapter.filter(newText ?: "")
if (::adapter.isInitialized) adapter.filter(newText ?: "")
return true
}
})
@ -72,4 +72,9 @@ class SearchableRecyclerView @JvmOverloads constructor(
return this
}
fun setSearchHintWithoutFocus(searchHint: String): SearchableRecyclerView {
searchView.queryHint = searchHint
return this
}
}

View File

@ -121,8 +121,7 @@ class AjustesFragment :
binding.searchableRecyclerView.setAdapter(adapter, listNames)
binding.searchableRecyclerView.visibility = View.VISIBLE
binding.searchableRecyclerView.setSearchHint(getString(R.string.sectorSearch))
binding.searchableRecyclerView.setSearchHintWithoutFocus(getString(R.string.sectorSearch))
}
private fun setToolBar() {

View File

@ -12,15 +12,13 @@ import es.verdnatura.domain.ConstAndValues.SUPPLIERID
import es.verdnatura.domain.ConstAndValues.SUPPLIERNAME
import es.verdnatura.presentation.base.BaseFragment
import es.verdnatura.presentation.common.OnPasillerosItemClickListener
import es.verdnatura.presentation.view.commom.NameWithId
import es.verdnatura.presentation.view.commom.SearchableAdapter
import es.verdnatura.presentation.view.component.CustomDialog
import es.verdnatura.presentation.view.feature.inventario.fragment.SearchSupplierModel
import es.verdnatura.presentation.view.feature.packaging.model.EntrySalix
import es.verdnatura.presentation.view.feature.packaging.model.Supplier
import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO
import ir.mirrajabi.searchdialog.SimpleSearchDialogCompat
import kotlinx.coroutines.runBlocking
@Suppress("UNUSED_ANONYMOUS_PARAMETER")
class SupplierFragment(
var entryPoint: String = ""
@ -31,8 +29,7 @@ class SupplierFragment(
private var pasillerosItemClickListener: OnPasillerosItemClickListener? = null
private var layoutManager: LinearLayoutManager? = null
private var onBack = false
private val suppliers = ArrayList<SearchSupplierModel>()
private val entries = ArrayList<SearchSupplierModel>()
private val entries = ArrayList<EntrySalix>()
private lateinit var customDialog: CustomDialog
companion object {
@ -59,27 +56,14 @@ class SupplierFragment(
override fun init() {
binding.filterSupplier.setOnClickListener {
SimpleSearchDialogCompat(
context,
getString(R.string.suppliers),
getString(R.string.escribirparteNombre),
null,
suppliers
) { baseSearchDialogCompat, nombre, position ->
binding.filterSupplier.text = (nombre.getName())
runBlocking {
mobileApplication.dataStoreApp.editDataStoreKey(
SUPPLIERNAME,
nombre.getName()
)
mobileApplication.dataStoreApp.editDataStoreKey(
SUPPLIERID,
nombre.getId().toInt()
)
binding.searchableSuplierRecyclerView.visibility = View.VISIBLE
binding.searchableSuplierRecyclerView.setSearchHint(getString(R.string.supplierSearch))
}
viewModel.getEntriesFromSupplier(nombre.getId().toInt())
baseSearchDialogCompat.dismiss()
}.show()
binding.filterEntry.setOnClickListener {
binding.searchableEntriesRecyclerView.visibility = View.VISIBLE
binding.searchableEntriesRecyclerView.setSearchHint(getString(R.string.entrySearch))
}
customDialog = CustomDialog(requireContext())
ma.hideBottomNavigation(View.GONE)
@ -89,6 +73,64 @@ class SupplierFragment(
super.init()
}
private fun setSearchable(listNames: MutableList<NameWithId>) {
val adapter =
SearchableAdapter(
listElements = listNames,
context = requireContext()
) { elementSelected ->
binding.filterSupplier.text = (elementSelected.name)
runBlocking {
mobileApplication.dataStoreApp.editDataStoreKey(
SUPPLIERNAME,
elementSelected.name
)
mobileApplication.dataStoreApp.editDataStoreKey(
SUPPLIERID,
elementSelected.id
)
}
viewModel.getEntriesFromSupplier(elementSelected.id)
binding.searchableSuplierRecyclerView.visibility = View.GONE
}
binding.searchableSuplierRecyclerView.setAdapter(adapter, listNames)
}
private fun setSearchableEntries(listNames: MutableList<NameWithId>) {
val adapter =
SearchableAdapter(
listElements = listNames,
context = requireContext()
) { elementSelected ->
binding.filterEntry.text = elementSelected.name
runBlocking {
mobileApplication.dataStoreApp.editDataStoreKey(
ENTRYID,
elementSelected.id
)
mobileApplication.dataStoreApp.editDataStoreKey(
ENTRYOBSERVATIONORIGINAL,
entries.find { it.id == elementSelected.id }?.observation ?: ""
)
mobileApplication.dataStoreApp.deleteImages()
}
ma.onPasillerosItemClickListener(
PasillerosItemVO(title = R.string.titlePackagingCount),
getString(R.string.titlePackagingCount)
)
binding.searchableEntriesRecyclerView.visibility = View.GONE
}
binding.searchableEntriesRecyclerView.setAdapter(adapter, listNames)
}
private fun setToolBar() {
binding.mainToolbar.toolbarTitle.text = entryPoint
}
@ -103,41 +145,18 @@ class SupplierFragment(
private fun setEntryDialog() {
binding.filterEntry.visibility = View.VISIBLE
binding.filterEntry.setOnClickListener {
SimpleSearchDialogCompat(
context,
getString(R.string.entry),
getString(R.string.escribirparteNombre),
null,
entries
) { baseSearchDialogCompat, nombre, position ->
binding.filterEntry.text = nombre.getName()
runBlocking {
mobileApplication.dataStoreApp.editDataStoreKey(
ENTRYID,
nombre.getId().toInt()
)
mobileApplication.dataStoreApp.editDataStoreKey(
ENTRYOBSERVATIONORIGINAL,
nombre.getObservation()
)
mobileApplication.dataStoreApp.deleteImages()
}
ma.onPasillerosItemClickListener(
PasillerosItemVO(title = R.string.titlePackagingCount),
getString(R.string.titlePackagingCount)
)
// }
baseSearchDialogCompat.dismiss()
}.show()
}
}
override fun observeViewModel() {
with(viewModel) {
supplierList.observe(viewLifecycleOwner) {
createSupplierList(it.list)
supplierList.observe(viewLifecycleOwner) { item ->
setSearchable(item.list.map {
NameWithId(
it.id!!,
it.name!!
)
} as MutableList<NameWithId>)
}
entryList.observe(viewLifecycleOwner) {
createEntryList(it.list)
@ -162,57 +181,20 @@ class SupplierFragment(
}
}
private fun createSupplierList(list: List<Supplier>) {
suppliers.clear()
if (list.isNotEmpty())
list.forEach { supplier ->
try {
suppliers.add(
SearchSupplierModel(
supplier.name,
supplier.id.toString(),
observation = ""
)
)
} catch (ex: Exception) {
ma.messageWithSound(
message = ex.message.toString(),
isError = true,
isPlayed = true
)
}
}
}
private fun createEntryList(list: List<EntrySalix>) {
list.sortedBy { it.travel?.landed }
entries.clear()
list.forEach { entry ->
if (!entry.isError) {
try {
entries.add(
SearchSupplierModel(
entry.id.toString() + "->" + (entry.travel?.landed),
id = entry.id.toString(),
observation = entry.observation
)
if (list.isNotEmpty() && !list[0].isError) {
setSearchableEntries(list.map { entry ->
NameWithId(
entry.id!!,
entry.id.toString() + "->" + (entry.travel?.landed)
)
} as MutableList<NameWithId>)
entries.addAll(list.sortedBy { it.travel?.landed })
}
binding.filterEntry.visibility = View.VISIBLE
} catch (ex: Exception) {
ma.messageWithSound(
message = ex.message.toString(),
isError = true,
isPlayed = true
)
}
}
}
setEntryDialog()
}
}

View File

@ -70,7 +70,7 @@ class SupplierViewModel(val context: Context) : BaseViewModel(context) {
})
}
fun getEntriesFromSupplier(supplier: Int) {
fun getEntriesFromSupplier(supplier: Number) {
val calendar = Calendar.getInstance()
calendar.add(Calendar.DAY_OF_YEAR, 0)