MainActivity.java 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. package xn.hxp.ui;
  2. import android.app.AlertDialog;
  3. import android.content.Intent;
  4. import android.content.IntentFilter;
  5. import android.graphics.Bitmap;
  6. import android.graphics.Color;
  7. import android.graphics.drawable.GradientDrawable;
  8. import android.hardware.usb.UsbManager;
  9. import android.os.AsyncTask;
  10. import android.os.Bundle;
  11. import android.os.CountDownTimer;
  12. import android.os.Handler;
  13. import android.os.Looper;
  14. import android.os.Message;
  15. import android.text.TextUtils;
  16. import android.util.Log;
  17. import android.view.KeyEvent;
  18. import android.view.View;
  19. import android.widget.EditText;
  20. import androidx.recyclerview.widget.LinearLayoutManager;
  21. import androidx.recyclerview.widget.RecyclerView;
  22. import androidx.viewbinding.ViewBinding;
  23. import com.blankj.utilcode.util.ActivityUtils;
  24. import com.blankj.utilcode.util.AppUtils;
  25. import com.blankj.utilcode.util.LogUtils;
  26. import com.blankj.utilcode.util.SPUtils;
  27. import com.bumptech.glide.Glide;
  28. import com.bumptech.glide.load.engine.DiskCacheStrategy;
  29. import com.bumptech.glide.request.RequestOptions;
  30. import com.king.zxing.util.CodeUtils;
  31. import com.kongzue.dialogx.dialogs.PopTip;
  32. import com.lztek.toolkit.Lztek;
  33. import com.rc.core.ui.activity.BaseActivity;
  34. import com.rc.httpcore.HttpClient;
  35. import com.rc.httpcore.HttpConfig;
  36. import com.rc.httpcore.client.ApiRepository;
  37. import com.rc.httpcore.client.HttpTool;
  38. import com.rc.httpcore.exception.NetException;
  39. import java.net.ConnectException;
  40. import java.net.SocketTimeoutException;
  41. import java.util.ArrayList;
  42. import java.util.HashMap;
  43. import java.util.List;
  44. import java.util.Map;
  45. import io.reactivex.rxjava3.functions.Consumer;
  46. import kotlin.Unit;
  47. import kotlin.jvm.functions.Function1;
  48. import retrofit2.HttpException;
  49. import xn.hxp.R;
  50. import xn.hxp.app.ChemicalApp;
  51. import xn.hxp.databinding.ActivityMainBinding;
  52. import xn.hxp.receiver.TimeTickReceiver;
  53. import xn.hxp.receiver.UsbReceiver;
  54. import xn.hxp.ui.adapter.CabinetAdapter;
  55. import xn.hxp.ui.discard.LedgerActivity;
  56. import xn.hxp.ui.discard.WasteChemicalsActivity;
  57. import xn.hxp.ui.inquiry.InquiryActivity;
  58. import xn.hxp.ui.login.FaceLoginActivity;
  59. import xn.hxp.ui.login.FacialCardActivity;
  60. import xn.hxp.ui.login.ScanLoginActivity;
  61. import xn.hxp.ui.login.SwipeActivity;
  62. import xn.hxp.ui.plan.PlanAddActivity;
  63. import xn.hxp.ui.plan.already.AlreadyActivity;
  64. import xn.hxp.ui.still.ChemicalsAlsoActivity;
  65. import xn.hxp.ui.still.MsdsActivity;
  66. import xn.hxp.ui.uses.UseActivity;
  67. import xn.hxp.ui.uses.WarningEventsActivity;
  68. import xn.hxp.ui.warehousing.ChemicalLabelingActivity;
  69. import xn.hxp.utils.RelativeLayoutDebouncer;
  70. import xn.hxp.utils.SharedPreferencesHelper;
  71. import xn.hxp.utils.TimeUpdater;
  72. import xn.hxp.utils.UiManager;
  73. import xn.hxp.weidith.CustomDialog;
  74. import xn.hxp.weidith.PlanDialog;
  75. public class MainActivity extends BaseActivity {
  76. private ActivityMainBinding viewBinding;
  77. private TimeUpdater timeUpdater;
  78. private CabinetAdapter mAdapter;
  79. private int currentPosition = 0;
  80. private RecyclerView recyclerView;
  81. private UsbReceiver mUsbReceiver;
  82. private Lztek mLztek;
  83. private String mDeviceNum;
  84. private List<String> faceList;
  85. private String mLoginType;
  86. private int mCounter = 0;
  87. private int MAX_TIME = 60;
  88. private static final int WHAT_COUNT_DOWN = 1;
  89. private LinearLayoutManager layoutManager;
  90. private Handler handlerBanner;
  91. private Runnable updateRunnable;
  92. private boolean isUpdating = false;
  93. private TimeTickReceiver timeTickReceiver = new TimeTickReceiver();
  94. private PlanDialog planDialog;
  95. private CountDownTimer heartbeatCdTimer;
  96. @Override
  97. protected void onResume() {
  98. super.onResume();
  99. if (ChemicalApp.userData != null) {
  100. viewBinding.inc.userLogin.setVisibility(View.GONE);
  101. viewBinding.inc.loggedIn.setVisibility(View.VISIBLE);
  102. viewBinding.inc.tvName.setText(ChemicalApp.userData.userName);
  103. Glide.with(this)
  104. .load(HttpConfig.Companion.getAPI_BASE_IMG_URL() + ChemicalApp.userData.avatar)
  105. .apply(new RequestOptions().diskCacheStrategy(DiskCacheStrategy.AUTOMATIC))
  106. .into(viewBinding.inc.imageName);
  107. viewBinding.inc.imgE.setBackgroundResource(R.mipmap.cshrk_dl_tc);
  108. MAX_TIME = ChemicalApp.confs.getSignOutTime();
  109. mCountDownHandler.removeMessages(WHAT_COUNT_DOWN);
  110. mCountDownHandler.sendEmptyMessage(WHAT_COUNT_DOWN);
  111. } else {
  112. viewBinding.inc.loggedIn.setVisibility(View.GONE);
  113. viewBinding.inc.userLogin.setVisibility(View.VISIBLE);
  114. viewBinding.inc.imgE.setBackgroundResource(R.mipmap.icon_login_img);
  115. }
  116. if (mAdapter.getData() != null && mAdapter.getData().size() > 1) {
  117. startUpdating();
  118. }
  119. timeUpdater.startUpdating();
  120. getCabinetIn();
  121. basicConf();
  122. }
  123. @Override
  124. protected void onCreate(Bundle savedInstanceState) {
  125. super.onCreate(savedInstanceState);
  126. registerReceiver(timeTickReceiver, new IntentFilter(Intent.ACTION_TIME_TICK));
  127. viewBinding.versionName.setText("版本号:" + AppUtils.getAppVersionName());
  128. viewBinding.test.setOnClickListener(new View.OnClickListener() {
  129. @Override
  130. public void onClick(View v) {
  131. if (!AppUtils.isAppDebug()) {
  132. showTextInputDialog("请输入内容", new TextInputCallback() {
  133. @Override
  134. public void onInput(String input) {
  135. if (input != null) {
  136. if (!input.isEmpty()) {
  137. try {
  138. if ("admin@098&".equals(input)) {
  139. ActivityUtils.startActivity(SettingActivity.class);
  140. finish();
  141. } else {
  142. SettingsBean urlBase = SharedPreferencesHelper.INSTANCE.getUrlBase(MainActivity.this);
  143. if (urlBase != null && urlBase.getPwd() != null) {
  144. if (input.equals(urlBase.getPwd())) {
  145. ActivityUtils.startActivity(SettingActivity.class);
  146. finish();
  147. } else {
  148. showToast("密码错误");
  149. }
  150. }
  151. }
  152. } catch (Exception e) {
  153. ActivityUtils.startActivity(SettingActivity.class);
  154. finish();
  155. }
  156. }
  157. } else {
  158. showToast("用户取消了输入");
  159. }
  160. }
  161. });
  162. } else {
  163. ActivityUtils.startActivity(SettingActivity.class);
  164. finish();
  165. }
  166. }
  167. });
  168. viewBinding.inc.bleIV.setVisibility(View.VISIBLE);
  169. String sppMac = SPUtils.getInstance().getString("sppMac", "");
  170. if (sppMac == null || TextUtils.isEmpty(sppMac)) {
  171. viewBinding.inc.bleIV.setBackgroundResource(R.drawable.ic_ble_unconnected);
  172. PopTip.show("未配置蓝牙称设备!").showLong();
  173. }
  174. // 心跳上报
  175. heartbeatCdTimer = new CountDownTimer(20000, 1000) {
  176. @Override
  177. public void onTick(long millisUntilFinished) {
  178. }
  179. @Override
  180. public void onFinish() {
  181. AsyncTask.execute(() -> {
  182. try {
  183. HttpTool.heartbeat();
  184. } catch (Exception e) {
  185. LogUtils.e(Log.getStackTraceString(e));
  186. }
  187. });
  188. heartbeatCdTimer.start();
  189. }
  190. };
  191. heartbeatCdTimer.start();
  192. }
  193. @Override
  194. public boolean dispatchKeyEvent(KeyEvent event) {
  195. return super.dispatchKeyEvent(event);
  196. }
  197. @Override
  198. protected void onStop() {
  199. super.onStop();
  200. LogUtils.i("============onStop");
  201. }
  202. @Override
  203. protected void onPause() {
  204. LogUtils.i("============onPause");
  205. try {
  206. stopUpdating();
  207. timeUpdater.stopUpdating();
  208. LogUtils.i("========UI在刷新停止");
  209. mCountDownHandler.removeMessages(WHAT_COUNT_DOWN);
  210. mCountDownHandler.removeCallbacksAndMessages(null);
  211. } catch (Exception e) {
  212. }
  213. super.onPause();
  214. }
  215. @Override
  216. protected void onNewIntent(Intent intent) {
  217. super.onNewIntent(intent);
  218. }
  219. private void getCabinetIn() {
  220. showLoading("查询中...");
  221. ApiRepository.INSTANCE.getCabinetBySubId(ChemicalApp.subjectId)
  222. .subscribe(data -> {
  223. dismissLoading();
  224. mAdapter.setNewInstance(new ArrayList<>(data));
  225. if (mAdapter.getData() != null && mAdapter.getData().size() > 1) {
  226. handlerBanner = new Handler(Looper.getMainLooper());
  227. updateRunnable = new Runnable() {
  228. @Override
  229. public void run() {
  230. int currentPosition = layoutManager.findFirstVisibleItemPosition();
  231. if (currentPosition != RecyclerView.NO_POSITION) {
  232. int nextPosition = (currentPosition + 1) % mAdapter.getItemCount();
  233. recyclerView.smoothScrollToPosition(nextPosition);
  234. }
  235. if (isUpdating) {
  236. handlerBanner.postDelayed(this, 5000);
  237. }
  238. }
  239. };
  240. startUpdating();
  241. }
  242. }, throwable -> {
  243. dismissLoading();
  244. throwable.printStackTrace();
  245. });
  246. }
  247. private void getUserIds() {
  248. if (ChemicalApp.subjectId != null) {
  249. showLoading("查询中...");
  250. ApiRepository.INSTANCE.getUserIds(ChemicalApp.subjectId)
  251. .subscribe(data -> {
  252. dismissLoading();
  253. faceList = data;
  254. }, throwable -> {
  255. dismissLoading();
  256. });
  257. }
  258. }
  259. private void initAdapter() {
  260. recyclerView = viewBinding.relView;
  261. layoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
  262. recyclerView.setLayoutManager(layoutManager);
  263. recyclerView.setAdapter(mAdapter);
  264. recyclerView.setOnTouchListener((v, event) -> true);
  265. mAdapter.setOnItemChildClickListener((adapter, view, position) -> {
  266. if (ChemicalApp.userData != null) {
  267. Map<String, Object> map = new HashMap<>();
  268. map.put("logIn", 1);
  269. if (view.getId() == R.id.lingOne) {
  270. map.put("cabinetId", mAdapter.getData().get(position).getCabinetId());
  271. map.put("doorId", mAdapter.getData().get(position).getCabinetDoorVoList().get(0).getDoorUniqueId());
  272. UiManager.INSTANCE.switcher(this, map, InquiryActivity.class);
  273. } else if (view.getId() == R.id.lintTwo) {
  274. map.put("cabinetId", mAdapter.getData().get(position).getCabinetDoorVoList().get(1).getCabinetId());
  275. map.put("doorId", mAdapter.getData().get(position).getCabinetDoorVoList().get(1).getDoorUniqueId());
  276. UiManager.INSTANCE.switcher(this, map, InquiryActivity.class);
  277. } else if (view.getId() == R.id.lintThree) {
  278. map.put("cabinetId", mAdapter.getData().get(position).getCabinetDoorVoList().get(2).getCabinetId());
  279. map.put("doorId", mAdapter.getData().get(position).getCabinetDoorVoList().get(2).getDoorUniqueId());
  280. UiManager.INSTANCE.switcher(this, map, InquiryActivity.class);
  281. } else if (view.getId() == R.id.lintFour) {
  282. map.put("cabinetId", mAdapter.getData().get(position).getCabinetDoorVoList().get(3).getCabinetId());
  283. map.put("doorId", mAdapter.getData().get(position).getCabinetDoorVoList().get(3).getDoorUniqueId());
  284. UiManager.INSTANCE.switcher(this, map, InquiryActivity.class);
  285. } else if (view.getId() == R.id.imgViews) {
  286. map.put("cabinetId", "a");
  287. map.put("doorId", "a");
  288. UiManager.INSTANCE.switcher(this, map, InquiryActivity.class);
  289. }
  290. } else {
  291. basicConfLog();
  292. }
  293. });
  294. }
  295. private void startUpdating() {
  296. if (!isUpdating) {
  297. isUpdating = true;
  298. handlerBanner.post(updateRunnable);
  299. }
  300. }
  301. private void stopUpdating() {
  302. if (isUpdating) {
  303. isUpdating = false;
  304. handlerBanner.removeCallbacks(updateRunnable);
  305. }
  306. }
  307. private void handleScanEvent(String cont) {
  308. // Implementation remains similar to Kotlin version
  309. }
  310. private void registerUsbBroadcast() {
  311. if (mUsbReceiver == null) {
  312. IntentFilter filter = new IntentFilter();
  313. filter.addAction(UsbReceiver.ACTION_USB_PERMISSION);
  314. filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
  315. filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
  316. filter.addAction(UsbReceiver.ACTION_USB_STATE);
  317. mUsbReceiver = new UsbReceiver();
  318. registerReceiver(mUsbReceiver, filter);
  319. }
  320. }
  321. @Override
  322. protected void onDestroy() {
  323. super.onDestroy();
  324. unregisterReceiver(timeTickReceiver);
  325. try {
  326. timeUpdater.stopUpdating();
  327. stopUpdating();
  328. mCountDownHandler.removeMessages(WHAT_COUNT_DOWN);
  329. mCountDownHandler.removeCallbacksAndMessages(null);
  330. } catch (Exception e) {
  331. }
  332. }
  333. private void subAddData() {
  334. mLztek = Lztek.create(this);
  335. String toUpperCase = mLztek.getEthMac().toUpperCase();
  336. mDeviceNum = toUpperCase.replace(":", "");
  337. ApiRepository.INSTANCE.monitor(mDeviceNum)
  338. .subscribe(data -> {
  339. }, this::showNetError);
  340. }
  341. private void basicConf() {
  342. ApiRepository.INSTANCE.basicConfig(ChemicalApp.subjectId)
  343. .subscribe(data -> {
  344. ChemicalApp.confs = data;
  345. mLoginType = data.getLoginType();
  346. if (data.getLevelName() != null) {
  347. String result = data.getLevelName().chars()
  348. .mapToObj(c -> String.valueOf((char) c))
  349. .reduce("", (s1, s2) -> s1 + "\n" + s2);
  350. viewBinding.tvNoName.setText(result);
  351. GradientDrawable shapes = new GradientDrawable();
  352. shapes.setShape(GradientDrawable.RECTANGLE);
  353. shapes.setColor(Color.parseColor(data.getLevelColor()));
  354. shapes.setCornerRadius(5f);
  355. viewBinding.tvNoName.setBackground(shapes);
  356. } else {
  357. viewBinding.tvNoName.setVisibility(View.GONE);
  358. }
  359. viewBinding.subName.setText(data.getSubName());
  360. viewBinding.inc.deptName.setText(data.getDeptName());
  361. Glide.with(this)
  362. .load(HttpConfig.Companion.getAPI_BASE_IMG_URL() + data.getCircularLogo())
  363. .apply(new RequestOptions().diskCacheStrategy(DiskCacheStrategy.AUTOMATIC))
  364. .into(viewBinding.inc.circularLogo);
  365. }, this::showNetError);
  366. }
  367. private void basicConfLog() {
  368. ApiRepository.INSTANCE.basicConfig(ChemicalApp.subjectId)
  369. .subscribe(data -> {
  370. LogUtils.json(data);
  371. ChemicalApp.confs = data;
  372. mLoginType = data.getLoginType();
  373. if (mLoginType == null) {
  374. customDialogView(2, "登录方式配置有误");
  375. } else {
  376. if (mLoginType.contains("4")) {
  377. UiManager.INSTANCE.switcher(this, FacialCardActivity.class);
  378. } else {
  379. Map<String, String> map = new HashMap<>();
  380. if (mLoginType.length() == 1) {
  381. switch (mLoginType) {
  382. case "1":
  383. map.put("faceList", faceList.toString());
  384. map.put("mtypes", "1");
  385. UiManager.INSTANCE.switcher(this, map, FaceLoginActivity.class);
  386. break;
  387. case "2":
  388. map.put("mtypes", "1");
  389. UiManager.INSTANCE.switcher(this, map, SwipeActivity.class);
  390. break;
  391. default:
  392. map.put("mtypes", "1");
  393. UiManager.INSTANCE.switcher(this, map, ScanLoginActivity.class);
  394. break;
  395. }
  396. } else {
  397. String[] array = mLoginType.split(",");
  398. if (array.length == 2) {
  399. if (mLoginType.equals("1,2") || mLoginType.equals("2,1")) {
  400. map.put("faceList", faceList.toString());
  401. map.put("mtypes", "4");
  402. UiManager.INSTANCE.switcher(this, map, FaceLoginActivity.class);
  403. } else if (mLoginType.equals("1,3") || mLoginType.equals("3,1")) {
  404. map.put("faceList", faceList.toString());
  405. map.put("mtypes", "5");
  406. UiManager.INSTANCE.switcher(this, map, FaceLoginActivity.class);
  407. } else if (mLoginType.equals("2,3") || mLoginType.equals("3,2")) {
  408. map.put("mtypes", "6");
  409. UiManager.INSTANCE.switcher(this, map, SwipeActivity.class);
  410. } else {
  411. showToast("登录方式" + mLoginType);
  412. }
  413. } else {
  414. try {
  415. map.put("mtypes", "0");
  416. map.put("faceList", faceList.toString());
  417. UiManager.INSTANCE.switcher(this, map, FaceLoginActivity.class);
  418. } catch (Exception e) {
  419. map.put("mtypes", "0");
  420. UiManager.INSTANCE.switcher(this, map, SwipeActivity.class);
  421. }
  422. }
  423. }
  424. }
  425. }
  426. }, this::showNetError);
  427. }
  428. private void customDialogView(int types, String msg) {
  429. CustomDialog customDialog = new CustomDialog(this, types, msg);
  430. if (!this.isFinishing() && !this.isDestroyed()) {
  431. customDialog.show();
  432. }
  433. }
  434. private void throwableView(Throwable throwable) {
  435. String message = null;
  436. if (throwable instanceof NetException) {
  437. message = throwable.getMessage() != null ? throwable.getMessage() :
  438. "接口请求失败(" + ((NetException) throwable).getCode() + ")";
  439. } else if (throwable instanceof SocketTimeoutException) {
  440. message = "请求超时,请稍后重试";
  441. } else if (throwable instanceof ConnectException) {
  442. message = "无法连接服务器,请检查网络";
  443. } else if (throwable instanceof HttpException) {
  444. message = "服务器繁忙,请稍后重试";
  445. }
  446. if (message != null) {
  447. customDialogView(2, message);
  448. }
  449. }
  450. private final Handler mCountDownHandler = new Handler(Looper.getMainLooper()) {
  451. @Override
  452. public void handleMessage(Message msg) {
  453. if (WHAT_COUNT_DOWN == msg.what) {
  454. int countDown = MAX_TIME - mCounter;
  455. if (isDestroyed()) return;
  456. if (countDown <= 0) {
  457. ChemicalApp.confs = null;
  458. ChemicalApp.subjectId = null;
  459. ChemicalApp.userData = null;
  460. callLogoutApis(success -> {
  461. ActivityUtils.startActivity(StartActivity.class);
  462. });
  463. } else {
  464. sendEmptyMessageDelayed(WHAT_COUNT_DOWN, 1000);
  465. }
  466. mCounter++;
  467. }
  468. }
  469. };
  470. @Override
  471. public void onUserInteraction() {
  472. mCounter = 0;
  473. }
  474. @Override
  475. protected void cdFinish() {
  476. }
  477. @Override
  478. protected void cdTime(int cd) {
  479. }
  480. @Override
  481. protected ViewBinding setViewBinding() {
  482. viewBinding = ActivityMainBinding.inflate(getLayoutInflater());
  483. return viewBinding;
  484. }
  485. @Override
  486. protected void onInit() {
  487. getUserIds();
  488. Handler handler = new Handler(Looper.getMainLooper());
  489. timeUpdater = new TimeUpdater(handler, new Function1<String, Unit>() {
  490. @Override
  491. public Unit invoke(String s) {
  492. viewBinding.inc.nowTime.setText(s);
  493. return null;
  494. }
  495. });
  496. timeUpdater.startUpdating();
  497. mAdapter = new CabinetAdapter();
  498. initAdapter();
  499. viewBinding.imgLeft.setOnClickListener(v -> {
  500. if (currentPosition > 0) {
  501. currentPosition--;
  502. recyclerView.smoothScrollToPosition(currentPosition);
  503. }
  504. });
  505. viewBinding.imgRight.setOnClickListener(v -> {
  506. if (currentPosition < mAdapter.getItemCount() - 1) {
  507. currentPosition++;
  508. recyclerView.smoothScrollToPosition(currentPosition);
  509. }
  510. });
  511. RelativeLayoutDebouncer.Companion.setDebouncedOnClickListener(viewBinding.inc.userLogin, 1000L, v -> {
  512. basicConfLog();
  513. });
  514. // 存储
  515. viewBinding.addChemicals.setOnClickListener(v -> {
  516. //新增
  517. if (ChemicalApp.userData != null) {
  518. if (ChemicalApp.administrators || ChemicalApp.responsibles) {
  519. planDialog = new PlanDialog(MainActivity.this, new View.OnClickListener() {
  520. @Override
  521. public void onClick(View v) {
  522. UiManager.INSTANCE.switcher(MainActivity.this, AlreadyActivity.class);
  523. planDialog.dismiss();
  524. }
  525. }, new View.OnClickListener() {
  526. @Override
  527. public void onClick(View v) {
  528. UiManager.INSTANCE.switcher(MainActivity.this, PlanAddActivity.class);
  529. planDialog.dismiss();
  530. }
  531. });
  532. planDialog.show();
  533. } else {
  534. customDialogView(2, "当前人员无权限");
  535. }
  536. } else {
  537. basicConfLog();
  538. }
  539. });
  540. viewBinding.reDis.setOnClickListener(v -> {
  541. if (ChemicalApp.userData != null) {
  542. UiManager.INSTANCE.switcher(this, WasteChemicalsActivity.class);
  543. } else {
  544. basicConfLog();
  545. }
  546. });
  547. viewBinding.reInq.setOnClickListener(v -> {
  548. Map<String, Object> map = new HashMap<>();
  549. map.put("logIn", ChemicalApp.userData != null ? 1 : 0);
  550. map.put("cabinetId", "a");
  551. map.put("doorId", "a");
  552. UiManager.INSTANCE.switcher(this, map, InquiryActivity.class);
  553. });
  554. viewBinding.reCla.setOnClickListener(v -> {
  555. if (ChemicalApp.userData != null) {
  556. UiManager.INSTANCE.switcher(this, UseActivity.class);
  557. } else {
  558. basicConfLog();
  559. }
  560. });
  561. viewBinding.reRet.setOnClickListener(v -> {
  562. if (ChemicalApp.userData != null) {
  563. UiManager.INSTANCE.switcher(this, ChemicalsAlsoActivity.class);
  564. } else {
  565. basicConfLog();
  566. }
  567. });
  568. viewBinding.rlLedger.setOnClickListener(v -> {
  569. if (ChemicalApp.userData != null) {
  570. UiManager.INSTANCE.switcher(this, LedgerActivity.class);
  571. } else {
  572. basicConfLog();
  573. }
  574. });
  575. viewBinding.reLedger.setOnClickListener(v -> {
  576. if (ChemicalApp.userData != null) {
  577. UiManager.INSTANCE.switcher(this, ChemicalLabelingActivity.class);
  578. } else {
  579. basicConfLog();
  580. }
  581. });
  582. viewBinding.rlWarning.setOnClickListener(v -> {
  583. if (ChemicalApp.userData != null) {
  584. UiManager.INSTANCE.switcher(this, WarningEventsActivity.class);
  585. } else {
  586. basicConfLog();
  587. }
  588. });
  589. viewBinding.rlDem.setOnClickListener(v -> {
  590. UiManager.INSTANCE.switcher(this, MsdsActivity.class);
  591. });
  592. viewBinding.inc.tvOutLogin.setOnClickListener(v -> {
  593. ChemicalApp.userData = null;
  594. ChemicalApp.subjectId = null;
  595. HttpClient.INSTANCE.setToken(null);
  596. ActivityUtils.startActivity(StartActivity.class);
  597. });
  598. basicConf();
  599. viewBinding.caozuoRL.setOnClickListener(v -> {
  600. viewBinding.caozuoRL.setVisibility(View.GONE);
  601. viewBinding.caozuoQrRL.setVisibility(View.VISIBLE);
  602. viewBinding.caozuoQrRL.postDelayed(() -> {
  603. viewBinding.caozuoRL.setVisibility(View.VISIBLE);
  604. viewBinding.caozuoQrRL.setVisibility(View.GONE);
  605. }, 1000 * 60);
  606. });
  607. viewBinding.caozuoRL.post(() -> {
  608. Bitmap qrCode = CodeUtils.createQRCode(
  609. "https://labcontrol.nwafu.edu.cn/api/?type=14",
  610. 120
  611. );
  612. viewBinding.caozuoQr.setImageBitmap(qrCode);
  613. });
  614. }
  615. private void callLogoutApis(LogoutCallback callback) {
  616. showLoading("退出中...");
  617. ApiRepository.INSTANCE.loginOut().subscribe(new Consumer<Boolean>() {
  618. @Override
  619. public void accept(Boolean aBoolean) throws Throwable {
  620. dismissLoading();
  621. if (callback != null) callback.onComplete(true);
  622. }
  623. }, new Consumer<Throwable>() {
  624. @Override
  625. public void accept(Throwable throwable) throws Throwable {
  626. dismissLoading();
  627. if (callback != null) callback.onComplete(false);
  628. }
  629. });
  630. }
  631. private void showTextInputDialog(String title, TextInputCallback callback) {
  632. EditText editText = new EditText(this);
  633. AlertDialog dialog = new AlertDialog.Builder(this)
  634. .setTitle(title)
  635. .setView(editText)
  636. .setPositiveButton("确定", (dialog1, which) -> {
  637. String inputText = editText.getText().toString();
  638. callback.onInput(inputText);
  639. })
  640. .setNegativeButton("取消", (dialog1, which) -> {
  641. callback.onInput(null);
  642. })
  643. .create();
  644. dialog.show();
  645. }
  646. interface TextInputCallback {
  647. void onInput(String input);
  648. }
  649. interface LogoutCallback {
  650. void onComplete(boolean success);
  651. }
  652. }