Browse Source

学生端首页推荐达人增加关注

Pq 3 years ago
parent
commit
cf54957e1a

+ 5 - 0
BaseLibrary/src/main/java/com/cooleshow/base/constanst/Constants.java

@@ -23,4 +23,9 @@ public class Constants {
 
     public static final String MAIN_PAGE_SELECT_POTION_KEY = "select_position";
     public static final String ON_LIVING_TAG = "1";//1是直播中, 0否
+
+    public static final int STUDENT_FOCUS_TEACHER_STATUS_NORMAL = 0;//取消关注
+    public static final int STUDENT_FOCUS_TEACHER_STATUS_FOLLOW = 1;//关注
+
+
 }

+ 5 - 0
BaseLibrary/src/main/res/drawable/shape_2dc7aa_12dp.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android">
+    <solid android:color="@color/color_2dc7aa" />
+    <corners android:radius="12dp" />
+</shape>

+ 5 - 0
BaseLibrary/src/main/res/drawable/shape_border_f0f0f0_1dp.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<shape xmlns:android="http://schemas.android.com/apk/res/android">
+    <stroke android:color="@color/color_f0f0f0" android:width="1dp"/>
+    <corners android:radius="12dp"/>
+</shape>

+ 1 - 0
BaseLibrary/src/main/res/values/colors.xml

@@ -128,6 +128,7 @@
     <color name="color_30c7ab">#30c7ab</color>
     <color name="color_e630c7ab">#E630c7ab</color>
     <color name="color_effbf9">#EFFBF9</color>
+    <color name="color_f0f0f0">#f0f0f0</color>
 
     <color name="color_25292e">#25292E</color>
     <color name="color_F8F8F8">#F8F8F8</color>

+ 10 - 0
student/src/main/java/com/cooleshow/student/adapter/HomeRecommendTalentAdapter.java

@@ -4,6 +4,7 @@ import android.text.TextUtils;
 import android.view.View;
 import android.view.animation.Animation;
 import android.widget.ImageView;
+import android.widget.TextView;
 
 import com.airbnb.lottie.LottieAnimationView;
 import com.chad.library.adapter.base.BaseQuickAdapter;
@@ -21,6 +22,7 @@ public class HomeRecommendTalentAdapter extends BaseQuickAdapter<RecommendTalent
 
     public HomeRecommendTalentAdapter() {
         super(R.layout.item_home_recommend_talent_layot);
+        addChildClickViewIds(R.id.tv_focus);
     }
 
     @Override
@@ -44,6 +46,14 @@ public class HomeRecommendTalentAdapter extends BaseQuickAdapter<RecommendTalent
             view_live_anim.setVisibility(View.GONE);
             tv_live_tip.setVisibility(View.GONE);
         }
+        TextView tv_focus = holder.getView(R.id.tv_focus);
 
+        if (data.isFocus) {
+            tv_focus.setBackgroundResource(R.drawable.shape_border_f0f0f0_1dp);
+            tv_focus.setTextColor(getContext().getResources().getColor(R.color.color_999999));
+        } else {
+            tv_focus.setBackgroundResource(R.drawable.shape_2dc7aa_12dp);
+            tv_focus.setTextColor(getContext().getResources().getColor(R.color.white));
+        }
     }
 }

+ 9 - 3
student/src/main/java/com/cooleshow/student/api/APIService.java

@@ -387,8 +387,7 @@ public interface APIService {
      * 提交陪练课老师作业点评
      *
      * @param
-     * @return
-     * 学生端未用到此接口
+     * @return 学生端未用到此接口
      */
     @POST(TEACHER_GROUP + "homework/review")
     Observable<BaseResponse<Object>> submitSparringCourseHomeworkComment(@Body RequestBody body);
@@ -502,7 +501,6 @@ public interface APIService {
     Observable<BaseResponse<HomeHotMusicSheetBean>> getHotMusicSheetList(@Body RequestBody body);
 
 
-
     /**
      * app首页热门专辑
      *
@@ -518,4 +516,12 @@ public interface APIService {
      */
     @GET(STUDENT_GROUP + "liveRoom/queryTeacherLivingList")
     Observable<BaseResponse<ArrayList<TempLiveTeacherListBean>>> getTempLiveList();
+
+    /**
+     * 关注老师
+     *
+     * @return
+     */
+    @GET(STUDENT_GROUP + "teacher/starOrUnStar")
+    Observable<BaseResponse<Object>> followTeacher(@Query("starStatus") int starStatus, @Query("userId") String userId);
 }

+ 1 - 0
student/src/main/java/com/cooleshow/student/bean/RecommendTalentListBean.java

@@ -81,4 +81,5 @@ public class RecommendTalentListBean {
     public String username;
     public String videoDate;
     public String workUnit;
+    public boolean isFocus;
 }

+ 2 - 0
student/src/main/java/com/cooleshow/student/contract/HomeContract.java

@@ -45,6 +45,8 @@ public interface HomeContract {
         void getHotNewsSuccess(int page, HomeHotNewsBean homeHotNewsBean);
 
         void getHotNewsError(int page);
+
+        void followTeacherSuccess();
     }
 
     interface Presenter {

+ 16 - 0
student/src/main/java/com/cooleshow/student/presenter/main/HomePresenter.java

@@ -188,6 +188,7 @@ public class HomePresenter extends BasePresenter<HomeContract.HomeView> implemen
 
     /**
      * 获取热门资讯
+     *
      * @param page
      */
     public void getHotNewsPage(int page) {
@@ -224,6 +225,7 @@ public class HomePresenter extends BasePresenter<HomeContract.HomeView> implemen
 
     /**
      * 获取达人风采
+     *
      * @param page
      */
     public void getTalentStyle(int page) {
@@ -407,4 +409,18 @@ public class HomePresenter extends BasePresenter<HomeContract.HomeView> implemen
             }
         });
     }
+
+    /**
+     * 关注老师
+     */
+    public void followTeacher(int starStatus, String userId) {
+        addSubscribe(create(APIService.class).followTeacher(starStatus, userId), new BaseObserver<Object>(getView()) {
+            @Override
+            protected void onSuccess(Object data) {
+                if (null != getView()) {
+                    getView().followTeacherSuccess();
+                }
+            }
+        });
+    }
 }

+ 5 - 0
student/src/main/java/com/cooleshow/student/ui/main/HomeFragment.java

@@ -640,4 +640,9 @@ public class HomeFragment extends BaseMVPFragment<FragmentHomeLayoutBinding, Hom
     public void getHotNewsError(int page) {
 
     }
+
+    @Override
+    public void followTeacherSuccess() {
+
+    }
 }

+ 31 - 1
student/src/main/java/com/cooleshow/student/ui/main/NewHomeFragment.java

@@ -10,8 +10,10 @@ import android.widget.ImageView;
 import com.alibaba.android.arouter.launcher.ARouter;
 import com.bumptech.glide.Glide;
 import com.chad.library.adapter.base.BaseQuickAdapter;
+import com.chad.library.adapter.base.listener.OnItemChildClickListener;
 import com.chad.library.adapter.base.listener.OnItemClickListener;
 import com.cooleshow.base.common.WebConstants;
+import com.cooleshow.base.constanst.Constants;
 import com.cooleshow.base.router.RouterPath;
 import com.cooleshow.base.ui.fragment.BaseMVPFragment;
 import com.cooleshow.base.utils.SizeUtils;
@@ -161,7 +163,7 @@ public class NewHomeFragment extends BaseMVPFragment<FragmentNewHomeLayoutBindin
         mViewBinding.recyclerviewRecommendTalent.addItemDecoration(commonItemDecoration);
         mViewBinding.recyclerviewRecommendTalent.setAdapter(mRecommendTalentAdapter);
 
-        LinearLayoutManager videoCourseManager = new LinearLayoutManager(getContext(),LinearLayoutManager.HORIZONTAL,false);
+        LinearLayoutManager videoCourseManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
         mViewBinding.rvVideoCourse.setLayoutManager(videoCourseManager);
         mHomeVideoCourseAdapter = new NewHomeVideoCourseAdapter();
         CommonItemDecoration videoListItemDecoration = new CommonItemDecoration(SizeUtils.dp2px(12), 0, 0, SizeUtils.dp2px(10), 0);
@@ -221,6 +223,22 @@ public class NewHomeFragment extends BaseMVPFragment<FragmentNewHomeLayoutBindin
     }
 
     private void initListener() {
+        mRecommendTalentAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
+            @Override
+            public void onItemChildClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
+                if (view.getId() == R.id.tv_focus) {
+                    //关注
+                    if (position < mRecommendTalentAdapter.getData().size()) {
+                        RecommendTalentListBean data = mRecommendTalentAdapter.getData().get(position);
+                        if (presenter != null) {
+                            presenter.followTeacher(data.isFocus ? Constants.STUDENT_FOCUS_TEACHER_STATUS_NORMAL : Constants.STUDENT_FOCUS_TEACHER_STATUS_FOLLOW, String.valueOf(data.userId));
+                        }
+                    }
+                }
+            }
+        });
+
+
         mViewBinding.viewPagerBottom.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
             @Override
             public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
@@ -631,6 +649,18 @@ public class NewHomeFragment extends BaseMVPFragment<FragmentNewHomeLayoutBindin
     }
 
     @Override
+    public void followTeacherSuccess() {
+        //关注老师成功
+        if (isDetached()) {
+            return;
+        }
+        //获取推荐达人列表
+        if (presenter != null) {
+            presenter.getRecommendTalentList();
+        }
+    }
+
+    @Override
     public void onClick(View v) {
         int id = v.getId();
 

+ 17 - 1
student/src/main/res/layout/item_home_recommend_talent_layot.xml

@@ -5,7 +5,7 @@
     android:layout_width="110dp"
     android:layout_height="wrap_content"
     android:background="@drawable/shape_10dp_white"
-    android:paddingBottom="16dp">
+    android:paddingBottom="11dp">
 
     <de.hdodenhof.circleimageview.CircleImageView
         android:id="@+id/iv_avatar"
@@ -92,4 +92,20 @@
         app:lottie_loop="true"
         app:lottie_rawRes="@raw/home_recommend_talent_anim" />
 
+
+    <TextView
+        android:id="@+id/tv_focus"
+        android:layout_width="58dp"
+        android:layout_height="24dp"
+        android:layout_marginTop="9dp"
+        android:background="@drawable/shape_2dc7aa_12dp"
+        android:gravity="center"
+        android:text="关注"
+        android:textColor="@color/white"
+        android:textSize="@dimen/sp_12"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintRight_toRightOf="parent"
+        app:layout_constraintTop_toBottomOf="@+id/tv_tip" />
+
+
 </androidx.constraintlayout.widget.ConstraintLayout>