RecommendFragment.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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 com.baidu.duer.bot.directive.payload.AmountInfo;
  13. import com.baidu.duer.botsdk.BotIntent;
  14. import com.edufound.reader.R;
  15. import com.edufound.reader.activity.CommentActivity;
  16. import com.edufound.reader.activity.OthersRecordActivity;
  17. import com.edufound.reader.activity.RecordActivity;
  18. import com.edufound.reader.base.BaseActivity;
  19. import com.edufound.reader.base.BaseMvpFragment;
  20. import com.edufound.reader.bean.UserRecordBean;
  21. import com.edufound.reader.contract.RecommendFragmentContract;
  22. import com.edufound.reader.presenter.RecommendFragmentPresenter;
  23. import com.edufound.reader.util.EfunboxUtil;
  24. import com.edufound.reader.util.GlideUtils;
  25. import com.orhanobut.logger.Logger;
  26. import java.util.HashMap;
  27. import androidx.annotation.NonNull;
  28. import androidx.recyclerview.widget.RecyclerView;
  29. import io.reactivex.rxjava3.annotations.Nullable;
  30. public class RecommendFragment extends BaseMvpFragment<RecommendFragmentPresenter> implements RecommendFragmentContract.View {
  31. View mRootView;
  32. RecyclerView mRecyclerView;
  33. FrameLayout mUserHeadLayout;
  34. FrameLayout mCommentLayout;
  35. FrameLayout mCollectionLayout;
  36. FrameLayout mThumbsLayout;
  37. LinearLayout mToRecordLayout;
  38. ImageView mVideoUp;
  39. ImageView mVideoNext;
  40. ObjectAnimator mRotationImgAnim;
  41. ImageView mToRecordRotationbg;
  42. ObjectAnimator mToRecordScaleXAnim;
  43. ObjectAnimator mToRecordScaleYAnim;
  44. ImageView mToRecordScaleIcon;
  45. ImageView mUserHead;
  46. TextView mUserPhone;
  47. TextView mCommentCount;
  48. TextView mCollentStatus;
  49. TextView mThumbCount;
  50. ImageView isFollow;
  51. //默认是推荐 mFragmentType=0
  52. //关注 mFragmentType=1
  53. //官方的 mFragmentType=2
  54. //关注的人的mFragmentType=3
  55. int mFragmentType = 0;
  56. boolean hideBottom = false;
  57. int startPosition = 0;
  58. String mDataJson = null;
  59. String intoPage;
  60. public RecommendFragment(int type) {
  61. mFragmentType = type;
  62. }
  63. @Override
  64. protected void initView(View view) {
  65. mRootView = view;
  66. mRootView.setVisibility(View.INVISIBLE);
  67. mPresenter = new RecommendFragmentPresenter(getContext());
  68. mPresenter.attachView(this);
  69. mRecyclerView = view.findViewById(R.id.fragment_recommend_recyclerview);
  70. mUserHeadLayout = view.findViewById(R.id.fragment_recommend_user_head_layout);
  71. mCommentLayout = view.findViewById(R.id.fragment_recommend_comment_layout);
  72. mCollectionLayout = view.findViewById(R.id.fragment_recommend_collection_layout);
  73. mThumbsLayout = view.findViewById(R.id.fragment_recommend_thumbs_layout);
  74. mVideoUp = view.findViewById(R.id.fragment_recommend_video_up);
  75. mVideoNext = view.findViewById(R.id.fragment_recommend_video_next);
  76. mToRecordLayout = view.findViewById(R.id.fragment_recommend_to_record_layout);
  77. mUserHead = view.findViewById(R.id.fragment_recommend_user_head);
  78. mUserPhone = view.findViewById(R.id.fragment_recommend_user_phone);
  79. mCommentCount = view.findViewById(R.id.fragment_recommend_comment_num);
  80. mCollentStatus = view.findViewById(R.id.fragment_recommend_collection_status);
  81. mThumbCount = view.findViewById(R.id.fragment_recommend_thumbs_num);
  82. isFollow = view.findViewById(R.id.fragment_main_recommend_isfollow);
  83. //录音按钮背景旋转
  84. mToRecordRotationbg = mToRecordLayout.findViewById(R.id.fragment_recommend_to_record_bg);
  85. mRotationImgAnim = ObjectAnimator.ofFloat(mToRecordRotationbg, "rotation", 0.0F, 359.0F);
  86. mRotationImgAnim.setRepeatCount(-1);
  87. mRotationImgAnim.setDuration(1500);
  88. LinearInterpolator interpolator = new LinearInterpolator();
  89. mRotationImgAnim.setInterpolator(interpolator); //设置匀速旋转,不卡顿 icon_anim.start();
  90. mRotationImgAnim.start();
  91. //录音按钮缩小放大
  92. mToRecordScaleIcon = mToRecordLayout.findViewById(R.id.fragment_recommend_to_record_icon);
  93. mToRecordScaleXAnim = ObjectAnimator.ofFloat(mToRecordScaleIcon, "scaleX", 1F, 1.2F);//设置Y轴的立体旋转动画
  94. mToRecordScaleXAnim.setRepeatCount(-1);
  95. mToRecordScaleXAnim.setRepeatMode(ObjectAnimator.REVERSE);
  96. mToRecordScaleXAnim.setDuration(1000);
  97. LinearInterpolator interpolator2 = new LinearInterpolator();
  98. mToRecordScaleXAnim.setInterpolator(interpolator2); //设置匀速旋转,不卡顿 icon_anim.start();
  99. mToRecordScaleYAnim = ObjectAnimator.ofFloat(mToRecordScaleIcon, "scaleY", 1F, 1.2F);//设置Y轴的立体旋转动画
  100. mToRecordScaleYAnim.setRepeatCount(-1);
  101. mToRecordScaleYAnim.setRepeatMode(ObjectAnimator.REVERSE);
  102. mToRecordScaleYAnim.setDuration(1000);
  103. mToRecordScaleYAnim.setInterpolator(interpolator2); //设置匀速旋转,不卡顿 icon_anim.start();
  104. AnimatorSet animatorSet = new AnimatorSet();
  105. animatorSet.play(mToRecordScaleXAnim).with(mToRecordScaleYAnim);
  106. animatorSet.start();
  107. mPresenter.setIntoPage(intoPage);
  108. }
  109. @Override
  110. protected int getLayoutId() {
  111. return R.layout.fragment_main_recommend;
  112. }
  113. public RecommendFragmentPresenter getPresenter() {
  114. return mPresenter;
  115. }
  116. @Override
  117. protected void initViewListener() {
  118. if (hideBottom) {
  119. mVideoUp.setVisibility(View.GONE);
  120. mVideoNext.setVisibility(View.GONE);
  121. } else {
  122. addUiClickListener(mVideoUp, o -> {
  123. Logger.e("上一个视频");
  124. mPresenter.scrollToUpFunction(mRecyclerView);
  125. });
  126. addUiClickListener(mVideoNext, o -> {
  127. mPresenter.scrollToNextFunction(mRecyclerView, true);
  128. Logger.e("下一个视频");
  129. });
  130. }
  131. addUiClickListener(mToRecordLayout, o -> {
  132. Bundle bundle = new Bundle();
  133. bundle.putString("exampleId", mPresenter.getCurVideoExampleId().toString());
  134. toNextActivity(RecordActivity.class, bundle);
  135. });
  136. mPresenter.initVideoList(mRecyclerView, mFragmentType, startPosition);
  137. }
  138. @Override
  139. public void showLoading() {
  140. }
  141. @Override
  142. public void hideLoading() {
  143. }
  144. @Override
  145. public void onError(String errMessage) {
  146. }
  147. @Override
  148. public void onPause() {
  149. mPresenter.fragmentPause(mRecyclerView);
  150. super.onPause();
  151. }
  152. @Override
  153. public void onResume() {
  154. mPresenter.fragmentResume(mRecyclerView);
  155. super.onResume();
  156. }
  157. @Override
  158. public ViewGroup getRootView() {
  159. return (ViewGroup) mRootView;
  160. }
  161. public void hiddenBottomView() {
  162. hideBottom = true;
  163. }
  164. public void scrollPosition(int position) {
  165. startPosition = position;
  166. }
  167. public void setDataJson(String json) {
  168. mDataJson = json;
  169. }
  170. public void setInToPage(String page) {
  171. intoPage = page;
  172. }
  173. @Override
  174. public void setTopStatus(UserRecordBean bean) {
  175. Logger.e("bean.getuser.getnickName:" + bean.getUser().getNickName());
  176. //设置信息和点赞数等
  177. GlideUtils.loadCircleImage(getActivity(), bean.getUser().getAvatar(), mUserHead);
  178. mUserPhone.setText(bean.getUser().getNickName());
  179. mCommentCount.setText(bean.getUserRead().getCommentAmount());
  180. if (bean.getIsFans()) {
  181. isFollow.setVisibility(View.INVISIBLE);
  182. } else {
  183. isFollow.setVisibility(View.VISIBLE);
  184. }
  185. if (bean.getIsFavorites() || bean.getFavoritesBean() != null) {
  186. mCollentStatus.setText("已收藏");
  187. ((ImageView) mCollectionLayout.findViewById(R.id.fragment_recommend_collection_icon)).setImageResource(R.drawable.fragment_recommend_collection_icon_s);
  188. } else {
  189. mCollentStatus.setText("未收藏");
  190. ((ImageView) mCollectionLayout.findViewById(R.id.fragment_recommend_collection_icon)).setImageResource(R.drawable.fragment_recommend_collection_icon);
  191. }
  192. if (bean.getIsLike()) {
  193. ((ImageView) mThumbsLayout.findViewById(R.id.fragment_recommend_thumbs_icon)).setImageResource(R.drawable.fragment_recommend_thumbs_up_s);
  194. } else {
  195. ((ImageView) mThumbsLayout.findViewById(R.id.fragment_recommend_thumbs_icon)).setImageResource(R.drawable.fragment_recommend_thumbs_up);
  196. }
  197. addUiClickListener(mUserHeadLayout, o -> {
  198. Logger.e("点击了手机号和头像,跳转他人作品界面");
  199. Bundle bundle = new Bundle();
  200. bundle.putString("other_uid", bean.getUser().getUid());
  201. bundle.putString("record_id", bean.getUserRead().getId());
  202. bundle.putString("intoPage", "RecommendFragment");
  203. toNextActivity(OthersRecordActivity.class, bundle);
  204. });
  205. addUiClickListener(mCollectionLayout, o -> {
  206. if (EfunboxUtil.checkLogin(getActivity())) {
  207. mPresenter.doFavorites(bean.getUserRead());
  208. }
  209. });
  210. addUiClickListener(mThumbsLayout, o -> {
  211. if (EfunboxUtil.checkLogin(getActivity())) {
  212. mPresenter.doLike(bean.getUserRead());
  213. }
  214. });
  215. mThumbCount.setText(bean.getUserRead().getLikeAmount());
  216. addUiClickListener(mCommentLayout, o -> {
  217. if (EfunboxUtil.checkLogin(getActivity())) {
  218. Logger.e("点击了评论");
  219. Bundle bundle = new Bundle();
  220. bundle.putString("id", bean.getUserRead().getId());
  221. toNextActivity(CommentActivity.class, bundle);
  222. }
  223. });
  224. }
  225. @Override
  226. public void setFavorites(boolean isfavorites) {
  227. if (isfavorites) {
  228. mCollentStatus.setText("已收藏");
  229. ((ImageView) mCollectionLayout.findViewById(R.id.fragment_recommend_collection_icon)).setImageResource(R.drawable.fragment_recommend_collection_icon_s);
  230. ((BaseActivity) getActivity()).showFollowCountAnim();
  231. } else {
  232. mCollentStatus.setText("未收藏");
  233. ((ImageView) mCollectionLayout.findViewById(R.id.fragment_recommend_collection_icon)).setImageResource(R.drawable.fragment_recommend_collection_icon);
  234. }
  235. }
  236. @Override
  237. public void setLikes(String count) {
  238. if (!count.equals(mThumbCount.getText().toString())) {
  239. ((ImageView) mThumbsLayout.findViewById(R.id.fragment_recommend_thumbs_icon)).setImageResource(R.drawable.fragment_recommend_thumbs_up_s);
  240. ((BaseActivity) getActivity()).showFollowCountAnim();
  241. }
  242. mThumbCount.setText(count);
  243. }
  244. @Override
  245. public String getDataJson() {
  246. return mDataJson;
  247. }
  248. @Override
  249. public void onDestroy() {
  250. mPresenter.activityDestory();
  251. mPresenter.detachView();
  252. super.onDestroy();
  253. }
  254. @Override
  255. public void onGetDisconnect() {
  256. }
  257. @Override
  258. public void onGetMobileConnect() {
  259. }
  260. @Override
  261. public void onGetWifiConnect() {
  262. }
  263. @Override
  264. public void onDestroyView() {
  265. super.onDestroyView();
  266. }
  267. @Override
  268. protected void botHandleIntent(BotIntent intent, String customData) {
  269. super.botHandleIntent(intent, customData);
  270. Logger.e("botHandleIntent:" + customData);
  271. }
  272. @Override
  273. protected void botOnClickLink(String url, HashMap<String, String> paramMap) {
  274. super.botOnClickLink(url, paramMap);
  275. Logger.e("botOnClickLink:" + url);
  276. }
  277. @Override
  278. protected void botOnHandleScreenNavigatorEvent(int event) {
  279. super.botOnHandleScreenNavigatorEvent(event);
  280. Logger.e("botOnHandleScreenNavigatorEvent:");
  281. }
  282. @Override
  283. protected void botOnLinkAccountSucceed(String s, String s1) {
  284. super.botOnLinkAccountSucceed(s, s1);
  285. Logger.e("botOnHandleScreenNavigatorEvent:");
  286. }
  287. @Override
  288. protected void botOnChargeStatusUpdated(String purchaseResult, AmountInfo authorizationAmount, AmountInfo capturedAmount, long creationTimestamp, String baiduOrderReferenceId, String sellerOrderId, String msg) {
  289. super.botOnChargeStatusUpdated(purchaseResult, authorizationAmount, capturedAmount, creationTimestamp, baiduOrderReferenceId, sellerOrderId, msg);
  290. Logger.e("botOnHandleScreenNavigatorEvent:");
  291. }
  292. @Override
  293. protected void botOnBuyStatusUpdated(@NonNull String purchaseResult, @NonNull String productId, @NonNull String baiduOrderId, @NonNull String sellerOrderId, @Nullable String msg, String token) {
  294. super.botOnBuyStatusUpdated(purchaseResult, productId, baiduOrderId, sellerOrderId, msg, token);
  295. Logger.e("botOnBuyStatusUpdated:");
  296. }
  297. }