十天冲刺(第一阶段)

今日份学习内容实现了即时通讯部分的文字聊天代码,又进行了图片的学习

问题出现在:只能穿图片路径但是别人那里有没有图片

  TextMessage msg = (TextMessage) message.getContent();
                    String content = msg.getContent();
                    LogUtils.i(content);
                    //解析内容
                    final TextBean textBean = new Gson().fromJson(content, TextBean.class);
                    LogUtils.i("textbean:" + textBean.toString());
                    //普通消息
                    if (textBean.getType().equals(CloudManager.TYPE_TEXT)){
                        MessageEvent event=new MessageEvent(EventManager.FLAG_SEND_TEXT);
                        event.setText(textBean.getMsg());
                        event.setUserId(message.getSenderUserId());

                        EventManager.post(event);
                    }else if (textBean.getType().equals(CloudManager.TYPE_ADD_FRIEND)){
                        //添加好友消息
                        //查询数据库,如果有重复的就不添加
                        disposable = Observable.create(new ObservableOnSubscribe<List<NewFriend>>() {
                            @Override
                            public void subscribe(ObservableEmitter<List<NewFriend>> emitter) throws Exception {
                                emitter.onNext(LitePalHelper.getInstance().queryNewFriend());
                                emitter.onComplete();
                            }
                        }).subscribeOn(Schedulers.newThread())
                                .observeOn(AndroidSchedulers.mainThread())
                                .subscribe(new Consumer<List<NewFriend>>() {

                                    @Override
                                    public void accept(List<NewFriend> newFriends) throws Exception {
                                        boolean isHave = false;
                                        if (CommonUtils.isEmpty(newFriends)){
                                            for (int j = 0; j < newFriends.size(); j++) {
                                                NewFriend newFriend = newFriends.get(j);
                                                if (message.getSenderUserId().equals(newFriend.getSenderId())){
                                                    isHave = true;
                                                    break;
                                                }
                                            }
                                            LogUtils.i(isHave + "");

                                        //数据库中没有才添加
                                                 if (!isHave){
                                            LitePalHelper.getInstance().saveNewFriend(textBean.getMsg()
                                                    ,message.getSenderUserId());
                                            }
                                        }else
                                        {
                                            LitePalHelper.getInstance().saveNewFriend(textBean.getMsg()
                                                    ,message.getSenderUserId());
                                        }
                                    }
                                });

                    }else if (textBean.getType().equals(CloudManager.TYPE_AGREE_FRIEND)){
                        //同意添加好友消息
                        BmobManager.getInstance().addFriend(message.getSenderUserId(), new SaveListener<String>() {
                            @Override
                            public void done(String s, BmobException e) {
                                if (e == null){
                                    //刷新好友列表
                                    EventManager.post(EventManager.FLAG_UPDATE_FRIEND_LIST);
                                }
                            }
                        });

                    }

  

 

posted @ 2020-06-04 15:44  恶霸xx  阅读(107)  评论(0编辑  收藏  举报