diff --git a/common/src/main/java/com/yunbao/common/interfaces/OnGetItemListener.java b/common/src/main/java/com/yunbao/common/interfaces/OnGetItemListener.java new file mode 100644 index 0000000..a58b70e --- /dev/null +++ b/common/src/main/java/com/yunbao/common/interfaces/OnGetItemListener.java @@ -0,0 +1,5 @@ +package com.yunbao.common.interfaces; + +public interface OnGetItemListener { + T getItems(); +} diff --git a/common/src/main/java/com/yunbao/common/utils/ListUtils.java b/common/src/main/java/com/yunbao/common/utils/ListUtils.java new file mode 100644 index 0000000..b14b2c3 --- /dev/null +++ b/common/src/main/java/com/yunbao/common/utils/ListUtils.java @@ -0,0 +1,34 @@ +package com.yunbao.common.utils; + +import android.os.Parcel; +import android.os.Parcelable; + + +import java.util.ArrayList; +import java.util.List; + +public class ListUtils { + public static List cloneList(List src) { + List copiedList = new ArrayList<>(); + for (T item : src) { + T copiedItem = deepCopyItem(item); + copiedList.add(copiedItem); + } + return copiedList; + } + private static T deepCopyItem(T item) { + Parcel parcel = Parcel.obtain(); + item.writeToParcel(parcel, 0); // 将对象写入Parcel + parcel.setDataPosition(0); // 重置Parcel的位置到开头 + Parcelable.Creator creator= null; + try { + creator = (Parcelable.Creator) item.getClass().getField("CREATOR").get(null); + } catch (Exception e) { + throw new RuntimeException(e); + } + T copiedItem = creator.createFromParcel(parcel); // 从Parcel中创建新的对象实例 + parcel.recycle(); // 回收Parcel对象 + return copiedItem; + } + +} diff --git a/common/src/main/java/com/yunbao/common/utils/RouteUtil.java b/common/src/main/java/com/yunbao/common/utils/RouteUtil.java index 2813572..f324011 100644 --- a/common/src/main/java/com/yunbao/common/utils/RouteUtil.java +++ b/common/src/main/java/com/yunbao/common/utils/RouteUtil.java @@ -50,6 +50,7 @@ public class RouteUtil { public static final String PATH_BattlePassActivity="/main/BattlePassActivity"; public static final String PATH_SudGameActivity="/live/SudGameActivity"; public static final String PATH_COMMUNITY_Activity="/main/MainHomeCommunityActivity"; + public static final String PATH_ADDRESSBOOK="/main/MsgAddressBookActivity"; public static void forwardCommunityActivity() { @@ -355,4 +356,8 @@ public class RouteUtil { ARouter.getInstance().build(PATH_BattlePassActivity) .navigation(); } + + public static void forwardActivity(String path) { + ARouter.getInstance().build(path).navigation(); + } } diff --git a/main/src/main/AndroidManifest.xml b/main/src/main/AndroidManifest.xml index eff2901..e83f7ce 100644 --- a/main/src/main/AndroidManifest.xml +++ b/main/src/main/AndroidManifest.xml @@ -162,6 +162,8 @@ + \ No newline at end of file diff --git a/main/src/main/java/com/yunbao/main/activity/MsgAddressBookActivity.java b/main/src/main/java/com/yunbao/main/activity/MsgAddressBookActivity.java new file mode 100644 index 0000000..b93cb76 --- /dev/null +++ b/main/src/main/java/com/yunbao/main/activity/MsgAddressBookActivity.java @@ -0,0 +1,311 @@ +package com.yunbao.main.activity; + +import android.content.Context; +import android.graphics.Color; +import android.os.Bundle; +import android.text.Editable; +import android.text.TextWatcher; +import android.view.View; +import android.widget.EditText; + +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; +import androidx.viewpager.widget.ViewPager; +import androidx.viewpager2.adapter.FragmentStateAdapter; +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.interfaces.OnGetItemListener; +import com.yunbao.common.utils.DpUtil; +import com.yunbao.common.utils.ListUtils; +import com.yunbao.common.utils.RandomUtil; +import com.yunbao.common.utils.RouteUtil; +import com.yunbao.common.utils.StringUtil; +import com.yunbao.common.utils.WordUtil; +import com.yunbao.main.R; +import com.yunbao.main.adapter.MainMsgAddressBookListAdapter; +import com.yunbao.main.fragment.MyAddressBookFragment; + +import net.lucode.hackware.magicindicator.MagicIndicator; +import net.lucode.hackware.magicindicator.ViewPagerHelper; +import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator; +import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter; +import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator; +import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView; +import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator; +import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ColorTransitionPagerTitleView; +import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView; + +import java.util.ArrayList; +import java.util.List; + +@Route(path = RouteUtil.PATH_ADDRESSBOOK) +public class MsgAddressBookActivity extends AbsActivity { + protected ViewPager2 mViewPager; + private MagicIndicator mIndicator; + private List fragmentList = new ArrayList<>(); + List userLists = new ArrayList<>(); + + + @Override + protected int getLayoutId() { + return R.layout.activity_msg_addressbook; + } + + @Override + protected void main(Bundle savedInstanceState) { + super.main(savedInstanceState); + mIndicator = (MagicIndicator) findViewById(R.id.indicator); + mViewPager = (ViewPager2) findViewById(R.id.viewPager); + initViewPager(); + initIndicator(); + ((EditText) findViewById(R.id.search)).addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { + + } + + @Override + public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { + + } + + @Override + public void afterTextChanged(Editable editable) { + String key = editable.toString(); + MyAddressBookFragment fragment = fragmentList.get(mViewPager.getCurrentItem()); + if (StringUtil.isEmpty(key)) { + mIndicator.setVisibility(View.VISIBLE); + fragment.reload(); + mViewPager.setUserInputEnabled(true); + } else { + mIndicator.setVisibility(View.GONE); + search(key); + } + } + }); + } + + 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); + + } + + 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); + if (i == 0) { + if (userBean.getUserNiceName().contains(key)) { + userBean.setMobile("SEARCH_USER" + key); + userBean.setPraise(1); + data.add(userBean); + } + } else if (i == tmp.size() - 1) { + if (userBean.getUserNiceName().contains(key)) { + userBean.setPraise(2); + userBean.setMobile("SEARCH_USER" + key); + data.add(userBean); + } + } else { + if (userBean.getUserNiceName().contains(key)) { + userBean.setMobile("SEARCH_USER" + key); + data.add(userBean); + } + } + } + if (data.size() == 1) { + data.get(0).setPraise(3); + } + + return data; + } + + private UserBean createTitleBean(String title) { + UserBean mutualTitle = new UserBean(); + mutualTitle.setUserNiceName(title); + mutualTitle.setMobile("SEARCH_TITLE"); + return mutualTitle; + } + + private void initIndicator() { + final String[] titles = getTitles(); + CommonNavigator commonNavigator = new CommonNavigator(mContext); + commonNavigator.setAdjustMode(true); + commonNavigator.setAdapter(new CommonNavigatorAdapter() { + + @Override + public int getCount() { + return titles.length; + } + + @Override + public IPagerTitleView getTitleView(Context context, final int index) { + SimplePagerTitleView simplePagerTitleView = new ColorTransitionPagerTitleView(context); + simplePagerTitleView.setNormalColor(Color.parseColor("#777777")); + simplePagerTitleView.setSelectedColor(Color.parseColor("#333333")); + simplePagerTitleView.setText(titles[index]); + simplePagerTitleView.setTextSize(18); + simplePagerTitleView.getPaint().setFakeBoldText(true); + simplePagerTitleView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if (mViewPager != null) { + mViewPager.setCurrentItem(index); + } + } + }); + return simplePagerTitleView; + } + + @Override + public IPagerIndicator getIndicator(Context context) { + LinePagerIndicator linePagerIndicator = new LinePagerIndicator(context); + linePagerIndicator.setMode(LinePagerIndicator.MODE_WRAP_CONTENT); + linePagerIndicator.setXOffset(DpUtil.dp2px(5)); + linePagerIndicator.setRoundRadius(DpUtil.dp2px(2)); + linePagerIndicator.setColors(Color.parseColor("#EB6FFF")); + return linePagerIndicator; + } + }); + mIndicator.setNavigator(commonNavigator); + bind(mIndicator, mViewPager); + } + + private void initViewPager() { + userLists.addAll(createTempData(MyAddressBookFragment.TYPE_FOLLOW)); + userLists.addAll(createTempData(MyAddressBookFragment.TYPE_FAN)); + userLists.addAll(createTempData(MyAddressBookFragment.TYPE_MUTUAL)); + fragmentList = new ArrayList<>(); + fragmentList.add(new MyAddressBookFragment(MyAddressBookFragment.TYPE_FOLLOW, new OnGetItemListener>() { + @Override + public List getItems() { + return getDate(MyAddressBookFragment.TYPE_FOLLOW); + } + })); + fragmentList.add(new MyAddressBookFragment(MyAddressBookFragment.TYPE_FAN, new OnGetItemListener>() { + @Override + public List getItems() { + return getDate(MyAddressBookFragment.TYPE_FAN); + } + })); + fragmentList.add(new MyAddressBookFragment(MyAddressBookFragment.TYPE_MUTUAL, new OnGetItemListener>() { + @Override + public List getItems() { + return getDate(MyAddressBookFragment.TYPE_MUTUAL); + } + })); + mViewPager.setAdapter(new FragmentStateAdapter(this) { + + @Override + public int getItemCount() { + return fragmentList.size(); + } + + @NonNull + @Override + public Fragment createFragment(int i) { + return fragmentList.get(i); + } + }); + } + + public static void bind(final MagicIndicator magicIndicator, ViewPager2 viewPager) { + viewPager.registerOnPageChangeCallback(new ViewPager2.OnPageChangeCallback() { + @Override + public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { + super.onPageScrolled(position, positionOffset, positionOffsetPixels); + magicIndicator.onPageScrolled(position, positionOffset, positionOffsetPixels); + } + + @Override + public void onPageSelected(int position) { + super.onPageSelected(position); + magicIndicator.onPageSelected(position); + } + + @Override + public void onPageScrollStateChanged(int state) { + super.onPageScrollStateChanged(state); + magicIndicator.onPageScrollStateChanged(state); + } + }); + } + + private List createTempData(int type) { + List list = new ArrayList<>(); + for (int i = 0; i < 3; i++) { + UserBean u = new UserBean(); + u.setUserNiceName(RandomUtil.nextInt(100) + "title" + type); + u.setAvatar("https://downs.yaoulive.com/girltwo.png"); + if (type == 0) { + u.setFollows(1); + } else if (type == 1) { + u.setFans(1); + } else { + u.setFans(1); + u.setFollows(1); + } + list.add(u); + } + if (list.size() == 1) { + list.get(0).setPraise(3); + } else if (list.size() != 0) { + list.get(0).setPraise(1); + list.get(list.size() - 1).setPraise(2); + } + return list; + } + + private List getDate(int type) { + List list = new ArrayList<>(); + for (UserBean bean : userLists) { + if (type == MyAddressBookFragment.TYPE_MUTUAL) { + if (bean.getFollows() == 1 && bean.getFans() == 1) { + list.add(bean); + } + } else if (type == MyAddressBookFragment.TYPE_FOLLOW) { + if (bean.getFollows() == 1 && bean.getFans() != 1) { + list.add(bean); + } + } else if (type == MyAddressBookFragment.TYPE_FAN) { + if (bean.getFollows() != 1 && bean.getFans() == 1) { + list.add(bean); + } + } + } + if (list.size() == 1) { + list.get(0).setPraise(3); + } else if (list.size() > 1) { + list.get(0).setPraise(1); + list.get(list.size() - 1).setPraise(2); + } + return list; + } + + private String[] getTitles() { + return new String[]{ + WordUtil.getNewString(R.string.activity_msg_addressbook_tab_follow), + WordUtil.getNewString(R.string.activity_msg_addressbook_tab_fan), + WordUtil.getNewString(R.string.activity_msg_addressbook_tab_mutual) + }; + } +} diff --git a/main/src/main/java/com/yunbao/main/adapter/MainMsgAddressBookListAdapter.java b/main/src/main/java/com/yunbao/main/adapter/MainMsgAddressBookListAdapter.java new file mode 100644 index 0000000..98d1326 --- /dev/null +++ b/main/src/main/java/com/yunbao/main/adapter/MainMsgAddressBookListAdapter.java @@ -0,0 +1,177 @@ +package com.yunbao.main.adapter; + +import android.graphics.Color; +import android.text.Html; +import android.text.Spanned; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import androidx.annotation.NonNull; + +import com.yunbao.common.bean.UserBean; +import com.yunbao.common.glide.ImgLoader; +import com.yunbao.common.utils.StringUtil; +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.widget.adapter.BaseAdapter; +import io.rong.imkit.widget.adapter.ViewHolder; + +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; + + @NonNull + @Override + public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + ViewHolder holder = null; + 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); + } else if (viewType == TYPE_SEARCH_USER) { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_main_msg_search_chat, parent, false); + holder = ViewHolder.createViewHolder(parent.getContext(), view); + } 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 { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_main_msg_search_chat, parent, false); + holder = ViewHolder.createViewHolder(parent.getContext(), view); + } + return holder; + } + + @Override + 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; + } + } + return type; + } + + @Override + public void onBindViewHolder(@NonNull ViewHolder holder, int position) { + if (getItemViewType(position) == TYPE_SEARCH_USER) { + bindUser(holder, position); + } else if (getItemViewType(position) == TYPE_SEARCH_CHAT) { + bindChat(holder, position); + } else if (getItemViewType(position) == TYPE_SEARCH_TITLE) { + bindTitle(holder, position); + } else { + bindList(holder, 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.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.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){ + 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.getView(R.id.btn).setBackgroundResource(R.drawable.bg_msg_address_book_user_btn_mutual); + }else if(mDataList.get(position).getFollows()==1){ + 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.getView(R.id.btn).setBackgroundResource(R.drawable.bg_msg_address_book_user_btn_follow); + } + } + + private void bindTitle(ViewHolder holder, int position) { + holder.setText(R.id.title, mDataList.get(position).getUserNiceName()); + } + + 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", ""); + title = title.replace(key, "" + key + ""); + Spanned spanned = Html.fromHtml(title); + ((TextView) holder.getView(R.id.rc_conversation_title)).setText(spanned); + 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); + } + + if (mDataList.get(position).getFans()==1 && mDataList.get(position).getFollows()==0) { + 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.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){ + 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.getView(R.id.btn).setBackgroundResource(R.drawable.bg_msg_address_book_user_btn_mutual); + }else if(mDataList.get(position).getFollows()==1){ + 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.getView(R.id.btn).setBackgroundResource(R.drawable.bg_msg_address_book_user_btn_follow); + } + } + + private void bindChat(ViewHolder holder, int position) { + + } + public void setDataCollection(List data) { + if (data == null) { + data = new ArrayList(); + } + + super.setDataCollection(data); + this.notifyDataSetChanged(); + } +} diff --git a/main/src/main/java/com/yunbao/main/fragment/MyAddressBookFragment.java b/main/src/main/java/com/yunbao/main/fragment/MyAddressBookFragment.java new file mode 100644 index 0000000..218af49 --- /dev/null +++ b/main/src/main/java/com/yunbao/main/fragment/MyAddressBookFragment.java @@ -0,0 +1,116 @@ +package com.yunbao.main.fragment; + +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import com.yunbao.common.bean.UserBean; +import com.yunbao.common.interfaces.OnGetItemListener; +import com.yunbao.common.interfaces.OnItemClickListener; +import com.yunbao.common.utils.RandomUtil; +import com.yunbao.main.R; +import com.yunbao.main.adapter.MainMsgAddressBookListAdapter; + +import java.util.ArrayList; +import java.util.List; + +import io.rong.imkit.widget.refresh.SmartRefreshLayout; +import io.rong.imkit.widget.refresh.api.RefreshLayout; +import io.rong.imkit.widget.refresh.listener.OnLoadMoreListener; +import io.rong.imkit.widget.refresh.listener.OnRefreshListener; +import io.rong.imkit.widget.refresh.wrapper.RongRefreshHeader; + +public class MyAddressBookFragment extends Fragment { + + public static final int TYPE_FOLLOW = 0; + public static final int TYPE_FAN = 1; + public static final int TYPE_MUTUAL = 2; + + protected SmartRefreshLayout mRefreshLayout; + protected RecyclerView mList; + private MainMsgAddressBookListAdapter mAdapter; + private int type; + List list; + private OnGetItemListener> listener; + + + public MyAddressBookFragment(int typeMutual,OnGetItemListener> listener) { + this.type=typeMutual; + this.listener=listener; + } + + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + return inflater.inflate(R.layout.fragment_msg_addressbook_list, container, false); + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + mAdapter = new MainMsgAddressBookListAdapter(); + this.mList = (RecyclerView) view.findViewById(R.id.rc_conversation_list); + this.mRefreshLayout = (SmartRefreshLayout) view.findViewById(R.id.rc_refresh); + LinearLayoutManager layoutManager = new LinearLayoutManager(this.getActivity()); + this.mList.setLayoutManager(layoutManager); + mList.setAdapter(mAdapter); + initRefreshView(); + initData(); + } + + protected void initRefreshView() { + this.mRefreshLayout.setNestedScrollingEnabled(false); + this.mRefreshLayout.setRefreshHeader(new RongRefreshHeader(this.getContext())); + this.mRefreshLayout.setRefreshFooter(new RongRefreshHeader(this.getContext())); + this.mRefreshLayout.setOnRefreshListener(new OnRefreshListener() { + public void onRefresh(@NonNull RefreshLayout refreshLayout) { + onConversationListRefresh(refreshLayout); + } + }); + this.mRefreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() { + public void onLoadMore(@NonNull RefreshLayout refreshLayout) { + onConversationListLoadMore(); + } + }); + } + + private void onConversationListLoadMore() { + } + + private void onConversationListRefresh(RefreshLayout refreshLayout) { + mAdapter.getData().clear(); + initData(); + } + + private void initData() { + list = listener.getItems(); + + mAdapter.setDataCollection(list); + mRefreshLayout.finishLoadMore(); + mRefreshLayout.finishRefresh(true); + + } + + public void reload() { + mAdapter.setDataCollection(list); + mRefreshLayout.setEnableRefresh(true); + mRefreshLayout.setEnableLoadMore(true); + } + + public List getDate() { + return mAdapter.getData(); + } + + public void setSearchData(List list) { + mAdapter.setDataCollection(list); + mRefreshLayout.setEnableRefresh(false); + mRefreshLayout.setEnableLoadMore(false); + } +} 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 24563cc..c0ab43c 100644 --- a/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java +++ b/main/src/main/java/com/yunbao/main/views/MainMessageViewHolder.java @@ -129,6 +129,7 @@ public class MainMessageViewHolder extends AbsMainViewHolder { search = findViewById(R.id.search); contacts.setOnClickListener(view -> { //通讯录 + RouteUtil.forwardActivity(RouteUtil.PATH_ADDRESSBOOK); }); search.addTextChangedListener(new TextWatcher() { @Override @@ -138,11 +139,6 @@ public class MainMessageViewHolder extends AbsMainViewHolder { @Override public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { - /* if(StringUtil.isEmpty(charSequence.toString())){ - conversationListFragment.onChatList(); - }else { - conversationListFragment.search(charSequence.toString()); - }*/ } @Override diff --git a/main/src/main/res/drawable/bg_msg_address_book_user_btn_fan.xml b/main/src/main/res/drawable/bg_msg_address_book_user_btn_fan.xml new file mode 100644 index 0000000..db16a4f --- /dev/null +++ b/main/src/main/res/drawable/bg_msg_address_book_user_btn_fan.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/main/src/main/res/drawable/bg_msg_address_book_user_btn_follow.xml b/main/src/main/res/drawable/bg_msg_address_book_user_btn_follow.xml new file mode 100644 index 0000000..06435f5 --- /dev/null +++ b/main/src/main/res/drawable/bg_msg_address_book_user_btn_follow.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/main/src/main/res/drawable/bg_msg_address_book_user_btn_mutual.xml b/main/src/main/res/drawable/bg_msg_address_book_user_btn_mutual.xml new file mode 100644 index 0000000..60df406 --- /dev/null +++ b/main/src/main/res/drawable/bg_msg_address_book_user_btn_mutual.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/main/src/main/res/layout/activity_msg_addressbook.xml b/main/src/main/res/layout/activity_msg_addressbook.xml new file mode 100644 index 0000000..90403fe --- /dev/null +++ b/main/src/main/res/layout/activity_msg_addressbook.xml @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/main/src/main/res/layout/fragment_msg_addressbook_list.xml b/main/src/main/res/layout/fragment_msg_addressbook_list.xml new file mode 100644 index 0000000..041dfc8 --- /dev/null +++ b/main/src/main/res/layout/fragment_msg_addressbook_list.xml @@ -0,0 +1,24 @@ + + + + + + + + \ No newline at end of file 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 ebe2b81..4282dc0 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 @@ -102,6 +102,19 @@ app:layout_constraintStart_toEndOf="@+id/rc_conversation_portrait_rl" app:layout_constraintTop_toBottomOf="@+id/rc_conversation_title" /> +