I am doing a search filter by identity document in a Recyclerview that is per page, the problem is that at the time of making the filter it only looks for the first diez that is the current page. How would I filter the search from the current page until last page?
RecyclerActasAdapter.java
@Override
public int getItemCount() {
return this.itemsMostrados.size();
}
public void filtrar(String query) {
this.itemsMostrados = new ArrayList<>();
if (query.length() == 0) {
itemsMostrados = listaActas;
layoutResultados.setVisibility(View.GONE);
} else {
ActasActivity actas= new ActasActivity();
for (Datum data: listaActas) {
if (data.getBeneficiario().getNumDocumento().contains(query)
//|| (data.getBeneficiario().getNombre().toLowerCase() + " " + data.getBeneficiario().getApellido().toLowerCase()).contains(text.toLowerCase())
|| (data.getBeneficiario() != null ? data.getBeneficiario().getNombre() : "No registra" + " " + data.getBeneficiario() != null ? data.getBeneficiario().getApellido() : "No registra").contains(query)
//|| data.getPoblacion().getNombre().toLowerCase().contains(text.toLowerCase())
//|| data.getMunicipio().getMunicipio().toLowerCase().contains(text.toLowerCase())
) {
itemsMostrados.add(data);
}
}
layoutResultados.setVisibility(View.VISIBLE);
txtResults.setText(itemsMostrados.size() + "");
}
notifyDataSetChanged();
}
public void actualizar() {
itemsMostrados = listaActas;
notifyDataSetChanged();
}
ActasActivity.java
In this activity I try to create the condition to filter search to the last page but still continue to filter only the first 10 of the current page
public void obtenerActas(boolean inicializar) {
if (inicializar) {
current_page = 1;
last_page = 1;
last_size_pages = 0;
}
final Promise<RespuestaActasDTO, BusinessException, RespuestaActasDTO> mPromise = actasService.obtenerActas(current_page);
mPromise.done(result -> {
if (progressDialog.isShowing()) {
progressDialog.dismiss();
}
actualizarListadoActas(result, inicializar);
if (progressBar.getVisibility() == View.VISIBLE) {
progressBar.setVisibility(View.GONE);
}
});
mPromise.fail(error -> {
if (progressDialog.isShowing()) {
progressDialog.dismiss();
}
if (progressBar.getVisibility() == View.VISIBLE) {
progressBar.setVisibility(View.GONE);
}
Toast.makeText(mContexto, "Ocurrió un error consultando las actas", Toast.LENGTH_SHORT).show();
});
}
public void actualizarListadoActas(RespuestaActasDTO respuestaActasDTO, boolean inicializar) {
// logica para controlar la pagina a consumir y saber cual es la ultima pagina
last_page = respuestaActasDTO.getLastPage();
//SI PAGINA ACTUAL ES MENOR QUE ULTIMA PAGINA
if (current_page < last_page) {
current_page++;//ENUMEREME DESDE LA PAGINA ACTUAL
}
if (actasAdapter == null || inicializar) {
listaActas = new ArrayList<>();
listaActas = respuestaActasDTO.getData();
actasAdapter = new RecyclerActasAdapter(mContexto, listaActas, layoutResultados, txtResults);
recyclerViewActas.setAdapter(actasAdapter);
scrollListener.resetState();
} else {
//página actual < última página
if (current_page < last_page) {
listaActas.addAll(respuestaActasDTO.getData());
actasAdapter.actualizar();
agregarUltimaConsulta = true;
} else if (current_page == last_page) {
if (agregarUltimaConsulta) {
agregarUltimaConsulta = false;
last_size_pages = respuestaActasDTO.getData().size();
ultimaLista = respuestaActasDTO.getData();
listaActas.addAll(ultimaLista);
actasAdapter.actualizar();
} else if (last_size_pages != respuestaActasDTO.getData().size()) {
// limpiar ultimos registros para volverlos a agregar
ultimaLista = respuestaActasDTO.getData();
last_size_pages = respuestaActasDTO.getData().size();
listaActas.addAll(ultimaLista);
actasAdapter.actualizar();
}
}
}
// Logical END to control the page to consume and know which is the last page ------>>>>
if (agregarEventoBuscar) {
agregarEventoBuscar = false;
// buscador
inputBuscar.setOnQueryTextListener( new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
actasAdapter.filtrar(inputBuscar.getQuery().toString() );
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
return false;
}
} );
}
Observation: I only filter the query if I scroll to the last page, Thanks for your support