|
@@ -0,0 +1,578 @@
|
|
|
+package com.liaobo.im.ui.me;
|
|
|
+
|
|
|
+import android.app.Activity;
|
|
|
+import android.app.AlertDialog;
|
|
|
+import android.app.DatePickerDialog;
|
|
|
+import android.content.DialogInterface;
|
|
|
+import android.content.Intent;
|
|
|
+import android.graphics.drawable.Drawable;
|
|
|
+import android.net.Uri;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.support.v7.widget.SwitchCompat;
|
|
|
+import android.text.Editable;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.text.TextWatcher;
|
|
|
+import android.util.Log;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.DatePicker;
|
|
|
+import android.widget.EditText;
|
|
|
+import android.widget.ImageView;
|
|
|
+import android.widget.TextView;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.bumptech.glide.Glide;
|
|
|
+import com.bumptech.glide.load.resource.drawable.GlideDrawable;
|
|
|
+import com.bumptech.glide.request.animation.GlideAnimation;
|
|
|
+import com.bumptech.glide.request.target.SimpleTarget;
|
|
|
+import com.bumptech.glide.signature.StringSignature;
|
|
|
+import com.liaobo.im.AppConstant;
|
|
|
+import com.liaobo.im.MyApplication;
|
|
|
+import com.liaobo.im.R;
|
|
|
+import com.liaobo.im.bean.Area;
|
|
|
+import com.liaobo.im.bean.EventAvatarUploadSuccess;
|
|
|
+import com.liaobo.im.bean.User;
|
|
|
+import com.liaobo.im.db.InternationalizationHelper;
|
|
|
+import com.liaobo.im.db.dao.UserAvatarDao;
|
|
|
+import com.liaobo.im.db.dao.UserDao;
|
|
|
+import com.liaobo.im.helper.AvatarHelper;
|
|
|
+import com.liaobo.im.helper.DialogHelper;
|
|
|
+import com.liaobo.im.helper.LoginHelper;
|
|
|
+import com.liaobo.im.ui.base.BaseActivity;
|
|
|
+import com.liaobo.im.ui.other.QRcodeActivity;
|
|
|
+import com.liaobo.im.ui.tool.SelectAreaActivity;
|
|
|
+import com.liaobo.im.util.CameraUtil;
|
|
|
+import com.liaobo.im.util.Constants;
|
|
|
+import com.liaobo.im.util.PreferenceUtils;
|
|
|
+import com.liaobo.im.util.StringUtils;
|
|
|
+import com.liaobo.im.util.TimeUtils;
|
|
|
+import com.liaobo.im.util.ToastUtil;
|
|
|
+import com.liaobo.im.volley.Result;
|
|
|
+import com.liaobo.im.xuan.xuanhttplibrary.okhttp.HttpUtils;
|
|
|
+import com.liaobo.im.xuan.xuanhttplibrary.okhttp.callback.BaseCallback;
|
|
|
+import com.liaobo.im.xuan.xuanhttplibrary.okhttp.result.ObjectResult;
|
|
|
+import com.loopj.android.http.AsyncHttpClient;
|
|
|
+import com.loopj.android.http.AsyncHttpResponseHandler;
|
|
|
+import com.loopj.android.http.RequestParams;
|
|
|
+import com.makeramen.roundedimageview.RoundedImageView;
|
|
|
+
|
|
|
+import org.apache.http.Header;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileNotFoundException;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.GregorianCalendar;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import de.greenrobot.event.EventBus;
|
|
|
+import okhttp3.Call;
|
|
|
+
|
|
|
+public class MyInfoActivity extends BaseActivity implements View.OnClickListener {
|
|
|
+
|
|
|
+
|
|
|
+ private RoundedImageView ivAvatar;
|
|
|
+ private TextView tvNickname, tvCommunication, tvPhone, tvBirthday, tvLocation;
|
|
|
+
|
|
|
+// private ImageView iv_modify_nickname;
|
|
|
+ private EditText edtDiyName;
|
|
|
+ private SwitchCompat switchSex;
|
|
|
+
|
|
|
+ private static final int REQUEST_CODE_CAPTURE_CROP_PHOTO = 1108;
|
|
|
+ private static final int REQUEST_CODE_PICK_CROP_PHOTO = 1109;
|
|
|
+ private static final int REQUEST_CODE_SELECT_LOCATION = 1110;
|
|
|
+ public static final int REQUEST_CODE_SET_ACCOUNT = 1111;
|
|
|
+ private static final int REQUEST_CODE_CROP_PHOTO = 1112;
|
|
|
+ private User mUser;
|
|
|
+ private Uri mNewPhotoUri;
|
|
|
+ private User mTempUserData;
|
|
|
+ private File mCurrentFile;
|
|
|
+ @Override
|
|
|
+ protected void onCreate(Bundle savedInstanceState) {
|
|
|
+ super.onCreate(savedInstanceState);
|
|
|
+ setContentView(R.layout.activity_my_info);
|
|
|
+ getSupportActionBar().hide();
|
|
|
+ findViewById(R.id.iv_title_left).setOnClickListener(view -> finish());
|
|
|
+ TextView tvTitle = (TextView) findViewById(R.id.tv_title_center);
|
|
|
+ tvTitle.setText(R.string.my_details);
|
|
|
+ mUser = coreManager.getSelf();
|
|
|
+ if (LoginHelper.isUserValidation(mUser)) {
|
|
|
+
|
|
|
+ }
|
|
|
+ tvNickname = findViewById(R.id.tv_nickname);
|
|
|
+ tvCommunication = findViewById(R.id.tv_communication);
|
|
|
+ tvPhone = findViewById(R.id.tv_phone);
|
|
|
+ tvBirthday = findViewById(R.id.tv_birthday);
|
|
|
+ tvLocation = findViewById(R.id.tv_location);
|
|
|
+ ivAvatar = findViewById(R.id.avatar_img);
|
|
|
+ switchSex = findViewById(R.id.switch_sex);
|
|
|
+ ivAvatar.setOnClickListener(this);
|
|
|
+ findViewById(R.id.rlt_birthday).setOnClickListener(this);
|
|
|
+ findViewById(R.id.rlt_user_location).setOnClickListener(this);
|
|
|
+ findViewById(R.id.rlt_qr_code).setOnClickListener(this);
|
|
|
+ findViewById(R.id.iv_modify_nickname).setOnClickListener(this);
|
|
|
+ findViewById(R.id.tv_update).setOnClickListener(this);
|
|
|
+ edtDiyName = findViewById(R.id.edt_diy_name);
|
|
|
+ edtDiyName.addTextChangedListener(new TextWatcher() {
|
|
|
+ @Override
|
|
|
+ public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void afterTextChanged(Editable editable) {
|
|
|
+ mTempUserData.setDescription(editable.toString());
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ switchSex.setOnCheckedChangeListener((c,b)->{
|
|
|
+ if (b){
|
|
|
+ mTempUserData.setSex(1);
|
|
|
+ }else {
|
|
|
+ mTempUserData.setSex(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ updateUI();
|
|
|
+ }
|
|
|
+ public void initView(){
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ switch (view.getId()){
|
|
|
+ case R.id.avatar_img:
|
|
|
+ showSelectAvatarDialog();
|
|
|
+ break;
|
|
|
+ case R.id.rlt_birthday:
|
|
|
+ showSelectBirthdayDialog();
|
|
|
+ break;
|
|
|
+ case R.id.rlt_user_location:
|
|
|
+ Intent intent = new Intent(this, SelectAreaActivity.class);
|
|
|
+ intent.putExtra(SelectAreaActivity.EXTRA_AREA_TYPE, Area.AREA_TYPE_PROVINCE);
|
|
|
+ intent.putExtra(SelectAreaActivity.EXTRA_AREA_PARENT_ID, Area.AREA_DATA_CHINA_ID);
|
|
|
+ intent.putExtra(SelectAreaActivity.EXTRA_AREA_DEEP, Area.AREA_TYPE_CITY);
|
|
|
+ startActivityForResult(intent, REQUEST_CODE_SELECT_LOCATION);
|
|
|
+ break;
|
|
|
+ case R.id.rlt_qr_code:
|
|
|
+ Intent intentQrCode = new Intent(this, QRcodeActivity.class);
|
|
|
+ intentQrCode.putExtra("isgroup", false);
|
|
|
+ if (!TextUtils.isEmpty(mUser.getAccount())) {
|
|
|
+ intentQrCode.putExtra("userid", mUser.getAccount());
|
|
|
+ } else {
|
|
|
+ intentQrCode.putExtra("userid", mUser.getUserId());
|
|
|
+ }
|
|
|
+ intentQrCode.putExtra("userAvatar", mUser.getUserId());
|
|
|
+ startActivity(intentQrCode);
|
|
|
+ break;
|
|
|
+ case R.id.iv_modify_nickname:
|
|
|
+ showEditNickname();
|
|
|
+ break;
|
|
|
+ case R.id.tv_update:
|
|
|
+ updateUserInfo();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
|
+ if (requestCode == REQUEST_CODE_CAPTURE_CROP_PHOTO) {// 拍照返回再去裁减
|
|
|
+ if (resultCode == Activity.RESULT_OK) {
|
|
|
+ if (mNewPhotoUri != null) {
|
|
|
+ Uri o = mNewPhotoUri;
|
|
|
+ mNewPhotoUri = CameraUtil.getOutputMediaFileUri(this, CameraUtil.MEDIA_TYPE_IMAGE);
|
|
|
+ mCurrentFile = new File(mNewPhotoUri.getPath());
|
|
|
+ CameraUtil.cropImage(this, o, mNewPhotoUri, REQUEST_CODE_CROP_PHOTO, 1, 1, 300, 300);
|
|
|
+ } else {
|
|
|
+ ToastUtil.showToast(this, R.string.c_photo_album_failed);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (requestCode == REQUEST_CODE_PICK_CROP_PHOTO) {// 选择一张图片,然后立即调用裁减
|
|
|
+ if (resultCode == Activity.RESULT_OK) {
|
|
|
+ if (data != null && data.getData() != null) {
|
|
|
+ Uri o = data.getData();
|
|
|
+ mNewPhotoUri = CameraUtil.getOutputMediaFileUri(this, CameraUtil.MEDIA_TYPE_IMAGE);
|
|
|
+ mCurrentFile = new File(mNewPhotoUri.getPath());
|
|
|
+ CameraUtil.cropImage(this, o, mNewPhotoUri, REQUEST_CODE_CROP_PHOTO, 1, 1, 300, 300);
|
|
|
+ } else {
|
|
|
+ ToastUtil.showToast(this, R.string.c_photo_album_failed);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (requestCode == REQUEST_CODE_CROP_PHOTO) {
|
|
|
+ if (resultCode == Activity.RESULT_OK) {
|
|
|
+ if (mNewPhotoUri != null) {
|
|
|
+ mCurrentFile = new File(mNewPhotoUri.getPath());
|
|
|
+ AvatarHelper.getInstance().displayUrl(mNewPhotoUri.toString(), ivAvatar);
|
|
|
+ // 上传头像
|
|
|
+ uploadAvatar(mCurrentFile);
|
|
|
+ } else {
|
|
|
+ ToastUtil.showToast(this, R.string.c_crop_failed);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (requestCode == REQUEST_CODE_SELECT_LOCATION) {// 选择城市
|
|
|
+ if (resultCode == RESULT_OK && data != null) {
|
|
|
+ int countryId = data.getIntExtra(SelectAreaActivity.EXTRA_COUNTRY_ID, 0);
|
|
|
+ int provinceId = data.getIntExtra(SelectAreaActivity.EXTRA_PROVINCE_ID, 0);
|
|
|
+ int cityId = data.getIntExtra(SelectAreaActivity.EXTRA_CITY_ID, 0);
|
|
|
+ int countyId = data.getIntExtra(SelectAreaActivity.EXTRA_COUNTY_ID, 0);
|
|
|
+
|
|
|
+ String province_name = data.getStringExtra(SelectAreaActivity.EXTRA_PROVINCE_NAME);
|
|
|
+ String city_name = data.getStringExtra(SelectAreaActivity.EXTRA_CITY_NAME);
|
|
|
+ /*String county_name = data.getStringExtra(SelectAreaActivity.EXTRA_COUNTY_ID);*/
|
|
|
+ tvLocation.setText(province_name + "-" + city_name);
|
|
|
+
|
|
|
+ mTempUserData.setCountryId(countryId);
|
|
|
+ mTempUserData.setProvinceId(provinceId);
|
|
|
+ mTempUserData.setCityId(cityId);
|
|
|
+ mTempUserData.setAreaId(countyId);
|
|
|
+ }
|
|
|
+ } else if (requestCode == REQUEST_CODE_SET_ACCOUNT) {
|
|
|
+ if (resultCode == RESULT_OK && data != null) {
|
|
|
+ String account = data.getStringExtra(AppConstant.EXTRA_USER_ACCOUNT);
|
|
|
+ mTempUserData.setAccount(account);
|
|
|
+ mTempUserData.setSetAccountCount(1);
|
|
|
+ initAccount();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void showEditNickname() {
|
|
|
+ EditText editText = new EditText(this);
|
|
|
+ final AlertDialog.Builder builder = new AlertDialog.Builder(this)
|
|
|
+ .setView(editText)
|
|
|
+ .setTitle(R.string.modify_nickname)
|
|
|
+ .setPositiveButton(R.string.confirm, (d,i)->{
|
|
|
+ String nickName = edtDiyName.getText().toString();
|
|
|
+ tvNickname.setText(nickName);
|
|
|
+
|
|
|
+ mTempUserData.setNickName(nickName);
|
|
|
+
|
|
|
+ })
|
|
|
+ .setNegativeButton(R.string.cancel,(d,i)->{
|
|
|
+
|
|
|
+ });
|
|
|
+ builder.show();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateUserInfo() {
|
|
|
+ if (!MyApplication.getInstance().isNetworkActive()) {
|
|
|
+ ToastUtil.showToast(this, R.string.net_exception);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (TextUtils.isEmpty(mTempUserData.getNickName())){
|
|
|
+ ToastUtil.showToast(this,getString(R.string.name_empty_error));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (!coreManager.getConfig().disableLocationServer) {
|
|
|
+ if (mTempUserData.getCityId() <= 0) {
|
|
|
+ ToastUtil.showToast(this, getString(R.string.live_address_empty_error));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (mUser != null && !mUser.equals(coreManager)) {// 数据改变了,提交数据
|
|
|
+ updateData();
|
|
|
+ } else {
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void showSelectAvatarDialog() {
|
|
|
+ String[] items = new String[]{InternationalizationHelper.getString("PHOTOGRAPH"), InternationalizationHelper.getString("ALBUM")};
|
|
|
+ AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle(InternationalizationHelper.getString("SELECT_AVATARS"))
|
|
|
+ .setSingleChoiceItems(items, 0,
|
|
|
+ new DialogInterface.OnClickListener() {
|
|
|
+ @Override
|
|
|
+ public void onClick(DialogInterface dialog, int which) {
|
|
|
+ if (which == 0) {
|
|
|
+ takePhoto();
|
|
|
+
|
|
|
+ } else {
|
|
|
+ selectPhoto();
|
|
|
+ }
|
|
|
+ dialog.dismiss();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ builder.show();
|
|
|
+ }
|
|
|
+ @SuppressWarnings("deprecation")
|
|
|
+ private void showSelectBirthdayDialog() {
|
|
|
+ Date date = new Date(mTempUserData.getBirthday() * 1000);
|
|
|
+ DatePickerDialog dialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
|
|
|
+ @Override
|
|
|
+ public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
|
|
|
+ GregorianCalendar calendar = new GregorianCalendar(year, monthOfYear, dayOfMonth);
|
|
|
+ mTempUserData.setBirthday(TimeUtils.getSpecialBeginTime(tvBirthday, calendar.getTime().getTime() / 1000));
|
|
|
+ long currentTime = System.currentTimeMillis() / 1000;
|
|
|
+ long birthdayTime = calendar.getTime().getTime() / 1000;
|
|
|
+ if (birthdayTime > currentTime) {
|
|
|
+ ToastUtil.showToast(mContext, R.string.data_of_birth);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, date.getYear() + 1900, date.getMonth(), date.getDate());
|
|
|
+ dialog.show();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void takePhoto() {
|
|
|
+ mNewPhotoUri = CameraUtil.getOutputMediaFileUri(this, CameraUtil.MEDIA_TYPE_IMAGE);
|
|
|
+ CameraUtil.captureImage(this, mNewPhotoUri, REQUEST_CODE_CAPTURE_CROP_PHOTO);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void selectPhoto() {
|
|
|
+ CameraUtil.pickImageSimple(this, REQUEST_CODE_PICK_CROP_PHOTO);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void updateUI() {
|
|
|
+ // clone一份临时数据,用来存数变化的值,返回的时候对比有无变化
|
|
|
+ try {
|
|
|
+ mTempUserData = (User) mUser.clone();
|
|
|
+ } catch (CloneNotSupportedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ switchSex.setChecked(mTempUserData.getSex()==1);
|
|
|
+ if (mTempUserData.getDescription()!=null){
|
|
|
+ edtDiyName.setText(mTempUserData.getDescription());
|
|
|
+ edtDiyName.setSelection(mTempUserData.getDescription().length());
|
|
|
+ }
|
|
|
+ AvatarHelper.getInstance().updateAvatar(mTempUserData.getUserId());
|
|
|
+ // AvatarHelper.getInstance().displayAvatar(mTempData.getUserId(), mAvatarImg, false);
|
|
|
+ displayAvatar(mTempUserData.getUserId());
|
|
|
+
|
|
|
+
|
|
|
+ tvNickname.setText(mTempUserData.getNickName());
|
|
|
+// if (mTempData.getSex() == 1) {
|
|
|
+// mSexTv.setText(InternationalizationHelper.getString("JX_Man"));
|
|
|
+// } else {
|
|
|
+// mSexTv.setText(InternationalizationHelper.getString("JX_Wuman"));
|
|
|
+// }
|
|
|
+ tvBirthday.setText(TimeUtils.sk_time_s_long_2_str(mTempUserData.getBirthday()));
|
|
|
+ tvLocation.setText(Area.getProvinceCityString(mTempUserData.getCityId(), mTempUserData.getAreaId()));
|
|
|
+// mTvDiyName.setText(mTempUserData.getDescription());
|
|
|
+
|
|
|
+ String phoneNumber = coreManager.getSelf().getTelephone();
|
|
|
+ int mobilePrefix = PreferenceUtils.getInt(this, Constants.AREA_CODE_KEY, -1);
|
|
|
+ String sPrefix = String.valueOf(mobilePrefix);
|
|
|
+ // 删除开头的区号,
|
|
|
+ if (phoneNumber.startsWith(sPrefix)) {
|
|
|
+ phoneNumber = phoneNumber.substring(sPrefix.length());
|
|
|
+ }
|
|
|
+ tvPhone.setText(phoneNumber);
|
|
|
+
|
|
|
+ initAccount();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void displayAvatar(final String userId) {
|
|
|
+ DialogHelper.showDefaulteMessageProgressDialog(this);
|
|
|
+ final String mOriginalUrl = AvatarHelper.getAvatarUrl(userId, false);
|
|
|
+ Log.e("zx", "displayAvatar: mOriginalUrl: " + mOriginalUrl + " uID: " + userId);
|
|
|
+ if (!TextUtils.isEmpty(mOriginalUrl)) {
|
|
|
+ String time = UserAvatarDao.getInstance().getUpdateTime(userId);
|
|
|
+
|
|
|
+ Glide.with(MyApplication.getContext())
|
|
|
+ .load(mOriginalUrl)
|
|
|
+ .placeholder(R.drawable.avatar_normal)
|
|
|
+ .signature(new StringSignature(time))
|
|
|
+ .dontAnimate()
|
|
|
+ .error(R.drawable.avatar_normal)
|
|
|
+ .into(new SimpleTarget<GlideDrawable>() {
|
|
|
+ @Override
|
|
|
+ public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
|
|
|
+ DialogHelper.dismissProgressDialog();
|
|
|
+ ivAvatar.setImageDrawable(resource);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onLoadFailed(Exception e, Drawable errorDrawable) {
|
|
|
+ DialogHelper.dismissProgressDialog();
|
|
|
+ Log.e("zq", "加载原图失败:" + mOriginalUrl);// 该用户未设置头像,网页访问该URL也是404
|
|
|
+ AvatarHelper.getInstance().displayAvatar(mTempUserData.getNickName(), userId, ivAvatar, true);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ DialogHelper.dismissProgressDialog();
|
|
|
+ Log.e("zq", "未获取到原图地址");// 基本上不会走这里
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initAccount() {
|
|
|
+ if (mTempUserData != null) {
|
|
|
+ if (mTempUserData.getSetAccountCount() == 0) {
|
|
|
+ // 之前未设置过sk号 前往设置
|
|
|
+ findViewById(R.id.rlt_account).setOnClickListener(v -> {
|
|
|
+ Intent intent = new Intent(mContext, SetAccountActivity.class);
|
|
|
+ intent.putExtra(AppConstant.EXTRA_USER_ID, mTempUserData.getUserId());
|
|
|
+ intent.putExtra(AppConstant.EXTRA_NICK_NAME, mTempUserData.getNickName());
|
|
|
+ startActivityForResult(intent, REQUEST_CODE_SET_ACCOUNT);
|
|
|
+ });
|
|
|
+ findViewById(R.id.iv_communication).setVisibility(View.VISIBLE);
|
|
|
+ } else {
|
|
|
+ findViewById(R.id.rlt_account).setOnClickListener(null);
|
|
|
+ findViewById(R.id.iv_communication).setVisibility(View.INVISIBLE);
|
|
|
+ }
|
|
|
+ if (!TextUtils.isEmpty(mTempUserData.getAccount())) {
|
|
|
+ tvCommunication.setText(mTempUserData.getAccount());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void uploadAvatar(File file) {
|
|
|
+ if (!file.exists()) {
|
|
|
+ // 文件不存在
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 显示正在上传的ProgressDialog
|
|
|
+ DialogHelper.showDefaulteMessageProgressDialog(this);
|
|
|
+ RequestParams params = new RequestParams();
|
|
|
+ final String loginUserId = coreManager.getSelf().getUserId();
|
|
|
+ params.put("userId", loginUserId);
|
|
|
+ try {
|
|
|
+ params.put("file1", file);
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ AsyncHttpClient client = new AsyncHttpClient();
|
|
|
+ client.post(coreManager.getConfig().AVATAR_UPLOAD_URL, params, new AsyncHttpResponseHandler() {
|
|
|
+ @Override
|
|
|
+ public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
|
|
|
+ DialogHelper.dismissProgressDialog();
|
|
|
+ boolean success = false;
|
|
|
+ if (arg0 == 200) {
|
|
|
+ Result result = null;
|
|
|
+ try {
|
|
|
+ result = JSON.parseObject(new String(arg2), Result.class);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ if (result != null && result.getResultCode() == Result.CODE_SUCCESS) {
|
|
|
+ success = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (success) {
|
|
|
+ ToastUtil.showToast(getBaseContext(), R.string.upload_avatar_success);
|
|
|
+ AvatarHelper.getInstance().updateAvatar(loginUserId);// 更新时间
|
|
|
+ EventBus.getDefault().post(new EventAvatarUploadSuccess(true));
|
|
|
+ } else {
|
|
|
+ ToastUtil.showToast(getBaseContext(), R.string.upload_avatar_failed);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) {
|
|
|
+ DialogHelper.dismissProgressDialog();
|
|
|
+ ToastUtil.showToast(getBaseContext(), R.string.upload_avatar_failed);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void updateData() {
|
|
|
+ Map<String, String> params = new HashMap<>();
|
|
|
+ params.put("access_token", coreManager.getSelfStatus().accessToken);
|
|
|
+ if (!mUser.getNickName().equals(mTempUserData.getNickName())) {
|
|
|
+ params.put("nickname", mTempUserData.getNickName());
|
|
|
+ }
|
|
|
+ if (mUser.getSex() != mTempUserData.getSex()) {
|
|
|
+ params.put("sex", String.valueOf(mTempUserData.getSex()));
|
|
|
+ }
|
|
|
+ if (mUser.getBirthday() != mTempUserData.getBirthday()) {
|
|
|
+ params.put("birthday", String.valueOf(mTempUserData.getBirthday()));
|
|
|
+ }
|
|
|
+ if (mUser.getCountryId() != mTempUserData.getCountryId()) {
|
|
|
+ params.put("countryId", String.valueOf(mTempUserData.getCountryId()));
|
|
|
+ }
|
|
|
+ if (mUser.getProvinceId() != mTempUserData.getProvinceId()) {
|
|
|
+ params.put("provinceId", String.valueOf(mTempUserData.getProvinceId()));
|
|
|
+ }
|
|
|
+ if (mUser.getCityId() != mTempUserData.getCityId()) {
|
|
|
+ params.put("cityId", String.valueOf(mTempUserData.getCityId()));
|
|
|
+ }
|
|
|
+ if (mUser.getAreaId() != mTempUserData.getAreaId()) {
|
|
|
+ params.put("areaId", String.valueOf(mTempUserData.getAreaId()));
|
|
|
+ }
|
|
|
+ if (!mUser.getDescription().equals(mTempUserData.getDescription())){
|
|
|
+ params.put("description", String.valueOf(mTempUserData.getDescription()));
|
|
|
+
|
|
|
+ }
|
|
|
+ DialogHelper.showDefaulteMessageProgressDialog(this);
|
|
|
+
|
|
|
+ HttpUtils.get().url(coreManager.getConfig().USER_UPDATE)
|
|
|
+ .params(params)
|
|
|
+ .build()
|
|
|
+ .execute(new BaseCallback<Void>(Void.class) {
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResponse(ObjectResult<Void> result) {
|
|
|
+ DialogHelper.dismissProgressDialog();
|
|
|
+ saveData();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onError(Call call, Exception e) {
|
|
|
+ DialogHelper.dismissProgressDialog();
|
|
|
+ ToastUtil.showErrorNet(getBaseContext());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private void saveData() {
|
|
|
+ if (!mUser.getNickName().equals(mTempUserData.getNickName())) {
|
|
|
+ coreManager.getSelf().setNickName(mTempUserData.getNickName());
|
|
|
+ UserDao.getInstance().updateNickName(mTempUserData.getUserId(), mTempUserData.getNickName()); // 更新数据库
|
|
|
+ }
|
|
|
+ if (mUser.getSex() != mTempUserData.getSex()) {
|
|
|
+ coreManager.getSelf().setSex(mTempUserData.getSex());
|
|
|
+ UserDao.getInstance().updateSex(mTempUserData.getUserId(), mTempUserData.getSex() + ""); // 更新数据库
|
|
|
+ }
|
|
|
+ if (mUser.getBirthday() != mTempUserData.getBirthday()) {
|
|
|
+ coreManager.getSelf().setBirthday(mTempUserData.getBirthday());
|
|
|
+ UserDao.getInstance().updateBirthday(mTempUserData.getUserId(), mTempUserData.getBirthday() + "");// 更新数据库
|
|
|
+ }
|
|
|
+
|
|
|
+ if (mUser.getCountryId() != mTempUserData.getCountryId()) {
|
|
|
+ coreManager.getSelf().setCountryId(mTempUserData.getCountryId());
|
|
|
+ UserDao.getInstance().updateCountryId(mTempUserData.getUserId(), mTempUserData.getCountryId());
|
|
|
+ }
|
|
|
+ if (mUser.getProvinceId() != mTempUserData.getProvinceId()) {
|
|
|
+ coreManager.getSelf().setProvinceId(mTempUserData.getProvinceId());
|
|
|
+ UserDao.getInstance().updateProvinceId(mTempUserData.getUserId(), mTempUserData.getProvinceId());
|
|
|
+ }
|
|
|
+ if (mUser.getCityId() != mTempUserData.getCityId()) {
|
|
|
+ coreManager.getSelf().setCityId(mTempUserData.getCityId());
|
|
|
+ UserDao.getInstance().updateCityId(mTempUserData.getUserId(), mTempUserData.getCityId());
|
|
|
+ }
|
|
|
+ if (mUser.getAreaId() != mTempUserData.getAreaId()) {
|
|
|
+ coreManager.getSelf().setAreaId(mTempUserData.getAreaId());
|
|
|
+ UserDao.getInstance().updateAreaId(mTempUserData.getUserId(), mTempUserData.getAreaId());
|
|
|
+ }
|
|
|
+ if (!mUser.getDescription().equals(mTempUserData.getDescription())){
|
|
|
+ coreManager.getSelf().setDescription(mTempUserData.getDescription());
|
|
|
+ UserDao.getInstance().updateDescription(mTempUserData.getUserId(), mTempUserData.getDescription());
|
|
|
+ }
|
|
|
+
|
|
|
+ setResult(RESULT_OK);
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|