瀏覽代碼

修改老师端我收到的评价页面数据异常问题

Pq 3 年之前
父節點
當前提交
0593c3da7f

+ 3 - 0
BaseLibrary/src/main/java/com/cooleshow/base/ui/activity/BaseActivity.java

@@ -10,6 +10,7 @@ import com.cooleshow.base.common.AppManager;
 import com.cooleshow.base.data.net.ApiException;
 import com.cooleshow.base.presenter.view.BaseView;
 import com.cooleshow.base.utils.ToastUtils;
+import com.cooleshow.base.utils.helper.ErrorParse;
 import com.cooleshow.base.utils.helper.QMUIStatusBarHelper;
 import com.cooleshow.base.widgets.ProgressLoading;
 import com.trello.rxlifecycle4.components.support.RxAppCompatActivity;
@@ -83,7 +84,9 @@ public abstract class BaseActivity<V extends ViewBinding> extends RxAppCompatAct
 
     @Override
     public void onError(@NonNull Throwable throwable) {
+        throwable.printStackTrace();
         if (throwable instanceof ApiException) {
+            ErrorParse.getInstance().parseError(throwable);
             ApiException apiException = (ApiException) throwable;
             ToastUtils.showShort("onError:" + apiException.getErrmsg());
         }

+ 3 - 0
BaseLibrary/src/main/java/com/cooleshow/base/ui/fragment/BaseFragment.java

@@ -15,6 +15,7 @@ import com.cooleshow.base.R;
 import com.cooleshow.base.presenter.view.BaseView;
 import com.cooleshow.base.utils.LogUtils;
 import com.cooleshow.base.utils.ToastUtils;
+import com.cooleshow.base.utils.helper.ErrorParse;
 import com.cooleshow.base.widgets.ProgressLoading;
 
 import androidx.annotation.NonNull;
@@ -105,6 +106,8 @@ public abstract class BaseFragment<V extends ViewBinding> extends Fragment imple
 
     @Override
     public void onError(@NonNull Throwable throwable) {
+        throwable.printStackTrace();
+        ErrorParse.getInstance().parseError(throwable);
         LogUtils.e("onError:" + throwable.getMessage());
         ToastUtils.showShort("onError:" + throwable.getMessage());
     }

+ 46 - 0
BaseLibrary/src/main/java/com/cooleshow/base/utils/helper/ErrorParse.java

@@ -0,0 +1,46 @@
+package com.cooleshow.base.utils.helper;
+
+import com.alibaba.android.arouter.launcher.ARouter;
+import com.cooleshow.base.data.net.ApiException;
+import com.cooleshow.base.router.RouterPath;
+import com.cooleshow.base.utils.ToastUtils;
+
+/**
+ * Author by pq, Date on 2022/5/9.
+ */
+public class ErrorParse {
+    private static volatile ErrorParse mErrorParse;
+    public static int TOKEN_INVALID_ERROR_CODE = 403;//token异常
+
+    private ErrorParse() {
+    }
+
+    public static ErrorParse getInstance() {
+        if (mErrorParse == null) {
+            synchronized (ErrorParse.class) {
+                if (mErrorParse == null) {
+                    mErrorParse = new ErrorParse();
+                }
+            }
+        }
+        return mErrorParse;
+    }
+
+    public void parseError(Throwable throwable) {
+        if (throwable instanceof ApiException) {
+            ApiException apiException = (ApiException) throwable;
+            ToastUtils.showShort("onError:" + apiException.getErrmsg());
+            if (apiException.getErrcode() == TOKEN_INVALID_ERROR_CODE) {
+                logOut();
+                return;
+            }
+        } else {
+            throwable.printStackTrace();
+            ToastUtils.showShort("未知错误");
+        }
+    }
+
+    private void logOut() {
+        ARouter.getInstance().build(RouterPath.UserCenter.PATH_VERIFY_LOGIN).navigation();
+    }
+}

+ 11 - 1
teacher/src/main/java/com/cooleshow/teacher/adapter/ReceivedCommentListAdapter.java

@@ -1,5 +1,6 @@
 package com.cooleshow.teacher.adapter;
 
+import android.text.TextUtils;
 import android.widget.ImageView;
 import android.widget.RatingBar;
 
@@ -37,7 +38,16 @@ public class ReceivedCommentListAdapter extends BaseQuickAdapter<ReceivedComment
         holder.setText(R.id.tv_comment_content, bean.studentReplied);
         //评分
         RatingBar ratingBar = holder.getView(R.id.rating_bar_for_student);
-        ratingBar.setRating(bean.score);
+        int rating = 0;
+        if (!TextUtils.isEmpty(bean.score)) {
+            try {
+                rating = Integer.parseInt(bean.score);
+            } catch (Exception e) {
+                e.printStackTrace();
+                rating = 0;
+            }
+        }
+        ratingBar.setRating(rating);
     }
 
     @NonNull

+ 1 - 1
teacher/src/main/java/com/cooleshow/teacher/bean/ReceivedCommentListBean.java

@@ -90,7 +90,7 @@ public class ReceivedCommentListBean {
         public int courseId;
         public String endTime;
         public String realName;
-        public int score;
+        public String score;
         public String startTime;
         public String studentReplied;
         public int subjectId;

+ 0 - 1
teacher/src/main/java/com/cooleshow/teacher/presenter/comment/ReceivedCommentPresenter.java

@@ -26,7 +26,6 @@ public class ReceivedCommentPresenter extends BasePresenter<ReceivedCommentContr
         JSONObject jsonObject = new JSONObject();
         try {
             jsonObject.putOpt("classDate", month);
-//            jsonObject.putOpt("classMonth", month);
             jsonObject.putOpt("page", page);
             if (!TextUtils.isEmpty(studentName)) {
                 jsonObject.putOpt("studentName", studentName);

+ 1 - 0
usercenter/src/main/AndroidManifest.xml

@@ -14,6 +14,7 @@
 
         <activity
             android:name=".ui.activity.VerifyCodeLoginActivity"
+            android:launchMode="singleTask"
             android:configChanges="orientation|screenSize|keyboardHidden"
             android:screenOrientation="portrait" />
         <activity

+ 15 - 0
usercenter/src/main/java/com/cooleshow/usercenter/helper/UserHelper.java

@@ -106,4 +106,19 @@ public class UserHelper {
         }
         return Utils.getApp().getString(R.string.nickname_fill_str, id);
     }
+
+    public static void clearUserInfo() {
+        //userId
+        SPUtils.getInstance().put(USER_ID, "");
+        //token
+        SPUtils.getInstance().put(USER_TOKEN_KEY, "");
+        //昵称
+        SPUtils.getInstance().put(USERNAME, "");
+        //imtoken
+        SPUtils.getInstance().put(USER_IM_TOKEN, "");
+        //电话
+        SPUtils.getInstance().put(USER_PHONE, "");
+        //头像
+        SPUtils.getInstance().put(USER_AVATAR, "");
+    }
 }

+ 8 - 0
usercenter/src/main/java/com/cooleshow/usercenter/ui/activity/VerifyCodeLoginActivity.java

@@ -12,6 +12,7 @@ import android.view.View;
 import com.alibaba.android.arouter.facade.annotation.Route;
 import com.alibaba.android.arouter.launcher.ARouter;
 import com.cooleshow.base.common.WebConstants;
+import com.cooleshow.base.data.net.CommonParamsHelper;
 import com.cooleshow.base.router.RouterPath;
 import com.cooleshow.base.ui.activity.BaseMVPActivity;
 import com.cooleshow.base.utils.SpannableStringUtils;
@@ -20,6 +21,7 @@ import com.cooleshow.usercenter.R;
 import com.cooleshow.usercenter.UserConstants;
 import com.cooleshow.usercenter.databinding.ActivityVerifyCodeLoginBinding;
 import com.cooleshow.usercenter.helper.PhoneCheckHelper;
+import com.cooleshow.usercenter.helper.UserHelper;
 import com.cooleshow.usercenter.presenter.VerifyLoginPresenter;
 
 import androidx.annotation.NonNull;
@@ -51,6 +53,12 @@ public class VerifyCodeLoginActivity extends BaseMVPActivity<ActivityVerifyCodeL
         setPrivacyText();
     }
 
+    @Override
+    public void initData() {
+        super.initData();
+        UserHelper.clearUserInfo();
+        CommonParamsHelper.getInstance().clear();
+    }
 
     @Override
     protected VerifyLoginPresenter createPresenter() {