Commit for save, converting ListView from GroupChatFragment+Adapter, currently onBindViewHolder Stage.
This commit is contained in:
parent
801a9a6708
commit
4fe67b5a46
7 changed files with 132 additions and 20 deletions
|
@ -19,6 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
|
||||
package org.linphone.chat;
|
||||
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
|
@ -28,11 +29,17 @@ import android.widget.ProgressBar;
|
|||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.linphone.LinphoneManager;
|
||||
import org.linphone.LinphoneUtils;
|
||||
import org.linphone.R;
|
||||
import org.linphone.core.ChatMessage;
|
||||
import org.linphone.core.ChatRoom;
|
||||
import org.linphone.core.EventLog;
|
||||
|
||||
public class ChatBubbleViewHolder {
|
||||
public class ChatBubbleViewHolder extends RecyclerView.ViewHolder{
|
||||
public String messageId;
|
||||
|
||||
public EventLog mEvent;
|
||||
public ChatMessage message;
|
||||
public LinearLayout eventLayout;
|
||||
//public TextView eventTime;
|
||||
public TextView eventMessage;
|
||||
|
@ -62,7 +69,8 @@ public class ChatBubbleViewHolder {
|
|||
public CheckBox delete;
|
||||
|
||||
public ChatBubbleViewHolder(View view) {
|
||||
eventLayout = view.findViewById(R.id.event);
|
||||
super(view);
|
||||
eventLayout = view.findViewById(R.id.event);
|
||||
//eventTime = view.findViewById(R.id.event_date);
|
||||
eventMessage = view.findViewById(R.id.event_text);
|
||||
|
||||
|
@ -90,4 +98,25 @@ public class ChatBubbleViewHolder {
|
|||
|
||||
delete = view.findViewById(R.id.delete_message);
|
||||
}
|
||||
|
||||
public void bindEvent(EventLog event) {
|
||||
|
||||
//Bind the data to the ViewHolder
|
||||
this.mEvent = event;
|
||||
this.message = event.getChatMessage();
|
||||
this.messageId = message.getMessageId();
|
||||
|
||||
this.eventLayout.setVisibility(event.getType() == EventLog.Type.ConferenceChatMessage ? View.GONE : View.VISIBLE);
|
||||
this.bubbleLayout.setVisibility(event.getType() == EventLog.Type.ConferenceChatMessage ? View.VISIBLE : View.GONE);
|
||||
this.messageText.setVisibility(event.getType() == EventLog.Type.ConferenceChatMessage ? View.VISIBLE : View.GONE);
|
||||
this.messageImage.setVisibility(View.GONE);
|
||||
this.fileTransferLayout.setVisibility(View.GONE);
|
||||
|
||||
this.lastMessageSenderView.setText(getSender(mRoom));
|
||||
this.lastMessageView.setText(mRoom.getLastMessageInHistory() != null ? mRoom.getLastMessageInHistory().getTextContent(): "");
|
||||
this.date.setText(mRoom.getLastMessageInHistory()!=null ? LinphoneUtils.timestampToHumanDate(this.mContext, mRoom.getLastUpdateTime(), R.string.messages_list_date_format) : "");
|
||||
this.displayName.setText(getContact(mRoom));
|
||||
this.unreadMessages.setText(String.valueOf(LinphoneManager.getInstance().getUnreadCountForChatRoom(mRoom)));
|
||||
getAvatar(mRoom);
|
||||
}
|
||||
}
|
|
@ -35,7 +35,9 @@ import android.net.Uri;
|
|||
import android.os.AsyncTask;
|
||||
import android.os.Environment;
|
||||
import android.provider.MediaStore;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.content.FileProvider;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.Spanned;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -55,12 +57,14 @@ import org.linphone.contacts.LinphoneContact;
|
|||
import org.linphone.core.Address;
|
||||
import org.linphone.core.ChatMessage;
|
||||
import org.linphone.core.ChatMessageListenerStub;
|
||||
import org.linphone.core.ChatRoom;
|
||||
import org.linphone.core.Content;
|
||||
import org.linphone.core.EventLog;
|
||||
import org.linphone.core.LimeState;
|
||||
import org.linphone.mediastream.Log;
|
||||
import org.linphone.ui.ListSelectionAdapter;
|
||||
import org.linphone.ui.ListSelectionHelper;
|
||||
import org.linphone.ui.SelectableHelper;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
|
@ -72,19 +76,24 @@ import java.util.List;
|
|||
|
||||
import static android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION;
|
||||
|
||||
public class ChatEventsAdapter extends ListSelectionAdapter {
|
||||
public class ChatEventsAdapter extends RecyclerView.Adapter<ChatBubbleViewHolder> {
|
||||
private Context mContext;
|
||||
private List<EventLog> mHistory;
|
||||
private List<LinphoneContact> mParticipants;
|
||||
private LayoutInflater mLayoutInflater;
|
||||
// private int itemResource;
|
||||
private Bitmap mDefaultBitmap;
|
||||
private GroupChatFragment mFragment;
|
||||
private ChatMessageListenerStub mListener;
|
||||
|
||||
// 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) {
|
||||
super(helper);
|
||||
// public ChatRoomsAdapter(Context context, int itemResource, List<ChatRoom > mRooms, ChatRoomViewHolder.ClickListener clickListener, SelectableHelper helper) {
|
||||
|
||||
super();
|
||||
mFragment = fragment;
|
||||
mContext = mFragment.getActivity();
|
||||
// itemResource = inflater.;
|
||||
mLayoutInflater = inflater;
|
||||
mHistory = new ArrayList<>(Arrays.asList(history));
|
||||
mParticipants = participants;
|
||||
|
@ -120,6 +129,77 @@ public class ChatEventsAdapter extends ListSelectionAdapter {
|
|||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatBubbleViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View v = mLayoutInflater.inflate(R.layout.chat_bubble, parent, false);
|
||||
return new ChatBubbleViewHolder(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ChatBubbleViewHolder holder, int position) {
|
||||
EventLog event = (EventLog)getItem(position);
|
||||
final ChatMessage message = event.getChatMessage();
|
||||
|
||||
//Apply generic bindings
|
||||
holder.bindEvent(event);
|
||||
|
||||
// holder.delete.setVisibility(this.isEditionEnabled() == true ? View.VISIBLE : View.INVISIBLE);
|
||||
// holder.delete.setChecked(isSelected(position) ? true : false);
|
||||
|
||||
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
|
||||
|
||||
//If event is Chat Message
|
||||
if(event.getType() == EventLog.Type.ConferenceChatMessage) {
|
||||
|
||||
|
||||
//layoutParams Settings
|
||||
|
||||
|
||||
|
||||
if (isEditionEnabled()) {
|
||||
layoutParams.addRule(RelativeLayout.LEFT_OF, holder.delete.getId());
|
||||
layoutParams.setMargins(100, 10, 10, 10);
|
||||
} else if (message.isOutgoing()) {
|
||||
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
|
||||
layoutParams.setMargins(100, 10, 10, 10);
|
||||
|
||||
} else {
|
||||
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
|
||||
layoutParams.setMargins(10, 10, 100, 10);
|
||||
}
|
||||
|
||||
|
||||
//Display attached files
|
||||
if (message.getAppdata() != null) {
|
||||
displayAttachedFile(message, holder);
|
||||
}
|
||||
|
||||
|
||||
if (message.getExternalBodyUrl() != null ) {
|
||||
holder.fileTransferProgressBar.setVisibility(View.GONE);
|
||||
holder.fileTransferLayout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
if (message.isFileTransferInProgress()){
|
||||
holder.fileTransferLayout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int i) {
|
||||
return i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void addToHistory(EventLog log) {
|
||||
mHistory.add(log);
|
||||
notifyDataSetChanged();
|
||||
|
@ -144,22 +224,22 @@ public class ChatEventsAdapter extends ListSelectionAdapter {
|
|||
mHistory.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
// @Override
|
||||
public int getCount() {
|
||||
return mHistory.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
// @Override
|
||||
public Object getItem(int i) {
|
||||
return mHistory.get(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int i) {
|
||||
return i;
|
||||
}
|
||||
@NonNull
|
||||
|
||||
public void removeItem(int i) {
|
||||
|
||||
|
||||
|
||||
public void removeItem(int i) {
|
||||
mHistory.remove(i);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
|
|
@ -112,15 +112,16 @@ public class ChatListFragment extends Fragment implements ContactsUpdatedListene
|
|||
|
||||
//Actions allowed by swipe buttons
|
||||
|
||||
/*final SwipeController swipeController = new SwipeController(new SwipeControllerActions() {
|
||||
*//*@Override
|
||||
public void onLeftClicked(int position) {
|
||||
super.onLeftClicked(position);
|
||||
}*//*
|
||||
final SwipeController swipeController = new SwipeController(new SwipeControllerActions() {
|
||||
// @Override
|
||||
// public void onLeftClicked(int position) {
|
||||
// super.onLeftClicked(position);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void onRightClicked(int position) {
|
||||
mChatRoomsAdapter.removeItem(position);
|
||||
mChatRoomsAdapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -137,7 +138,6 @@ public class ChatListFragment extends Fragment implements ContactsUpdatedListene
|
|||
swipeController.onDraw(c);
|
||||
}
|
||||
});
|
||||
*/
|
||||
|
||||
|
||||
// Buttons onClickListeners definitions
|
||||
|
|
|
@ -54,6 +54,7 @@ import java.util.List;
|
|||
public class ChatRoomsAdapter extends SelectableAdapter<ChatRoomsAdapter.ChatRoomViewHolder> {
|
||||
|
||||
public static class ChatRoomViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener{
|
||||
|
||||
public TextView lastMessageSenderView;
|
||||
public TextView lastMessageView;
|
||||
public TextView date;
|
||||
|
|
|
@ -96,6 +96,7 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con
|
|||
private ListView mChatEventsList;
|
||||
private LinearLayout mFilesUploadLayout;
|
||||
private ListSelectionHelper mSelectionHelper;
|
||||
// private ListSelectionHelper mSelectionHelper;
|
||||
|
||||
private ViewTreeObserver.OnGlobalLayoutListener mKeyboardListener;
|
||||
private Uri mImageToUploadUri;
|
||||
|
@ -551,6 +552,7 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con
|
|||
if (mChatRoom == null) return;
|
||||
if (mChatRoom.hasCapability(ChatRoomCapabilities.OneToOne.toInt())) {
|
||||
mEventsAdapter = new ChatEventsAdapter(this, mSelectionHelper, mInflater, mChatRoom.getHistoryMessageEvents(0), mParticipants);
|
||||
// mChatRoomsAdapter = new ChatRoomsAdapter(mContext, R.layout.chatlist_cell, mRooms,this, mSelectionHelper);
|
||||
} else {
|
||||
mEventsAdapter = new ChatEventsAdapter(this, mSelectionHelper, mInflater, mChatRoom.getHistoryEvents(0), mParticipants);
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 456993eddd5f4724ff2b59487fb57aa5a85d782a
|
||||
Subproject commit f58510c8ce6cd89dadff2b29574d03b05c6efcc9
|
|
@ -1 +1 @@
|
|||
Subproject commit 75a86196030bb6efd9d67d42c0b25f17b4ec4e25
|
||||
Subproject commit 52d3169349b55b27090ecb81f88d10ebb65fa469
|
Loading…
Reference in a new issue