MainActivity.java 25 KB

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