package com.tejia.lijin.app.ui.dialog;
|
|
import android.app.Activity;
|
import android.app.Dialog;
|
import android.content.ClipboardManager;
|
import android.content.Context;
|
import android.content.DialogInterface;
|
import android.graphics.Paint;
|
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.GradientDrawable;
|
import android.text.Spannable;
|
import android.text.SpannableString;
|
import android.text.Spanned;
|
import android.text.style.RelativeSizeSpan;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.widget.FrameLayout;
|
import android.widget.ImageView;
|
import android.widget.LinearLayout;
|
import android.widget.RelativeLayout;
|
import android.widget.TextView;
|
|
import com.app.hubert.guide.util.ScreenUtils;
|
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
import com.wpc.library.util.SystemCommon;
|
import com.wpc.library.util.common.DimenUtils;
|
import com.tejia.lijin.app.R;
|
import com.tejia.lijin.app.entity.recommendinfo.RecommendGoodsInfo;
|
import com.tejia.lijin.app.util.Constant;
|
import com.tejia.lijin.app.util.GlideRoundTransform;
|
import com.tejia.lijin.app.util.ImageUtil;
|
import com.tejia.lijin.app.util.JumpActivityUtil;
|
import com.tejia.lijin.app.util.clipboard.ClipboardUtil;
|
|
/**
|
* 猜你喜欢dialog
|
* Created by weikou2015 on 2017/2/28.
|
*/
|
|
public class CopyLinkDialog extends Dialog {
|
|
public CopyLinkDialog(Context context) {
|
super(context);
|
this.setCancelable(false);
|
}
|
|
public CopyLinkDialog(Context context, int theme) {
|
super(context, theme);
|
this.setCancelable(false);
|
}
|
|
public static class Builder {
|
private Activity context;
|
private RecommendGoodsInfo info;
|
private String positiveButtonText;
|
private String negativeButtonText;
|
private OnClickListener positiveButtonClickListener;
|
private OnClickListener negativeButtonClickListener;
|
private int type = 0;//默认为0
|
|
public Builder(Activity context) {
|
this.context = context;
|
}
|
|
public Builder setMessage(RecommendGoodsInfo info) {
|
this.info = info;
|
return this;
|
}
|
|
public Builder setType(int type) {/**判断是否未加入淘宝联盟*/
|
this.type = type;
|
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_link, null);
|
|
dialog.addContentView(layout, new FrameLayout.LayoutParams(
|
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT));
|
|
LinearLayout ll_item1 = layout.findViewById(R.id.ll_horizontal_item);//商品详情布局
|
RelativeLayout ll_not_item = layout.findViewById(R.id.ll_not_item);//未加入淘宝联盟布局
|
TextView tv_go = layout.findViewById(R.id.tv_go);
|
TextView tv_left = layout.findViewById(R.id.tv_left);
|
|
GradientDrawable gradientDrawable = new GradientDrawable();
|
gradientDrawable.setCornerRadius(DimenUtils.dip2px(context, 40));
|
gradientDrawable.setStroke(DimenUtils.dip2px(context, 1), context.getResources().getColor(R.color.theme));
|
gradientDrawable.setColor(context.getResources().getColor(R.color.white));
|
tv_left.setBackgroundDrawable(gradientDrawable);
|
tv_left.setVisibility(View.GONE);
|
|
if (type == 4) {/**兼容未加入淘宝联盟的情况*/
|
ll_item1.setVisibility(View.GONE);//商品详情
|
ll_not_item.setVisibility(View.VISIBLE);//未加入淘宝联盟
|
tv_go.setText("查看相似");
|
ImageView ll_not_img = layout.findViewById(R.id.ll_not_img);
|
TextView ll_not_title1 = layout.findViewById(R.id.ll_not_title1);
|
// 图片
|
Glide.with(context).load(info.getGoods().getPictUrl())
|
.placeholder(R.drawable.ic_goods_default).error(R.drawable.ic_goods_default)
|
.transform(new GlideRoundTransform(context, 5))
|
.diskCacheStrategy(DiskCacheStrategy.ALL)
|
.into(ll_not_img);
|
ll_not_title1.setText(info.getGoods().getTitle());//纯标题
|
if (positiveButtonClickListener != null) {
|
tv_go.setOnClickListener(new View.OnClickListener() {
|
public void onClick(View v) {
|
positiveButtonClickListener.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
|
ClipboardUtil.emptyClipboard(context);
|
}
|
});
|
}
|
} else {/**商品详情布局*/
|
ll_item1.setVisibility(View.VISIBLE);//商品详情
|
ll_not_item.setVisibility(View.GONE);//未加入淘宝联盟
|
|
if (info.getLeft() != null) {
|
tv_left.setVisibility(View.VISIBLE);
|
tv_left.setText(info.getLeft().getName());
|
tv_left.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
JumpActivityUtil.jumpPage(context, info.getLeft().getJumpDetail(), info.getLeft().getParams());
|
ClipboardUtil.emptyClipboard(context);
|
if (dialog.isShowing())
|
dialog.dismiss();
|
}
|
});
|
} else
|
tv_left.setVisibility(View.GONE);
|
if (info.getRight() != null) {
|
tv_go.setText(info.getRight().getName());
|
tv_go.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
JumpActivityUtil.jumpPage(context, info.getRight().getJumpDetail(), info.getRight().getParams());
|
ClipboardUtil.emptyClipboard(context);
|
}
|
});
|
} else {
|
tv_go.setText("去看看");
|
if (positiveButtonClickListener != null) {
|
tv_go.setOnClickListener(new View.OnClickListener() {
|
public void onClick(View v) {
|
positiveButtonClickListener.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
|
ClipboardUtil.emptyClipboard(context);
|
}
|
});
|
}
|
}
|
LinearLayout ll_coupon_bg1 = layout.findViewById(R.id.ll_coupon_bg1);
|
ImageView iv_pic1 = layout.findViewById(R.id.iv_movie_cover1);
|
TextView tv_normal_price1 = layout.findViewById(R.id.tv_normal_price1);
|
TextView tv_shop_name1 = layout.findViewById(R.id.tv_shop_name1);
|
TextView tv_name1 = layout.findViewById(R.id.tv_movie_title1);
|
TextView tv_price1 = layout.findViewById(R.id.tv_price1);
|
TextView tv_coupon_price1 = layout.findViewById(R.id.tv_coupon_price1);
|
TextView tv_favourable1 = layout.findViewById(R.id.tv_favourable1);
|
TextView tv_rate_info = layout.findViewById(R.id.tv_rate_info);
|
|
LinearLayout ll_discount_new = layout.findViewById(R.id.ll_discount_new);
|
TextView tv_discount_new = layout.findViewById(R.id.tv_discount_new);
|
|
TextView tv_sale_num1 = layout.findViewById(R.id.tv_sale_num1);
|
TextView tv_sale_num2 = layout.findViewById(R.id.tv_sale_num2);
|
|
LinearLayout ll_shop1 = layout.findViewById(R.id.ll_shop1);
|
|
//不加商品类型图标(淘宝联盟不允许用链接搜索)
|
ImageUtil.showImageFaceDialog(context, info.getGoods().getTitle(), info.getGoods().getShopType(), tv_name1);
|
// tv_name1.setText(taoBaoGoodsBrief.getTitle());//纯标题
|
tv_normal_price1.setText("¥" + info.getGoods().getZkPrice());
|
tv_normal_price1.setPaintFlags(tv_normal_price1.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
|
|
// 图片
|
Glide.with(context).load(info.getGoods().getPicUrl()).
|
placeholder(R.drawable.ic_goods_default).error(R.drawable.ic_goods_default).
|
transform(new GlideRoundTransform(context, 5))
|
.diskCacheStrategy(DiskCacheStrategy.ALL)
|
.into(iv_pic1);
|
// ImageLoader.getInstance().displayImage(taoBaoGoodsBrief.getPicUrl(), iv_pic1, options);
|
if (info.getGoods().getShopInfo() != null && info.getGoods().getShopInfo().getShopName() != null) {
|
ll_shop1.setVisibility(View.VISIBLE);
|
tv_shop_name1.setText(info.getGoods().getShopInfo().getShopName());
|
Drawable drawable = context.getResources().getDrawable(R.drawable.ic_shopci);
|
drawable.setBounds(0, 0, 27 * tv_shop_name1.getLineHeight() / 24, tv_shop_name1.getLineHeight());//第一0是距左边距离,第二0是距上边距离,30、35分别是长宽
|
tv_shop_name1.setCompoundDrawables(drawable, null, null, null);//只放左边
|
} else {
|
ll_shop1.setVisibility(View.GONE);
|
// v_top.setVisibility(position == 0 ? View.VISIBLE : View.GONE);
|
}
|
tv_price1.setTextColor(context.getResources().getColor(R.color.theme));
|
|
if (info.getGoods().getMoneyInfo() != null && info.getGoods().getMoneyInfo().getRateInfo() != null)
|
tv_rate_info.setText(info.getGoods().getMoneyInfo().getRateInfo());
|
|
if (info.getGoods().getMoneyInfo().getMoneyType() == 1) {
|
tv_favourable1.setBackgroundResource(R.drawable.shape_goods_list_price_fan);
|
tv_favourable1.setText("返 " + info.getGoods().getMoneyInfo().getFanliMoney());
|
} else {
|
tv_favourable1.setBackgroundResource(R.drawable.shape_goods_list_price_fan);
|
tv_favourable1.setText("奖 " + info.getGoods().getMoneyInfo().getFanliMoney());
|
}
|
|
|
String disCount;
|
|
if (!info.getGoods().isHasCoupon()) {
|
ll_coupon_bg1.setVisibility(View.GONE);
|
disCount = "¥ " + info.getGoods().getZkPrice();
|
if (info.getGoods().getGoodsType() == Constant.GOODS_TYPE_VIP) {
|
disCount = "¥ " + info.getGoods().getCouponPrice();
|
}
|
} else {
|
ll_coupon_bg1.setVisibility(View.VISIBLE);
|
disCount = "¥ " + info.getGoods().getCouponPrice();
|
tv_coupon_price1.setVisibility(View.VISIBLE);
|
tv_coupon_price1.setText("¥ " + info.getGoods().getCouponInfo().getAmount());
|
}
|
|
|
tv_sale_num1.setTextColor((info.getGoods().getSalesType() == 1 || info.getGoods().getSalesType() == 4) ?
|
context.getResources().getColor(R.color.gray5) : info.getGoods().getSalesType() == 2 ?
|
context.getResources().getColor(R.color.goods_sale_num_text_color_orange) :
|
context.getResources().getColor(R.color.goods_sale_num_text_color_blue));
|
tv_sale_num1.setText(info.getGoods().getSalesType() == 1 ? "月销 " + info.getGoods().getSalesCount() :
|
info.getGoods().getSalesType() == 2 ? "2小时销量 " + info.getGoods().getSalesCount() : info.getGoods().getSalesType() == 3 ?
|
"今日销量 " + info.getGoods().getSalesCount() : "总销量 " + info.getGoods().getSalesCount());
|
tv_sale_num2.setTextColor((info.getGoods().getSalesType() == 1 || info.getGoods().getSalesType() == 4) ?
|
context.getResources().getColor(R.color.gray5) : info.getGoods().getSalesType() == 2 ?
|
context.getResources().getColor(R.color.goods_sale_num_text_color_orange) :
|
context.getResources().getColor(R.color.goods_sale_num_text_color_blue));
|
tv_sale_num2.setText(info.getGoods().getSalesType() == 1 ? "月销 " + info.getGoods().getSalesCount() :
|
info.getGoods().getSalesType() == 2 ? "2小时销量 " + info.getGoods().getSalesCount() : info.getGoods().getSalesType() == 3 ?
|
"今日销量 " + info.getGoods().getSalesCount() : "总销量 " + info.getGoods().getSalesCount());
|
|
tv_sale_num2.setVisibility(View.GONE);
|
if (info.getGoods().getGoodsType() == Constant.GOODS_TYPE_VIP) {
|
tv_sale_num1.setVisibility(View.GONE);
|
ll_discount_new.setVisibility(View.VISIBLE);
|
tv_discount_new.setText(info.getGoods().getDiscount());
|
} else {
|
ll_discount_new.setVisibility(View.GONE);
|
tv_sale_num1.setVisibility(View.VISIBLE);
|
|
}
|
|
int pos = disCount.indexOf(".");
|
Spannable span = new SpannableString(disCount);
|
span.setSpan(new RelativeSizeSpan(1.2f), 1, pos > 1 ? pos : disCount.length(),
|
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
//span.setSpan(new StyleSpan(Typeface.BOLD), 1, disCount.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
tv_price1.setText(span);
|
|
|
}
|
|
// set the confirm button
|
|
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
//动态改变shape
|
GradientDrawable shape = new GradientDrawable();
|
shape.setCornerRadius(ScreenUtils.dp2px(context, 100));
|
//设置颜色
|
shape.setColor(context.getResources().getColor(R.color.theme));
|
//设置大小
|
tv_go.setBackground(shape);
|
|
|
if (negativeButtonClickListener != null) {
|
layout.findViewById(R.id.iv_cancle).setOnClickListener(new View.OnClickListener() {
|
public void onClick(View v) {
|
negativeButtonClickListener.onClick(dialog, DialogInterface.BUTTON_NEGATIVE);
|
ClipboardUtil.emptyClipboard(context);
|
}
|
});
|
}
|
dialog.setContentView(layout);
|
|
android.view.WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
|
params.width = (int) ((SystemCommon.getScreenWidth(context) * 19) / 23);
|
params.height = android.view.WindowManager.LayoutParams.WRAP_CONTENT;
|
dialog.getWindow().setAttributes(params);
|
dialog.setCanceledOnTouchOutside(false);
|
return dialog;
|
}
|
}
|
}
|