| | |
| | | |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | |
| | | houseIdList = new ArrayList<>(); |
| | | } |
| | | this.houseIdList = houseIdList; |
| | | } |
| | | |
| | | /** |
| | | * 删除电站 |
| | | * |
| | | * @param houseId 电站id |
| | | */ |
| | | public void delHouseId(String houseId) { |
| | | if (TextUtils.isEmpty(houseId)) { |
| | | return; |
| | | } |
| | | for (int i = 0; i < houseIdList.size(); i++) { |
| | | if (houseIdList.get(i).getHomeId().equals(houseId)) { |
| | | houseIdList.remove(i); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 移动电站位置 |
| | | * |
| | | * @param houseId 电站id |
| | | */ |
| | | public void moveHouseId(String houseId) { |
| | | if (TextUtils.isEmpty(houseId)) { |
| | | return; |
| | | } |
| | | int index = -1; |
| | | for (int i = 0; i < houseIdList.size(); i++) { |
| | | if (houseIdList.get(i).getHomeId().equals(houseId)) { |
| | | index = i; |
| | | break; |
| | | } |
| | | } |
| | | if (index == -1) { |
| | | return; |
| | | } |
| | | //index==0表示只有一个元素或者在首位,不需要移动位置 |
| | | if (index > 0) { |
| | | Collections.swap(houseIdList, index - 1, index); |
| | | } |
| | | } |
| | | |
| | | //住宅ID列表 |
| | |
| | | json.addProperty("electrovalence", houseInfoBean.getElectrovalence()); |
| | | json.addProperty("totalCost", houseInfoBean.getTotalCost()); |
| | | json.addProperty("zoneType", houseInfoBean.getZoneType()); |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { |
| | | @Override |
| | | public void onSuccess(String str) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(true); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 住宅(电站)移动位置 |
| | | * |
| | | * @param homeId 电站id |
| | | * @param frontHomeId 前面的电站id,如果不传表示排到第一位 |
| | | * @param cloudCallBeak - |
| | | */ |
| | | public void moveResidence(String homeId, String frontHomeId, CloudCallBeak<Boolean> cloudCallBeak) { |
| | | String requestUrl = HttpApi.POST_PowerStation_UserSort; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("homeId", homeId); |
| | | if (!TextUtils.isEmpty(frontHomeId)) { |
| | | json.addProperty("frontHomeId", frontHomeId); |
| | | } |
| | | // json.addProperty("zoneType", "zoneType"); |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { |
| | | @Override |
| | | public void onSuccess(String str) { |
| | |
| | | UserConfigManage.getInstance().setHomeName(houseIdBean.getHomeName()); |
| | | //重新设置本地通讯秘钥 |
| | | UserConfigManage.getInstance().setLocalSecret(houseIdBean.getLocalSecret()); |
| | | UserConfigManage.getInstance().Save(); |
| | | //配置本地通信的信息 |
| | | HDLLinkConfig.getInstance().setHomeId(UserConfigManage.getInstance().getHomeId()); |
| | | HDLLinkConfig.getInstance().setLocalSecret(UserConfigManage.getInstance().getLocalSecret()); |