add 购买守护使用优惠卷

This commit is contained in:
zlzw 2023-03-31 17:26:28 +08:00
parent 0177a1314d
commit 9eed92302d
6 changed files with 142 additions and 48 deletions

View File

@ -19,7 +19,7 @@ public class DiscountsModel extends BaseModel {
public static final int TYPE_MONTH=7;//月守护
public static final int TYPE_YEARS=8;//月守护
@SerializedName("userCouponID")
@SerializedName("userCouponId")
private int userCouponID;
@SerializedName("num")
private int num;

View File

@ -3,6 +3,7 @@ package com.yunbao.common.utils;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
@ -13,6 +14,7 @@ import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import com.yunbao.common.BuildConfig;
import com.yunbao.common.CommonAppContext;
import com.yunbao.common.R;
@ -76,7 +78,16 @@ public class ToastUtil {
dialog.show();
new Handler(Looper.getMainLooper()).postDelayed(dialog::dismiss, delayMillis);
}
public static void showDebug(String s){
if(BuildConfig.DEBUG){
show(s);
}
}
public static void showDebug(int s){
if(BuildConfig.DEBUG){
show(s);
}
}
public static void show(String s) {
if (TextUtils.isEmpty(s)) {
return;

View File

@ -1104,6 +1104,8 @@
<string name="replacement_reset_confirmed_hint">重置後將會清空當前心願單列表\n無論心願單是否完成</string>
<string name="replacement_reset_confirmed_sure">確定重置</string>
<string name="replacement_reset_confirmed_cancel">返回列表</string>
<string name="live_use_discount_content">您有一張%s是否使用使用後開通花費鉆石%s返還金豆%s</string>
<string name="live_use_discount_no">不使用</string>
<string name="live_use_discount_yes">使用</string>
</resources>

View File

@ -3,10 +3,12 @@ package com.yunbao.live.dialog;
import android.app.Dialog;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
@ -52,7 +54,7 @@ public class LiveGuardBuyDialogFragment extends AbsDialogFragment implements Vie
private RadioGroup mRadioGroup;
private RadioButton[] mRadioBtns;
private TextView mCoinNameTextView;
private TextView txt1,txt2,txt3;
private TextView txt1, txt2, txt3;
private TextView mCoin;
private String mCoinName;
private View mBtnBuy;
@ -108,9 +110,9 @@ public class LiveGuardBuyDialogFragment extends AbsDialogFragment implements Vie
mRadioBtns[1] = (RadioButton) mRootView.findViewById(R.id.btn_2);
mRadioBtns[2] = (RadioButton) mRootView.findViewById(R.id.btn_3);
txt1 = (TextView)mRootView.findViewById(R.id.txt_1);
txt2 = (TextView)mRootView.findViewById(R.id.txt_2);
txt3 = (TextView)mRootView.findViewById(R.id.txt_3);
txt1 = (TextView) mRootView.findViewById(R.id.txt_1);
txt2 = (TextView) mRootView.findViewById(R.id.txt_2);
txt3 = (TextView) mRootView.findViewById(R.id.txt_3);
mCoinNameTextView = (TextView) mRootView.findViewById(R.id.coin_name);
mCoin = (TextView) mRootView.findViewById(R.id.coin);
@ -125,7 +127,7 @@ public class LiveGuardBuyDialogFragment extends AbsDialogFragment implements Vie
if (bundle != null) {
mLiveUid = bundle.getString(Constants.LIVE_UID);
mStream = bundle.getString(Constants.STREAM);
String coinName = WordUtil.getString(R.string.diamond) ;
String coinName = WordUtil.getString(R.string.diamond);
mCoinName = coinName;
mCoinNameTextView.setText(WordUtil.getString(R.string.guard_my) + coinName + ":");
}
@ -138,34 +140,36 @@ public class LiveGuardBuyDialogFragment extends AbsDialogFragment implements Vie
mBuyList = JSON.parseArray(obj.getString("list"), GuardBuyBean.class);
try {
mCoinVal = obj.getLongValue("coin");
}catch (Exception e){e.printStackTrace();}
} catch (Exception e) {
e.printStackTrace();
}
mCoin.setText(String.valueOf(mCoinVal));
int buyListSize = mBuyList.size();
for (int i = 0, length = mRadioBtns.length; i < length; i++) {
if (i < buyListSize) {
GuardBuyBean buyBean = mBuyList.get(i);
if(i == 0){
if(CommonAppContext.lang.equals("chinese")){
txt1.setText(("贈送"+buyBean.getCoin()+"金豆"));
}else{
txt1.setText(("Free gold beans"+buyBean.getCoin()));
if (i == 0) {
if (CommonAppContext.lang.equals("chinese")) {
txt1.setText(("贈送" + buyBean.getCoin() + "金豆"));
} else {
txt1.setText(("Free gold beans" + buyBean.getCoin()));
}
}else if(i == 1){
if(CommonAppContext.lang.equals("chinese")){
txt2.setText(("贈送"+buyBean.getCoin()+"金豆"));
}else{
txt2.setText(("Free gold beans"+buyBean.getCoin()));
} else if (i == 1) {
if (CommonAppContext.lang.equals("chinese")) {
txt2.setText(("贈送" + buyBean.getCoin() + "金豆"));
} else {
txt2.setText(("Free gold beans" + buyBean.getCoin()));
}
}else if(i == 2){
if(CommonAppContext.lang.equals("chinese")){
txt3.setText(("贈送"+buyBean.getCoin()+"金豆"));
}else{
txt3.setText(("Free gold beans"+buyBean.getCoin()));
} else if (i == 2) {
if (CommonAppContext.lang.equals("chinese")) {
txt3.setText(("贈送" + buyBean.getCoin() + "金豆"));
} else {
txt3.setText(("Free gold beans" + buyBean.getCoin()));
}
}
mRadioBtns[i].setText(StringUtil.contact(buyBean.getName(), "\n", String.valueOf(buyBean.getCoin()),mCoinName));
mRadioBtns[i].setText(StringUtil.contact(buyBean.getName(), "\n", String.valueOf(buyBean.getCoin()), mCoinName));
}
}
refreshList(0);
@ -252,14 +256,14 @@ public class LiveGuardBuyDialogFragment extends AbsDialogFragment implements Vie
if (TextUtils.isEmpty(mLiveUid) || TextUtils.isEmpty(mStream) || mLiveGuardInfo == null || mTargetBuyBean == null) {
return;
}
Log.d("ffffff",""+mLiveGuardInfo.getMyGuardType()+" "+mTargetBuyBean.getType());
if (mLiveGuardInfo.getMyGuardType()==Constants.GUARD_TYPE_MONTH && mTargetBuyBean.getType()==Constants.GUARD_TYPE_DAY) {
Log.d("ffffff", "" + mLiveGuardInfo.getMyGuardType() + " " + mTargetBuyBean.getType());
if (mLiveGuardInfo.getMyGuardType() == Constants.GUARD_TYPE_MONTH && mTargetBuyBean.getType() == Constants.GUARD_TYPE_DAY) {
DialogUitl.showSimpleTipDialog(mContext, WordUtil.getString(R.string.guard_buy_tip));
return;
}else if (mLiveGuardInfo.getMyGuardType()==Constants.GUARD_TYPE_YEAR && mTargetBuyBean.getType()==Constants.GUARD_TYPE_DAY) {
} else if (mLiveGuardInfo.getMyGuardType() == Constants.GUARD_TYPE_YEAR && mTargetBuyBean.getType() == Constants.GUARD_TYPE_DAY) {
DialogUitl.showSimpleTipDialog(mContext, "您為當前主播的年守護無法開通周守護");
return;
}else if (mLiveGuardInfo.getMyGuardType()==Constants.GUARD_TYPE_YEAR&& mTargetBuyBean.getType()==Constants.GUARD_TYPE_MONTH) {
} else if (mLiveGuardInfo.getMyGuardType() == Constants.GUARD_TYPE_YEAR && mTargetBuyBean.getType() == Constants.GUARD_TYPE_MONTH) {
DialogUitl.showSimpleTipDialog(mContext, "您為當前主播的年守護無法開通月守護");
return;
} else {
@ -272,8 +276,8 @@ public class LiveGuardBuyDialogFragment extends AbsDialogFragment implements Vie
}
});
return;
}else if(mLiveGuardInfo.getMyGuardType() == Constants.GUARD_TYPE_DAY
&& mTargetBuyBean.getType() == Constants.GUARD_TYPE_MONTH){
} else if (mLiveGuardInfo.getMyGuardType() == Constants.GUARD_TYPE_DAY
&& mTargetBuyBean.getType() == Constants.GUARD_TYPE_MONTH) {
DialogUitl.showSimpleDialog(mContext, "您為當前主播的周守護,開通月守護將覆蓋您的周守護時長,是否開通?", new DialogUitl.SimpleCallback() {
@Override
public void onConfirmClick(Dialog dialog, String content) {
@ -281,8 +285,8 @@ public class LiveGuardBuyDialogFragment extends AbsDialogFragment implements Vie
}
});
return;
}else if(mLiveGuardInfo.getMyGuardType() == Constants.GUARD_TYPE_DAY
&& mTargetBuyBean.getType() == Constants.GUARD_TYPE_YEAR){
} else if (mLiveGuardInfo.getMyGuardType() == Constants.GUARD_TYPE_DAY
&& mTargetBuyBean.getType() == Constants.GUARD_TYPE_YEAR) {
DialogUitl.showSimpleDialog(mContext, "您為當前主播的周守護,開通年守護將覆蓋您的周守護時長,是否開通?", new DialogUitl.SimpleCallback() {
@Override
public void onConfirmClick(Dialog dialog, String content) {
@ -321,7 +325,7 @@ public class LiveGuardBuyDialogFragment extends AbsDialogFragment implements Vie
if (mTargetBuyBean == null) {
return;
}
LiveHttpUtil.buyGuard(mLiveUid, mStream, mTargetBuyBean.getId(), new HttpCallback() {
LiveHttpUtil.buyGuard(mLiveUid, mStream, mTargetBuyBean.getId(), -1, new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
if (code == 0 && info.length > 0) {
@ -344,7 +348,7 @@ public class LiveGuardBuyDialogFragment extends AbsDialogFragment implements Vie
u.setCoin(coinString);
u.setLevel(obj.getIntValue("level"));
}
((LiveActivity) mContext).sendBuyGuardMessage2(votes, guardNum, guardType,ancherName,liveuid);
((LiveActivity) mContext).sendBuyGuardMessage2(votes, guardNum, guardType, ancherName, liveuid);
dismiss();
}
ToastUtil.show(msg);

View File

@ -2,6 +2,7 @@ package com.yunbao.live.dialog;
import android.app.Dialog;
import android.os.Bundle;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
@ -29,6 +30,7 @@ import com.yunbao.common.bean.UserBean;
import com.yunbao.common.dialog.AbsDialogFragment;
import com.yunbao.common.glide.ImgLoader;
import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.http.live.LiveNetManager;
import com.yunbao.common.utils.DialogUitl;
import com.yunbao.common.utils.RouteUtil;
import com.yunbao.common.utils.ToastUtil;
@ -363,15 +365,8 @@ public class LiveNewGuardBuyDialogFragment extends AbsDialogFragment implements
if (mTargetBuyBean == null) {
return;
}
DialogUitl.showSimpleDialog(mContext,
String.format(WordUtil.getString(R.string.guard_buy_tip_3), mTargetBuyBean.getCoin(), mCoinName, mTargetBuyBean.getShopName()),
new DialogUitl.SimpleCallback() {
doBuyGuard();
@Override
public void onConfirmClick(Dialog dialog, String content) {
doBuyGuard();
}
});
}
/**
@ -393,8 +388,84 @@ public class LiveNewGuardBuyDialogFragment extends AbsDialogFragment implements
discountType = DiscountsModel.TYPE_YEARS;
break;
}
if (discountType == 0) {
buy();
} else {
LiveNetManager.get(mContext)
.getDiscountInfo(discountType, new com.yunbao.common.http.base.HttpCallback<List<DiscountsModel>>() {
@Override
public void onSuccess(List<DiscountsModel> data) {
if (data == null || data.isEmpty()) {
buy();
return;
}
DiscountsModel bean = null;
//寻找折扣力度最大的
for (DiscountsModel datum : data) {
if (bean == null) {
bean = datum;
} else if (datum.getDiscount() < bean.getDiscount()) {
bean = datum;
}
}
String str = String.format(WordUtil.getString(R.string.live_use_discount_content),
bean.getName(),
"###",//占位符
"###"
);
double coin = (mTargetBuyBean.getCoin() * (bean.getDiscount() / 10));
//千分位计算 12000 > 12,000
String coinStr = coin + "";
if (coin >= 1000) {
coinStr = ((int) coin / 1000) + "," + ((int) coin % 1000);
}
CharSequence content = Html.fromHtml(str.replace("###",
" <font color='#FF8E43'>" + coinStr + "</font> "));
final int cid = bean.getUserCouponID();
Dialog dialog = new DialogUitl.Builder(mContext)
.setHtmlCode(content)
.setView(R.layout.dialog_live_random_pk)
.setTitle(WordUtil.getString(R.string.dialog_tip))
.setCancelString(WordUtil.getString(R.string.live_use_discount_no))
.setConfrimString(WordUtil.getString(R.string.live_use_discount_yes))
.setClickCallback(new DialogUitl.SimpleCallback2() {
@Override
public void onCancelClick() {
buy();
}
LiveHttpUtil.buyGuard(mLiveUid, mStream, mTargetBuyBean.getId(), new HttpCallback() {
@Override
public void onConfirmClick(Dialog dialog, String content) {
buy(cid);
}
}).build();
dialog.show();
}
@Override
public void onError(String error) {
}
});
}
}
private void buy() {
DialogUitl.showSimpleDialog(mContext,
String.format(WordUtil.getString(R.string.guard_buy_tip_3), mTargetBuyBean.getCoin(), mCoinName, mTargetBuyBean.getShopName()),
new DialogUitl.SimpleCallback() {
@Override
public void onConfirmClick(Dialog dialog, String content) {
buy(-1);
}
});
}
private void buy(int cid) {
LiveHttpUtil.buyGuard(mLiveUid, mStream, mTargetBuyBean.getId(), cid, new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
if (code == 0 && info.length > 0) {

View File

@ -2,6 +2,7 @@ package com.yunbao.live.http;
import android.text.TextUtils;
import com.lzy.okgo.request.GetRequest;
import com.lzy.okgo.request.PostRequest;
import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.CommonAppContext;
@ -322,12 +323,16 @@ public class LiveHttpUtil {
/**
* 购买守护接口
*/
public static void buyGuard(String liveUid, String stream, int guardId, HttpCallback callback) {
HttpClient.getInstance().get("Guard.buyGuard", LiveHttpConsts.BUY_GUARD)
public static void buyGuard(String liveUid, String stream, int guardId, int cid, HttpCallback callback) {
GetRequest<JsonBean> request = HttpClient.getInstance().get("Guard.buyGuard", LiveHttpConsts.BUY_GUARD)
.params("liveuid", liveUid)
.params("stream", stream)
.params("guardid", guardId)
.execute(callback);
.params("guardid", guardId);
if (cid != -1) {
request = request.params("userCouponId", cid);
}
request.execute(callback);
}
@ -611,6 +616,7 @@ public class LiveHttpUtil {
/**
* 观众给主播送礼物
*
* @param isContactGift 是否为联系方式礼物
*/
public static void sendGift(String by, String liveUid, String stream, int giftId, String giftCount, int isContactGift, HttpCallback callback) {