private void setShippingDataUi(){ if (shippingData ==null){ rlAddress.setVisibility(View.GONE); rlAddAddress.setVisibility(View.VISIBLE); }else { rlAddress.setVisibility(View.VISIBLE); rlAddAddress.setVisibility(View.GONE); tvShippingName.setText("收货人:"+ shippingData.getReceiverName()); tvShippingPhone.setText("电话:" +shippingData.getReceiverPhone() ); tvShippingAddress.setText("地址:"+shippingData.getReceiverAddress()); }
时间: 2024-04-03 07:31:12 浏览: 54
这是一个私有方法 setShippingDataUi(),用于设置收货地址的 UI。在方法内部,首先判断 shippingData 是否为空,如果为空,则将收货地址视图隐藏起来,将添加收货地址视图显示出来。否则,将收货地址视图显示出来,将添加收货地址视图隐藏起来。接着根据 shippingData 的数据,将收货人姓名、电话和地址分别设置给对应的 TextView 控件(tvShippingName、tvShippingPhone、tvShippingAddress)显示出来。该方法一般在获取收货地址数据后调用,用于将获取的收货地址数据展示给用户。
相关问题
private void getAddressData() { OkGo.<ResponseData<ShippingVo>>post(AppConst.Shipping.list) .execute(new JsonCallback<ResponseData<ShippingVo>>() { @Override public void onSuccess(Response<ResponseData<ShippingVo>> response) { ResponseData<ShippingVo> model = response.body(); if (model.getData() !=null && model.getData().getList() != null && model.getData().getList().size()>0 ){ rlAddress.setVisibility(View.VISIBLE); rlAddAddress.setVisibility(View.GONE); for (ShippingBean bean: model.getData().getList()) { if (bean.isDefault()){ shippingData = bean; } } }else { rlAddress.setVisibility(View.GONE); rlAddAddress.setVisibility(View.VISIBLE); } }
这是一个私有方法 getAddressData(),用于获取收货地址数据。在方法内部,首先使用 OkGo 发送一个 post 请求,请求地址为 AppConst.Shipping.list,这里使用了泛型,期望返回一个 ResponseData 类型的 ShippingVo 对象。接着注册一个 JsonCallback,在请求成功时会回调该方法的 onSuccess() 方法。在 onSuccess() 方法内部,首先获取响应的数据 model,然后判断其数据是否为空以及收货地址列表是否为空,如果不为空则将收货地址视图显示出来,将添加收货地址视图隐藏起来,并遍历收货地址列表,找到默认的收货地址并将其赋值给 shippingData 变量。如果数据为空,则将收货地址视图隐藏起来,将添加收货地址视图显示出来。
new Thread(() -> { BNRoutePlanInfos routePlaneInfo = BaiduNaviManagerFactory.getRoutePlanManager().getRoutePlanInfo(); if (routePlaneInfo != null) { // 获取限行数据 limitInfo = routePlaneInfo.getLimitInfo(); //3Tab数据 mRoutePlanItems = routePlaneInfo.getRouteTabInfos(); //路线详情 mRouteDetails = routePlaneInfo.getRouteDetailLists(); } // 获取数据后更新 UI runOnUiThread(() -> { if (limitInfo != null) { for (int i = 0; i < limitInfo.size(); i++) { String[] arr = limitInfo.get(i).split(","); Log.e(TAG, "第" + arr[0] + "条路线限行消息:" + arr[1]); } } if (mRoutePlanItems != null) { if (mRoutePlanItems.size() > 0 && mRoutePlanItems.get(0) != null) { initTabView(mLayoutTab0, mRoutePlanItems.get(0)); } if (mRoutePlanItems.size() > 1 && mRoutePlanItems.get(1) != null) { initTabView(mLayoutTab1, mRoutePlanItems.get(1)); mLayoutTab1.setVisibility(View.VISIBLE); } else { mLayoutTab1.setVisibility(View.GONE); } if (mRoutePlanItems.size() > 2 && mRoutePlanItems.get(2) != null) { initTabView(mLayoutTab2, mRoutePlanItems.get(2)); mLayoutTab2.setVisibility(View.VISIBLE); } else { mLayoutTab2.setVisibility(View.GONE); } } mLayoutTab0.setSelected(true); mRouteList.clear(); mRouteList.addAll(mRouteDetails.get(0)); LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity()); mRecyclerView.setLayoutManager(layoutManager); mResultAdapter = new RouteResultAdapter(mRouteList); mRecyclerView.setAdapter(mResultAdapter); // 展示长途信息 if (BaiduNaviManagerFactory.getRouteResultManager().isLongDistance()) { mLDLayout.setVisibility(View.VISIBLE); } else { mLDLayout.setVisibility(View.GONE); } }); }).start(); 以上代码有问题吗? 如有不安全性问题,帮我修改一下
以上代码并没有明显的安全问题。但是建议将敏感信息进行加密传输或存储,比如限行数据和路线详情等。此外,建议将线程操作封装成方法,提高代码的可读性和可维护性。具体修改代码如下:
```
private void getRoutePlanInfo() {
new Thread(() -> {
BNRoutePlanInfos routePlaneInfo = BaiduNaviManagerFactory.getRoutePlanManager().getRoutePlanInfo();
if (routePlaneInfo != null) {
// 获取限行数据
limitInfo = routePlaneInfo.getLimitInfo();
//3Tab数据
mRoutePlanItems = routePlaneInfo.getRouteTabInfos();
//路线详情
mRouteDetails = routePlaneInfo.getRouteDetailLists();
}
// 获取数据后更新 UI
getActivity().runOnUiThread(() -> {
if (limitInfo != null) {
for (int i = 0; i < limitInfo.size(); i++) {
String[] arr = limitInfo.get(i).split(",");
Log.e(TAG, "第" + arr[0] + "条路线限行消息:" + arr[1]);
}
}
if (mRoutePlanItems != null) {
if (mRoutePlanItems.size() > 0 && mRoutePlanItems.get(0) != null) {
initTabView(mLayoutTab0, mRoutePlanItems.get(0));
}
if (mRoutePlanItems.size() > 1 && mRoutePlanItems.get(1) != null) {
initTabView(mLayoutTab1, mRoutePlanItems.get(1));
mLayoutTab1.setVisibility(View.VISIBLE);
} else {
mLayoutTab1.setVisibility(View.GONE);
}
if (mRoutePlanItems.size() > 2 && mRoutePlanItems.get(2) != null) {
initTabView(mLayoutTab2, mRoutePlanItems.get(2));
mLayoutTab2.setVisibility(View.VISIBLE);
} else {
mLayoutTab2.setVisibility(View.GONE);
}
}
mLayoutTab0.setSelected(true);
mRouteList.clear();
mRouteList.addAll(mRouteDetails.get(0));
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
mRecyclerView.setLayoutManager(layoutManager);
mResultAdapter = new RouteResultAdapter(mRouteList);
mRecyclerView.setAdapter(mResultAdapter);
// 展示长途信息
if (BaiduNaviManagerFactory.getRouteResultManager().isLongDistance()) {
mLDLayout.setVisibility(View.VISIBLE);
} else {
mLDLayout.setVisibility(View.GONE);
}
});
}).start();
}
```
阅读全文