fix 修复空聊天信息从通讯录返回时闪退问题
This commit is contained in:
parent
c30f18eaa9
commit
9c54cfca2a
@ -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;
|
||||
|
@ -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<BaseUiConversation> 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<BaseUiConversation> 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<BaseUiConversation> 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;
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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"
|
||||
|
@ -78,7 +78,20 @@
|
||||
android:textSize="@dimen/rc_font_auxiliary_size" />
|
||||
</RelativeLayout>
|
||||
</RelativeLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/rc_conversation_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginStart="12dp"
|
||||
android:layout_marginTop="4dp"
|
||||
android:text="你好,朋友!"
|
||||
android:visibility="gone"
|
||||
android:textColor="#777777"
|
||||
android:textSize="11sp"
|
||||
app:layout_constraintEnd_toStartOf="@+id/rc_conversation_title"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintStart_toEndOf="@+id/rc_conversation_portrait_rl"
|
||||
app:layout_constraintTop_toBottomOf="@+id/rc_conversation_title" />
|
||||
<TextView
|
||||
android:id="@+id/rc_conversation_title"
|
||||
android:layout_width="0dp"
|
||||
|
Loading…
Reference in New Issue
Block a user