Esempio n. 1
0
  /**
   * 请求车辆列表
   *
   * @param userName
   */
  public synchronized void queryVehicleList(Context context) {
    if (!isLogin) {
      return;
    }

    final String userName =
        PreferenceUtil.getString(this, BaseActivity.SETTING_INFOS, BaseActivity.NAME);
    final boolean oilPriceSaved =
        !TextUtils.isEmpty(
            PreferenceUtil.getString(
                this, BaseActivity.SETTING_INFOS, BaseActivity.EXTRA_DEFAULT_OIL_PRICE));
    QueryVehicleListRequest request = new QueryVehicleListRequest();
    request.setApiParams(userName);
    request.doRequest(
        context,
        new AsyncJsonBaseResponseParseHandler<VehicleListResponse>() {

          @Override
          public void onParseSuccess(VehicleListResponse result, String originResult) {
            super.onParseSuccess(result, originResult);
            if (!oilPriceSaved) {
              PreferenceUtil.putString(
                  getApplicationContext(),
                  BaseActivity.SETTING_INFOS,
                  BaseActivity.EXTRA_DEFAUL_TOIL_KIND,
                  result.getDefaultOilKind());
              PreferenceUtil.putString(
                  getApplicationContext(),
                  BaseActivity.SETTING_INFOS,
                  BaseActivity.EXTRA_DEFAULT_OIL_PRICE,
                  result.getDefaultOilPrice());
            }
            List<VehicleInfo> vehicleList = result.getVehicleList();
            if (vehicleList == null || vehicleList.isEmpty()) {
              // 原来的连接该停掉
              stopScanOBD();
            } else {
              setDefaultVehicleBindOBDs(vehicleList);
            }
          }

          @Override
          public Class<VehicleListResponse> getTypeClass() {
            return VehicleListResponse.class;
          }
        });
  }
Esempio n. 2
0
  public synchronized void setDefaultVehicleBindOBDs(List<VehicleInfo> data) {
    initDefaultVehicleList();
    sVehicleList.clear();
    sVehicleList.addAll(data);
    // 更新本地车辆数据库
    VehicleManager manager = new VehicleManager();
    String userNo =
        PreferenceUtil.getString(mInstance, BaseActivity.SETTING_INFOS, BaseActivity.NAME);
    manager.updateAllVehicle(userNo, data);

    List<OBDBindInfo> newObdData = new ArrayList<OBDBindInfo>();
    MainActivity.defaultBrandAndModle = "";
    PreferenceUtil.remove(this, BaseActivity.SETTING_INFOS, BaseActivity.BRAND);
    PreferenceUtil.remove(this, BaseActivity.SETTING_INFOS, BaseActivity.MODEL);
    PreferenceUtil.remove(this, BaseActivity.SETTING_INFOS, BaseActivity.VEHICLENUM);
    PreferenceUtil.remove(this, BaseActivity.SETTING_INFOS, BaseActivity.VEHICLE_MODE_ID);
    if (data == null || data.isEmpty()) {
      stopScanOBD();
      sObdLists.clear();
      return;
    }
    for (VehicleInfo vehicle : data) {
      if ("YES".equals(vehicle.getIsDefault())) {
        String vehiBrand = vehicle.getVehicleBrand();
        String vehiModel = vehicle.getVehicleModel();
        String vehiNo = vehicle.getVehicleNo();
        String vehiModelId = vehicle.getVehicleModelId();

        if (TextUtils.isEmpty(vehiBrand)) {
          vehiBrand = "";
        } else {
          PreferenceUtil.putString(this, BaseActivity.SETTING_INFOS, BaseActivity.BRAND, vehiBrand);
        }
        if (TextUtils.isEmpty(vehiModel)) {
          vehiModel = "";
        } else {
          PreferenceUtil.putString(this, BaseActivity.SETTING_INFOS, BaseActivity.MODEL, vehiModel);
        }
        if (!TextUtils.isEmpty(vehiNo)) {
          PreferenceUtil.putString(
              this, BaseActivity.SETTING_INFOS, BaseActivity.VEHICLENUM, vehiNo);
        }
        if (!TextUtils.isEmpty(vehiModelId)) {
          PreferenceUtil.putString(
              this, BaseActivity.SETTING_INFOS, BaseActivity.VEHICLE_MODE_ID, vehiModelId);
        }
        MainActivity.defaultBrandAndModle = vehiBrand + " " + vehiModel;
        if (TextUtils.isEmpty(vehicle.getObdSN())) {
          stopScanOBD();
          continue;
        }
      }
      String obdAddress = vehicle.getObdSN();
      if (TextUtils.isEmpty(obdAddress)) {
        continue;
      }
      OBDBindInfo obd = new OBDBindInfo();
      obd.setVehicleInfo(vehicle);
      obd.setObdSN(obdAddress);
      obd.setIsDefault(vehicle.getIsDefault());
      TongGouApplication.showLog(obdAddress + "  " + vehicle.getVehicleNo());
      newObdData.add(obd);
    }
    if (TongGouApplication.connetedOBD
        && sObdLists.containsAll(newObdData)
        && newObdData.containsAll(sObdLists)) {
      TongGouApplication.showLog(
          "obdLists.containsAll(newObdData) && newObdData.containsAll(obdLists)");
    } else {
      sObdLists.clear();
      sObdLists.addAll(newObdData);
      doScanOBDAndPulling();
    }
  }