0

i made my app with like button, now i would add the like counter...but i'm confused. you can help me? how can i add the like counter? i have 2 functions:

first

viewHolder.mLikeBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    mProcessLike = true;

                    if(mProcessLike){

                        mDatabaseLike.addValueEventListener(new ValueEventListener() {
                            @Override
                            public void onDataChange(DataSnapshot dataSnapshot) {

                                if (mProcessLike) {

                                    if (dataSnapshot.child(post_key).hasChild(mAuth.getCurrentUser().getUid())) {

                                        mDatabaseLike.child(post_key).child(mAuth.getCurrentUser().getUid()).removeValue();
                                        mProcessLike=false;


                                    } else {

                                        mDatabaseLike.child(post_key).child(mAuth.getCurrentUser().getUid()).setValue("RandomValue");

                                        mProcessLike=false;
                                    }

                                }

                            }

                            @Override
                            public void onCancelled(DatabaseError databaseError) {

                            }
                        });

                    }

                }
            }

second (it's for change the colour of the button)

public void setLikeBtn(final String post_key){

        mDatabaseLike.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {

                if(dataSnapshot.child(post_key).hasChild(mAuth.getCurrentUser().getUid())){

                    mLikeBtn.setImageResource(R.mipmap.likepieno);

                }else{
                    mLikeBtn.setImageResource(R.mipmap.likevuoto);
                }

            }

            @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });

    }

0 Answers0