|
@@ -5,7 +5,10 @@ import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.os.Bundle;
|
|
|
import android.text.TextUtils;
|
|
|
+import android.view.LayoutInflater;
|
|
|
import android.view.MenuItem;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.TextView;
|
|
|
|
|
|
import com.alibaba.android.arouter.facade.annotation.Route;
|
|
|
import com.common.im.ui.MessageFragment;
|
|
@@ -25,6 +28,8 @@ import com.cooleshow.usercenter.bean.UserInfo;
|
|
|
import com.cooleshow.usercenter.helper.UserHelper;
|
|
|
import com.daya.live_teaching.common.ResultCallback;
|
|
|
import com.daya.live_teaching.im.IMManager;
|
|
|
+import com.google.android.material.bottomnavigation.BottomNavigationItemView;
|
|
|
+import com.google.android.material.bottomnavigation.BottomNavigationMenuView;
|
|
|
import com.google.android.material.bottomnavigation.BottomNavigationView;
|
|
|
import com.tbruyelle.rxpermissions3.RxPermissions;
|
|
|
import com.tencent.open.im.IM;
|
|
@@ -39,6 +44,7 @@ import androidx.annotation.NonNull;
|
|
|
import androidx.annotation.Nullable;
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
|
|
+import io.rong.imkit.manager.UnReadMessageManager;
|
|
|
import io.rong.imlib.RongIMClient;
|
|
|
|
|
|
import static com.cooleshow.base.constanst.Constants.MAIN_PAGE_SELECT_POTION_KEY;
|
|
@@ -47,11 +53,12 @@ import static com.cooleshow.base.constanst.Constants.MAIN_PAGE_SELECT_POTION_KEY
|
|
|
* Author by pq, Date on 2022/4/20.
|
|
|
*/
|
|
|
@Route(path = RouterPath.APPCenter.PATH_HOME)
|
|
|
-public class MainActivity extends BaseMVPActivity<ActivityMainBinding, MainPresenter> implements MainContract.MainView {
|
|
|
+public class MainActivity extends BaseMVPActivity<ActivityMainBinding, MainPresenter> implements MainContract.MainView, UnReadMessageManager.IUnReadMessageObserver {
|
|
|
private ArrayList<Fragment> mFragments = new ArrayList<>();
|
|
|
private HomeFragment mHomeFragment;
|
|
|
private MineFragment mMineFragment;
|
|
|
private MallFragment shopMallFragment;
|
|
|
+ private TextView tvMsgCount;
|
|
|
|
|
|
/**
|
|
|
* 打开首页并选中指定tab
|
|
@@ -99,6 +106,12 @@ public class MainActivity extends BaseMVPActivity<ActivityMainBinding, MainPrese
|
|
|
|
|
|
@Override
|
|
|
protected void initView() {
|
|
|
+ BottomNavigationMenuView menuView = (BottomNavigationMenuView) viewBinding.navigation.getChildAt(0);
|
|
|
+ BottomNavigationItemView messageTab = (BottomNavigationItemView) menuView.getChildAt(2);
|
|
|
+ View badge = LayoutInflater.from(this).inflate(com.cooleshow.base.R.layout.im_badge, menuView, false);
|
|
|
+ tvMsgCount = badge.findViewById(com.cooleshow.base.R.id.tv_msg_count);
|
|
|
+ messageTab.addView(badge);
|
|
|
+
|
|
|
HomePageAdapter homePageAdapter = new HomePageAdapter(this);
|
|
|
mHomeFragment = new HomeFragment();
|
|
|
CourseTableFragment courseTableFragment = new CourseTableFragment();
|
|
@@ -149,6 +162,7 @@ public class MainActivity extends BaseMVPActivity<ActivityMainBinding, MainPrese
|
|
|
public void initData() {
|
|
|
super.initData();
|
|
|
requestPermission();
|
|
|
+ IMManager.getInstance().addOnUnReadMessageListener(this);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -271,8 +285,23 @@ public class MainActivity extends BaseMVPActivity<ActivityMainBinding, MainPrese
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public void onCountChanged(int count) {
|
|
|
+ if (count > 0) {
|
|
|
+ tvMsgCount.setVisibility(View.VISIBLE);
|
|
|
+ if (count <= 99) {
|
|
|
+ tvMsgCount.setText(String.valueOf(count));
|
|
|
+ } else {
|
|
|
+ tvMsgCount.setText("99+");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ tvMsgCount.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public void onDestroy() {
|
|
|
super.onDestroy();
|
|
|
EventBus.getDefault().unregister(this);
|
|
|
+ IMManager.getInstance().removeOnUnReadMessageListener(this);
|
|
|
}
|
|
|
}
|