123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364 |
- package com.edufound.reader.fragment;
- import android.animation.AnimatorSet;
- import android.animation.ObjectAnimator;
- import android.os.Bundle;
- 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 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.UserRecordBean;
- import com.edufound.reader.contract.RecommendFragmentContract;
- import com.edufound.reader.presenter.RecommendFragmentPresenter;
- import com.edufound.reader.util.EfunboxUtil;
- import com.edufound.reader.util.GlideUtils;
- import com.orhanobut.logger.Logger;
- import java.util.HashMap;
- import androidx.annotation.NonNull;
- import androidx.recyclerview.widget.RecyclerView;
- import io.reactivex.rxjava3.annotations.Nullable;
- public class RecommendFragment extends BaseMvpFragment<RecommendFragmentPresenter> implements RecommendFragmentContract.View {
- View mRootView;
- 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 mThumbCount;
- ImageView isFollow;
- //默认是推荐 mFragmentType=0
- //关注 mFragmentType=1
- //官方的 mFragmentType=2
- //关注的人的mFragmentType=3
- int mFragmentType = 0;
- boolean hideBottom = false;
- int startPosition = 0;
- String mDataJson = null;
- String intoPage;
- public RecommendFragment(int type) {
- mFragmentType = type;
- }
- @Override
- protected void initView(View view) {
- mRootView = view;
- mRootView.setVisibility(View.INVISIBLE);
- mPresenter = new RecommendFragmentPresenter(getContext());
- mPresenter.attachView(this);
- 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);
- isFollow = view.findViewById(R.id.fragment_main_recommend_isfollow);
- //录音按钮背景旋转
- mToRecordRotationbg = mToRecordLayout.findViewById(R.id.fragment_recommend_to_record_bg);
- mRotationImgAnim = ObjectAnimator.ofFloat(mToRecordRotationbg, "rotation", 0.0F, 359.0F);
- mRotationImgAnim.setRepeatCount(-1);
- mRotationImgAnim.setDuration(1500);
- 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(1000);
- 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(1000);
- mToRecordScaleYAnim.setInterpolator(interpolator2); //设置匀速旋转,不卡顿 icon_anim.start();
- AnimatorSet animatorSet = new AnimatorSet();
- animatorSet.play(mToRecordScaleXAnim).with(mToRecordScaleYAnim);
- animatorSet.start();
- mPresenter.setIntoPage(intoPage);
- }
- @Override
- protected int getLayoutId() {
- return R.layout.fragment_main_recommend;
- }
- public RecommendFragmentPresenter getPresenter() {
- return mPresenter;
- }
- @Override
- protected void initViewListener() {
- if (hideBottom) {
- mVideoUp.setVisibility(View.GONE);
- mVideoNext.setVisibility(View.GONE);
- } else {
- addUiClickListener(mVideoUp, o -> {
- Logger.e("上一个视频");
- mPresenter.scrollToUpFunction(mRecyclerView);
- });
- addUiClickListener(mVideoNext, o -> {
- mPresenter.scrollToNextFunction(mRecyclerView, true);
- Logger.e("下一个视频");
- });
- }
- addUiClickListener(mToRecordLayout, o -> {
- Bundle bundle = new Bundle();
- bundle.putString("exampleId", mPresenter.getCurVideoExampleId().toString());
- toNextActivity(RecordActivity.class, bundle);
- });
- 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);
- super.onResume();
- }
- @Override
- public ViewGroup getRootView() {
- return (ViewGroup) mRootView;
- }
- public void hiddenBottomView() {
- hideBottom = true;
- }
- 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) {
- Logger.e("bean.getuser.getnickName:" + bean.getUser().getNickName());
- //设置信息和点赞数等
- GlideUtils.loadCircleImage(getActivity(), bean.getUser().getAvatar(), mUserHead);
- mUserPhone.setText(bean.getUser().getNickName());
- mCommentCount.setText(bean.getUserRead().getCommentAmount());
- if (bean.getIsFans()) {
- isFollow.setVisibility(View.INVISIBLE);
- } else {
- isFollow.setVisibility(View.VISIBLE);
- }
- if (bean.getIsFavorites() || bean.getFavoritesBean() != null) {
- 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);
- }
- if (bean.getIsLike()) {
- ((ImageView) mThumbsLayout.findViewById(R.id.fragment_recommend_thumbs_icon)).setImageResource(R.drawable.fragment_recommend_thumbs_up_s);
- } else {
- ((ImageView) mThumbsLayout.findViewById(R.id.fragment_recommend_thumbs_icon)).setImageResource(R.drawable.fragment_recommend_thumbs_up);
- }
- addUiClickListener(mUserHeadLayout, o -> {
- Logger.e("点击了手机号和头像,跳转他人作品界面");
- 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);
- });
- addUiClickListener(mCollectionLayout, o -> {
- if (EfunboxUtil.checkLogin(getActivity())) {
- mPresenter.doFavorites(bean.getUserRead());
- }
- });
- addUiClickListener(mThumbsLayout, o -> {
- if (EfunboxUtil.checkLogin(getActivity())) {
- mPresenter.doLike(bean.getUserRead());
- }
- });
- mThumbCount.setText(bean.getUserRead().getLikeAmount());
- addUiClickListener(mCommentLayout, o -> {
- if (EfunboxUtil.checkLogin(getActivity())) {
- Logger.e("点击了评论");
- 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);
- }
- }
- @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 onDestroy() {
- mPresenter.activityDestory();
- mPresenter.detachView();
- super.onDestroy();
- }
- @Override
- public void onGetDisconnect() {
- }
- @Override
- public void onGetMobileConnect() {
- }
- @Override
- public void onGetWifiConnect() {
- }
- @Override
- public void onDestroyView() {
- super.onDestroyView();
- }
- @Override
- protected void botHandleIntent(BotIntent intent, String customData) {
- super.botHandleIntent(intent, customData);
- Logger.e("botHandleIntent:" + customData);
- }
- @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:");
- }
- }
|