|
@@ -1,25 +1,58 @@
|
|
|
package com.cooleshow.institution.stu.ui.main;
|
|
|
|
|
|
+import android.text.TextUtils;
|
|
|
import android.view.View;
|
|
|
|
|
|
+import com.alibaba.android.arouter.launcher.ARouter;
|
|
|
+import com.bumptech.glide.Glide;
|
|
|
+import com.cooleshow.base.common.WebConstants;
|
|
|
+import com.cooleshow.base.router.RouterPath;
|
|
|
import com.cooleshow.base.ui.activity.BaseMVPActivity;
|
|
|
import com.cooleshow.base.ui.fragment.BaseMVPFragment;
|
|
|
+import com.cooleshow.base.utils.SizeUtils;
|
|
|
import com.cooleshow.base.utils.Utils;
|
|
|
import com.cooleshow.institution.stu.R;
|
|
|
+import com.cooleshow.institution.stu.adapter.HomeHotAlbumAdapter;
|
|
|
+import com.cooleshow.institution.stu.adapter.HomeHotMusicSheetAdapter;
|
|
|
+import com.cooleshow.institution.stu.bean.AppHomeBean;
|
|
|
+import com.cooleshow.institution.stu.bean.HomeHotMusicSheetBean;
|
|
|
+import com.cooleshow.institution.stu.bean.HomeHotMusicSheetItemBean;
|
|
|
import com.cooleshow.institution.stu.bean.HomePageMode;
|
|
|
+import com.cooleshow.institution.stu.bean.HotAlbumBean;
|
|
|
import com.cooleshow.institution.stu.constants.Constants;
|
|
|
+import com.cooleshow.institution.stu.contract.HomeMusicContract;
|
|
|
import com.cooleshow.institution.stu.databinding.FgHomeMusicLayoutBinding;
|
|
|
import com.cooleshow.institution.stu.presenter.HomeMusicPresenter;
|
|
|
import com.cooleshow.institution.stu.viewmodel.HomeViewModel;
|
|
|
+import com.cooleshow.institution.stu.widget.HomeHotMusicSheetItemDecoration;
|
|
|
+import com.scwang.smart.refresh.layout.api.RefreshLayout;
|
|
|
+import com.scwang.smart.refresh.layout.listener.OnRefreshListener;
|
|
|
+import com.youth.banner.adapter.BannerImageAdapter;
|
|
|
+import com.youth.banner.config.IndicatorConfig;
|
|
|
+import com.youth.banner.holder.BannerImageHolder;
|
|
|
+import com.youth.banner.indicator.RectangleIndicator;
|
|
|
+import com.youth.banner.listener.OnBannerListener;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import androidx.annotation.NonNull;
|
|
|
import androidx.lifecycle.ViewModelProviders;
|
|
|
+import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
|
|
/**
|
|
|
* Author by pq, Date on 2023/9/12.
|
|
|
*/
|
|
|
-public class HomeMusicFragment extends BaseMVPFragment<FgHomeMusicLayoutBinding, HomeMusicPresenter> implements View.OnClickListener {
|
|
|
+public class HomeMusicFragment extends BaseMVPFragment<FgHomeMusicLayoutBinding, HomeMusicPresenter> implements View.OnClickListener, HomeMusicContract.HomeMusicContractView {
|
|
|
|
|
|
private HomeViewModel mHomeViewModel;
|
|
|
+ private HomeHotAlbumAdapter mAlbumAdapter;
|
|
|
+ private HomeHotMusicSheetAdapter mRecommendAdapter;
|
|
|
+ private HomeHotMusicSheetAdapter mLatestAdapter;
|
|
|
+ private HomeHotMusicSheetAdapter mHomeHotMusicSheetAdapter;
|
|
|
+ private BannerImageAdapter mBannerImageAdapter;
|
|
|
+
|
|
|
+ private ArrayList<AppHomeBean.ItemBean> itemBeans = new ArrayList<>();
|
|
|
|
|
|
@Override
|
|
|
protected void initView(View rootView) {
|
|
@@ -30,10 +63,78 @@ public class HomeMusicFragment extends BaseMVPFragment<FgHomeMusicLayoutBinding,
|
|
|
protected void initData() {
|
|
|
initViewModel();
|
|
|
initListener();
|
|
|
+ mBannerImageAdapter = new BannerImageAdapter<AppHomeBean.ItemBean>(itemBeans) {
|
|
|
+ @Override
|
|
|
+ public void onBindView(BannerImageHolder holder, AppHomeBean.ItemBean data, int position, int size) {
|
|
|
+ Glide.with(holder.imageView)
|
|
|
+ .load(data.coverImage)
|
|
|
+ .thumbnail(Glide.with(holder.itemView).load(com.cooleshow.base.R.drawable.bg_video_placeholder))//加载成功前显示一个loading的加载
|
|
|
+// .apply(RequestOptions.bitmapTransform(new RoundedCorners(30))) //设置图片圆角
|
|
|
+ .into(holder.imageView);
|
|
|
+
|
|
|
+ }
|
|
|
+ };
|
|
|
+ mViewBinding.banner.setAdapter(mBannerImageAdapter, true).addBannerLifecycleObserver(this)//添加生命周期观察者
|
|
|
+ .isAutoLoop(true)
|
|
|
+ .setIndicatorGravity(IndicatorConfig.Direction.RIGHT)
|
|
|
+// .removeIndicator()
|
|
|
+ .setIndicator(new RectangleIndicator(getContext())) //圆形指示器 还支持条形指示器等
|
|
|
+ .setOnBannerListener(new OnBannerListener() {
|
|
|
+ @Override
|
|
|
+ public void OnBannerClick(Object data, int position) {
|
|
|
+ AppHomeBean.ItemBean item = (AppHomeBean.ItemBean) data;
|
|
|
+ if (!TextUtils.isEmpty(item.linkUrl)) {
|
|
|
+ ARouter.getInstance()
|
|
|
+ .build(RouterPath.WebCenter.ACTIVITY_HTML)
|
|
|
+ .withString(WebConstants.WEB_URL, item.linkUrl)
|
|
|
+ .navigation();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ //热门专辑
|
|
|
+ LinearLayoutManager manager = new LinearLayoutManager(getContext());
|
|
|
+ manager.setOrientation(LinearLayoutManager.HORIZONTAL);
|
|
|
+ mViewBinding.rvHotAlbum.setLayoutManager(manager);
|
|
|
+ mAlbumAdapter = new HomeHotAlbumAdapter();
|
|
|
+ mViewBinding.rvHotAlbum.setAdapter(mAlbumAdapter);
|
|
|
+
|
|
|
+ LinearLayoutManager recommendMusicSheetManager = new LinearLayoutManager(getContext());
|
|
|
+ recommendMusicSheetManager.setOrientation(LinearLayoutManager.HORIZONTAL);
|
|
|
+ mRecommendAdapter = new HomeHotMusicSheetAdapter();
|
|
|
+ HomeHotMusicSheetItemDecoration itemDecoration1 = new HomeHotMusicSheetItemDecoration(0, SizeUtils.dp2px(12), 0, SizeUtils.dp2px(12), 0);
|
|
|
+ mViewBinding.rvRecommendTrack.addItemDecoration(itemDecoration1);
|
|
|
+ mViewBinding.rvRecommendTrack.setLayoutManager(recommendMusicSheetManager);
|
|
|
+ mViewBinding.rvRecommendTrack.setAdapter(mRecommendAdapter);
|
|
|
+ mViewBinding.rvRecommendTrack.setNestedScrollingEnabled(false);
|
|
|
+
|
|
|
+ LinearLayoutManager latestMusicSheetManager = new LinearLayoutManager(getContext());
|
|
|
+ latestMusicSheetManager.setOrientation(LinearLayoutManager.HORIZONTAL);
|
|
|
+ mLatestAdapter = new HomeHotMusicSheetAdapter();
|
|
|
+ HomeHotMusicSheetItemDecoration itemDecoration2 = new HomeHotMusicSheetItemDecoration(0, SizeUtils.dp2px(12), 0, SizeUtils.dp2px(12), 0);
|
|
|
+ mViewBinding.rvLatestTrack.addItemDecoration(itemDecoration2);
|
|
|
+ mViewBinding.rvLatestTrack.setLayoutManager(latestMusicSheetManager);
|
|
|
+ mViewBinding.rvLatestTrack.setAdapter(mLatestAdapter);
|
|
|
+ mViewBinding.rvLatestTrack.setNestedScrollingEnabled(false);
|
|
|
+
|
|
|
+ //热门曲目
|
|
|
+ LinearLayoutManager musicSheetManager = new LinearLayoutManager(getContext());
|
|
|
+ musicSheetManager.setOrientation(LinearLayoutManager.HORIZONTAL);
|
|
|
+ mHomeHotMusicSheetAdapter = new HomeHotMusicSheetAdapter();
|
|
|
+ HomeHotMusicSheetItemDecoration itemDecoration = new HomeHotMusicSheetItemDecoration(0, 0, 0, SizeUtils.dp2px(12), 0);
|
|
|
+ mViewBinding.rvHotTrack.addItemDecoration(itemDecoration);
|
|
|
+ mViewBinding.rvHotTrack.setLayoutManager(musicSheetManager);
|
|
|
+ mViewBinding.rvHotTrack.setAdapter(mHomeHotMusicSheetAdapter);
|
|
|
}
|
|
|
|
|
|
private void initListener() {
|
|
|
mViewBinding.ivPractice.setOnClickListener(this);
|
|
|
+ mViewBinding.refreshLayout.setOnRefreshListener(new OnRefreshListener() {
|
|
|
+ @Override
|
|
|
+ public void onRefresh(@NonNull RefreshLayout refreshLayout) {
|
|
|
+ getData();
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
private void initViewModel() {
|
|
@@ -41,6 +142,21 @@ public class HomeMusicFragment extends BaseMVPFragment<FgHomeMusicLayoutBinding,
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public void onResume() {
|
|
|
+ super.onResume();
|
|
|
+ getData();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getData() {
|
|
|
+ //banner
|
|
|
+// presenter.appHome();
|
|
|
+ //热门专辑
|
|
|
+ presenter.userAccountPage();
|
|
|
+ //曲目列表
|
|
|
+ presenter.getHotMusicSheetList();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
protected FgHomeMusicLayoutBinding getLayoutView() {
|
|
|
return FgHomeMusicLayoutBinding.inflate(getLayoutInflater());
|
|
|
}
|
|
@@ -53,9 +169,116 @@ public class HomeMusicFragment extends BaseMVPFragment<FgHomeMusicLayoutBinding,
|
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
|
int id = v.getId();
|
|
|
- if(id == R.id.iv_practice){
|
|
|
+ if (id == R.id.iv_practice) {
|
|
|
mHomeViewModel.getHomePageModeEvent().postValue(new HomePageMode(Constants.PRACTICE_TUTORIALS));
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void getHotMusicSheetListSuccess(HomeHotMusicSheetBean homeHotMusicSheetBean) {
|
|
|
+ if (isDetached() || homeHotMusicSheetBean == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ mViewBinding.refreshLayout.finishRefresh();
|
|
|
+ //推荐曲目
|
|
|
+ if (homeHotMusicSheetBean.topMusicSheet != null && homeHotMusicSheetBean.topMusicSheet.size() > 0) {
|
|
|
+ mViewBinding.clRecommendTrack.setVisibility(View.VISIBLE);
|
|
|
+ ArrayList<HomeHotMusicSheetItemBean> itemBeans = formatMusicSheetData(homeHotMusicSheetBean.topMusicSheet);
|
|
|
+ if (mRecommendAdapter != null) {
|
|
|
+ mRecommendAdapter.setNewInstance(itemBeans);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ mViewBinding.clRecommendTrack.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+
|
|
|
+ //最新曲目
|
|
|
+ if (homeHotMusicSheetBean.newMusicSheet != null && homeHotMusicSheetBean.newMusicSheet.size() > 0) {
|
|
|
+ mViewBinding.clLatestTrack.setVisibility(View.VISIBLE);
|
|
|
+ ArrayList<HomeHotMusicSheetItemBean> itemBeans = formatMusicSheetData(homeHotMusicSheetBean.newMusicSheet);
|
|
|
+ if (mLatestAdapter != null) {
|
|
|
+ mLatestAdapter.setNewInstance(itemBeans);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ mViewBinding.clLatestTrack.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+
|
|
|
+ //最热曲目
|
|
|
+ if (homeHotMusicSheetBean.hotMusicSheet != null && homeHotMusicSheetBean.hotMusicSheet.size() > 0) {
|
|
|
+ mViewBinding.clHotTrack.setVisibility(View.VISIBLE);
|
|
|
+ ArrayList<HomeHotMusicSheetItemBean> itemBeans = formatMusicSheetData(homeHotMusicSheetBean.hotMusicSheet);
|
|
|
+ if (mHomeHotMusicSheetAdapter != null) {
|
|
|
+ mHomeHotMusicSheetAdapter.setNewInstance(itemBeans);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ mViewBinding.clHotTrack.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private ArrayList<HomeHotMusicSheetItemBean> formatMusicSheetData(List<HomeHotMusicSheetBean.MusicSheetBean> rows) {
|
|
|
+ ArrayList<HomeHotMusicSheetItemBean> itemBeans = new ArrayList<>();
|
|
|
+ if (rows != null && rows.size() > 0) {
|
|
|
+ mViewBinding.clHotTrack.setVisibility(View.VISIBLE);
|
|
|
+ int pageCount = 0;
|
|
|
+ int pageResult = rows.size() % Constants.MAX_HOT_MUSIC_LIST_PAGE;
|
|
|
+ if (pageResult == 0) {
|
|
|
+ pageCount = rows.size() / Constants.MAX_HOT_MUSIC_LIST_PAGE;
|
|
|
+ } else {
|
|
|
+ pageCount = (rows.size() / Constants.MAX_HOT_MUSIC_LIST_PAGE) + 1;
|
|
|
+ }
|
|
|
+ for (int i = 0; i < pageCount; i++) {
|
|
|
+ HomeHotMusicSheetItemBean hotMusicSheetItemBean = new HomeHotMusicSheetItemBean();
|
|
|
+ for (int k = i * Constants.MAX_HOT_MUSIC_LIST_PAGE; k < rows.size() && k < (i + 1) * Constants.MAX_HOT_MUSIC_LIST_PAGE; k++) {
|
|
|
+ hotMusicSheetItemBean.sheetBeans.add(rows.get(k));
|
|
|
+ }
|
|
|
+ itemBeans.add(hotMusicSheetItemBean);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return itemBeans;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void hotAlbumListSuccess(HotAlbumBean homeHotAlbumListBean) {
|
|
|
+ if (isDetached() || homeHotAlbumListBean == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (mAlbumAdapter != null) {
|
|
|
+ if (homeHotAlbumListBean.rows != null && homeHotAlbumListBean.rows.size() > 0) {
|
|
|
+ mViewBinding.clHotAlbum.setVisibility(View.VISIBLE);
|
|
|
+ mAlbumAdapter.setNewInstance(homeHotAlbumListBean.rows);
|
|
|
+ } else {
|
|
|
+ mViewBinding.clHotAlbum.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void appHomeSuccess(AppHomeBean appHomeBean) {
|
|
|
+ if (isDetached()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ mViewBinding.refreshLayout.finishRefresh();
|
|
|
+ //banner
|
|
|
+ bindBanner(appHomeBean.banner);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 处理banner数据
|
|
|
+ *
|
|
|
+ * @param bannerList
|
|
|
+ */
|
|
|
+ private void bindBanner(List<AppHomeBean.ItemBean> bannerList) {
|
|
|
+ if (mBannerImageAdapter == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (bannerList != null && bannerList.size() > 0) {
|
|
|
+ mViewBinding.flBanner.setVisibility(View.VISIBLE);
|
|
|
+ itemBeans.clear();
|
|
|
+ itemBeans.addAll(bannerList);
|
|
|
+ mBannerImageAdapter.notifyDataSetChanged();
|
|
|
+ } else {
|
|
|
+ itemBeans.clear();
|
|
|
+ mViewBinding.flBanner.setVisibility(View.GONE);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|