From 0982b9554cdc439a79541de757ca628716f36eff Mon Sep 17 00:00:00 2001 From: z583819556 Date: Sat, 9 Mar 2024 13:37:59 +0800 Subject: [PATCH] =?UTF-8?q?update=E9=80=9A=E8=AE=AF=E5=BD=95=E6=90=9C?= =?UTF-8?q?=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/bean/MessageChatUserBean.java | 93 +++++++++ .../java/com/yunbao/common/bean/UserBean.java | 60 ++++++ .../common/interfaces/OnGetItemListener.java | 2 +- .../main/activity/MsgAddressBookActivity.java | 179 ++++++++++++------ .../activity/PDLiveConversationActivity.java | 23 ++- .../adapter/MainConversationListAdapter.java | 43 ++++- .../MainMsgAddressBookListAdapter.java | 130 ++++++++----- .../fragment/MainHomeCommunityFragment.java | 1 + .../fragment/MainMessageChatFragment.java | 38 ++-- .../main/fragment/MyAddressBookFragment.java | 45 +++-- .../res/layout/item_main_msg_search_chat.xml | 3 +- 11 files changed, 487 insertions(+), 130 deletions(-) create mode 100644 common/src/main/java/com/yunbao/common/bean/MessageChatUserBean.java diff --git a/common/src/main/java/com/yunbao/common/bean/MessageChatUserBean.java b/common/src/main/java/com/yunbao/common/bean/MessageChatUserBean.java new file mode 100644 index 000000000..c56507b7e --- /dev/null +++ b/common/src/main/java/com/yunbao/common/bean/MessageChatUserBean.java @@ -0,0 +1,93 @@ +package com.yunbao.common.bean; + +import com.google.gson.annotations.SerializedName; +import com.yunbao.common.utils.StringUtil; + +public class MessageChatUserBean extends UserBean{ + private String type; + private int modelType; + @SerializedName("user_nicename") + protected String userNiceName; + @SerializedName("isAttention") + private int attention;//isAttention 1被关注 2已关注 3互相关注 + + + public String getType() { + return type; + } + + public void setType(int type){ + this.type=type+""; + } + public int getTypeInt(){ + if(StringUtil.isEmpty(type)){ + return 0; + } + return Integer.parseInt(type); + } + + + @Override + public String getUserNiceName() { + return userNiceName; + } + + public int getModelType() { + return modelType; + } + + public void setModelType(int modelType) { + this.modelType = modelType; + } + + @Override + public void setUserNiceName(String userNiceName) { + this.userNiceName = userNiceName; + } + + public int getAttention() { + return attention; + } + + public void setAttention(int attention) { + this.attention = attention; + } + + @Override + public String toString() { + return "MessageChatUserBean{" + + "type='" + type + '\'' + + ", modelType='" + modelType + '\'' + + ", userNiceName='" + userNiceName + '\'' + + ", id='" + id + '\'' + + ", userNiceName='" + userNiceName + '\'' + + ", avatar='" + avatar + '\'' + + ", avatarThumb='" + avatarThumb + '\'' + + ", sex=" + sex + + ", signature='" + signature + '\'' + + ", coin='" + coin + '\'' + + ", gold='" + gold + '\'' + + ", votes='" + votes + '\'' + + ", consumption='" + consumption + '\'' + + ", votestotal='" + votestotal + '\'' + + ", province='" + province + '\'' + + ", city='" + city + '\'' + + ", location='" + location + '\'' + + ", birthday='" + birthday + '\'' + + ", level=" + level + + ", levelAnchor=" + levelAnchor + + ", lives=" + lives + + ", follows=" + follows + + ", fans=" + fans + + ", vip=" + vip + + ", liang=" + liang + + ", car=" + car + + ", medal_level=" + medal_level + + ", medal_name='" + medal_name + '\'' + + ", Dress=" + Dress + + ", noble_id='" + noble_id + '\'' + + ", yuanbao='" + yuanbao + '\'' + + ", typeMic=" + typeMic + + '}'; + } +} diff --git a/common/src/main/java/com/yunbao/common/bean/UserBean.java b/common/src/main/java/com/yunbao/common/bean/UserBean.java index aa44fc257..8a392d55f 100644 --- a/common/src/main/java/com/yunbao/common/bean/UserBean.java +++ b/common/src/main/java/com/yunbao/common/bean/UserBean.java @@ -76,6 +76,66 @@ public class UserBean implements Parcelable { private boolean isRequest = false; + @Override + public String toString() { + return "UserBean{" + + "id='" + id + '\'' + + ", userNiceName='" + userNiceName + '\'' + + ", avatar='" + avatar + '\'' + + ", avatarThumb='" + avatarThumb + '\'' + + ", sex=" + sex + + ", signature='" + signature + '\'' + + ", coin='" + coin + '\'' + + ", gold='" + gold + '\'' + + ", votes='" + votes + '\'' + + ", consumption='" + consumption + '\'' + + ", votestotal='" + votestotal + '\'' + + ", province='" + province + '\'' + + ", city='" + city + '\'' + + ", location='" + location + '\'' + + ", birthday='" + birthday + '\'' + + ", level=" + level + + ", levelAnchor=" + levelAnchor + + ", lives=" + lives + + ", follows=" + follows + + ", fans=" + fans + + ", vip=" + vip + + ", liang=" + liang + + ", car=" + car + + ", medal_level=" + medal_level + + ", medal_name='" + medal_name + '\'' + + ", Dress=" + Dress + + ", noble_id='" + noble_id + '\'' + + ", yuanbao='" + yuanbao + '\'' + + ", noble_name='" + noble_name + '\'' + + ", islive='" + islive + '\'' + + ", medal_no_display_src='" + medal_no_display_src + '\'' + + ", hot_num='" + hot_num + '\'' + + ", goodnum='" + goodnum + '\'' + + ", fans_pic='" + fans_pic + '\'' + + ", gifticon='" + gifticon + '\'' + + ", department_name='" + department_name + '\'' + + ", token_rong='" + token_rong + '\'' + + ", noble_end_time='" + noble_end_time + '\'' + + ", slide='" + slide + '\'' + + ", users_type='" + users_type + '\'' + + ", is_bind='" + is_bind + '\'' + + ", mobile='" + mobile + '\'' + + ", front_task='" + front_task + '\'' + + ", is_admin='" + is_admin + '\'' + + ", praise=" + praise + + ", isHide=" + isHide + + ", randomPk=" + randomPk + + ", mRankPkImgUrl='" + mRankPkImgUrl + '\'' + + ", user_info_complete=" + user_info_complete + + ", fansLevel=" + fansLevel + + ", typeMic=" + typeMic + + ", isMicList=" + isMicList + + ", isRequest=" + isRequest + + ", fansEnterRoomUrl='" + fansEnterRoomUrl + '\'' + + '}'; + } + public boolean isRequest() { return isRequest; } diff --git a/common/src/main/java/com/yunbao/common/interfaces/OnGetItemListener.java b/common/src/main/java/com/yunbao/common/interfaces/OnGetItemListener.java index a58b70efe..c08f8f039 100644 --- a/common/src/main/java/com/yunbao/common/interfaces/OnGetItemListener.java +++ b/common/src/main/java/com/yunbao/common/interfaces/OnGetItemListener.java @@ -1,5 +1,5 @@ package com.yunbao.common.interfaces; public interface OnGetItemListener { - T getItems(); + T getItems(int p); } diff --git a/main/src/main/java/com/yunbao/main/activity/MsgAddressBookActivity.java b/main/src/main/java/com/yunbao/main/activity/MsgAddressBookActivity.java index b93cb762c..b9e2e4914 100644 --- a/main/src/main/java/com/yunbao/main/activity/MsgAddressBookActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/MsgAddressBookActivity.java @@ -16,8 +16,13 @@ import androidx.viewpager2.widget.ViewPager2; import com.alibaba.android.arouter.facade.annotation.Route; import com.yunbao.common.activity.AbsActivity; -import com.yunbao.common.bean.UserBean; +import com.yunbao.common.bean.MessageChatUserBean; +import com.yunbao.common.bean.MessageChatUserBean; +import com.yunbao.common.http.API; +import com.yunbao.common.http.base.HttpCallback; +import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.interfaces.OnGetItemListener; +import com.yunbao.common.interfaces.OnItemClickListener; import com.yunbao.common.utils.DpUtil; import com.yunbao.common.utils.ListUtils; import com.yunbao.common.utils.RandomUtil; @@ -46,7 +51,7 @@ public class MsgAddressBookActivity extends AbsActivity { protected ViewPager2 mViewPager; private MagicIndicator mIndicator; private List fragmentList = new ArrayList<>(); - List userLists = new ArrayList<>(); + List userLists = new ArrayList<>(); @Override @@ -89,46 +94,71 @@ public class MsgAddressBookActivity extends AbsActivity { } private void search(String key) { - List list = new ArrayList<>(); - list.add(createTitleBean(WordUtil.getNewString(R.string.activity_msg_addressbook_tab_mutual))); - list.addAll(getSearchData(key, getDate(MyAddressBookFragment.TYPE_MUTUAL))); - list.add(createTitleBean(WordUtil.getNewString(R.string.activity_msg_addressbook_tab_fan))); - list.addAll(getSearchData(key, getDate(MyAddressBookFragment.TYPE_FAN))); - list.add(createTitleBean(WordUtil.getNewString(R.string.activity_msg_addressbook_tab_follow))); - list.addAll(getSearchData(key, getDate(MyAddressBookFragment.TYPE_FOLLOW))); - System.out.println("筛选 "); - System.out.println("筛选 "); - System.out.println("筛选--------------------------------------------"); - for (UserBean datum : list) { - System.out.println("筛选 " + datum.getUserNiceName() + " "); - } - System.out.println("筛选--------------------------------------------"); - fragmentList.get(mViewPager.getCurrentItem()).setSearchData(list); - mViewPager.setUserInputEnabled(false); + + LiveNetManager.get(mContext) + .addressBookSearch(key, new HttpCallback>() { + @Override + public void onSuccess(List tmp) { + List data = new ArrayList<>(); + for (int i = 0; i < tmp.size(); i++) { + MessageChatUserBean MessageChatUserBean = tmp.get(i); + MessageChatUserBean.setModelType(MainMsgAddressBookListAdapter.TYPE_SEARCH_USER); + if (MessageChatUserBean.getAttention() == 1) { + MessageChatUserBean.setType(MyAddressBookFragment.TYPE_FAN); + } else if (MessageChatUserBean.getAttention() == 2) { + MessageChatUserBean.setType(MyAddressBookFragment.TYPE_FOLLOW); + } else if (MessageChatUserBean.getAttention() == 3) { + MessageChatUserBean.setType(MyAddressBookFragment.TYPE_MUTUAL); + } else { + MessageChatUserBean.setType(-1); + } + if (i == 0) { + MessageChatUserBean.setPraise(1); + data.add(MessageChatUserBean); + } else if (i == tmp.size() - 1) { + MessageChatUserBean.setPraise(2); + data.add(MessageChatUserBean); + } else { + data.add(MessageChatUserBean); + } + } + if (data.size() == 1) { + data.get(0).setPraise(3); + } + fragmentList.get(mViewPager.getCurrentItem()).setSearchData(data); + mViewPager.setUserInputEnabled(false); + } + + @Override + public void onError(String error) { + + } + }); + } - private List getSearchData(String key, List list) { - List data = new ArrayList<>(); - List tmp = ListUtils.cloneList(list); + private List getSearchData(String key, List list) { + List data = new ArrayList<>(); + List tmp = ListUtils.cloneList(list); for (int i = 0; i < tmp.size(); i++) { - UserBean userBean = tmp.get(i); + MessageChatUserBean MessageChatUserBean = tmp.get(i); if (i == 0) { - if (userBean.getUserNiceName().contains(key)) { - userBean.setMobile("SEARCH_USER" + key); - userBean.setPraise(1); - data.add(userBean); + if (MessageChatUserBean.getUserNiceName().contains(key)) { + MessageChatUserBean.setMobile("SEARCH_USER" + key); + MessageChatUserBean.setPraise(1); + data.add(MessageChatUserBean); } } else if (i == tmp.size() - 1) { - if (userBean.getUserNiceName().contains(key)) { - userBean.setPraise(2); - userBean.setMobile("SEARCH_USER" + key); - data.add(userBean); + if (MessageChatUserBean.getUserNiceName().contains(key)) { + MessageChatUserBean.setPraise(2); + MessageChatUserBean.setMobile("SEARCH_USER" + key); + data.add(MessageChatUserBean); } } else { - if (userBean.getUserNiceName().contains(key)) { - userBean.setMobile("SEARCH_USER" + key); - data.add(userBean); + if (MessageChatUserBean.getUserNiceName().contains(key)) { + MessageChatUserBean.setMobile("SEARCH_USER" + key); + data.add(MessageChatUserBean); } } } @@ -139,8 +169,8 @@ public class MsgAddressBookActivity extends AbsActivity { return data; } - private UserBean createTitleBean(String title) { - UserBean mutualTitle = new UserBean(); + private MessageChatUserBean createTitleBean(String title) { + MessageChatUserBean mutualTitle = new MessageChatUserBean(); mutualTitle.setUserNiceName(title); mutualTitle.setMobile("SEARCH_TITLE"); return mutualTitle; @@ -191,26 +221,69 @@ public class MsgAddressBookActivity extends AbsActivity { } private void initViewPager() { - userLists.addAll(createTempData(MyAddressBookFragment.TYPE_FOLLOW)); - userLists.addAll(createTempData(MyAddressBookFragment.TYPE_FAN)); - userLists.addAll(createTempData(MyAddressBookFragment.TYPE_MUTUAL)); + userLists = new ArrayList<>(); fragmentList = new ArrayList<>(); - fragmentList.add(new MyAddressBookFragment(MyAddressBookFragment.TYPE_FOLLOW, new OnGetItemListener>() { + fragmentList.add(new MyAddressBookFragment(MyAddressBookFragment.TYPE_FOLLOW, new OnItemClickListener>>() { @Override - public List getItems() { - return getDate(MyAddressBookFragment.TYPE_FOLLOW); + public void onItemClick(OnItemClickListener> bean, int position) { + LiveNetManager.get(mContext) + .getPdluserFollow(position, new HttpCallback>() { + @Override + public void onSuccess(List data) { + for (MessageChatUserBean item : data) { + item.setType(MyAddressBookFragment.TYPE_FOLLOW); + } + bean.onItemClick(data, position); + userLists.addAll(data); + } + + @Override + public void onError(String error) { + + } + }); } })); - fragmentList.add(new MyAddressBookFragment(MyAddressBookFragment.TYPE_FAN, new OnGetItemListener>() { + fragmentList.add(new MyAddressBookFragment(MyAddressBookFragment.TYPE_FAN, new OnItemClickListener>>() { @Override - public List getItems() { - return getDate(MyAddressBookFragment.TYPE_FAN); + public void onItemClick(OnItemClickListener> bean, int position) { + LiveNetManager.get(mContext) + .getPdluserFans(position, new HttpCallback>() { + @Override + public void onSuccess(List data) { + for (MessageChatUserBean item : data) { + item.setType(MyAddressBookFragment.TYPE_FAN); + } + bean.onItemClick(data, position); + userLists.addAll(data); + } + + @Override + public void onError(String error) { + + } + }); } })); - fragmentList.add(new MyAddressBookFragment(MyAddressBookFragment.TYPE_MUTUAL, new OnGetItemListener>() { + fragmentList.add(new MyAddressBookFragment(MyAddressBookFragment.TYPE_MUTUAL, new OnItemClickListener>>() { @Override - public List getItems() { - return getDate(MyAddressBookFragment.TYPE_MUTUAL); + public void onItemClick(OnItemClickListener> bean, int position) { + LiveNetManager.get(mContext) + .getPdluserFriend(position, new HttpCallback>() { + @Override + public void onSuccess(List data) { + for (MessageChatUserBean item : data) { + item.setType(MyAddressBookFragment.TYPE_MUTUAL); + } + bean.onItemClick(data, position); + userLists.addAll(data); + } + + @Override + public void onError(String error) { + + } + }); } })); mViewPager.setAdapter(new FragmentStateAdapter(this) { @@ -250,10 +323,10 @@ public class MsgAddressBookActivity extends AbsActivity { }); } - private List createTempData(int type) { - List list = new ArrayList<>(); + private List createTempData(int type) { + List list = new ArrayList<>(); for (int i = 0; i < 3; i++) { - UserBean u = new UserBean(); + MessageChatUserBean u = new MessageChatUserBean(); u.setUserNiceName(RandomUtil.nextInt(100) + "title" + type); u.setAvatar("https://downs.yaoulive.com/girltwo.png"); if (type == 0) { @@ -275,9 +348,9 @@ public class MsgAddressBookActivity extends AbsActivity { return list; } - private List getDate(int type) { - List list = new ArrayList<>(); - for (UserBean bean : userLists) { + private List getDate(int type) { + List list = new ArrayList<>(); + for (MessageChatUserBean bean : userLists) { if (type == MyAddressBookFragment.TYPE_MUTUAL) { if (bean.getFollows() == 1 && bean.getFans() == 1) { list.add(bean); diff --git a/main/src/main/java/com/yunbao/main/activity/PDLiveConversationActivity.java b/main/src/main/java/com/yunbao/main/activity/PDLiveConversationActivity.java index 6ca910553..bd8411c2e 100644 --- a/main/src/main/java/com/yunbao/main/activity/PDLiveConversationActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/PDLiveConversationActivity.java @@ -30,8 +30,11 @@ import com.yunbao.common.activity.AbsActivity; import com.yunbao.common.activity.SelectImageActivity; import com.yunbao.common.bean.IMLoginModel; import com.yunbao.common.bean.ImageEntity; +import com.yunbao.common.bean.MessageChatUserBean; import com.yunbao.common.bean.NoviceInstructorModel; import com.yunbao.common.event.PDChatInputModeEvent; +import com.yunbao.common.http.base.HttpCallback; +import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.interfaces.OnSendMessageListener; import com.yunbao.common.manager.IMLoginManager; import com.yunbao.common.manager.NoviceInstructorManager; @@ -169,6 +172,7 @@ public class PDLiveConversationActivity extends AbsActivity implements View.OnCl //绑定聊天用户id inputPanel.setTargetId(targetId); + ToastUtil.show("id:"+targetId); //获取用户信息 UserInfo userInfo = RongUserInfoManager.getInstance().getUserInfo(targetId); if (null != userInfo) { @@ -190,8 +194,9 @@ public class PDLiveConversationActivity extends AbsActivity implements View.OnCl Log.e("PDLiveConversation", userInfo.getExtra()); } } else { - titleView.setText("系統消息"); - inputPanel.setVisibility(View.GONE); + /* titleView.setText("系統消息"); + inputPanel.setVisibility(View.GONE);*/ + setUserCard(); } getDraft(); @@ -241,6 +246,20 @@ public class PDLiveConversationActivity extends AbsActivity implements View.OnCl } + private void setUserCard() { + LiveNetManager.get(mContext) + .getOtherInfo(targetId, new HttpCallback() { + @Override + public void onSuccess(MessageChatUserBean data) { + + } + + @Override + public void onError(String error) { + + } + }); + } @Override public void onClick(View v) { 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 987c1b972..0f3ce6045 100644 --- a/main/src/main/java/com/yunbao/main/adapter/MainConversationListAdapter.java +++ b/main/src/main/java/com/yunbao/main/adapter/MainConversationListAdapter.java @@ -1,5 +1,6 @@ package com.yunbao.main.adapter; +import android.content.Context; import android.text.Html; import android.text.Spanned; import android.text.TextUtils; @@ -12,23 +13,37 @@ import android.widget.TextView; import androidx.annotation.NonNull; import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.utils.ListUtils; import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; import com.yunbao.main.R; +import java.util.ArrayList; +import java.util.List; + import io.rong.imkit.conversationlist.ConversationListAdapter; +import io.rong.imkit.conversationlist.model.BaseUiConversation; +import io.rong.imkit.conversationlist.model.SingleConversation; +import io.rong.imkit.utils.RouteUtils; import io.rong.imkit.widget.adapter.ViewHolder; public class MainConversationListAdapter extends ConversationListAdapter { public static final int TYPE_SEARCH_TITLE = 500; public static final int TYPE_SEARCH_USER = 510; public static final int TYPE_SEARCH_CHAT = 520; + private List srcList; + private Context mContext; + + public MainConversationListAdapter(Context mContext) { + this.mContext = mContext; + } @NonNull @Override public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { ViewHolder holder = 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); @@ -73,6 +88,26 @@ public class MainConversationListAdapter extends ConversationListAdapter { } } + @Override + public void setDataCollection(List data) { + super.setDataCollection(data); + if(srcList==null){ + srcList=new ArrayList<>(); + } + srcList.clear(); + for (BaseUiConversation item : data) { + BaseUiConversation cn=new SingleConversation(mContext,item.mCore); + srcList.add(cn); + } + } + + public List getSrcList() { + if(srcList==null){ + srcList=new ArrayList<>(); + } + return srcList; + } + private void bindTitle(ViewHolder holder, int position) { holder.setText(R.id.title, mDataList.get(position).mCore.getObjectName().replace("SEARCH_TITLE", "")); } @@ -98,6 +133,9 @@ public class MainConversationListAdapter extends ConversationListAdapter { holder.getView(R.id.itemDecorationBottom).setVisibility(View.VISIBLE); holder.itemView.setBackgroundResource(R.drawable.bg_msg_list_item_centre); } + holder.itemView.setOnClickListener(view -> { + RouteUtils.routeToConversationActivity(view.getContext(), mDataList.get(position).mCore.getConversationType(), mDataList.get(position).mCore.getTargetId()); + }); } private void bindChat(ViewHolder holder, int position) { @@ -106,7 +144,7 @@ public class MainConversationListAdapter extends ConversationListAdapter { String title = mDataList.get(position).mConversationContent.toString(); String key = mDataList.get(position).mCore.getObjectName().replace("SEARCH_CHAT", ""); title = title.replace(key, "" + key + ""); - Spanned spanned = Html.fromHtml(WordUtil.getNewString(R.string.activity_msg_list_include) +title); + Spanned spanned = Html.fromHtml(WordUtil.getNewString(R.string.activity_msg_list_include) + title); ((TextView) holder.getView(R.id.rc_conversation_content)).setText(spanned); int type = mDataList.get(position).mCore.getMentionedCount(); holder.getView(R.id.itemDecorationTop).setVisibility(View.GONE); @@ -122,5 +160,8 @@ public class MainConversationListAdapter extends ConversationListAdapter { holder.getView(R.id.itemDecorationBottom).setVisibility(View.VISIBLE); holder.itemView.setBackgroundResource(R.drawable.bg_msg_list_item_centre); } + holder.itemView.setOnClickListener(view -> { + RouteUtils.routeToConversationActivity(view.getContext(), mDataList.get(position).mCore.getConversationType(), mDataList.get(position).mCore.getTargetId()); + }); } } diff --git a/main/src/main/java/com/yunbao/main/adapter/MainMsgAddressBookListAdapter.java b/main/src/main/java/com/yunbao/main/adapter/MainMsgAddressBookListAdapter.java index 98d13266d..01f145b5b 100644 --- a/main/src/main/java/com/yunbao/main/adapter/MainMsgAddressBookListAdapter.java +++ b/main/src/main/java/com/yunbao/main/adapter/MainMsgAddressBookListAdapter.java @@ -6,25 +6,34 @@ import android.text.Spanned; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Button; import android.widget.TextView; import androidx.annotation.NonNull; +import com.yunbao.common.bean.MessageChatUserBean; +import com.yunbao.common.bean.SetAttentsModel; import com.yunbao.common.bean.UserBean; import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.http.base.HttpCallback; +import com.yunbao.common.http.live.LiveNetManager; import com.yunbao.common.utils.StringUtil; +import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; import com.yunbao.main.R; +import com.yunbao.main.fragment.MyAddressBookFragment; import java.util.ArrayList; import java.util.List; import io.rong.imkit.conversationlist.ConversationListAdapter; import io.rong.imkit.conversationlist.model.BaseUiConversation; +import io.rong.imkit.utils.RouteUtils; import io.rong.imkit.widget.adapter.BaseAdapter; import io.rong.imkit.widget.adapter.ViewHolder; +import io.rong.imlib.model.Conversation; -public class MainMsgAddressBookListAdapter extends BaseAdapter { +public class MainMsgAddressBookListAdapter extends BaseAdapter { public static final int TYPE_SEARCH_TITLE = 500; public static final int TYPE_SEARCH_USER = 510; public static final int TYPE_SEARCH_CHAT = 520; @@ -53,14 +62,7 @@ public class MainMsgAddressBookListAdapter extends BaseAdapter { public int getItemViewType(int position) { int type = super.getItemViewType(position); if (mDataList.size() > position) { - String objectName = mDataList.get(position).getMobile(); - if (!StringUtil.isEmpty(objectName) && objectName.startsWith("SEARCH_USER")) { - type = TYPE_SEARCH_USER; - } else if (!StringUtil.isEmpty(objectName) && objectName.equals("SEARCH_CHAT")) { - type = TYPE_SEARCH_CHAT; - } else if (!StringUtil.isEmpty(objectName) && objectName.startsWith("SEARCH_TITLE")) { - type = TYPE_SEARCH_TITLE; - } + type = mDataList.get(position).getModelType(); } return type; } @@ -76,45 +78,50 @@ public class MainMsgAddressBookListAdapter extends BaseAdapter { } else { bindList(holder, position); } + holder.getConvertView().setTag(mDataList.get(position)); + holder.getConvertView().setOnClickListener(view -> { + MessageChatUserBean userBean= (MessageChatUserBean) view.getTag(); + RouteUtils.routeToConversationActivity(view.getContext(), + Conversation.ConversationType.PRIVATE, + userBean.getId()); + }); } - private void bindList(ViewHolder holder, int position){ + + private void bindList(ViewHolder holder, int position) { ImgLoader.display(holder.getContext(), mDataList.get(position).getAvatar(), holder.getView(R.id.rc_conversation_portrait)); String title = mDataList.get(position).getUserNiceName(); ((TextView) holder.getView(R.id.rc_conversation_title)).setText(title); - int type = mDataList.get(position).getPraise(); holder.getView(R.id.itemDecorationTop).setVisibility(View.GONE); holder.getView(R.id.itemDecorationBottom).setVisibility(View.GONE); - /* if (type == 1) { - holder.itemView.setBackgroundResource(R.drawable.bg_msg_list_item_top); - holder.getView(R.id.itemDecorationBottom).setVisibility(View.VISIBLE); - } else if (type == 2) { - holder.itemView.setBackgroundResource(R.drawable.bg_msg_list_item_bottom); - } else if (type == 3) { - holder.itemView.setBackgroundResource(R.drawable.bg_msg_list_item); - } else { - holder.getView(R.id.itemDecorationBottom).setVisibility(View.VISIBLE); - holder.itemView.setBackgroundResource(R.drawable.bg_msg_list_item_centre); - }*/ holder.itemView.setBackground(null); - //holder.setText(R.id.rc_conversation_content,mDataList.get(position).getSignature()); - if (mDataList.get(position).getFans()==1 && mDataList.get(position).getFollows()==0) { + holder.setText(R.id.rc_conversation_content, mDataList.get(position).getSignature()); + holder.getView(R.id.btn).setTag(mDataList.get(position)); + if (mDataList.get(position).getTypeInt() == MyAddressBookFragment.TYPE_FAN) { holder.getView(R.id.btn).setVisibility(View.VISIBLE); - holder.getView(R.id.btn).setEnabled(true); holder.setTextColor(R.id.btn, Color.parseColor("#FFFFFF")); - holder.setText(R.id.btn,WordUtil.getNewString(R.string.activity_msg_addressbook_tab_fan2)); + holder.setText(R.id.btn, WordUtil.getNewString(R.string.activity_msg_addressbook_tab_fan2)); holder.getView(R.id.btn).setBackgroundResource(R.drawable.bg_msg_address_book_user_btn_fan); - }else if(mDataList.get(position).getFans()==1 && mDataList.get(position).getFollows()==1){ + } else if (mDataList.get(position).getTypeInt() == MyAddressBookFragment.TYPE_MUTUAL) { holder.getView(R.id.btn).setVisibility(View.VISIBLE); - holder.getView(R.id.btn).setEnabled(true); holder.setTextColor(R.id.btn, Color.parseColor("#333333")); - holder.setText(R.id.btn,WordUtil.getNewString(R.string.activity_msg_addressbook_tab_mutual)); + holder.setText(R.id.btn, WordUtil.getNewString(R.string.activity_msg_addressbook_tab_mutual)); holder.getView(R.id.btn).setBackgroundResource(R.drawable.bg_msg_address_book_user_btn_mutual); - }else if(mDataList.get(position).getFollows()==1){ + } else if (mDataList.get(position).getTypeInt() == MyAddressBookFragment.TYPE_FOLLOW) { holder.getView(R.id.btn).setVisibility(View.VISIBLE); - holder.getView(R.id.btn).setEnabled(false); - holder.setText(R.id.btn,WordUtil.getNewString(R.string.activity_msg_addressbook_tab_follow)); + holder.setText(R.id.btn, WordUtil.getNewString(R.string.activity_msg_addressbook_tab_follow)); holder.getView(R.id.btn).setBackgroundResource(R.drawable.bg_msg_address_book_user_btn_follow); + }else{ + holder.getView(R.id.btn).setVisibility(View.GONE); } + holder.getView(R.id.btn).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + MessageChatUserBean bean = (MessageChatUserBean) view.getTag(); + Button btn = (Button) view; + follow(btn, bean); + + } + }); } private void bindTitle(ViewHolder holder, int position) { @@ -124,13 +131,14 @@ public class MainMsgAddressBookListAdapter extends BaseAdapter { private void bindUser(ViewHolder holder, int position) { ImgLoader.display(holder.getContext(), mDataList.get(position).getAvatar(), holder.getView(R.id.rc_conversation_portrait)); String title = mDataList.get(position).getUserNiceName(); - String key = mDataList.get(position).getMobile().replace("SEARCH_USER", ""); + /* String key = mDataList.get(position).getMobile().replace("SEARCH_USER", ""); title = title.replace(key, "" + key + ""); - Spanned spanned = Html.fromHtml(title); - ((TextView) holder.getView(R.id.rc_conversation_title)).setText(spanned); + Spanned spanned = Html.fromHtml(title);*/ + ((TextView) holder.getView(R.id.rc_conversation_title)).setText(title); int type = mDataList.get(position).getPraise(); holder.getView(R.id.itemDecorationTop).setVisibility(View.GONE); holder.getView(R.id.itemDecorationBottom).setVisibility(View.GONE); + holder.setText(R.id.rc_conversation_content, mDataList.get(position).getSignature()); if (type == 1) { holder.itemView.setBackgroundResource(R.drawable.bg_msg_list_item_top); holder.getView(R.id.itemDecorationBottom).setVisibility(View.VISIBLE); @@ -142,31 +150,61 @@ public class MainMsgAddressBookListAdapter extends BaseAdapter { holder.getView(R.id.itemDecorationBottom).setVisibility(View.VISIBLE); holder.itemView.setBackgroundResource(R.drawable.bg_msg_list_item_centre); } - - if (mDataList.get(position).getFans()==1 && mDataList.get(position).getFollows()==0) { + holder.getView(R.id.btn).setTag(mDataList.get(position)); + if (mDataList.get(position).getTypeInt() == MyAddressBookFragment.TYPE_FAN) { holder.getView(R.id.btn).setVisibility(View.VISIBLE); - holder.getView(R.id.btn).setEnabled(true); holder.setTextColor(R.id.btn, Color.parseColor("#FFFFFF")); - holder.setText(R.id.btn,WordUtil.getNewString(R.string.activity_msg_addressbook_tab_fan2)); + holder.setText(R.id.btn, WordUtil.getNewString(R.string.activity_msg_addressbook_tab_fan2)); holder.getView(R.id.btn).setBackgroundResource(R.drawable.bg_msg_address_book_user_btn_fan); - }else if(mDataList.get(position).getFans()==1 && mDataList.get(position).getFollows()==1){ + } else if (mDataList.get(position).getTypeInt() == MyAddressBookFragment.TYPE_MUTUAL) { holder.getView(R.id.btn).setVisibility(View.VISIBLE); - holder.getView(R.id.btn).setEnabled(true); holder.setTextColor(R.id.btn, Color.parseColor("#333333")); - holder.setText(R.id.btn,WordUtil.getNewString(R.string.activity_msg_addressbook_tab_mutual)); + holder.setText(R.id.btn, WordUtil.getNewString(R.string.activity_msg_addressbook_tab_mutual)); holder.getView(R.id.btn).setBackgroundResource(R.drawable.bg_msg_address_book_user_btn_mutual); - }else if(mDataList.get(position).getFollows()==1){ + } else if (mDataList.get(position).getTypeInt() == MyAddressBookFragment.TYPE_FOLLOW) { holder.getView(R.id.btn).setVisibility(View.VISIBLE); - holder.getView(R.id.btn).setEnabled(false); - holder.setText(R.id.btn,WordUtil.getNewString(R.string.activity_msg_addressbook_tab_follow)); + holder.setText(R.id.btn, WordUtil.getNewString(R.string.activity_msg_addressbook_tab_follow)); holder.getView(R.id.btn).setBackgroundResource(R.drawable.bg_msg_address_book_user_btn_follow); + }else{ + holder.getView(R.id.btn).setVisibility(View.GONE); } + holder.getView(R.id.btn).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + MessageChatUserBean bean = (MessageChatUserBean) view.getTag(); + Button btn = (Button) view; + follow(btn, bean); + + } + }); } private void bindChat(ViewHolder holder, int position) { } - public void setDataCollection(List data) { + + private void follow(Button btn, MessageChatUserBean bean) { + LiveNetManager.get(btn.getContext()) + .setAttents(bean.getId(), new HttpCallback() { + @Override + public void onSuccess(SetAttentsModel data) { + bean.setType(MyAddressBookFragment.TYPE_MUTUAL); + btn.setEnabled(true); + btn.setTextColor(Color.parseColor("#333333")); + btn.setText(WordUtil.getNewString(R.string.activity_msg_addressbook_tab_mutual)); + btn.setBackgroundResource(R.drawable.bg_msg_address_book_user_btn_mutual); + btn.setTag(bean); + notifyDataSetChanged(); + } + + @Override + public void onError(String error) { + ToastUtil.show(error); + } + }); + } + + public void setDataCollection(List data) { if (data == null) { data = new ArrayList(); } diff --git a/main/src/main/java/com/yunbao/main/fragment/MainHomeCommunityFragment.java b/main/src/main/java/com/yunbao/main/fragment/MainHomeCommunityFragment.java index ae5f07953..567b843be 100644 --- a/main/src/main/java/com/yunbao/main/fragment/MainHomeCommunityFragment.java +++ b/main/src/main/java/com/yunbao/main/fragment/MainHomeCommunityFragment.java @@ -238,6 +238,7 @@ public class MainHomeCommunityFragment extends BaseFragment { mWebView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); } mWebView.loadUrl(url); + Log.i(TAG, url); findViewById(R.id.native_callback).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { 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 dacc061cc..8733c0c5b 100644 --- a/main/src/main/java/com/yunbao/main/fragment/MainMessageChatFragment.java +++ b/main/src/main/java/com/yunbao/main/fragment/MainMessageChatFragment.java @@ -11,6 +11,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.yunbao.common.custom.ItemDecoration; +import com.yunbao.common.utils.StringUtil; import com.yunbao.common.utils.ToastUtil; import com.yunbao.common.utils.WordUtil; import com.yunbao.main.R; @@ -23,6 +24,9 @@ import io.rong.imkit.conversationlist.ConversationListAdapter; import io.rong.imkit.conversationlist.ConversationListFragment; import io.rong.imkit.conversationlist.model.BaseUiConversation; import io.rong.imkit.conversationlist.model.SingleConversation; +import io.rong.imlib.IRongCoreCallback; +import io.rong.imlib.IRongCoreEnum; +import io.rong.imlib.RongCoreClient; import io.rong.imlib.RongIMClient; import io.rong.imlib.model.Conversation; import io.rong.imlib.model.SearchConversationResult; @@ -40,25 +44,35 @@ public class MainMessageChatFragment extends ConversationListFragment { public void search(String search) { - mAdapter.getData().clear(); getContactsList(search); } private void getContactsList(String search) { List list = new ArrayList<>(); - List data = new ArrayList<>(); + BaseUiConversation conversation = new SingleConversation(getContext(), new Conversation()); conversation.mCore.setObjectName("SEARCH_TITLE" + WordUtil.getNewString(R.string.activity_msg_list_title_contacts)); conversation.mCore.setConversationType(Conversation.ConversationType.PRIVATE); list.add(conversation); - for (int i = 0; i < 3; i++) { - conversation = new SingleConversation(getContext(), new Conversation()); - conversation.mCore.setObjectName("SEARCH_USER" + search); - conversation.mCore.setConversationTitle(search + "|" + i); - conversation.mCore.setConversationType(Conversation.ConversationType.PRIVATE); - conversation.mCore.setPortraitUrl("https://downs.yaoulive.com/girltwo.png"); - data.add(conversation); + + List data = new ArrayList<>(); + System.err.println(" ----------------------->" + mAdapter.getData().size()); + for (BaseUiConversation cn : ((MainConversationListAdapter) mAdapter).getSrcList()) { + System.err.println(" ----------------------->" + cn.mCore.getConversationTitle() + "|" + cn.mCore.getSenderUserName()); + if(StringUtil.isEmpty(cn.mCore.getConversationTitle()))continue; + if (cn.mCore.getConversationTitle().contains(search)) { + conversation = new SingleConversation(getContext(), new Conversation()); + conversation.mCore.setObjectName("SEARCH_USER" + search); + conversation.mCore.setConversationTitle(cn.mCore.getConversationTitle()); + conversation.mCore.setConversationType(Conversation.ConversationType.PRIVATE); + conversation.mCore.setPortraitUrl(cn.mCore.getPortraitUrl()); + conversation.mCore.setTargetId(cn.mCore.getTargetId()); + conversation.mCore.setSenderUserId(cn.mCore.getSenderUserId()); + data.add(conversation); + } + } + mAdapter.getData().clear(); if (data.size() == 1) { data.get(0).mCore.setMentionedCount(3); } else if (data.size() != 0) { @@ -85,7 +99,7 @@ public class MainMessageChatFragment extends ConversationListFragment { List data = new ArrayList<>(); for (SearchConversationResult result : searchConversationResults) { BaseUiConversation cn = new SingleConversation(getContext(), result.getConversation()); - cn.mCore.setObjectName("SEARCH_CHAT"+search); + cn.mCore.setObjectName("SEARCH_CHAT" + search); data.add(cn); } if (data.size() == 1) { @@ -103,7 +117,7 @@ public class MainMessageChatFragment extends ConversationListFragment { @Override public void onError(RongIMClient.ErrorCode e) { - ToastUtil.show("搜索出错了:"+e.getMessage()); + ToastUtil.show("搜索出错了:" + e.getMessage()); mAdapter.setDataCollection(list); mAdapter.notifyDataSetChanged(); } @@ -119,7 +133,7 @@ public class MainMessageChatFragment extends ConversationListFragment { @Override protected ConversationListAdapter onResolveAdapter() { - this.mAdapter = new MainConversationListAdapter(); + this.mAdapter = new MainConversationListAdapter(getContext()); return this.mAdapter; } } diff --git a/main/src/main/java/com/yunbao/main/fragment/MyAddressBookFragment.java b/main/src/main/java/com/yunbao/main/fragment/MyAddressBookFragment.java index 218af4941..91dc685a1 100644 --- a/main/src/main/java/com/yunbao/main/fragment/MyAddressBookFragment.java +++ b/main/src/main/java/com/yunbao/main/fragment/MyAddressBookFragment.java @@ -11,6 +11,7 @@ import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.yunbao.common.bean.MessageChatUserBean; import com.yunbao.common.bean.UserBean; import com.yunbao.common.interfaces.OnGetItemListener; import com.yunbao.common.interfaces.OnItemClickListener; @@ -37,13 +38,13 @@ public class MyAddressBookFragment extends Fragment { protected RecyclerView mList; private MainMsgAddressBookListAdapter mAdapter; private int type; - List list; - private OnGetItemListener> listener; + List list; + private OnItemClickListener>> listener; + int p = 1; - - public MyAddressBookFragment(int typeMutual,OnGetItemListener> listener) { - this.type=typeMutual; - this.listener=listener; + public MyAddressBookFragment(int typeMutual, OnItemClickListener>> listener) { + this.type = typeMutual; + this.listener = listener; } @Nullable @@ -82,6 +83,19 @@ public class MyAddressBookFragment extends Fragment { } private void onConversationListLoadMore() { + listener.onItemClick(new OnItemClickListener>() { + @Override + public void onItemClick(List bean, int position) { + if(bean.isEmpty()){ + mRefreshLayout.finishLoadMoreWithNoMoreData(); + return; + } + list.addAll(bean); + mAdapter.setDataCollection(list); + mRefreshLayout.finishLoadMore(); + p = position + 1; + } + }, p); } private void onConversationListRefresh(RefreshLayout refreshLayout) { @@ -90,11 +104,16 @@ public class MyAddressBookFragment extends Fragment { } private void initData() { - list = listener.getItems(); - - mAdapter.setDataCollection(list); - mRefreshLayout.finishLoadMore(); - mRefreshLayout.finishRefresh(true); + p = 1; + listener.onItemClick(new OnItemClickListener>() { + @Override + public void onItemClick(List bean, int position) { + list = bean; + mAdapter.setDataCollection(list); + mRefreshLayout.finishRefresh(); + p = position + 1; + } + }, p); } @@ -104,11 +123,11 @@ public class MyAddressBookFragment extends Fragment { mRefreshLayout.setEnableLoadMore(true); } - public List getDate() { + public List getDate() { return mAdapter.getData(); } - public void setSearchData(List list) { + public void setSearchData(List list) { mAdapter.setDataCollection(list); mRefreshLayout.setEnableRefresh(false); mRefreshLayout.setEnableLoadMore(false); diff --git a/main/src/main/res/layout/item_main_msg_search_chat.xml b/main/src/main/res/layout/item_main_msg_search_chat.xml index 4282dc01a..753b169ba 100644 --- a/main/src/main/res/layout/item_main_msg_search_chat.xml +++ b/main/src/main/res/layout/item_main_msg_search_chat.xml @@ -93,11 +93,10 @@ android:layout_height="wrap_content" android:layout_marginStart="12dp" android:layout_marginTop="4dp" - android:layout_marginEnd="60dp" android:text="你好,朋友!" android:textColor="#777777" android:textSize="11sp" - app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintEnd_toStartOf="@+id/btn" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toEndOf="@+id/rc_conversation_portrait_rl" app:layout_constraintTop_toBottomOf="@+id/rc_conversation_title" />