|
@@ -1,10 +1,174 @@
|
|
|
package com.cooleshow.student.ui.main;
|
|
|
|
|
|
+import android.os.Bundle;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.view.MenuItem;
|
|
|
+
|
|
|
+import androidx.annotation.NonNull;
|
|
|
+import androidx.annotation.Nullable;
|
|
|
+import androidx.fragment.app.Fragment;
|
|
|
+
|
|
|
+import com.alibaba.android.arouter.facade.annotation.Route;
|
|
|
+import com.common.im.ui.MessageFragment;
|
|
|
+import com.cooleshow.base.router.RouterPath;
|
|
|
+import com.cooleshow.base.ui.activity.BaseMVPActivity;
|
|
|
+import com.cooleshow.base.utils.LogUtils;
|
|
|
+import com.cooleshow.base.utils.helper.QMUIStatusBarHelper;
|
|
|
+import com.cooleshow.student.R;
|
|
|
+import com.cooleshow.student.adapter.HomePageAdapter;
|
|
|
+import com.cooleshow.student.contract.MainContract;
|
|
|
+import com.cooleshow.student.databinding.ActivityMainBinding;
|
|
|
+import com.cooleshow.student.presenter.main.MainPresenter;
|
|
|
+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.BottomNavigationView;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+
|
|
|
+import io.rong.imlib.RongIMClient;
|
|
|
+
|
|
|
/**
|
|
|
* 创建日期:2022/5/25 18:02
|
|
|
*
|
|
|
* @author Ryan
|
|
|
* 类说明:
|
|
|
*/
|
|
|
-public class MainActivity {
|
|
|
+@Route(path = RouterPath.APPCenter.PATH_HOME)
|
|
|
+public class MainActivity extends BaseMVPActivity<ActivityMainBinding, MainPresenter> implements MainContract.MainView {
|
|
|
+ private ArrayList<Fragment> mFragments = new ArrayList<>();
|
|
|
+ private HomeFragment mHomeFragment;
|
|
|
+ private MineFragment mMineFragment;
|
|
|
+ private ShopMallFragment shopMallFragment;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+ QMUIStatusBarHelper.setStatusBarLightMode(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void initView() {
|
|
|
+ HomePageAdapter homePageAdapter = new HomePageAdapter(this);
|
|
|
+ mHomeFragment = new HomeFragment();
|
|
|
+ CourseTableFragment courseTableFragment = new CourseTableFragment();
|
|
|
+ MessageFragment messageFragment = new MessageFragment();
|
|
|
+ shopMallFragment = new ShopMallFragment();
|
|
|
+ mMineFragment = new MineFragment();
|
|
|
+ mFragments.add(mHomeFragment);
|
|
|
+ mFragments.add(courseTableFragment);
|
|
|
+ mFragments.add(messageFragment);
|
|
|
+ mFragments.add(shopMallFragment);
|
|
|
+ mFragments.add(mMineFragment);
|
|
|
+ homePageAdapter.setFragments(mFragments);
|
|
|
+ getViewBinding().viewPager.setAdapter(homePageAdapter);
|
|
|
+ getViewBinding().viewPager.setOffscreenPageLimit(mFragments.size());
|
|
|
+ getViewBinding().viewPager.setUserInputEnabled(false);
|
|
|
+ getViewBinding().navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
|
|
|
+ @Override
|
|
|
+ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
|
|
+ return onTabClick(item.getItemId());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onBackPressed() {
|
|
|
+ int currentItem = getViewBinding().viewPager.getCurrentItem();
|
|
|
+ if (currentItem == 3) {
|
|
|
+ //商城
|
|
|
+ if (null!=shopMallFragment){
|
|
|
+// shopMallFragment.clickBack();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ super.onBackPressed();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void clickBackPressed(){
|
|
|
+ super.onBackPressed();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void initData() {
|
|
|
+ super.initData();
|
|
|
+ connectIM();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 连接rong IM
|
|
|
+ */
|
|
|
+ private void connectIM() {
|
|
|
+ if (UserHelper.isLogin()) {
|
|
|
+ String userIMToken = UserHelper.getUserIMToken();
|
|
|
+ if (!TextUtils.isEmpty(userIMToken)) {
|
|
|
+ RongIMClient.ConnectionStatusListener.ConnectionStatus currentConnectionStatus = RongIMClient.getInstance().getCurrentConnectionStatus();
|
|
|
+ if (currentConnectionStatus != RongIMClient.ConnectionStatusListener.ConnectionStatus.CONNECTED) {
|
|
|
+ IMManager.getInstance().login(userIMToken, new ResultCallback<String>() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(String s) {
|
|
|
+ LogUtils.i("im connect success:" + s);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFail(int errorCode, String errorStr) {
|
|
|
+ LogUtils.i("im connect fail:" + errorStr + "-errorCode:" + errorCode);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private boolean onTabClick(int viewId) {
|
|
|
+ if (viewId == R.id.menu_home) {
|
|
|
+ getViewBinding().viewPager.setCurrentItem(0, false);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (viewId == R.id.menu_coursetable) {
|
|
|
+ getViewBinding().viewPager.setCurrentItem(1, false);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (viewId == R.id.menu_chat) {
|
|
|
+ getViewBinding().viewPager.setCurrentItem(2, false);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (viewId == R.id.menu_mall) {
|
|
|
+ getViewBinding().viewPager.setCurrentItem(3, false);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if (viewId == R.id.menu_mine) {
|
|
|
+ getViewBinding().viewPager.setCurrentItem(4, false);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ protected void onResume() {
|
|
|
+ super.onResume();
|
|
|
+ presenter.getUserInfo();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getUserInfoSuccess(UserInfo userInfo) {
|
|
|
+ if (isFinishing() || isDestroyed()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //存储userInfo信息
|
|
|
+ UserHelper.saveUserInfo(userInfo);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected ActivityMainBinding getLayoutView() {
|
|
|
+ return ActivityMainBinding.inflate(getLayoutInflater());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected MainPresenter createPresenter() {
|
|
|
+ return new MainPresenter();
|
|
|
+ }
|
|
|
}
|