红包直播间展示样式构建

This commit is contained in:
18401019693
2023-06-26 18:04:58 +08:00
parent 6889828c00
commit 279575d80b
12 changed files with 483 additions and 9 deletions

View File

@@ -0,0 +1,146 @@
package com.yunbao.live.dialog;
import android.content.Context;
import android.graphics.Color;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.widget.Button;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.lxj.xpopup.core.CenterPopupView;
import com.yunbao.common.utils.ToastUtil;
import com.yunbao.common.views.weight.ViewClicksAntiShake;
import com.yunbao.live.R;
public class SendRendPacketPopup extends CenterPopupView {
private Button thereIsNo, followingAnchor;
private TextView redEnvelopeRill, totalConsumptionOfDrill;
private TextView rill, total;
public SendRendPacketPopup(@NonNull Context context) {
super(context);
}
// 返回自定义弹窗的布局离开
@Override
protected int getImplLayoutId() {
return R.layout.view_send_red_packet;
}
// 执行初始化操作比如findView设置点击或者任何你弹窗内的业务逻辑
@Override
protected void onCreate() {
super.onCreate();
initView();
}
private void initView() {
thereIsNo = findViewById(R.id.there_is_no);
followingAnchor = findViewById(R.id.following_anchor);
redEnvelopeRill = findViewById(R.id.red_envelope_rill);
totalConsumptionOfDrill = findViewById(R.id.total_consumption_of_drill);
rill = findViewById(R.id.rill);
total = findViewById(R.id.total);
selectText(thereIsNo, true);
selectText(followingAnchor, false);
ViewClicksAntiShake.clicksAntiShake(thereIsNo, () -> {
selectText(thereIsNo, true);
selectText(followingAnchor, false);
});
ViewClicksAntiShake.clicksAntiShake(followingAnchor, () -> {
selectText(thereIsNo, false);
selectText(followingAnchor, true);
});
redEnvelopeRill.setText(String.format(getContext().getString(R.string.red_envelope_rill), "0"));
totalConsumptionOfDrill.setText(String.format(getContext().getString(R.string.total_consumption_of_drill), "0"));
rill.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
String number = s.toString();
String rillNumber = total.getText().toString();
int totalInt = 0;
try {
totalInt = Integer.parseInt(rillNumber);
} catch (NumberFormatException e) {
totalInt = 0;
}
if (TextUtils.isEmpty(number)) {
redEnvelopeRill.setText(String.format(getContext().getString(R.string.red_envelope_rill), "0"));
totalConsumptionOfDrill.setText(String.format(getContext().getString(R.string.total_consumption_of_drill), "0"));
} else {
int numberInt = Integer.parseInt(number);
if (numberInt >= 200 && numberInt <= 10000) {
totalConsumptionOfDrill.setText(String.format(getContext().getString(R.string.total_consumption_of_drill), String.valueOf((totalInt * numberInt))));
redEnvelopeRill.setText(String.format(getContext().getString(R.string.red_envelope_rill), s.toString()));
} else {
ToastUtil.show(String.format(getContext().getString(R.string.range_range_is), "200~10000"));
}
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
total.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
String number = s.toString();
String rillNumber = rill.getText().toString();
int rillInt = 0;
try {
rillInt = Integer.parseInt(rillNumber);
} catch (NumberFormatException e) {
rillInt = 0;
}
if (TextUtils.isEmpty(number)) {
totalConsumptionOfDrill.setText(String.format(getContext().getString(R.string.total_consumption_of_drill), "0"));
} else {
int numberInt = Integer.parseInt(number);
if (numberInt >= 1 && numberInt <= 100) {
totalConsumptionOfDrill.setText(String.format(getContext().getString(R.string.total_consumption_of_drill), String.valueOf((rillInt * numberInt))));
} else {
ToastUtil.show(String.format(getContext().getString(R.string.range_range_is), "1~100"));
}
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
//红包初始数量
rill.setText("200");
total.setText("10");
}
private void selectText(TextView textView, boolean select) {
textView.setSelected(select);
if (select) {
textView.setTextColor(Color.parseColor("#E12801"));
} else {
textView.setTextColor(Color.parseColor("#FDD04A"));
}
}
}

View File

@@ -50,6 +50,7 @@ import com.bumptech.glide.load.resource.gif.GifDrawable;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.Target;
import com.lxj.xpopup.XPopup;
import com.makeramen.roundedimageview.RoundedImageView;
import com.ms.banner.Banner;
import com.ms.banner.BannerConfig;
@@ -151,6 +152,7 @@ import com.yunbao.live.dialog.LiveHDDialogFragment;
import com.yunbao.live.dialog.LiveUserAnchorMailBoxWebInfoPopDialog;
import com.yunbao.live.dialog.LiveUserDialogFragment;
import com.yunbao.live.dialog.LiveWishListDialogFragment4Audience;
import com.yunbao.live.dialog.SendRendPacketPopup;
import com.yunbao.live.event.LiveAnchorEvent;
import com.yunbao.live.event.LiveAudienceEvent;
import com.yunbao.live.event.LiveRoomChangeEvent;
@@ -1407,6 +1409,15 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis
new LoadDian9TuUtil().loadDian9TuAssets2(mContext, liveWksLayout, "rectangle_new.png", 1);
new LoadDian9TuUtil().loadDian9TuAssets2(mContext, wishListLayout2, "rectangle_new.png", 1);
//测试点开红包
ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.red_packet), new ViewClicksAntiShake.ViewClicksCallBack() {
@Override
public void onViewClicks() {
new XPopup.Builder(mContext)
.asCustom(new SendRendPacketPopup(mContext))
.show();
}
});
}
/**