InquiryActivity.java 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  1. package xn.hxp.ui.inquiry;
  2. import android.content.IntentFilter;
  3. import android.hardware.usb.UsbManager;
  4. import android.os.Bundle;
  5. import android.os.CountDownTimer;
  6. import android.os.Handler;
  7. import android.os.Looper;
  8. import android.view.KeyEvent;
  9. import android.view.View;
  10. import androidx.recyclerview.widget.LinearLayoutManager;
  11. import androidx.viewbinding.ViewBinding;
  12. import com.blankj.utilcode.util.ClickUtils;
  13. import com.blankj.utilcode.util.LogUtils;
  14. import com.bumptech.glide.Glide;
  15. import com.bumptech.glide.load.engine.DiskCacheStrategy;
  16. import com.bumptech.glide.request.RequestOptions;
  17. import com.rc.core.ui.activity.BaseActivity;
  18. import com.rc.core.ui.fragment.BaseFragment;
  19. import com.rc.httpcore.HttpConfig;
  20. import com.rc.httpcore.bean.HxpStockWaitListBean;
  21. import com.rc.httpcore.bean.LockVoListBean;
  22. import com.rc.httpcore.bean.RuleBean;
  23. import com.rc.httpcore.bean.UseNoBean;
  24. import com.rc.httpcore.bean.UseNoTwoBean;
  25. import com.rc.httpcore.client.ApiRepository;
  26. import com.rc.httpcore.client.HttpTool;
  27. import org.greenrobot.eventbus.EventBus;
  28. import org.greenrobot.eventbus.Subscribe;
  29. import org.greenrobot.eventbus.ThreadMode;
  30. import java.util.ArrayList;
  31. import java.util.HashMap;
  32. import java.util.List;
  33. import java.util.Map;
  34. import kotlin.Unit;
  35. import kotlin.jvm.functions.Function1;
  36. import xn.hxp.R;
  37. import xn.hxp.app.ChemicalApp;
  38. import xn.hxp.databinding.ActivityInquiryBinding;
  39. import xn.hxp.receiver.OnSerialScanListener;
  40. import xn.hxp.receiver.PortScanHelper;
  41. import xn.hxp.receiver.UsbReceiver;
  42. import xn.hxp.ui.DoubleDialogBean;
  43. import xn.hxp.ui.adapter.CabinetDoorAdapter;
  44. import xn.hxp.ui.adapter.CabinetDoorRighAdapter;
  45. import xn.hxp.ui.fragments.QueryOneFragment;
  46. import xn.hxp.ui.fragments.QueryTwoFragment;
  47. import xn.hxp.ui.login.FaceLoginActivity;
  48. import xn.hxp.ui.login.FacialCardActivity;
  49. import xn.hxp.ui.login.ScanLoginActivity;
  50. import xn.hxp.ui.login.SwipeActivity;
  51. import xn.hxp.utils.AudioPlayer;
  52. import xn.hxp.utils.BigDecimalUtils;
  53. import xn.hxp.utils.HandlerUtil;
  54. import xn.hxp.utils.SharedPreferencesHelper;
  55. import xn.hxp.utils.TimeUpdater;
  56. import xn.hxp.utils.UiManager;
  57. import xn.hxp.weidith.CustomDialog;
  58. import xn.hxp.weidith.PromptDialog;
  59. import xn.hxp.weidith.ScanCodeDialog;
  60. import xn.hxp.weidith.SwipeViewPager;
  61. import xn.hxp.weidith.TabFragmentPagerAdapter;
  62. public class InquiryActivity extends BaseActivity {
  63. private TimeUpdater timeUpdater;
  64. private int logIn = 0;
  65. private UsbReceiver mUsbReceiver;
  66. private boolean mHandleScanEvent = false;
  67. private CabinetDoorAdapter mAdapterLeft;
  68. private CabinetDoorRighAdapter mAdapterRigh;
  69. private SwipeViewPager viewPager;
  70. private TabFragmentPagerAdapter pagerAdapter;
  71. private int mLeftPosition = 0;
  72. private List<LockVoListBean> mCabinetLockVoList;
  73. private ArrayList<String> mLockStr = new ArrayList<>();
  74. private final HandlerUtil handlerUtil = HandlerUtil.Companion.getInstance();
  75. private String mCabinetId;
  76. private String mCabinetName;
  77. private String mDoorId;
  78. private String mDoorName;
  79. private List<String> faceList;
  80. private String mLoginType;
  81. private ActivityInquiryBinding viewBinding;
  82. private CountDownTimer countdownTimer;
  83. private final Runnable task = new Runnable() {
  84. @Override
  85. public void run() {
  86. if (mCabinetLockVoList != null) {
  87. boolean containsFalse = false;
  88. for (LockVoListBean it : mCabinetLockVoList) {
  89. if (!it.isOk() && it.getUnlockingMethod() == 2) {
  90. containsFalse = true;
  91. break;
  92. }
  93. }
  94. if (containsFalse) {
  95. getLocks();
  96. } else {
  97. dismissLoading();
  98. customDialogView(1, "柜门已开");
  99. AudioPlayer.getInstance().play(R.raw.gui_men_yi_kai);
  100. handlerUtil.stopAllTasks();
  101. if (countdownTimer != null) {
  102. countdownTimer.cancel();
  103. }
  104. }
  105. }
  106. }
  107. };
  108. private final PortScanHelper mPortScanHelper = new PortScanHelper(this, new OnSerialScanListener() {
  109. @Override
  110. public void dispatchScanEvent(ScanType type, String content) {
  111. if (!mHandleScanEvent && content != null && !content.isEmpty()) {
  112. mHandleScanEvent = true;
  113. if (content.startsWith("http")) {
  114. try {
  115. LogUtils.i("=======查询扫码 " + content);
  116. String currentDateTimeString = BigDecimalUtils.INSTANCE.extractParameterValue(content, "code");
  117. LogUtils.i("=======查询扫码 " + currentDateTimeString);
  118. handleScanEvent(currentDateTimeString);
  119. } catch (Exception e) {
  120. mHandleScanEvent = false;
  121. showToast("扫描异常,请重操作");
  122. }
  123. } else {
  124. handleScanEvent(content);
  125. }
  126. }
  127. }
  128. });
  129. private void initData() {
  130. logIn = getIntent().getIntExtra("logIn", 0);
  131. String stringExtra = getIntent().getStringExtra("cabinetId");
  132. String stringExtra1 = getIntent().getStringExtra("doorId");
  133. if (stringExtra != null && !"a".equals(stringExtra)) {
  134. mCabinetId = stringExtra;
  135. mDoorId = stringExtra1;
  136. viewBinding.tvReturn.setText("返回" + ChemicalApp.confs.getBackTime() + "s");
  137. }
  138. EventBus.getDefault().register(this);
  139. viewBinding.tvLogin.setOnClickListener(new ClickUtils.OnDebouncingClickListener() {
  140. @Override
  141. public void onDebouncingClick(View v) {
  142. try {
  143. HttpTool.logout();
  144. } catch (Exception e) {
  145. LogUtils.e(e.getMessage());
  146. }
  147. }
  148. });
  149. if (logIn == 1) {
  150. viewBinding.loggedIn.setVisibility(View.VISIBLE);
  151. viewBinding.tvName.setText(ChemicalApp.userData.getUserName());
  152. viewBinding.relOne.setVisibility(View.GONE);
  153. getCabinet(ChemicalApp.subjectId);
  154. fragmentInView();
  155. inAdapter();
  156. } else {
  157. mLoginType = ChemicalApp.confs.getLoginType();
  158. viewBinding.loggedIn.setVisibility(View.GONE);
  159. viewBinding.tvName.setVisibility(View.GONE);
  160. }
  161. viewBinding.logIn.setOnClickListener(new ClickUtils.OnDebouncingClickListener() {
  162. @Override
  163. public void onDebouncingClick(View v) {
  164. getUserIds();
  165. }
  166. });
  167. initTitle();
  168. viewBinding.tvReturn.setOnClickListener(new ClickUtils.OnDebouncingClickListener() {
  169. @Override
  170. public void onDebouncingClick(View v) {
  171. finish();
  172. }
  173. });
  174. viewBinding.butOpen.setOnClickListener(new ClickUtils.OnDebouncingClickListener() {
  175. @Override
  176. public void onDebouncingClick(View v) {
  177. if (ChemicalApp.administrators || ChemicalApp.responsibles) {
  178. if (mCabinetLockVoList != null && !mCabinetLockVoList.isEmpty()) {
  179. mLockStr.clear();
  180. for (LockVoListBean it : mCabinetLockVoList) {
  181. if (it.getUnlockingMethod() == 2) {
  182. mLockStr.add(it.getLockNum());
  183. }
  184. }
  185. if (!mLockStr.isEmpty()) {
  186. openLock(mLockStr);
  187. } else {
  188. customDialogView(1, "柜门已开");
  189. }
  190. } else {
  191. customDialogView(1, "柜门已开");
  192. }
  193. } else {
  194. showToast("无权限信息");
  195. }
  196. }
  197. });
  198. Handler handler = new Handler(Looper.getMainLooper());
  199. timeUpdater = new TimeUpdater(handler, new Function1<String, Unit>() {
  200. @Override
  201. public Unit invoke(String s) {
  202. viewBinding.nowTime.setText(s);
  203. return null;
  204. }
  205. });
  206. timeUpdater.startUpdating();
  207. }
  208. private void initTitle() {
  209. if (ChemicalApp.userData != null) {
  210. viewBinding.logIn.setVisibility(View.GONE);
  211. viewBinding.tvName.setText(ChemicalApp.userData.getUserName());
  212. Glide.with(this)
  213. .load(HttpConfig.Companion.getAPI_BASE_IMG_URL() + ChemicalApp.userData.getAvatar())
  214. .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.AUTOMATIC))
  215. .into(viewBinding.imageName);
  216. }
  217. viewBinding.deptName.setText(ChemicalApp.confs.getDeptName() + "-" + ChemicalApp.confs.getRoomNum());
  218. Glide.with(this)
  219. .load(HttpConfig.Companion.getAPI_BASE_IMG_URL() + ChemicalApp.confs.getCircularLogo())
  220. .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.AUTOMATIC))
  221. .into(viewBinding.image);
  222. }
  223. private void fragmentInView() {
  224. List<BaseFragment> tabArray = new ArrayList<>();
  225. tabArray.add(QueryOneFragment.Companion.newInstance());
  226. tabArray.add(QueryTwoFragment.Companion.newInstance());
  227. pagerAdapter = new TabFragmentPagerAdapter(getSupportFragmentManager(), tabArray);
  228. viewPager = viewBinding.swipePagerView;
  229. viewPager.setAdapter(pagerAdapter);
  230. }
  231. private void inAdapter() {
  232. mAdapterLeft = new CabinetDoorAdapter(this);
  233. mAdapterRigh = new CabinetDoorRighAdapter(this);
  234. viewBinding.recyclerViewListLeft.setLayoutManager(new LinearLayoutManager(this));
  235. viewBinding.recyclerViewListLeft.setAdapter(mAdapterLeft);
  236. viewBinding.recyclerViewListRight.setLayoutManager(new LinearLayoutManager(this));
  237. viewBinding.recyclerViewListRight.setAdapter(mAdapterRigh);
  238. mAdapterLeft.setOnItemClickListener((adapter, view, position) -> {
  239. mLeftPosition = position;
  240. for (int i = 0; i < mAdapterLeft.getData().size(); i++) {
  241. mAdapterLeft.getData().get(i).setType(i == position);
  242. }
  243. for (int i = 0; i < mAdapterRigh.getData().size(); i++) {
  244. mAdapterRigh.getData().get(i).setType(false);
  245. }
  246. mAdapterLeft.notifyDataSetChanged();
  247. if (mAdapterLeft.getData().get(mLeftPosition).getCabinetDoorVoList() != null) {
  248. mCabinetId = mAdapterLeft.getData().get(mLeftPosition).getCabinetId();
  249. mCabinetName = mAdapterLeft.getData().get(mLeftPosition).getCabinetName();
  250. mAdapterRigh.setNewInstance(mAdapterLeft.getData().get(mLeftPosition).getCabinetDoorVoList());
  251. }
  252. });
  253. mAdapterRigh.setOnItemClickListener((adapter, view, position) -> {
  254. mDoorId = mAdapterRigh.getData().get(position).getDoorUniqueId();
  255. mDoorName = mAdapterRigh.getData().get(position).getDoorName();
  256. mCabinetLockVoList = mAdapterRigh.getData().get(position).getCabinetLockVoList();
  257. for (int i = 0; i < mAdapterRigh.getData().size(); i++) {
  258. mAdapterRigh.getData().get(i).setType(i == position);
  259. }
  260. mAdapterRigh.notifyDataSetChanged();
  261. goQueryTwoFragment();
  262. if (mCabinetLockVoList != null && !mCabinetLockVoList.isEmpty()) {
  263. boolean isLock = false;
  264. for (LockVoListBean it : mCabinetLockVoList) {
  265. if (it.getUnlockingMethod() == 2) {
  266. isLock = true;
  267. break;
  268. }
  269. }
  270. if (ChemicalApp.userData != null && ChemicalApp.userData.getUserValidationBean() != null) {
  271. if (isLock) {
  272. boolean canOpen = ChemicalApp.userData.getUserValidationBean().getCabinetAdmin() ||
  273. ChemicalApp.userData.getUserValidationBean().getSafeUser() ||
  274. ChemicalApp.userData.getUserValidationBean().getCabinetAdmin();
  275. viewBinding.butOpen.setVisibility(canOpen ? View.VISIBLE : View.GONE);
  276. } else {
  277. viewBinding.butOpen.setVisibility(View.GONE);
  278. }
  279. } else {
  280. viewBinding.butOpen.setVisibility(isLock ? View.VISIBLE : View.GONE);
  281. }
  282. }
  283. });
  284. }
  285. private void getCabinet(String subId) {
  286. showLoading("查询中...");
  287. addDisposable(ApiRepository.INSTANCE.getCabinetList(subId).subscribe(
  288. data -> {
  289. dismissLoading();
  290. mAdapterLeft.setNewInstance(data);
  291. if (mCabinetId != null) {
  292. for (int i = 0; i < mAdapterLeft.getData().size(); i++) {
  293. if (mCabinetId.equals(mAdapterLeft.getData().get(i).getCabinetId())) {
  294. RuleBean cabinetId = mAdapterLeft.getData().get(i);
  295. cabinetId.setType(true);
  296. mAdapterRigh.setNewInstance(cabinetId.getCabinetDoorVoList());
  297. for (int j = 0; j < mAdapterRigh.getData().size(); j++) {
  298. if (mDoorId.equals(mAdapterRigh.getData().get(j).getDoorUniqueId())) {
  299. mAdapterRigh.getData().get(j).setType(true);
  300. break;
  301. }
  302. }
  303. break;
  304. }
  305. }
  306. } else {
  307. mAdapterRigh.setNewInstance(data.get(0).getCabinetDoorVoList());
  308. mCabinetId = mAdapterLeft.getData().get(0).getCabinetId();
  309. mCabinetName = mAdapterLeft.getData().get(0).getCabinetName();
  310. mAdapterLeft.getData().get(0).setType(true);
  311. mDoorId = mAdapterRigh.getData().get(0).getDoorUniqueId();
  312. mDoorName = mAdapterRigh.getData().get(0).getDoorName();
  313. mAdapterRigh.getData().get(0).setType(true);
  314. mCabinetLockVoList = mAdapterLeft.getData().get(0).getCabinetDoorVoList().get(0).getCabinetLockVoList();
  315. if (mCabinetLockVoList != null && !mCabinetLockVoList.isEmpty()) {
  316. boolean isLock = false;
  317. for (LockVoListBean it : mCabinetLockVoList) {
  318. if (it.getUnlockingMethod() == 2) {
  319. isLock = true;
  320. break;
  321. }
  322. }
  323. if (ChemicalApp.userData != null && ChemicalApp.userData.getUserValidationBean() != null) {
  324. boolean canOpen = ChemicalApp.userData.getUserValidationBean().getCabinetAdmin() ||
  325. ChemicalApp.userData.getUserValidationBean().getSafeUser() ||
  326. ChemicalApp.userData.getUserValidationBean().getAdminUser();
  327. viewBinding.butOpen.setVisibility(isLock && canOpen ? View.VISIBLE : View.GONE);
  328. } else {
  329. viewBinding.butOpen.setVisibility(isLock ? View.VISIBLE : View.GONE);
  330. }
  331. }
  332. }
  333. goQueryTwoFragment();
  334. },
  335. throwable -> {
  336. dismissLoading();
  337. showNetError(throwable);
  338. }
  339. ));
  340. }
  341. public void goQueryTwoFragment(String stockId, HxpStockWaitListBean hxpStockWaitListBean) {
  342. QueryTwoFragment secondFragment = (QueryTwoFragment) pagerAdapter.getItem(1);
  343. secondFragment.setData(stockId, hxpStockWaitListBean, mCabinetId, mDoorId);
  344. viewPager.setCurrentItem(1);
  345. }
  346. private void goQueryTwoFragment() {
  347. QueryOneFragment secondFragment = (QueryOneFragment) pagerAdapter.getItem(0);
  348. secondFragment.upDatas(mCabinetId, mDoorId);
  349. viewPager.setCurrentItem(0);
  350. }
  351. private void handleScanEvent(String cont) {
  352. if (logIn == 1) {
  353. showLoading("查询中...");
  354. ApiRepository.INSTANCE.getStockDetailsByCode(cont).subscribe(
  355. data -> {
  356. dismissLoading();
  357. upViewTwo(data);
  358. },
  359. throwable -> {
  360. dismissLoading();
  361. showNetError(throwable);
  362. mHandleScanEvent = false;
  363. }
  364. );
  365. } else {
  366. showLoading("查询中...");
  367. ApiRepository.INSTANCE.indexDetailbyRfid(cont).subscribe(
  368. data -> {
  369. dismissLoading();
  370. upView(data);
  371. },
  372. throwable -> {
  373. dismissLoading();
  374. showNetError(throwable);
  375. mHandleScanEvent = false;
  376. }
  377. );
  378. }
  379. }
  380. private void upView(UseNoBean data) {
  381. PromptDialog proDialog = new PromptDialog(this, data);
  382. if (!this.isFinishing() && !this.isDestroyed()) {
  383. proDialog.show();
  384. }
  385. mHandleScanEvent = false;
  386. }
  387. private void upViewTwo(UseNoTwoBean data) {
  388. ScanCodeDialog scanCodeDialog = new ScanCodeDialog(this, data);
  389. if (!this.isFinishing() && !this.isDestroyed()) {
  390. scanCodeDialog.show();
  391. }
  392. mHandleScanEvent = false;
  393. }
  394. private void registerUsbBroadcast() {
  395. if (mUsbReceiver == null) {
  396. IntentFilter filter = new IntentFilter();
  397. filter.addAction(UsbReceiver.ACTION_USB_PERMISSION);
  398. filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
  399. filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
  400. filter.addAction(UsbReceiver.ACTION_USB_STATE);
  401. mUsbReceiver = new UsbReceiver();
  402. registerReceiver(mUsbReceiver, filter);
  403. }
  404. }
  405. @Override
  406. protected void onResume() {
  407. super.onResume();
  408. mPortScanHelper.onResume();
  409. registerUsbBroadcast();
  410. }
  411. @Override
  412. public boolean dispatchKeyEvent(KeyEvent event) {
  413. mPortScanHelper.dispatchKeyEvent(event);
  414. return super.dispatchKeyEvent(event);
  415. }
  416. @Override
  417. protected void onPause() {
  418. mPortScanHelper.onPause();
  419. super.onPause();
  420. }
  421. @Override
  422. protected ViewBinding setViewBinding() {
  423. return viewBinding = ActivityInquiryBinding.inflate(getLayoutInflater());
  424. }
  425. @Override
  426. protected void onInit() {
  427. initData();
  428. }
  429. @Override
  430. protected void onDestroy() {
  431. mPortScanHelper.onPause();
  432. try {
  433. handlerUtil.stopAllTasks();
  434. if (countdownTimer != null) {
  435. countdownTimer.cancel();
  436. }
  437. } catch (Exception e) {
  438. e.printStackTrace();
  439. }
  440. try {
  441. timeUpdater.stopUpdating();
  442. } catch (Exception e) {
  443. e.printStackTrace();
  444. }
  445. unregisterReceiver(mUsbReceiver);
  446. EventBus.getDefault().unregister(this);
  447. super.onDestroy();
  448. }
  449. @Override
  450. public void cdFinish() {
  451. finish();
  452. }
  453. @Subscribe(threadMode = ThreadMode.MAIN)
  454. public void onUpdateEventEvent(KeyEvent event) {
  455. // EventBus event handler
  456. }
  457. @Override
  458. public void onBackPressed() {
  459. super.onBackPressed();
  460. finish();
  461. }
  462. @Override
  463. public void cdTime(int cd) {
  464. viewBinding.tvReturn.setText("返回" + cd + "s");
  465. }
  466. private void openLock(ArrayList<String> mLockStr) {
  467. Map<String, Object> map = new HashMap<>();
  468. map.put("subId", ChemicalApp.subjectId);
  469. map.put("subName", ChemicalApp.subjectName);
  470. map.put("cabinetId", mCabinetId);
  471. map.put("cabinetName", mCabinetName);
  472. map.put("doorId", mDoorId);
  473. map.put("doorName", mDoorName);
  474. map.put("lockNumList", mLockStr);
  475. map.put("operationType", 6);
  476. if (ChemicalApp.subRoom != null) {
  477. map.put("subRoom", ChemicalApp.subRoom);
  478. }
  479. map.put("type", true);
  480. try {
  481. List<DoubleDialogBean> retrievedList = SharedPreferencesHelper.INSTANCE.getList(this);
  482. if (retrievedList != null && retrievedList.size() > 1) {
  483. map.put("oneUserId", retrievedList.get(0).getUserId());
  484. map.put("oneUserName", retrievedList.get(0).getName());
  485. map.put("twoUserId", retrievedList.get(1).getUserId());
  486. map.put("twoUserName", retrievedList.get(1).getName());
  487. }
  488. } catch (Exception e) {
  489. e.printStackTrace();
  490. }
  491. showLoading("加载中...");
  492. ApiRepository.INSTANCE.lockOperate(map).subscribe(
  493. data -> {
  494. dismissLoading();
  495. if (mCabinetLockVoList != null) {
  496. boolean containsFalse = false;
  497. for (LockVoListBean it : mCabinetLockVoList) {
  498. if (!it.isOk() && it.getUnlockingMethod() == 2) {
  499. containsFalse = true;
  500. break;
  501. }
  502. }
  503. if (containsFalse) {
  504. showLoading("查询中...");
  505. startCountdownLock();
  506. handlerUtil.startTask(task, 1000);
  507. }
  508. }
  509. },
  510. throwable -> {
  511. dismissLoading();
  512. showNetError(throwable);
  513. }
  514. );
  515. }
  516. private void startCountdownLock() {
  517. countdownTimer = new CountDownTimer(30000, 1000) {
  518. @Override
  519. public void onTick(long millisUntilFinished) {
  520. long secondsLeft = millisUntilFinished / 1000;
  521. System.out.println("剩余时间: " + secondsLeft + " 秒");
  522. }
  523. @Override
  524. public void onFinish() {
  525. System.out.println("倒计时结束!");
  526. mCabinetLockVoList = null;
  527. mLockStr.clear();
  528. showToast("开锁超时,可重新操作");
  529. dismissLoading();
  530. handlerUtil.stopAllTasks();
  531. }
  532. };
  533. countdownTimer.start();
  534. }
  535. private void getLocks() {
  536. for (int i = 0; i < mCabinetLockVoList.size(); i++) {
  537. LockVoListBean fruit = mCabinetLockVoList.get(i);
  538. if (!fruit.isOk() && fruit.getUnlockingMethod() == 2) {
  539. getLocksDate(i, fruit.getLockNum());
  540. }
  541. }
  542. }
  543. private void getLocksDate(int index, String fruit) {
  544. ApiRepository.INSTANCE.getLocks(ChemicalApp.subjectId, fruit).subscribe(
  545. data -> {
  546. if (data) {
  547. mCabinetLockVoList.get(index).setOk(true);
  548. }
  549. },
  550. throwable -> {
  551. dismissLoading();
  552. showNetError(throwable);
  553. }
  554. );
  555. }
  556. private void customDialogView(int types, String msg) {
  557. CustomDialog customDialog = new CustomDialog(this, types, msg);
  558. if (!this.isFinishing() && !this.isDestroyed()) {
  559. customDialog.show();
  560. }
  561. }
  562. private void getUserIds() {
  563. if (ChemicalApp.subjectId != null) {
  564. showLoading("查询中...");
  565. ApiRepository.INSTANCE.getUserIds(ChemicalApp.subjectId).subscribe(
  566. data -> {
  567. dismissLoading();
  568. faceList = data;
  569. getLogin();
  570. },
  571. throwable -> {
  572. dismissLoading();
  573. }
  574. );
  575. }
  576. }
  577. private void getLogin() {
  578. if (mLoginType == null) {
  579. customDialogView(2, "登录方式配置有误");
  580. } else {
  581. finish();
  582. if (mLoginType.contains("4")) {
  583. UiManager.INSTANCE.switcher(this, FacialCardActivity.class);
  584. } else {
  585. Map<String, String> map = new HashMap<>();
  586. if (mLoginType.length() == 1) {
  587. switch (mLoginType) {
  588. case "1":
  589. map.put("faceList", faceList.toString());
  590. map.put("mtypes", "1");
  591. UiManager.INSTANCE.switcher(this, map, FaceLoginActivity.class);
  592. break;
  593. case "2":
  594. map.put("mtypes", "1");
  595. UiManager.INSTANCE.switcher(this, map, SwipeActivity.class);
  596. break;
  597. default:
  598. map.put("mtypes", "1");
  599. UiManager.INSTANCE.switcher(this, map, ScanLoginActivity.class);
  600. break;
  601. }
  602. } else {
  603. String[] array = mLoginType.split(",");
  604. if (array.length == 2) {
  605. if ("1,2".equals(mLoginType) || "2,1".equals(mLoginType)) {
  606. map.put("faceList", faceList.toString());
  607. map.put("mtypes", "4");
  608. UiManager.INSTANCE.switcher(this, map, FaceLoginActivity.class);
  609. } else if ("1,3".equals(mLoginType) || "3,1".equals(mLoginType)) {
  610. map.put("faceList", faceList.toString());
  611. map.put("mtypes", "5");
  612. UiManager.INSTANCE.switcher(this, map, FaceLoginActivity.class);
  613. } else if ("2,3".equals(mLoginType) || "3,2".equals(mLoginType)) {
  614. map.put("mtypes", "6");
  615. UiManager.INSTANCE.switcher(this, map, SwipeActivity.class);
  616. } else {
  617. showToast("登录方式" + mLoginType);
  618. }
  619. } else {
  620. try {
  621. map.put("mtypes", "0");
  622. map.put("faceList", faceList.toString());
  623. UiManager.INSTANCE.switcher(this, map, FaceLoginActivity.class);
  624. } catch (Exception e) {
  625. map.put("mtypes", "0");
  626. UiManager.INSTANCE.switcher(this, map, SwipeActivity.class);
  627. }
  628. }
  629. }
  630. }
  631. }
  632. }
  633. }