RecommendFragment.java 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. package com.edufound.reader.fragment;
  2. import android.animation.AnimatorSet;
  3. import android.animation.ObjectAnimator;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.view.ViewGroup;
  7. import android.view.animation.LinearInterpolator;
  8. import android.widget.FrameLayout;
  9. import android.widget.ImageView;
  10. import android.widget.LinearLayout;
  11. import android.widget.TextView;
  12. import android.widget.Toast;
  13. import com.edufound.reader.R;
  14. import com.edufound.reader.activity.CommentActivity;
  15. import com.edufound.reader.activity.RecordActivity;
  16. import com.edufound.reader.base.BaseActivity;
  17. import com.edufound.reader.base.BaseMvpFragment;
  18. import com.edufound.reader.bean.UserRecordBean;
  19. import com.edufound.reader.contract.RecommendFragmentContract;
  20. import com.edufound.reader.presenter.RecommendFragmentPresenter;
  21. import com.edufound.reader.util.GlideUtils;
  22. import com.orhanobut.logger.Logger;
  23. import androidx.recyclerview.widget.RecyclerView;
  24. public class RecommendFragment extends BaseMvpFragment<RecommendFragmentPresenter> implements RecommendFragmentContract.View {
  25. View mRootView;
  26. RecyclerView mRecyclerView;
  27. FrameLayout mUserHeadLayout;
  28. FrameLayout mCommentLayout;
  29. FrameLayout mCollectionLayout;
  30. FrameLayout mThumbsLayout;
  31. LinearLayout mToRecordLayout;
  32. ImageView mVideoUp;
  33. ImageView mVideoNext;
  34. ObjectAnimator mRotationImgAnim;
  35. ImageView mToRecordRotationbg;
  36. ObjectAnimator mToRecordScaleXAnim;
  37. ObjectAnimator mToRecordScaleYAnim;
  38. ImageView mToRecordScaleIcon;
  39. ImageView mUserHead;
  40. TextView mUserPhone;
  41. TextView mCommentCount;
  42. TextView mCollentStatus;
  43. TextView mThumbCount;
  44. //默认是推荐 mFragmentType=0
  45. //关注 mFragmentType=1
  46. //官方的 mFragmentType=2
  47. //关注的人的mFragmentType=3
  48. int mFragmentType = 0;
  49. public RecommendFragment(int type) {
  50. mFragmentType = type;
  51. }
  52. boolean hideBottom = false;
  53. int startPosition = 0;
  54. @Override
  55. protected void initView(View view) {
  56. mRootView = view;
  57. mPresenter = new RecommendFragmentPresenter(getContext());
  58. mPresenter.attachView(this);
  59. mRecyclerView = view.findViewById(R.id.fragment_recommend_recyclerview);
  60. mUserHeadLayout = view.findViewById(R.id.fragment_recommend_user_head_layout);
  61. mCommentLayout = view.findViewById(R.id.fragment_recommend_comment_layout);
  62. mCollectionLayout = view.findViewById(R.id.fragment_recommend_collection_layout);
  63. mThumbsLayout = view.findViewById(R.id.fragment_recommend_thumbs_layout);
  64. mVideoUp = view.findViewById(R.id.fragment_recommend_video_up);
  65. mVideoNext = view.findViewById(R.id.fragment_recommend_video_next);
  66. mToRecordLayout = view.findViewById(R.id.fragment_recommend_to_record_layout);
  67. mUserHead = view.findViewById(R.id.fragment_recommend_user_head);
  68. mUserPhone = view.findViewById(R.id.fragment_recommend_user_phone);
  69. mCommentCount = view.findViewById(R.id.fragment_recommend_comment_num);
  70. mCollentStatus = view.findViewById(R.id.fragment_recommend_collection_status);
  71. mThumbCount = view.findViewById(R.id.fragment_recommend_thumbs_num);
  72. //录音按钮背景旋转
  73. mToRecordRotationbg = mToRecordLayout.findViewById(R.id.fragment_recommend_to_record_bg);
  74. mRotationImgAnim = ObjectAnimator.ofFloat(mToRecordRotationbg, "rotation", 0.0F, 359.0F);
  75. mRotationImgAnim.setRepeatCount(-1);
  76. mRotationImgAnim.setDuration(1500);
  77. LinearInterpolator interpolator = new LinearInterpolator();
  78. mRotationImgAnim.setInterpolator(interpolator); //设置匀速旋转,不卡顿 icon_anim.start();
  79. mRotationImgAnim.start();
  80. //录音按钮缩小放大
  81. mToRecordScaleIcon = mToRecordLayout.findViewById(R.id.fragment_recommend_to_record_icon);
  82. mToRecordScaleXAnim = ObjectAnimator.ofFloat(mToRecordScaleIcon, "scaleX", 1F, 1.2F);//设置Y轴的立体旋转动画
  83. mToRecordScaleXAnim.setRepeatCount(-1);
  84. mToRecordScaleXAnim.setRepeatMode(ObjectAnimator.REVERSE);
  85. mToRecordScaleXAnim.setDuration(1000);
  86. LinearInterpolator interpolator2 = new LinearInterpolator();
  87. mToRecordScaleXAnim.setInterpolator(interpolator2); //设置匀速旋转,不卡顿 icon_anim.start();
  88. mToRecordScaleYAnim = ObjectAnimator.ofFloat(mToRecordScaleIcon, "scaleY", 1F, 1.2F);//设置Y轴的立体旋转动画
  89. mToRecordScaleYAnim.setRepeatCount(-1);
  90. mToRecordScaleYAnim.setRepeatMode(ObjectAnimator.REVERSE);
  91. mToRecordScaleYAnim.setDuration(1000);
  92. mToRecordScaleYAnim.setInterpolator(interpolator2); //设置匀速旋转,不卡顿 icon_anim.start();
  93. AnimatorSet animatorSet = new AnimatorSet();
  94. animatorSet.play(mToRecordScaleXAnim).with(mToRecordScaleYAnim);
  95. animatorSet.start();
  96. }
  97. @Override
  98. protected int getLayoutId() {
  99. return R.layout.fragment_main_recommend;
  100. }
  101. @Override
  102. protected void initViewListener() {
  103. addUiClickListener(mUserHeadLayout, o -> {
  104. Logger.e("点击了手机号旁边的头像");
  105. });
  106. if (hideBottom) {
  107. mVideoUp.setVisibility(View.GONE);
  108. mVideoNext.setVisibility(View.GONE);
  109. } else {
  110. addUiClickListener(mVideoUp, o -> {
  111. Logger.e("上一个视频");
  112. mPresenter.scrollToUpFunction(mRecyclerView);
  113. });
  114. addUiClickListener(mVideoNext, o -> {
  115. mPresenter.scrollToNextFunction(mRecyclerView, true);
  116. Logger.e("下一个视频");
  117. });
  118. }
  119. addUiClickListener(mToRecordLayout, o -> {
  120. Logger.e("点击我要录音了:" + mPresenter.getCurPlayVideo());
  121. Bundle bundle = new Bundle();
  122. bundle.putString("index", mPresenter.getCurPlayVideo().toString());
  123. toNextActivity(RecordActivity.class, bundle);
  124. });
  125. mPresenter.initVideoList(mRecyclerView, mFragmentType, startPosition);
  126. }
  127. @Override
  128. public void showLoading() {
  129. }
  130. @Override
  131. public void hideLoading() {
  132. }
  133. @Override
  134. public void onError(String errMessage) {
  135. }
  136. @Override
  137. public void onPause() {
  138. super.onPause();
  139. // JzvdStd.goOnPlayOnPause();
  140. mPresenter.fragmentPause(mRecyclerView);
  141. }
  142. @Override
  143. public void onResume() {
  144. Logger.e("onResume");
  145. super.onResume();
  146. // JzvdStd.goOnPlayOnResume();
  147. mPresenter.fragmentResume(mRecyclerView);
  148. }
  149. @Override
  150. public ViewGroup getRootView() {
  151. return (ViewGroup) mRootView;
  152. }
  153. public void hiddenBottomView() {
  154. hideBottom = true;
  155. }
  156. public void scrollPosition(int position) {
  157. startPosition = position;
  158. }
  159. @Override
  160. public void setTopStatus(UserRecordBean bean) {
  161. //设置信息和点赞数等
  162. GlideUtils.loadImage(getActivity(), bean.getUser().getAvatar(), mUserHead);
  163. mUserPhone.setText(bean.getUser().getMobile());
  164. mCommentCount.setText(bean.getUserRead().getCommentAmount());
  165. if (bean.getIsFavorites()) {
  166. mCollentStatus.setText("已收藏");
  167. ((ImageView) mCollectionLayout.findViewById(R.id.fragment_recommend_collection_icon)).setImageResource(R.drawable.fragment_recommend_collection_icon_s);
  168. } else {
  169. mCollentStatus.setText("未收藏");
  170. ((ImageView) mCollectionLayout.findViewById(R.id.fragment_recommend_collection_icon)).setImageResource(R.drawable.fragment_recommend_collection_icon);
  171. }
  172. if (bean.getIsLike()) {
  173. ((ImageView) mThumbsLayout.findViewById(R.id.fragment_recommend_thumbs_icon)).setImageResource(R.drawable.fragment_recommend_thumbs_up_s);
  174. } else {
  175. ((ImageView) mThumbsLayout.findViewById(R.id.fragment_recommend_thumbs_icon)).setImageResource(R.drawable.fragment_recommend_thumbs_up);
  176. }
  177. addUiClickListener(mCollectionLayout, o -> {
  178. mPresenter.doFavorites(bean.getUserRead());
  179. });
  180. addUiClickListener(mThumbsLayout, o -> {
  181. mPresenter.doLike(bean.getUserRead());
  182. });
  183. mThumbCount.setText(bean.getUserRead().getLikeAmount());
  184. addUiClickListener(mCommentLayout, o -> {
  185. Logger.e("点击了评论");
  186. Bundle bundle = new Bundle();
  187. bundle.putString("exampleId", bean.getUserRead().getExampleId());
  188. toNextActivity(CommentActivity.class, bundle);
  189. });
  190. }
  191. @Override
  192. public void setFavorites(boolean isfavorites) {
  193. if (isfavorites) {
  194. mCollentStatus.setText("已收藏");
  195. ((ImageView) mCollectionLayout.findViewById(R.id.fragment_recommend_collection_icon)).setImageResource(R.drawable.fragment_recommend_collection_icon_s);
  196. ((BaseActivity) getActivity()).showFollowCountAnim();
  197. } else {
  198. mCollentStatus.setText("未收藏");
  199. ((ImageView) mCollectionLayout.findViewById(R.id.fragment_recommend_collection_icon)).setImageResource(R.drawable.fragment_recommend_collection_icon);
  200. }
  201. }
  202. @Override
  203. public void setLikes(String count) {
  204. if (!count.equals(mThumbCount.getText().toString())) {
  205. ((ImageView) mThumbsLayout.findViewById(R.id.fragment_recommend_thumbs_icon)).setImageResource(R.drawable.fragment_recommend_thumbs_up_s);
  206. ((BaseActivity) getActivity()).showFollowCountAnim();
  207. }
  208. mThumbCount.setText(count);
  209. }
  210. @Override
  211. public void onDestroy() {
  212. mPresenter.destory();
  213. super.onDestroy();
  214. }
  215. @Override
  216. public void onDestroyView() {
  217. mPresenter.destory();
  218. super.onDestroyView();
  219. }
  220. }