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.bumptech.glide.request.RequestOptions;
|
import com.tejia.lijin.app.util.goods.GoodsDetailListUtil;
|
import com.tejia.lijin.app.util.ui.GoodsDetailUtil;
|
import com.tejia.lijin.app.util.ui.GoodsRightViewHolder;
|
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;
|
|
import static com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade;
|
|
/**
|
* 猜你喜欢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_goods_detail = layout.findViewById(R.id.ll_goods_detail);//商品详情布局
|
RelativeLayout ll_not_item = layout.findViewById(R.id.ll_not_item);//未加入淘宝联盟布局
|
TextView tv_left = layout.findViewById(R.id.tv_left);
|
if (type == 4) {/**兼容未加入淘宝联盟的情况*/
|
ll_goods_detail.setVisibility(View.GONE);//商品详情
|
ll_not_item.setVisibility(View.VISIBLE);//未加入淘宝联盟
|
tv_left.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_left.setOnClickListener(new View.OnClickListener() {
|
public void onClick(View v) {
|
positiveButtonClickListener.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
|
ClipboardUtil.emptyClipboard(context);
|
}
|
});
|
}
|
} else {/**商品详情布局*/
|
ll_goods_detail.setVisibility(View.VISIBLE);//商品详情
|
ll_not_item.setVisibility(View.GONE);//未加入淘宝联盟
|
if (positiveButtonClickListener != null) {
|
tv_left.setOnClickListener(new View.OnClickListener() {
|
public void onClick(View v) {
|
positiveButtonClickListener.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
|
ClipboardUtil.emptyClipboard(context);
|
}
|
});
|
}
|
// 图片
|
ImageView iv_pic = layout.findViewById(R.id.iv_pic);
|
try {
|
Glide.with(context).load(info.getGoods().getPicUrl()).apply(new RequestOptions().centerCrop()).transform(new GlideRoundTransform(context, 5)).transition(withCrossFade()).placeholder(R.drawable.ic_goods_default).diskCacheStrategy(DiskCacheStrategy.ALL).into(iv_pic);
|
} catch (IllegalArgumentException e) {
|
}
|
//商品详情填充
|
GoodsDetailListUtil.setGoodsDetail(context, info.getGoods(), new GoodsRightViewHolder(ll_goods_detail));
|
}
|
|
|
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) * 4) / 5);
|
params.height = android.view.WindowManager.LayoutParams.WRAP_CONTENT;
|
dialog.getWindow().setAttributes(params);
|
dialog.setCanceledOnTouchOutside(false);
|
return dialog;
|
}
|
}
|
}
|