Merge branch 'dev_use_discounts'

# Conflicts:
#	common/src/main/res/values/strings.xml
This commit is contained in:
zlzw 2023-03-31 17:27:24 +08:00
commit 48f1d42739
8 changed files with 294 additions and 47 deletions

View File

@ -0,0 +1,109 @@
package com.yunbao.common.bean;
import androidx.annotation.NonNull;
import com.google.gson.annotations.SerializedName;
/**
* 优惠卷
*/
public class DiscountsModel extends BaseModel {
//------------------贵族--------------------
public static final int TYPE_VISCOUNT=1;//子爵
public static final int TYPE_MARQUIS=2;//侯爵
public static final int TYPE_DUKE=3;//公爵
public static final int TYPE_KING=4;//国王
public static final int TYPE_EMPEROR=5;//皇帝
//------------------守护--------------------
public static final int TYPE_WEEKS=6;//周守护
public static final int TYPE_MONTH=7;//月守护
public static final int TYPE_YEARS=8;//月守护
@SerializedName("userCouponId")
private int userCouponID;
@SerializedName("num")
private int num;
@SerializedName("endTime")
private long endTime;
@SerializedName("img")
private String img;
@SerializedName("name")
private String name;
@SerializedName("discount")
private double discount;
@SerializedName("describe")
private String describe;
public DiscountsModel() {
}
public int getUserCouponID() {
return userCouponID;
}
public void setUserCouponID(int userCouponID) {
this.userCouponID = userCouponID;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public long getEndTime() {
return endTime;
}
public void setEndTime(long endTime) {
this.endTime = endTime;
}
public String getImg() {
return img;
}
public void setImg(String img) {
this.img = img;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getDiscount() {
return discount;
}
public void setDiscount(double discount) {
this.discount = discount;
}
public String getDescribe() {
return describe;
}
public void setDescribe(String describe) {
this.describe = describe;
}
@NonNull
@Override
public String toString() {
return "DiscountsModel{" +
"userCouponID=" + userCouponID +
", num=" + num +
", endTime=" + endTime +
", img='" + img + '\'' +
", name='" + name + '\'' +
", discount=" + discount +
", describe='" + describe + '\'' +
'}';
}
}

View File

@ -7,6 +7,7 @@ import com.yunbao.common.bean.BaseModel;
import com.yunbao.common.bean.CheckLiveModel;
import com.yunbao.common.bean.ContributeModel;
import com.yunbao.common.bean.CustomSidebarInfoModel;
import com.yunbao.common.bean.DiscountsModel;
import com.yunbao.common.bean.EnterRoomNewModel;
import com.yunbao.common.bean.FaceBookUpModel;
import com.yunbao.common.bean.HourRank;
@ -671,5 +672,11 @@ public interface PDLiveApi {
@Query("type") int type,
@Query("list") String list
);
/**
* 获取折扣卷信息
*/
@GET("/api/public/?service=Coupon.getUserCoupon")
Observable<ResponseModel<List<DiscountsModel>>> getDiscountInfo(
@Query("type") int type
);
}

View File

@ -10,6 +10,7 @@ import com.yunbao.common.bean.ActiveModel;
import com.yunbao.common.bean.BaseModel;
import com.yunbao.common.bean.CheckLiveModel;
import com.yunbao.common.bean.CustomSidebarInfoModel;
import com.yunbao.common.bean.DiscountsModel;
import com.yunbao.common.bean.EnterRoomNewModel;
import com.yunbao.common.bean.HttpCallbackModel;
import com.yunbao.common.bean.LinkMicUserBean;
@ -1357,6 +1358,27 @@ public class LiveNetManager {
}
}).isDisposed();
}
public void getDiscountInfo(int type,HttpCallback<List<DiscountsModel>> callback) {
API.get().pdLiveApi(mContext)
.getDiscountInfo(type)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Consumer<ResponseModel<List<DiscountsModel>>>() {
@Override
public void accept(ResponseModel<List<DiscountsModel>> wishListGiftConfModelResponseModel) throws Exception {
if (callback != null) {
callback.onSuccess(wishListGiftConfModelResponseModel.getData().getInfo());
}
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
if (callback != null) {
callback.onError(throwable.getMessage());
}
}
}).isDisposed();
}
/**
* 直播间取消网络请求

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

@ -1109,5 +1109,8 @@
<string name="replacement_reset_confirmed_cancel3">当前心愿单未保存</string>
<string name="replacement_reset_confirmed_cancel4">不保存</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;
@ -24,10 +25,12 @@ import com.makeramen.roundedimageview.RoundedImageView;
import com.opensource.svgaplayer.SVGAImageView;
import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.Constants;
import com.yunbao.common.bean.DiscountsModel;
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;
@ -362,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() {
@Override
public void onConfirmClick(Dialog dialog, String content) {
doBuyGuard();
}
});
}
/**
@ -380,7 +376,96 @@ public class LiveNewGuardBuyDialogFragment extends AbsDialogFragment implements
if (mTargetBuyBean == null) {
return;
}
LiveHttpUtil.buyGuard(mLiveUid, mStream, mTargetBuyBean.getId(), new HttpCallback() {
int discountType = 0;
switch (mTargetBuyBean.getType()) {
case Constants.GUARD_TYPE_DAY:
discountType = DiscountsModel.TYPE_WEEKS;
break;
case Constants.GUARD_TYPE_MONTH:
discountType = DiscountsModel.TYPE_MONTH;
break;
case Constants.GUARD_TYPE_YEAR:
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();
}
@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) {