0

I am integrating a new piece of code and I need to update firebase-ui-database from 0.4.0 to 3.1.3

I am aware of Why I cant use the populateViewHolder override method?

but here I am using RecyclerView.Adapter and I do not have the documentation of 0.4.0 so I need an help to translate the below in 3.1.3 format.

 private RecyclerView.Adapter<CommentViewHolder> mAdapter;
        final DatabaseReference commentsRef = FirebaseUtil.getCommentsRef().child(mPostRef);
        mAdapter = new FirebaseRecyclerAdapter<Comment, CommentViewHolder>(
                Comment.class, R.layout.comment_item, CommentViewHolder.class, commentsRef) {
            @Override
            protected void populateViewHolder(final CommentViewHolder viewHolder,
                                              Comment comment, int position) {
                Author author = comment.getAuthor();
                //viewHolder.commentAuthor.setText(author.getFull_name());
                //GlideUtil.loadProfileIcon(author.getProfile_picture(), viewHolder.commentPhoto);

                viewHolder.authorRef = author.getUid();
                viewHolder.commentTime
                        .setText(DateUtils.getRelativeTimeSpanString((long) comment.getTimestamp
                                ()));
                viewHolder.commentText.setText(comment.getText());
            }
        };

Any thoughts?

EDITED: Below what I have done so far:

public class CommentsFragment extends Fragment {
    public static final String TAG = "CommentsFragment";
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String POST_REF_PARAM = "post_ref_param";
    private static final int DEFAULT_MSG_LENGTH_LIMIT = 256;
    private EditText mEditText;

    public static class CommentViewHolder extends RecyclerView.ViewHolder {
        public final ImageView commentPhoto;
        public final TextView commentText;
        public final TextView commentAuthor;
        public final TextView commentTime;
        public String authorRef;

        public CommentViewHolder(View itemView) {
            super(itemView);
            commentPhoto = (ImageView) itemView.findViewById(R.id.comment_author_icon);
            commentText = (TextView) itemView.findViewById(R.id.comment_text);
            commentAuthor = (TextView) itemView.findViewById(R.id.comment_name);
            commentTime = (TextView) itemView.findViewById(R.id.comment_time);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (authorRef != null) {
                        Context context = v.getContext();
                        Intent userDetailIntent = new Intent(context, UserDetailActivity.class);
                        userDetailIntent.putExtra(UserDetailActivity.USER_ID_EXTRA_NAME,
                                authorRef);
                        context.startActivity(userDetailIntent);
                    }
                }
            });
        }
    }

    private FirebaseRecyclerAdapter<Comment, CommentViewHolder> mAdapter;
<CODE>
        final DatabaseReference commentsRef = FirebaseUtil.getCommentsRef().child(mPostRef);


        SnapshotParser<Comment> parser = new SnapshotParser<Comment>() {
            @Override
            public Comment parseSnapshot(DataSnapshot dataSnapshot) {
                Comment comment = dataSnapshot.getValue(Comment.class);
                if (comment != null) {
                    comment.setId(dataSnapshot.getKey());
                }
                return comment;
            }
        };

        FirebaseRecyclerOptions<Comment> options =
                new FirebaseRecyclerOptions.Builder<Comment>()
                        .setQuery(commentsRef, parser)
                        .build();

        mAdapter = new FirebaseRecyclerAdapter<Comment, CommentViewHolder>(options){
            @Override
            protected void populateViewHolder(final CommentViewHolder viewHolder, Comment comment, int position) {
                Author author = comment.getAuthor();
                //viewHolder.commentAuthor.setText(author.getFull_name());
                //GlideUtil.loadProfileIcon(author.getProfile_picture(), viewHolder.commentPhoto);

                viewHolder.authorRef = author.getUid();
                viewHolder.commentTime
                        .setText(DateUtils.getRelativeTimeSpanString((long) comment.getTimestamp
                                ()));
                viewHolder.commentText.setText(comment.getText());
            }
czane
  • 392
  • 1
  • 6
  • 18
  • `new FirebaseRecyclerAdapter< Comment, CommentViewHolder >(new FirebaseRecyclerOptions.Builder() .setQuery(commentsRef, CommentViewHolder.class) .build())` – Frank van Puffelen Jan 21 '18 at 18:25
  • Not so simple Frank, edited the question with what done so far. – czane Jan 21 '18 at 19:15
  • ust a guess but use .setQuery(commentsRef,Comment.class) comment instead of parser. (use the model class name), did this work with you @czane – Peter Haddad Jan 23 '18 at 08:23

0 Answers0