feat: refs #8176 refactorSearchDialog
This commit is contained in:
parent
7837a11254
commit
61e6aa2a5a
|
@ -40,7 +40,7 @@ class SearchableRecyclerView @JvmOverloads constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onQueryTextChange(newText: String?): Boolean {
|
override fun onQueryTextChange(newText: String?): Boolean {
|
||||||
adapter.filter(newText ?: "")
|
if (::adapter.isInitialized) adapter.filter(newText ?: "")
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -72,4 +72,9 @@ class SearchableRecyclerView @JvmOverloads constructor(
|
||||||
|
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setSearchHintWithoutFocus(searchHint: String): SearchableRecyclerView {
|
||||||
|
searchView.queryHint = searchHint
|
||||||
|
return this
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,8 +121,7 @@ class AjustesFragment :
|
||||||
|
|
||||||
binding.searchableRecyclerView.setAdapter(adapter, listNames)
|
binding.searchableRecyclerView.setAdapter(adapter, listNames)
|
||||||
binding.searchableRecyclerView.visibility = View.VISIBLE
|
binding.searchableRecyclerView.visibility = View.VISIBLE
|
||||||
binding.searchableRecyclerView.setSearchHint(getString(R.string.sectorSearch))
|
binding.searchableRecyclerView.setSearchHintWithoutFocus(getString(R.string.sectorSearch))
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setToolBar() {
|
private fun setToolBar() {
|
||||||
|
|
|
@ -12,15 +12,13 @@ import es.verdnatura.domain.ConstAndValues.SUPPLIERID
|
||||||
import es.verdnatura.domain.ConstAndValues.SUPPLIERNAME
|
import es.verdnatura.domain.ConstAndValues.SUPPLIERNAME
|
||||||
import es.verdnatura.presentation.base.BaseFragment
|
import es.verdnatura.presentation.base.BaseFragment
|
||||||
import es.verdnatura.presentation.common.OnPasillerosItemClickListener
|
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.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.EntrySalix
|
||||||
import es.verdnatura.presentation.view.feature.packaging.model.Supplier
|
|
||||||
import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO
|
import es.verdnatura.presentation.view.feature.pasillero.model.PasillerosItemVO
|
||||||
import ir.mirrajabi.searchdialog.SimpleSearchDialogCompat
|
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
|
|
||||||
@Suppress("UNUSED_ANONYMOUS_PARAMETER")
|
|
||||||
class SupplierFragment(
|
class SupplierFragment(
|
||||||
var entryPoint: String = ""
|
var entryPoint: String = ""
|
||||||
|
|
||||||
|
@ -31,8 +29,7 @@ class SupplierFragment(
|
||||||
private var pasillerosItemClickListener: OnPasillerosItemClickListener? = null
|
private var pasillerosItemClickListener: OnPasillerosItemClickListener? = null
|
||||||
private var layoutManager: LinearLayoutManager? = null
|
private var layoutManager: LinearLayoutManager? = null
|
||||||
private var onBack = false
|
private var onBack = false
|
||||||
private val suppliers = ArrayList<SearchSupplierModel>()
|
private val entries = ArrayList<EntrySalix>()
|
||||||
private val entries = ArrayList<SearchSupplierModel>()
|
|
||||||
private lateinit var customDialog: CustomDialog
|
private lateinit var customDialog: CustomDialog
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -59,27 +56,14 @@ class SupplierFragment(
|
||||||
|
|
||||||
override fun init() {
|
override fun init() {
|
||||||
binding.filterSupplier.setOnClickListener {
|
binding.filterSupplier.setOnClickListener {
|
||||||
SimpleSearchDialogCompat(
|
binding.searchableSuplierRecyclerView.visibility = View.VISIBLE
|
||||||
context,
|
binding.searchableSuplierRecyclerView.setSearchHint(getString(R.string.supplierSearch))
|
||||||
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()
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
viewModel.getEntriesFromSupplier(nombre.getId().toInt())
|
binding.filterEntry.setOnClickListener {
|
||||||
baseSearchDialogCompat.dismiss()
|
binding.searchableEntriesRecyclerView.visibility = View.VISIBLE
|
||||||
}.show()
|
binding.searchableEntriesRecyclerView.setSearchHint(getString(R.string.entrySearch))
|
||||||
|
|
||||||
}
|
}
|
||||||
customDialog = CustomDialog(requireContext())
|
customDialog = CustomDialog(requireContext())
|
||||||
ma.hideBottomNavigation(View.GONE)
|
ma.hideBottomNavigation(View.GONE)
|
||||||
|
@ -89,6 +73,64 @@ class SupplierFragment(
|
||||||
super.init()
|
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() {
|
private fun setToolBar() {
|
||||||
binding.mainToolbar.toolbarTitle.text = entryPoint
|
binding.mainToolbar.toolbarTitle.text = entryPoint
|
||||||
}
|
}
|
||||||
|
@ -103,41 +145,18 @@ class SupplierFragment(
|
||||||
|
|
||||||
private fun setEntryDialog() {
|
private fun setEntryDialog() {
|
||||||
binding.filterEntry.visibility = View.VISIBLE
|
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() {
|
override fun observeViewModel() {
|
||||||
with(viewModel) {
|
with(viewModel) {
|
||||||
supplierList.observe(viewLifecycleOwner) {
|
supplierList.observe(viewLifecycleOwner) { item ->
|
||||||
createSupplierList(it.list)
|
setSearchable(item.list.map {
|
||||||
|
NameWithId(
|
||||||
|
it.id!!,
|
||||||
|
it.name!!
|
||||||
|
)
|
||||||
|
} as MutableList<NameWithId>)
|
||||||
}
|
}
|
||||||
entryList.observe(viewLifecycleOwner) {
|
entryList.observe(viewLifecycleOwner) {
|
||||||
createEntryList(it.list)
|
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>) {
|
private fun createEntryList(list: List<EntrySalix>) {
|
||||||
list.sortedBy { it.travel?.landed }
|
list.sortedBy { it.travel?.landed }
|
||||||
entries.clear()
|
entries.clear()
|
||||||
list.forEach { entry ->
|
if (list.isNotEmpty() && !list[0].isError) {
|
||||||
if (!entry.isError) {
|
setSearchableEntries(list.map { entry ->
|
||||||
|
NameWithId(
|
||||||
try {
|
entry.id!!,
|
||||||
entries.add(
|
entry.id.toString() + "->" + (entry.travel?.landed)
|
||||||
SearchSupplierModel(
|
|
||||||
entry.id.toString() + "->" + (entry.travel?.landed),
|
|
||||||
id = entry.id.toString(),
|
|
||||||
observation = entry.observation
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
} 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()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,7 +70,7 @@ class SupplierViewModel(val context: Context) : BaseViewModel(context) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getEntriesFromSupplier(supplier: Int) {
|
fun getEntriesFromSupplier(supplier: Number) {
|
||||||
val calendar = Calendar.getInstance()
|
val calendar = Calendar.getInstance()
|
||||||
calendar.add(Calendar.DAY_OF_YEAR, 0)
|
calendar.add(Calendar.DAY_OF_YEAR, 0)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue