fix 修复空聊天信息从通讯录返回时闪退问题

This commit is contained in:
zlzw 2024-03-15 17:20:51 +08:00
parent 687d6e9bc0
commit 0f2269925f
2 changed files with 45 additions and 7 deletions

View File

@ -34,6 +34,7 @@ public class MainConversationListAdapter extends ConversationListAdapter {
public static final int TYPE_SEARCH_CHAT = 520;
private List<BaseUiConversation> srcList;
private Context mContext;
private View emptyView;
public MainConversationListAdapter(Context mContext) {
this.mContext = mContext;
@ -43,7 +44,7 @@ public class MainConversationListAdapter extends ConversationListAdapter {
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
ViewHolder holder = null;
mContext=parent.getContext();
mContext = parent.getContext();
if (viewType == TYPE_SEARCH_TITLE) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_main_msg_search_title, parent, false);
holder = ViewHolder.createViewHolder(parent.getContext(), view);
@ -54,7 +55,9 @@ public class MainConversationListAdapter extends ConversationListAdapter {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_main_msg_search_chat, parent, false);
holder = ViewHolder.createViewHolder(parent.getContext(), view);
} else {
holder = super.onCreateViewHolder(parent, viewType);
// holder = super.onCreateViewHolder(parent, viewType);
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_main_msg_search_empty, parent, false);
holder = ViewHolder.createViewHolder(parent.getContext(), view);
}
return holder;
}
@ -71,12 +74,18 @@ public class MainConversationListAdapter extends ConversationListAdapter {
} else if (!StringUtil.isEmpty(objectName) && objectName.startsWith("SEARCH_TITLE")) {
type = TYPE_SEARCH_TITLE;
}
} else {
type = -200;
}
return type;
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
if (isEmpty() || mDataList.isEmpty()) {
bindEmpty(holder, position);
return;
}
if (getItemViewType(position) == TYPE_SEARCH_USER) {
bindUser(holder, position);
} else if (getItemViewType(position) == TYPE_SEARCH_CHAT) {
@ -88,22 +97,26 @@ public class MainConversationListAdapter extends ConversationListAdapter {
}
}
private void bindEmpty(ViewHolder holder, int position) {
((ViewGroup) holder.getView(R.id.layout)).addView(emptyView);
}
@Override
public void setDataCollection(List<BaseUiConversation> data) {
super.setDataCollection(data);
if(srcList==null){
srcList=new ArrayList<>();
if (srcList == null) {
srcList = new ArrayList<>();
}
srcList.clear();
for (BaseUiConversation item : data) {
BaseUiConversation cn=new SingleConversation(mContext,item.mCore);
BaseUiConversation cn = new SingleConversation(mContext, item.mCore);
srcList.add(cn);
}
}
public List<BaseUiConversation> getSrcList() {
if(srcList==null){
srcList=new ArrayList<>();
if (srcList == null) {
srcList = new ArrayList<>();
}
return srcList;
}
@ -112,6 +125,11 @@ public class MainConversationListAdapter extends ConversationListAdapter {
holder.setText(R.id.title, mDataList.get(position).mCore.getObjectName().replace("SEARCH_TITLE", ""));
}
@Override
public void setEmptyView(View view) {
this.emptyView = view;
}
private void bindUser(ViewHolder holder, int position) {
ImgLoader.display(holder.getContext(), mDataList.get(position).mCore.getPortraitUrl(), holder.getView(R.id.rc_conversation_portrait));
String title = mDataList.get(position).mCore.getConversationTitle();

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/layout"
android:layout_width="300dp"
android:layout_height="300dp"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>