cd4eede01f837658bebb7d7f209b01108fa89edd.svn-base 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  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.allen.library.RxHttpUtils;
  23. import com.allen.library.download.DownloadObserver;
  24. import com.hjq.dialog.MessageDialog;
  25. import java.io.File;
  26. import java.util.ArrayList;
  27. import java.util.Arrays;
  28. import java.util.List;
  29. import butterknife.BindView;
  30. import butterknife.ButterKnife;
  31. import butterknife.OnClick;
  32. import cn.bingoogolapple.photopicker.activity.BGAPhotoPickerActivity;
  33. import cn.bingoogolapple.photopicker.imageloader.BGAImage;
  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 {
  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.attc_et_imgcount)
  72. TextView attcEtImgcount;
  73. @BindView(R.id.btn_prove_download)
  74. Button btnProveDownload;
  75. private File takePhotoDir = new File(Environment.getExternalStorageDirectory(), "eVVM");
  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. Button downloadBtn = (Button) findViewById(R.id.download_btn);
  121. // download() ;
  122. downloadBtn.setOnClickListener(new View.OnClickListener() {
  123. @Override
  124. public void onClick(View v) {
  125. List<String> permissionList = new ArrayList<>();
  126. if (ContextCompat.checkSelfPermission(AuthenticationActivity.this,
  127. Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
  128. permissionList.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
  129. }
  130. if (!permissionList.isEmpty()) {
  131. String[] permissions = permissionList.toArray(new String[permissionList.size()]);
  132. ActivityCompat.requestPermissions(AuthenticationActivity.this, permissions, 1);
  133. } else {
  134. ImgDonwloads.donwloadImg(AuthenticationActivity.this, ApiUrl.authPath);//iPath
  135. }
  136. }
  137. });
  138. }
  139. @Override
  140. public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
  141. switch (requestCode) {
  142. case 1:
  143. if (grantResults.length > 0) {
  144. for (int result : grantResults) {
  145. if (result != PackageManager.PERMISSION_GRANTED) {
  146. toast( "拒绝了权限");
  147. return;
  148. }
  149. }
  150. ImgDonwloads.donwloadImg(AuthenticationActivity.this,"");
  151. } else {
  152. toast( "发生未知错误");
  153. }
  154. break;
  155. default:
  156. }
  157. }
  158. @Override
  159. protected void initData() {
  160. }
  161. @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.btn_prove_download})
  162. public void onViewClicked(View view) {
  163. switch (view.getId()) {
  164. case R.id.attc_et_license:
  165. //上传营业执照
  166. /*
  167. 从相册选取二维码图片,这里为了方便演示,使用的是
  168. https://github.com/bingoogolapple/BGAPhotoPicker-Android
  169. 这个库来从图库中选择二维码图片,这个库不是必须的,你也可以通过自己的方式从图库中选择图片
  170. */
  171. Intent licensePhotoPickerIntent = new BGAPhotoPickerActivity.IntentBuilder(this)
  172. .cameraFileDir(takePhotoDir)
  173. .maxChooseCount(3)
  174. .selectedPhotos(null)
  175. .pauseOnScroll(false)
  176. .build();
  177. startActivityForResult(licensePhotoPickerIntent, REQUEST_LICENSE_CHOOSE_FROM_GALLERY);
  178. break;
  179. case R.id.attc_et_prove:
  180. //上传授权证明
  181. if (uploadimgpaths1.size() == 0) {
  182. toast("请先选择营业执照");
  183. } else {
  184. Intent provePhotoPickerIntent = new BGAPhotoPickerActivity.IntentBuilder(this)
  185. .cameraFileDir(takePhotoDir)
  186. .maxChooseCount(1)
  187. .selectedPhotos(null)
  188. .pauseOnScroll(false)
  189. .build();
  190. startActivityForResult(provePhotoPickerIntent, REQUEST_PROVE_CHOOSE_FROM_GALLERY);
  191. }
  192. break;
  193. case R.id.attc_btn_register:
  194. //进行实名认证
  195. List<String> uploadimgpaths3 = new ArrayList<>();
  196. if ("预防接种机构".equals(tvInformationHospital.getText().toString())) {
  197. if (uploadimgpaths1.size() == 0 || uploadimgpaths2.size() == 0) {
  198. toast("请选择营业执照及授权证明");
  199. } else {
  200. uploadimgpaths3.clear();
  201. uploadimgpaths3.addAll(uploadimgpaths1);
  202. uploadimgpaths3.addAll(uploadimgpaths2);
  203. //String user_id = (String) SPUtils.get("USER_ID", "");
  204. if (TextUtils.isEmpty(registerUserId)) {
  205. Log.e("getPresenterattct", "" + uploadimgpaths3.toString());
  206. } else {
  207. getPresenter().attct(Integer.parseInt(registerUserId), attcEtPhone.getText().toString()
  208. , attcEtName.getText().toString(), attcEtCode.getText().toString(),
  209. attcEtEmail.getText().toString(), getRoleId(tvInformationFactory.getText().toString()) + "",
  210. 0, Build.BRAND + " " + Build.MODEL, uploadimgpaths3);
  211. }
  212. }
  213. } else {
  214. if (TextUtils.isEmpty(registerUserId)) {
  215. } else {
  216. getPresenter().attct(Integer.parseInt(registerUserId), attcEtPhone.getText().toString()
  217. , attcEtName.getText().toString(), attcEtCode.getText().toString(),
  218. attcEtEmail.getText().toString(), getRoleId(tvInformationFactory.getText().toString()) + "",
  219. 0, Build.BRAND + " " + Build.MODEL, uploadimgpaths3);
  220. }
  221. }
  222. break;
  223. case R.id.tv_information_hospital:
  224. DataPickerDialog.Builder builder = new DataPickerDialog.Builder(this);
  225. List<String> data = Arrays.asList(new String[]{"医药企业", "预防接种机构", "预防接受种者", "物流公司"});
  226. /*List<RoleTypeBean.RoleParen> parentlist = new ArrayList<>();
  227. parentlist.add(new RoleTypeBean.RoleParen(6,"","医药企业"));
  228. parentlist.add(new RoleTypeBean.RoleParen(7,"","预防接种机构"));
  229. parentlist.add(new RoleTypeBean.RoleParen(8,"","预防接受种者"));
  230. parentlist.add(new RoleTypeBean.RoleParen(9,"","物流公司"));*/
  231. DataPickerDialog dialog = builder.setData(data).setSelection(0).setTitle("标题")
  232. .setOnDataSelectedListener(new DataPickerDialog.OnDataSelectedListener() {
  233. @Override
  234. public void onDataSelected(String itemValue) {
  235. if (!TextUtils.isEmpty(tvInformationHospital.getText().toString())) {
  236. tvInformationFactory.setText("");
  237. }
  238. tvInformationHospital.setText(itemValue + "");
  239. if ("预防接种机构".equals(itemValue)) {
  240. attcLlLicense.setVisibility(View.VISIBLE);
  241. attcLlProve.setVisibility(View.VISIBLE);
  242. } else {
  243. attcLlLicense.setVisibility(View.GONE);
  244. attcLlProve.setVisibility(View.GONE);
  245. }
  246. }
  247. }).create();
  248. dialog.show();
  249. break;
  250. case R.id.tv_information_factory:
  251. if (TextUtils.isEmpty(tvInformationHospital.getText().toString())) {
  252. toast("请先选择所属类型");
  253. return;
  254. } else {
  255. int roleParentId = getRoleParentId(tvInformationHospital.getText().toString());
  256. List<String> roleType = getRoleType(roleParentId);
  257. DataPickerDialog.Builder builder2 = new DataPickerDialog.Builder(this);
  258. /*List<String> data2 = Arrays.asList(new String[]{"品控人员", "生产人员", "物流人员", "管理人员", "护士", "受种者家属",
  259. "管理人员", "操作人员","后台管理者"});*/
  260. DataPickerDialog dialog2 = builder2.setData(roleType).setSelection(0).setTitle("职务")
  261. .setOnDataSelectedListener(new DataPickerDialog.OnDataSelectedListener() {
  262. @Override
  263. public void onDataSelected(String itemValue) {
  264. tvInformationFactory.setText(itemValue + "");
  265. //Toast.makeText(getApplicationContext(), itemValue, Toast.LENGTH_SHORT).show();
  266. }
  267. }).create();
  268. dialog2.show();
  269. }
  270. break;
  271. case R.id.btn_prove_download:
  272. //toast("下载");
  273. //下载的图片路径
  274. 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";
  275. final String fileName = "evvmproveimg.jpg"; //文件名 注意结尾要加后缀
  276. RxHttpUtils
  277. .downloadFile(url)
  278. //.subscribe(new DownloadObserver(fileName,destFileDir) 其中 destFileDir是自定义下载存储路径
  279. .subscribe(new DownloadObserver(fileName, Environment.getExternalStorageDirectory().getPath()) {
  280. //可以通过配置tag用于取消下载请求
  281. @Override
  282. protected String setTag() {
  283. return "download";
  284. }
  285. @Override
  286. protected void onError(String errorMsg) {
  287. toast(errorMsg);
  288. }
  289. @Override
  290. protected void onSuccess(long bytesRead, long contentLength, float progress, boolean done, String filePath) {
  291. btnProveDownload.setText("" + progress + "%");
  292. if (done) {
  293. btnProveDownload.setText("下载\n完成");
  294. toast("下载完成,请上传");
  295. }
  296. }
  297. });
  298. break;
  299. }
  300. }
  301. //根据parent名字返回id
  302. private int getRoleParentId(String name) {
  303. if ("医药企业".equals(name))
  304. return 6;
  305. if ("预防接种机构".equals(name))
  306. return 7;
  307. if ("预防接受种者".equals(name))
  308. return 8;
  309. if ("物流公司".equals(name))
  310. return 9;
  311. return 0;
  312. }
  313. //根据id返回字列表
  314. private List<String> getRoleType(int parentId) {
  315. List<String> list = new ArrayList<>();
  316. switch (parentId) {
  317. case 6:
  318. list.clear();
  319. list.add("管理员");
  320. list.add("操作员");
  321. list.add("品控人员");
  322. list.add("生产人员");
  323. list.add("物流人员");
  324. list.add("后台管理员");
  325. return list;
  326. case 7:
  327. list.clear();
  328. list.add("医生");
  329. list.add("管理人员");
  330. list.add("护士");
  331. return list;
  332. case 8:
  333. list.clear();
  334. list.add("受种者本人");
  335. list.add("受种者家属");
  336. return list;
  337. case 9:
  338. list.clear();
  339. list.add("管理人员");
  340. list.add("操作人员");
  341. return list;
  342. default:
  343. return null;
  344. }
  345. }
  346. //根据名字返回id
  347. private int getRoleId(String name) {
  348. if ("超级管理员".equals(name))
  349. return 1;
  350. if ("医生".equals(name))
  351. return 2;
  352. if ("管理员".equals(name))
  353. return 3;
  354. if ("操作员".equals(name))
  355. return 4;
  356. if ("受种着本人".equals(name))
  357. return 5;
  358. if ("医药企业".equals(name))
  359. return 6;
  360. if ("预防接种机构".equals(name))
  361. return 7;
  362. if ("预防接种者".equals(name))
  363. return 8;
  364. if ("物流公司".equals(name))
  365. return 9;
  366. if ("其他".equals(name))
  367. return 10;
  368. if ("品控人员".equals(name))
  369. return 11;
  370. if ("生产人员".equals(name))
  371. return 12;
  372. if ("物流人员".equals(name))
  373. return 13;
  374. if ("管理人员".equals(name) && "预防接种机构".equals(tvInformationHospital.getText().toString()))
  375. return 14;
  376. if ("护士".equals(name))
  377. return 15;
  378. if ("受种者家属".equals(name))
  379. return 16;
  380. if ("管理人员".equals(name) && "物流公司".equals(tvInformationHospital.getText().toString()))
  381. return 17;
  382. if ("操作人员".equals(name))
  383. return 18;
  384. if ("后台管理者".equals(name))
  385. return 19;
  386. return 0;
  387. }
  388. @Override
  389. protected AttctPresenter createPresenter() {
  390. return new AttctPresenter();
  391. }
  392. @Override
  393. public void attctError(String msg) {
  394. toast(msg);
  395. }
  396. @Override
  397. public void attctSuccess(VerificationCodeBean data) {
  398. // Log.e("attctSuccessVN",data.getData().toString()+data.getMsg());
  399. toast("注册成功");
  400. Intent in = new Intent(this, LikeActivity.class);
  401. in.putExtra("LikeUserId", "" + Double.valueOf(String.valueOf(data.getData())).intValue());
  402. in.putExtra("LikeRoleId", getRoleId(tvInformationFactory.getText().toString()) + "");
  403. startActivityFinish(in);
  404. }
  405. private List<String> uploadimgpaths1 = new ArrayList<>();
  406. private List<String> uploadimgpaths2 = new ArrayList<>();
  407. @Override
  408. protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
  409. super.onActivityResult(requestCode, resultCode, data);
  410. if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_LICENSE_CHOOSE_FROM_GALLERY) {
  411. //营业执照回调
  412. List<String> selectedPhotos = BGAPhotoPickerActivity.getSelectedPhotos(data);
  413. uploadimgpaths1.clear();
  414. uploadimgpaths1.addAll(selectedPhotos);
  415. attcEtImgcount.setText("照片数量:" + uploadimgpaths1.size() + "张");
  416. BGAImage.display(attcEtLicense, R.mipmap.iv_upload_icon, selectedPhotos.get(0), AutoSizeUtils.dp2px(this, 77), AutoSizeUtils.dp2px(this, 43));
  417. Log.e("uploadimgpaths1", "" + uploadimgpaths1.toString());
  418. } else if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_PROVE_CHOOSE_FROM_GALLERY) {
  419. //授权证明回调
  420. String picturePath = BGAPhotoPickerActivity.getSelectedPhotos(data).get(0);
  421. uploadimgpaths2.clear();
  422. uploadimgpaths2.add(picturePath);
  423. BGAImage.display(attcEtProve, R.mipmap.iv_upload_icon, picturePath, AutoSizeUtils.dp2px(this, 77), AutoSizeUtils.dp2px(this, 43));
  424. Log.e("uploadimgpaths2", "" + uploadimgpaths2.toString());
  425. }
  426. }
  427. }