ba714943a122cd3edd239a5a1be6e81b406802e6.svn-base 22 KB

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