394 lines
14 KiB
Java
394 lines
14 KiB
Java
package com.xscm.moduleutil.adapter;
|
||
|
||
import android.os.Bundle;
|
||
import android.view.View;
|
||
|
||
import androidx.annotation.NonNull;
|
||
import androidx.annotation.Nullable;
|
||
|
||
|
||
import com.blankj.utilcode.util.ToastUtils;
|
||
import com.xscm.moduleutil.R;
|
||
import com.xscm.moduleutil.base.BaseMvpFragment;
|
||
import com.xscm.moduleutil.bean.GiftLabelBean;
|
||
import com.xscm.moduleutil.bean.GiftPackBean;
|
||
import com.xscm.moduleutil.bean.GiftPackListCount;
|
||
import com.xscm.moduleutil.bean.RewardUserBean;
|
||
import com.xscm.moduleutil.bean.RoonGiftModel;
|
||
import com.xscm.moduleutil.bean.WalletBean;
|
||
import com.xscm.moduleutil.bean.room.RoomAuction;
|
||
import com.xscm.moduleutil.databinding.RoomVpGiftBinding;
|
||
import com.xscm.moduleutil.event.GiftDoubleClickEvent;
|
||
import com.xscm.moduleutil.event.GiftUserRefreshEvent;
|
||
import com.xscm.moduleutil.event.RoomGiftClickEvent;
|
||
import com.xscm.moduleutil.event.RoomGiftClickToEvent;
|
||
import com.xscm.moduleutil.event.RoomGiftPackToEvent;
|
||
import com.xscm.moduleutil.presenter.RewardGiftContacts;
|
||
import com.xscm.moduleutil.presenter.RewardGiftPresenter;
|
||
|
||
import org.greenrobot.eventbus.EventBus;
|
||
import org.greenrobot.eventbus.Subscribe;
|
||
import org.greenrobot.eventbus.ThreadMode;
|
||
|
||
import java.util.ArrayList;
|
||
import java.util.List;
|
||
|
||
public class GiftTwoDetailsFragment extends BaseMvpFragment<RewardGiftPresenter, RoomVpGiftBinding> implements RewardGiftContacts.View {
|
||
private String id;
|
||
private GiftTwoAdapter mAdapter;
|
||
private GiftRoomAdapter roomAdapter;
|
||
private GiftPackAdapter packAdapter;
|
||
private String tag;
|
||
private int pageSize = 100;//一页显示的礼物个数
|
||
private int pageCount;//页数
|
||
private int type;//1:房间点击进入的;2:打赏进入的
|
||
private List<RoonGiftModel> giftList = new ArrayList<>();
|
||
private List<GiftPackBean> giftPackList = new ArrayList<>();
|
||
private String roomId;
|
||
private String bdgiftId;
|
||
|
||
public static GiftTwoDetailsFragment newInstance(String id, int type, String roomId) {
|
||
|
||
Bundle args = new Bundle();
|
||
args.putString("id", id);
|
||
args.putInt("type", type);
|
||
args.putString("roomId", roomId);
|
||
GiftTwoDetailsFragment fragment = new GiftTwoDetailsFragment();
|
||
fragment.setArguments(args);
|
||
return fragment;
|
||
}
|
||
|
||
@Override
|
||
public void initArgs(Bundle arguments) {
|
||
super.initArgs(arguments);
|
||
id = arguments.getString("id");
|
||
type = arguments.getInt("type");
|
||
roomId = arguments.getString("roomId");
|
||
|
||
}
|
||
|
||
@Override
|
||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||
super.onViewCreated(view, savedInstanceState);
|
||
EventBus.getDefault().register(this);
|
||
}
|
||
|
||
@Override
|
||
protected RewardGiftPresenter bindPresenter() {
|
||
return new RewardGiftPresenter(this, getActivity());
|
||
}
|
||
|
||
public void loadDataIfNeeded(String id, int type, String roomId) {
|
||
if (id.equals("0")) {
|
||
MvpPre.giftPack();
|
||
} else {
|
||
if (type == 0) {
|
||
MvpPre.getGiftList("0", type, roomId);
|
||
} else {
|
||
if (id == null) {
|
||
id = "0";
|
||
}
|
||
MvpPre.getGiftList(id, type, roomId);
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||
public void onString(String giftId) {
|
||
bdgiftId = giftId;
|
||
MvpPre.giftPack();
|
||
}
|
||
|
||
@Override
|
||
protected void initData() {
|
||
// if (id.equals("0")) {
|
||
// MvpPre.giftPack();
|
||
// } else {
|
||
// if (type == 0) {
|
||
// MvpPre.getGiftList("0", type, roomId);
|
||
// } else {
|
||
// MvpPre.getGiftList(id, type, roomId);
|
||
// }
|
||
//
|
||
// }
|
||
}
|
||
|
||
@Override
|
||
protected void initView() {
|
||
|
||
}
|
||
|
||
@Override
|
||
protected int getLayoutId() {
|
||
return R.layout.room_vp_gift;
|
||
}
|
||
|
||
|
||
public RoonGiftModel getGiftList() {
|
||
if (giftList != null) {
|
||
for (RoonGiftModel item : giftList) {
|
||
if (item.isChecked()) {
|
||
return item;
|
||
}
|
||
}
|
||
}
|
||
return null;
|
||
}
|
||
|
||
public GiftPackBean mGiftList() {
|
||
if (giftPackList != null) {
|
||
for (GiftPackBean item : giftPackList) {
|
||
if (item.isChecked()) {
|
||
return item;
|
||
}
|
||
}
|
||
}
|
||
return null;
|
||
}
|
||
|
||
@Override
|
||
public void setGiftList(List<RoonGiftModel> data, int type) {
|
||
giftList = new ArrayList<>();
|
||
giftList.addAll(data);
|
||
pageCount = (int) Math.ceil(data.size() * 1.0 / pageSize);
|
||
|
||
// 只需要创建一次Adapter并设置,循环设置没有意义
|
||
if (pageCount > 0) {
|
||
roomAdapter = new GiftRoomAdapter(getActivity(), data, 0, "0");
|
||
mBinding.rvGift.setAdapter(roomAdapter);
|
||
}
|
||
}
|
||
|
||
|
||
@Override
|
||
public void giveGift() {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void wallet(WalletBean walletBean) {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void reward_zone() {
|
||
ToastUtils.showShort("打赏成功");
|
||
}
|
||
|
||
@Override
|
||
public void roomAuctionJoin(RoomAuction.AuctionListBean auctionListBean) {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void giftPack(List<GiftPackBean> giftPackBean) {
|
||
giftPackList = new ArrayList<>();
|
||
|
||
if (giftPackBean != null && giftPackBean.size() > 0) {
|
||
|
||
if (bdgiftId != null) {
|
||
for (GiftPackBean item : giftPackBean) {
|
||
if (item.getGift_id().equals(bdgiftId)) {
|
||
item.setChecked(true);
|
||
}
|
||
}
|
||
}
|
||
giftPackList.addAll(giftPackBean);
|
||
pageCount = (int) Math.ceil(giftPackBean.size() * 1.0 / pageSize);
|
||
for (int j = 0; j < pageCount; j++) {
|
||
// mAdapter = new GiftTwoAdapter(getActivity(), data, j, "0");
|
||
// mBinding.rvGift.setAdapter(mAdapter);
|
||
packAdapter = new GiftPackAdapter(getActivity(), giftPackBean, j, "0");
|
||
mBinding.rvGift.setAdapter(packAdapter);
|
||
}
|
||
} else {
|
||
giftPackBean = new ArrayList<>();
|
||
pageCount = (int) Math.ceil(giftPackBean.size() * 1.0 / pageSize);
|
||
packAdapter = new GiftPackAdapter(getActivity(), giftPackBean, 0, "0");
|
||
mBinding.rvGift.setAdapter(packAdapter);
|
||
}
|
||
|
||
|
||
|
||
}
|
||
|
||
@Override
|
||
public void getGiftPack(String s) {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void getGiftPackListCount(GiftPackListCount giftPackListCount) {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void getRewardList(List<RewardUserBean> rewardUserBeanList) {
|
||
|
||
}
|
||
|
||
@Override
|
||
public void getGiftLabel(List<GiftLabelBean> giftLabelBeans) {
|
||
|
||
}
|
||
|
||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||
public void onGiftClicRoomkEvent(RoomGiftClickEvent event) {
|
||
if (giftList == null) {
|
||
giftList = new ArrayList<>();
|
||
giftList.add(event.gift);
|
||
}
|
||
if (event.type == 1) {
|
||
String id = event.gift.getGift_id();
|
||
for (int i = 0; i < giftList.size(); i++) {
|
||
RoonGiftModel giftModel = giftList.get(i);
|
||
if (giftModel.getGift_id().equals(id)) {
|
||
if (!giftModel.isChecked()) {
|
||
EventBus.getDefault().post(new GiftUserRefreshEvent(giftModel.isCan_send_self(), event.type, event.gift));
|
||
giftModel.setChecked(true);
|
||
}
|
||
} else {
|
||
giftModel.setChecked(false);
|
||
}
|
||
}
|
||
if (event.adapter != null && event.adapter.get() != null) {
|
||
event.adapter.get().notifyDataSetChanged();
|
||
}
|
||
} else if (event.type == 2) {
|
||
String id = event.gift.getGift_id();
|
||
RoonGiftModel selGift = null;
|
||
for (int i = 0; i < giftList.size(); i++) {
|
||
RoonGiftModel giftModel = giftList.get(i);
|
||
if (giftModel.getGift_id().equals(id)) {
|
||
selGift = giftModel;
|
||
if (!giftModel.isChecked()) {
|
||
EventBus.getDefault().post(new GiftUserRefreshEvent(giftModel.isCan_send_self(), event.type, event.gift));
|
||
giftModel.setChecked(true);
|
||
}
|
||
} else {
|
||
giftModel.setChecked(false);
|
||
}
|
||
}
|
||
if (event.adapter != null && event.adapter.get() != null) {
|
||
event.adapter.get().notifyDataSetChanged();
|
||
}
|
||
if (selGift != null) {
|
||
EventBus.getDefault().post(new GiftDoubleClickEvent());
|
||
}
|
||
}
|
||
}
|
||
|
||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||
public void onGiftClicPackEvent(RoomGiftPackToEvent event) {
|
||
if (giftPackList == null) {
|
||
giftPackList = new ArrayList<>();
|
||
giftPackList.add(event.gift);
|
||
}
|
||
if (event.type == 1) {
|
||
String id = event.gift.getGift_id();
|
||
for (int i = 0; i < giftPackList.size(); i++) {
|
||
GiftPackBean giftModel = giftPackList.get(i);
|
||
RoonGiftModel roonGiftModel = new RoonGiftModel();
|
||
roonGiftModel.setGift_id(giftModel.getGift_id());
|
||
roonGiftModel.setGift_name(giftModel.getGift_name());
|
||
roonGiftModel.setGift_price(giftModel.getGift_price());
|
||
roonGiftModel.setBase_image(giftModel.getBase_image());
|
||
roonGiftModel.setNum(Integer.parseInt(giftModel.getNum()));
|
||
if (giftModel.getGift_id().equals(id)) {
|
||
if (!giftModel.isChecked()) {
|
||
EventBus.getDefault().post(new GiftUserRefreshEvent(true, event.type, roonGiftModel));
|
||
giftModel.setChecked(true);
|
||
}
|
||
} else {
|
||
giftModel.setChecked(false);
|
||
}
|
||
}
|
||
if (event.adapter != null && event.adapter.get() != null) {
|
||
event.adapter.get().notifyDataSetChanged();
|
||
}
|
||
} else {
|
||
String id = event.gift.getGift_id();
|
||
GiftPackBean selGift = null;
|
||
for (int i = 0; i < giftPackList.size(); i++) {
|
||
GiftPackBean giftModel = giftPackList.get(i);
|
||
RoonGiftModel roonGiftModel = new RoonGiftModel();
|
||
roonGiftModel.setGift_id(giftModel.getGift_id());
|
||
roonGiftModel.setGift_name(giftModel.getGift_name());
|
||
roonGiftModel.setGift_price(giftModel.getGift_price());
|
||
roonGiftModel.setBase_image(giftModel.getBase_image());
|
||
roonGiftModel.setNum(Integer.parseInt(giftModel.getNum()));
|
||
if (giftModel.getGift_id().equals(id)) {
|
||
selGift = giftModel;
|
||
if (!giftModel.isChecked()) {
|
||
EventBus.getDefault().post(new GiftUserRefreshEvent(true, event.type, roonGiftModel));
|
||
giftModel.setChecked(true);
|
||
}
|
||
} else {
|
||
giftModel.setChecked(false);
|
||
EventBus.getDefault().post(new GiftUserRefreshEvent(false, event.type, null));
|
||
}
|
||
}
|
||
if (event.adapter != null && event.adapter.get() != null) {
|
||
event.adapter.get().notifyDataSetChanged();
|
||
}
|
||
if (selGift != null) {
|
||
EventBus.getDefault().post(new GiftDoubleClickEvent());
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||
public void onGiftClicRoomkTEvent(RoomGiftClickToEvent event) {
|
||
if (giftList == null) {
|
||
giftList = new ArrayList<>();
|
||
giftList.add(event.gift);
|
||
}
|
||
if (event.type == 1) {
|
||
String id = event.gift.getGift_id();
|
||
for (int i = 0; i < giftList.size(); i++) {
|
||
RoonGiftModel giftModel = giftList.get(i);
|
||
if (giftModel.getGift_id().equals(id)) {
|
||
if (giftModel.isChecked()) {
|
||
giftModel.setChecked(false);
|
||
EventBus.getDefault().post(new GiftUserRefreshEvent(false, event.type, null));
|
||
} else {
|
||
giftModel.setChecked(true);
|
||
EventBus.getDefault().post(new GiftUserRefreshEvent(true, event.type, event.gift));
|
||
}
|
||
} else {
|
||
giftModel.setChecked(false);
|
||
}
|
||
}
|
||
if (event.adapter != null && event.adapter.get() != null) {
|
||
event.adapter.get().notifyDataSetChanged();
|
||
}
|
||
} else if (event.type == 2) {
|
||
String id = event.gift.getGift_id();
|
||
RoonGiftModel selGift = null;
|
||
for (int i = 0; i < giftList.size(); i++) {
|
||
RoonGiftModel giftModel = giftList.get(i);
|
||
if (giftModel.getGift_id().equals(id)) {
|
||
selGift = giftModel;
|
||
if (giftModel.isChecked()) {
|
||
giftModel.setChecked(false);
|
||
EventBus.getDefault().post(new GiftUserRefreshEvent(false, event.type, null));
|
||
} else {
|
||
giftModel.setChecked(true);
|
||
EventBus.getDefault().post(new GiftUserRefreshEvent(giftModel.isCan_send_self(), event.type, event.gift));
|
||
}
|
||
} else {
|
||
giftModel.setChecked(false);
|
||
}
|
||
}
|
||
if (event.adapter != null && event.adapter.get() != null) {
|
||
event.adapter.get().notifyDataSetChanged();
|
||
}
|
||
if (selGift != null) {
|
||
EventBus.getDefault().post(new GiftDoubleClickEvent());
|
||
}
|
||
}
|
||
}
|
||
|
||
} |