MainAbilitySlice.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. package com.fujica.abk.slice;
  2. import com.fujica.abk.ResourceTable;
  3. import com.fujica.abk.api.auth;
  4. import com.fujica.abk.api.cache;
  5. import com.fujica.abk.common.EventBus;
  6. import com.fujica.abk.component.LoadingComponent;
  7. import com.fujica.abk.component.OrderDetailComponent;
  8. import com.fujica.abk.component.ParkDetailComponent;
  9. import com.fujica.abk.component.nav.ChargeComponent;
  10. import com.fujica.abk.component.nav.OrderComponent;
  11. import com.fujica.abk.component.nav.ParkComponent;
  12. import com.fujica.abk.model.out.OrderRes;
  13. import com.fujica.abk.model.out.ParkNearRes;
  14. import com.fujica.abk.utils.DialogUtil;
  15. import com.fujica.abk.utils.Log;
  16. import com.fujica.abk.utils.Toast;
  17. import com.huawei.hms.accountsdk.constant.CommonConstant;
  18. import com.huawei.hms.accountsdk.exception.ApiException;
  19. import com.huawei.hms.accountsdk.support.account.AccountAuthManager;
  20. import com.huawei.hms.accountsdk.support.account.request.AccountAuthParams;
  21. import com.huawei.hms.accountsdk.support.account.request.AccountAuthParamsHelper;
  22. import com.huawei.hms.accountsdk.support.account.result.AuthAccount;
  23. import com.huawei.hms.accountsdk.support.account.service.AccountAuthService;
  24. import com.huawei.hms.accountsdk.support.account.tasks.OnFailureListener;
  25. import com.huawei.hms.accountsdk.support.account.tasks.OnSuccessListener;
  26. import com.huawei.hms.accountsdk.support.account.tasks.Task;
  27. import ohos.aafwk.ability.AbilitySlice;
  28. import ohos.aafwk.content.Intent;
  29. import ohos.agp.components.*;
  30. import ohos.agp.utils.Color;
  31. import ohos.agp.window.dialog.ToastDialog;
  32. import ohos.agp.window.service.Window;
  33. import ohos.agp.window.service.WindowManager;
  34. import ohos.location.Location;
  35. import ohos.location.Locator;
  36. import ohos.location.LocatorCallback;
  37. import ohos.location.RequestParam;
  38. import ohos.rpc.RemoteException;
  39. public class MainAbilitySlice extends AbilitySlice {
  40. // 页面容器
  41. private StackLayout pageContainer;
  42. // 底部导航栏组件
  43. private DirectionalLayout navCharge;
  44. private DirectionalLayout navPark;
  45. private DirectionalLayout navOrder;
  46. private DirectionalLayout navCurrentLocation;
  47. // 底部导航栏文字和图标
  48. private Text textCharge;
  49. private Text textPark;
  50. private Text textOrder;
  51. private Image iconPark;
  52. private Image iconPark1;
  53. private Image iconCharge;
  54. private Image iconCharge1;
  55. private Image iconOrder;
  56. private Image iconOrder1;
  57. // 当前选中的 tab
  58. private int currentTab = 1; // 0: 我的, 1: 找车位, 2: 缴费记录
  59. // 定位相关
  60. private Locator locator;
  61. private LocatorCallback locatorCallback;
  62. private Location currentLocation; // 当前定位坐标
  63. // 页面组件
  64. private ChargeComponent chargeComponent;
  65. private ParkComponent parkComponent; // 找车位页面组件
  66. private OrderComponent orderComponent; // 缴费记录页面组件
  67. // 页面初始化标志
  68. private boolean isChargeComponentInitialized = false;
  69. private boolean isParkComponentInitialized = false;
  70. private boolean isOrderComponentInitialized = false;
  71. // 详情区域
  72. private DirectionalLayout mainRight; // 右侧详情区域
  73. private OrderDetailComponent orderDetailComponent; // 订单详情组件
  74. private ParkDetailComponent parkDetailComponent; // 停车场详情组件
  75. // Loading组件
  76. private LoadingComponent loadingComponent;
  77. // 登录成功事件监听器
  78. private EventBus.EventListener loginSuccessListener;
  79. // 认证状态变化事件监听器
  80. private EventBus.EventListener authChangedListener;
  81. private Image quit;
  82. @Override
  83. public void onStart(Intent intent) {
  84. super.onStart(intent);
  85. try {
  86. //com.fujica.abk_BD8VI9k5bO0HeGAPnhTGeYX++mgKw87G8y+3RZ6nrb9evCePddojupXJN03auUKxTKn1qbFrYQAjFyGumpjsHzw=
  87. String appId = getApplicationContext().getBundleManager().getBundleInfo(getBundleName(), 0).getAppId();
  88. Log.info(appId);
  89. } catch (RemoteException e) {
  90. }
  91. // 设置全屏显示
  92. setFullScreen();
  93. // 设置布局
  94. super.setUIContent(ResourceTable.Layout_ability_main);
  95. // 初始化Loading组件并添加到根布局
  96. loadingComponent = findComponentById(ResourceTable.Id_loading_component);
  97. // 初始化详情区域
  98. mainRight = findComponentById(ResourceTable.Id_main_right);
  99. if (mainRight != null) {
  100. // 创建详情组件
  101. orderDetailComponent = new OrderDetailComponent(this);
  102. parkDetailComponent = new ParkDetailComponent(this);
  103. }
  104. quit = findComponentById(ResourceTable.Id_quit);
  105. quit.setClickedListener(v -> {
  106. DialogUtil.confirm(getContext(), "确认要退出吗?", () -> {
  107. cache.logout(getContext());
  108. quit.setVisibility(Component.HIDE);
  109. });
  110. });
  111. quit.setVisibility(cache.isAuth(getContext()) ? Component.VISIBLE : Component.HIDE);
  112. // 初始化组件
  113. initComponents();
  114. // 设置事件监听
  115. setupListeners();
  116. // 初始化定位
  117. initLocation();
  118. Button mBtnHuaweiIdSignIn = findComponentById(ResourceTable.Id_btn_hwid_sign_in);
  119. mBtnHuaweiIdSignIn.setClickedListener((Component c) -> {
  120. huaweiIdSignIn();
  121. });
  122. // 订阅登录成功事件
  123. subscribeLoginSuccessEvent();
  124. // 订阅认证状态变化事件
  125. subscribeAuthChangedEvent();
  126. }
  127. void setTimeFormat(String timeFormat) {
  128. String timeStr = "12";
  129. if (timeStr.equals(timeFormat)) {
  130. // Display in 12-hour format
  131. } else {
  132. // Display in 24-hour format
  133. }
  134. }
  135. void huaweiIdSignIn() {
  136. AccountAuthService accountAuthService;
  137. // 1、配置登录请求参数AccountAuthParams,包括请求用户id(openid、unionid)、email、profile(昵称、头像)等。
  138. // 2、DEFAULT_AUTH_REQUEST_PARAM默认包含了id和profile(昵称、头像)的请求。
  139. // 3、如需要再获取用户邮箱,需要setEmail();
  140. // 4、如需要获取其他受限信息,如国家和地区,则需要先申请scope,再设置请求参数。
  141. AccountAuthParams accountAuthParams = new AccountAuthParamsHelper(AccountAuthParams.DEFAULT_AUTH_REQUEST_PARAM)
  142. .setEmail()
  143. .createParams();
  144. try {
  145. accountAuthService = AccountAuthManager.getService(accountAuthParams);
  146. } catch (ApiException e) {
  147. // 处理初始化登录授权服务失败,status code标识了失败的原因,请参考API中的错误码参考了解详细错误原因
  148. e.getStatusCode();
  149. Toast.error(getContext(), "Init Huawei accountAuthService FAILED.");
  150. return;
  151. }
  152. Toast.info(getContext(), "Init Huawei accountAuthService SUCCESS");
  153. if (accountAuthService == null) {
  154. Toast.error(getContext(), "获取不到账号信息");
  155. return;
  156. }
  157. // 调用静默登录接口。
  158. // 如果华为系统帐号已经登录,并且已经授权,会登录成功;
  159. // 否则静默登录失败,需要在失败监听中,显式地调用前台登录授权接口,完成登录授权。
  160. Task<AuthAccount> taskSilentSignIn = accountAuthService.silentSignIn();
  161. // Task<AuthAccount> taskSilentSignIn = accountAuthService.silentSignIn();
  162. Toast.info(getContext(), "SilentSign START.");
  163. // 添加静默登录成功处理监听
  164. taskSilentSignIn.addOnSuccessListener(authAccount -> updateUI(authAccount));
  165. // 添加静默登录失败监听
  166. taskSilentSignIn.addOnFailureListener(e -> {
  167. if (e instanceof ApiException) {
  168. ApiException apiException = (ApiException) e;
  169. Toast.error(getContext(), "SilentSignIn FAILED, status code: " + apiException.getStatusCode() + ". Need to foreground sign in" + "\r\n" + apiException.getStatusMessage()
  170. + "\r\n" + apiException.getMessage() + "\r\n" + apiException.getCause());
  171. // 静默登录失败,显式地调用前台登录授权接口,完成登录授权。
  172. Task<AuthAccount> taskSignIn = accountAuthService.signIn();
  173. Toast.info(getContext(), "SignIn foreground START.");
  174. if (taskSignIn == null) {
  175. Toast.info(getContext(), "SignIn foreground task is null.");
  176. return;
  177. }
  178. taskSignIn.addOnSuccessListener(new OnSuccessListener<AuthAccount>() {
  179. @Override
  180. public void onSuccess(AuthAccount result) {
  181. Toast.info(getContext(), "SignIn foreground SUCCESS.");
  182. updateUI(result);
  183. }
  184. });
  185. taskSignIn.addOnFailureListener(new OnFailureListener() {
  186. @Override
  187. public void onFailure(Exception e) {
  188. Toast.info(getContext(), "SignIn foreground FAILED.");
  189. if (e instanceof ApiException) {
  190. ApiException apiException = (ApiException) e;
  191. // 登录失败,status code标识了失败的原因,请参考API中的错误码参考了解详细错误原因
  192. apiException.getStatusCode();
  193. Toast.info(getContext(), "SignIn foreground FAILED. status code: "
  194. + apiException.getStatusCode()
  195. + ".");
  196. if (CommonConstant.RETCODE.SIGN_IN_CANCELLED == apiException.getStatusCode()) {
  197. Toast.info(getContext(), "Error message: User click CANCEL or Return, user cancel login in.");
  198. }
  199. }
  200. }
  201. });
  202. }
  203. });
  204. }
  205. private void updateUI(AuthAccount authAccount) {
  206. Toast.info(getContext(), authAccount.getOpenId() + " : " + authAccount.getUnionId());
  207. }
  208. /**
  209. * 设置全屏显示
  210. */
  211. private void setFullScreen() {
  212. try {
  213. Window window = getWindow();
  214. if (window != null) {
  215. WindowManager.LayoutConfig layoutConfig = window.getLayoutConfig().orElse(null);
  216. if (layoutConfig == null) {
  217. layoutConfig = new WindowManager.LayoutConfig();
  218. }
  219. layoutConfig.type = WindowManager.LayoutConfig.MARK_FULL_SCREEN;
  220. window.setLayoutConfig(layoutConfig);
  221. }
  222. } catch (Exception e) {
  223. Log.error("设置全屏失败: " + e.getMessage());
  224. }
  225. }
  226. /**
  227. * 初始化组件
  228. */
  229. private void initComponents() {
  230. // 初始化页面容器
  231. pageContainer = findComponentById(ResourceTable.Id_page_container);
  232. if (pageContainer != null) {
  233. try {
  234. // 创建我的页面(缴费)
  235. chargeComponent = new ChargeComponent(MainAbilitySlice.this);
  236. chargeComponent.setLoadingComponent(loadingComponent);
  237. chargeComponent.setVisibility(Component.HIDE);
  238. pageContainer.addComponent(chargeComponent);
  239. // 创建找车位页面
  240. parkComponent = new ParkComponent(MainAbilitySlice.this);
  241. parkComponent.setLoadingComponent(loadingComponent);
  242. // 如果已有定位信息,设置到组件中
  243. if (currentLocation != null) {
  244. parkComponent.setCurrentLocation(currentLocation);
  245. }
  246. // 设置停车场选中监听器
  247. parkComponent.setOnParkSelectedListener(new ParkComponent.OnParkSelectedListener() {
  248. @Override
  249. public void onParkSelected(ParkNearRes park) {
  250. showParkDetail(park);
  251. }
  252. @Override
  253. public void onParkDeselected() {
  254. hideDetail();
  255. }
  256. });
  257. parkComponent.setVisibility(Component.VISIBLE); // 默认显示找车位页面
  258. pageContainer.addComponent(parkComponent);
  259. // 创建缴费记录页面
  260. orderComponent = new OrderComponent(MainAbilitySlice.this);
  261. orderComponent.setLoadingComponent(loadingComponent);
  262. // 设置订单选中监听器
  263. orderComponent.setOnOrderSelectedListener(new OrderComponent.OnOrderSelectedListener() {
  264. @Override
  265. public void onOrderSelected(OrderRes order) {
  266. showOrderDetail(order);
  267. }
  268. @Override
  269. public void onOrderDeselected() {
  270. hideDetail();
  271. }
  272. });
  273. orderComponent.setVisibility(Component.HIDE);
  274. pageContainer.addComponent(orderComponent);
  275. Log.info("页面组件初始化完成");
  276. } catch (Exception e) {
  277. Log.error("创建页面组件失败: " + e.getMessage());
  278. e.printStackTrace();
  279. }
  280. }
  281. // 初始化底部导航栏
  282. initBottomNavigation();
  283. }
  284. /**
  285. * 初始化底部导航栏
  286. */
  287. private void initBottomNavigation() {
  288. navCharge = findComponentById(ResourceTable.Id_nav_charge);
  289. navPark = findComponentById(ResourceTable.Id_nav_find_parking);
  290. navOrder = findComponentById(ResourceTable.Id_nav_order);
  291. navCurrentLocation = findComponentById(ResourceTable.Id_nav_current_location);
  292. textCharge = findComponentById(ResourceTable.Id_text_charge);
  293. textPark = findComponentById(ResourceTable.Id_text_park);
  294. textOrder = findComponentById(ResourceTable.Id_text_order);
  295. iconPark = findComponentById(ResourceTable.Id_icon_park);
  296. iconPark1 = findComponentById(ResourceTable.Id_icon_park_1);
  297. iconCharge = findComponentById(ResourceTable.Id_icon_charge);
  298. iconCharge1 = findComponentById(ResourceTable.Id_icon_charge_1);
  299. iconOrder = findComponentById(ResourceTable.Id_icon_order);
  300. iconOrder1 = findComponentById(ResourceTable.Id_icon_order_1);
  301. // 设置点击事件
  302. if (navCharge != null) {
  303. navCharge.setClickedListener(component -> switchToPage(0));
  304. }
  305. if (navPark != null) {
  306. navPark.setClickedListener(component -> switchToPage(1));
  307. }
  308. if (navOrder != null) {
  309. navOrder.setClickedListener(component -> {
  310. // 先检查是否已登录
  311. if (!cache.isAuth(this)) {
  312. // 未登录,调用登录方法
  313. Log.info("未登录,开始登录流程");
  314. auth.login(this).thenAccept(success -> {
  315. if (success) {
  316. Log.info("登录成功,切换到缴费记录页面");
  317. // 登录成功后切换到缴费记录页面
  318. DialogUtil.postTask(() -> switchToPage(2));
  319. } else {
  320. Toast.error(this, "登录失败,请重试");
  321. }
  322. }).exceptionally(e -> {
  323. Log.error("登录异常: " + e.getMessage());
  324. e.printStackTrace();
  325. Toast.error(this, "登录异常: " + e.getMessage());
  326. return null;
  327. });
  328. } else {
  329. // 已登录,直接切换页面
  330. switchToPage(2);
  331. }
  332. });
  333. }
  334. if (navCurrentLocation != null) {
  335. navCurrentLocation.setClickedListener(component -> {
  336. Log.info("点击了当前位置按钮");
  337. locateCurrentPosition();
  338. });
  339. }
  340. // 默认选中找车位
  341. updateBottomNavState(1); // 测试
  342. }
  343. /**
  344. * 切换到指定页面
  345. */
  346. private void switchToPage(int index) {
  347. if (index < 0 || index > 2) {
  348. return;
  349. }
  350. // 隐藏所有页面
  351. if (chargeComponent != null) {
  352. chargeComponent.setVisibility(Component.HIDE);
  353. }
  354. if (parkComponent != null) {
  355. parkComponent.setVisibility(Component.HIDE);
  356. }
  357. if (orderComponent != null) {
  358. orderComponent.setVisibility(Component.HIDE);
  359. }
  360. // 显示目标页面
  361. switch (index) {
  362. case 0: // 我的
  363. if (chargeComponent != null) {
  364. chargeComponent.setVisibility(Component.VISIBLE);
  365. chargeComponent.refresh();
  366. }
  367. break;
  368. case 1: // 找车位
  369. if (parkComponent != null) {
  370. parkComponent.setVisibility(Component.VISIBLE);
  371. parkComponent.refresh();
  372. }
  373. break;
  374. case 2: // 缴费记录
  375. if (orderComponent != null) {
  376. orderComponent.setVisibility(Component.VISIBLE);
  377. orderComponent.reset();
  378. }
  379. break;
  380. }
  381. // 更新当前tab状态
  382. currentTab = index;
  383. updateBottomNavState(index);
  384. // 切换页面时隐藏详情
  385. hideDetail();
  386. Log.info("切换到页面: " + index);
  387. }
  388. /**
  389. * 更新底部导航栏状态
  390. */
  391. private void updateBottomNavState(int index) {
  392. // 重置所有导航项样式
  393. Color grayColor = new Color(Color.getIntColor("#FF666666"));
  394. Color blueColor = new Color(Color.getIntColor("#FA6332"));
  395. if (textCharge != null) {
  396. textCharge.setTextColor(grayColor);
  397. }
  398. if (textPark != null) {
  399. textPark.setTextColor(grayColor);
  400. }
  401. if (textOrder != null) {
  402. textOrder.setTextColor(grayColor);
  403. }
  404. // 设置选中状态
  405. switch (index) {
  406. case 0: // 我的
  407. textCharge.setTextColor(blueColor);
  408. iconCharge.setVisibility(Component.HIDE);
  409. iconCharge1.setVisibility(Component.VISIBLE);
  410. iconOrder.setVisibility(Component.VISIBLE);
  411. iconOrder1.setVisibility(Component.HIDE);
  412. iconPark.setVisibility(Component.VISIBLE);
  413. iconPark1.setVisibility(Component.HIDE);
  414. break;
  415. case 1: // 找车位
  416. textPark.setTextColor(blueColor);
  417. iconCharge.setVisibility(Component.VISIBLE);
  418. iconCharge1.setVisibility(Component.HIDE);
  419. iconOrder.setVisibility(Component.VISIBLE);
  420. iconOrder1.setVisibility(Component.HIDE);
  421. iconPark.setVisibility(Component.HIDE);
  422. iconPark1.setVisibility(Component.VISIBLE);
  423. break;
  424. case 2: // 缴费记录
  425. textOrder.setTextColor(blueColor);
  426. iconCharge.setVisibility(Component.VISIBLE);
  427. iconCharge1.setVisibility(Component.HIDE);
  428. iconOrder.setVisibility(Component.HIDE);
  429. iconOrder1.setVisibility(Component.VISIBLE);
  430. iconPark.setVisibility(Component.VISIBLE);
  431. iconPark1.setVisibility(Component.HIDE);
  432. break;
  433. }
  434. }
  435. /**
  436. * 设置事件监听
  437. */
  438. private void setupListeners() {
  439. // 事件监听已在initBottomNavigation中设置
  440. }
  441. /**
  442. * 初始化定位服务
  443. */
  444. private void initLocation() {
  445. try {
  446. locator = new Locator(this);
  447. locatorCallback = new LocatorCallback() {
  448. @Override
  449. public void onLocationReport(Location location) {
  450. // 保存当前位置坐标
  451. currentLocation = location;
  452. double latitude = location.getLatitude();
  453. double longitude = location.getLongitude();
  454. Log.info("定位成功: " + latitude + ", " + longitude);
  455. // 定位成功后,如果当前在找车位页面,更新定位信息
  456. if (currentTab == 1 && parkComponent != null) {
  457. parkComponent.setCurrentLocation(location);
  458. }
  459. }
  460. @Override
  461. public void onStatusChanged(int type) {
  462. Log.info("定位状态变化: " + type);
  463. }
  464. @Override
  465. public void onErrorReport(int errorCode) {
  466. Log.error("定位错误: " + errorCode);
  467. new ToastDialog(getContext())
  468. .setText("定位失败,错误码: " + errorCode)
  469. .show();
  470. }
  471. };
  472. } catch (Exception e) {
  473. Log.error("初始化定位服务失败: " + e.getMessage());
  474. }
  475. }
  476. /**
  477. * 定位到当前位置
  478. */
  479. private void locateCurrentPosition() {
  480. if (locator == null || locatorCallback == null) {
  481. Log.error("定位服务未初始化");
  482. return;
  483. }
  484. try {
  485. // 请求定位
  486. RequestParam requestParam = new RequestParam(RequestParam.PRIORITY_ACCURACY, 0, 0);
  487. locator.startLocating(requestParam, locatorCallback);
  488. Log.info("开始定位...");
  489. } catch (Exception e) {
  490. Log.error("定位失败: " + e.getMessage());
  491. }
  492. }
  493. /**
  494. * 订阅登录成功事件
  495. */
  496. private void subscribeLoginSuccessEvent() {
  497. loginSuccessListener = event -> {
  498. // 在主线程更新UI
  499. DialogUtil.postTask(() -> {
  500. Log.info("收到登录成功事件,更新UI");
  501. // 刷新我的页面
  502. if (chargeComponent != null) {
  503. chargeComponent.refresh();
  504. }
  505. quit.setVisibility(Component.VISIBLE);
  506. // 可以在这里添加其他需要更新的UI逻辑
  507. });
  508. };
  509. EventBus.getInstance().on("onLoginSuccess", loginSuccessListener);
  510. }
  511. /**
  512. * 订阅认证状态变化事件
  513. */
  514. private void subscribeAuthChangedEvent() {
  515. authChangedListener = event -> {
  516. // 在主线程更新UI
  517. DialogUtil.postTask(() -> {
  518. Log.error("收到认证状态变化事件,更新UI");
  519. // 隐藏退出按钮
  520. if (quit != null) {
  521. quit.setVisibility(Component.HIDE);
  522. }
  523. // 刷新我的页面
  524. if (chargeComponent != null) {
  525. chargeComponent.refresh();
  526. }
  527. // 可以在这里添加其他需要更新的UI逻辑
  528. });
  529. // 认证过期后重新登录
  530. auth.login(MainAbilitySlice.this).thenAccept(success -> {
  531. if (success) {
  532. Log.info("重新登录成功");
  533. } else {
  534. Log.error("重新登录失败");
  535. }
  536. }).exceptionally(e -> {
  537. Log.error("重新登录异常: " + e.getMessage());
  538. return null;
  539. });
  540. };
  541. EventBus.getInstance().on("onLoginExpired", authChangedListener);
  542. }
  543. @Override
  544. protected void onStop() {
  545. super.onStop();
  546. // 取消订阅登录成功事件
  547. if (loginSuccessListener != null) {
  548. EventBus.getInstance().off("onLoginSuccess", loginSuccessListener);
  549. }
  550. // 取消订阅认证状态变化事件
  551. if (authChangedListener != null) {
  552. EventBus.getInstance().off("onLoginExpired", authChangedListener);
  553. }
  554. // 停止定位
  555. if (locator != null && locatorCallback != null) {
  556. try {
  557. locator.stopLocating(locatorCallback);
  558. } catch (Exception e) {
  559. Log.error("停止定位失败: " + e.getMessage());
  560. }
  561. }
  562. }
  563. /**
  564. * 显示订单详情
  565. */
  566. private void showOrderDetail(OrderRes order) {
  567. if (mainRight == null || orderDetailComponent == null) {
  568. return;
  569. }
  570. // 移除所有子组件
  571. mainRight.removeAllComponents();
  572. // 设置订单数据
  573. orderDetailComponent.setOrderData(order,getContext());
  574. // 添加详情组件
  575. mainRight.addComponent(orderDetailComponent);
  576. // 显示详情区域
  577. mainRight.setVisibility(Component.VISIBLE);
  578. }
  579. /**
  580. * 显示停车场详情
  581. */
  582. private void showParkDetail(ParkNearRes park) {
  583. if (mainRight == null || parkDetailComponent == null) {
  584. return;
  585. }
  586. // 移除所有子组件
  587. mainRight.removeAllComponents();
  588. // 设置停车场数据
  589. parkDetailComponent.setParkData(park);
  590. // 添加详情组件
  591. mainRight.addComponent(parkDetailComponent);
  592. // 显示详情区域
  593. mainRight.setVisibility(Component.VISIBLE);
  594. }
  595. /**
  596. * 隐藏详情
  597. */
  598. private void hideDetail() {
  599. if (mainRight == null) {
  600. return;
  601. }
  602. // 移除所有子组件
  603. mainRight.removeAllComponents();
  604. // 隐藏详情区域
  605. mainRight.setVisibility(Component.HIDE);
  606. }
  607. }