admin
2021-05-14 1b4b3fed2569ac21ad6feb0a3a2c051175e7c36e
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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
package com.tejia.lijin.app.ui.recommend.singleshare;
 
import android.Manifest;
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
 
import com.app.hubert.guide.util.ScreenUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.tejia.lijin.app.ShoppingApplication;
import com.tejia.lijin.app.util.user.UserUtil;
import com.wpc.library.RetainViewFragment;
import com.wpc.library.util.common.DimenUtils;
import com.wpc.library.util.common.StringUtils;
import com.wpc.library.widget.MyGridView;
import com.wpc.library.widget.ResizableImageView;
import com.tejia.lijin.app.BasicTextHttpResponseHandler;
import com.tejia.lijin.app.R;
import com.tejia.lijin.app.ShoppingApi;
import com.tejia.lijin.app.callBack.GeneralSingelCallback;
import com.tejia.lijin.app.callBack.PermissionInterface;
import com.tejia.lijin.app.entity.share.ShareImageEntity;
import com.tejia.lijin.app.entity.share.SingleGoodsShareInfo;
import com.tejia.lijin.app.ui.dialog.ShareGoodsImgNativeDialog;
import com.tejia.lijin.app.ui.recommend.ActivityContentCompile;
import com.tejia.lijin.app.util.GlideRoundTransform;
import com.tejia.lijin.app.util.ImageUtil;
import com.tejia.lijin.app.util.PermissionHelper;
import com.tejia.lijin.app.util.Toast_Dialog;
import com.tejia.lijin.app.util.clipboard.ClipboardUtil;
import com.tejia.lijin.app.util.share.ShareCacheUtil;
import com.tejia.lijin.app.util.umengCustomEvent.GoodsCustomEvent;
import com.tejia.lijin.app.util.zxing.ZxingUtils;
 
import org.apache.http.Header;
import org.json.JSONObject;
 
import java.util.ArrayList;
import java.util.List;
 
 
/**
 * 多图分享
 */
public class MultiImageShareFragment extends RetainViewFragment implements View.OnClickListener, PermissionInterface, GeneralSingelCallback {
 
    private TextView tv_multiple_goods_title,
            tv_multiple_after_coupon_price,
            tv_multiple_normal_price,
            tv_multiple_sale_num, tv_multiple_coupon_price,
            tv_tlj_multiple, tv_multiple_free_shipping, cb_copytxt, tv_share_content, tv_remind_content, tv_share_img;
    private ImageView iv_multiple_qr_code,
            iv_multiple_first_close, iv_multiple_qr_code_center_img;
    private CheckBox cb_copy;
    private ResizableImageView iv_multiple_first_img, iv_multiple_img_coupon_ad;
 
    private FrameLayout fl_multiple_qr,
            fl_multiple_img_coupon_ad, fl_multiple_free_shipping;
 
    private LinearLayout
            ll_multiple_share_img, ll_multiple_coupon, ll_ambush;
    private MyGridView gv_multiple_imgs;
    RelativeLayout ll_ambushlayout;
    private SingleGoodsShareInfo shareInfo;//分享信息
 
    private DisplayImageOptions options;
    private TextView tv_share_content_restore;//还原文字模板
    private TextView tv_share_content_compile;//编辑文字模板
    private Toast_Dialog toast_dialog;
    private TextView tv_template_copy;//复制文字模版
 
 
    @Override
    public int getContentResource() {
        return R.layout.fragment_share_goods_multi_img;
    }
 
    @Override
    public void onCreateView(View contentView, Bundle savedInstanceState) {
        Bundle bundle = this.getArguments();
        shareInfo = (SingleGoodsShareInfo) bundle.getSerializable("shareInfo");
        initView(contentView);
        initListener(contentView);
        mPermissionsChecker = new PermissionHelper(getActivity(), this);
    }
 
    private void initView(View contentView) {
        tv_share_img = contentView.findViewById(R.id.tv_share_img);
        tv_share_content = contentView.findViewById(R.id.tv_share_content);
        tv_remind_content = contentView.findViewById(R.id.tv_remind_content);
        tv_tlj_multiple = contentView.findViewById(R.id.tv_tlj_multiple);
        iv_multiple_first_img = contentView.findViewById(R.id.iv_multiple_first_img);
        iv_multiple_first_close = contentView.findViewById(R.id.iv_multiple_first_close);
        cb_copy = contentView.findViewById(R.id.cb_copy);
        ll_multiple_share_img = contentView.findViewById(R.id.ll_multiple_share_img);
        gv_multiple_imgs = contentView.findViewById(R.id.gv_multiple_imgs);
        fl_multiple_qr = contentView.findViewById(R.id.fl_multiple_qr);
        iv_multiple_qr_code = contentView.findViewById(R.id.iv_multiple_qr_code);
        iv_multiple_qr_code_center_img = contentView.findViewById(R.id.iv_multiple_qr_code_center_img);
        tv_multiple_goods_title = contentView.findViewById(R.id.tv_multiple_goods_title);
        tv_multiple_after_coupon_price = contentView.findViewById(R.id.tv_multiple_after_coupon_price);
        tv_multiple_normal_price = contentView.findViewById(R.id.tv_multiple_normal_price);
        tv_multiple_sale_num = contentView.findViewById(R.id.tv_multiple_sale_num);
        ll_multiple_coupon = contentView.findViewById(R.id.ll_multiple_coupon);
        ll_ambush = contentView.findViewById(R.id.ll_ambush);
        ll_ambushlayout = contentView.findViewById(R.id.ll_ambushlayout);
        tv_multiple_coupon_price = contentView.findViewById(R.id.tv_multiple_coupon_price);
        fl_multiple_img_coupon_ad = contentView.findViewById(R.id.fl_multiple_img_coupon_ad);
        iv_multiple_img_coupon_ad = contentView.findViewById(R.id.iv_multiple_img_coupon_ad);
        tv_share_content_restore = contentView.findViewById(R.id.tv_share_content_restore);
        tv_share_content_compile = contentView.findViewById(R.id.tv_share_content_compile);
        fl_multiple_free_shipping = contentView.findViewById(R.id.fl_multiple_free_shipping);
        tv_multiple_free_shipping = contentView.findViewById(R.id.tv_multiple_free_shipping);
        tv_template_copy = contentView.findViewById(R.id.tv_template_copy);
        cb_copytxt = contentView.findViewById(R.id.cb_copytxt);
 
        this.options = new DisplayImageOptions.Builder()
                .showImageForEmptyUri(R.drawable.ic_goods_default)
                .showImageOnFail(R.drawable.ic_goods_default)
                .showImageOnLoading(R.drawable.ic_goods_default)
                .resetViewBeforeLoading(false).cacheInMemory(true)
                .cacheOnDisk(true).imageScaleType(ImageScaleType.EXACTLY)
                .considerExifParams(true)
                .build();
        tv_tlj_multiple.setVisibility(StringUtils.isEmpty(shareInfo.getTljId()) ? View.GONE : View.VISIBLE);
        tv_tlj_multiple.setText(StringUtils.isEmpty(shareInfo.getTljId()) ? "" : shareInfo.getSpreadMoney());
 
        ImageUtil.showImageFace1(getContext(), shareInfo.getGoodsInfo().getTitle(), shareInfo.getGoodsInfo().getShopType(), tv_multiple_goods_title);
        String price;
        int startP;
 
 
        if (shareInfo.getGoodsInfo().isHasCoupon()) {//有优惠券
            price = "券后价 ¥ " + shareInfo.getGoodsInfo().getCouponPrice();
            startP = 5;
            tv_multiple_coupon_price.setText("¥ " + shareInfo.getGoodsInfo().getCouponInfo().getAmount());
            contentView.findViewById(R.id.v_space).setVisibility(View.VISIBLE);
            ll_multiple_coupon.setVisibility(View.VISIBLE);
            tv_multiple_normal_price.setVisibility(View.VISIBLE);
            fl_multiple_img_coupon_ad.setVisibility(View.VISIBLE);
            fl_multiple_qr.setBackgroundResource(R.drawable.ic_qr_code_frame_old);
        } else {
            price = "¥ " + shareInfo.getGoodsInfo().getZkPrice();
            startP = 1;
            contentView.findViewById(R.id.v_space).setVisibility(View.GONE);
            ll_multiple_coupon.setVisibility(View.GONE);
            tv_multiple_normal_price.setVisibility(View.GONE);
            fl_multiple_img_coupon_ad.setVisibility(View.GONE);
            fl_multiple_qr.setBackgroundResource(R.drawable.ic_qr_code_frame_no_coupon_old);
        }
        Spannable span = new SpannableString(price);
        span.setSpan(new RelativeSizeSpan(1.3f), startP, price.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        span.setSpan(new StyleSpan(Typeface.BOLD), startP, price.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        tv_multiple_after_coupon_price.setText(span);
        setQRCode(shareInfo.getClickUrl());//设置二维码
        if (shareInfo.getGoodsInfo().getShopType() == 21) {
            fl_multiple_free_shipping.setVisibility(View.VISIBLE);
            tv_multiple_free_shipping.setText("自营");
        } else {
            if (shareInfo.getGoodsInfo().isBaoyou()) {
                fl_multiple_free_shipping.setVisibility(View.VISIBLE);
                tv_multiple_free_shipping.setText("包邮");
            } else {
                fl_multiple_free_shipping.setVisibility(View.GONE);
            }
        }
 
 
        tv_multiple_normal_price.setText(shareInfo.getGoodsInfo().getPriceName() + "  ¥" + shareInfo.getGoodsInfo().getZkPrice());
 
        String saleType = shareInfo.getGoodsInfo().getSalesType() == 1 ? "月销 " : "总销量 ";
        tv_multiple_sale_num.setText(saleType + shareInfo.getGoodsInfo().getSalesCount());
        Glide.with(this).load(shareInfo.getNotifyPicture()).into(iv_multiple_img_coupon_ad);
 
        final RequestOptions options = new RequestOptions().placeholder(R.drawable.ic_goods_default);
 
        Glide.with(this).load(shareInfo.getGoodsInfo().getImgList().get(0)).apply(options).into(iv_multiple_first_img);
        multipleImg();
        iv_multiple_first_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (shareInfo.getGoodsInfo().getImgList().size() > 1) {
                    shareInfo.getGoodsInfo().getImgList().remove(0);
                    imgList.clear();
                    multipleImg();
                    Glide.with(getContext()).load(shareInfo.getGoodsInfo().getImgList().get(0)).apply(options).into(iv_multiple_first_img);
                } else {
                    Toast.makeText(getContext(), "至少保留一张图片", Toast.LENGTH_SHORT).show();
                }
            }
        });
        tv_share_content.setText(shareInfo.getDescText());
        tv_remind_content.setText(shareInfo.getNotifyDesc());
 
        toast_dialog = new Toast_Dialog(getContext());
        setcommentTexts();//设置淘口令//评论区文案
        final SharedPreferences sp = getContext().getSharedPreferences("user", Context.MODE_PRIVATE);
        if (sp.getBoolean("sharecheck", true)) {
            cb_copy.setChecked(true);
        } else {
            cb_copy.setChecked(false);
        }
 
        cb_copy.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                SharedPreferences.Editor editor = sp.edit();
                if (b) {
                    editor.putBoolean("sharecheck", true);
                } else {
                    editor.putBoolean("sharecheck", false);
                }
                editor.apply();
            }
        });
 
        final RequestOptions requestOptions = new RequestOptions().transform(new GlideRoundTransform(
                getContext(), 4));
        String portrait = getContext().getSharedPreferences("user", Context.MODE_PRIVATE).getString("portrait", "");
        Glide.with(getContext()).load(portrait).apply(requestOptions).into(iv_multiple_qr_code_center_img);
    }
 
 
    private void initListener(View contentView) {
        tv_share_img.setOnClickListener(this);
        tv_share_content_compile.setOnClickListener(this);
        tv_share_content_restore.setOnClickListener(this);
        tv_template_copy.setOnClickListener(this);
        cb_copytxt.setOnClickListener(this);
    }
 
    /***********动态添加 评论区文案**/
    private void setcommentTexts() {
        List<String> commentTextsArr = shareInfo.getCommentTexts();
 
        if (commentTextsArr == null || commentTextsArr.size() == 0) {
            ll_ambushlayout.setVisibility(View.GONE);
            return;
        }
 
        ll_ambush.removeAllViews();
        for (int i = 0; i < commentTextsArr.size(); i++) {
            View item = LayoutInflater.from(getContext()).inflate(R.layout.item_commenttexts, null);
            TextView tv_ambush1 = item.findViewById(R.id.tv_ambush1);
            final TextView tv_ambush = item.findViewById(R.id.tv_ambush);
            TextView tv_ambush_copy = item.findViewById(R.id.tv_ambush_copy);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            int left = ScreenUtils.dp2px(getContext(), 10);
            int top = ScreenUtils.dp2px(getContext(), 13);
            params.setMargins(left, top, left, top);
            item.setLayoutParams(params);
            tv_ambush.setText(commentTextsArr.get(i).toString());
            tv_ambush1.setText((i + 1) + "");
            tv_ambush_copy.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    GoodsCustomEvent.goodsDetailShareCopyToken(getContext());
 
                    ClipboardUtil.copy(getContext(), tv_ambush.getText().toString());
                    Toast.makeText(getContext(), "文本复制成功", Toast.LENGTH_SHORT).show();
                }
            });
            ll_ambush.addView(item);
        }
    }
 
    /*****************设置二维码******/
    private void setQRCode(String clickUrl) {
        //二维码
        Bitmap QRCode = ZxingUtils.createBitmap(clickUrl, DimenUtils.dip2px(getContext(), 85));
        Bitmap QRCodeMul = ZxingUtils.createBitmap(clickUrl, DimenUtils.dip2px(getContext(), 85));
        iv_multiple_qr_code.setImageBitmap(QRCodeMul);
//        iv_multiple_qr_code.setScaleType(ImageView.ScaleType.FIT_XY);
    }
 
    /**
     * 多图小图设置
     */
    MultipleImgAdapter imgAdapter;
    List<String> imgList;
 
    private void multipleImg() {
        if (imgList == null) {
            imgList = new ArrayList<>();
            for (int i = 0; i < shareInfo.getGoodsInfo().getImgList().size(); i++) {
                if (i > 0 && i < 5) {
                    imgList.add(shareInfo.getGoodsInfo().getImgList().get(i));
                }
            }
        } else {
            for (int i = 0; i < shareInfo.getGoodsInfo().getImgList().size(); i++) {
                if (i > imgList.size() && i < 5) {
                    imgList.add(shareInfo.getGoodsInfo().getImgList().get(i));
                }
            }
        }
 
        if (imgAdapter == null) {
            imgAdapter = new MultipleImgAdapter(imgList);
            gv_multiple_imgs.setAdapter(imgAdapter);
        } else {
            imgAdapter.notifyDataSetChanged();
//            imgAdapter.isSharing(false);
        }
    }
 
    @Override
    public void onResume() {
        super.onResume();
 
    }
 
    private PermissionHelper mPermissionsChecker; // 权限检测器
 
    /**
     * 权限请求码
     *
     * @return
     */
    @Override
    public int getPermissionsRequestCode() {
        return 1001;
    }
 
    /**
     * 请求权限
     *
     * @return
     */
    @Override
    public String[] getPermissions() {
        return new String[]{Manifest.permission.CAMERA};
    }
 
    /**
     * 权限请求成功
     */
    @Override
    public void requestPermissionsSuccess() {
    }
 
    /**
     * 权限请求失败
     */
    @Override
    public void requestPermissionsFail() {
//        Toast.makeText(this, "你以拒绝权限", Toast.LENGTH_SHORT).show();
    }
 
    /**
     * 请求权限结果
     *
     * @param requestCode
     * @param permissions
     * @param grantResults
     */
    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (mPermissionsChecker.requestPermissionsResult(requestCode, permissions, grantResults)) {
            //权限请求结果,并已经处理了该回调
            return;
        }
    }
 
    int isCheck = 0;
 
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_template_copy://复制模版文字
                ClipboardUtil.copy(getContext(), tv_share_content.getText().toString());
                Toast.makeText(getContext(), "文本复制成功",
                        Toast.LENGTH_SHORT).show();
                break;
            case R.id.tv_share_img://分享图片
                if (mPermissionsChecker.lacksPermissions(getPermissions())) { //检测权限
                    isCheck = 2;
                    mPermissionsChecker.showNormalDialog();
                } else {
                    if (mPermissionsChecker.lacksPermissions(getPermissions())) { //检测权限
                        mPermissionsChecker.showNormalDialog();
                    } else {
                        copyShareText();
 
                        //隐藏关闭
                        iv_multiple_first_close.setVisibility(View.GONE);
                        imgAdapter.isSharing(true);
//                            if (info.getImgList().size() == 1) {
                        Bitmap shareBp = getViewBp(ll_multiple_share_img);
                        showShareImg(shareBp);
                        iv_multiple_first_close.setVisibility(View.VISIBLE);
                        imgAdapter.isSharing(false);
                    }
                }
                break;
 
            case R.id.tv_share_content_compile://编辑文字模板
                Intent intent2 = new Intent(getContext(), ActivityContentCompile.class);
                intent2.putExtra("goodsId", shareInfo.getGoodsInfo().getGoodsId());
                intent2.putExtra("hasCoupon", shareInfo.getGoodsInfo().isHasCoupon());
                intent2.putExtra("tljId", shareInfo.getTljId());
                intent2.putExtra("goodsType", shareInfo.getGoodsInfo().getGoodsType());
                startActivity(intent2);
                break;
            case R.id.tv_share_content_restore://还原文字模板
                resetShareTextTemplate();
                break;
            case R.id.cb_copytxt:
                if (cb_copy.isChecked())
                    cb_copy.setChecked(false);
                else
                    cb_copy.setChecked(true);
                break;
 
            default:
                break;
 
        }
    }
 
 
    //复制分享文本
    private void copyShareText() {
        ClipboardUtil.copy(getContext(), tv_share_content.getText().toString());
        Toast.makeText(getContext(), "文本复制成功",
                Toast.LENGTH_SHORT).show();
    }
 
    /*
还原分享模板
 */
    private void resetShareTextTemplate() {
        SharedPreferences sp = getContext().getSharedPreferences("user", Context.MODE_PRIVATE);
        ShoppingApi.resetShareTextTemplate(getContext(), UserUtil.getUid(ShoppingApplication.application), shareInfo.getGoodsInfo().isHasCoupon() + "",
                shareInfo.getGoodsInfo().getGoodsId(), shareInfo.getTljId(), shareInfo.getGoodsInfo().getGoodsType(), new BasicTextHttpResponseHandler() {
                    @Override
                    public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                        if (jsonObject.optInt("code") == 0) {
                            tv_share_content.setText(jsonObject.optJSONObject("data").optString("content"));
                            Toast.makeText(getContext(), "文字模板还原成功", Toast.LENGTH_LONG).show();
                        } else {
                            Toast.makeText(getContext(), jsonObject.optString("msg"), Toast.LENGTH_LONG).show();
                        }
                    }
                });
    }
 
    /**
     * 截图
     *
     * @param v
     * @return
     */
    public Bitmap getViewBp(View v) {
        if (null == v) {
            return null;
        }
        v.setDrawingCacheEnabled(true);
        v.buildDrawingCache();
        v.measure(View.MeasureSpec.makeMeasureSpec(v.getWidth(),
                View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(
                v.getHeight(), View.MeasureSpec.EXACTLY));
        v.layout((int) v.getX(), (int) v.getY(),
                (int) v.getX() + v.getMeasuredWidth(),
                (int) v.getY() + v.getMeasuredHeight());
        Bitmap b = Bitmap.createBitmap(v.getDrawingCache(), 0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
        v.setDrawingCacheEnabled(false);
        v.destroyDrawingCache();
        return b;
    }
 
    @Override
    public void onPause() {
        super.onPause();
    }
 
    @Override
    public void onDestroy() {
        super.onDestroy();
    }
 
 
    ShareGoodsImgNativeDialog.Builder mSharebuilder;
    Dialog multiShareDialog = null;
 
    private void showShareImg(Bitmap shareBp) {
        String type = "many";//多图
 
        if (multiShareDialog == null) {
            mSharebuilder = new ShareGoodsImgNativeDialog.Builder(getActivity());
            setShareImages(shareBp);
            if (ShareCacheUtil.isSingleGoodsShareAllImage(getContext()))
                mSharebuilder.setSelectAll(true);
            mSharebuilder.setGeneralSingelCallback(this);
            multiShareDialog = mSharebuilder.setShareType(type).setShareId(shareInfo.getShareId())
                    .setFootMark(cb_copy.isChecked())//带不带角标
                    .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            dialogInterface.dismiss();
                        }
                    })
                    .create();
            multiShareDialog.show();
        } else {
            setShareImages(shareBp);
            if (!multiShareDialog.isShowing())
                multiShareDialog.show();
        }
    }
 
 
    /**
     * 获取分享图
     *
     * @return
     */
    private Bitmap getShareImage() {
        imgAdapter.isSharing(true);
        iv_multiple_first_close.setVisibility(View.GONE);
        Bitmap shareBp2 = getViewBp(ll_multiple_share_img);
        imgAdapter.isSharing(false);
        iv_multiple_first_close.setVisibility(View.VISIBLE);
        return shareBp2;
    }
 
    /**
     * 设置分享的图片
     */
    private void setShareImages(Bitmap shareImage) {
        if (shareImage == null)
            shareImage = getShareImage();
        mSharebuilder.setBitmap(shareImage);
        ArrayList<ShareImageEntity> shangImageList = new ArrayList<>();
        shangImageList.add(new ShareImageEntity(shareImage, null));
        List<String> imgList = shareInfo.getGoodsInfo().getImgList();
        if (imgList.size() > 0)
            for (String imgUrl : imgList) {
                shangImageList.add(new ShareImageEntity(null, imgUrl));
            }
        mSharebuilder.setShareImageList(shangImageList);
    }
 
    private int showCount = 0;
 
    public class MultipleImgAdapter extends BaseAdapter {
 
        private List<String> mList;
        private boolean isSharing = false;
 
        public MultipleImgAdapter(List<String> list) {
            this.mList = list;
        }
 
        @Override
        public int getCount() {
            return mList.size();
        }
 
        @Override
        public Object getItem(int position) {
            return mList.get(position);
        }
 
 
        @Override
        public long getItemId(int position) {
            return position;
        }
 
        @Override
        public View getView(final int position, View view, ViewGroup parent) {
            final MultipleImgAdapter.Holder holder;
            if (view == null) {
                holder = new MultipleImgAdapter.Holder();
                view = LayoutInflater.from(getContext()).inflate(R.layout.item_share_multiple_img, null);
                holder.iv_img = view.findViewById(R.id.iv_img);
                holder.iv_img_close = view.findViewById(R.id.iv_img_close);
                view.setTag(holder);
            } else {
                holder = (MultipleImgAdapter.Holder) view.getTag();
            }
            holder.iv_img_close.setVisibility(View.GONE);
 
//            ImageLoader.getInstance().displayImage(mList.get(position), holder.iv_img, options);
            RequestOptions options=new RequestOptions().placeholder(R.drawable.ic_goods_default);
 
            Glide.with(getContext()).load(mList.get(position)).apply(options).into(new SimpleTarget<Drawable>(){
                @Override
                public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<? super Drawable> transition) {
                    holder.iv_img.setImageDrawable(resource);
                    if (isSharing) {
                        holder.iv_img_close.setVisibility(View.GONE);
                        showCount++;
                        if (showCount == mList.size()) {
                            handler.sendEmptyMessage(0);
                            holder.iv_img_close.postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    iv_multiple_first_close.setVisibility(View.VISIBLE);
                                    isSharing(false);
//
                                }
                            }, 300);
                        }
                    } else {
                        holder.iv_img_close.setVisibility(View.VISIBLE);
                    }
                }
            });
 
            holder.iv_img_close.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mList.remove(position);
                    shareInfo.getGoodsInfo().getImgList().remove(position + 1);
                    multipleImg();
//                    notifyDataSetChanged();
                }
            });
            return view;
        }
 
        Handler handler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                Bitmap mulBp = getViewBp(ll_multiple_share_img);
                showShareImg(mulBp);
            }
        };
 
        class Holder {
            ImageView iv_img;
            ImageView iv_img_close;
        }
 
        public void isSharing(boolean isSharing) {
            this.isSharing = isSharing;
            notifyDataSetChanged();
        }
    }
 
    /**
     * 替换二维码 传送给dialog
     */
    @SuppressLint("HandlerLeak")
    private Handler qrCodeUpdatehandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            if (shareInfo.getWxErCode() == null || shareInfo.getWxErCode().length() == 0) {
                return;
            }
            if (msg.what == 1 || msg.what == 0)
                setQRCode(shareInfo.getWxErCode());
            else
                setQRCode(shareInfo.getClickUrl());//设置二维码
            setShareImages(null);
            //继续分享
            mSharebuilder.shareImgs(msg.what);
        }
    };
 
    /*****************分享点击了微信 替换二维码********/
    @Override
    public void onSuccess(Object var1, int imgSize) {
        //保存分享习惯
        if (shareInfo.getGoodsInfo() != null && shareInfo.getGoodsInfo().getImgList() != null) {
            if (imgSize == shareInfo.getGoodsInfo().getImgList().size())
                ShareCacheUtil.saveSingleGoodsShareImage(getContext(), true);
            else
                ShareCacheUtil.saveSingleGoodsShareImage(getContext(), false);
        }
        qrCodeUpdatehandler.sendEmptyMessage((int) var1);
    }
 
}