JumpUtils.java 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package com.cooleshow.base.utils;
  2. import android.text.TextUtils;
  3. import com.alibaba.android.arouter.launcher.ARouter;
  4. import com.cooleshow.base.bean.RouteBean;
  5. import com.cooleshow.base.common.BaseApplication;
  6. import com.cooleshow.base.common.WebConstants;
  7. import com.cooleshow.base.constanst.Constants;
  8. import com.cooleshow.base.constanst.RouteConstants;
  9. import com.cooleshow.base.router.RouterPath;
  10. import org.json.JSONObject;
  11. /**
  12. * Author by pq, Date on 2022/6/29.
  13. */
  14. public class JumpUtils {
  15. public static final String ACTION_H5 = "h5";
  16. public static final String ACTION_APP = "app";
  17. public static boolean jump(RouteBean routeBean) {
  18. if (routeBean == null) {
  19. return false;
  20. }
  21. try {
  22. String action = routeBean.action;
  23. if (TextUtils.equals(action, ACTION_APP)) {
  24. //跳转原生页面
  25. if (!TextUtils.isEmpty(routeBean.pageTag)) {
  26. if (TextUtils.equals(routeBean.pageTag, RouteConstants.PAGE_TAG_BUY_PRACTICE)) {
  27. //购买陪练课,跳转首页课表
  28. ARouter.getInstance().build(RouterPath.APPCenter.PATH_HOME)
  29. .withInt(Constants.MAIN_PAGE_SELECT_POTION_KEY, 1)
  30. .navigation();
  31. return true;
  32. }
  33. if (TextUtils.equals(routeBean.pageTag, RouteConstants.PAGE_TAG_EVALUATE)) {
  34. //跳转评价页面
  35. if (BaseApplication.Companion.isTeacherClient()) {
  36. ARouter.getInstance().build(RouterPath.CommentCenter.TEACHER_COURSE_COMMENT)
  37. .navigation();
  38. }
  39. }
  40. if (TextUtils.equals(routeBean.pageTag, RouteConstants.PAGE_TAG_HOMEWORK)) {
  41. //原生跳作业详情页面
  42. if (BaseApplication.Companion.isTeacherClient()) {
  43. //老师端 区分琴房课和陪练课
  44. String params = routeBean.params;
  45. if (!TextUtils.isEmpty(params)) {
  46. String courseId = getParams(params, "courseId");
  47. String studentId = getParams(params, "studentId");
  48. if (TextUtils.isEmpty(courseId) && TextUtils.isEmpty(studentId)) {
  49. ARouter.getInstance().build(RouterPath.WorkCenter.TEACHER_WORK_ASSIGN_HOMEWORK)
  50. .withString("course_id", courseId)
  51. .withString("student_id", studentId)
  52. .navigation();
  53. }
  54. }
  55. } else {
  56. //学生端直接跳作业详情页面
  57. String params = routeBean.params;
  58. if (!TextUtils.isEmpty(params)) {
  59. String courseId = getParams(params, "courseId");
  60. if (TextUtils.isEmpty(courseId)) {
  61. ARouter.getInstance().build(RouterPath.WorkCenter.STUDENT_HOMEWORK_DETAIL)
  62. .withString("course_id", courseId)
  63. .navigation();
  64. }
  65. }
  66. }
  67. }
  68. }
  69. } else {
  70. //跳转H5页面
  71. if (TextUtils.isEmpty(routeBean.url)) {
  72. return false;
  73. }
  74. ARouter.getInstance()
  75. .build(RouterPath.WebCenter.ACTIVITY_HTML)
  76. .withString(WebConstants.WEB_URL, routeBean.url)
  77. .navigation();
  78. return true;
  79. }
  80. } catch (Exception e) {
  81. e.printStackTrace();
  82. }
  83. return false;
  84. }
  85. private static String getParams(String paramsJson, String key) {
  86. try {
  87. JSONObject jsonObject = new JSONObject(paramsJson);
  88. return jsonObject.optString(key);
  89. } catch (Exception e) {
  90. e.printStackTrace();
  91. }
  92. return "";
  93. }
  94. }