From 9eed92302dc502d3d8448a365ba4918b2345f383 Mon Sep 17 00:00:00 2001
From: zlzw <583819556@qq.com>
Date: Fri, 31 Mar 2023 17:26:28 +0800
Subject: [PATCH] =?UTF-8?q?add=20=E8=B4=AD=E4=B9=B0=E5=AE=88=E6=8A=A4?=
=?UTF-8?q?=E4=BD=BF=E7=94=A8=E4=BC=98=E6=83=A0=E5=8D=B7?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../yunbao/common/bean/DiscountsModel.java | 2 +-
.../com/yunbao/common/utils/ToastUtil.java | 13 ++-
common/src/main/res/values/strings.xml | 4 +-
.../dialog/LiveGuardBuyDialogFragment.java | 68 +++++++-------
.../dialog/LiveNewGuardBuyDialogFragment.java | 89 +++++++++++++++++--
.../com/yunbao/live/http/LiveHttpUtil.java | 14 ++-
6 files changed, 142 insertions(+), 48 deletions(-)
diff --git a/common/src/main/java/com/yunbao/common/bean/DiscountsModel.java b/common/src/main/java/com/yunbao/common/bean/DiscountsModel.java
index 825b3db99..7b5c99c20 100644
--- a/common/src/main/java/com/yunbao/common/bean/DiscountsModel.java
+++ b/common/src/main/java/com/yunbao/common/bean/DiscountsModel.java
@@ -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;
diff --git a/common/src/main/java/com/yunbao/common/utils/ToastUtil.java b/common/src/main/java/com/yunbao/common/utils/ToastUtil.java
index d8245a7ab..3aa789611 100644
--- a/common/src/main/java/com/yunbao/common/utils/ToastUtil.java
+++ b/common/src/main/java/com/yunbao/common/utils/ToastUtil.java
@@ -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;
diff --git a/common/src/main/res/values/strings.xml b/common/src/main/res/values/strings.xml
index ecf31dd7a..0f4de5815 100644
--- a/common/src/main/res/values/strings.xml
+++ b/common/src/main/res/values/strings.xml
@@ -1104,6 +1104,8 @@
重置後將會清空當前心願單列表\n無論心願單是否完成
確定重置
返回列表
-
+ 您有一張%s,是否使用?使用後開通花費鉆石%s,返還金豆%s
+ 不使用
+ 使用
diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveGuardBuyDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveGuardBuyDialogFragment.java
index cff77e42b..ee759acc5 100644
--- a/live/src/main/java/com/yunbao/live/dialog/LiveGuardBuyDialogFragment.java
+++ b/live/src/main/java/com/yunbao/live/dialog/LiveGuardBuyDialogFragment.java
@@ -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);
diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveNewGuardBuyDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveNewGuardBuyDialogFragment.java
index 19492c34e..473e34caa 100644
--- a/live/src/main/java/com/yunbao/live/dialog/LiveNewGuardBuyDialogFragment.java
+++ b/live/src/main/java/com/yunbao/live/dialog/LiveNewGuardBuyDialogFragment.java
@@ -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>() {
+ @Override
+ public void onSuccess(List 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("###",
+ " " + coinStr + " "));
+ 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) {
diff --git a/live/src/main/java/com/yunbao/live/http/LiveHttpUtil.java b/live/src/main/java/com/yunbao/live/http/LiveHttpUtil.java
index a86c2906d..72ec2881f 100644
--- a/live/src/main/java/com/yunbao/live/http/LiveHttpUtil.java
+++ b/live/src/main/java/com/yunbao/live/http/LiveHttpUtil.java
@@ -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 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) {