Chat_bubble display working, TODO: selection + context menu
This commit is contained in:
parent
0341e5da61
commit
46bcb41d0e
4 changed files with 84 additions and 68 deletions
|
@ -75,71 +75,76 @@ public class ChatBubbleViewHolder extends RecyclerView.ViewHolder implements Vie
|
|||
super(view);
|
||||
this.mContext = context;
|
||||
|
||||
this.listener = listener;
|
||||
eventLayout = view.findViewById(R.id.event);
|
||||
this.eventLayout = view.findViewById(R.id.event);
|
||||
//eventTime = view.findViewById(R.id.event_date);
|
||||
eventMessage = view.findViewById(R.id.event_text);
|
||||
this.eventMessage = view.findViewById(R.id.event_text);
|
||||
|
||||
bubbleLayout = view.findViewById(R.id.bubble);
|
||||
background = view.findViewById(R.id.background);
|
||||
contactPicture = view.findViewById(R.id.contact_picture);
|
||||
contactPictureMask = view.findViewById(R.id.mask);
|
||||
contactName = view.findViewById(R.id.contact_header);
|
||||
this.bubbleLayout = view.findViewById(R.id.bubble);
|
||||
this.background = view.findViewById(R.id.background);
|
||||
this.contactPicture = view.findViewById(R.id.contact_picture);
|
||||
this.contactPictureMask = view.findViewById(R.id.mask);
|
||||
this.contactName = view.findViewById(R.id.contact_header);
|
||||
|
||||
messageStatus = view.findViewById(R.id.status);
|
||||
messageSendingInProgress = view.findViewById(R.id.inprogress);
|
||||
imdmLayout = view.findViewById(R.id.imdmLayout);
|
||||
imdmIcon = view.findViewById(R.id.imdmIcon);
|
||||
imdmLabel = view.findViewById(R.id.imdmText);
|
||||
this.messageStatus = view.findViewById(R.id.status);
|
||||
this.messageSendingInProgress = view.findViewById(R.id.inprogress);
|
||||
this.imdmLayout = view.findViewById(R.id.imdmLayout);
|
||||
this.imdmIcon = view.findViewById(R.id.imdmIcon);
|
||||
this.imdmLabel = view.findViewById(R.id.imdmText);
|
||||
|
||||
messageText = view.findViewById(R.id.message);
|
||||
messageImage = view.findViewById(R.id.image);
|
||||
this.messageText = view.findViewById(R.id.message);
|
||||
this.messageImage = view.findViewById(R.id.image);
|
||||
|
||||
fileTransferLayout = view.findViewById(R.id.file_transfer_layout);
|
||||
fileTransferProgressBar = view.findViewById(R.id.progress_bar);
|
||||
fileTransferAction = view.findViewById(R.id.file_transfer_action);
|
||||
this.fileTransferLayout = view.findViewById(R.id.file_transfer_layout);
|
||||
this.fileTransferProgressBar = view.findViewById(R.id.progress_bar);
|
||||
this.fileTransferAction = view.findViewById(R.id.file_transfer_action);
|
||||
|
||||
fileName = view.findViewById(R.id.file_name);
|
||||
openFileButton = view.findViewById(R.id.open_file);
|
||||
this.fileName = view.findViewById(R.id.file_name);
|
||||
this.openFileButton = view.findViewById(R.id.open_file);
|
||||
|
||||
this.delete = view.findViewById(R.id.delete_message);
|
||||
|
||||
this.listener = listener;
|
||||
|
||||
delete = view.findViewById(R.id.delete_message);
|
||||
view.setOnClickListener(this);
|
||||
}
|
||||
public ChatBubbleViewHolder(View view) {
|
||||
super(view);
|
||||
this.listener = listener;
|
||||
eventLayout = view.findViewById(R.id.event);
|
||||
this.eventLayout = view.findViewById(R.id.event);
|
||||
//eventTime = view.findViewById(R.id.event_date);
|
||||
eventMessage = view.findViewById(R.id.event_text);
|
||||
this.eventMessage = view.findViewById(R.id.event_text);
|
||||
|
||||
bubbleLayout = view.findViewById(R.id.bubble);
|
||||
background = view.findViewById(R.id.background);
|
||||
contactPicture = view.findViewById(R.id.contact_picture);
|
||||
contactPictureMask = view.findViewById(R.id.mask);
|
||||
contactName = view.findViewById(R.id.contact_header);
|
||||
this.bubbleLayout = view.findViewById(R.id.bubble);
|
||||
this.background = view.findViewById(R.id.background);
|
||||
this.contactPicture = view.findViewById(R.id.contact_picture);
|
||||
this.contactPictureMask = view.findViewById(R.id.mask);
|
||||
this.contactName = view.findViewById(R.id.contact_header);
|
||||
|
||||
messageStatus = view.findViewById(R.id.status);
|
||||
messageSendingInProgress = view.findViewById(R.id.inprogress);
|
||||
imdmLayout = view.findViewById(R.id.imdmLayout);
|
||||
imdmIcon = view.findViewById(R.id.imdmIcon);
|
||||
imdmLabel = view.findViewById(R.id.imdmText);
|
||||
this.messageStatus = view.findViewById(R.id.status);
|
||||
this.messageSendingInProgress = view.findViewById(R.id.inprogress);
|
||||
this.imdmLayout = view.findViewById(R.id.imdmLayout);
|
||||
this.imdmIcon = view.findViewById(R.id.imdmIcon);
|
||||
this.imdmLabel = view.findViewById(R.id.imdmText);
|
||||
|
||||
messageText = view.findViewById(R.id.message);
|
||||
messageImage = view.findViewById(R.id.image);
|
||||
this.messageText = view.findViewById(R.id.message);
|
||||
this.messageImage = view.findViewById(R.id.image);
|
||||
|
||||
fileTransferLayout = view.findViewById(R.id.file_transfer_layout);
|
||||
fileTransferProgressBar = view.findViewById(R.id.progress_bar);
|
||||
fileTransferAction = view.findViewById(R.id.file_transfer_action);
|
||||
this.fileTransferLayout = view.findViewById(R.id.file_transfer_layout);
|
||||
this.fileTransferProgressBar = view.findViewById(R.id.progress_bar);
|
||||
this.fileTransferAction = view.findViewById(R.id.file_transfer_action);
|
||||
|
||||
fileName = view.findViewById(R.id.file_name);
|
||||
openFileButton = view.findViewById(R.id.open_file);
|
||||
this.fileName = view.findViewById(R.id.file_name);
|
||||
this.openFileButton = view.findViewById(R.id.open_file);
|
||||
|
||||
delete = view.findViewById(R.id.delete_message);
|
||||
this.delete = view.findViewById(R.id.delete_message);
|
||||
}
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
listener.onItemClicked(getAdapterPosition());
|
||||
if(listener!=null) {
|
||||
listener.onItemClicked(getAdapterPosition());
|
||||
}
|
||||
}
|
||||
|
||||
public interface ClickListener {
|
||||
public void onItemClicked(int position);
|
||||
}
|
||||
|
|
|
@ -91,17 +91,17 @@ public class ChatEventsAdapter extends SelectableAdapter<ChatBubbleViewHolder> {
|
|||
private ChatBubbleViewHolder.ClickListener clickListener;
|
||||
|
||||
// public ChatEventsAdapter(GroupChatFragment fragment, ListSelectionHelper helper, LayoutInflater inflater, EventLog[] history, ArrayList<LinphoneContact> participants) {
|
||||
public ChatEventsAdapter(GroupChatFragment fragment, SelectableHelper helper, int itemResource, ArrayList<EventLog> mHistory, ArrayList<LinphoneContact> participants, ChatBubbleViewHolder.ClickListener clickListener) {
|
||||
public ChatEventsAdapter(GroupChatFragment fragment, SelectableHelper helper, int itemResource, EventLog[] history, ArrayList<LinphoneContact> participants, ChatBubbleViewHolder.ClickListener clickListener) {
|
||||
// public ChatEventsAdapter(GroupChatFragment fragment, SelectableHelper helper, LayoutInflater inflater, ArrayList<EventLog> mHistory, ArrayList<LinphoneContact> participants, ChatBubbleViewHolder.ClickListener clickListener) {
|
||||
|
||||
super(helper);
|
||||
this.mContext = fragment.getActivity();
|
||||
this.itemResource = itemResource;
|
||||
// this.mLayoutInflater = inflater;
|
||||
this.mHistory = mHistory;
|
||||
|
||||
// this.mHistory = mHistory;
|
||||
mHistory = new ArrayList<>(Arrays.asList(history));
|
||||
this.mParticipants = participants;
|
||||
|
||||
this.clickListener = clickListener;
|
||||
mListener = new ChatMessageListenerStub() {
|
||||
@Override
|
||||
public void onFileTransferProgressIndication(ChatMessage message, Content content, int offset, int total) {
|
||||
|
@ -134,7 +134,7 @@ public class ChatEventsAdapter extends SelectableAdapter<ChatBubbleViewHolder> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ChatBubbleViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
public ChatBubbleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
// View v = mLayoutInflater.inflate(R.layout.chat_bubble, parent, false);
|
||||
View v = LayoutInflater.from(parent.getContext())
|
||||
.inflate(this.itemResource, parent, false);
|
||||
|
@ -142,8 +142,8 @@ public class ChatEventsAdapter extends SelectableAdapter<ChatBubbleViewHolder> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ChatBubbleViewHolder holder, int position) {
|
||||
EventLog event = this.mHistory.get(position);
|
||||
public void onBindViewHolder(ChatBubbleViewHolder holder, int position) {
|
||||
final EventLog event = this.mHistory.get(position);
|
||||
holder.eventLayout.setVisibility(View.GONE);
|
||||
holder.bubbleLayout.setVisibility(View.GONE);
|
||||
holder.delete.setVisibility(isEditionEnabled() ? View.VISIBLE : View.GONE);
|
||||
|
@ -342,6 +342,7 @@ public class ChatEventsAdapter extends SelectableAdapter<ChatBubbleViewHolder> {
|
|||
|
||||
holder.bubbleLayout.setLayoutParams(layoutParams);
|
||||
} else { // Event is not chat message
|
||||
|
||||
holder.eventLayout.setVisibility(View.VISIBLE);
|
||||
|
||||
Address address = event.getParticipantAddress();
|
||||
|
@ -401,12 +402,9 @@ public class ChatEventsAdapter extends SelectableAdapter<ChatBubbleViewHolder> {
|
|||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return 0;
|
||||
return this.mHistory.size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void addToHistory(EventLog log) {
|
||||
mHistory.add(log);
|
||||
notifyDataSetChanged();
|
||||
|
@ -417,7 +415,7 @@ public class ChatEventsAdapter extends SelectableAdapter<ChatBubbleViewHolder> {
|
|||
}
|
||||
|
||||
public void refresh(EventLog[] history) {
|
||||
// mHistory = new ArrayList<>(Arrays.asList(history));
|
||||
mHistory = new ArrayList<>(Arrays.asList(history));
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
@ -433,7 +431,7 @@ public class ChatEventsAdapter extends SelectableAdapter<ChatBubbleViewHolder> {
|
|||
|
||||
// @Override
|
||||
public int getCount() {
|
||||
return mHistory.size();
|
||||
return this.mHistory.size();
|
||||
}
|
||||
|
||||
// @Override
|
||||
|
@ -643,6 +641,7 @@ public class ChatEventsAdapter extends SelectableAdapter<ChatBubbleViewHolder> {
|
|||
}
|
||||
|
||||
private BitmapWorkerTask getBitmapWorkerTask(ImageView imageView) {
|
||||
// private BitmapWorkerTask getBitmapWorkerTask(ImageView imageView) {
|
||||
if (imageView != null) {
|
||||
final Drawable drawable = imageView.getDrawable();
|
||||
if (drawable instanceof AsyncBitmap) {
|
||||
|
|
|
@ -119,15 +119,11 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con
|
|||
mRemoteSipUri = getArguments().getString("SipUri");
|
||||
mRemoteSipAddress = LinphoneManager.getLc().createAddress(mRemoteSipUri);
|
||||
}
|
||||
|
||||
this.mContext = getActivity().getApplicationContext();
|
||||
View view = inflater.inflate(R.layout.chat, container, false);
|
||||
mChatEventsList = view.findViewById(R.id.chat_message_list);
|
||||
mSelectionHelper = new SelectableHelper(view, this);
|
||||
|
||||
|
||||
layoutManager = new LinearLayoutManager(mContext);
|
||||
mChatEventsList.setLayoutManager(layoutManager);
|
||||
|
||||
mBackButton = view.findViewById(R.id.back);
|
||||
mBackButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
@ -219,9 +215,17 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con
|
|||
|
||||
mRemoteComposing = view.findViewById(R.id.remote_composing);
|
||||
|
||||
|
||||
|
||||
|
||||
mChatEventsList = view.findViewById(R.id.chat_message_list);
|
||||
mSelectionHelper = new SelectableHelper(view, this);
|
||||
layoutManager = new LinearLayoutManager(mContext);
|
||||
mChatEventsList.setLayoutManager(layoutManager);
|
||||
registerForContextMenu(mChatEventsList);
|
||||
|
||||
|
||||
|
||||
if (getArguments() != null) {
|
||||
String fileSharedUri = getArguments().getString("fileSharedUri");
|
||||
if (fileSharedUri != null) {
|
||||
|
@ -240,7 +244,6 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con
|
|||
if (getArguments().getString("messageDraft") != null)
|
||||
mMessageTextToSend.setText(getArguments().getString("messageDraft"));
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
|
@ -264,7 +267,6 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con
|
|||
initChatRoom();
|
||||
displayChatRoomHeader();
|
||||
displayChatRoomHistory();
|
||||
|
||||
LinphoneManager.getInstance().setCurrentChatRoomAddress(mRemoteSipAddress);
|
||||
}
|
||||
|
||||
|
@ -555,7 +557,19 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con
|
|||
}
|
||||
|
||||
private void displayChatRoomHistory() {
|
||||
|
||||
if (mChatRoom == null) return;
|
||||
if (mChatRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt())) {
|
||||
mEventsAdapter = new ChatEventsAdapter(this, mSelectionHelper, R.layout.chat_bubble, mChatRoom.getHistoryMessageEvents(0), mParticipants, this);
|
||||
} else {
|
||||
mEventsAdapter = new ChatEventsAdapter(this, mSelectionHelper, R.layout.chat_bubble, mChatRoom.getHistoryEvents(0), mParticipants, this);
|
||||
}
|
||||
mSelectionHelper.setAdapter(mEventsAdapter);
|
||||
mChatEventsList.setAdapter(mEventsAdapter);
|
||||
|
||||
|
||||
scrollToBottom();
|
||||
/*if (mChatRoom == null) return;
|
||||
if (mChatRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt())) {
|
||||
EventLog[] history = mChatRoom.getHistoryMessageEvents(0);
|
||||
mHistory = new ArrayList<>(Arrays.asList(history));
|
||||
|
@ -567,17 +581,15 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con
|
|||
mEventsAdapter = new ChatEventsAdapter(this, mSelectionHelper, R.layout.chat_bubble, mHistory, mParticipants, this);
|
||||
}
|
||||
mChatEventsList.setAdapter(mEventsAdapter);
|
||||
mSelectionHelper.setAdapter(mEventsAdapter);
|
||||
|
||||
|
||||
mSelectionHelper.setAdapter(mEventsAdapter);*/
|
||||
}
|
||||
|
||||
public void scrollToBottom() {
|
||||
if (((layoutManager.findLastVisibleItemPosition() >= (mEventsAdapter.getCount() - 1)) && (layoutManager.findFirstVisibleItemPosition() <= (mEventsAdapter.getCount() - 1)))) {
|
||||
// if ((layoutManager.findLastVisibleItemPosition() >= (mEventsAdapter.getCount() - 1)) && (layoutManager.findFirstVisibleItemPosition() <= (mEventsAdapter.getCount() - 1))) {
|
||||
// if (((mChatEventsList.getLastVisiblePosition() >= (mEventsAdapter.getCount() - 1)) && (mChatEventsList.getFirstVisiblePosition() <= (mEventsAdapter.getCount() - 1)))) {
|
||||
mChatEventsList.getLayoutManager().scrollToPosition(mEventsAdapter.getCount() - 1);
|
||||
// mChatEventsList.setSelection(mEventsAdapter.getCount() - 1);
|
||||
}
|
||||
// }
|
||||
}
|
||||
|
||||
public String getRemoteSipUri() {
|
||||
|
|
|
@ -22,7 +22,7 @@ public abstract class SelectableAdapter<VH extends RecyclerView.ViewHolder> exte
|
|||
private CompoundButton.OnCheckedChangeListener mDeleteCheckboxListener = new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
Integer position = (Integer)compoundButton.getTag();
|
||||
// Integer position = (Integer)compoundButton.getTag();
|
||||
|
||||
mListHelper.updateSelectionButtons(mSelectedItems.size() == 0, mSelectedItems.size() == getItemCount());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue