优化浇水流程,以及中英文遗漏点
This commit is contained in:
@@ -22,6 +22,7 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
@@ -1016,6 +1017,16 @@ public abstract class BaseFragment<T extends ViewBinding,P extends IPresenter> e
|
|||||||
|
|
||||||
dialog = builder.show();
|
dialog = builder.show();
|
||||||
|
|
||||||
|
editText.requestFocus();
|
||||||
|
editText.postDelayed(() -> {
|
||||||
|
if (editText != null) {
|
||||||
|
InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
|
if (imm != null) {
|
||||||
|
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 200);
|
||||||
|
|
||||||
dialog.setCanceledOnTouchOutside(
|
dialog.setCanceledOnTouchOutside(
|
||||||
touchOutsideCancel
|
touchOutsideCancel
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ public class WaterConfigFragment extends BaseFragment<WaterConfigFragmentLayoutC
|
|||||||
timeDataList.add(timeData);
|
timeDataList.add(timeData);
|
||||||
bean.setTimeData(timeDataList);
|
bean.setTimeData(timeDataList);
|
||||||
bean.setWeekday(i + 1);
|
bean.setWeekday(i + 1);
|
||||||
bean.setStatus("1");
|
bean.setStatus("0");
|
||||||
bean.setWeekName(ZYTimeUtils.getWeekName(i,mContext));
|
bean.setWeekName(ZYTimeUtils.getWeekName(i,mContext));
|
||||||
bean.setTriggerType("0");
|
bean.setTriggerType("0");
|
||||||
list.add(bean);
|
list.add(bean);
|
||||||
|
|||||||
@@ -1,412 +0,0 @@
|
|||||||
package com.ckkj.water.plan;
|
|
||||||
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.text.Editable;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.text.TextWatcher;
|
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
import com.bigkoo.pickerview.builder.TimePickerBuilder;
|
|
||||||
import com.bigkoo.pickerview.listener.OnTimeSelectListener;
|
|
||||||
import com.bigkoo.pickerview.view.TimePickerView;
|
|
||||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
|
||||||
import com.ckkj.water.R;
|
|
||||||
import com.ckkj.water.base.BaseActivity;
|
|
||||||
import com.ckkj.water.base.BaseFragment;
|
|
||||||
import com.ckkj.water.databinding.WaterConfigFragmentLayoutBinding;
|
|
||||||
import com.ckkj.water.index.entity.WaterDeviceEntity;
|
|
||||||
import com.ckkj.water.network.BaseBean;
|
|
||||||
import com.ckkj.water.plan.adapter.WaterPlanWeekAdapter;
|
|
||||||
import com.ckkj.water.plan.entity.WaterPlanWeekEntity;
|
|
||||||
import com.ckkj.water.plan.mvp.WaterPlanContract;
|
|
||||||
import com.ckkj.water.plan.mvp.WaterPlanImpl;
|
|
||||||
import com.ckkj.water.plan.mvp.WaterPlanPresenter;
|
|
||||||
import com.ckkj.water.utils.show.ToastUtil;
|
|
||||||
import com.ckkj.water.utils.time.ZYTimeUtils;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 配置信息页面
|
|
||||||
*/
|
|
||||||
public class WaterConfigFragment2 extends BaseFragment<WaterConfigFragmentLayoutBinding, WaterPlanPresenter>
|
|
||||||
implements WaterPlanContract.WaterPlanView {
|
|
||||||
private List<WaterPlanWeekEntity.DetailsBean> mConfigList = new ArrayList<>();
|
|
||||||
//用户本地操作排程时的数据
|
|
||||||
private WaterPlanWeekEntity mConfigEntity;
|
|
||||||
//排程接口新增成功之后,接口返回的该排程在远端的数据信息
|
|
||||||
private WaterPlanWeekEntity mRemoteConfigEntity;
|
|
||||||
private WaterPlanWeekAdapter mWeekAdapter;
|
|
||||||
private String mPlanName = "";
|
|
||||||
public static boolean isConfigSave;
|
|
||||||
//当下是否编辑模式
|
|
||||||
private boolean mIsEditMode = false;
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void initData(Bundle state) {
|
|
||||||
mConfigEntity = new WaterPlanWeekEntity();
|
|
||||||
List<WaterPlanWeekEntity.DetailsBean> list = new ArrayList<>();
|
|
||||||
for(int i = 0; i < 7; i++){
|
|
||||||
WaterPlanWeekEntity.DetailsBean bean = new WaterPlanWeekEntity.DetailsBean();
|
|
||||||
bean.setWeekday(i + 1);
|
|
||||||
bean.setStatus("0");
|
|
||||||
bean.setWeekName(ZYTimeUtils.getWeekName(i,mContext));
|
|
||||||
list.add(bean);
|
|
||||||
}
|
|
||||||
mConfigEntity.setDetails(list);
|
|
||||||
mWeekAdapter = new WaterPlanWeekAdapter(mContext,R.layout.plan_week_config_item, mConfigEntity.getDetails());
|
|
||||||
viewBinding.rvWeekConfig.setAdapter(mWeekAdapter);
|
|
||||||
initListener();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 设置编辑模式的排程数据
|
|
||||||
* @param entity 从详情页传来的排程数据
|
|
||||||
*/
|
|
||||||
public void setEditEntity(WaterPlanWeekEntity entity) {
|
|
||||||
if (entity == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mIsEditMode = true;
|
|
||||||
// 深拷贝数据到 mConfigEntity,用于本地编辑
|
|
||||||
mConfigEntity = cloneEntity(entity);
|
|
||||||
// 保存远程原始数据,用于后续变化检测
|
|
||||||
mRemoteConfigEntity = entity;
|
|
||||||
isConfigSave = true;
|
|
||||||
|
|
||||||
// 初始化 UI
|
|
||||||
viewBinding.etPlanName.setText(entity.getName());
|
|
||||||
mPlanName = entity.getName();
|
|
||||||
|
|
||||||
// 更新周配置列表的显示,使用 mConfigEntity.getDetails() 保证数据一致
|
|
||||||
if (mConfigEntity.getDetails() != null) {
|
|
||||||
mWeekAdapter.setNewData(mConfigEntity.getDetails());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 深拷贝 WaterPlanWeekEntity
|
|
||||||
*/
|
|
||||||
private WaterPlanWeekEntity cloneEntity(WaterPlanWeekEntity source) {
|
|
||||||
if (source == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
WaterPlanWeekEntity target = new WaterPlanWeekEntity();
|
|
||||||
target.setId(source.getId());
|
|
||||||
target.setName(source.getName());
|
|
||||||
target.setStatus(source.getStatus());
|
|
||||||
|
|
||||||
if (source.getDetails() != null) {
|
|
||||||
List<WaterPlanWeekEntity.DetailsBean> detailsList = new ArrayList<>();
|
|
||||||
for (WaterPlanWeekEntity.DetailsBean bean : source.getDetails()) {
|
|
||||||
WaterPlanWeekEntity.DetailsBean newBean = new WaterPlanWeekEntity.DetailsBean();
|
|
||||||
newBean.setId(bean.getId());
|
|
||||||
newBean.setWeekday(bean.getWeekday());
|
|
||||||
newBean.setWeekName(ZYTimeUtils.getWeekName(bean.getWeekday() - 1,mContext));
|
|
||||||
newBean.setStatus(bean.getStatus());
|
|
||||||
newBean.setStartTime(ZYTimeUtils.formatHHmm(bean.getStartTime()));
|
|
||||||
newBean.setDurationMin(bean.getDurationMin());
|
|
||||||
detailsList.add(newBean);
|
|
||||||
}
|
|
||||||
target.setDetails(detailsList);
|
|
||||||
}
|
|
||||||
|
|
||||||
return target;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initListener() {
|
|
||||||
setClick(viewBinding.tvCommit);
|
|
||||||
mWeekAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
|
|
||||||
switch (view.getId()){
|
|
||||||
case R.id.linear_week://选中
|
|
||||||
case R.id.checkbox:
|
|
||||||
if(mConfigEntity.getDetails().get(position).getStatus().equals("1")){
|
|
||||||
mConfigEntity.getDetails().get(position).setStatus("0");
|
|
||||||
}else{
|
|
||||||
mConfigEntity.getDetails().get(position).setStatus("1");
|
|
||||||
}
|
|
||||||
mWeekAdapter.notifyItemChanged(position);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case R.id.tv_select_time:
|
|
||||||
selectStartTime(position);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case R.id.tv_plan_duration:
|
|
||||||
inputDuration(position);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
viewBinding.etPlanName.addTextChangedListener(new TextWatcher() {
|
|
||||||
@Override
|
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterTextChanged(Editable s) {
|
|
||||||
if(!TextUtils.isEmpty(s.toString())){
|
|
||||||
mPlanName = s.toString();
|
|
||||||
mConfigEntity.setName(s.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onClick(View v){
|
|
||||||
switch (v.getId()){
|
|
||||||
case R.id.tv_commit:
|
|
||||||
commitConfig();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void commitConfig(){
|
|
||||||
if (!checkConfigFinish()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// mRemoteConfigEntity 为空,说明是新增场景
|
|
||||||
if (mRemoteConfigEntity == null) {
|
|
||||||
mPresenter.saveConfig(mConfigEntity);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// mRemoteConfigEntity 不为空,说明是更新场景
|
|
||||||
if (isConfigChanged()) {
|
|
||||||
// TODO: 触发更新接口,调用 mPresenter.updateConfig(mConfigEntity)
|
|
||||||
mPresenter.updateConfig(mConfigEntity);
|
|
||||||
} else {
|
|
||||||
ToastUtil.showShort(mContext, "配置没有变化,无需保存");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void inputDuration(int position) {
|
|
||||||
showEditDialog(getString(R.string.device_work_times_title),
|
|
||||||
getString(R.string.input_water_plan_time),
|
|
||||||
mConfigEntity.getDetails().get(position).getDurationMin() == 0 ?
|
|
||||||
"" : mConfigEntity.getDetails().get(position).getDurationMin() + "",
|
|
||||||
true,
|
|
||||||
getString(R.string.cancel_text),
|
|
||||||
getString(R.string.confirm_text),
|
|
||||||
BaseFragment.INPUT_TYPE_NUMBER,
|
|
||||||
new BaseActivity.OnDialogClick() {
|
|
||||||
@Override
|
|
||||||
public void onCancelClick() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onConfirmClisk() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onConfirmClisk(String content) {
|
|
||||||
if(Integer.parseInt(content) <= 0){
|
|
||||||
ToastUtil.showShort(mContext, getString(R.string.input_water_plan_time_error));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mConfigEntity.getDetails().get(position).setDurationMin(Integer.parseInt(content));
|
|
||||||
mWeekAdapter.notifyItemChanged(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onView1Click() {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void selectStartTime(int position) {
|
|
||||||
boolean times[] = {false, false, false, true, true, false};
|
|
||||||
//时间选择器
|
|
||||||
TimePickerView pvTime = new TimePickerBuilder(mContext, new OnTimeSelectListener() {
|
|
||||||
@Override
|
|
||||||
public void onTimeSelect(Date date, View v) {
|
|
||||||
//用于提交接口
|
|
||||||
mConfigEntity.getDetails().get(position).setStartTime(ZYTimeUtils.getStrTimeData_H_M(date));
|
|
||||||
mWeekAdapter.notifyItemChanged(position);
|
|
||||||
}
|
|
||||||
}).setType(times)
|
|
||||||
.setCancelColor(mContext.getColor(R.color.color_999999))
|
|
||||||
.setSubmitColor(mContext.getColor(R.color.color_zhu))
|
|
||||||
.setTextColorCenter(mContext.getColor(R.color.color_zhu))
|
|
||||||
.build();
|
|
||||||
pvTime.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setClick(View view) {
|
|
||||||
view.setOnClickListener(this::onClick);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 比较本地配置和远程配置是否有变化
|
|
||||||
* @return true 表示有变化,false 表示无变化
|
|
||||||
*/
|
|
||||||
public boolean isConfigChanged() {
|
|
||||||
if (mRemoteConfigEntity == null || mRemoteConfigEntity.getDetails() == null) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// 比对排程名称
|
|
||||||
if (!equalsString(mConfigEntity.getName(), mRemoteConfigEntity.getName())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
List<WaterPlanWeekEntity.DetailsBean> localDetails = mConfigEntity.getDetails();
|
|
||||||
List<WaterPlanWeekEntity.DetailsBean> remoteDetails = mRemoteConfigEntity.getDetails();
|
|
||||||
for (int i = 0; i < localDetails.size(); i++) {
|
|
||||||
WaterPlanWeekEntity.DetailsBean local = localDetails.get(i);
|
|
||||||
WaterPlanWeekEntity.DetailsBean remote = remoteDetails.get(i);
|
|
||||||
// 勾选状态下对比状态、时间、时长
|
|
||||||
if ("1".equals(local.getStatus())) {
|
|
||||||
if (!equalsString(local.getStatus(), remote.getStatus())
|
|
||||||
|| !equalsString(local.getStartTime(), ZYTimeUtils.formatHHmm(remote.getStartTime()))
|
|
||||||
|| local.getDurationMin() != remote.getDurationMin()) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 未勾选状态下只对比勾选状态,不关心时间/时长
|
|
||||||
if (!equalsString(local.getStatus(), remote.getStatus())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean equalsString(String s1, String s2) {
|
|
||||||
if (s1 == null && s2 == null) return true;
|
|
||||||
if (s1 == null || s2 == null) return false;
|
|
||||||
return s1.equals(s2);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 检查配置信息是否完成
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public boolean checkConfigFinish() {
|
|
||||||
if(TextUtils.isEmpty(viewBinding.etPlanName.getText().toString())){
|
|
||||||
ToastUtil.showShort(mContext,getString(R.string.plan_name_text_empty_hint));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
List<WaterPlanWeekEntity.DetailsBean> list = mConfigEntity.getDetails();
|
|
||||||
//是否勾选了排程日期
|
|
||||||
boolean isSelectOne = false;
|
|
||||||
if(list != null){
|
|
||||||
for(WaterPlanWeekEntity.DetailsBean bean : list){
|
|
||||||
if(bean.getStatus().equals("1")){
|
|
||||||
isSelectOne = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!isSelectOne){
|
|
||||||
ToastUtil.showShort(mContext,getString(R.string.plan_week_empty_hint));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
//是否配置了排程日期的时间
|
|
||||||
boolean isPlanConfig = false;
|
|
||||||
for(WaterPlanWeekEntity.DetailsBean bean : list){
|
|
||||||
if(bean.getStatus().equals("1")){
|
|
||||||
if((TextUtils.isEmpty(bean.getStartTime()) ||
|
|
||||||
bean.getDurationMin() == 0)){
|
|
||||||
ToastUtil.showShort(mContext,"请完成" + bean.getWeekName() + "的时间配置");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void getWaterConfigListSuccess(List<WaterPlanWeekEntity> list,int total) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void saveConfigSuccess(WaterPlanWeekEntity entity) {
|
|
||||||
ToastUtil.showShort(mContext, "排程新增成功");
|
|
||||||
isConfigSave = true;
|
|
||||||
// 把接口返回的 ID 设置到 mConfigEntity,便于后续更新操作
|
|
||||||
mConfigEntity.setId(entity.getId());
|
|
||||||
// 把 details 中每个 bean 的 id 也设置到 mConfigEntity,便于后续更新操作
|
|
||||||
if (entity.getDetails() != null && mConfigEntity.getDetails() != null) {
|
|
||||||
for (int i = 0; i < entity.getDetails().size() && i < mConfigEntity.getDetails().size(); i++) {
|
|
||||||
mConfigEntity.getDetails().get(i).setId(entity.getDetails().get(i).getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//接口请求之后返回的数据,方便后面做对比
|
|
||||||
mRemoteConfigEntity = entity;
|
|
||||||
if (getActivity() instanceof AddWaterPlanActivity) {
|
|
||||||
((AddWaterPlanActivity) getActivity()).onConfigSaved(entity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新排程成功
|
|
||||||
* @param entity
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void updateConfigSuccess(WaterPlanWeekEntity entity) {
|
|
||||||
ToastUtil.showShort(mContext, "排程更新成功");
|
|
||||||
mRemoteConfigEntity = entity;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updatePlanStatusSuccess(BaseBean bean, String status) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void getPlanDetailInfo(WaterPlanWeekEntity entity) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void getPlanBindDeviceList(WaterDeviceEntity bean) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void planBindDeviceSuccess(BaseBean bean) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void deletePlanSuccess(BaseBean bean) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void planUnbindDeviceSuccess(BaseBean bean, int position) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public WaterPlanPresenter createPresenter() {
|
|
||||||
return new WaterPlanPresenter(new WaterPlanImpl());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNetChange(int netModel) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void showError(String message) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void logOut(BaseBean bean) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user