| | |
| | | package com.hdl.photovoltaic.ui.me; |
| | | |
| | | import android.app.AppComponentFactory; |
| | | import android.Manifest; |
| | | import android.content.Intent; |
| | | import android.os.Build; |
| | | import android.os.Bundle; |
| | | import android.view.Gravity; |
| | | import android.view.View; |
| | | |
| | | |
| | | import androidx.activity.result.ActivityResultLauncher; |
| | | import androidx.core.app.ActivityCompat; |
| | | |
| | | |
| | | import com.bumptech.glide.load.resource.bitmap.RoundedCorners; |
| | | 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.databinding.ActivityPersonalDataBinding; |
| | | import com.hdl.photovoltaic.listener.CloudCallBeak; |
| | | import com.hdl.photovoltaic.other.HdlAccountLogic; |
| | | import com.hdl.photovoltaic.other.HdlLogLogic; |
| | | import com.hdl.photovoltaic.other.HdlThreadLogic; |
| | | import com.hdl.photovoltaic.other.HdlUniLogic; |
| | | 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; |
| | | |
| | | |
| | | /** |
| | |
| | | */ |
| | | public class PersonalDataActivity extends CustomBaseActivity { |
| | | private ActivityPersonalDataBinding viewBinding; |
| | | |
| | | private CameraAlbumPopWindow cameraAlbumPopWindow; |
| | | //头像地址 |
| | | private String mMemberHeadIcon; |
| | | private String mMemberHeadIconUrl; |
| | | private ActivityResultLauncher<String[]> generalPermission; |
| | | |
| | | |
| | | @Override |
| | | public Object getContentView() { |
| | |
| | | public void onBindView(Bundle savedInstanceState) { |
| | | setNotificationBarBackgroundColor(CustomColor.white); |
| | | setStatusBarTextColor(); |
| | | mMemberHeadIcon = getIntent().getStringExtra("memberHeadIcon"); |
| | | mMemberHeadIconUrl = getIntent().getStringExtra("memberHeadIcon"); |
| | | //初始化 |
| | | initView(); |
| | | //初始化界面监听器 |
| | |
| | | } |
| | | |
| | | private void initData() { |
| | | viewBinding.toolbarTopFragmentMeRl.topBackBtn.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | finish(); |
| | | } |
| | | }); |
| | | // 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.topBackBtn.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 |
| | |
| | | changedNickname(); |
| | | } |
| | | }); |
| | | |
| | | |
| | | } |
| | | |
| | |
| | | viewBinding.personalDataUserPortraitIl.sllLlRlNameTv.setText(R.string.me_personal_data_portrait); |
| | | viewBinding.personalDataUserNameIl.sllLlRlNameTv.setText(R.string.me_personal_data_user_name); |
| | | viewBinding.personalDataUserPortraitIl.sllLlRlRightContentIv.setVisibility(View.VISIBLE); |
| | | GlideUtils.getRoundedCornersImage(_mActivity, this.mMemberHeadIcon, viewBinding.personalDataUserPortraitIl.sllLlRlRightContentIv, new RoundedCorners(4)); |
| | | viewBinding.personalDataUserNameIl.sllLlRlRightContentTv.setVisibility(View.VISIBLE); |
| | | viewBinding.personalDataUserNameIl.sllLlRlRightContentTv.setText(UserConfigManage.getInstance().getUserName()); |
| | | setMemberHeadIcon(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 更改用户头像; |
| | | */ |
| | | 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(); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HdlLogLogic.print("uploadUserHeadImage error:" + e.getMsg()); |
| | | // hideLoading(); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException error) { |
| | | HdlLogLogic.print("uploadUserHeadImage error:" + error.getMsg()); |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | 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.setYesOnclickListener(new ConfirmationInputDialog.onYesOnclickListener() { |
| | | @Override |
| | | public void Confirm(String str) { |
| | | HdlAccountLogic.getInstance().updateMemberInfo_C("", str, "", "", "", "", new CloudCallBeak<Boolean>() { |
| | | HdlAccountLogic.getInstance().updateMemberName_C(str, new CloudCallBeak<Boolean>() { |
| | | @Override |
| | | public void onSuccess(Boolean obj) { |
| | | UserConfigManage.getInstance().setUserName(str); |
| | |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HdlThreadLogic.tipFlashingBox(_mActivity, false, e.getMessage(), e.getCode()); |
| | | HdlThreadLogic.tipFlashingBox(_mActivity, false, e.getMsg(), e.getCode()); |
| | | } |
| | | }); |
| | | |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 显示用户头像 |
| | | */ |
| | | private void setMemberHeadIcon() { |
| | | GlideUtils.getRoundedCornersImage(_mActivity, mMemberHeadIconUrl, viewBinding.personalDataUserPortraitIl.sllLlRlRightContentIv, new RoundedCorners(4)); |
| | | } |
| | | |
| | | |
| | | @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; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 物理按键返回事件 |
| | | */ |
| | | @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(); |
| | | uniCallBackBaseBean.setType(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_REFRESH_USERINFO); |
| | | HdlUniLogic.getInstance().sendUni(HDLUniMP.UNI_EVENT_NOTIFICATION_DEVICE_MODEL, uniCallBackBaseBean); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |