|
@@ -1,29 +1,65 @@
|
|
|
package com.cooleshow.institution.stu.ui.main;
|
|
|
|
|
|
+import android.Manifest;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.text.TextUtils;
|
|
|
import android.view.View;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
import com.alibaba.android.arouter.facade.annotation.Route;
|
|
|
+import com.cooleshow.base.common.BaseApplication;
|
|
|
+import com.cooleshow.base.constanst.LoginStatusConstants;
|
|
|
+import com.cooleshow.base.event.LoginStatusEvent;
|
|
|
import com.cooleshow.base.router.RouterPath;
|
|
|
import com.cooleshow.base.ui.activity.BaseActivity;
|
|
|
+import com.cooleshow.base.ui.activity.BaseMVPActivity;
|
|
|
+import com.cooleshow.base.utils.LogUtils;
|
|
|
+import com.cooleshow.base.utils.helper.MidiFileHelper;
|
|
|
import com.cooleshow.base.utils.helper.QMUIStatusBarHelper;
|
|
|
+import com.cooleshow.base.utils.helper.UpdateAppHelper;
|
|
|
+import com.cooleshow.chatmodule.contract.IUnReadMessageObserver;
|
|
|
+import com.cooleshow.chatmodule.manager.IMCenter;
|
|
|
import com.cooleshow.chatmodule.ui.ChatFragment;
|
|
|
import com.cooleshow.institution.stu.R;
|
|
|
import com.cooleshow.institution.stu.adapter.HomePageAdapter;
|
|
|
+import com.cooleshow.institution.stu.contract.MainContract;
|
|
|
import com.cooleshow.institution.stu.databinding.ActivityInstitutionMainLayoutBinding;
|
|
|
+import com.cooleshow.institution.stu.presenter.MainPresenter;
|
|
|
+import com.cooleshow.usercenter.bean.StudentUserInfo;
|
|
|
+import com.cooleshow.usercenter.helper.UserHelper;
|
|
|
+import com.tbruyelle.rxpermissions3.RxPermissions;
|
|
|
+import com.tencent.bugly.crashreport.CrashReport;
|
|
|
+
|
|
|
+import org.greenrobot.eventbus.EventBus;
|
|
|
+import org.greenrobot.eventbus.Subscribe;
|
|
|
+import org.greenrobot.eventbus.ThreadMode;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
+import androidx.annotation.Nullable;
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
+import cn.jpush.android.api.JPushInterface;
|
|
|
|
|
|
/**
|
|
|
* Author by pq, Date on 2023/9/11.
|
|
|
*/
|
|
|
@Route(path = RouterPath.JGCenter.PATH_HOME)
|
|
|
-public class MainActivity extends BaseActivity<ActivityInstitutionMainLayoutBinding> {
|
|
|
+public class MainActivity extends BaseMVPActivity<ActivityInstitutionMainLayoutBinding, MainPresenter> implements MainContract.MainContractView {
|
|
|
ArrayList<Fragment> mFragments = new ArrayList<>();
|
|
|
private ChatFragment mChatFragment;
|
|
|
private HomeFragment mHomeFragment;
|
|
|
+ private boolean isNeedSetPushId = true;
|
|
|
+ private IUnReadMessageObserver mUnReadMessageObserver =new IUnReadMessageObserver(){
|
|
|
+ @Override
|
|
|
+ public void onTotalUnreadMessageCountChanged(long totalUnreadCount) {
|
|
|
+ onCountChanged(totalUnreadCount);
|
|
|
+ }
|
|
|
+ };
|
|
|
+ @Override
|
|
|
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+ EventBus.getDefault().register(this);
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
protected void initView() {
|
|
@@ -42,6 +78,12 @@ public class MainActivity extends BaseActivity<ActivityInstitutionMainLayoutBind
|
|
|
onTabClick(viewBinding.viewHome);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void initData() {
|
|
|
+ super.initData();
|
|
|
+ requestPermission();
|
|
|
+ IMCenter.getInstance().addUnReadMessageObserver(mUnReadMessageObserver);
|
|
|
+ }
|
|
|
|
|
|
public void onTabClick(View view) {
|
|
|
int id = view.getId();
|
|
@@ -88,4 +130,106 @@ public class MainActivity extends BaseActivity<ActivityInstitutionMainLayoutBind
|
|
|
protected ActivityInstitutionMainLayoutBinding getLayoutView() {
|
|
|
return ActivityInstitutionMainLayoutBinding.inflate(getLayoutInflater());
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected MainPresenter createPresenter() {
|
|
|
+ return new MainPresenter();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onResume() {
|
|
|
+ super.onResume();
|
|
|
+ presenter.queryUserInfo();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Subscribe(threadMode = ThreadMode.MAIN)
|
|
|
+ public void loadEventBus(LoginStatusEvent event) {
|
|
|
+ if (event != null && event.eventCode == LoginStatusConstants.LOGIN_OUT) {
|
|
|
+ IMCenter.getInstance().logoutIM();
|
|
|
+ isNeedSetPushId = true;
|
|
|
+ LogUtils.i("pq", "LoginStatusEvent:logout");
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void queryUserInfoSuccess(StudentUserInfo data) {
|
|
|
+ if (isFinishing() || isDestroyed()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //存储userInfo信息
|
|
|
+ UserHelper.saveUserInfo(data);
|
|
|
+ connectIM();
|
|
|
+ bindPushId();
|
|
|
+ refreshUserInfo(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void refreshUserInfo(StudentUserInfo data) {
|
|
|
+ if (mHomeFragment != null) {
|
|
|
+ mHomeFragment.refreshUserInfo(data);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 申请存储权限
|
|
|
+ */
|
|
|
+ private void requestPermission() {
|
|
|
+ new RxPermissions(this)
|
|
|
+ .request(Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
|
|
+ .subscribe(permission -> {
|
|
|
+ if (permission) {
|
|
|
+ checkAppVersion();
|
|
|
+ MidiFileHelper.initMidFile();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkAppVersion() {
|
|
|
+ UpdateAppHelper.getInstance().checkUpdate(this, "android-student");
|
|
|
+ }
|
|
|
+
|
|
|
+ private void bindPushId() {
|
|
|
+ if (isNeedSetPushId && UserHelper.isLogin() && !TextUtils.isEmpty(UserHelper.getUserId())) {
|
|
|
+ String userId = UserHelper.getUserId();
|
|
|
+ LogUtils.i("pq", "registrationId:" + BaseApplication.registrationId);
|
|
|
+ JPushInterface.setAlias(getApplicationContext(), 1, userId);
|
|
|
+ CrashReport.setDeviceId(getApplicationContext(), userId);
|
|
|
+ isNeedSetPushId = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void onCountChanged(long count) {
|
|
|
+ if (count > 0) {
|
|
|
+ viewBinding.tvMsgCount.setVisibility(View.VISIBLE);
|
|
|
+ if (count <= 99) {
|
|
|
+ viewBinding.tvMsgCount.setText(String.valueOf(count));
|
|
|
+ } else {
|
|
|
+ viewBinding.tvMsgCount.setText("99+");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ viewBinding.tvMsgCount.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 连接rong IM
|
|
|
+ */
|
|
|
+ private void connectIM() {
|
|
|
+ if (UserHelper.isLogin()) {
|
|
|
+ String userIMToken = UserHelper.getUserIMToken();
|
|
|
+ String imUserId = UserHelper.getImUserId();
|
|
|
+ if (!TextUtils.isEmpty(userIMToken)) {
|
|
|
+ // 在用户 UI 点击登录的时候调用
|
|
|
+ IMCenter.getInstance().loginIM(this, imUserId, userIMToken);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onDestroy() {
|
|
|
+ super.onDestroy();
|
|
|
+ EventBus.getDefault().unregister(this);
|
|
|
+ IMCenter.getInstance().removeUnReadMessageObserver(mUnReadMessageObserver);
|
|
|
+ }
|
|
|
}
|