优化开启浇水
This commit is contained in:
@@ -21,6 +21,7 @@ import com.ckkj.water.device.mvp.DeviceImpl;
|
||||
import com.ckkj.water.device.mvp.DevicePresenter;
|
||||
import com.ckkj.water.index.entity.WaterDeviceEntity;
|
||||
import com.ckkj.water.network.BaseBean;
|
||||
import com.ckkj.water.utils.ClickUtils;
|
||||
import com.ckkj.water.utils.manager.PowerIconManage;
|
||||
import com.ckkj.water.utils.manager.ThemeManager;
|
||||
import com.ckkj.water.utils.show.ToastUtil;
|
||||
@@ -188,23 +189,7 @@ public class DeviceControlActivity extends BaseActivity<DeviceControlLayoutBindi
|
||||
break;
|
||||
|
||||
case R.id.tv_confirm:
|
||||
if(mDeviceEntity.getWorkStatus().equals("0")){
|
||||
if(mCustomDuration == 0 && mAdapter.getmSelPostion() == -1){
|
||||
ToastUtil.showShort(mContext,getString(R.string.select_watering_duration));
|
||||
return;
|
||||
}
|
||||
}
|
||||
int duration = 0;
|
||||
String workStatus = mDeviceEntity.getWorkStatus();
|
||||
if(workStatus.equals("1")){
|
||||
workStatus = "0";
|
||||
}else{
|
||||
workStatus = "1";
|
||||
duration = convertToMinutes(mTimeList.get(mAdapter.getmSelPostion()));
|
||||
}
|
||||
mPresenter.switchDeviceWork(mDeviceEntity,workStatus,
|
||||
mCustomDuration == 0 ? convertToMinutes(mTimeList.get(mAdapter.getmSelPostion()))
|
||||
: mCustomDuration);
|
||||
handleDeviceSwitch();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -285,6 +270,50 @@ public class DeviceControlActivity extends BaseActivity<DeviceControlLayoutBindi
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 处理设备开关操作
|
||||
*/
|
||||
private void handleDeviceSwitch() {
|
||||
if (mDeviceEntity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查设备在线状态
|
||||
if (!mDeviceEntity.getStatus().equals("1") && !mDeviceEntity.getStatus().equals("2")) {
|
||||
ToastUtil.showShort(mContext, getString(R.string.device_offline_tip));
|
||||
return;
|
||||
}
|
||||
|
||||
boolean isCurrentlyWorking = mDeviceEntity.getWorkStatus().equals("1");
|
||||
|
||||
// 开启浇水时,必须选择时长
|
||||
if (!isCurrentlyWorking) {
|
||||
if (mCustomDuration <= 0 && mAdapter.getmSelPostion() < 0) {
|
||||
ToastUtil.showShort(mContext, getString(R.string.select_watering_duration));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 防止快速点击
|
||||
if (!ClickUtils.onclickTimes()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 显示加载状态
|
||||
showLoadingDialog();
|
||||
|
||||
String newStatus = isCurrentlyWorking ? "0" : "1";
|
||||
int duration = 0;
|
||||
|
||||
// 只有开启浇水时才计算时长
|
||||
if (!isCurrentlyWorking) {
|
||||
duration = mCustomDuration > 0 ? mCustomDuration
|
||||
: convertToMinutes(mTimeList.get(mAdapter.getmSelPostion()));
|
||||
}
|
||||
|
||||
mPresenter.switchDeviceWork(mDeviceEntity, newStatus, duration);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
@@ -327,9 +356,11 @@ public class DeviceControlActivity extends BaseActivity<DeviceControlLayoutBindi
|
||||
*/
|
||||
@Override
|
||||
public void turnOnOffDeviceSuccess(BaseBean bean, String status) {
|
||||
hideDialogLoading();
|
||||
mDeviceEntity.setWorkStatus(status);
|
||||
mCustomDuration = 0;
|
||||
mAdapter.setOnSelPosition(-1);
|
||||
viewBinding.tvWorkDuartion.setText("");
|
||||
if(status.equals("0")){
|
||||
showCenterTipDialog(R.mipmap.icon_dialog_success,getString(R.string.end_watering));
|
||||
viewBinding.tvConfirm.setText(getString(R.string.start_watering));
|
||||
|
||||
@@ -93,6 +93,7 @@
|
||||
<string name="select_watering_duration">请选择浇水时长</string>
|
||||
<string name="start_watering">开启浇水</string>
|
||||
<string name="end_watering">关闭浇水</string>
|
||||
<string name="device_offline_tip">设备已离线</string>
|
||||
<string name="reset_device_provision">该操作需要手动将设备重置到配网模式</string>
|
||||
<string name="device_binding_conflict_message">该设备已被其他用户绑定,您可以登录该账号尝试解绑,或重置设备进入配网模式</string>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user