|
@@ -60,7 +60,7 @@ public class MainAbilitySlice extends AbilitySlice {
|
|
|
private Image iconOrder1;
|
|
private Image iconOrder1;
|
|
|
|
|
|
|
|
// 当前选中的 tab
|
|
// 当前选中的 tab
|
|
|
- private int currentTab = 1; // 0: 我的, 1: 找车位, 2: 缴费记录
|
|
|
|
|
|
|
+ private int currentTab = 0; // 0: 找车位, 1: 计费, 2: 缴费记录
|
|
|
|
|
|
|
|
// 定位相关
|
|
// 定位相关
|
|
|
private Locator locator;
|
|
private Locator locator;
|
|
@@ -149,15 +149,6 @@ public class MainAbilitySlice extends AbilitySlice {
|
|
|
subscribeAuthChangedEvent();
|
|
subscribeAuthChangedEvent();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- void setTimeFormat(String timeFormat) {
|
|
|
|
|
- String timeStr = "12";
|
|
|
|
|
- if (timeStr.equals(timeFormat)) {
|
|
|
|
|
- // Display in 12-hour format
|
|
|
|
|
- } else {
|
|
|
|
|
- // Display in 24-hour format
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
void huaweiIdSignIn() {
|
|
void huaweiIdSignIn() {
|
|
|
AccountAuthService accountAuthService;
|
|
AccountAuthService accountAuthService;
|
|
|
// 1、配置登录请求参数AccountAuthParams,包括请求用户id(openid、unionid)、email、profile(昵称、头像)等。
|
|
// 1、配置登录请求参数AccountAuthParams,包括请求用户id(openid、unionid)、email、profile(昵称、头像)等。
|
|
@@ -262,63 +253,108 @@ public class MainAbilitySlice extends AbilitySlice {
|
|
|
// 初始化页面容器
|
|
// 初始化页面容器
|
|
|
pageContainer = findComponentById(ResourceTable.Id_page_container);
|
|
pageContainer = findComponentById(ResourceTable.Id_page_container);
|
|
|
|
|
|
|
|
- if (pageContainer != null) {
|
|
|
|
|
- try {
|
|
|
|
|
- // 创建我的页面(缴费)
|
|
|
|
|
- chargeComponent = new ChargeComponent(MainAbilitySlice.this);
|
|
|
|
|
- chargeComponent.setLoadingComponent(loadingComponent);
|
|
|
|
|
- chargeComponent.setVisibility(Component.HIDE);
|
|
|
|
|
- pageContainer.addComponent(chargeComponent);
|
|
|
|
|
-
|
|
|
|
|
- // 创建找车位页面
|
|
|
|
|
- parkComponent = new ParkComponent(MainAbilitySlice.this);
|
|
|
|
|
- parkComponent.setLoadingComponent(loadingComponent);
|
|
|
|
|
- // 如果已有定位信息,设置到组件中
|
|
|
|
|
- if (currentLocation != null) {
|
|
|
|
|
- parkComponent.setCurrentLocation(currentLocation);
|
|
|
|
|
- }
|
|
|
|
|
- // 设置停车场选中监听器
|
|
|
|
|
- parkComponent.setOnParkSelectedListener(new ParkComponent.OnParkSelectedListener() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onParkSelected(ParkNearRes park) {
|
|
|
|
|
- showParkDetail(park);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onParkDeselected() {
|
|
|
|
|
- hideDetail();
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- parkComponent.setVisibility(Component.VISIBLE); // 默认显示找车位页面
|
|
|
|
|
- pageContainer.addComponent(parkComponent);
|
|
|
|
|
-
|
|
|
|
|
- // 创建缴费记录页面
|
|
|
|
|
- orderComponent = new OrderComponent(MainAbilitySlice.this);
|
|
|
|
|
- orderComponent.setLoadingComponent(loadingComponent);
|
|
|
|
|
- // 设置订单选中监听器
|
|
|
|
|
- orderComponent.setOnOrderSelectedListener(new OrderComponent.OnOrderSelectedListener() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onOrderSelected(OrderRes order) {
|
|
|
|
|
- showOrderDetail(order);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 初始化底部导航栏
|
|
|
|
|
+ initBottomNavigation();
|
|
|
|
|
+
|
|
|
|
|
+ // 默认初始化找车位页面(因为默认显示该页面)
|
|
|
|
|
+// initParkComponent();
|
|
|
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onOrderDeselected() {
|
|
|
|
|
- hideDetail();
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- orderComponent.setVisibility(Component.HIDE);
|
|
|
|
|
- pageContainer.addComponent(orderComponent);
|
|
|
|
|
|
|
+ // 默认选中找车位
|
|
|
|
|
+ switchToPage(0);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- Log.info("页面组件初始化完成");
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- Log.error("创建页面组件失败: " + e.getMessage());
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 初始化缴费页面组件
|
|
|
|
|
+ */
|
|
|
|
|
+ private void initChargeComponent() {
|
|
|
|
|
+ if (isChargeComponentInitialized || pageContainer == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ Log.info("首次初始化缴费页面");
|
|
|
|
|
+ chargeComponent = new ChargeComponent(MainAbilitySlice.this);
|
|
|
|
|
+ chargeComponent.setLoadingComponent(loadingComponent);
|
|
|
|
|
+ chargeComponent.setVisibility(Component.HIDE);
|
|
|
|
|
+ pageContainer.addComponent(chargeComponent);
|
|
|
|
|
+ isChargeComponentInitialized = true;
|
|
|
|
|
+ Log.info("缴费页面初始化完成");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ Log.error("创建缴费页面组件失败: " + e.getMessage());
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 初始化找车位页面组件
|
|
|
|
|
+ */
|
|
|
|
|
+ private void initParkComponent() {
|
|
|
|
|
+ if (isParkComponentInitialized || pageContainer == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ Log.info("首次初始化找车位页面");
|
|
|
|
|
+ parkComponent = new ParkComponent(MainAbilitySlice.this);
|
|
|
|
|
+ parkComponent.setLoadingComponent(loadingComponent);
|
|
|
|
|
+ // 如果已有定位信息,设置到组件中
|
|
|
|
|
+ if (currentLocation != null) {
|
|
|
|
|
+ parkComponent.setCurrentLocation(currentLocation);
|
|
|
}
|
|
}
|
|
|
|
|
+ // 设置停车场选中监听器
|
|
|
|
|
+ parkComponent.setOnParkSelectedListener(new ParkComponent.OnParkSelectedListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onParkSelected(ParkNearRes park) {
|
|
|
|
|
+ showParkDetail(park);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onParkDeselected() {
|
|
|
|
|
+ hideDetail();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ parkComponent.setVisibility(Component.HIDE);
|
|
|
|
|
+ pageContainer.addComponent(parkComponent);
|
|
|
|
|
+ isParkComponentInitialized = true;
|
|
|
|
|
+ Log.info("找车位页面初始化完成");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ Log.error("创建找车位页面组件失败: " + e.getMessage());
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 初始化缴费记录页面组件
|
|
|
|
|
+ */
|
|
|
|
|
+ private void initOrderComponent() {
|
|
|
|
|
+ if (isOrderComponentInitialized || pageContainer == null) {
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ Log.info("首次初始化缴费记录页面");
|
|
|
|
|
+ orderComponent = new OrderComponent(MainAbilitySlice.this);
|
|
|
|
|
+ orderComponent.setLoadingComponent(loadingComponent);
|
|
|
|
|
+ // 设置订单选中监听器
|
|
|
|
|
+ orderComponent.setOnOrderSelectedListener(new OrderComponent.OnOrderSelectedListener() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onOrderSelected(OrderRes order) {
|
|
|
|
|
+ showOrderDetail(order);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // 初始化底部导航栏
|
|
|
|
|
- initBottomNavigation();
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onOrderDeselected() {
|
|
|
|
|
+ hideDetail();
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ orderComponent.setVisibility(Component.HIDE);
|
|
|
|
|
+ pageContainer.addComponent(orderComponent);
|
|
|
|
|
+ isOrderComponentInitialized = true;
|
|
|
|
|
+ Log.info("缴费记录页面初始化完成");
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ Log.error("创建缴费记录页面组件失败: " + e.getMessage());
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -341,37 +377,14 @@ public class MainAbilitySlice extends AbilitySlice {
|
|
|
iconOrder1 = findComponentById(ResourceTable.Id_icon_order_1);
|
|
iconOrder1 = findComponentById(ResourceTable.Id_icon_order_1);
|
|
|
|
|
|
|
|
// 设置点击事件
|
|
// 设置点击事件
|
|
|
- if (navCharge != null) {
|
|
|
|
|
- navCharge.setClickedListener(component -> switchToPage(0));
|
|
|
|
|
- }
|
|
|
|
|
if (navPark != null) {
|
|
if (navPark != null) {
|
|
|
- navPark.setClickedListener(component -> switchToPage(1));
|
|
|
|
|
|
|
+ navPark.setClickedListener(component -> switchToPage(0));
|
|
|
|
|
+ }
|
|
|
|
|
+ if (navCharge != null) {
|
|
|
|
|
+ navCharge.setClickedListener(component -> switchToPageAfterLogin(1));
|
|
|
}
|
|
}
|
|
|
if (navOrder != null) {
|
|
if (navOrder != null) {
|
|
|
- navOrder.setClickedListener(component -> {
|
|
|
|
|
- // 先检查是否已登录
|
|
|
|
|
- if (!cache.isAuth(this)) {
|
|
|
|
|
- // 未登录,调用登录方法
|
|
|
|
|
- Log.info("未登录,开始登录流程");
|
|
|
|
|
- auth.login(this).thenAccept(success -> {
|
|
|
|
|
- if (success) {
|
|
|
|
|
- Log.info("登录成功,切换到缴费记录页面");
|
|
|
|
|
- // 登录成功后切换到缴费记录页面
|
|
|
|
|
- DialogUtil.postTask(() -> switchToPage(2));
|
|
|
|
|
- } else {
|
|
|
|
|
- Toast.error(this, "登录失败,请重试");
|
|
|
|
|
- }
|
|
|
|
|
- }).exceptionally(e -> {
|
|
|
|
|
- Log.error("登录异常: " + e.getMessage());
|
|
|
|
|
- e.printStackTrace();
|
|
|
|
|
- Toast.error(this, "登录异常: " + e.getMessage());
|
|
|
|
|
- return null;
|
|
|
|
|
- });
|
|
|
|
|
- } else {
|
|
|
|
|
- // 已登录,直接切换页面
|
|
|
|
|
- switchToPage(2);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ navOrder.setClickedListener(component -> switchToPageAfterLogin(2));
|
|
|
}
|
|
}
|
|
|
if (navCurrentLocation != null) {
|
|
if (navCurrentLocation != null) {
|
|
|
navCurrentLocation.setClickedListener(component -> {
|
|
navCurrentLocation.setClickedListener(component -> {
|
|
@@ -379,11 +392,33 @@ public class MainAbilitySlice extends AbilitySlice {
|
|
|
locateCurrentPosition();
|
|
locateCurrentPosition();
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // 默认选中找车位
|
|
|
|
|
- updateBottomNavState(1); // 测试
|
|
|
|
|
|
|
+ private void switchToPageAfterLogin(int index){
|
|
|
|
|
+ // 先检查是否已登录
|
|
|
|
|
+ if (!cache.isAuth(this)) {
|
|
|
|
|
+ // 未登录,调用登录方法
|
|
|
|
|
+ Log.info("未登录,开始登录流程");
|
|
|
|
|
+ auth.login(this).thenAccept(success -> {
|
|
|
|
|
+ if (success) {
|
|
|
|
|
+ // 登录成功后切换到缴费记录页面
|
|
|
|
|
+ DialogUtil.postTask(() -> switchToPage(index));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ Toast.error(this, "登录失败,请重试");
|
|
|
|
|
+ }
|
|
|
|
|
+ }).exceptionally(e -> {
|
|
|
|
|
+ Log.error("登录异常: " + e.getMessage());
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ Toast.error(this, "登录异常: " + e.getMessage());
|
|
|
|
|
+ return null;
|
|
|
|
|
+ });
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 已登录,直接切换页面
|
|
|
|
|
+ switchToPage(index);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 切换到指定页面
|
|
* 切换到指定页面
|
|
|
*/
|
|
*/
|
|
@@ -405,22 +440,43 @@ public class MainAbilitySlice extends AbilitySlice {
|
|
|
|
|
|
|
|
// 显示目标页面
|
|
// 显示目标页面
|
|
|
switch (index) {
|
|
switch (index) {
|
|
|
- case 0: // 我的
|
|
|
|
|
- if (chargeComponent != null) {
|
|
|
|
|
- chargeComponent.setVisibility(Component.VISIBLE);
|
|
|
|
|
- chargeComponent.refresh();
|
|
|
|
|
|
|
+ case 0: // 找车位
|
|
|
|
|
+ // 首次打开时初始化
|
|
|
|
|
+ if (!isParkComponentInitialized) {
|
|
|
|
|
+ initParkComponent();
|
|
|
|
|
+ // 首次初始化时,组件内部已经加载了数据,无需再调用refresh()
|
|
|
|
|
+ } else if (parkComponent != null) {
|
|
|
|
|
+ // 非首次打开时才刷新数据
|
|
|
|
|
+ parkComponent.refresh();
|
|
|
}
|
|
}
|
|
|
- break;
|
|
|
|
|
- case 1: // 找车位
|
|
|
|
|
if (parkComponent != null) {
|
|
if (parkComponent != null) {
|
|
|
parkComponent.setVisibility(Component.VISIBLE);
|
|
parkComponent.setVisibility(Component.VISIBLE);
|
|
|
- parkComponent.refresh();
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
|
|
+ case 1: // 计费
|
|
|
|
|
+ // 首次打开时初始化
|
|
|
|
|
+ if (!isChargeComponentInitialized) {
|
|
|
|
|
+ initChargeComponent();
|
|
|
|
|
+ // 首次初始化时,组件内部已经加载了数据,无需再调用refresh()
|
|
|
|
|
+ } else if (chargeComponent != null) {
|
|
|
|
|
+ // 非首次打开时才刷新数据
|
|
|
|
|
+ chargeComponent.refresh();
|
|
|
|
|
+ }
|
|
|
|
|
+ if (chargeComponent != null) {
|
|
|
|
|
+ chargeComponent.setVisibility(Component.VISIBLE);
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
case 2: // 缴费记录
|
|
case 2: // 缴费记录
|
|
|
|
|
+ // 首次打开时初始化
|
|
|
|
|
+ if (!isOrderComponentInitialized) {
|
|
|
|
|
+ initOrderComponent();
|
|
|
|
|
+ // 首次初始化时,组件内部已经加载了数据,无需再调用reset()
|
|
|
|
|
+ } else if (orderComponent != null) {
|
|
|
|
|
+ // 非首次打开时才刷新数据
|
|
|
|
|
+ orderComponent.reset();
|
|
|
|
|
+ }
|
|
|
if (orderComponent != null) {
|
|
if (orderComponent != null) {
|
|
|
orderComponent.setVisibility(Component.VISIBLE);
|
|
orderComponent.setVisibility(Component.VISIBLE);
|
|
|
- orderComponent.reset();
|
|
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
@@ -431,8 +487,6 @@ public class MainAbilitySlice extends AbilitySlice {
|
|
|
|
|
|
|
|
// 切换页面时隐藏详情
|
|
// 切换页面时隐藏详情
|
|
|
hideDetail();
|
|
hideDetail();
|
|
|
-
|
|
|
|
|
- Log.info("切换到页面: " + index);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -455,17 +509,7 @@ public class MainAbilitySlice extends AbilitySlice {
|
|
|
|
|
|
|
|
// 设置选中状态
|
|
// 设置选中状态
|
|
|
switch (index) {
|
|
switch (index) {
|
|
|
- case 0: // 我的
|
|
|
|
|
- textCharge.setTextColor(blueColor);
|
|
|
|
|
-
|
|
|
|
|
- iconCharge.setVisibility(Component.HIDE);
|
|
|
|
|
- iconCharge1.setVisibility(Component.VISIBLE);
|
|
|
|
|
- iconOrder.setVisibility(Component.VISIBLE);
|
|
|
|
|
- iconOrder1.setVisibility(Component.HIDE);
|
|
|
|
|
- iconPark.setVisibility(Component.VISIBLE);
|
|
|
|
|
- iconPark1.setVisibility(Component.HIDE);
|
|
|
|
|
- break;
|
|
|
|
|
- case 1: // 找车位
|
|
|
|
|
|
|
+ case 0: // 找车位
|
|
|
textPark.setTextColor(blueColor);
|
|
textPark.setTextColor(blueColor);
|
|
|
|
|
|
|
|
iconCharge.setVisibility(Component.VISIBLE);
|
|
iconCharge.setVisibility(Component.VISIBLE);
|
|
@@ -475,6 +519,16 @@ public class MainAbilitySlice extends AbilitySlice {
|
|
|
iconPark.setVisibility(Component.HIDE);
|
|
iconPark.setVisibility(Component.HIDE);
|
|
|
iconPark1.setVisibility(Component.VISIBLE);
|
|
iconPark1.setVisibility(Component.VISIBLE);
|
|
|
break;
|
|
break;
|
|
|
|
|
+ case 1: // 我的
|
|
|
|
|
+ textCharge.setTextColor(blueColor);
|
|
|
|
|
+
|
|
|
|
|
+ iconCharge.setVisibility(Component.HIDE);
|
|
|
|
|
+ iconCharge1.setVisibility(Component.VISIBLE);
|
|
|
|
|
+ iconOrder.setVisibility(Component.VISIBLE);
|
|
|
|
|
+ iconOrder1.setVisibility(Component.HIDE);
|
|
|
|
|
+ iconPark.setVisibility(Component.VISIBLE);
|
|
|
|
|
+ iconPark1.setVisibility(Component.HIDE);
|
|
|
|
|
+ break;
|
|
|
case 2: // 缴费记录
|
|
case 2: // 缴费记录
|
|
|
textOrder.setTextColor(blueColor);
|
|
textOrder.setTextColor(blueColor);
|
|
|
|
|
|
|
@@ -511,7 +565,7 @@ public class MainAbilitySlice extends AbilitySlice {
|
|
|
|
|
|
|
|
Log.info("定位成功: " + latitude + ", " + longitude);
|
|
Log.info("定位成功: " + latitude + ", " + longitude);
|
|
|
// 定位成功后,如果当前在找车位页面,更新定位信息
|
|
// 定位成功后,如果当前在找车位页面,更新定位信息
|
|
|
- if (currentTab == 1 && parkComponent != null) {
|
|
|
|
|
|
|
+ if (currentTab == 0 && parkComponent != null) {
|
|
|
parkComponent.setCurrentLocation(location);
|
|
parkComponent.setCurrentLocation(location);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -561,7 +615,6 @@ public class MainAbilitySlice extends AbilitySlice {
|
|
|
loginSuccessListener = event -> {
|
|
loginSuccessListener = event -> {
|
|
|
// 在主线程更新UI
|
|
// 在主线程更新UI
|
|
|
DialogUtil.postTask(() -> {
|
|
DialogUtil.postTask(() -> {
|
|
|
- Log.info("收到登录成功事件,更新UI");
|
|
|
|
|
// 刷新我的页面
|
|
// 刷新我的页面
|
|
|
if (chargeComponent != null) {
|
|
if (chargeComponent != null) {
|
|
|
chargeComponent.refresh();
|
|
chargeComponent.refresh();
|