| | |
| | | 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 com.bumptech.glide.load.resource.bitmap.RoundedCorners; |
| | | import com.google.gson.JsonObject; |
| | | import com.hdl.linkpm.sdk.core.callback.IDefaultCallBack; |
| | | 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.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; |
| | |
| | | private CameraAlbumPopWindow cameraAlbumPopWindow; |
| | | //头像地址 |
| | | private String mMemberHeadIconUrl; |
| | | private ActivityResultLauncher<String[]> generalPermission; |
| | | |
| | | |
| | | @Override |
| | |
| | | public void onBindView(Bundle savedInstanceState) { |
| | | setNotificationBarBackgroundColor(CustomColor.white); |
| | | setStatusBarTextColor(); |
| | | mMemberHeadIconUrl = getIntent().getStringExtra("memberHeadIcon"); |
| | | mMemberHeadIconUrl = UserConfigManage.getInstance().getUserImageUrl(); |
| | | //初始化 |
| | | initView(); |
| | | //初始化界面监听器 |
| | |
| | | } |
| | | |
| | | 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.topBackBtn.setOnClickListener(new View.OnClickListener() { |
| | | viewBinding.toolbarTopFragmentMeRl.topBackLl.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | | //数据是使用Intent返回 |
| | | Intent intent = new Intent(); |
| | | //把返回数据存入Intent |
| | | intent.putExtra("memberHeadIcon", mMemberHeadIconUrl); |
| | | //设置返回数据 |
| | | setResult(10, intent); |
| | | // backPressedData(); |
| | | finish(); |
| | | } |
| | | }); |
| | | viewBinding.personalDataUserPortraitIl.getRoot().setOnClickListener(new View.OnClickListener() { |
| | | |
| | | @Override |
| | | public void onClick(View v) { |
| | | //Manifest.permission.WRITE_EXTERNAL_STORAGE 读写设备上的照片以及文件 |
| | | PermissionUtils.applyForRight(_mActivity, Manifest.permission.WRITE_EXTERNAL_STORAGE, new PermissionUtils.PermissionState() { |
| | | //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); |
| | | // HdlThreadLogic.toast(_mActivity, R.string.permission_open); |
| | | return; |
| | | } |
| | | changedUserAvatar(); |
| | | } |
| | | }); |
| | | }, true); |
| | | |
| | | } |
| | | }); |
| | |
| | | |
| | | private void initView() { |
| | | viewBinding.toolbarTopFragmentMeRl.topTitleTv.setText(R.string.me_personal_data); |
| | | viewBinding.toolbarTopFragmentMeRl.topBackBtn.setVisibility(View.VISIBLE); |
| | | 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); |
| | |
| | | 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()); |
| | | HDLLinkPMUser.getInstance().updateMemberInfo(imageInfo, new IDefaultCallBack() { |
| | | //上传头像地址 |
| | | HdlAccountLogic.getInstance().updateMemberHeadIcon_C(imageKey.getUrl(), new CloudCallBeak<Boolean>() { |
| | | @Override |
| | | public void onSuccess() { |
| | | public void onSuccess(Boolean obj) { |
| | | mMemberHeadIconUrl = imageKey.getUrl(); |
| | | setMemberHeadIcon(); |
| | | backPressedData(); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException error) { |
| | | HdlLogLogic.print("uploadUserHeadImage error:" + error.getMsg()); |
| | | public void onFailure(HDLException e) { |
| | | |
| | | HdlThreadLogic.toast(_mActivity, e); |
| | | // HdlLogLogic.print("uploadUserHeadImage error:" + error.getMsg()); |
| | | // hideLoading(); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException error) { |
| | | HdlLogLogic.print("uploadUserHeadImage error:" + error.getMsg()); |
| | | public void onFailure(HDLException e) { |
| | | // HdlThreadLogic.tipFlashingBox(_mActivity, false, e.getMsg(), e.getCode()); |
| | | HdlThreadLogic.toast(_mActivity, e); |
| | | } |
| | | }); |
| | | } |
| | |
| | | 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); |
| | |
| | | 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.getMessage(), e.getCode()); |
| | | HdlThreadLogic.tipFlashingBox(_mActivity, false, e.getMsg(), e.getCode()); |
| | | } |
| | | }); |
| | | |
| | |
| | | * 显示用户头像 |
| | | */ |
| | | private void setMemberHeadIcon() { |
| | | GlideUtils.getRoundedCornersImage(_mActivity, mMemberHeadIconUrl, viewBinding.personalDataUserPortraitIl.sllLlRlRightContentIv, new RoundedCorners(4)); |
| | | 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 |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |