From 0f2269925f59c57c35e0b05ce75c7128692ac2a1 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Fri, 15 Mar 2024 17:20:51 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D=E7=A9=BA=E8=81=8A?= =?UTF-8?q?=E5=A4=A9=E4=BF=A1=E6=81=AF=E4=BB=8E=E9=80=9A=E8=AE=AF=E5=BD=95?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E6=97=B6=E9=97=AA=E9=80=80=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter/MainConversationListAdapter.java | 32 +++++++++++++++---- .../res/layout/item_main_msg_search_empty.xml | 20 ++++++++++++ 2 files changed, 45 insertions(+), 7 deletions(-) create mode 100644 main/src/main/res/layout/item_main_msg_search_empty.xml diff --git a/main/src/main/java/com/yunbao/main/adapter/MainConversationListAdapter.java b/main/src/main/java/com/yunbao/main/adapter/MainConversationListAdapter.java index 0f3ce60..8ca8fbb 100644 --- a/main/src/main/java/com/yunbao/main/adapter/MainConversationListAdapter.java +++ b/main/src/main/java/com/yunbao/main/adapter/MainConversationListAdapter.java @@ -34,6 +34,7 @@ public class MainConversationListAdapter extends ConversationListAdapter { public static final int TYPE_SEARCH_CHAT = 520; private List 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 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 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(); diff --git a/main/src/main/res/layout/item_main_msg_search_empty.xml b/main/src/main/res/layout/item_main_msg_search_empty.xml new file mode 100644 index 0000000..26690d8 --- /dev/null +++ b/main/src/main/res/layout/item_main_msg_search_empty.xml @@ -0,0 +1,20 @@ + + + + + + + \ No newline at end of file