package eVVM.apk.ui.login; import android.Manifest; import android.app.Activity; import android.app.Dialog; import android.content.Intent; import android.content.pm.PackageManager; import android.os.Build; import android.os.Environment; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.ActivityCompat; import android.support.v4.content.ContextCompat; import android.text.TextUtils; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import com.hjq.dialog.MessageDialog; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import butterknife.BindView; import butterknife.OnClick; import cn.bingoogolapple.photopicker.activity.BGAPhotoPickerActivity; import cn.bingoogolapple.photopicker.activity.BGAPhotoPickerPreviewActivity; import cn.bingoogolapple.photopicker.imageloader.BGAImage; import cn.bingoogolapple.photopicker.widget.BGASortableNinePhotoLayout; import eVVM.apk.R; import eVVM.apk.api.ApiUrl; import eVVM.apk.helper.ImgDonwloads; import eVVM.apk.helper.InputTextHelper; import eVVM.apk.helper.basepicker.DataPickerDialog; import eVVM.apk.mvp.MvpActivity; import eVVM.apk.ui.bean.VerificationCodeBean; import eVVM.apk.ui.event.CompanyEvent; import eVVM.apk.ui.launcher.LikeActivity; import eVVM.apk.ui.login.authentication.AttctContract; import eVVM.apk.ui.login.authentication.AttctPresenter; import me.jessyan.autosize.utils.AutoSizeUtils; /** * 实名认证页 */ public class AuthenticationActivity extends MvpActivity implements AttctContract.View, BGASortableNinePhotoLayout.Delegate { @BindView(R.id.attc_et_phone) TextView attcEtPhone; @BindView(R.id.attc_et_name) EditText attcEtName; @BindView(R.id.attc_et_code) EditText attcEtCode; @BindView(R.id.attc_et_email) EditText attcEtEmail; @BindView(R.id.attc_et_license) ImageView attcEtLicense; @BindView(R.id.attc_et_prove) ImageView attcEtProve; @BindView(R.id.attc_btn_register) Button attcBtnRegister; @BindView(R.id.tv_information_hospital) TextView tvInformationHospital; @BindView(R.id.tv_information_factory) TextView tvInformationFactory; @BindView(R.id.attc_ll_license) LinearLayout attcLlLicense; @BindView(R.id.attc_ll_prove) LinearLayout attcLlProve; @BindView(R.id.snpl_moment_add_photos) BGASortableNinePhotoLayout mPhotosSnpl; private File takePhotoDir = new File(Environment.getExternalStorageDirectory(), "eVVM"); private static final int REQUEST_LICENSE_PHOTO_PREVIEW = 1324; private static final int REQUEST_LICENSE_CHOOSE_FROM_GALLERY = 1325; private static final int REQUEST_PROVE_CHOOSE_FROM_GALLERY = 1326; private String registerUserId; @Override protected int getLayoutId() { return R.layout.activity_authentication; } @Override protected int getTitleId() { return R.id.attc_title; } @Override public void onLeftClick(View v) { new MessageDialog.Builder(this) .setTitle("") // 标题可以不用填写 .setMessage("您未完成实名认证,是否退出") .setConfirm("确定") .setCancel("取消") // 设置 null 表示不显示取消按钮 //.setAutoDismiss(false) // 设置点击按钮后不关闭对话框 .setListener(new MessageDialog.OnListener() { @Override public void onConfirm(Dialog dialog) { finish(); } @Override public void onCancel(Dialog dialog) { //toast("取消了"); } }) .show(); } @Override protected void initView() { new InputTextHelper.Builder(this) .setMain(attcBtnRegister) .addView(attcEtPhone) .addView(attcEtName) .addView(attcEtCode) .addView(attcEtEmail) .addView(tvInformationHospital) .addView(tvInformationFactory) .build(); Intent in = getIntent(); registerUserId = in.getStringExtra("registerUserId"); mPhotosSnpl.setData(null); mPhotosSnpl.setMaxItemCount(3); mPhotosSnpl.setSortable(false); mPhotosSnpl.setEditable(true); mPhotosSnpl.setPlusEnable(true); mPhotosSnpl.setDelegate(this); Button downloadBtn = (Button) findViewById(R.id.download_btn); // download() ; downloadBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { List permissionList = new ArrayList<>(); if (ContextCompat.checkSelfPermission(AuthenticationActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { permissionList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE); } if (!permissionList.isEmpty()) { String[] permissions = permissionList.toArray(new String[permissionList.size()]); ActivityCompat.requestPermissions(AuthenticationActivity.this, permissions, 1); } else { ImgDonwloads.donwloadImg(AuthenticationActivity.this, ApiUrl.authPath);//iPath } } }); } @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { switch (requestCode) { case 1: if (grantResults.length > 0) { for (int result : grantResults) { if (result != PackageManager.PERMISSION_GRANTED) { toast("拒绝了权限"); return; } } ImgDonwloads.donwloadImg(AuthenticationActivity.this, ""); } else { toast("发生未知错误"); } break; default: } } @Override protected void initData() { } @OnClick({R.id.attc_et_license, R.id.attc_et_prove, R.id.attc_btn_register, R.id.tv_information_hospital, R.id.tv_information_factory, R.id.attc_et_phone}) public void onViewClicked(View view) { switch (view.getId()) { case R.id.attc_et_license: //上传执业执照 /* 从相册选取二维码图片,这里为了方便演示,使用的是 https://github.com/bingoogolapple/BGAPhotoPicker-Android 这个库来从图库中选择二维码图片,这个库不是必须的,你也可以通过自己的方式从图库中选择图片 */ Intent licensePhotoPickerIntent = new BGAPhotoPickerActivity.IntentBuilder(this) .cameraFileDir(takePhotoDir) .maxChooseCount(3) .selectedPhotos(null) .pauseOnScroll(false) .build(); startActivityForResult(licensePhotoPickerIntent, REQUEST_LICENSE_CHOOSE_FROM_GALLERY); break; case R.id.attc_et_prove: //上传授权证明 if (uploadimgpaths1.size() == 0) { toast("请先选择执业执照"); } else { Intent provePhotoPickerIntent = new BGAPhotoPickerActivity.IntentBuilder(this) .cameraFileDir(takePhotoDir) .maxChooseCount(1) .selectedPhotos(null) .pauseOnScroll(false) .build(); startActivityForResult(provePhotoPickerIntent, REQUEST_PROVE_CHOOSE_FROM_GALLERY); } break; case R.id.attc_btn_register: //进行实名认证 List uploadimgpaths3 = new ArrayList<>(); if ("预防接种机构".equals(tvInformationHospital.getText().toString())) { if (mPhotosSnpl.getData().size() == 0 || uploadimgpaths2.size() == 0) { toast("请选择执业执照及授权证明"); } else { uploadimgpaths3.clear(); uploadimgpaths3.addAll(mPhotosSnpl.getData()); uploadimgpaths3.addAll(uploadimgpaths2); //String user_id = (String) SPUtils.get("USER_ID", ""); if (TextUtils.isEmpty(registerUserId)) { Log.e("getPresenterattct", "" + uploadimgpaths3.toString()); } else { getPresenter().attct(Integer.parseInt(registerUserId), attcEtPhone.getText().toString() , attcEtName.getText().toString(), attcEtCode.getText().toString(), attcEtEmail.getText().toString(), getRoleId(tvInformationFactory.getText().toString()) + "", 0, Build.BRAND + " " + Build.MODEL, uploadimgpaths3); } } } else { if (TextUtils.isEmpty(registerUserId)) { } else { List emptyList = new ArrayList<>(); getPresenter().attct(Integer.parseInt(registerUserId), attcEtPhone.getText().toString() , attcEtName.getText().toString(), attcEtCode.getText().toString(), attcEtEmail.getText().toString(), getRoleId(tvInformationFactory.getText().toString()) + "", 0, Build.BRAND + " " + Build.MODEL, emptyList); } } break; case R.id.tv_information_hospital: DataPickerDialog.Builder builder = new DataPickerDialog.Builder(this); List data = Arrays.asList(new String[]{"医药企业", "预防接种机构", "预防接受种者", "物流公司"}); /*List parentlist = new ArrayList<>(); parentlist.add(new RoleTypeBean.RoleParen(6,"","医药企业")); parentlist.add(new RoleTypeBean.RoleParen(7,"","预防接种机构")); parentlist.add(new RoleTypeBean.RoleParen(8,"","预防接受种者")); parentlist.add(new RoleTypeBean.RoleParen(9,"","物流公司"));*/ DataPickerDialog dialog = builder.setData(data).setSelection(0).setTitle("标题") .setOnDataSelectedListener(new DataPickerDialog.OnDataSelectedListener() { @Override public void onDataSelected(String itemValue) { if (!TextUtils.isEmpty(tvInformationHospital.getText().toString())) { tvInformationFactory.setText(""); } tvInformationHospital.setText(itemValue + ""); if ("预防接种机构".equals(itemValue)) { attcLlLicense.setVisibility(View.VISIBLE); attcLlProve.setVisibility(View.VISIBLE); } else { attcLlLicense.setVisibility(View.GONE); attcLlProve.setVisibility(View.GONE); } } }).create(); dialog.show(); break; case R.id.tv_information_factory: if (TextUtils.isEmpty(tvInformationHospital.getText().toString())) { toast("请先选择所属类型"); return; } else { int roleParentId = getRoleParentId(tvInformationHospital.getText().toString()); List roleType = getRoleType(roleParentId); DataPickerDialog.Builder builder2 = new DataPickerDialog.Builder(this); /*List data2 = Arrays.asList(new String[]{"品控人员", "生产人员", "物流人员", "管理人员", "护士", "受种者家属", "管理人员", "操作人员","后台管理者"});*/ DataPickerDialog dialog2 = builder2.setData(roleType).setSelection(0).setTitle("职务") .setOnDataSelectedListener(new DataPickerDialog.OnDataSelectedListener() { @Override public void onDataSelected(String itemValue) { tvInformationFactory.setText(itemValue + ""); //Toast.makeText(getApplicationContext(), itemValue, Toast.LENGTH_SHORT).show(); } }).create(); dialog2.show(); } break; case R.id.attc_et_phone: startActivity(CompanyChooseActivity.class); break; /*case R.id.download_btn: //toast("下载"); //下载的图片路径 String url = "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1560345333671&di=3642b27a83162af116af51289ec4d11f&imgtype=jpg&src=http%3A%2F%2Fimg1.imgtn.bdimg.com%2Fit%2Fu%3D2191520521%2C2689315141%26fm%3D214%26gp%3D0.jpg"; final String fileName = "evvmproveimg.jpg"; //文件名 注意结尾要加后缀 RxHttpUtils .downloadFile(url) //.subscribe(new DownloadObserver(fileName,destFileDir) 其中 destFileDir是自定义下载存储路径 .subscribe(new DownloadObserver(fileName, Environment.getExternalStorageDirectory().getPath()) { //可以通过配置tag用于取消下载请求 @Override protected String setTag() { return "download"; } @Override protected void onError(String errorMsg) { toast(errorMsg); } @Override protected void onSuccess(long bytesRead, long contentLength, float progress, boolean done, String filePath) { btnProveDownload.setText("" + progress + "%"); if (done) { btnProveDownload.setText("下载\n完成"); toast("下载完成,请上传"); } } }); break;*/ } } //根据parent名字返回id private int getRoleParentId(String name) { if ("医药企业".equals(name)) return 6; if ("预防接种机构".equals(name)) return 7; if ("预防接受种者".equals(name)) return 8; if ("物流公司".equals(name)) return 9; return 0; } @Subscribe(threadMode = ThreadMode.MAIN, sticky = true) public void onEvent(CompanyEvent event) { attcEtPhone.setText(event.getCompanyName()); } //根据id返回字列表 private List getRoleType(int parentId) { List list = new ArrayList<>(); switch (parentId) { case 6: list.clear(); list.add("管理员"); list.add("操作员"); list.add("品控人员"); list.add("生产人员"); list.add("物流人员"); list.add("后台管理员"); return list; case 7: list.clear(); list.add("医生"); list.add("管理人员"); list.add("护士"); return list; case 8: list.clear(); list.add("受种者本人"); list.add("受种者家属"); return list; case 9: list.clear(); list.add("管理人员"); list.add("操作人员"); return list; default: return null; } } //根据名字返回id private int getRoleId(String name) { if ("超级管理员".equals(name)) return 1; if ("医生".equals(name)) return 2; if ("管理员".equals(name)) return 3; if ("操作员".equals(name)) return 4; if ("受种着本人".equals(name)) return 5; if ("医药企业".equals(name)) return 6; if ("预防接种机构".equals(name)) return 7; if ("预防接种者".equals(name)) return 8; if ("物流公司".equals(name)) return 9; if ("其他".equals(name)) return 10; if ("品控人员".equals(name)) return 11; if ("生产人员".equals(name)) return 12; if ("物流人员".equals(name)) return 13; if ("管理人员".equals(name) && "预防接种机构".equals(tvInformationHospital.getText().toString())) return 14; if ("护士".equals(name)) return 15; if ("受种者家属".equals(name)) return 16; if ("管理人员".equals(name) && "物流公司".equals(tvInformationHospital.getText().toString())) return 17; if ("操作人员".equals(name)) return 18; if ("后台管理者".equals(name)) return 19; return 0; } @Override protected AttctPresenter createPresenter() { return new AttctPresenter(); } @Override public void attctError(String msg) { toast(msg); } @Override public void attctSuccess(VerificationCodeBean data) { // Log.e("attctSuccessVN",data.getData().toString()+data.getMsg()); toast("注册成功"); Intent in = new Intent(this, LikeActivity.class); in.putExtra("LikeUserId", "" + Double.valueOf(String.valueOf(data.getData())).intValue()); in.putExtra("LikeRoleId", getRoleId(tvInformationFactory.getText().toString()) + ""); startActivityFinish(in); } private List uploadimgpaths1 = new ArrayList<>(); private List uploadimgpaths2 = new ArrayList<>(); @Override protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_LICENSE_CHOOSE_FROM_GALLERY) { //执业执照回调 List selectedPhotos = BGAPhotoPickerActivity.getSelectedPhotos(data); uploadimgpaths1.clear(); uploadimgpaths1.addAll(selectedPhotos); //attcEtImgcount.setText("照片数量:" + uploadimgpaths1.size() + "张"); // BGAImage.display(attcEtLicense, R.mipmap.iv_upload_icon, selectedPhotos.get(0), AutoSizeUtils.dp2px(this, 77), AutoSizeUtils.dp2px(this, 43)); mPhotosSnpl.addMoreData(BGAPhotoPickerActivity.getSelectedPhotos(data)); Log.e("uploadimgpaths1", "" + uploadimgpaths1.toString()); } else if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_PROVE_CHOOSE_FROM_GALLERY) { //授权证明回调 String picturePath = BGAPhotoPickerActivity.getSelectedPhotos(data).get(0); uploadimgpaths2.clear(); uploadimgpaths2.add(picturePath); BGAImage.display(attcEtProve, R.mipmap.iv_upload_icon, picturePath, AutoSizeUtils.dp2px(this, 77), AutoSizeUtils.dp2px(this, 43)); Log.e("uploadimgpaths2", "" + uploadimgpaths2.toString()); } } @Override public void onClickAddNinePhotoItem(BGASortableNinePhotoLayout sortableNinePhotoLayout, View view, int position, ArrayList models) { Intent photoPickerIntent = new BGAPhotoPickerActivity.IntentBuilder(this) .cameraFileDir(takePhotoDir) // 拍照后照片的存放目录,改成你自己拍照后要存放照片的目录。如果不传递该参数的话则不开启图库里的拍照功能 .maxChooseCount(mPhotosSnpl.getMaxItemCount() - mPhotosSnpl.getItemCount()) // 图片选择张数的最大值 .selectedPhotos(null) // 当前已选中的图片路径集合 .pauseOnScroll(false) // 滚动列表时是否暂停加载图片 .build(); startActivityForResult(photoPickerIntent, REQUEST_LICENSE_CHOOSE_FROM_GALLERY); } @Override public void onClickDeleteNinePhotoItem(BGASortableNinePhotoLayout sortableNinePhotoLayout, View view, int position, String model, ArrayList models) { mPhotosSnpl.removeItem(position); } @Override public void onClickNinePhotoItem(BGASortableNinePhotoLayout sortableNinePhotoLayout, View view, int position, String model, ArrayList models) { Intent photoPickerPreviewIntent = new BGAPhotoPickerPreviewActivity.IntentBuilder(this) .previewPhotos(models) // 当前预览的图片路径集合 .selectedPhotos(models) // 当前已选中的图片路径集合 .maxChooseCount(mPhotosSnpl.getMaxItemCount()) // 图片选择张数的最大值 .currentPosition(position) // 当前预览图片的索引 .isFromTakePhoto(false) // 是否是拍完照后跳转过来 .build(); startActivityForResult(photoPickerPreviewIntent, REQUEST_LICENSE_PHOTO_PREVIEW); } @Override public void onNinePhotoItemExchanged(BGASortableNinePhotoLayout sortableNinePhotoLayout, int fromPosition, int toPosition, ArrayList models) { } }