pdlivexp/live/src/main/java/com/yunbao/live/dialog/ReceiveRendPacketPopup.java
2023-07-03 13:05:29 +08:00

223 lines
9.2 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.yunbao.live.dialog;
import android.content.Context;
import android.os.Handler;
import android.text.TextUtils;
import android.util.TypedValue;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.CenterPopupView;
import com.yunbao.common.bean.IMLoginModel;
import com.yunbao.common.bean.RedPacketInfoModel;
import com.yunbao.common.glide.ImgLoader;
import com.yunbao.common.http.CommonHttpUtil;
import com.yunbao.common.http.base.HttpCallback;
import com.yunbao.common.http.live.LiveNetManager;
import com.yunbao.common.interfaces.CommonCallback;
import com.yunbao.common.manager.IMLoginManager;
import com.yunbao.common.utils.TimeUtils;
import com.yunbao.common.views.weight.CircleProgress;
import com.yunbao.common.views.weight.ClipPathCircleImage;
import com.yunbao.common.views.weight.ViewClicksAntiShake;
import com.yunbao.live.R;
import com.yunbao.live.adapter.RedPacketGiftAdapter;
public class ReceiveRendPacketPopup extends CenterPopupView {
private CircleProgress circleProgress;
private int time = 10;
private Button redPacketOpen;
private TextView redPacketTimeText, receiveRed, redPacketValue;
private FrameLayout redPacketTimeLayout;
private String mLiveUid, stream, redPacketId, userID;
private ClipPathCircleImage headPortrait;
private RecyclerView redPacketGiftList;
private RedPacketGiftAdapter redPacketGiftAdapter;
private ImageView isAttention;
private RedPacketInfoModel redPacketInfoModel;
private boolean isSuperJackpot;
public ReceiveRendPacketPopup(@NonNull Context context, int time, String mLiveUid, String stream,
String redPacketId, RedPacketInfoModel redPacketInfoModel,
boolean isSuperJackpot) {
super(context);
this.time = time;
this.mLiveUid = mLiveUid;
this.stream = stream;
this.redPacketId = redPacketId;
this.redPacketInfoModel = redPacketInfoModel;
this.isSuperJackpot = isSuperJackpot;
}
// 返回自定义弹窗的布局离开
@Override
protected int getImplLayoutId() {
return R.layout.view_receive_red_packet;
}
// 执行初始化操作比如findView设置点击或者任何你弹窗内的业务逻辑
@Override
protected void onCreate() {
super.onCreate();
initView();
initData();
}
private void initData() {
ImgLoader.displayAvatar(getContext(), redPacketInfoModel.getAvatar(), headPortrait);
redPacketValue.setText(redPacketInfoModel.getAmountDiamond());
redPacketGiftAdapter.addData(redPacketInfoModel.getPacketGiftModels());
IMLoginModel userInfo = IMLoginManager.get(getContext()).getUserInfo();
if (TextUtils.equals(String.valueOf(userInfo.getId()), redPacketInfoModel.getUid())) {
isAttention.setVisibility(GONE);
} else {
isAttention.setVisibility(TextUtils.equals(redPacketInfoModel.getIsAttention(), "0") ? VISIBLE : GONE);
}
if (isSuperJackpot) {
receiveRed.setText(redPacketInfoModel.getUserNicename());
} else {
receiveRed.setText(String.format(getContext()
.getString(R.string.together_to_achieve_goal),
redPacketInfoModel.getUserNicename()));
}
userID = redPacketInfoModel.getUserId();
}
private Handler timeHandler = new Handler();
private Runnable timeRunnable = new Runnable() {
@Override
public void run() {
if (time > 0) {
circleProgress.setCurrent(time--);
timeHandler.postDelayed(timeRunnable, 1000);
String countdown = TimeUtils.getTime(time);
if (countdown.length() < 4) {
redPacketTimeText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 36);
} else {
redPacketTimeText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 23);
}
redPacketTimeText.setText(countdown);
} else {
redPacketTimeLayout.setVisibility(GONE);
redPacketOpen.setVisibility(VISIBLE);
}
}
};
private void initView() {
circleProgress = findViewById(R.id.circleProgress);
redPacketOpen = findViewById(R.id.red_packet_open);
redPacketTimeText = findViewById(R.id.red_packet_time_text);
redPacketTimeLayout = findViewById(R.id.red_packet_time_layout);
receiveRed = findViewById(R.id.receive_red);
redPacketValue = findViewById(R.id.red_packet_value);
headPortrait = findViewById(R.id.head_portrait);
isAttention = findViewById(R.id.is_attention);
redPacketGiftList = findViewById(R.id.red_packet_gift_list);
redPacketGiftList.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));
redPacketGiftAdapter = new RedPacketGiftAdapter();
redPacketGiftList.setAdapter(redPacketGiftAdapter);
if (time > 0) {
circleProgress.setMax(time);
circleProgress.setCurrent(time);
String countdown = TimeUtils.getTime(time);
if (countdown.length() < 4) {
redPacketTimeText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 36);
} else {
redPacketTimeText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 23);
}
redPacketTimeText.setText(countdown);
timeHandler.postDelayed(timeRunnable, 1000);
} else {
redPacketTimeLayout.setVisibility(GONE);
redPacketOpen.setVisibility(VISIBLE);
}
ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.red_packet_open), () -> {
if (isSuperJackpot) {
LiveNetManager.get(getContext())
.getRedPacketSuperPrize(mLiveUid, redPacketInfoModel.getSuperJackpotId(), new HttpCallback<RedPacketInfoModel>() {
@Override
public void onSuccess(RedPacketInfoModel data) {
dismiss();
new XPopup.Builder(getContext())
.asCustom(new ResultRendPacketPopup(getContext(),
false,
data.setSuperJackpotId(redPacketInfoModel.getSuperJackpotId()),
isSuperJackpot))
.show();
}
@Override
public void onError(String error) {
dismiss();
new XPopup.Builder(getContext())
.asCustom(new ResultRendPacketPopup(getContext(),
true,
null,
isSuperJackpot))
.show();
}
});
} else {
LiveNetManager.get(getContext())
.getRedPacket(mLiveUid, stream, redPacketId, new HttpCallback<RedPacketInfoModel>() {
@Override
public void onSuccess(RedPacketInfoModel data) {
dismiss();
new XPopup.Builder(getContext())
.asCustom(new ResultRendPacketPopup(getContext(),
false,
data.setRedPacketId(redPacketId),
isSuperJackpot))
.show();
}
@Override
public void onError(String error) {
dismiss();
new XPopup.Builder(getContext())
.asCustom(new ResultRendPacketPopup(getContext(),
true,
null,
isSuperJackpot))
.show();
}
});
}
});
ViewClicksAntiShake.clicksAntiShake(isAttention, new ViewClicksAntiShake.ViewClicksCallBack() {
@Override
public void onViewClicks() {
CommonHttpUtil.setAttention(userID, new CommonCallback<Integer>() {
@Override
public void callback(Integer attention) {
if (attention == 1) {
isAttention.setVisibility(GONE);
}
}
});
}
});
}
}