融云即时通讯的自定义会话列表

来源:互联网 发布:淘宝店铺怎么关闭 编辑:程序博客网 时间:2024/06/06 00:56

集成了融云的会话列表,本以为万事大吉了但是我们的项目有夜间模式呀.....有木有很坑.好吧我还是乖乖的做夜间模式吧

1.自定义会话列表adapter继承ConversationListAdapter

因为我只是想改变item的背景颜色,自定义的内容不是很多.因此只展示这些.其他需求的话在重写的newView中可以换成自己的布局.,重写item的layout.

在bindView方法中可以把数据绑定给自己重写的布局.大家根据自己的需求看着来吧.


public class ConversationListAdapterEx extends ConversationListAdapter {    private Context context;    public ConversationListAdapterEx(Context context) {        super(context);        this.context = context;    }    @Override    protected View newView(Context context, int position, ViewGroup group) {        return super.newView(context, position, group);    }    @Override    protected void bindView(View v, int position, UIConversation data) {        super.bindView(v, position, data);        if(data.getConversationType().equals(Conversation.ConversationType.DISCUSSION)) {            data.setUnreadType(UIConversation.UnreadRemindType.REMIND_ONLY);        }        if(SharedPreferencesUtil.isNightModel(context)){            v.setBackgroundColor(context.getResources().getColor(R.color.colorBlack));        }else{            v.setBackgroundColor(context.getResources().getColor(R.color.colorWhite));        }    }}

2.因为动态加载fragment.将刚刚自定义的adapter设置给ConversationListFragment,这个fragment是融云的类.

conversationListFragment.setAdapter(newConversationListAdapterEx(RongContext.getInstance()));

  private void AddConversationListFragment(){      //会话列表        conversationListFragment.setAdapter(new ConversationListAdapterEx(RongContext.getInstance()));      Uri uri = Uri.parse("rong://" + getActivity().getApplicationInfo().packageName).buildUpon()              .appendPath("conversationlist")              .appendQueryParameter(Conversation.ConversationType.PRIVATE.getName(), "false") //设置私聊会话,该会话聚合不显示              .build();      conversationListFragment.setUri(uri);      FragmentTransaction transaction = fragmentManager.beginTransaction();      transaction.add(R.id.rong_container,conversationListFragment);      transaction.commit();  }

至此会话列表上的背景变成了黑色在夜间模式下,但是ConversationListFragment的北京是白的.....聪明的我去修改了会话列表fragment'的布局R.layour.rc_fr_conversationlist.xml,将其背景置为透明.这样ConversationListFragment的父fragmet,也就是我自己的fragment的夜间模式就可以显示出来了.

还有就是切换账号的时候会话列表的数据混乱.切换后重新加载一遍ConversationListFragment

删除会话列表的某一条数据 :

   private void removeList(String mid){        RongIM.getInstance().getRongIMClient().removeConversation(Conversation.ConversationType.PRIVATE, mid, new RongIMClient.ResultCallback<Boolean>() {            @Override            public void onSuccess(Boolean aBoolean) {                Log.e("onSuccess","你已经删除了会话列表上用户id为mid的人");            }            @Override            public void onError(RongIMClient.ErrorCode errorCode) {                Log.e("onError","onError"+errorCode.getMessage());            }        });    }