I want to display a view holder for all users except the current user. The best solution I found was to simply query all the "Users" then hide the current user view holder. In order to so I check if the model user is the current user. However, my if statement is not working as it should. I print out both UID's and clearly they are equal. However, my if statement which should only run when they aren't equal still executes when the activity is initially opened. If I jump to another activity and then go back to this activity then it works as it should and it hides the view. Anyone know why my if statement isn't working when the activity is first created?
final FirebaseRecyclerAdapter<Users, UsersViewHolder> adapter = new FirebaseRecyclerAdapter<Users, UsersViewHolder>(options) {
@Override
protected void onBindViewHolder(@NonNull UsersViewHolder holder, final int position, @NonNull final Users model) {
holder.setInfo(getApplicationContext(), model.getUsername(), model.getName(), model.getProfilePhoto());
final String currentUserID = FirebaseAuth.getInstance().getCurrentUser().getUid();
final String otherUserID = getRef(position).getKey();
System.out.println(currentUserID + " === " + otherUserID + "\n");
if (currentUserID != otherUserID) {
holder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DatabaseReference currentUserDB = FirebaseDatabase.getInstance().getReference().child("Users").child(userID);
Map newPost = new HashMap();
newPost.put("otherUserID", otherUserID);
currentUserDB.updateChildren(newPost);
startActivity(new Intent(SearchActivity.this, OthersProfileActivity.class));
}
});
}
else {
holder.mView.setVisibility(View.GONE);
}
}
@NonNull
@Override
public UsersViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.users_layout, parent, false);
return new UsersViewHolder(v);
}
};
adapter.startListening();
rvSearchUsers.setAdapter(adapter);