3404f768e5441de874d899dc8452aca0c2565383.svn-base 22 KB

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