feat: refs #8176 refactorSearchDialog
This commit is contained in:
parent
ca91beddf3
commit
233399dcb3
|
@ -69,7 +69,6 @@ import es.verdnatura.presentation.view.feature.sacador.model.TicketStateSalix
|
|||
import es.verdnatura.presentation.view.feature.ubicador.model.ItemBuy
|
||||
import es.verdnatura.presentation.view.feature.ubicador.model.ItemShelvingNewer
|
||||
import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicador
|
||||
import es.verdnatura.presentation.view.feature.ubicador.model.ItemUbicadorVO
|
||||
import es.verdnatura.presentation.view.feature.workermistake.model.DepartmentMistake
|
||||
import es.verdnatura.presentation.view.feature.workermistake.model.ExpeditionMistakeSalix
|
||||
import es.verdnatura.presentation.view.feature.workermistake.model.MistakeType
|
||||
|
@ -140,6 +139,11 @@ interface SalixService {
|
|||
@Query("filter") filter: String
|
||||
): Call<List<AddressLoses>>
|
||||
|
||||
@POST("Applications/buy_getUltimate/execute-func")
|
||||
fun buyUltimate(
|
||||
@Query("params") params: Any, @Query("schema") schema: String = "vn"
|
||||
): Call<Long>
|
||||
|
||||
@GET("Buyers")
|
||||
fun getBuyers(
|
||||
@Query("filter") filter: String
|
||||
|
@ -440,6 +444,12 @@ interface SalixService {
|
|||
@Query("barcode") barcode: Number, @Query("warehouseFk") warehouseFk: Int
|
||||
): Call<ItemCardVO>
|
||||
|
||||
@POST("Applications/report_print/execute-proc")
|
||||
fun printItem(
|
||||
@Query("params") params: Any? = null,
|
||||
@Query("schema") schema: String = "vn"
|
||||
): Call<Unit>
|
||||
|
||||
@POST("Applications/itemPlacementSupplyAiming/execute-proc")
|
||||
fun itemPlacementSupplyAiming(
|
||||
@Query("params") params: Any? = null, @Query("schema") schema: String = "vn"
|
||||
|
@ -643,12 +653,6 @@ interface SalixService {
|
|||
@Query("params") params: Any,
|
||||
): Call<List<ItemLocationVO>>
|
||||
|
||||
@POST("Applications/itemShelving_get/execute-proc")
|
||||
fun itemShelvingList(
|
||||
@Query("schema") schema: String = "vn",
|
||||
@Query("params") params: Any,
|
||||
): Call<List<ItemUbicadorVO>>
|
||||
|
||||
@POST("Applications/itemShelving_get/execute-proc")
|
||||
fun itemShelvingListNew(
|
||||
@Query("schema") schema: String = "vn",
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
package es.verdnatura.presentation.view.commom
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.text.Spannable
|
||||
import android.text.SpannableString
|
||||
import android.text.style.ForegroundColorSpan
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import es.verdnatura.domain.toast
|
||||
|
||||
class SearchableAdapter(
|
||||
private var names: MutableList<String>,
|
||||
private var context: Context,
|
||||
private val onItemClick: (String) -> Unit,
|
||||
) : RecyclerView.Adapter<SearchableAdapter.NameViewHolder>() {
|
||||
private var nombresFiltrados = names.toMutableList()
|
||||
private var currentQuery: String = ""
|
||||
private lateinit var searchView: SearchView
|
||||
|
||||
inner class NameViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
private val nombreTextView: TextView = itemView.findViewById(android.R.id.text1)
|
||||
|
||||
fun bind(nombre: String, query: String) {
|
||||
val spannableString = SpannableString(nombre)
|
||||
try {
|
||||
|
||||
if (query.isNotEmpty()) {
|
||||
val startIndex = nombre.indexOf(query, ignoreCase = true)
|
||||
if (startIndex >= 0) {
|
||||
val endIndex = startIndex + query.length
|
||||
spannableString.setSpan(
|
||||
ForegroundColorSpan(Color.RED),
|
||||
startIndex,
|
||||
endIndex,
|
||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
|
||||
)
|
||||
}
|
||||
}
|
||||
nombreTextView.text = spannableString
|
||||
itemView.setOnClickListener {
|
||||
onItemClick(nombre)
|
||||
}
|
||||
} catch (ex: Exception) {
|
||||
ex.message!!.toast(context = context)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NameViewHolder {
|
||||
val view = LayoutInflater.from(parent.context)
|
||||
.inflate(android.R.layout.simple_list_item_1, parent, false)
|
||||
return NameViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: NameViewHolder, position: Int) {
|
||||
val nombre = nombresFiltrados[position]
|
||||
holder.bind(nombre, currentQuery)
|
||||
}
|
||||
|
||||
fun filter(query: String) {
|
||||
currentQuery = query
|
||||
nombresFiltrados = if (query.isEmpty()) {
|
||||
names.toMutableList()
|
||||
} else {
|
||||
names.filter { it.contains(query, ignoreCase = true) }
|
||||
.toMutableList()
|
||||
}
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = nombresFiltrados.size
|
||||
|
||||
fun updateList(newList: MutableList<String>) {
|
||||
names = newList
|
||||
filter("")
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package es.verdnatura.presentation.view.commom
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Color
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.LinearLayout
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import es.verdnatura.R
|
||||
|
||||
class SearchableRecyclerView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0
|
||||
) : LinearLayout(context, attrs, defStyleAttr) {
|
||||
|
||||
private val searchView: SearchView
|
||||
private val recyclerView: RecyclerView
|
||||
lateinit var adapter: SearchableAdapter
|
||||
private var allItems: MutableList<String> = mutableListOf()
|
||||
|
||||
init {
|
||||
LayoutInflater.from(context).inflate(R.layout.component_searchable_dialog, this, true)
|
||||
searchView = findViewById(R.id.search_view)
|
||||
recyclerView = findViewById(R.id.recycler_viewer)
|
||||
recyclerView.layoutManager = LinearLayoutManager(context)
|
||||
recyclerView.setBackgroundColor(Color.WHITE)
|
||||
searchView.setBackgroundColor(Color.WHITE)
|
||||
searchView.setOnCloseListener {
|
||||
visibility = View.GONE
|
||||
true
|
||||
}
|
||||
visibility = View.GONE
|
||||
searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
||||
override fun onQueryTextSubmit(query: String?): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun onQueryTextChange(newText: String?): Boolean {
|
||||
adapter.filter(newText ?: "")
|
||||
return true
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fun setAdapter(adapter: SearchableAdapter, items: MutableList<String>) {
|
||||
this.adapter = adapter
|
||||
this.allItems = items
|
||||
recyclerView.adapter = adapter
|
||||
adapter.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
fun setVisibilityRecycler(visibility: Int) {
|
||||
recyclerView.visibility = visibility
|
||||
}
|
||||
|
||||
fun setOnCloseListener(listener: () -> Boolean) {
|
||||
searchView.setOnCloseListener { listener() }
|
||||
}
|
||||
|
||||
fun getSearchView(): SearchView {
|
||||
return searchView
|
||||
}
|
||||
}
|
|
@ -32,6 +32,7 @@ import es.verdnatura.presentation.base.BaseFragment
|
|||
import es.verdnatura.presentation.common.OnAjustesItemClickListener
|
||||
import es.verdnatura.presentation.common.OnOptionsSelectedListener
|
||||
import es.verdnatura.presentation.common.ToolBarAdapterTooltip
|
||||
import es.verdnatura.presentation.view.commom.SearchableAdapter
|
||||
import es.verdnatura.presentation.view.component.CustomDialog
|
||||
import es.verdnatura.presentation.view.feature.ajustes.adapter.SettingsAdapter
|
||||
import es.verdnatura.presentation.view.feature.ajustes.model.AjustesItemVO
|
||||
|
@ -87,6 +88,45 @@ class AjustesFragment :
|
|||
super.init()
|
||||
}
|
||||
|
||||
private fun setSearchable(name: MutableList<String>) {
|
||||
val searchableRecyclerView = binding.searchableRecyclerView
|
||||
searchableRecyclerView.visibility = View.VISIBLE
|
||||
|
||||
val adapter = SearchableAdapter(names = name, context = requireContext()) { nombre ->
|
||||
sectorListVO.forEach {
|
||||
if (it.description == nombre) {
|
||||
runBlocking {
|
||||
mobileApplication.dataStoreApp.editDataStoreKey(
|
||||
PRINTERNAME, getString(R.string.noprinter)
|
||||
)
|
||||
mobileApplication.dataStoreApp.editDataStoreKey(PRINTERFK, -1)
|
||||
mobileApplication.dataStoreApp.editDataStoreKey(
|
||||
SECTORDESCRIP, it.description
|
||||
)
|
||||
mobileApplication.dataStoreApp.editDataStoreKey(
|
||||
SECTORFK, it.id
|
||||
)
|
||||
it.warehouseFk?.let { it1 ->
|
||||
mobileApplication.dataStoreApp.editDataStoreKey(
|
||||
WAREHOUSEFK, it1
|
||||
)
|
||||
}
|
||||
}
|
||||
viewModel.settingsItem[0].sectorFk = it.id
|
||||
viewModel.settingsItem[0].selected = it.description
|
||||
viewModel.workerUpdateOperatorSalix(
|
||||
"sector", mobileApplication.userId!!, it.id, null
|
||||
)
|
||||
settingsAdapter!!.notifyItemChanged(0)
|
||||
return@forEach
|
||||
}
|
||||
}
|
||||
searchableRecyclerView.visibility = View.GONE
|
||||
}
|
||||
searchableRecyclerView.setAdapter(adapter, name)
|
||||
|
||||
}
|
||||
|
||||
private fun setToolBar() {
|
||||
|
||||
val listIcons: ArrayList<ImageView> = ArrayList()
|
||||
|
@ -208,6 +248,8 @@ class AjustesFragment :
|
|||
listSectores.sort()
|
||||
val array = arrayOfNulls<String>(listSectores.size)
|
||||
sectorListVO = it.list
|
||||
//Tarea 8176
|
||||
//setSearchable(sectorListVO.map { it.description } as MutableList<String>)
|
||||
showDialogForAll(
|
||||
listSectores.toArray(array), getString(R.string.selectSector)
|
||||
)
|
||||
|
@ -297,16 +339,6 @@ class AjustesFragment :
|
|||
private fun getUserData() {
|
||||
|
||||
loginViewModel = LoginViewModel(requireActivity().applicationContext)
|
||||
/* try {
|
||||
loginViewModel.operatorGetData(mobileApplication.userId!!)
|
||||
} catch (_: Exception) {
|
||||
ma.messageWithSound(
|
||||
message = getString(R.string.errorGetData), isError = true, isPlayed = true
|
||||
)
|
||||
}
|
||||
loginViewModel.workerOperator.observe(this@AjustesFragment) { iti ->
|
||||
runBlocking { mobileApplication.dataStoreApp.saveDataOperator(iti) }
|
||||
}*/
|
||||
handleUserCall()
|
||||
loginViewModel.handleUserResponse.observe(this@AjustesFragment) { iti ->
|
||||
runBlocking { mobileApplication.dataStoreApp.saveWorkerData(iti) }
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="8dp">
|
||||
|
||||
<es.verdnatura.presentation.view.commom.SearchableRecyclerView
|
||||
android:id="@+id/searchable_recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="8dp" />
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue