123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634 |
- package com.edufound.reader.fragment;
- import android.animation.AnimatorSet;
- import android.animation.ObjectAnimator;
- import android.os.Bundle;
- import android.text.TextUtils;
- import android.view.View;
- import android.view.ViewGroup;
- import android.view.animation.LinearInterpolator;
- import android.widget.FrameLayout;
- import android.widget.ImageView;
- import android.widget.LinearLayout;
- import android.widget.TextView;
- import androidx.annotation.NonNull;
- import androidx.recyclerview.widget.RecyclerView;
- import com.baidu.duer.bot.directive.payload.AmountInfo;
- import com.baidu.duer.botsdk.BotIntent;
- import com.edufound.reader.R;
- import com.edufound.reader.activity.CommentActivity;
- import com.edufound.reader.activity.OthersRecordActivity;
- import com.edufound.reader.activity.RecordActivity;
- import com.edufound.reader.base.BaseActivity;
- import com.edufound.reader.base.BaseMvpFragment;
- import com.edufound.reader.bean.ChannelCodeEnum;
- import com.edufound.reader.bean.UserEventEnum;
- import com.edufound.reader.bean.UserRecordBean;
- import com.edufound.reader.contract.RecommendFragmentContract;
- import com.edufound.reader.cusview.CusToast;
- import com.edufound.reader.presenter.PopWindowPresneter;
- import com.edufound.reader.presenter.RecommendFragmentPresenter;
- import com.edufound.reader.util.Consts;
- import com.edufound.reader.util.DeviceUtil;
- import com.edufound.reader.util.EfunboxUtil;
- import com.edufound.reader.util.FloatingAnimation;
- import com.edufound.reader.util.GlideUtils;
- import com.edufound.reader.util.MMKVUtil;
- import com.orhanobut.logger.Logger;
- import com.ufreedom.floatingview.Floating;
- import com.ufreedom.floatingview.FloatingBuilder;
- import com.ufreedom.floatingview.FloatingElement;
- import java.util.HashMap;
- import cn.jzvd.Jzvd;
- import io.reactivex.rxjava3.annotations.Nullable;
- public class RecommendFragment extends BaseMvpFragment<RecommendFragmentPresenter> implements RecommendFragmentContract.View {
- View mRootView;
- FrameLayout mREcommendLayout;
- RecyclerView mRecyclerView;
- FrameLayout mUserHeadLayout;
- FrameLayout mCommentLayout;
- FrameLayout mCollectionLayout;
- FrameLayout mThumbsLayout;
- LinearLayout mToRecordLayout;
- ImageView mVideoUp;
- ImageView mVideoNext;
- ObjectAnimator mRotationImgAnim;
- ImageView mToRecordRotationbg;
- ObjectAnimator mToRecordScaleXAnim;
- ObjectAnimator mToRecordScaleYAnim;
- ImageView mToRecordScaleIcon;
- ImageView mUserHead;
- TextView mUserPhone;
- TextView mCommentCount;
- TextView mCollentStatus;
- TextView mUserReadNum;
- TextView mThumbCount;
- ImageView mCollectIconView;
- ImageView isFollow;
- ImageView mThumbIconView;
- ImageView isUserVip;
- FrameLayout mUserReadCountLayout;
- //默认是推荐 mFragmentType=0
- //关注 mFragmentType=1
- //官方的 mFragmentType=2
- //关注的人的mFragmentType=3
- int mFragmentType = 0;
- boolean hideBottom = false;
- int startPosition = 0;
- String mDataJson = null;
- String intoPage;
- float mRootViewScaleX = 0;
- float mRootViewScaleY = 0;
- boolean isShowReadCount = false;
- ChangeCharacterListener mChangeCharacterListener;
- public RecommendFragment(int type) {
- mFragmentType = type;
- }
- public RecommendFragment() {
- }
- @Override
- protected void initView(View view) {
- mRootView = view;
- mRootView.setVisibility(View.INVISIBLE);
- mPresenter = new RecommendFragmentPresenter(getContext());
- mPresenter.attachView(this);
- mREcommendLayout = view.findViewById(R.id.fragment_recommend_layout);
- mRecyclerView = view.findViewById(R.id.fragment_recommend_recyclerview);
- mUserHeadLayout = view.findViewById(R.id.fragment_recommend_user_head_layout);
- mCommentLayout = view.findViewById(R.id.fragment_recommend_comment_layout);
- mCollectionLayout = view.findViewById(R.id.fragment_recommend_collection_layout);
- mThumbsLayout = view.findViewById(R.id.fragment_recommend_thumbs_layout);
- mVideoUp = view.findViewById(R.id.fragment_recommend_video_up);
- mVideoNext = view.findViewById(R.id.fragment_recommend_video_next);
- mToRecordLayout = view.findViewById(R.id.fragment_recommend_to_record_layout);
- mUserHead = view.findViewById(R.id.fragment_recommend_user_head);
- mUserPhone = view.findViewById(R.id.fragment_recommend_user_phone);
- mCommentCount = view.findViewById(R.id.fragment_recommend_comment_num);
- mCollentStatus = view.findViewById(R.id.fragment_recommend_collection_status);
- mThumbCount = view.findViewById(R.id.fragment_recommend_thumbs_num);
- mCollectIconView = view.findViewById(R.id.fragment_recommend_collection_icon);
- mThumbIconView = view.findViewById(R.id.fragment_recommend_thumbs_icon);
- isFollow = view.findViewById(R.id.fragment_main_recommend_isfollow);
- isUserVip = view.findViewById(R.id.fragment_recommend_app_user_isvip);
- mUserReadCountLayout = view.findViewById(R.id.fragment_recommend_userread_count_layout);
- mUserReadNum = view.findViewById(R.id.fragment_recommend_userread_num);
- mUserReadCountLayout.setVisibility(View.GONE);
- if (!Consts.getUMengChannel().equals(ChannelCodeEnum.BAIDU.getChannelCode())) {
- //不是百度渠道得增加动画
- int scaleTime = 0;
- int rotateTime = 0;
- scaleTime = 1000;
- rotateTime = 1500;
- mToRecordRotationbg = mToRecordLayout.findViewById(R.id.fragment_recommend_to_record_bg);
- mRotationImgAnim = ObjectAnimator.ofFloat(mToRecordRotationbg, "rotation", 0.0F, 359.0F);
- mRotationImgAnim.setRepeatCount(-1);
- mRotationImgAnim.setDuration(rotateTime);
- LinearInterpolator interpolator = new LinearInterpolator();
- mRotationImgAnim.setInterpolator(interpolator); //设置匀速旋转,不卡顿 icon_anim.start();
- mRotationImgAnim.start();
- // 录音按钮缩小放大
- mToRecordScaleIcon = mToRecordLayout.findViewById(R.id.fragment_recommend_to_record_icon);
- mToRecordScaleXAnim = ObjectAnimator.ofFloat(mToRecordScaleIcon, "scaleX", 1F, 1.2F);//设置Y轴的立体旋转动画
- mToRecordScaleXAnim.setRepeatCount(-1);
- mToRecordScaleXAnim.setRepeatMode(ObjectAnimator.REVERSE);
- mToRecordScaleXAnim.setDuration(scaleTime);
- LinearInterpolator interpolator2 = new LinearInterpolator();
- mToRecordScaleXAnim.setInterpolator(interpolator2); //设置匀速旋转,不卡顿 icon_anim.start();
- mToRecordScaleYAnim = ObjectAnimator.ofFloat(mToRecordScaleIcon, "scaleY", 1F, 1.2F);//设置Y轴的立体旋转动画
- mToRecordScaleYAnim.setRepeatCount(-1);
- mToRecordScaleYAnim.setRepeatMode(ObjectAnimator.REVERSE);
- mToRecordScaleYAnim.setDuration(scaleTime);
- mToRecordScaleYAnim.setInterpolator(interpolator2); //设置匀速旋转,不卡顿 icon_anim.start();
- AnimatorSet animatorSet = new AnimatorSet();
- animatorSet.play(mToRecordScaleXAnim).with(mToRecordScaleYAnim);
- animatorSet.start();
- }
- }
- @Override
- protected int getLayoutId() {
- return R.layout.fragment_main_recommend;
- }
- public RecommendFragmentPresenter getPresenter() {
- return mPresenter;
- }
- @Override
- protected void initViewListener() {
- if (Consts.getUMengChannel().equals(ChannelCodeEnum.MISOUND.getChannelCode())) {
- //小米渠道,加个回调监听
- EfunboxUtil.setMISoundLoginCallBack(new PopWindowPresneter.MISoundLoginCallBack() {
- @Override
- public void success() {
- if (EfunboxUtil.checkIsVip()) {
- if (isUserVip != null) {
- isUserVip.setVisibility(View.INVISIBLE);
- }
- }
- EfunboxUtil.clearMISoundLoginCallBack();
- }
- @Override
- public void closeWindow() {
- }
- });
- }
- if (mRootViewScaleX > 0) {
- mREcommendLayout.setScaleX(mRootViewScaleX);
- }
- if (mRootViewScaleY > 0) {
- mREcommendLayout.setScaleY(mRootViewScaleY);
- }
- if (hideBottom) {
- mVideoUp.setVisibility(View.GONE);
- mVideoNext.setVisibility(View.GONE);
- } else {
- addUiClickListener(mVideoUp, o -> {
- mPresenter.scrollToUpFunction(mRecyclerView);
- });
- addUiClickListener(mVideoNext, o -> {
- mPresenter.checkIsOver();
- mPresenter.scrollToNextFunction(mRecyclerView, true);
- // mPresenter.toNext(mRecyclerView);
- });
- }
- addUiClickListener(mToRecordLayout, o -> {
- mPresenter.getUserApi().postUserEvent(getActivity(), UserEventEnum.EVENT_RECREAD.getEvent());
- if (EfunboxUtil.checkLogin(getActivity(), getRootView())) {
- //登陆了,判断是否是VIP
- if (EfunboxUtil.checkIsVip()) {
- //如果是VIP
- if (!TextUtils.isEmpty(mPresenter.getCurVideoExampleId().toString())) {
- Bundle bundle = new Bundle();
- bundle.putString("exampleId", mPresenter.getCurVideoExampleId().toString());
- toNextActivity(RecordActivity.class, bundle);
- } else {
- CusToast.getInstance(getContext()).show("视频id出现问题", 1000);
- }
- } else {
- EfunboxUtil.userPay(getActivity());
- }
- }
- });
- mPresenter.initVideoList(mRecyclerView, mFragmentType, startPosition);
- }
- @Override
- public void showLoading() {
- }
- @Override
- public void hideLoading() {
- }
- @Override
- public void onError(String errMessage) {
- }
- @Override
- public void onPause() {
- mPresenter.fragmentPause(mRecyclerView);
- super.onPause();
- }
- @Override
- public void onResume() {
- mPresenter.fragmentResume(mRecyclerView);
- if (EfunboxUtil.checkIsVip()) {
- if (isUserVip != null) {
- isUserVip.setVisibility(View.INVISIBLE);
- }
- }
- super.onResume();
- }
- @Override
- public ViewGroup getRootView() {
- return (ViewGroup) mRootView;
- }
- public void hiddenBottomView() {
- hideBottom = true;
- }
- public void setLayoutViewScale(float x, float y) {
- mRootViewScaleX = x;
- mRootViewScaleY = y;
- }
- public void showUserReadCount(boolean bool) {
- isShowReadCount = bool;
- }
- public void scrollPosition(int position) {
- startPosition = position;
- }
- public void setDataJson(String json) {
- mDataJson = json;
- }
- public void setInToPage(String page) {
- intoPage = page;
- }
- @Override
- public void setTopStatus(UserRecordBean bean) {
- //设置信息和点赞数等
- if (bean.getUser().getAvatar() == null || bean.getUser().getAvatar().equals("")) {
- if (bean.getUser().getGender().equals("1")) {
- //男
- GlideUtils.loadImage(getActivity(), R.drawable.activity_userinfo_setting_boy, mUserHead);
- } else {
- GlideUtils.loadImage(getActivity(), R.drawable.activity_userinfo_setting_girl, mUserHead);
- }
- } else {
- GlideUtils.loadCircleImage(getActivity(), bean.getUser().getAvatar(), mUserHead);
- }
- if (bean.getUser().getNickName().length() > 6) {
- mUserPhone.setText(bean.getUser().getNickName().substring(0, 6) + "...");
- } else {
- mUserPhone.setText(bean.getUser().getNickName());
- }
- mCommentCount.setText(bean.getUserRead().getCommentAmount());
- if (isShowReadCount) {
- mUserReadCountLayout.setVisibility(View.VISIBLE);
- addUiClickListener(mUserReadCountLayout, o -> {
- mPresenter.getListByExampleId(bean.getUserRead().getExampleId());
- });
- mUserReadNum.setText(EfunboxUtil.checkNum10000(bean.getUserRead().getReadAmount()));
- }
- if (bean.getIsFavorites() || bean.getFavoritesBean() != null) {
- mCollentStatus.setText("已收藏");
- mCollectIconView.setImageResource(R.drawable.fragment_recommend_collection_icon_s);
- } else {
- mCollentStatus.setText("未收藏");
- mCollectIconView.setImageResource(R.drawable.fragment_recommend_collection_icon);
- }
- if (bean.getIsLike()) {
- mThumbIconView.setImageResource(R.drawable.fragment_recommend_thumbs_up_s);
- } else {
- mThumbIconView.setImageResource(R.drawable.fragment_recommend_thumbs_up);
- }
- if (!bean.getUserRead().getTag().equals("ACTIVITY")) {
- isFollow.setVisibility(View.INVISIBLE);
- mUserHeadLayout.setClickable(true);
- addUiClickListener(mUserHeadLayout, o -> {
- if (EfunboxUtil.checkLogin(getActivity(), getRootView())) {
- Bundle bundle = new Bundle();
- bundle.putString("other_uid", bean.getUser().getUid());
- bundle.putString("record_id", bean.getUserRead().getId());
- bundle.putString("intoPage", "RecommendFragment");
- toNextActivity(OthersRecordActivity.class, bundle);
- }
- });
- } else {
- mUserHeadLayout.setClickable(false);
- }
- if (bean.getUser().getUid().equals(Consts.getUID()) || bean.getUser().getProfession().equals("官方")) {
- //是自己
- isFollow.setVisibility(View.INVISIBLE);
- } else {
- if (bean.getIsFans()) {
- isFollow.setVisibility(View.INVISIBLE);
- } else {
- isFollow.setVisibility(View.VISIBLE);
- }
- }
- addUiClickListener(mCollectionLayout, o -> {
- //收藏
- if (EfunboxUtil.checkLogin(getActivity(), getRootView())) {
- mPresenter.doFavorites(bean.getUserRead());
- }
- });
- addUiClickListener(mThumbsLayout, o -> {
- //点赞
- if (EfunboxUtil.checkLogin(getActivity(), getRootView())) {
- mPresenter.doLike(bean.getUserRead());
- ImageView imageView = new ImageView(getActivity());
- imageView.setLayoutParams(new ViewGroup.LayoutParams(mThumbIconView.getMeasuredWidth(), mThumbIconView.getMeasuredHeight()));
- imageView.setImageDrawable(mThumbIconView.getDrawable());
- Floating floating = new Floating(getActivity());
- FloatingElement builder = new FloatingBuilder()
- .anchorView(mThumbIconView)
- .targetView(imageView)
- .offsetX(0)
- .offsetY(0)
- .floatingTransition(new FloatingAnimation.PlaneFloating(DeviceUtil.getHeight(getActivity())))
- .build();
- floating.startFloating(builder);
- }
- });
- mThumbCount.setText(bean.getUserRead().getLikeAmount());
- addUiClickListener(mCommentLayout, o -> {
- if (EfunboxUtil.checkLogin(getActivity(), getRootView())) {
- Bundle bundle = new Bundle();
- bundle.putString("id", bean.getUserRead().getId());
- toNextActivity(CommentActivity.class, bundle);
- }
- });
- }
- @Override
- public void setFavorites(boolean isfavorites) {
- if (isfavorites) {
- mCollentStatus.setText("已收藏");
- ((ImageView) mCollectionLayout.findViewById(R.id.fragment_recommend_collection_icon)).setImageResource(R.drawable.fragment_recommend_collection_icon_s);
- } else {
- mCollentStatus.setText("未收藏");
- ((ImageView) mCollectionLayout.findViewById(R.id.fragment_recommend_collection_icon)).setImageResource(R.drawable.fragment_recommend_collection_icon);
- }
- ImageView imageView = new ImageView(getActivity());
- imageView.setLayoutParams(new ViewGroup.LayoutParams(mCollectIconView.getMeasuredWidth(), mCollectIconView.getMeasuredHeight()));
- imageView.setImageDrawable(mCollectIconView.getDrawable());
- Floating floating = new Floating(getActivity());
- FloatingElement builder = new FloatingBuilder()
- .anchorView(mCollectionLayout)
- .targetView(imageView)
- .offsetX(0)
- .offsetY(0)
- .floatingTransition(new FloatingAnimation.PlaneFloating(DeviceUtil.getHeight(getActivity())))
- .build();
- floating.startFloating(builder);
- }
- @Override
- public void setLikes(String count) {
- if (!count.equals(mThumbCount.getText().toString())) {
- ((ImageView) mThumbsLayout.findViewById(R.id.fragment_recommend_thumbs_icon)).setImageResource(R.drawable.fragment_recommend_thumbs_up_s);
- }
- mThumbCount.setText(count);
- }
- @Override
- public String getDataJson() {
- return mDataJson;
- }
- @Override
- public void showFirstIntoView() {
- boolean isFirst = (boolean) MMKVUtil.getInstance().decode("first_into", true);
- if (isFirst) {
- //是第一次进入
- if (!((BaseActivity) getActivity()).getLocalClassName().contains("SmallFullVideoActivity")) {
- ((BaseActivity) getActivity()).showFirstTouchView();
- MMKVUtil.getInstance().encode("first_into", false);
- }
- } else {
- //不是第一次进入了
- }
- }
- @Override
- public ImageView getisViewUI() {
- if (isUserVip == null) {
- return null;
- }
- return isUserVip;
- }
- @Override
- public void clearRecyclerView() {
- if (mRecyclerView != null) {
- mRecyclerView.removeAllViews();
- mRecyclerView = null;
- }
- }
- @Override
- public void eventHideUi() {
- mCommentLayout.setVisibility(View.INVISIBLE);
- mCollectionLayout.setVisibility(View.INVISIBLE);
- mThumbsLayout.setVisibility(View.INVISIBLE);
- mToRecordLayout.setVisibility(View.INVISIBLE);
- }
- @Override
- public void showAllUi() {
- mCommentLayout.setVisibility(View.VISIBLE);
- mCollectionLayout.setVisibility(View.VISIBLE);
- mThumbsLayout.setVisibility(View.VISIBLE);
- mToRecordLayout.setVisibility(View.VISIBLE);
- }
- public void danMuStatus(boolean bool) {
- mPresenter.getPlayingSwitch().setChecked(bool);
- }
- public void playingMarqueenStatus(int status) {
- mPresenter.getPlayingMarqueen().setVisibility(status);
- }
- @Override
- public void onDestroy() {
- mPresenter.activityDestory();
- mPresenter.detachView();
- mPresenter.clearAll();
- super.onDestroy();
- }
- @Override
- public void onGetDisconnect() {
- }
- @Override
- public void onGetMobileConnect() {
- }
- @Override
- public void onGetWifiConnect() {
- }
- @Override
- public void onDestroyView() {
- super.onDestroyView();
- Jzvd.releaseAllVideos();
- getRootView().removeAllViews();
- mREcommendLayout = null;
- mRecyclerView = null;
- mUserHeadLayout = null;
- mCommentLayout = null;
- mCollectionLayout = null;
- mThumbsLayout = null;
- mToRecordLayout = null;
- mVideoUp = null;
- mVideoNext = null;
- mRotationImgAnim = null;
- mToRecordRotationbg = null;
- mToRecordScaleXAnim = null;
- mToRecordScaleYAnim = null;
- mToRecordScaleIcon = null;
- mUserHead = null;
- mUserPhone = null;
- mCommentCount = null;
- mCollentStatus = null;
- mUserReadNum = null;
- mThumbCount = null;
- mCollectIconView = null;
- isFollow = null;
- mThumbIconView = null;
- isUserVip = null;
- mUserReadCountLayout = null;
- }
- @Override
- protected void botHandleIntent(BotIntent intent, String customData) {
- super.botHandleIntent(intent, customData);
- Logger.e("botHandleIntent:" + customData);
- if (EfunboxUtil.checkIsVip()) {
- isUserVip.setVisibility(View.INVISIBLE);
- }
- }
- @Override
- protected void botOnClickLink(String url, HashMap<String, String> paramMap) {
- super.botOnClickLink(url, paramMap);
- Logger.e("botOnClickLink:" + url);
- }
- @Override
- protected void botOnHandleScreenNavigatorEvent(int event) {
- super.botOnHandleScreenNavigatorEvent(event);
- Logger.e("botOnHandleScreenNavigatorEvent:");
- }
- @Override
- protected void botOnLinkAccountSucceed(String s, String s1) {
- super.botOnLinkAccountSucceed(s, s1);
- Logger.e("botOnHandleScreenNavigatorEvent:");
- }
- @Override
- protected void botOnChargeStatusUpdated(String purchaseResult, AmountInfo authorizationAmount, AmountInfo capturedAmount, long creationTimestamp, String baiduOrderReferenceId, String sellerOrderId, String msg) {
- super.botOnChargeStatusUpdated(purchaseResult, authorizationAmount, capturedAmount, creationTimestamp, baiduOrderReferenceId, sellerOrderId, msg);
- Logger.e("botOnHandleScreenNavigatorEvent:");
- }
- @Override
- protected void botOnBuyStatusUpdated(@NonNull String purchaseResult, @NonNull String productId, @NonNull String baiduOrderId, @NonNull String sellerOrderId, @Nullable String msg, String token) {
- super.botOnBuyStatusUpdated(purchaseResult, productId, baiduOrderId, sellerOrderId, msg, token);
- Logger.e("botOnBuyStatusUpdated:");
- }
- public void setChangeCharacterListener(ChangeCharacterListener listener) {
- mChangeCharacterListener = listener;
- }
- @Override
- public ChangeCharacterListener getChangeCharacterListener() {
- return mChangeCharacterListener;
- }
- @Override
- public RecyclerView getmRecyclerView() {
- return mRecyclerView;
- }
- public interface ChangeCharacterListener {
- void changeDataList(UserRecordBean list);
- }
- }
|