admin
2021-07-08 1764c1784a4cf1a6afd25fcf1a0eef6187a84218
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
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;
        }
    }
}