Forráskód Böngészése

增加学生端新首页UI(达人风采相关逻辑)

Pq 2 éve
szülő
commit
3abdd53552

+ 67 - 0
student/src/main/java/com/cooleshow/student/adapter/HomeTalentStyleAdapter.java

@@ -0,0 +1,67 @@
+package com.cooleshow.student.adapter;
+
+import android.text.TextUtils;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import com.chad.library.adapter.base.BaseQuickAdapter;
+import com.chad.library.adapter.base.viewholder.BaseViewHolder;
+import com.cooleshow.base.utils.GlideUtils;
+import com.cooleshow.base.utils.SizeUtils;
+import com.cooleshow.student.R;
+import com.cooleshow.student.bean.HomeStyleBean;
+
+import org.w3c.dom.Text;
+
+import androidx.annotation.NonNull;
+import androidx.constraintlayout.widget.ConstraintLayout;
+
+/**
+ * Author by pq, Date on 2022/8/30.
+ */
+public class HomeTalentStyleAdapter extends BaseQuickAdapter<HomeStyleBean.RowsBean, BaseViewHolder> {
+    private int long_img_height = 0;
+    private int normal_img_height = 0;
+
+    public HomeTalentStyleAdapter() {
+        super(R.layout.item_home_talent_style_layout);
+        long_img_height = SizeUtils.dp2px(222);
+        normal_img_height = SizeUtils.dp2px(168);
+    }
+
+    @Override
+    protected void convert(@NonNull BaseViewHolder holder, HomeStyleBean.RowsBean data) {
+        ImageView coverImagView = holder.getView(R.id.iv_cover);
+        ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams) coverImagView.getLayoutParams();
+        int position = holder.getLayoutPosition();
+        if (position == 0) {
+            layoutParams.height = long_img_height;
+        } else {
+            layoutParams.height = normal_img_height;
+        }
+        coverImagView.setLayoutParams(layoutParams);
+        boolean isLiving = TextUtils.equals(data.liveing, "1");
+        //封面
+        GlideUtils.INSTANCE.loadImage(getContext(), isLiving ? data.coverPic : data.cover, coverImagView, com.cooleshow.base.R.drawable.bg_video_placeholder);
+        //直播标题
+        TextView tv_title = holder.getView(R.id.tv_title);
+        tv_title.setVisibility(isLiving ? View.VISIBLE : View.GONE);
+        tv_title.setText(data.liveTitle);
+
+        //头像
+        ImageView iv_avatar = holder.getView(R.id.iv_avatar);
+        GlideUtils.INSTANCE.loadImage(getContext(), data.avatar, iv_avatar, R.drawable.icon_teacher_default_head);
+        //昵称
+        holder.setText(R.id.tv_name, data.username);
+        TextView tv_tip = holder.getView(R.id.tv_tip);
+        if (isLiving) {
+            tv_tip.setText("正在直播");
+            tv_tip.setTextColor(getContext().getResources().getColor(com.cooleshow.base.R.color.color_ff0000));
+        } else {
+            tv_tip.setText(String.format("%d人观看", data.browse));
+            tv_tip.setTextColor(getContext().getResources().getColor(com.cooleshow.base.R.color.color_999999));
+        }
+    }
+}

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

@@ -34,6 +34,7 @@ import com.cooleshow.student.bean.SparringCourseHomeworkBean;
 import com.cooleshow.student.bean.StudentUserInfo;
 import com.cooleshow.student.bean.SystemMessageBean;
 import com.cooleshow.student.bean.TeachableInstrumentBean;
+import com.cooleshow.student.bean.TempLiveTeacherListBean;
 import com.cooleshow.student.bean.VideoCourseListBean;
 import com.cooleshow.usercenter.bean.SetDetailBean;
 import com.cooleshow.usercenter.bean.UserInfo;
@@ -498,4 +499,12 @@ public interface APIService {
      */
     @GET(STUDENT_GROUP + "teacher/queryHotTeacherList")
     Observable<BaseResponse<ArrayList<RecommendTalentListBean>>> getRecommendTalentList();
+
+    /**
+     * 获取临时直播老师列表
+     *
+     * @return
+     */
+    @GET(STUDENT_GROUP + "liveRoom/queryTeacherLivingList")
+    Observable<BaseResponse<ArrayList<TempLiveTeacherListBean>>> getTempLiveList();
 }

+ 4 - 0
student/src/main/java/com/cooleshow/student/bean/HomeStyleBean.java

@@ -56,5 +56,9 @@ public class HomeStyleBean {
         public long verifyUserId;
         public String videoUrl;
         public String cover;
+        public String coverPic;
+        public String liveCoverImg;
+        public String liveTitle;
+        public String roomUid;
     }
 }

+ 23 - 0
student/src/main/java/com/cooleshow/student/bean/TempLiveTeacherListBean.java

@@ -0,0 +1,23 @@
+package com.cooleshow.student.bean;
+
+/**
+ * Author by pq, Date on 2022/8/30.
+ */
+public class TempLiveTeacherListBean {
+
+    /**
+     * avatar :
+     * liveCoverImg :
+     * liveTitle :
+     * roomUid :
+     * teacherId : 0
+     * username :
+     */
+
+    public String avatar;
+    public String liveCoverImg;
+    public String liveTitle;
+    public String roomUid;
+    public String teacherId;
+    public String username;
+}

+ 114 - 4
student/src/main/java/com/cooleshow/student/presenter/main/HomePresenter.java

@@ -1,6 +1,10 @@
 package com.cooleshow.student.presenter.main;
 
+import android.text.TextUtils;
+import android.util.Log;
+
 import com.cooleshow.base.constanst.Constants;
+import com.cooleshow.base.data.net.BaseResponse;
 import com.cooleshow.base.presenter.BasePresenter;
 import com.cooleshow.base.rx.BaseObserver;
 import com.cooleshow.base.utils.RequestBodyUtil;
@@ -14,6 +18,7 @@ import com.cooleshow.student.bean.HomeStyleBean;
 import com.cooleshow.student.bean.HotAlbumBean;
 import com.cooleshow.student.bean.RecommendTalentListBean;
 import com.cooleshow.student.bean.StudentUserInfo;
+import com.cooleshow.student.bean.TempLiveTeacherListBean;
 import com.cooleshow.student.contract.HomeContract;
 
 import org.json.JSONException;
@@ -22,6 +27,17 @@ import org.json.JSONObject;
 import java.util.ArrayList;
 import java.util.List;
 
+import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
+import io.reactivex.rxjava3.annotations.NonNull;
+import io.reactivex.rxjava3.core.Observable;
+import io.reactivex.rxjava3.core.ObservableEmitter;
+import io.reactivex.rxjava3.core.ObservableOnSubscribe;
+import io.reactivex.rxjava3.core.ObservableSource;
+import io.reactivex.rxjava3.core.Observer;
+import io.reactivex.rxjava3.disposables.Disposable;
+import io.reactivex.rxjava3.functions.Function;
+import io.reactivex.rxjava3.schedulers.Schedulers;
+
 /**
  * 创建日期:2022/5/26 10:09
  *
@@ -180,6 +196,102 @@ public class HomePresenter extends BasePresenter<HomeContract.HomeView> implemen
         });
     }
 
+
+    public void getTalentStyle() {
+        JSONObject jsonObject = new JSONObject();
+        try {
+            jsonObject.putOpt("platform", "android");
+            jsonObject.putOpt("version", "1");
+            jsonObject.putOpt("page", 1);
+            jsonObject.putOpt("rows", Constants.DEFAULT_DATA_SIZE);
+        } catch (JSONException e) {
+            e.printStackTrace();
+        }
+        Observable<BaseResponse<HomeStyleBean>> observable = create(APIService.class).getStylePage(RequestBodyUtil.convertToRequestBodyJson(jsonObject.toString()));
+        Observable<BaseResponse<ArrayList<TempLiveTeacherListBean>>> tempLiveObservable = create(APIService.class).getTempLiveList();
+        tempLiveObservable.flatMap(new Function<BaseResponse<ArrayList<TempLiveTeacherListBean>>, ObservableSource<BaseResponse<HomeStyleBean>>>() {
+            @Override
+            public ObservableSource<BaseResponse<HomeStyleBean>> apply(BaseResponse<ArrayList<TempLiveTeacherListBean>> arrayListBaseResponse) throws Throwable {
+                return observable.map(new Function<BaseResponse<HomeStyleBean>, BaseResponse<HomeStyleBean>>() {
+                    @Override
+                    public BaseResponse<HomeStyleBean> apply(BaseResponse<HomeStyleBean> homeStyleBeanBaseResponse) throws Throwable {
+                        Log.i("pq", "匹配直播线程:" + Thread.currentThread().getName());
+                        if (arrayListBaseResponse != null) {
+                            ArrayList<TempLiveTeacherListBean> data = arrayListBaseResponse.getData();
+                            if (data != null && data.size() > 0) {
+                                for (int i = 0; i < data.size(); i++) {
+                                    TempLiveTeacherListBean tempLiveTeacherListBean = data.get(i);
+                                    if (homeStyleBeanBaseResponse != null && homeStyleBeanBaseResponse.getData() != null && homeStyleBeanBaseResponse.getData().rows != null && homeStyleBeanBaseResponse.getData().rows.size() > 0) {
+                                        for (int j = 0; j < homeStyleBeanBaseResponse.getData().rows.size(); j++) {
+                                            HomeStyleBean.RowsBean rowsBean = homeStyleBeanBaseResponse.getData().rows.get(j);
+                                            if (TextUtils.equals(tempLiveTeacherListBean.teacherId, String.valueOf(rowsBean.id))) {
+                                                Log.i("pq", "匹配直播老师id:" + tempLiveTeacherListBean.teacherId);
+                                                rowsBean.liveCoverImg = tempLiveTeacherListBean.liveCoverImg;
+                                                rowsBean.liveTitle = tempLiveTeacherListBean.liveTitle;
+                                                rowsBean.roomUid = tempLiveTeacherListBean.roomUid;
+                                            }
+                                        }
+                                    }
+                                }
+                            } else {
+                                Log.i("pq", "直播列表为空");
+                            }
+                        }
+                        return homeStyleBeanBaseResponse;
+                    }
+                });
+            }
+        }).subscribeOn(Schedulers.newThread())
+                .observeOn(AndroidSchedulers.mainThread())
+                .subscribe(new Observer<BaseResponse<HomeStyleBean>>() {
+                    @Override
+                    public void onSubscribe(@NonNull Disposable d) {
+
+                    }
+
+                    @Override
+                    public void onNext(@NonNull BaseResponse<HomeStyleBean> homeStyleBeanBaseResponse) {
+                        if (getView() != null && homeStyleBeanBaseResponse != null) {
+                            getView().getStylePageSuccess(homeStyleBeanBaseResponse.getData());
+                        }
+                    }
+
+                    @Override
+                    public void onError(@NonNull Throwable e) {
+                        if (getView() != null) {
+                            getView().onError(e);
+                            getView().hideLoading();
+                        }
+                    }
+
+                    @Override
+                    public void onComplete() {
+                        if (getView() != null) {
+                            getView().hideLoading();
+                        }
+                    }
+                });
+        //        addSubscribe(create(APIService.class).getStylePage(RequestBodyUtil.convertToRequestBodyJson(jsonObject.toString())), new BaseObserver<HomeStyleBean>(getView()) {
+//            @Override
+//            protected void onSuccess(HomeStyleBean data) {
+//                if (getView() != null) {
+//                    getView().getStylePageSuccess(data);
+//                }
+//            }
+//
+//            @Override
+//            public void onComplete() {
+//                super.onComplete();
+//            }
+//
+//            @Override
+//            public void onError(Throwable e) {
+//                super.onError(e);
+//
+//            }
+//        });
+    }
+
     public void queryUserInfo() {
         addSubscribe(create(APIService.class).queryUserInfo(), new BaseObserver<StudentUserInfo>(getView()) {
             @Override
@@ -192,8 +304,6 @@ public class HomePresenter extends BasePresenter<HomeContract.HomeView> implemen
     }
 
 
-
-
     public void queryCountOfUnread() {
 
         addSubscribe(create(APIService.class).queryCountOfUnread(), new BaseObserver<List<CountOfUnreadBean>>(getView()) {
@@ -210,7 +320,7 @@ public class HomePresenter extends BasePresenter<HomeContract.HomeView> implemen
     /**
      * 获取热门曲目
      */
-    public void getHotMusicSheetList(){
+    public void getHotMusicSheetList() {
         if (getView() != null) {
             getView().showLoading();
         }
@@ -233,7 +343,7 @@ public class HomePresenter extends BasePresenter<HomeContract.HomeView> implemen
     /**
      * 获取推荐达人列表
      */
-    public void getRecommendTalentList(){
+    public void getRecommendTalentList() {
         addSubscribe(create(APIService.class).getRecommendTalentList(), new BaseObserver<ArrayList<RecommendTalentListBean>>(getView()) {
             @Override
             protected void onSuccess(ArrayList<RecommendTalentListBean> data) {

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

@@ -272,6 +272,7 @@ public class NewHomeFragment extends BaseMVPFragment<FragmentNewHomeLayoutBindin
         if (presenter != null) {
             presenter.appHome();
             presenter.queryLiveAndVideo();
+            presenter.getTalentStyle();
         }
     }
 

+ 45 - 0
student/src/main/java/com/cooleshow/student/ui/main/TalentStyleFragment.java

@@ -0,0 +1,45 @@
+package com.cooleshow.student.ui.main;
+
+import android.view.View;
+
+import com.cooleshow.base.ui.fragment.BaseFragment;
+import com.cooleshow.student.adapter.HomeTalentStyleAdapter;
+import com.cooleshow.student.bean.HomeStyleBean;
+import com.cooleshow.student.databinding.FragmentHomeTalentLayoutBinding;
+
+import java.util.ArrayList;
+
+import androidx.recyclerview.widget.RecyclerView;
+import androidx.recyclerview.widget.StaggeredGridLayoutManager;
+
+/**
+ * Author by pq, Date on 2022/8/30.
+ */
+public class TalentStyleFragment extends BaseFragment<FragmentHomeTalentLayoutBinding> {
+    RecyclerView recyclerView;
+    private HomeTalentStyleAdapter mTalentStyleAdapter;
+
+    @Override
+    protected FragmentHomeTalentLayoutBinding getLayoutView() {
+        return FragmentHomeTalentLayoutBinding.inflate(getLayoutInflater());
+    }
+
+    @Override
+    protected void initView(View rootView) {
+        recyclerView = mViewBinding.recyclerView;
+    }
+
+    @Override
+    protected void initData() {
+        StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
+        recyclerView.setLayoutManager(staggeredGridLayoutManager);
+        mTalentStyleAdapter = new HomeTalentStyleAdapter();
+        recyclerView.setAdapter(mTalentStyleAdapter);
+    }
+
+    public void setData(ArrayList<HomeStyleBean.RowsBean> data) {
+        if (mTalentStyleAdapter != null) {
+            mTalentStyleAdapter.setNewInstance(data);
+        }
+    }
+}

+ 12 - 0
student/src/main/res/layout/fragment_home_talent_layout.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+    <androidx.recyclerview.widget.RecyclerView
+        android:id="@+id/recyclerView"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:overScrollMode="never"
+        android:scrollbars="none" />
+</FrameLayout>

+ 74 - 0
student/src/main/res/layout/item_home_talent_style_layout.xml

@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:background="@drawable/bg_white_10dp"
+    android:paddingBottom="14dp">
+
+    <androidx.constraintlayout.utils.widget.ImageFilterButton
+        android:id="@+id/iv_cover"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:minHeight="100dp"
+        android:scaleType="centerCrop"
+        app:layout_constraintTop_toTopOf="parent" />
+
+    <TextView
+        android:id="@+id/tv_title"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_marginTop="7dp"
+        android:ellipsize="end"
+        android:includeFontPadding="false"
+        android:maxLines="2"
+        android:paddingStart="11dp"
+        android:paddingEnd="11dp"
+        android:textColor="@color/color_333333"
+        android:textSize="@dimen/sp_14"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintRight_toRightOf="parent"
+        app:layout_constraintTop_toBottomOf="@+id/iv_cover"
+        tools:text="长笛练习过程中的小技巧-换气法" />
+
+    <de.hdodenhof.circleimageview.CircleImageView
+        android:id="@+id/iv_avatar"
+        android:layout_width="16dp"
+        android:layout_height="16dp"
+        android:layout_marginStart="11dp"
+        android:layout_marginTop="13dp"
+        app:layout_constraintLeft_toLeftOf="parent"
+        app:layout_constraintTop_toBottomOf="@+id/tv_title" />
+
+
+    <TextView
+        android:id="@+id/tv_name"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_marginStart="5dp"
+        android:layout_marginEnd="5dp"
+        android:ellipsize="end"
+        android:includeFontPadding="false"
+        android:maxLines="1"
+        android:textColor="@color/color_333333"
+        android:textSize="@dimen/sp_12"
+        app:layout_constraintBottom_toBottomOf="@+id/iv_avatar"
+        app:layout_constraintLeft_toRightOf="@+id/iv_avatar"
+        app:layout_constraintRight_toLeftOf="@+id/tv_tip"
+        app:layout_constraintTop_toTopOf="@+id/iv_avatar"
+        tools:text="酷乐秀官方" />
+
+    <TextView
+        android:id="@+id/tv_tip"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_marginEnd="11dp"
+        android:includeFontPadding="false"
+        android:textColor="@color/color_999999"
+        android:textSize="@dimen/sp_12"
+        app:layout_constraintBottom_toBottomOf="@+id/iv_avatar"
+        app:layout_constraintRight_toRightOf="parent"
+        app:layout_constraintTop_toTopOf="@+id/iv_avatar"
+        tools:text="1112人观看" />
+</androidx.constraintlayout.widget.ConstraintLayout>