Guys, the question is as follows. Is it possible to somehow dynamically change the markup properties? I will explain: There is a correspondence between 2 users, and there is 1 markup for the messages themselves. Here is the method for initializing and configuring the adapter:

mFBAdapter = new FirebaseRecyclerAdapter<ChatMessage, FirechatMsgViewHolder>( ChatMessage.class, // chat_message собственно сама разметка текстового сообщения R.layout.chat_message, FirechatMsgViewHolder.class, mDatabaseReference.child(romName) ) { @Override protected void populateViewHolder(FirechatMsgViewHolder firechatMsgViewHolder, ChatMessage chatMessage, int i) { mProgressBar.setVisibility(ProgressBar.INVISIBLE); firechatMsgViewHolder.msgText.setText(chatMessage.getText()) firechatMsgViewHolder.userText.setText(chatMessage.getName()); if (mFirebaseUser.getPhotoUrl() == null) { firechatMsgViewHolder.userImage.setImageDrawable( ContextCompat.getDrawable(context, R.drawable.ic_account_circle_black_36dp)); } else { mUsername = mFirebaseUser.getDisplayName(); mPhotoUrl = mFirebaseUser.getPhotoUrl().toString(); Glide.with(ChatFragment.this). load(chatMessage.getPhotoUrl()).into(firechatMsgViewHolder.userImage); } } }; mFBAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() { @Override public void onItemRangeInserted(int positionStart, int itemCount) { super.onItemRangeInserted(positionStart, itemCount); int chatMsgCount = mFBAdapter.getItemCount(); int lastVisiblePosition = mLayoutManager.findLastCompletelyVisibleItemPosition(); if (lastVisiblePosition == -1 || (positionStart >= (chatMsgCount - 1) && lastVisiblePosition == (positionStart - 1))) { mMsgRecyclerView.scrollToPosition(positionStart); } } }); mMsgRecyclerView.setLayoutManager(mLayoutManager); mMsgRecyclerView.setAdapter(mFBAdapter); mUsername = mFirebaseUser.getDisplayName().toString(); 

I have the names of both participants, and I wanted somehow with their help to make it so that the messages sent by the user were displayed on his right and the received ones on the left. There are Gravity.LEFT and Gravity.RIGHT constants that can be used to control the position from the code, but how to tighten it. there was a type option

  if(mFirebaseAuth.getCurrentUser().getDisplayName().equals(mUsername)){ // gravity right... } else { // gravity lef..... } 

but it didn't work. Any thoughts, can anyone come across?

    1 answer 1

    You can do this:

      adapter = new FirebaseRecyclerAdapter<MessageModel, ChatMessageHolder>(MessageModel.class, R.layout.item_message_once, ChatMessageHolder.class, query) { @Override protected void populateViewHolder(ChatMessageHolder viewHolder, MessageModel model, int position) { //which will align? RelativeLayout.LayoutParams tvTime_params = (RelativeLayout.LayoutParams) viewHolder.tvTime.getLayoutParams(); RelativeLayout.LayoutParams llContent_params = (RelativeLayout.LayoutParams) viewHolder.llContent.getLayoutParams(); //align all in the right if (myUid != null && myUid.equals(model.author_uid)) { tvTime_params.addRule(RelativeLayout.ALIGN_RIGHT, R.id.llContent); llContent_params.setMargins(px140, 0, 0, 0); viewHolder.llContent.setBackground(getResources().getDrawable(R.drawable.border)); } else { //align all in the left tvTime_params.addRule(RelativeLayout.ALIGN_LEFT, R.id.llContent); llContent_params.setMargins(0, 0, px140, 0); viewHolder.llContent.setBackground(getResources().getDrawable(R.drawable.border_white_gray)); } //set params for align viewHolder.tvTime.setLayoutParams(tvTime_params); viewHolder.llContent.setLayoutParams(llContent_params); //set values for fields String timestamp = sdf.format(new Date(model.message_time)); viewHolder.tvTime.setText(timestamp); viewHolder.tvBody.setText(model.message_body); } }; recyclerView.setAdapter(adapter ); 

    This code checks the author's uId, and if it is yours, then the item will be placed on the right, and if another user, then on the left + we add the background and other parameters, if necessary.