Exchange of information between Recycleviews

Asked

Viewed 109 times

0

I have request tabs where "RECEIVED" retrieves data from Firebase BD inside a Recycleview. Request made by a user and received by the company. Now how do the items below:

1 - The company representative click on an item of the received request appear a Alertdialog whether or not to meet the request.

2 - If you answer, delete the "RECEIVED" item and appear in "ANSWERED". If not, appear in "PENDING".

If possible wanted to notify the user also about these actions.

From now on thank those who can help. Follow my current code.

inserir a descrição da imagem aqui

    public class SolicRecebidaFragment extends Fragment {

private RecyclerView recyclerViewListaSolicitacao;
private DatabaseReference refSolicitacao, database ;
private AdapterSolicitacoes adapter;
private ArrayList<DadosSolicitacao> listaSolicitacoes = new ArrayList<>();
private ValueEventListener valueEventoSolicitacao;
private String idUsuario;


public SolicRecebidaFragment() {
    // Required empty public constructor
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view =  inflater.inflate(R.layout.fragment_solicitacao_recebida, container, false);

    //Config.Inciais
    recyclerViewListaSolicitacao = view.findViewById(R.id.recyclerView_ListaSolicitacao);

    //Config.Referenciar nó de recuperação dos dados
   // idUsuario = IdUsuarioFirabase.getIdentificadorUsuario();
    database = ConfiguracaoFirebase.getFirebaseDataBase();
    refSolicitacao = database
            .child("solicitacao_coleta");

    //Config.Adapter
    adapter = new AdapterSolicitacoes(listaSolicitacoes, getActivity());

    //Config.RecyclerView
    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
    recyclerViewListaSolicitacao.setLayoutManager( layoutManager);
    recyclerViewListaSolicitacao.setHasFixedSize(true);
    recyclerViewListaSolicitacao.addItemDecoration( new DividerItemDecoration(getActivity(), LinearLayout.VERTICAL));
    recyclerViewListaSolicitacao.setAdapter( adapter );

    //Evento de click
    recyclerViewListaSolicitacao.addOnItemTouchListener(
            new RecyclerItemClickListener(getActivity(), recyclerViewListaSolicitacao,
                    new RecyclerItemClickListener.OnItemClickListener() {
                        @Override
                        public void onItemClick(View view, int position) {

                            Toast.makeText(getActivity(), "Item clicado",
                                    Toast.LENGTH_SHORT).show();
                        }

                        @Override
                        public void onLongItemClick(View view, int position) {

                            Toast.makeText(getActivity(), "Item pressionado",
                                    Toast.LENGTH_SHORT).show();

                        }

                        @Override
                        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                        }
                    })
    );

return view;
}

@Override //Exibi lista ao carregar o fragment
public void onStart() {
    super.onStart();
    recuperarSolicitacao();
}

@Override // Remove lista ao sair do fragment
public void onStop() {
    super.onStop();
    refSolicitacao.removeEventListener(valueEventoSolicitacao);
}

public void recuperarSolicitacao (){

   valueEventoSolicitacao =  refSolicitacao.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {

            listaSolicitacoes.clear();

            for ( DataSnapshot dados: dataSnapshot.getChildren() ){

               // Log.i("DADOS COLETA FIREBASE", dataSnapshot.getValue().toString());

                DadosSolicitacao solicitacao = dados.getValue(DadosSolicitacao.class);
                listaSolicitacoes.add( solicitacao );

            }

            adapter.notifyDataSetChanged();

        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });


}

}

1 answer

0

For that you will need two things.

First: Modify your application code. Every time a request is answered, you must remove it from the received set and place it in the answered set. That is, let Firebase do the updates for you.

Second: Notifications you can create a Firebase Cloud Function and every time an item is added to the suite answered, you send a notification to the user in question.

Avoid making communication between tabs. They usually slow down. And anyway, you already need to update the database.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.