正在查看: 自健身 v3.3.4 应用的 PersonalInfoActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: 自健身 v3.3.4 应用的 PersonalInfoActivity.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.mu.gymtrain.Activity.PersonPackage;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.OnClick;
import com.bigkoo.pickerview.builder.OptionsPickerBuilder;
import com.bigkoo.pickerview.builder.TimePickerBuilder;
import com.bigkoo.pickerview.listener.OnOptionsSelectListener;
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
import com.bigkoo.pickerview.view.OptionsPickerView;
import com.bigkoo.pickerview.view.TimePickerView;
import com.blankj.utilcode.util.LogUtils;
import com.bumptech.glide.Glide;
import com.luck.picture.lib.PictureSelector;
import com.luck.picture.lib.config.PictureMimeType;
import com.mu.gymtrain.Base.BaseActivity;
import com.mu.gymtrain.Base.BaseModel;
import com.mu.gymtrain.Bean.SucessBean;
import com.mu.gymtrain.Bean.UserInfoBean;
import com.mu.gymtrain.Dialog.NameDialogHolder;
import com.mu.gymtrain.Http.CreatMap;
import com.mu.gymtrain.Http.HttpHelper;
import com.mu.gymtrain.R;
import com.mu.gymtrain.Utils.CommonUtils;
import com.mu.gymtrain.Utils.DateUtils;
import com.mu.gymtrain.Utils.FinalTools;
import com.mu.gymtrain.Utils.GlideUtils;
import com.mu.gymtrain.Utils.JsonUtil;
import com.mu.gymtrain.Utils.PreferenceUtils;
import com.mu.gymtrain.Utils.ToastUtil;
import com.mu.gymtrain.Utils.ToastUtils;
import com.mu.gymtrain.Utils.UrlConfig;
import com.mu.gymtrain.Utils.ViewUtils;
import com.mu.gymtrain.Widget.CircleImageView;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.MultipartBody$Builder;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import org.greenrobot.eventbus.EventBus;
import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
public class PersonalInfoActivity extends BaseActivity {
@BindView(R.id.cbSex)
CheckBox cbSex;
@BindView(R.id.civ_head)
CircleImageView civHead;
@BindView(R.id.et_name)
TextView etName;
private ArrayList<String> list;
private OptionsPickerView<String> pickerView;
private PictureSelector pictureSelector;
private String time;
private TimePickerView timePickerDialog;
@BindView(R.id.title_left)
ImageView titleLeft;
@BindView(R.id.title_middle)
TextView titleMiddle;
@BindView(R.id.title_righttext)
TextView titleRighttext;
@BindView(R.id.tv_birth)
TextView tvBirth;
@BindView(R.id.tv_high)
TextView tvHigh;
@BindView(R.id.tv_profession)
EditText tvProfession;
@BindView(R.id.tv_upload)
TextView tvUpload;
@BindView(R.id.tv_weight)
TextView tvWeight;
public int getContentLayout() {
return R.layout.activity_personinfo;
}
public void initData() {
UserInfoBean userInfoBean = (UserInfoBean) getIntent().getParcelableExtra("userInfo");
if (userInfoBean != null) {
GlideUtils.withReplace(UrlConfig.Path.IMG_URL + userInfoBean.getAvatar(), this.civHead, this);
this.etName.setText(userInfoBean.getUser_name());
this.tvHigh.setText(userInfoBean.getHeight() + "CM");
this.tvWeight.setText(userInfoBean.getWeight() + "公斤");
this.tvBirth.setText(userInfoBean.getBirthday());
this.tvProfession.setText(userInfoBean.getProfessional());
if ("女".equals(userInfoBean.getGender())) {
this.cbSex.setChecked(false);
} else {
this.cbSex.setChecked(true);
}
}
this.cbSex.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public final void onCheckedChanged(CompoundButton compoundButton, boolean z) {
PersonalInfoActivity.this.lambda$initData$0$PersonalInfoActivity(compoundButton, z);
}
});
final String obj = this.tvProfession.getText().toString();
this.tvProfession.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.toString().equals(obj)) {
return;
}
PersonalInfoActivity.this.changFlag();
}
});
this.pictureSelector = PictureSelector.create((Activity) this);
creatDateDialog();
createHeightDialog();
}
public void lambda$initData$0$PersonalInfoActivity(CompoundButton compoundButton, boolean z) {
changFlag();
}
public void initView() {
this.titleMiddle.setText("个人资料");
this.titleRighttext.setText("完成");
this.titleRighttext.setTextColor(CommonUtils.getColor(this, R.color.main_color));
this.titleRighttext.setTextColor(getResources().getColor(R.color.main_text_hint_color));
this.titleRighttext.setEnabled(false);
}
private void upDateUserInfo() {
String charSequence = this.etName.getText().toString();
String charSequence2 = this.tvBirth.getText().toString();
String charSequence3 = this.tvHigh.getText().toString();
if (TextUtils.isEmpty(charSequence) || charSequence2.equals("未设置") || TextUtils.isEmpty(charSequence3)) {
showToast("请补充完整必填项");
} else {
ViewUtils.showLoading(this, "加载中...");
HttpHelper.getInstance().getRetrofitService(this).upDateUserInfo(new CreatMap.Builder().addParams(UrlConfig.Params.NAME, charSequence).addParams(UrlConfig.Params.GENDER, this.cbSex.isChecked() ? "男" : "女").addParams("professional", this.tvProfession.getEditableText().toString()).addParams(UrlConfig.Params.BIRTHDAY, charSequence2).addParams("height", charSequence3).addParams("weight", this.tvWeight.getText().toString()).build().getParam()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<BaseModel>() {
public void onCompleted() {
}
public void onError(Throwable e) {
ViewUtils.hideLoading();
ToastUtil.showShort((Context) PersonalInfoActivity.this, (CharSequence) "修改失败!");
}
public void onNext(BaseModel baseModel) {
ViewUtils.hideLoading();
EventBus.getDefault().post("2");
ToastUtil.showShort((Context) PersonalInfoActivity.this, (CharSequence) "修改成功!");
PersonalInfoActivity.this.finish();
}
});
}
}
@OnClick({R.id.tvAvatart, R.id.tv_high, R.id.et_name, R.id.title_left, R.id.title_righttext, R.id.tv_upload, R.id.cbSex, R.id.tv_birth, R.id.civ_head})
public void onViewClicked(View view) {
switch (view.getId()) {
case R.id.civ_head:
case R.id.tvAvatart:
case R.id.tv_upload:
takePhoto();
break;
case R.id.et_name:
showDialogName();
break;
case R.id.title_left:
finish();
break;
case R.id.title_righttext:
upDateUserInfo();
break;
case R.id.tv_birth:
this.timePickerDialog.show();
break;
case R.id.tv_high:
this.pickerView.show();
break;
}
}
private void takePhoto() {
this.pictureSelector.openGallery(PictureMimeType.ofImage()).maxSelectNum(1).minSelectNum(1).imageSpanCount(4).selectionMode(1).previewImage(true).isCamera(true).isZoomAnim(true).compress(true).glideOverride(400, 400).isGif(true).compress(true).cropCompressQuality(50).previewVideo(true).forResult(188);
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 188 && resultCode == -1) {
uploadNewPhoto(new File(PictureSelector.obtainMultipleResult(data).get(0).getCompressPath()));
}
}
private void uploadNewPhoto(final File file) {
HttpHelper.getInstance().getRetrofitService(this).submitAvatar1(new MultipartBody$Builder().setType(MultipartBody.FORM).addFormDataPart(UrlConfig.Params.TOKEN, PreferenceUtils.getInstance().getString(FinalTools.TOKEN, "")).addFormDataPart("avatar_file", file.getName(), RequestBody.create(MediaType.parse("image/*"), file)).build()).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<ResponseBody>() {
public void onCompleted() {
}
public void onError(Throwable e) {
LogUtils.i(new Object[]{e.getMessage()});
ViewUtils.hideLoading();
}
public void onNext(ResponseBody responseBody) {
ViewUtils.hideLoading();
try {
String string = responseBody.string();
LogUtils.i(new Object[]{string});
SucessBean sucessBean = (SucessBean) JsonUtil.json2Bean(string, SucessBean.class);
if (sucessBean != null && sucessBean.code == 10000) {
EventBus.getDefault().post("2");
ToastUtils.show(PersonalInfoActivity.this, "上传成功");
Glide.with(PersonalInfoActivity.this).load(file.getPath()).into(PersonalInfoActivity.this.civHead);
} else {
ToastUtils.show(PersonalInfoActivity.this, "上传失败");
}
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
private void showDialogName() {
final NameDialogHolder nameDialogHolder = new NameDialogHolder(this);
nameDialogHolder.mTvOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
nameDialogHolder.mDialog.dismiss();
PersonalInfoActivity.this.etName.setText(nameDialogHolder.mEtName.getText().toString());
PersonalInfoActivity.this.changFlag();
}
});
nameDialogHolder.mTvCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
nameDialogHolder.mDialog.dismiss();
}
});
nameDialogHolder.mDialog.setCanceledOnTouchOutside(true);
nameDialogHolder.mDialog.show();
}
public void creatDateDialog() {
Calendar calendar = Calendar.getInstance();
calendar.set(DateUtils.getYear(), DateUtils.getMonth(), DateUtils.getDay());
this.timePickerDialog = new TimePickerBuilder(this, new OnTimeSelectListener() {
public void onTimeSelect(Date date, View v) {
PersonalInfoActivity.this.time = DateUtils.dateToTime(date, "yyyy-MM-dd");
PersonalInfoActivity.this.tvBirth.setText(PersonalInfoActivity.this.time);
PersonalInfoActivity.this.changFlag();
}
}).setType(new boolean[]{true, true, true, false, false, false}).setCancelText("✘").setSubmitText("✔").setRangDate((Calendar) null, calendar).setTitleSize(15).setOutSideCancelable(true).isCyclic(false).setSubmitColor(getResources().getColor(R.color.gray_98)).setCancelColor(getResources().getColor(R.color.gray_98)).setTitleBgColor(getResources().getColor(2131099935)).setBgColor(getResources().getColor(2131099935)).setTitleText("编辑").setLabel("", "", "", "时", "分", "秒").isCenterLabel(false).isDialog(false).build();
}
private void createHeightDialog() {
this.list = new ArrayList<>();
for (int i = 140; i < 230; i++) {
this.list.add(i + "CM");
}
OptionsPickerView<String> build = new OptionsPickerBuilder(this, new OnOptionsSelectListener() {
public void onOptionsSelect(int options1, int options2, int options3, View v) {
PersonalInfoActivity.this.tvHigh.setText((CharSequence) PersonalInfoActivity.this.list.get(options1));
PersonalInfoActivity.this.changFlag();
}
}).isDialog(false).setOutSideCancelable(false).setCancelText("✘").setSubmitText("✔").setTitleText("编辑").setSubmitColor(getResources().getColor(R.color.gray_98)).setCancelColor(getResources().getColor(R.color.gray_98)).setTitleBgColor(getResources().getColor(2131099935)).setBgColor(getResources().getColor(2131099935)).build();
this.pickerView = build;
build.setPicker(this.list);
}
void changFlag() {
this.titleRighttext.setTextColor(getResources().getColor(R.color.orange));
this.titleRighttext.setEnabled(true);
}
}