Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////SETTING UP THE ADAPTER
- private void setupAdapter() {
- //stops lag for recycler view for load
- commentsRecyclerView.setHasFixedSize(true);
- commentsAdapter = new CommentsAdapter(commentsList, TypeFaceProvider.getTypeFace(this, 0),
- TypeFaceProvider.getTypeFace(this, 1), TypeFaceProvider.getTypeFace(this, 2));
- LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
- mLayoutManager.setReverseLayout(true);
- mLayoutManager.setStackFromEnd(true);
- commentsRecyclerView.setLayoutManager(mLayoutManager);
- commentsRecyclerView.setItemAnimator(new DefaultItemAnimator());
- commentsAdapter.setOnEntryClickListener(new CommentsAdapter.OnEntryClickListener() {
- @Override
- public void onEntryClick(View view, int position) {
- //DatabaseComment comment = commentsList.get(position);
- // TextView deleteBtn = (TextView) view.findViewById(R.id.commentUserRemove);
- // if (view == deleteBtn) {
- //
- // //used to remove the comment from db and the list
- // db.removeSingleComment(comment);
- // dbCommentsList.remove(position);
- // commentsAdapter.notifyDataSetChanged();
- //
- // } else {
- takeToUserProfile(commentsList.get(position));
- // }
- }
- });
- commentsRecyclerView.setAdapter(commentsAdapter);
- commentsRecyclerView.scrollToPosition(0);
- if(commentsList.size() < 1) {
- noCommentsResults.setVisibility(View.VISIBLE);
- }
- hideProgressDialog();
- }
- ////////////THE ADAPTER CLASS
- public class CommentsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
- private static OnEntryClickListener mOnEntryClickListener;
- private List<ConversationComment> dbCommentsList;
- private Typeface typeFace, italicTypeface, boldTypeface;
- public CommentsAdapter(List<ConversationComment> comments, Typeface myTypeface, Typeface myTypefaceItalic, Typeface myTypefaceBold) {
- dbCommentsList = comments;
- typeFace = myTypeface;
- italicTypeface = myTypefaceItalic;
- boldTypeface = myTypefaceBold;
- Log.d(Constants.DEBUG, "THE COMMENT SIZE " + dbCommentsList.size());
- }
- public void setOnEntryClickListener(OnEntryClickListener onEntryClickListener) {
- mOnEntryClickListener = onEntryClickListener;
- }
- @Override
- public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
- switch (viewType) {
- case 0:
- return new MyFeatureViewHolder(LayoutInflater.from(parent.getContext())
- .inflate(R.layout.comment_business_item, parent, false));
- case 1:
- return new MyViewHolder(LayoutInflater.from(parent.getContext())
- .inflate(R.layout.comment_user_item, parent, false));
- }
- return new MyViewHolder(LayoutInflater.from(parent.getContext())
- .inflate(R.layout.comment_user_item, parent, false));
- }
- @Override
- public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
- int pos = getItemViewType(position);
- //is a business comment
- if (pos == 0) {
- MyFeatureViewHolder featureViewHolder = (MyFeatureViewHolder) holder;
- ConversationComment dbComment = dbCommentsList.get(position);
- featureViewHolder.commentCompany.setTypeface(boldTypeface);
- featureViewHolder.commentCompanyMsg.setTypeface(typeFace);
- featureViewHolder.commentCompanyDate.setTypeface(italicTypeface);
- featureViewHolder.commentCompany.setText(dbComment.getUsername());
- featureViewHolder.commentCompanyMsg.setText(dbComment.getMsg());
- Calendar date = Calendar.getInstance();
- date.setTimeInMillis(dbComment.getDateCommented());
- int newMonth = date.get(Calendar.MONTH) + 1;
- String commentDateTxt = (newMonth + "." + date.get(Calendar.DAY_OF_MONTH) + "." + date.get(Calendar.YEAR));
- featureViewHolder.commentCompanyDate.setText(commentDateTxt);
- }
- //anything greater than 0 is a user comment - with emoji
- if (pos == 1) {
- MyViewHolder myViewHolder = (MyViewHolder) holder;
- // if (dbCommentsList.get(position).getIsChanged() == 1) {
- // myViewHolder.commentUserRemove.setVisibility(View.VISIBLE);
- // } else {
- // myViewHolder.commentUserRemove.setVisibility(View.GONE);
- // }
- Log.d(Constants.DEBUG, "THE comment " + dbCommentsList.get(position).getMsg());
- ConversationComment dbComment = dbCommentsList.get(position);
- myViewHolder.commentUsername.setTypeface(boldTypeface);
- myViewHolder.commentUserMsg.setTypeface(typeFace);
- myViewHolder.commentUserDate.setTypeface(italicTypeface);
- myViewHolder.commentUsername.setText(dbComment.getUsername());
- myViewHolder.commentUserMsg.setText(dbComment.getMsg());
- Calendar date = Calendar.getInstance();
- date.setTimeInMillis(dbComment.getDateCommented());
- //Note only one plus one because of new comments added will
- int newMonth = date.get(Calendar.MONTH) + 1;
- String commentDateTxt = (newMonth + "." + date.get(Calendar.DAY_OF_MONTH) + "." + date.get(Calendar.YEAR));
- myViewHolder.commentUserDate.setText(commentDateTxt);
- int[] commentsImageList = new int[]{R.drawable.e1, R.drawable.e1, R.drawable.e2, R.drawable.e3, R.drawable.e4,
- R.drawable.e5, R.drawable.e6, R.drawable.e7, R.drawable.e8, R.drawable.e9, R.drawable.e10,
- R.drawable.e11, R.drawable.e12, R.drawable.e13, R.drawable.e14,
- R.drawable.e15, R.drawable.e16, R.drawable.e17, R.drawable.e18, R.drawable.e19};
- myViewHolder.emojiIcon.setImageResource(commentsImageList[dbComment.getEmoji()]);
- }
- }
- @Override
- public int getItemCount() {
- Log.d(Constants.DEBUG, "THE comment " + dbCommentsList.size());
- return dbCommentsList.size();
- }
- @Override
- public int getItemViewType(int position) {
- if (dbCommentsList.get(position).getEmoji() == 0) {
- return 0;
- } else {
- return 1;
- }
- }
- public interface OnEntryClickListener {
- void onEntryClick(View view, int position);
- }
- public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
- public TextView commentUsername, commentUserMsg, commentUserDate, commentUserRemove;
- public ImageView emojiIcon;
- public MyViewHolder(View view) {
- super(view);
- commentUsername = (TextView) view.findViewById(R.id.commentUsername);
- commentUserMsg = (TextView) view.findViewById(R.id.commentUserMsg);
- commentUserDate = (TextView) view.findViewById(R.id.commentUserDate);
- commentUserRemove = (TextView) view.findViewById(R.id.commentUserRemove);
- emojiIcon = (ImageView) view.findViewById(R.id.emojiIcon);
- view.setOnClickListener(this);
- commentUserRemove.setOnClickListener(this);
- }
- @Override
- public void onClick(View v) {
- if (mOnEntryClickListener != null) {
- mOnEntryClickListener.onEntryClick(v, getAdapterPosition());
- }
- }
- }
- public class MyFeatureViewHolder extends RecyclerView.ViewHolder {
- public TextView commentCompany, commentCompanyMsg, commentCompanyDate;
- public ImageView emojiIcon;
- public MyFeatureViewHolder(View view) {
- super(view);
- commentCompany = (TextView) view.findViewById(R.id.commentCompany);
- commentCompanyMsg = (TextView) view.findViewById(R.id.commentCompanyMsg);
- commentCompanyDate = (TextView) view.findViewById(R.id.commentCompanyDate);
- emojiIcon = (ImageView) view.findViewById(R.id.emojiIcon);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement