admin
2021-05-08 f93ff67ed4681f416a653370aa1e7995a56940ef
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
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;
        }
    }
}