24890b2a0ec32dfefdf996afd80d9840309ebc9e.svn-base 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. package eVVM.apk.ui.login;
  2. import android.Manifest;
  3. import android.app.Activity;
  4. import android.app.Dialog;
  5. import android.content.Intent;
  6. import android.content.pm.PackageManager;
  7. import android.os.Build;
  8. import android.os.Environment;
  9. import android.support.annotation.NonNull;
  10. import android.support.annotation.Nullable;
  11. import android.support.v4.app.ActivityCompat;
  12. import android.support.v4.content.ContextCompat;
  13. import android.text.TextUtils;
  14. import android.util.Log;
  15. import android.view.View;
  16. import android.widget.Button;
  17. import android.widget.EditText;
  18. import android.widget.ImageView;
  19. import android.widget.LinearLayout;
  20. import android.widget.TextView;
  21. import com.hjq.dialog.MessageDialog;
  22. import java.io.File;
  23. import java.util.ArrayList;
  24. import java.util.Arrays;
  25. import java.util.List;
  26. import butterknife.BindView;
  27. import butterknife.OnClick;
  28. import cn.bingoogolapple.photopicker.activity.BGAPhotoPickerActivity;
  29. import cn.bingoogolapple.photopicker.activity.BGAPhotoPickerPreviewActivity;
  30. import cn.bingoogolapple.photopicker.imageloader.BGAImage;
  31. import cn.bingoogolapple.photopicker.widget.BGASortableNinePhotoLayout;
  32. import eVVM.apk.R;
  33. import eVVM.apk.api.ApiUrl;
  34. import eVVM.apk.helper.ImgDonwloads;
  35. import eVVM.apk.helper.InputTextHelper;
  36. import eVVM.apk.helper.basepicker.DataPickerDialog;
  37. import eVVM.apk.mvp.MvpActivity;
  38. import eVVM.apk.ui.bean.VerificationCodeBean;
  39. import eVVM.apk.ui.launcher.LikeActivity;
  40. import eVVM.apk.ui.login.authentication.AttctContract;
  41. import eVVM.apk.ui.login.authentication.AttctPresenter;
  42. import me.jessyan.autosize.utils.AutoSizeUtils;
  43. /**
  44. * 实名认证页
  45. */
  46. public class AuthenticationActivity extends MvpActivity<AttctPresenter> implements AttctContract.View, BGASortableNinePhotoLayout.Delegate {
  47. @BindView(R.id.attc_et_phone)
  48. TextView attcEtPhone;
  49. @BindView(R.id.attc_et_name)
  50. EditText attcEtName;
  51. @BindView(R.id.attc_et_code)
  52. EditText attcEtCode;
  53. @BindView(R.id.attc_et_email)
  54. EditText attcEtEmail;
  55. @BindView(R.id.attc_et_license)
  56. ImageView attcEtLicense;
  57. @BindView(R.id.attc_et_prove)
  58. ImageView attcEtProve;
  59. @BindView(R.id.attc_btn_register)
  60. Button attcBtnRegister;
  61. @BindView(R.id.tv_information_hospital)
  62. TextView tvInformationHospital;
  63. @BindView(R.id.tv_information_factory)
  64. TextView tvInformationFactory;
  65. @BindView(R.id.attc_ll_license)
  66. LinearLayout attcLlLicense;
  67. @BindView(R.id.attc_ll_prove)
  68. LinearLayout attcLlProve;
  69. @BindView(R.id.snpl_moment_add_photos)
  70. BGASortableNinePhotoLayout mPhotosSnpl;
  71. private File takePhotoDir = new File(Environment.getExternalStorageDirectory(), "eVVM");
  72. private static final int REQUEST_LICENSE_PHOTO_PREVIEW = 1324;
  73. private static final int REQUEST_LICENSE_CHOOSE_FROM_GALLERY = 1325;
  74. private static final int REQUEST_PROVE_CHOOSE_FROM_GALLERY = 1326;
  75. private String registerUserId;
  76. @Override
  77. protected int getLayoutId() {
  78. return R.layout.activity_authentication;
  79. }
  80. @Override
  81. protected int getTitleId() {
  82. return R.id.attc_title;
  83. }
  84. @Override
  85. public void onLeftClick(View v) {
  86. new MessageDialog.Builder(this)
  87. .setTitle("") // 标题可以不用填写
  88. .setMessage("您未完成实名认证,是否退出")
  89. .setConfirm("确定")
  90. .setCancel("取消") // 设置 null 表示不显示取消按钮
  91. //.setAutoDismiss(false) // 设置点击按钮后不关闭对话框
  92. .setListener(new MessageDialog.OnListener() {
  93. @Override
  94. public void onConfirm(Dialog dialog) {
  95. finish();
  96. }
  97. @Override
  98. public void onCancel(Dialog dialog) {
  99. //toast("取消了");
  100. }
  101. })
  102. .show();
  103. }
  104. @Override
  105. protected void initView() {
  106. new InputTextHelper.Builder(this)
  107. .setMain(attcBtnRegister)
  108. .addView(attcEtPhone)
  109. .addView(attcEtName)
  110. .addView(attcEtCode)
  111. .addView(attcEtEmail)
  112. .addView(tvInformationHospital)
  113. .addView(tvInformationFactory)
  114. .build();
  115. Intent in = getIntent();
  116. registerUserId = in.getStringExtra("registerUserId");
  117. mPhotosSnpl.setData(null);
  118. mPhotosSnpl.setMaxItemCount(3);
  119. mPhotosSnpl.setSortable(false);
  120. mPhotosSnpl.setEditable(true);
  121. mPhotosSnpl.setPlusEnable(true);
  122. mPhotosSnpl.setDelegate(this);
  123. Button downloadBtn = (Button) findViewById(R.id.download_btn);
  124. // download() ;
  125. downloadBtn.setOnClickListener(new View.OnClickListener() {
  126. @Override
  127. public void onClick(View v) {
  128. List<String> permissionList = new ArrayList<>();
  129. if (ContextCompat.checkSelfPermission(AuthenticationActivity.this,
  130. Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
  131. permissionList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
  132. }
  133. if (!permissionList.isEmpty()) {
  134. String[] permissions = permissionList.toArray(new String[permissionList.size()]);
  135. ActivityCompat.requestPermissions(AuthenticationActivity.this, permissions, 1);
  136. } else {
  137. ImgDonwloads.donwloadImg(AuthenticationActivity.this, ApiUrl.authPath);//iPath
  138. }
  139. }
  140. });
  141. }
  142. @Override
  143. public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
  144. switch (requestCode) {
  145. case 1:
  146. if (grantResults.length > 0) {
  147. for (int result : grantResults) {
  148. if (result != PackageManager.PERMISSION_GRANTED) {
  149. toast("拒绝了权限");
  150. return;
  151. }
  152. }
  153. ImgDonwloads.donwloadImg(AuthenticationActivity.this, "");
  154. } else {
  155. toast("发生未知错误");
  156. }
  157. break;
  158. default:
  159. }
  160. }
  161. @Override
  162. protected void initData() {
  163. }
  164. @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})
  165. public void onViewClicked(View view) {
  166. switch (view.getId()) {
  167. case R.id.attc_et_license:
  168. //上传执业执照
  169. /*
  170. 从相册选取二维码图片,这里为了方便演示,使用的是
  171. https://github.com/bingoogolapple/BGAPhotoPicker-Android
  172. 这个库来从图库中选择二维码图片,这个库不是必须的,你也可以通过自己的方式从图库中选择图片
  173. */
  174. Intent licensePhotoPickerIntent = new BGAPhotoPickerActivity.IntentBuilder(this)
  175. .cameraFileDir(takePhotoDir)
  176. .maxChooseCount(3)
  177. .selectedPhotos(null)
  178. .pauseOnScroll(false)
  179. .build();
  180. startActivityForResult(licensePhotoPickerIntent, REQUEST_LICENSE_CHOOSE_FROM_GALLERY);
  181. break;
  182. case R.id.attc_et_prove:
  183. //上传授权证明
  184. if (uploadimgpaths1.size() == 0) {
  185. toast("请先选择执业执照");
  186. } else {
  187. Intent provePhotoPickerIntent = new BGAPhotoPickerActivity.IntentBuilder(this)
  188. .cameraFileDir(takePhotoDir)
  189. .maxChooseCount(1)
  190. .selectedPhotos(null)
  191. .pauseOnScroll(false)
  192. .build();
  193. startActivityForResult(provePhotoPickerIntent, REQUEST_PROVE_CHOOSE_FROM_GALLERY);
  194. }
  195. break;
  196. case R.id.attc_btn_register:
  197. //进行实名认证
  198. List<String> uploadimgpaths3 = new ArrayList<>();
  199. if ("预防接种机构".equals(tvInformationHospital.getText().toString())) {
  200. if (mPhotosSnpl.getData().size() == 0 || uploadimgpaths2.size() == 0) {
  201. toast("请选择执业执照及授权证明");
  202. } else {
  203. uploadimgpaths3.clear();
  204. uploadimgpaths3.addAll(mPhotosSnpl.getData());
  205. uploadimgpaths3.addAll(uploadimgpaths2);
  206. //String user_id = (String) SPUtils.get("USER_ID", "");
  207. if (TextUtils.isEmpty(registerUserId)) {
  208. Log.e("getPresenterattct", "" + uploadimgpaths3.toString());
  209. } else {
  210. getPresenter().attct(Integer.parseInt(registerUserId), attcEtPhone.getText().toString()
  211. , attcEtName.getText().toString(), attcEtCode.getText().toString(),
  212. attcEtEmail.getText().toString(), getRoleId(tvInformationFactory.getText().toString()) + "",
  213. 0, Build.BRAND + " " + Build.MODEL, uploadimgpaths3);
  214. }
  215. }
  216. } else {
  217. if (TextUtils.isEmpty(registerUserId)) {
  218. } else {
  219. List<String> emptyList = new ArrayList<>();
  220. getPresenter().attct(Integer.parseInt(registerUserId), attcEtPhone.getText().toString()
  221. , attcEtName.getText().toString(), attcEtCode.getText().toString(),
  222. attcEtEmail.getText().toString(), getRoleId(tvInformationFactory.getText().toString()) + "",
  223. 0, Build.BRAND + " " + Build.MODEL, emptyList);
  224. }
  225. }
  226. break;
  227. case R.id.tv_information_hospital:
  228. DataPickerDialog.Builder builder = new DataPickerDialog.Builder(this);
  229. List<String> data = Arrays.asList(new String[]{"医药企业", "预防接种机构", "预防接受种者", "物流公司"});
  230. /*List<RoleTypeBean.RoleParen> parentlist = new ArrayList<>();
  231. parentlist.add(new RoleTypeBean.RoleParen(6,"","医药企业"));
  232. parentlist.add(new RoleTypeBean.RoleParen(7,"","预防接种机构"));
  233. parentlist.add(new RoleTypeBean.RoleParen(8,"","预防接受种者"));
  234. parentlist.add(new RoleTypeBean.RoleParen(9,"","物流公司"));*/
  235. DataPickerDialog dialog = builder.setData(data).setSelection(0).setTitle("标题")
  236. .setOnDataSelectedListener(new DataPickerDialog.OnDataSelectedListener() {
  237. @Override
  238. public void onDataSelected(String itemValue) {
  239. if (!TextUtils.isEmpty(tvInformationHospital.getText().toString())) {
  240. tvInformationFactory.setText("");
  241. }
  242. tvInformationHospital.setText(itemValue + "");
  243. if ("预防接种机构".equals(itemValue)) {
  244. attcLlLicense.setVisibility(View.VISIBLE);
  245. attcLlProve.setVisibility(View.VISIBLE);
  246. } else {
  247. attcLlLicense.setVisibility(View.GONE);
  248. attcLlProve.setVisibility(View.GONE);
  249. }
  250. }
  251. }).create();
  252. dialog.show();
  253. break;
  254. case R.id.tv_information_factory:
  255. if (TextUtils.isEmpty(tvInformationHospital.getText().toString())) {
  256. toast("请先选择所属类型");
  257. return;
  258. } else {
  259. int roleParentId = getRoleParentId(tvInformationHospital.getText().toString());
  260. List<String> roleType = getRoleType(roleParentId);
  261. DataPickerDialog.Builder builder2 = new DataPickerDialog.Builder(this);
  262. /*List<String> data2 = Arrays.asList(new String[]{"品控人员", "生产人员", "物流人员", "管理人员", "护士", "受种者家属",
  263. "管理人员", "操作人员","后台管理者"});*/
  264. DataPickerDialog dialog2 = builder2.setData(roleType).setSelection(0).setTitle("职务")
  265. .setOnDataSelectedListener(new DataPickerDialog.OnDataSelectedListener() {
  266. @Override
  267. public void onDataSelected(String itemValue) {
  268. tvInformationFactory.setText(itemValue + "");
  269. //Toast.makeText(getApplicationContext(), itemValue, Toast.LENGTH_SHORT).show();
  270. }
  271. }).create();
  272. dialog2.show();
  273. }
  274. break;
  275. case R.id.attc_et_phone:
  276. startActivity(CompanyChooseActivity.class);
  277. break;
  278. /*case R.id.download_btn:
  279. //toast("下载");
  280. //下载的图片路径
  281. 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";
  282. final String fileName = "evvmproveimg.jpg"; //文件名 注意结尾要加后缀
  283. RxHttpUtils
  284. .downloadFile(url)
  285. //.subscribe(new DownloadObserver(fileName,destFileDir) 其中 destFileDir是自定义下载存储路径
  286. .subscribe(new DownloadObserver(fileName, Environment.getExternalStorageDirectory().getPath()) {
  287. //可以通过配置tag用于取消下载请求
  288. @Override
  289. protected String setTag() {
  290. return "download";
  291. }
  292. @Override
  293. protected void onError(String errorMsg) {
  294. toast(errorMsg);
  295. }
  296. @Override
  297. protected void onSuccess(long bytesRead, long contentLength, float progress, boolean done, String filePath) {
  298. btnProveDownload.setText("" + progress + "%");
  299. if (done) {
  300. btnProveDownload.setText("下载\n完成");
  301. toast("下载完成,请上传");
  302. }
  303. }
  304. });
  305. break;*/
  306. }
  307. }
  308. //根据parent名字返回id
  309. private int getRoleParentId(String name) {
  310. if ("医药企业".equals(name))
  311. return 6;
  312. if ("预防接种机构".equals(name))
  313. return 7;
  314. if ("预防接受种者".equals(name))
  315. return 8;
  316. if ("物流公司".equals(name))
  317. return 9;
  318. return 0;
  319. }
  320. //根据id返回字列表
  321. private List<String> getRoleType(int parentId) {
  322. List<String> list = new ArrayList<>();
  323. switch (parentId) {
  324. case 6:
  325. list.clear();
  326. list.add("管理员");
  327. list.add("操作员");
  328. list.add("品控人员");
  329. list.add("生产人员");
  330. list.add("物流人员");
  331. list.add("后台管理员");
  332. return list;
  333. case 7:
  334. list.clear();
  335. list.add("医生");
  336. list.add("管理人员");
  337. list.add("护士");
  338. return list;
  339. case 8:
  340. list.clear();
  341. list.add("受种者本人");
  342. list.add("受种者家属");
  343. return list;
  344. case 9:
  345. list.clear();
  346. list.add("管理人员");
  347. list.add("操作人员");
  348. return list;
  349. default:
  350. return null;
  351. }
  352. }
  353. //根据名字返回id
  354. private int getRoleId(String name) {
  355. if ("超级管理员".equals(name))
  356. return 1;
  357. if ("医生".equals(name))
  358. return 2;
  359. if ("管理员".equals(name))
  360. return 3;
  361. if ("操作员".equals(name))
  362. return 4;
  363. if ("受种着本人".equals(name))
  364. return 5;
  365. if ("医药企业".equals(name))
  366. return 6;
  367. if ("预防接种机构".equals(name))
  368. return 7;
  369. if ("预防接种者".equals(name))
  370. return 8;
  371. if ("物流公司".equals(name))
  372. return 9;
  373. if ("其他".equals(name))
  374. return 10;
  375. if ("品控人员".equals(name))
  376. return 11;
  377. if ("生产人员".equals(name))
  378. return 12;
  379. if ("物流人员".equals(name))
  380. return 13;
  381. if ("管理人员".equals(name) && "预防接种机构".equals(tvInformationHospital.getText().toString()))
  382. return 14;
  383. if ("护士".equals(name))
  384. return 15;
  385. if ("受种者家属".equals(name))
  386. return 16;
  387. if ("管理人员".equals(name) && "物流公司".equals(tvInformationHospital.getText().toString()))
  388. return 17;
  389. if ("操作人员".equals(name))
  390. return 18;
  391. if ("后台管理者".equals(name))
  392. return 19;
  393. return 0;
  394. }
  395. @Override
  396. protected AttctPresenter createPresenter() {
  397. return new AttctPresenter();
  398. }
  399. @Override
  400. public void attctError(String msg) {
  401. toast(msg);
  402. }
  403. @Override
  404. public void attctSuccess(VerificationCodeBean data) {
  405. // Log.e("attctSuccessVN",data.getData().toString()+data.getMsg());
  406. toast("注册成功");
  407. Intent in = new Intent(this, LikeActivity.class);
  408. in.putExtra("LikeUserId", "" + Double.valueOf(String.valueOf(data.getData())).intValue());
  409. in.putExtra("LikeRoleId", getRoleId(tvInformationFactory.getText().toString()) + "");
  410. startActivityFinish(in);
  411. }
  412. private List<String> uploadimgpaths1 = new ArrayList<>();
  413. private List<String> uploadimgpaths2 = new ArrayList<>();
  414. @Override
  415. protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
  416. super.onActivityResult(requestCode, resultCode, data);
  417. if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_LICENSE_CHOOSE_FROM_GALLERY) {
  418. //执业执照回调
  419. List<String> selectedPhotos = BGAPhotoPickerActivity.getSelectedPhotos(data);
  420. uploadimgpaths1.clear();
  421. uploadimgpaths1.addAll(selectedPhotos);
  422. //attcEtImgcount.setText("照片数量:" + uploadimgpaths1.size() + "张");
  423. // BGAImage.display(attcEtLicense, R.mipmap.iv_upload_icon, selectedPhotos.get(0), AutoSizeUtils.dp2px(this, 77), AutoSizeUtils.dp2px(this, 43));
  424. mPhotosSnpl.addMoreData(BGAPhotoPickerActivity.getSelectedPhotos(data));
  425. Log.e("uploadimgpaths1", "" + uploadimgpaths1.toString());
  426. } else if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_PROVE_CHOOSE_FROM_GALLERY) {
  427. //授权证明回调
  428. String picturePath = BGAPhotoPickerActivity.getSelectedPhotos(data).get(0);
  429. uploadimgpaths2.clear();
  430. uploadimgpaths2.add(picturePath);
  431. BGAImage.display(attcEtProve, R.mipmap.iv_upload_icon, picturePath, AutoSizeUtils.dp2px(this, 77), AutoSizeUtils.dp2px(this, 43));
  432. Log.e("uploadimgpaths2", "" + uploadimgpaths2.toString());
  433. }
  434. }
  435. @Override
  436. public void onClickAddNinePhotoItem(BGASortableNinePhotoLayout sortableNinePhotoLayout, View view, int position, ArrayList<String> models) {
  437. Intent photoPickerIntent = new BGAPhotoPickerActivity.IntentBuilder(this)
  438. .cameraFileDir(takePhotoDir) // 拍照后照片的存放目录,改成你自己拍照后要存放照片的目录。如果不传递该参数的话则不开启图库里的拍照功能
  439. .maxChooseCount(mPhotosSnpl.getMaxItemCount() - mPhotosSnpl.getItemCount()) // 图片选择张数的最大值
  440. .selectedPhotos(null) // 当前已选中的图片路径集合
  441. .pauseOnScroll(false) // 滚动列表时是否暂停加载图片
  442. .build();
  443. startActivityForResult(photoPickerIntent, REQUEST_LICENSE_CHOOSE_FROM_GALLERY);
  444. }
  445. @Override
  446. public void onClickDeleteNinePhotoItem(BGASortableNinePhotoLayout sortableNinePhotoLayout, View view, int position, String model, ArrayList<String> models) {
  447. mPhotosSnpl.removeItem(position);
  448. }
  449. @Override
  450. public void onClickNinePhotoItem(BGASortableNinePhotoLayout sortableNinePhotoLayout, View view, int position, String model, ArrayList<String> models) {
  451. Intent photoPickerPreviewIntent = new BGAPhotoPickerPreviewActivity.IntentBuilder(this)
  452. .previewPhotos(models) // 当前预览的图片路径集合
  453. .selectedPhotos(models) // 当前已选中的图片路径集合
  454. .maxChooseCount(mPhotosSnpl.getMaxItemCount()) // 图片选择张数的最大值
  455. .currentPosition(position) // 当前预览图片的索引
  456. .isFromTakePhoto(false) // 是否是拍完照后跳转过来
  457. .build();
  458. startActivityForResult(photoPickerPreviewIntent, REQUEST_LICENSE_PHOTO_PREVIEW);
  459. }
  460. @Override
  461. public void onNinePhotoItemExchanged(BGASortableNinePhotoLayout sortableNinePhotoLayout, int fromPosition, int toPosition, ArrayList<String> models) {
  462. }
  463. }