mac
2024-07-02 d7ff801372431e64aee8f68ece4b8532cffb2207
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
package com.hdl.photovoltaic.ui.me;
 
import android.Manifest;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
 
 
import androidx.activity.result.ActivityResultLauncher;
import androidx.annotation.Nullable;
import androidx.appcompat.content.res.AppCompatResources;
 
 
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.hdl.linkpm.sdk.core.callback.IResponseCallBack;
import com.hdl.linkpm.sdk.core.exception.HDLException;
import com.hdl.linkpm.sdk.user.HDLLinkPMUser;
import com.hdl.linkpm.sdk.user.bean.ImageSubmitInfo;
import com.hdl.photovoltaic.R;
import com.hdl.photovoltaic.base.CustomBaseActivity;
 
import com.hdl.photovoltaic.config.UserConfigManage;
import com.hdl.photovoltaic.databinding.ActivityPersonalDataBinding;
import com.hdl.photovoltaic.listener.CloudCallBeak;
import com.hdl.photovoltaic.other.HdlAccountLogic;
import com.hdl.photovoltaic.other.HdlThreadLogic;
import com.hdl.photovoltaic.other.HdlUniLogic;
import com.hdl.photovoltaic.ui.bean.QrCodeBean;
import com.hdl.photovoltaic.uni.HDLUniMP;
import com.hdl.photovoltaic.utils.GlideUtils;
import com.hdl.photovoltaic.utils.PermissionUtils;
import com.hdl.photovoltaic.widget.ConfirmationInputDialog;
import com.hdl.photovoltaic.widget.popupview.CameraAlbumPopWindow;
 
import java.io.File;
 
 
/**
 * C端个人资料的界面
 */
public class CPersonalDataActivity extends CustomBaseActivity {
    private ActivityPersonalDataBinding viewBinding;
 
    private CameraAlbumPopWindow cameraAlbumPopWindow;
    //头像地址
    private String mMemberHeadIconUrl;
    private ActivityResultLauncher<String[]> generalPermission;
 
 
    @Override
    public Object getContentView() {
        viewBinding = ActivityPersonalDataBinding.inflate(getLayoutInflater());
        return viewBinding.getRoot();
    }
 
    @Override
    public void onBindView(Bundle savedInstanceState) {
        setNotificationBarBackgroundColor(CustomColor.white);
        setStatusBarTextColor();
        mMemberHeadIconUrl = UserConfigManage.getInstance().getUserImageUrl();
        //初始化
        initView();
        //初始化界面监听器
        initEvent();
        //初始化数据
        initData();
    }
 
    private void initData() {
//        generalPermission = registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), new ActivityResultCallback<Map<String, Boolean>>() {
//            @Override
//            public void onActivityResult(Map<String, Boolean> result) {
//
//            }
//        });
//        generalPermission.launch(new String[]{});
 
//        generalPermission = registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), new ActivityResultCallback<Map<String, Boolean>>() {
//            @Override
//            public void onActivityResult(Map<String, Boolean> result) {
//
////                        if (value == PermissionUtils.STATUS_REFUSE_PERMANENT) {
////                            HdlThreadLogic.toast(_mActivity, R.string.permission_open);
////                            return;
////                        }
//                        changedUserAvatar();
//            }
//        });
 
    }
 
    private void initEvent() {
 
        viewBinding.toolbarTopFragmentMeRl.topBackLl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                backPressedData();
                finish();
            }
        });
        viewBinding.personalDataUserPortraitIl.getRoot().setOnClickListener(new View.OnClickListener() {
 
            @Override
            public void onClick(View v) {
                //Manifest.permission.WRITE_EXTERNAL_STORAGE 读写设备上的照片以及文件
                //generalPermission.launch(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE});
 
                PermissionUtils.requestPermissionsResultCallback(_mActivity, Manifest.permission.WRITE_EXTERNAL_STORAGE, new PermissionUtils.PermissionState() {
                    @Override
                    public void Success(int value) {
                        if (value == PermissionUtils.STATUS_REFUSE_PERMANENT) {
//                            HdlThreadLogic.toast(_mActivity, R.string.permission_open);
                            return;
                        }
                        changedUserAvatar();
                    }
                }, true);
 
            }
        });
 
        viewBinding.personalDataUserNameIl.getRoot().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                changedNickname();
            }
        });
        viewBinding.personalDataPhoneIl.getRoot().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(_mActivity, BindPhoneActivity.class);
                startActivityForResult(intent, 20);
            }
        });
        viewBinding.personalDataMailIl.getRoot().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(_mActivity, BindMailActivity.class);
                startActivityForResult(intent, 20);
            }
        });
        viewBinding.personalDataQrCodeIl.getRoot().setOnClickListener(new View.OnClickListener() {
 
            @Override
            public void onClick(View v) {
 
                startActivity(QrCodeMainActivity.class);
 
            }
        });
 
 
    }
 
    private void initView() {
        viewBinding.toolbarTopFragmentMeRl.topTitleTv.setText(R.string.me_personal_data);
        viewBinding.toolbarTopFragmentMeRl.topBackLl.setVisibility(View.VISIBLE);
        viewBinding.toolbarTopFragmentMeRl.topTitleTv.setTextColor(getResources().getColor(R.color.text_030D1C, null));
        viewBinding.toolbarTopFragmentMeRl.topBarView.setBackgroundColor(getResources().getColor(R.color.text_FFFFFFFF, null));
        viewBinding.personalDataUserPortraitIl.sllLlRlNameTv.setText(R.string.me_personal_data_portrait);
        viewBinding.personalDataUserNameIl.sllLlRlNameTv.setText(R.string.me_personal_data_user_name);
        viewBinding.personalDataMailIl.sllLlRlNameTv.setText(R.string.home_login_email);
        viewBinding.personalDataPhoneIl.sllLlRlNameTv.setText(R.string.home_login_phone);
        viewBinding.personalDataQrCodeIl.sllLlRlNameTv.setText(R.string.qr_code_business_card);
        viewBinding.personalDataUserPortraitIl.sllLlRlRightContentIv.setVisibility(View.VISIBLE);
        viewBinding.personalDataUserNameIl.sllLlRlRightContentTv.setVisibility(View.VISIBLE);
        viewBinding.personalDataMailIl.sllLlRlRightContentTv.setVisibility(View.VISIBLE);
        viewBinding.personalDataPhoneIl.sllLlRlRightContentTv.setVisibility(View.VISIBLE);
        viewBinding.personalDataQrCodeIl.sllLlRlRightContentIv.setVisibility(View.VISIBLE);
        viewBinding.personalDataUserNameIl.sllLlRlRightContentTv.setText(UserConfigManage.getInstance().getUserName());
        viewBinding.personalDataQrCodeIl.sllLlRlRightContentIv.setImageDrawable(AppCompatResources.getDrawable(_mActivity, R.drawable.qr_code));
        setMemberHeadIcon();
        updateStyle();
    }
 
 
    /**
     * 更改用户头像;
     */
    private void changedUserAvatar() {
        if (UserConfigManage.getInstance().isBAccount()) {
            //todo B端不支持更改昵称
            HdlThreadLogic.toast(_mActivity, R.string.loading_not_supported);
        } else {
            cameraAlbumPopWindow = new CameraAlbumPopWindow(_mActivity, new CameraAlbumPopWindow.CameraAlbumListener() {
                @Override
                public void successCallBack(final File a) {
                    //上传头像文件
                    HDLLinkPMUser.getInstance().uploadUserHeadImage(a, new IResponseCallBack<ImageSubmitInfo>() {
                        @Override
                        public void onSuccess(ImageSubmitInfo imageKey) {
                            JsonObject imageInfo = new JsonObject();
                            imageInfo.addProperty("memberHeadIcon", imageKey.getUrl());
                            //上传头像地址
                            HdlAccountLogic.getInstance().updateMemberHeadIcon_C(imageKey.getUrl(), new CloudCallBeak<Boolean>() {
                                @Override
                                public void onSuccess(Boolean obj) {
                                    mMemberHeadIconUrl = imageKey.getUrl();
                                    setMemberHeadIcon();
                                    backPressedData();
                                }
 
                                @Override
                                public void onFailure(HDLException e) {
 
                                    HdlThreadLogic.toast(_mActivity, e);
//                                    HdlLogLogic.print("uploadUserHeadImage error:" + error.getMsg());
//                                    hideLoading();
                                }
                            });
                        }
 
                        @Override
                        public void onFailure(HDLException e) {
//                            HdlThreadLogic.tipFlashingBox(_mActivity, false, e.getMsg(), e.getCode());
                            HdlThreadLogic.toast(_mActivity, e);
                        }
                    });
                }
            });
            cameraAlbumPopWindow.show(viewBinding.getRoot(), Gravity.BOTTOM, 0, 0);
        }
 
    }
 
 
    /**
     * 修改用户昵称
     */
    private void changedNickname() {
        if (UserConfigManage.getInstance().isBAccount()) {
            //todo B端不支持更改昵称
            HdlThreadLogic.toast(_mActivity, R.string.loading_not_supported);
        } else {
            ConfirmationInputDialog confirmationInputDialog = new ConfirmationInputDialog(_mActivity);
            confirmationInputDialog.setTitle(getString(R.string.set_nickname_modification));
            confirmationInputDialog.setEditContent(UserConfigManage.getInstance().getUserName());
            confirmationInputDialog.show();
            confirmationInputDialog.setYesOnclickListener(new ConfirmationInputDialog.onYesOnclickListener() {
                @Override
                public void Confirm(String str) {
                    HdlAccountLogic.getInstance().updateMemberName_C(str, new CloudCallBeak<Boolean>() {
                        @Override
                        public void onSuccess(Boolean obj) {
                            UserConfigManage.getInstance().setUserName(str);
                            UserConfigManage.getInstance().Save();
                            viewBinding.personalDataUserNameIl.sllLlRlRightContentTv.setText(UserConfigManage.getInstance().getUserName());
                            confirmationInputDialog.dismiss();
                            HdlThreadLogic.tipFlashingBox(_mActivity, true, getString(R.string.home_login_change_name_succeed), 0);
                            backPressedData();
                        }
 
                        @Override
                        public void onFailure(HDLException e) {
                            HdlThreadLogic.tipFlashingBox(_mActivity, false, e.getMsg(), e.getCode());
                        }
                    });
 
                }
            });
            confirmationInputDialog.setNoOnclickListener(new ConfirmationInputDialog.onNoOnclickListener() {
                @Override
                public void Cancel() {
                    confirmationInputDialog.dismiss();
                }
            });
        }
 
    }
 
    /**
     * 显示用户头像
     */
    private void setMemberHeadIcon() {
        if (UserConfigManage.getInstance().isBAccount()) {
            GlideUtils.getRoundedCornersImage(_mActivity, mMemberHeadIconUrl, viewBinding.personalDataUserPortraitIl.sllLlRlRightContentIv, new RoundedCorners(4), true);
        } else {
            GlideUtils.getCircleCropImage(_mActivity, mMemberHeadIconUrl, viewBinding.personalDataUserPortraitIl.sllLlRlRightContentIv, true);
 
        }
    }
 
 
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == CameraAlbumPopWindow.TAKE_PHOTO || requestCode == CameraAlbumPopWindow.SELECT_PHOTO) {
            if (cameraAlbumPopWindow == null) {
                return;
            }
            switch (requestCode) {
                //打开相机后返回
                case CameraAlbumPopWindow.TAKE_PHOTO:
                    if (resultCode == RESULT_OK) {
                        //这种方法是通过内存卡的路径进行读取图片,所以的到的图片是拍摄的原图
                        cameraAlbumPopWindow.displayImage();
                    }
                    break;
                //打开相册后返回
                case CameraAlbumPopWindow.SELECT_PHOTO:
                    if (resultCode == RESULT_OK) {
                        //判断手机系统版本号
                        if (Build.VERSION.SDK_INT > 19) {
                            //4.4及以上系统使用这个方法处理图片
                            cameraAlbumPopWindow.handleImgeOnKitKat(data);
                        } else {
                            cameraAlbumPopWindow.handleImageBeforeKitKat(data);
                        }
                    }
                    break;
                default:
                    break;
            }
        } else if (requestCode == 20 && resultCode == 20) {
            updateStyle();
        }
    }
 
    /**
     * 物理按键返回事件
     */
    @Override
    public void onBackPressed() {
//        backPressedData();
        super.onBackPressed();
    }
 
    /**
     * 返回给上一级界面数据
     */
    private void backPressedData() {
 
        if (UserConfigManage.getInstance().isBAccount()) {
            Intent intent = new Intent();
            intent.putExtra("memberHeadIcon", mMemberHeadIconUrl);
            intent.putExtra("memberName", UserConfigManage.getInstance().getUserName());
            setResult(10, intent);
        } else {
            //通知给小程序更新头像或者用户名
            HDLUniMP.UniCallBackBaseBean uniCallBackBaseBean = new HDLUniMP.UniCallBackBaseBean();
            JsonObject jsonObject = new JsonObject();
            if (!TextUtils.isEmpty(mMemberHeadIconUrl)) {
                jsonObject.addProperty("memberHeadIcon", mMemberHeadIconUrl);
            }
            if (!TextUtils.isEmpty(UserConfigManage.getInstance().getUserName())) {
                jsonObject.addProperty("memberName", UserConfigManage.getInstance().getUserName());
            }
            uniCallBackBaseBean.setType(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_REFRESH_USERINFO);
            uniCallBackBaseBean.setData(jsonObject);
            HdlUniLogic.getInstance().sendUni(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL, uniCallBackBaseBean);
        }
    }
 
    /**
     * 刷新绑定手机号和邮箱
     */
    private void updateStyle() {
        String phoneStr = TextUtils.isEmpty(UserConfigManage.getInstance().getBingPhone()) ? getString(R.string.set_not_bind) : UserConfigManage.getInstance().getBingPhone();
        String emailStr = TextUtils.isEmpty(UserConfigManage.getInstance().getBingEmail()) ? getString(R.string.set_not_bind) : UserConfigManage.getInstance().getBingEmail();
        viewBinding.personalDataPhoneIl.sllLlRlRightContentTv.setText(phoneStr);
        viewBinding.personalDataMailIl.sllLlRlRightContentTv.setText(emailStr);
 
    }
 
 
}