update
This commit is contained in:
@@ -19,19 +19,29 @@ import com.shayu.onetoone.activity.fragments.DynamicFragment;
|
||||
import com.shayu.onetoone.activity.fragments.FriendsFragment;
|
||||
import com.shayu.onetoone.activity.fragments.MessageFragment;
|
||||
import com.shayu.onetoone.activity.fragments.MyFragment;
|
||||
import com.shayu.onetoone.bean.OfficialNoticeBean;
|
||||
import com.shayu.onetoone.event.MessageMsgBusEvent;
|
||||
import com.shayu.onetoone.manager.OTONetManager;
|
||||
import com.shayu.onetoone.manager.RouteManager;
|
||||
import com.yunbao.common.CommonAppConfig;
|
||||
import com.yunbao.common.bean.IMLoginModel;
|
||||
import com.yunbao.common.http.base.HttpCallback;
|
||||
import com.yunbao.common.manager.IMLoginManager;
|
||||
import com.yunbao.common.manager.imrongcloud.RongcloudIMManager;
|
||||
import com.yunbao.common.utils.Bus;
|
||||
import com.yunbao.common.utils.ToastUtil;
|
||||
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.rong.imkit.RongIM;
|
||||
import io.rong.imkit.manager.UnReadMessageManager;
|
||||
import io.rong.imkit.userinfo.RongUserInfoManager;
|
||||
import io.rong.imlib.RongIMClient;
|
||||
import io.rong.imlib.model.Conversation;
|
||||
import io.rong.imlib.model.UserInfo;
|
||||
import kotlin.Unit;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
@@ -46,8 +56,15 @@ public class MainActivity extends AbsOTOActivity {
|
||||
private ViewPager2 viewPager;
|
||||
private DslTabLayout dslTabLayout;
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
Bus.getOff(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void main(Bundle savedInstanceState) {
|
||||
Bus.getOn(this);
|
||||
fragments.add(new FriendsFragment());
|
||||
fragments.add(new DynamicFragment());
|
||||
fragments.add(new MessageFragment());
|
||||
@@ -87,13 +104,70 @@ public class MainActivity extends AbsOTOActivity {
|
||||
}
|
||||
});
|
||||
RongcloudIMManager.connectIM(mContext);
|
||||
IMLoginModel userInfo = IMLoginManager.get(this).getUserInfo();
|
||||
UserInfo info = new UserInfo(userInfo.getId() + "", userInfo.getUserNicename(), Uri.parse(userInfo.getAvatar()));
|
||||
RongUserInfoManager.getInstance().refreshUserInfoCache(info);
|
||||
showRedPoint(-1);
|
||||
UnReadMessageManager.getInstance().addObserver(new Conversation.ConversationType[]{Conversation.ConversationType.SYSTEM, Conversation.ConversationType.PRIVATE}, new UnReadMessageManager.IUnReadMessageObserver() {
|
||||
@Override
|
||||
public void onCountChanged(int count) {
|
||||
showRedPoint(count);
|
||||
Bus.get().post(new MessageMsgBusEvent(MessageMsgBusEvent.TYPE_UPDATE_SYSTEM));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void showRedPoint(int count) {
|
||||
OTONetManager.getInstance(mContext)
|
||||
.getMessageSystemLists(new HttpCallback<List<OfficialNoticeBean>>() {
|
||||
int point = 0;
|
||||
|
||||
@Override
|
||||
public void onSuccess(List<OfficialNoticeBean> data) {
|
||||
for (OfficialNoticeBean datum : data) {
|
||||
point += datum.getNum();
|
||||
}
|
||||
//大于0则是通过会话未读监听器获取到的数,则不用再调用获取未读数接口了
|
||||
if (count >= 0) {
|
||||
updateUnreadCount(point + count);
|
||||
return;
|
||||
}
|
||||
RongIMClient.getInstance().getTotalUnreadCount(new RongIMClient.ResultCallback<Integer>() {
|
||||
@Override
|
||||
public void onSuccess(Integer integer) {
|
||||
updateUnreadCount(point + integer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(RongIMClient.ErrorCode e) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String error) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void updateUnreadCount(int count) {
|
||||
if(count==0){
|
||||
dslTabLayout.setDrawBadge(false);
|
||||
}else {
|
||||
dslTabLayout.setDrawBadge(true);
|
||||
}
|
||||
dslTabLayout.updateTabBadge(2, count + "");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.activity_main;
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void busEvent(MessageMsgBusEvent event) {
|
||||
if (event.getType() == MessageMsgBusEvent.TYPE_ALL_READ) {
|
||||
updateUnreadCount(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user