package com.tejia.lijin.app.ui.dialog;
|
|
import android.app.Activity;
|
import android.app.Dialog;
|
import android.content.Context;
|
import android.content.DialogInterface;
|
import android.view.Gravity;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.view.ViewGroup.LayoutParams;
|
import android.view.WindowManager;
|
import android.widget.FrameLayout;
|
import android.widget.ImageView;
|
import android.widget.TextView;
|
import android.widget.Toast;
|
|
import com.bumptech.glide.Glide;
|
import com.tejia.lijin.app.R;
|
import com.tejia.lijin.app.entity.TaoBaoGoodsBrief;
|
|
import java.math.BigDecimal;
|
|
public class CustomGoodsDetailBottomDialog extends Dialog {
|
|
public CustomGoodsDetailBottomDialog(Context context) {
|
super(context);
|
}
|
|
public CustomGoodsDetailBottomDialog(Context context, int theme) {
|
super(context, theme);
|
}
|
|
public static class Builder {
|
private Activity context;
|
private TaoBaoGoodsBrief mInfo;
|
private String userHongbao;
|
private String positiveButtonText;
|
private String negativeButtonText;
|
private OnClickListener positiveButtonClickListener;
|
private OnClickListener negativeButtonClickListener;
|
|
public Builder(Activity context) {
|
this.context = context;
|
}
|
|
public Builder setInfo(TaoBaoGoodsBrief info) {
|
this.mInfo = info;
|
return this;
|
}
|
|
public Builder setSurplus(String userHongbao) {
|
this.userHongbao = userHongbao;
|
return this;
|
}
|
|
|
/**
|
* Set the positive button resource and it's listener
|
*
|
* @param positiveButtonText
|
* @return
|
*/
|
public Builder setPositiveButton(int positiveButtonText,
|
OnClickListener listener) {
|
this.positiveButtonText = (String) context
|
.getText(positiveButtonText);
|
this.positiveButtonClickListener = listener;
|
return this;
|
}
|
|
public Builder setPositiveButton(String positiveButtonText,
|
OnClickListener listener) {
|
this.positiveButtonText = positiveButtonText;
|
this.positiveButtonClickListener = listener;
|
return this;
|
}
|
|
public Builder setNegativeButton(int negativeButtonText,
|
OnClickListener listener) {
|
this.negativeButtonText = (String) context
|
.getText(negativeButtonText);
|
this.negativeButtonClickListener = listener;
|
return this;
|
}
|
|
public Builder setNegativeButton(String negativeButtonText,
|
OnClickListener listener) {
|
this.negativeButtonText = negativeButtonText;
|
this.negativeButtonClickListener = listener;
|
return this;
|
}
|
|
CustomGoodsDetailBottomDialog dialog;
|
int num;
|
|
public CustomGoodsDetailBottomDialog create() {
|
LayoutInflater inflater = (LayoutInflater) context
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
// instantiate the dialog with the custom Theme
|
WindowManager wm = (WindowManager) context
|
.getSystemService(Context.WINDOW_SERVICE);
|
|
int width = wm.getDefaultDisplay().getWidth();
|
dialog = new CustomGoodsDetailBottomDialog(context,
|
R.style.Dialog);
|
|
View layout = inflater.inflate(R.layout.custom_goods_detail_bottom_dialog,
|
null);
|
dialog.addContentView(layout, new LayoutParams(
|
LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
|
// set the cancel button
|
dialog.setContentView(layout);
|
|
ImageView iv_goods_img = layout.findViewById(R.id.iv_goods_img);
|
TextView tv_goods_price_coupon = layout.findViewById(R.id.tv_goods_price_coupon);
|
TextView tv_rebate_num = layout.findViewById(R.id.tv_rebate_num);
|
TextView tv_goods_price_before = layout.findViewById(R.id.tv_goods_price_before);
|
TextView tv_share_red_packet_date = layout.findViewById(R.id.tv_share_red_packet_date);
|
TextView tv_share_red_packet_num = layout.findViewById(R.id.tv_share_red_packet_num);
|
final ImageView iv_num_subtraction = layout.findViewById(R.id.iv_num_subtraction);
|
final TextView tv_num = layout.findViewById(R.id.tv_num);
|
final ImageView iv_num_addition = layout.findViewById(R.id.iv_num_addition);
|
final TextView tv_need_num = layout.findViewById(R.id.tv_need_num);
|
final TextView tv_surplus_num = layout.findViewById(R.id.tv_surplus_num);
|
FrameLayout fl_red_packet = layout.findViewById(R.id.fl_red_packet);
|
FrameLayout fl_create_share = layout.findViewById(R.id.fl_create_share);
|
|
Glide.with(context).load(mInfo.getImgList().get(0)).into(iv_goods_img);
|
if (mInfo.isHasCoupon())
|
tv_goods_price_coupon.setText(mInfo.getCouponPrice());
|
if (mInfo.getMoneyInfo().getMoneyType() == 1) {
|
tv_rebate_num.setText(" 返" + mInfo.getMoneyInfo().getFanliMoney());
|
tv_rebate_num.setBackgroundResource(R.drawable.shape_red_goods_detail_corner);
|
tv_rebate_num.setTextColor(context.getResources().getColor(R.color.main_text_color));
|
} else {
|
tv_rebate_num.setText(" 奖" + mInfo.getMoneyInfo().getFanliMoney());
|
tv_rebate_num.setBackgroundResource(R.drawable.shape_goods_list_price_reward);
|
tv_rebate_num.setTextColor(context.getResources().getColor(R.color.orange4));
|
}
|
tv_goods_price_before.setText(mInfo.getPriceName() + " ¥" + mInfo.getZkPrice());
|
tv_share_red_packet_num.setText("¥ " + mInfo.getOtherInfo().getSpreadHongBao().getMoney());
|
tv_share_red_packet_date.setText(mInfo.getOtherInfo().getSpreadHongBao().getTip());
|
|
iv_num_subtraction.setEnabled(false);
|
if (Double.parseDouble(userHongbao) >= Double.parseDouble(mInfo.getOtherInfo().getSpreadHongBao().getMoney())) {
|
num = 1;
|
iv_num_addition.setEnabled(true);
|
} else {
|
iv_num_addition.setEnabled(false);
|
num = 0;
|
fl_create_share.setBackgroundResource(R.drawable.shape_login_gain_sms);
|
}
|
tv_num.setText(num + "");
|
BigDecimal money = new BigDecimal(mInfo.getOtherInfo().getSpreadHongBao().getMoney()).multiply(new BigDecimal(num));
|
tv_need_num.setText(money + "");
|
BigDecimal surplusMoney = new BigDecimal(userHongbao).subtract(money);
|
tv_surplus_num.setText("剩余推广红包 ¥ " + surplusMoney);
|
|
iv_num_subtraction.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
if (num > 1) {
|
num--;
|
iv_num_subtraction.setEnabled(num == 1 ? false : true);
|
}
|
iv_num_addition.setEnabled(Double.parseDouble(userHongbao) >=
|
(Double.parseDouble(mInfo.getOtherInfo().getSpreadHongBao().getMoney()) * num + 1) ? true : false);
|
tv_num.setText(num + "");
|
BigDecimal money = new BigDecimal(mInfo.getOtherInfo().getSpreadHongBao().getMoney()).multiply(new BigDecimal(num));
|
tv_need_num.setText(money + "");
|
BigDecimal surplusMoney = new BigDecimal(userHongbao).subtract(money);
|
tv_surplus_num.setText("剩余推广红包 ¥ " + surplusMoney);
|
}
|
});
|
|
iv_num_addition.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
if (Double.parseDouble(userHongbao) >=
|
(Double.parseDouble(mInfo.getOtherInfo().getSpreadHongBao().getMoney()) * (num + 1))) {
|
num++;
|
iv_num_addition.setEnabled(Double.parseDouble(userHongbao) >=
|
(Double.parseDouble(mInfo.getOtherInfo().getSpreadHongBao()
|
.getMoney()) * (num + 1)) ? true : false);
|
}
|
iv_num_subtraction.setEnabled(num == 1 ? false : true);
|
tv_num.setText(num + "");
|
BigDecimal money = new BigDecimal(mInfo.getOtherInfo().getSpreadHongBao().getMoney()).multiply(new BigDecimal(num));
|
tv_need_num.setText(money + "");
|
BigDecimal surplusMoney = new BigDecimal(userHongbao).subtract(money);
|
tv_surplus_num.setText("剩余推广红包 ¥ " + surplusMoney);
|
}
|
});
|
|
if (negativeButtonClickListener != null) {
|
fl_red_packet.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
negativeButtonClickListener.onClick(dialog, DialogInterface.BUTTON_NEGATIVE);
|
}
|
});
|
}
|
if (positiveButtonClickListener != null) {
|
fl_create_share.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
if (num > 0) {
|
positiveButtonClickListener.onClick(dialog, num);
|
} else {
|
Toast.makeText(context, "推广红包余额不足", Toast.LENGTH_LONG).show();
|
}
|
}
|
});
|
}
|
|
WindowManager.LayoutParams params = dialog.getWindow()
|
.getAttributes();
|
params.gravity = Gravity.BOTTOM;
|
params.width = width;
|
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
|
dialog.getWindow().setAttributes(params);
|
dialog.getWindow().setWindowAnimations(R.style.bottomstyle);
|
|
dialog.setCanceledOnTouchOutside(true);
|
return dialog;
|
}
|
|
}
|
}
|