package com.tejia.lijin.app.ui.dialog;
|
|
import android.app.Dialog;
|
import android.content.Context;
|
import android.content.DialogInterface;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.widget.FrameLayout;
|
import android.widget.ImageView;
|
import android.widget.ListView;
|
import android.widget.RelativeLayout;
|
import android.widget.TextView;
|
|
import com.bumptech.glide.Glide;
|
import com.wpc.library.util.SystemCommon;
|
import com.tejia.lijin.app.R;
|
import com.tejia.lijin.app.entity.GiftCoupon;
|
import com.tejia.lijin.app.ui.mine.MultipleContentPopUpsAdapter;
|
import com.tejia.lijin.app.util.ApkUtil;
|
import com.tejia.lijin.app.util.GlideCircleTransform;
|
|
|
/**
|
* 10-免单券 11-奖励券 12-红包 弹窗
|
*/
|
public class CopyGiftDialog extends Dialog {
|
public CopyGiftDialog(Context context) {
|
super(context);
|
this.setCancelable(false);
|
}
|
|
public CopyGiftDialog(Context context, int theme) {
|
super(context, theme);
|
this.setCancelable(false);
|
}
|
|
public static class Builder {
|
private Context context;
|
private GiftCoupon mGiftCoupon; //免单券 -奖励券 -红包 实体类
|
private String positiveButtonText;
|
private String negativeButtonText;
|
private OnClickListener positiveButtonClickListener;
|
private OnClickListener negativeButtonClickListener;
|
|
public Builder(Context context) {
|
this.context = context;
|
}
|
|
public Builder setMessage(GiftCoupon mGiftCoupon) {
|
this.mGiftCoupon = mGiftCoupon;
|
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;
|
}
|
|
public CopyLinkDialog create() {
|
LayoutInflater inflater = (LayoutInflater) context
|
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
// instantiate the dialog with the custom Theme
|
final CopyLinkDialog dialog = new CopyLinkDialog(context, R.style.Dialog1);
|
View layout = inflater.inflate(R.layout.item_copy_gift, null);
|
dialog.addContentView(layout, new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT));
|
|
TextView popups_title = layout.findViewById(R.id.popups_title);//title
|
ImageView popups_titleimg = layout.findViewById(R.id.popups_titleimg);//titleimg
|
ImageView popups_close = layout.findViewById(R.id.popups_close);
|
TextView popups_single = layout.findViewById(R.id.popups_single);//领取按钮
|
// TextView popups_dual = layout.findViewById(R.id.popups_dual);//第二个按钮
|
ListView listView = layout.findViewById(R.id.popups_listview);
|
TextView popups_statetxt = layout.findViewById(R.id.popups_statetxt);//显示无效提示语
|
popups_title.setText(mGiftCoupon.nickName);
|
Glide.with(context).load(mGiftCoupon.portrait)
|
.transform(new GlideCircleTransform(context))
|
.placeholder(R.drawable.ic_goods_default)
|
.error(R.drawable.ic_goods_default)
|
.into(popups_titleimg);
|
if (mGiftCoupon.state) { // 有效:确认领取 无效:知道了
|
popups_single.setText("确认领取");
|
MultipleContentPopUpsAdapter adapter = new MultipleContentPopUpsAdapter(context, mGiftCoupon.tips);
|
listView.setAdapter(adapter);
|
} else {
|
popups_single.setText("知道了");
|
listView.setVisibility(View.GONE);
|
popups_statetxt.setVisibility(View.VISIBLE);
|
popups_statetxt.setText(mGiftCoupon.tips.get(0));
|
}
|
ImageView popups_img = layout.findViewById(R.id.popups_img);//免单券
|
if (mGiftCoupon.type == 10) { // 类型:10-免单券 11-奖励券 13-红包
|
popups_img.setBackground(context.getResources().getDrawable(R.drawable.ic_freecoupon));
|
} else if (mGiftCoupon.type == 11) {//奖励券
|
popups_img.setBackground(context.getResources().getDrawable(R.drawable.ic_freereward));
|
} else if (mGiftCoupon.type == 13) {//红包
|
popups_img.setVisibility(View.GONE);
|
RelativeLayout popups_imglayout = layout.findViewById(R.id.popups_imglayout);//红包布局
|
popups_imglayout.setVisibility(View.VISIBLE);
|
TextView popups_imgmoney = layout.findViewById(R.id.popups_imgmoney);
|
popups_imgmoney.setText(mGiftCoupon.money);
|
}
|
|
// set the confirm button
|
|
if (positiveButtonClickListener != null) {
|
popups_single.setOnClickListener(new View.OnClickListener() {
|
public void onClick(View v) {
|
positiveButtonClickListener.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
|
// setClipboardManager(clipboard);
|
ApkUtil.setEmptyClipboardManager(context);
|
}
|
});
|
}
|
if (negativeButtonClickListener != null) {
|
// popups_close.setVisibility(View.VISIBLE);//显示第二个按钮
|
popups_close.setOnClickListener(new View.OnClickListener() {
|
public void onClick(View v) {
|
negativeButtonClickListener.onClick(dialog, DialogInterface.BUTTON_NEGATIVE);
|
ApkUtil.setEmptyClipboardManager(context);
|
}
|
});
|
}
|
dialog.setContentView(layout);
|
|
android.view.WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
|
params.width = (int) ((SystemCommon.getScreenWidth(context) * 19) / 25);
|
params.height = android.view.WindowManager.LayoutParams.WRAP_CONTENT;
|
dialog.getWindow().setAttributes(params);
|
dialog.setCanceledOnTouchOutside(false);
|
return dialog;
|
}
|
|
|
}
|
}
|