Merge branch 'dev_use_discounts'
# Conflicts: # common/src/main/res/values/strings.xml
This commit is contained in:
commit
48f1d42739
109
common/src/main/java/com/yunbao/common/bean/DiscountsModel.java
Normal file
109
common/src/main/java/com/yunbao/common/bean/DiscountsModel.java
Normal 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 + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -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
|
||||
);
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 直播间取消网络请求
|
||||
|
@ -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;
|
||||
|
@ -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>
|
||||
|
@ -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;
|
||||
@ -138,7 +140,9 @@ 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();
|
||||
|
||||
@ -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) {
|
||||
|
@ -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) {
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user