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