From 9c54cfca2a1cefa58eb46d373432e7b8314bca6b Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Sat, 16 Mar 2024 10:54:05 +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 --- .../content/MessageChatCardContent.java | 2 +- .../adapter/MainConversationListAdapter.java | 47 +++++++++++++------ .../fragment/MainMessageChatFragment.java | 6 +-- .../main/views/MainMessageViewHolder.java | 9 +--- .../res/layout/item_main_msg_search_empty.xml | 1 + .../res/layout/item_main_msg_search_user.xml | 15 +++++- 6 files changed, 53 insertions(+), 27 deletions(-) diff --git a/common/src/main/java/com/yunbao/common/message/content/MessageChatCardContent.java b/common/src/main/java/com/yunbao/common/message/content/MessageChatCardContent.java index 1b2b088c2..138313281 100644 --- a/common/src/main/java/com/yunbao/common/message/content/MessageChatCardContent.java +++ b/common/src/main/java/com/yunbao/common/message/content/MessageChatCardContent.java @@ -20,7 +20,7 @@ import io.rong.imlib.model.Conversation; import io.rong.imlib.model.Message; import io.rong.imlib.model.MessageContent; -@MessageTag(value = "MessageChatCardContent", flag = MessageTag.ISPERSISTED) +@MessageTag(value = "MessageChatCardContent", flag = MessageTag.ISCOUNTED) public class MessageChatCardContent extends MessageContent implements Parcelable { private String cover; private String title; 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 8ca8fbbe4..90a1d0f96 100644 --- a/main/src/main/java/com/yunbao/main/adapter/MainConversationListAdapter.java +++ b/main/src/main/java/com/yunbao/main/adapter/MainConversationListAdapter.java @@ -8,14 +8,17 @@ import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.NonNull; import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.utils.AppManager; import com.yunbao.common.utils.ListUtils; import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.ToastUtil; +import com.yunbao.common.utils.ViewUtils; import com.yunbao.common.utils.WordUtil; import com.yunbao.main.R; @@ -34,7 +37,7 @@ public class MainConversationListAdapter extends ConversationListAdapter { public static final int TYPE_SEARCH_CHAT = 520; private List srcList; private Context mContext; - private View emptyView; + private boolean isChat=true; public MainConversationListAdapter(Context mContext) { this.mContext = mContext; @@ -44,7 +47,9 @@ public class MainConversationListAdapter extends ConversationListAdapter { @Override public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { ViewHolder holder = null; - mContext = parent.getContext(); + if (mContext == null) { + 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,10 +59,11 @@ public class MainConversationListAdapter extends ConversationListAdapter { } else if (viewType == TYPE_SEARCH_CHAT) { 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); - View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_main_msg_search_empty, parent, false); + } else if (viewType != -200) { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.rc_conversationlist_item, parent, false); holder = ViewHolder.createViewHolder(parent.getContext(), view); + } else { + holder = super.onCreateViewHolder(parent, viewType); } return holder; } @@ -74,7 +80,7 @@ public class MainConversationListAdapter extends ConversationListAdapter { } else if (!StringUtil.isEmpty(objectName) && objectName.startsWith("SEARCH_TITLE")) { type = TYPE_SEARCH_TITLE; } - } else { + } else if (mDataList.isEmpty() || isEmpty() || srcList.isEmpty()) { type = -200; } return type; @@ -83,7 +89,7 @@ public class MainConversationListAdapter extends ConversationListAdapter { @Override public void onBindViewHolder(@NonNull ViewHolder holder, int position) { if (isEmpty() || mDataList.isEmpty()) { - bindEmpty(holder, position); + bindEmpty(holder, position); return; } if (getItemViewType(position) == TYPE_SEARCH_USER) { @@ -92,26 +98,35 @@ public class MainConversationListAdapter extends ConversationListAdapter { bindChat(holder, position); } else if (getItemViewType(position) == TYPE_SEARCH_TITLE) { bindTitle(holder, position); - } else { + } else if (getItemViewType(position) != -200) { super.onBindViewHolder(holder, position); } } private void bindEmpty(ViewHolder holder, int position) { - ((ViewGroup) holder.getView(R.id.layout)).addView(emptyView); + if(isChat){ + ViewUtils.findViewById(holder.itemView,R.id.imageView, ImageView.class).setImageResource(R.mipmap.ic_message_not_chat_list); + ViewUtils.findViewById(holder.itemView,R.id.textView, TextView.class).setText(R.string.not_data_message_chat_list); + }else{ + ViewUtils.findViewById(holder.itemView,R.id.imageView, ImageView.class).setImageResource(R.mipmap.ic_message_not_search); + ViewUtils.findViewById(holder.itemView,R.id.textView, TextView.class).setText(R.string.not_data_message_chat_list_search); + } } @Override public void setDataCollection(List data) { - super.setDataCollection(data); if (srcList == null) { srcList = new ArrayList<>(); } + mDataList.clear(); srcList.clear(); + if (mContext == null) + mContext = AppManager.getInstance().getLastActivity(); for (BaseUiConversation item : data) { BaseUiConversation cn = new SingleConversation(mContext, item.mCore); srcList.add(cn); } + super.setDataCollection(data); } public List getSrcList() { @@ -125,10 +140,6 @@ 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)); @@ -182,4 +193,12 @@ public class MainConversationListAdapter extends ConversationListAdapter { RouteUtils.routeToConversationActivity(view.getContext(), mDataList.get(position).mCore.getConversationType(), mDataList.get(position).mCore.getTargetId()); }); } + + public void setChat() { + isChat=true; + } + + public void setSearch() { + isChat=false; + } } diff --git a/main/src/main/java/com/yunbao/main/fragment/MainMessageChatFragment.java b/main/src/main/java/com/yunbao/main/fragment/MainMessageChatFragment.java index 894d2daba..2b1c94eb9 100644 --- a/main/src/main/java/com/yunbao/main/fragment/MainMessageChatFragment.java +++ b/main/src/main/java/com/yunbao/main/fragment/MainMessageChatFragment.java @@ -47,6 +47,7 @@ public class MainMessageChatFragment extends ConversationListFragment { public void search(String search) { + ((MainConversationListAdapter)mAdapter).setSearch(); getContactsList(search); } @@ -75,7 +76,6 @@ public class MainMessageChatFragment extends ConversationListFragment { } } - mAdapter.getData().clear(); if (data.size() == 1) { data.get(0).mCore.setMentionedCount(3); } else if (data.size() != 0) { @@ -115,14 +115,12 @@ public class MainMessageChatFragment extends ConversationListFragment { } list.addAll(data); mAdapter.setDataCollection(list); - mAdapter.notifyDataSetChanged(); } @Override public void onError(RongIMClient.ErrorCode e) { ToastUtil.show("搜索出错了:" + e.getMessage()); mAdapter.setDataCollection(list); - mAdapter.notifyDataSetChanged(); } }); @@ -130,7 +128,7 @@ public class MainMessageChatFragment extends ConversationListFragment { } public void onChatList() { - mAdapter.getData().clear(); + ((MainConversationListAdapter)mAdapter).setChat(); subscribeUi(); } diff --git a/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java b/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java index c6584107a..a64ab50a3 100644 --- a/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java @@ -95,7 +95,6 @@ public class MainMessageViewHolder extends AbsMainViewHolder { private EditText search; XPopup.Builder moreXPopup; private String homeZdyPop; - private View emptyView; public MainMessageViewHolder setHomeZdyPop(String homeZdyPop) { this.homeZdyPop = homeZdyPop; @@ -141,7 +140,6 @@ public class MainMessageViewHolder extends AbsMainViewHolder { contacts = findViewById(R.id.news_icon_contacts); more = findViewById(R.id.news_icon_more); search = findViewById(R.id.search); - emptyView = LayoutInflater.from(getContentView().getContext()).inflate(R.layout.view_layout_msg, getRootView(), false); contacts.setOnClickListener(view -> { //通讯录 RouteUtil.forwardActivity(RouteUtil.PATH_ADDRESSBOOK); @@ -162,12 +160,8 @@ public class MainMessageViewHolder extends AbsMainViewHolder { public void afterTextChanged(Editable editable) { if (conversationListFragment == null) return; if (StringUtil.isEmpty(editable.toString())) { - ViewUtils.findViewById(emptyView,R.id.imageView, ImageView.class).setImageResource(R.mipmap.ic_message_not_chat_list); - ViewUtils.findViewById(emptyView,R.id.textView, TextView.class).setText(R.string.not_data_message_chat_list); conversationListFragment.onChatList(); } else { - ViewUtils.findViewById(emptyView,R.id.imageView, ImageView.class).setImageResource(R.mipmap.ic_message_not_search); - ViewUtils.findViewById(emptyView,R.id.textView, TextView.class).setText(R.string.not_data_message_chat_list_search); conversationListFragment.search(editable.toString()); } } @@ -256,7 +250,8 @@ public class MainMessageViewHolder extends AbsMainViewHolder { transaction.replace(R.id.container, conversationListFragment); transaction.commit(); //自定义空数据背景View - conversationListFragment.setEmptyView(emptyView); + //conversationListFragment.setEmptyView(emptyView); + conversationListFragment.setEmptyView(R.layout.view_layout_msg); //刷新列表内用户信息 ConversationIMListManager.get(mContext).addUserInfoProvider(); } 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 index 26690d828..e2079d285 100644 --- a/main/src/main/res/layout/item_main_msg_search_empty.xml +++ b/main/src/main/res/layout/item_main_msg_search_empty.xml @@ -11,6 +11,7 @@ android:layout_height="300dp" android:gravity="center" android:orientation="vertical" + android:background="@color/blue" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" diff --git a/main/src/main/res/layout/item_main_msg_search_user.xml b/main/src/main/res/layout/item_main_msg_search_user.xml index b9131ea09..2103a5092 100644 --- a/main/src/main/res/layout/item_main_msg_search_user.xml +++ b/main/src/main/res/layout/item_main_msg_search_user.xml @@ -78,7 +78,20 @@ android:textSize="@dimen/rc_font_auxiliary_size" /> - +