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