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
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
package com.tejia.lijin.app.ui.mine;
 
import android.Manifest;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
 
import androidx.databinding.BindingAdapter;
import androidx.databinding.DataBindingUtil;
 
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
 
import androidx.annotation.NonNull;
 
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;
import android.widget.Toast;
 
import com.alibaba.baichuan.trade.biz.login.AlibcLogin;
import com.alibaba.baichuan.trade.biz.login.AlibcLoginCallback;
import com.bumptech.glide.Glide;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.tejia.lijin.app.entity.common.GoodsConvertLinkJumpLink;
import com.tejia.lijin.app.ui.dialog.ShapeLoadingDialog;
import com.tejia.lijin.app.util.GoodsBuyJumpUtil;
import com.tejia.lijin.app.util.user.UserUtil;
import com.tencent.mm.opensdk.modelmsg.SendAuth;
import com.wpc.library.util.common.DimenUtils;
import com.wpc.library.util.common.StringUtils;
import com.tejia.lijin.app.BasicTextHttpResponseHandler;
import com.tejia.lijin.app.R;
import com.tejia.lijin.app.ShoppingApi;
import com.tejia.lijin.app.ShoppingApplication;
import com.tejia.lijin.app.callBack.PermissionInterface;
import com.tejia.lijin.app.databinding.ActivityMyinfoMvvmBinding;
import com.tejia.lijin.app.entity.JumpDetail;
import com.tejia.lijin.app.entity.UserInfo;
import com.tejia.lijin.app.ui.BaseActivity;
import com.tejia.lijin.app.ui.dialog.AddZFBInfoDialog2;
import com.tejia.lijin.app.ui.invite.ShareBrowserActivity;
import com.tejia.lijin.app.util.GlideCircleTransform;
import com.tejia.lijin.app.util.JumpActivityUtil;
import com.tejia.lijin.app.util.PermissionHelper;
import com.tejia.lijin.app.util.Photo_crop;
import com.tejia.lijin.app.util.TopStatusSettings;
import com.tejia.lijin.app.util.baichuan.AlibcTradeUtil;
import com.tejia.lijin.app.util.clipboard.ClipboardUtil;
 
import org.apache.http.Header;
import org.json.JSONObject;
 
import java.io.File;
 
import de.greenrobot.event.EventBus;
 
/**
 * Created by weikou2015 on 2017/12/15.
 * 我的信息
 */
 
public class MyInfoActivity extends BaseActivity implements View.OnClickListener, PermissionInterface {
 
    //    private DisplayImageOptions options;
    public ActivityMyinfoMvvmBinding binding;
    //邀请码是否已经修改过
    private boolean invitCodeUpdated = true;
    //邀请码
    private String inviteCode = null;
    //vip升级链接
    private String vipLink = null;
 
    private String fansCountLink;
 
    //拼多多是否备案
    private Boolean pddBuyBind;
    private Boolean pddShareBind;
 
    protected ShapeLoadingDialog loading = null;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_myinfo_mvvm);
//        TopStatusSettings.setStatusView(this, binding.includeStatusBar.vStatusBar);
        TopStatusSettings.setStatusViewAndDeepColor(this);
        EventBus.getDefault().register(this);
        binding.includeTopBar.tvTopBarMiddle.setText("我的信息");
//        tv_middle.setText("我的信息");
        binding.includeTopBar.tvTopBarLeft.setOnClickListener(this);
        binding.llInfoSex.setOnClickListener(this);
        binding.llInfoPortrait.setOnClickListener(this);
        binding.llInfoNickname.setOnClickListener(this);
        binding.llInfoRelativeQq.setOnClickListener(this);
        binding.llInfoTbaccount.setOnClickListener(this);
        binding.llInfoRelativeWechat.setOnClickListener(this);
        binding.llInfoRelativeMobile.setOnClickListener(this);
        binding.llInfoInviteCode.setOnClickListener(this);
        binding.llInfoFans.setOnClickListener(this);
        binding.llInfoPddBuy.setOnClickListener(this);
        binding.llInfoPddShare.setOnClickListener(this);
 
 
        binding.tvInfoUid.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                if (binding.tvInfoUid.getText() != null && !StringUtils.isEmpty(binding.tvInfoUid.getText().toString())) {
                    ClipboardUtil.copy(getApplicationContext(), binding.tvInfoUid.getText().toString());
 
                    Toast.makeText(MyInfoActivity.this, "复制成功", Toast.LENGTH_SHORT).show();
                }
                return false;
            }
        });
        mPermissionsChecker = new PermissionHelper(this, this);//权限
 
        loading = new ShapeLoadingDialog.Builder(this).build();
    }
 
    @Override
    protected void onResume() {
        super.onResume();
        SharedPreferences sp = getSharedPreferences("user", MODE_PRIVATE);
        mUid = sp.getString("uid", "0");
        if (sp.getBoolean("isLogin", false)) {
            getUserInfo(sp.getString("uid", "0"));
        }
    }
 
    @Override
    public void onClick(View view) {
        Boolean buy = null;
        switch (view.getId()) {
            case R.id.tv_top_bar_left:
                finish();
                break;
            case R.id.ll_info_relative_wechat: {
                if (info == null)
                    return;
                String title = "更换微信帐号";
                String message = "确定更换微信账号";
                String positive = "更换";
                if (StringUtils.isEmpty(info.getWxOpenId())) {//微信
                    title = "绑定微信帐号";
                    message = "确定绑定微信账号";
                    positive = "绑定";
                }
 
                if (StringUtils.isEmpty(phoneNum)) {
                    title = "更换提醒";
                    message = "该帐号没有绑定手机号,需绑定手机号才能完成微信更换。";
                    positive = "绑定手机号";
                }
                AddZFBInfoDialog2.Builder builder1 = new AddZFBInfoDialog2.Builder(MyInfoActivity.this);
                builder1.setTitle(title).setMessage(message)
                        .setPositiveButton(positive, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                                if (StringUtils.isEmpty(phoneNum)) {
                                    bindMobile();
                                } else {
                                    bindWx();
                                }
                            }
                        }).setNegativeButton("不了", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).create().show();
                break;
            }
 
            case R.id.ll_info_relative_qq: {
                if (info == null)
                    return;
                String title = "更换QQ帐号";
                String message = "确定更换QQ帐号";
                String positive = "更换";
                if (StringUtils.isEmpty(info.getQqOpenId())) {//QQ
                    title = "绑定QQ帐号";
                    message = "确定绑定QQ账号";
                    positive = "绑定";
                }
 
                if (StringUtils.isEmpty(phoneNum)) {
                    title = "更换提醒";
                    message = "该帐号没有绑定手机号,需绑定手机号才能完成QQ更换。";
                    positive = "绑定手机号";
                }
                AddZFBInfoDialog2.Builder builder1 = new AddZFBInfoDialog2.Builder(MyInfoActivity.this);
                builder1.setTitle(title).setMessage(message)
                        .setPositiveButton(positive, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                                if (StringUtils.isEmpty(phoneNum)) {
                                    bindMobile();
                                } else {
                                    bindQQ();
                                }
                            }
                        }).setNegativeButton("不了", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).create().show();
                break;
            }
 
            case R.id.ll_info_tbaccount:
                String title1 = "更换淘宝账号";
                String message1 = "确定更换淘宝账号";
                String positive1 = "更换";
                if (info != null && StringUtils.isEmpty(info.getOpenid())) {//淘宝
                    title1 = "绑定淘宝账号";
                    message1 = "确定绑定淘宝账号";
                    positive1 = "绑定";
                }
 
                if (info != null && StringUtils.isEmpty(phoneNum)) {
                    title1 = "更换提醒";
                    positive1 = "绑定手机号";
                    message1 = "该帐号没有绑定手机号,需绑定手机号才能完成淘宝更换。";
                }
                AddZFBInfoDialog2.Builder builder2 = new AddZFBInfoDialog2.Builder(MyInfoActivity.this);
                builder2.setTitle(title1).setMessage(message1)
                        .setPositiveButton(positive1, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                                if (StringUtils.isEmpty(phoneNum)) {
                                    bindMobile();
                                } else {
                                    bindTB();
                                }
                            }
                        }).setNegativeButton("不了", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).create().show();
                break;
            case R.id.ll_info_relative_mobile://电话号码绑定
                bindMobile();
                break;
            case R.id.ll_info_portrait://更换头像
                if (mPermissionsChecker.lacksPermissions(getPermissions())) {//检测是否有写入的权限
                    mPermissionsChecker.showNormalDialog();
                } else {
                    popwindow_img();//选择相册
                }
                break;
            case R.id.ll_info_nickname:
                startActivity(new Intent(this, MyNickName.class).putExtra("name", binding.tvInfoNickname.getText().toString()));
                break;
            case R.id.ll_info_sex://设置性别
                popwindow_sex();//选择相册
                break;
            case R.id.ll_info_invite_code://邀请码
                if (info == null)
                    return;
                if (invitCodeUpdated || StringUtils.isEmpty(inviteCode) || !info.isVip())
                    return;
                Intent intent2 = new Intent(this, MyInviteCodeActivity.class);
                intent2.putExtra("inviteCode", inviteCode);
                startActivity(intent2);
                break;
            case R.id.ll_info_fans:
                startActivity(new Intent(this, ShareBrowserActivity.class).putExtra("url", fansCountLink));
                break;
 
            case R.id.ll_info_pdd_buy:
                buy = true;
            case R.id.ll_info_pdd_share:
                if (buy == null)
                    buy = false;
                ShoppingApi.getPDDAuthInfo(getApplicationContext(), UserUtil.getUid(getApplicationContext()) , buy, new BasicTextHttpResponseHandler() {
                    @Override
                    public void onStart() {
                        super.onStart();
                        if (loading != null && !loading.isShowing())
                            loading.show();
                    }
 
                    @Override
                    public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                        super.onSuccessPerfect(statusCode, headers, jsonObject);
                        if (jsonObject.optInt("code") == 0) {
                            JSONObject data = jsonObject.optJSONObject("data");
                            GoodsConvertLinkJumpLink pddJumpLink = new Gson().fromJson(data.toString(), GoodsConvertLinkJumpLink.class);
                            GoodsBuyJumpUtil.jumpPDD(getApplicationContext(), pddJumpLink);
                        } else {
                            Toast.makeText(MyInfoActivity.this, jsonObject.optString("msg"), Toast.LENGTH_SHORT).show();
                        }
                    }
 
                    @Override
                    public void onFailure(int statusCode, Header[] headers, String jsonObject, Throwable e) {
                        super.onFailure(statusCode, headers, jsonObject, e);
                    }
 
                    @Override
                    public void onFinish() {
                        super.onFinish();
                        if (loading != null && loading.isShowing())
                            loading.dismiss();
                    }
                });
 
                break;
        }
    }
 
    private PermissionHelper mPermissionsChecker; // 权限检测器 检测是否有储存卡写入读取权限
 
    /**
     * 权限请求码
     *
     * @return
     */
    @Override
    public int getPermissionsRequestCode() {
        return 1001;
    }
 
    /**
     * 请求权限
     *
     * @return
     */
    @Override
    public String[] getPermissions() {
        return new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE};
    }
 
    /**
     * 权限请求成功
     */
    @Override
    public void requestPermissionsSuccess() {
        binding.llInfoPortrait.performClick();
    }
 
    /**
     * 权限请求失败
     */
    @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) {
        if (mPermissionsChecker.requestPermissionsResult(requestCode, permissions, grantResults)) {
            //权限请求结果,并已经处理了该回调
            return;
        }
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }
 
    /**
     * 从相册选择 图片
     */
    private void popwindow_img() {
        View view = getLayoutInflater().inflate(R.layout.myinfo_photopreview, null);
 
        final PopupWindow popupBigPhoto = new PopupWindow(view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
 
        //必须设置以下两项,否则弹出窗口无法取消
        popupBigPhoto.setFocusable(true);
        setBackgroundAlpha(0.5f);//设置屏幕透明度
        popupBigPhoto.setBackgroundDrawable(new BitmapDrawable());
        //设置动画效果
//        popupBigPhoto.setAnimationStyle(R.style.AnimBottom);
        // 设置点击popupwindow外屏幕其它地方消失
        popupBigPhoto.setOutsideTouchable(true);
//设置显示位置,findViewById获取的是包含当前整个页面的view
        popupBigPhoto.showAtLocation(getWindow().getDecorView(), Gravity.BOTTOM, 0, 0);
        TextView myinfo_photopreview_photo = view.findViewById(R.id.myinfo_photopreview_photo);
        TextView myinfo_photopreview_cancle = view.findViewById(R.id.myinfo_photopreview_photo_cancle);
        myinfo_photopreview_cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupBigPhoto.dismiss();
            }
        });
        popupBigPhoto.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                setBackgroundAlpha(1.0f);
            }
        });
        myinfo_photopreview_photo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 打开系统图库选择图片
                Intent picture = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                //解决手机找不到activity 方案一 检测裁是否有对应的app(选择了方案二 方案一占时屏蔽)
//                PackageManager packageManager = getPackageManager();
//                List<ResolveInfo> applist = packageManager.queryIntentActivities(picture, 0);
//                if (applist == null || applist.isEmpty()) {
//                    Toast.makeText(MyInfoActivity.this, "no activity", Toast.LENGTH_SHORT).show();
//                    return;
//                }
                //解决手机找不到activity 方案二 抛异常
                try {
                    startActivityForResult(picture, 1001);
                } catch (ActivityNotFoundException exception) {
                    Toast.makeText(MyInfoActivity.this, "no activity", Toast.LENGTH_SHORT).show();
                }
                popupBigPhoto.dismiss();
            }
        });
 
    }
 
    /**
     * 性别选择
     */
    private void popwindow_sex() {
        View view = getLayoutInflater().inflate(R.layout.myinfo_photopreview, null);
        final PopupWindow popupSex = new PopupWindow(view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
 
        //必须设置以下两项,否则弹出窗口无法取消
        popupSex.setFocusable(true);
        setBackgroundAlpha(0.5f);//设置屏幕透明度
        popupSex.setBackgroundDrawable(new BitmapDrawable());
        //设置动画效果
//        popupBigPhoto.setAnimationStyle(R.style.AnimBottom);
        // 设置点击popupwindow外屏幕其它地方消失
        popupSex.setOutsideTouchable(true);
//设置显示位置,findViewById获取的是包含当前整个页面的view
        popupSex.showAtLocation(getWindow().getDecorView(), Gravity.BOTTOM, 0, 0);
        TextView myinfo_sex_boy = view.findViewById(R.id.myinfo_sex_boy);
        View v_line = view.findViewById(R.id.v_line);
        TextView myinfo_sex_girl = view.findViewById(R.id.myinfo_photopreview_photo);
        TextView myinfo_photopreview_cancle = view.findViewById(R.id.myinfo_photopreview_photo_cancle);
        myinfo_sex_boy.setVisibility(View.VISIBLE);
        v_line.setVisibility(View.VISIBLE);
        myinfo_sex_girl.setText("女");
        myinfo_photopreview_cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popupSex.dismiss();
            }
        });
        popupSex.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                setBackgroundAlpha(1.0f);
            }
        });
        myinfo_sex_boy.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                saveInfo(null, null, 2);
                popupSex.dismiss();
            }
        });
        myinfo_sex_girl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                saveInfo(null, null, 1);
                popupSex.dismiss();
            }
        });
 
    }
 
    /**
     * 保存用户信息
     */
    private void saveInfo(String nickName, String weixin, final Integer sex) {
        ShoppingApi.saveInfo(this, UserUtil.getUid(ShoppingApplication.application), nickName, weixin, sex, null, null, new BasicTextHttpResponseHandler() {
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                if (jsonObject.optInt("code") == 0) {
                    if (sex != null)
                        binding.tvInfoSex.setText(sex == 2 ? "男" : "女");
                }
            }
        });
    }
 
    /**
     * 设置添加屏幕的背景透明度
     *
     * @param bgAlpha 屏幕透明度0.0-1.0 1表示完全不透明
     */
    public void setBackgroundAlpha(float bgAlpha) {
        WindowManager.LayoutParams lp = getWindow()
                .getAttributes();
        lp.alpha = bgAlpha;
        getWindow().setAttributes(lp);
    }
 
    /*
     *绑定手机号
     */
    private void bindMobile() {
        Intent intent = new Intent(MyInfoActivity.this, LoginSelectActivity.class);
        intent.putExtra("uid", mUid);
        intent.putExtra("type", LoginSelectActivity.TYPE_BIND);
        startActivity(intent);
    }
 
    private void bindWx() {
        if (ShoppingApplication.application.mWxApi.isWXAppInstalled()) {
            SharedPreferences sp = getSharedPreferences("user", MODE_PRIVATE);
            SharedPreferences.Editor editor = sp.edit();
            editor.putBoolean("closeHint", false);
            editor.putBoolean("bindwx", true);
            editor.commit();
            SendAuth.Req req = new SendAuth.Req();
            req.scope = "snsapi_userinfo";
            req.state = "rebate";
            ShoppingApplication.application.mWxApi.sendReq(req);
        } else {
//            SingleToast.showToast(MyInfoActivity.this, "请先安装微信客户端");
            Toast.makeText(MyInfoActivity.this, "请先安装微信客户端", Toast.LENGTH_SHORT).show();
        }
    }
 
 
    private void bindQQ() {
        if (ShoppingApplication.application.mWxApi.isWXAppInstalled()) {
            SharedPreferences sp = getSharedPreferences("user", MODE_PRIVATE);
            SharedPreferences.Editor editor = sp.edit();
            editor.putBoolean("closeHint", false);
            editor.putBoolean("bindqq", true);
            editor.commit();
            SendAuth.Req req = new SendAuth.Req();
            req.scope = "snsapi_userinfo";
            req.state = "rebate";
            ShoppingApplication.application.mWxApi.sendReq(req);
        } else {
//            SingleToast.showToast(MyInfoActivity.this, "请先安装微信客户端");
            Toast.makeText(MyInfoActivity.this, "请先安装QQ客户端", Toast.LENGTH_SHORT).show();
        }
    }
 
    /*
    绑定淘宝授权
     */
    private void getTaoBaoH5AuthInfo() {
        ShoppingApi.getTaoBaoAuthInfo(MyInfoActivity.this, UserUtil.getUid(ShoppingApplication.application), "", "bind", true, new BasicTextHttpResponseHandler() {
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                if (jsonObject.optInt("code") == 0) {
                    String authLink = jsonObject.optJSONObject("data").getString("authLink");
                    if (!StringUtils.isEmpty(authLink)) {
//                        Intent intent = new Intent(MyInfoActivity.this, ShareBrowserActivity.class);
//                        intent.putExtra("url", authLink);
//                        startActivity(intent);
//                        AlibcTradeUtil.openByUrl(MyInfoActivity.this, authLink, null, new WebViewClient(),
//                                new WebChromeClient(), null, null,null);
 
                        AlibcTradeUtil.openAuthLink(MyInfoActivity.this, authLink);
                    }
                }
            }
 
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                super.onFailure(statusCode, headers, responseString, throwable);
                Toast.makeText(MyInfoActivity.this, "请求失败", Toast.LENGTH_SHORT).show();
                AlibcLogin.getInstance().logout(new AlibcLoginCallback() {
 
                    @Override
                    public void onSuccess(int i, String s, String s1) {
 
                    }
 
                    @Override
                    public void onFailure(int i, String s) {
 
                    }
                });
            }
 
        });
    }
 
    private void bindTB() {
        AlibcLogin alibcLogin = AlibcLogin.getInstance();
        if (alibcLogin.isLogin()) {
            getTaoBaoH5AuthInfo();
        } else {
            alibcLogin.showLogin(new AlibcLoginCallback() {
 
                @Override
                public void onSuccess(int i, String s, String s1) {
                    SharedPreferences.Editor editor = getSharedPreferences("user",
                            MODE_PRIVATE).edit();
                    editor.putString("TrolleyTransformationLink", "");
                    editor.commit();
                    getTaoBaoH5AuthInfo();
                }
 
                @Override
                public void onFailure(int code, String msg) {
                    Toast.makeText(MyInfoActivity.this, "登录失败,请稍候重试",
                            Toast.LENGTH_LONG).show();
                }
            });
        }
    }
 
    String mUid = "";
    String phoneNum = "";
    String weixin = "";
    String weixintip = "";
    VIPActionInfo vipAction = null;
 
    private void getUserInfo(String uid) {
        ShoppingApi.getUserInfo2(this, UserUtil.getUid(ShoppingApplication.application), new BasicTextHttpResponseHandler() {
            @Override
            public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                if (jsonObject.optString("code").equalsIgnoreCase("0")) {
                    JSONObject data = jsonObject.optJSONObject("data");
                    vipLink = data.optString("vipLink");
                    inviteCode = data.optString("invitCode");
                    invitCodeUpdated = data.optBoolean("invitCodeUpdated");
                    fansCountLink = data.optString("fansCountLink");
                    if (data.optJSONObject("vipAction") != null) {
                        vipAction = new Gson().fromJson(data.optJSONObject("vipAction").toString(), VIPActionInfo.class);
                    }
                    pddBuyBind = data.optBoolean("pddBuyBind");
                    pddShareBind = data.optBoolean("pddShareBind");
 
 
                    String json = data.optJSONObject("user").toString();
                    bindData(json);
                }
            }
        });
    }
 
    private UserInfo info;
 
    /**
     * 填充页面数据
     */
    private void bindData(String json) {
        if (StringUtils.isEmpty(json))
            return;
        Gson gson = new GsonBuilder().serializeNulls().create();
        info = gson.fromJson(json, new TypeToken<UserInfo>() {
        }.getType());
        Log.i("mResult", json);
        mUid = info.getId();
        phoneNum = info.getPhone();
        weixin = info.getWeiXin();
        weixintip = info.getWeiXinTip();
        binding.setUserInfo(info);
//        binding.tvInfoSex.setText(info.getSex() == 0 ? "去设置" : info.getSex() == 1 ? "女" : "男");
 
        if (StringUtils.isEmpty(info.getWxOpenId())) {//微信
            binding.tvInfoRelativeWechat.setText("去绑定");
        } else {
            binding.tvInfoRelativeWechat.setText(info.getWxName());
        }
 
        if (StringUtils.isEmpty(info.getQqOpenId())) {//QQ
            binding.tvInfoRelativeQq.setText("去绑定");
        } else {
            binding.tvInfoRelativeQq.setText(info.getQqNickName());
        }
 
        if (StringUtils.isEmpty(info.getOpenid())) {//淘宝
            binding.tvInfoTbaccount.setText("去绑定");
        } else {
            binding.tvInfoTbaccount.setText(info.getTbName());
        }
        if (StringUtils.isEmpty(info.getPhone())) {//手机
            binding.tvInfoRelativeMobile.setText("去绑定");
        } else {
            binding.tvInfoRelativeMobile.setText(info.getPhone());
        }
 
        if (pddBuyBind != null) {
            if (pddBuyBind) {
                binding.tvInfoPddBuy.setText("去更改");
            } else {
                binding.tvInfoPddBuy.setText("去备案");
            }
        } else {
            binding.tvInfoPddBuy.setText("");
        }
 
        if (pddShareBind != null) {
            if (pddShareBind) {
                binding.tvInfoPddShare.setText("去更改");
            } else {
                binding.tvInfoPddShare.setText("去备案");
            }
        } else {
            binding.tvInfoPddShare.setText("");
        }
 
 
        //邀请码设置
//        if (StringUtils.isEmpty(inviteCode) || !info.isVip())
//            binding.llInfoInviteCode.setVisibility(View.GONE);
//        else {
//            binding.llInfoInviteCode.setVisibility(View.VISIBLE);
//            binding.tvInfoInviteCode.setText(inviteCode);
//            if (invitCodeUpdated || !info.isVip()) {
//                binding.ivInfoInviteCodeEdit.setVisibility(View.GONE);
//                ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) binding.tvInfoInviteCode.getLayoutParams();
//                params.setMargins(0, 0, DimenUtils.dip2px(this, 20), 0);
//                binding.tvInfoInviteCode.requestLayout();
//            } else {
//                binding.ivInfoInviteCodeEdit.setVisibility(View.VISIBLE);
//                ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) binding.tvInfoInviteCode.getLayoutParams();
//                params.setMargins(0, 0, DimenUtils.dip2px(this, 10), 0);
//                binding.tvInfoInviteCode.requestLayout();
//            }
//        }
 
        //是否显示邀请人
//        if (StringUtils.isEmpty(fansCountLink)) {
//            binding.llInfoFans.setVisibility(View.GONE);
//        } else {
//            binding.llInfoFans.setVisibility(View.VISIBLE);
//            binding.ivInfoFansEdit.setVisibility(View.VISIBLE);
//        }
 
 
    }
 
    //图片展示  头像展示
    @BindingAdapter({"portraitUrl"})
    public static void loadPortrait(ImageView view, String url) {
        Glide.with(view.getContext())
                .load(url)
                .transform(new GlideCircleTransform(view.getContext()))
                .into(view);
    }
 
    public void onEventMainThread(UserInfo info) {
        binding.tvInfoRelativeWechat.setText(info.getNickName());
    }
 
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        //图库
        if (resultCode == RESULT_OK && resultCode != RESULT_CANCELED && requestCode == 1001 && data != null) {//相册
            Uri selectedImage = data.getData();
            startPhotoZoom(selectedImage);//系统剪裁
        } else if (resultCode == RESULT_OK && requestCode == 1002 && data != null) {//剪裁完成
            if (uriClipUri != null) {
                //图库
                Photo_crop crop = new Photo_crop();//初始化 图片压缩
                File f = new File(uriClipUri.getPath());//获取图片
                if (crop.compressPhto(f, false)) {//压缩并保存成功
                    uploadPortrait();//更换头像
                }
            }
        }
    }
 
    /**
     * 更换头像
     */
    private void uploadPortrait() {
        Uri uri = Uri.parse("file://" + "/" + Environment.getExternalStorageDirectory().getPath() + "/FLQImg/" + "avatar.png");
        File f = new File(uri.getPath());
        File[] photo = new File[1];
        photo[0] = f;
        final SharedPreferences sp = getSharedPreferences("user", MODE_PRIVATE);
        if (sp.getBoolean("isLogin", false)) {
            mUid = sp.getString("uid", "0");
            ShoppingApi.uploadPortrait(this, UserUtil.getUid(ShoppingApplication.application), photo, new BasicTextHttpResponseHandler() {
                @Override
                public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
                    if (jsonObject.optInt("code") == 0) {
                        getUserInfo(mUid);
                    }
                }
            });
        }
    }
 
    private Uri uriClipUri;//剪裁图片路径
 
    /**
     * 获取相册图片
     *
     * @param uri
     */
    public void startPhotoZoom(Uri uri) {
        File storageDir = new File(Environment.getExternalStorageDirectory().getPath() + "/FLQImg/");
        if (!storageDir.exists()) {//没有文件夹则创建
            storageDir.mkdir();
        }
        //com.android.camera.action.CROP,这个action是调用系统自带的图片裁切功能
        Intent intent = new Intent("com.android.camera.action.CROP");
        intent.setDataAndType(uri, "image/*");//裁剪的图片uri和图片类型
        intent.putExtra("crop", "true");//设置允许裁剪,如果不设置,就会跳过裁剪的过程,还可以设置putExtra("crop", "circle")
        if (Build.MANUFACTURER.equals("HUAWEI")) { //华为特殊处理 不然会显示圆
            intent.putExtra("aspectX", 9998);
            intent.putExtra("aspectY", 9999);
        } else {
            intent.putExtra("aspectX", 1);//裁剪框的 X 方向的比例,需要为整数
            intent.putExtra("aspectY", 1);//裁剪框的 Y 方向的比例,需要为整数
        }
        intent.putExtra("outputX", 250);//返回数据的时候的X像素大小。
        intent.putExtra("outputY", 250);//返回数据的时候的Y像素大小。
        //裁剪时是否保留图片的比例,这里的比例是1:1
        intent.putExtra("scale", true);
        //是否是圆形裁剪区域,设置了也不一定有效
        intent.putExtra("circleCrop", false);
 
        //uritempFile为Uri类变量,实例化uritempFile
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            //如果是7.0的相册
            //设置裁剪的图片地址Uri
            uriClipUri = Uri.parse("file://" + "/" + Environment.getExternalStorageDirectory().getPath() + "/FLQImg/" + "clip.jpg");
        } else {
            uriClipUri = Uri.parse("file://" + "/" + Environment.getExternalStorageDirectory().getPath() + "/FLQImg/" + "clip.jpg");
        }
        //Android 对Intent中所包含数据的大小是有限制的,一般不能超过 1M,否则会使用缩略图 ,所以我们要指定输出裁剪的图片路径
        intent.putExtra(MediaStore.EXTRA_OUTPUT, uriClipUri);
        intent.putExtra("return-data", false);//是否将数据保留在Bitmap中返回
        intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());//输出格式,一般设为Bitmap格式及图片类型
        intent.putExtra("noFaceDetection", false);//人脸识别功能
        startActivityForResult(intent, 1002);//裁剪完成的标识
    }
 
    private void updateInviteCode() {
        if (invitCodeUpdated)
            return;
 
 
    }
 
    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
 
    class VIPActionInfo {
        private String name;
        private String content;
        private JumpDetail jumpDetail;
        private com.alibaba.fastjson.JSONObject params;
 
        public String getName() {
            return name;
        }
 
        public void setName(String name) {
            this.name = name;
        }
 
        public String getContent() {
            return content;
        }
 
        public void setContent(String content) {
            this.content = content;
        }
 
        public JumpDetail getJumpDetail() {
            return jumpDetail;
        }
 
        public void setJumpDetail(JumpDetail jumpDetail) {
            this.jumpDetail = jumpDetail;
        }
 
        public com.alibaba.fastjson.JSONObject getParams() {
            return params;
        }
 
        public void setParams(com.alibaba.fastjson.JSONObject params) {
            this.params = params;
        }
 
 
    }
}