7d3fb2ea525a385d6530a516bbb615e4732a6092.svn-base 23 KB

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