123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- package com.edufound.reader.presenter;
- import android.content.Intent;
- import android.os.Build;
- import android.os.Bundle;
- import android.os.Handler;
- import android.os.Message;
- import android.view.LayoutInflater;
- import android.view.MotionEvent;
- import android.view.View;
- import android.widget.FrameLayout;
- import android.widget.GridLayout;
- import android.widget.ImageView;
- import android.widget.LinearLayout;
- import android.widget.TextView;
- import android.widget.Toast;
- import com.edufound.reader.R;
- import com.edufound.reader.activity.OthersRecordActivity;
- import com.edufound.reader.activity.SmallFullVideoActivity;
- import com.edufound.reader.apiserver.UserApiServerImpl;
- import com.edufound.reader.base.BaseActivity;
- import com.edufound.reader.base.BasePresenter;
- import com.edufound.reader.bean.FansBean;
- import com.edufound.reader.bean.HttpResultBean;
- import com.edufound.reader.bean.HttpResultDataListBean;
- import com.edufound.reader.bean.MyInfoBean;
- import com.edufound.reader.bean.UserRecordBean;
- import com.edufound.reader.contract.OthersRecordContract;
- import com.edufound.reader.model.CharacterFragmentModel;
- import com.edufound.reader.model.MyFollowModel;
- import com.edufound.reader.model.OthersRecordModel;
- import com.edufound.reader.receiver.BackPageReceiver;
- import com.edufound.reader.util.EfunboxUtil;
- import com.edufound.reader.util.GlideUtils;
- import com.edufound.reader.util.MMKVUtil;
- import com.edufound.reader.util.SizeUtils;
- import com.google.gson.reflect.TypeToken;
- import com.okhttplib.HttpInfo;
- import com.okhttplib.callback.Callback;
- import com.orhanobut.logger.Logger;
- import java.io.IOException;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import androidx.annotation.RequiresApi;
- public class OthersRecordPresenter extends BasePresenter<OthersRecordContract.View> implements OthersRecordContract.Presenter {
- OthersRecordModel mModel;
- UserApiServerImpl mUserApi;
- List<UserRecordBean> mDataList;
- int onceLoadCount = 10;
- int mListStart = 0;
- int mListEnd = onceLoadCount;
- String backRecordId = null;
- public OthersRecordPresenter() {
- mModel = new OthersRecordModel();
- mUserApi = new UserApiServerImpl();
- }
- @Override
- public void initGridLayout(GridLayout gridLayout, FrameLayout norecordlayout) {
- gridLayout.removeAllViews();
- gridLayout.setRowCount(2);
- onceLoadCount = 10;
- mListStart = 0;
- mListEnd = onceLoadCount;
- setGridData(gridLayout, norecordlayout);
- }
- private void setGridItemView(GridLayout gridLayout, int index) {
- if (mView == null) {
- return;
- }
- View view = LayoutInflater.from(mView.getActivity()).inflate(R.layout.adapter_item_record_user, null);
- UserRecordBean.UserRead reader = mDataList.get(index).getUserRead();
- ImageView imgIcon = view.findViewById(R.id.adapter_item_record_user_icon);
- TextView name = view.findViewById(R.id.adapter_item_record_user_name);
- ImageView imgDel = view.findViewById(R.id.adapter_item_record_user_del);
- ImageView imgPriv = view.findViewById(R.id.adapter_item_record_user_priv);
- TextView lookAmount = view.findViewById(R.id.adapter_item_record_user_look_num);
- TextView likeAmount = view.findViewById(R.id.adapter_item_record_user_thumb_num);
- TextView commentAmount = view.findViewById(R.id.adapter_item_record_user_comment_num);
- TextView favoritesAmount = view.findViewById(R.id.adapter_item_record_user_start_num);
- FrameLayout checkLayout = view.findViewById(R.id.adapter_item_record_user_examine_layout);
- // GlideUtils.loadRoundCircleImage(mView.getActivity(), reader.getCoverImg(), imgIcon, SizeUtils.dp2px(mView.getActivity(), 20));
- GlideUtils.loadImage(mView.getActivity(), reader.getCoverImg(), imgIcon);
- name.setText(reader.getTitle());
- lookAmount.setText(EfunboxUtil.checkNum10000(reader.getPlayAmount()));
- likeAmount.setText(EfunboxUtil.checkNum10000(reader.getLikeAmount()));
- commentAmount.setText(EfunboxUtil.checkNum10000(reader.getCommentAmount()));
- favoritesAmount.setText(EfunboxUtil.checkNum10000(reader.getFavoritesAmount()));
- imgDel.setVisibility(View.GONE);
- imgPriv.setVisibility(View.GONE);
- checkLayout.setVisibility(View.GONE);
- mView.addUiClick(view, o -> {
- Bundle bundle = new Bundle();
- bundle.putString("index", index + "");
- bundle.putString("dataJson", "getmmkv");
- bundle.putString("intoPage", "OthersRecord");
- //数据太多了。直接传不过去,通过MMKV写一下再读一下
- try {
- System.gc();
- MMKVUtil.getInstance().removeKey("video_data");
- String json = ((BaseActivity) mView.getActivity()).getGson().toJson(mDataList);
- MMKVUtil.getInstance().encode("video_data", json);
- // bundle.putString("dataJson", ((BaseActivity) mView.getActivity()).getGson().toJson(mDataList));
- ((BaseActivity) mView.getActivity()).toNextActivity(SmallFullVideoActivity.class, bundle);
- } catch (Exception e) {
- Logger.e("报错数据:" + mDataList);
- e.printStackTrace();
- }
- });
- checkLayout.setOnTouchListener(new View.OnTouchListener() {
- @Override
- public boolean onTouch(View view, MotionEvent motionEvent) {
- return true;
- }
- });
- GridLayout.LayoutParams params = new GridLayout.LayoutParams(new FrameLayout.LayoutParams(SizeUtils.dp2px(mView.getActivity(), 415), SizeUtils.dp2px(mView.getActivity(), 290)));
- params.setMargins(SizeUtils.dp2px(mView.getActivity(), 10), 0, SizeUtils.dp2px(mView.getActivity(), 20), SizeUtils.dp2px(mView.getActivity(), 30));
- view.setLayoutParams(params);
- gridLayout.setOrientation(GridLayout.VERTICAL);
- gridLayout.addView(view);
- }
- public void setGridData(GridLayout gridLayout, FrameLayout norecordlayout) {
- if (mDataList == null || mDataList.size() <= 0) {
- norecordlayout.setVisibility(View.VISIBLE);
- gridLayout.setVisibility(View.GONE);
- return;
- }
- if (mListEnd > mDataList.size()) {
- mListEnd = mDataList.size();
- }
- int timeCount = 0;
- for (int j = mListStart; j < mListEnd; j++) {
- timeCount++;
- Message message = new Message();
- message.obj = gridLayout;
- message.what = OthersRecordModel.LOAD_GRID;
- message.arg1 = j;
- otherRecordHandler.sendMessageDelayed(message, 50 * timeCount);
- }
- mListStart = mListEnd;
- if (mListEnd + onceLoadCount > mDataList.size()) {
- mListEnd = mDataList.size();
- } else {
- mListEnd = mListEnd + onceLoadCount;
- }
- }
- @Override
- public void getOtherRecordList(String uid) {
- mModel.getOtherRecordList(mView.getActivity(), uid, new Callback() {
- @Override
- public void onSuccess(HttpInfo info) throws IOException {
- HttpResultBean<HttpResultDataListBean<UserRecordBean>> bean = info.getRetDetail(new TypeToken<HttpResultBean<HttpResultDataListBean<UserRecordBean>>>() {
- }.getType());
- mDataList = bean.getData().getList();
- mView.getOtherRecordSuccess();
- // mView.loadMoreItem();
- }
- @Override
- public void onFailure(HttpInfo info) throws IOException {
- }
- });
- }
- @Override
- public void doFollow(String uid) {
- Map<String, String> map = new HashMap<>();
- map.put("uid", uid);
- String json = ((BaseActivity) mView.getActivity()).getGson().toJson(map);
- mModel.doFollow(mView.getActivity(), json, new Callback() {
- @RequiresApi(api = Build.VERSION_CODES.N)
- @Override
- public void onSuccess(HttpInfo info) throws IOException {
- HttpResultBean<FansBean> bean = info.getRetDetail(new TypeToken<HttpResultBean<FansBean>>() {
- }.getType());
- if (bean.getData().getStatus().equals("NORMAL")) {
- //已关注状态
- mView.doFollowSuccess(true);
- setFans(true);
- } else if (bean.getData().getStatus().equals("DEL")) {
- //未关注状态
- mView.doFollowSuccess(false);
- setFans(false);
- }
- getOtherUserInfo(uid);
- }
- @Override
- public void onFailure(HttpInfo info) throws IOException {
- }
- });
- }
- public void setFans(boolean fans) {
- for (int i = 0; i < mDataList.size(); i++) {
- mDataList.get(i).setFans(fans);
- }
- }
- @Override
- public void sendBackReceiver(String action) {
- Intent intent = new Intent(action);
- intent.putExtra("recordId", backRecordId);
- mView.getActivity().sendBroadcast(intent);
- }
- @Override
- public void setBackRecordId(String id) {
- backRecordId = id;
- }
- @Override
- public void onDestory(GridLayout layout) {
- otherRecordHandler.removeMessages(CharacterFragmentModel.LOAD_GRID);
- otherRecordHandler = null;
- layout.removeAllViews();
- layout = null;
- mView = null;
- }
- @Override
- public void getOtherUserInfo(String uid) {
- mUserApi.getOtherUserInfo(mView.getActivity(), uid, new Callback() {
- @Override
- public void onSuccess(HttpInfo info) throws IOException {
- HttpResultBean<MyInfoBean> bean = info.getRetDetail(new TypeToken<HttpResultBean<MyInfoBean>>() {
- }.getType());
- mView.setLeftUserInfo(bean.getData());
- }
- @Override
- public void onFailure(HttpInfo info) throws IOException {
- }
- });
- }
- Handler otherRecordHandler = new Handler(new Handler.Callback() {
- @Override
- public boolean handleMessage(Message msg) {
- switch (msg.what) {
- case OthersRecordModel.LOAD_GRID:
- setGridItemView((GridLayout) msg.obj, msg.arg1);
- break;
- default:
- throw new IllegalStateException("Unexpected value: " + msg.what);
- }
- return false;
- }
- });
- }
|