Information exchange between RecycleViews

0

I have request tabs in which "RECEIVED" retrieves data from the BD Firebase within a RecycleView. This request is made by a user and received by the company. Now how do I do the items below:

1 - The company representative clicks on an item of the received request to appear an AlertDialog whether or not to respond to the request.

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

If possible, you also want to notify the user about these actions.

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

publicclassSolicRecebidaFragmentextendsFragment{privateRecyclerViewrecyclerViewListaSolicitacao;privateDatabaseReferencerefSolicitacao,database;privateAdapterSolicitacoesadapter;privateArrayList<DadosSolicitacao>listaSolicitacoes=newArrayList<>();privateValueEventListenervalueEventoSolicitacao;privateStringidUsuario;publicSolicRecebidaFragment(){//Requiredemptypublicconstructor}@OverridepublicViewonCreateView(LayoutInflaterinflater,ViewGroupcontainer,BundlesavedInstanceState){//InflatethelayoutforthisfragmentViewview=inflater.inflate(R.layout.fragment_solicitacao_recebida,container,false);//Config.InciaisrecyclerViewListaSolicitacao=view.findViewById(R.id.recyclerView_ListaSolicitacao);//Config.Referenciarnóderecuperaçãodosdados//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) {

        }
    });


}

}

    
asked by anonymous 29.04.2018 / 19:44

1 answer

0

For this you will need two things.

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

Second: The notifications you can create a Firebase Cloud Function and every time an item is added to the attended set, you send a notification to the user in question.

Avoid making communication between tabs. They usually go slower. And anyway, you already need to upgrade the database.

    
03.05.2018 / 01:20