排程部分功能优化,
解绑,删除,绑定
This commit is contained in:
@@ -2,6 +2,7 @@ package com.ckkj.water.plan;
|
|||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
||||||
@@ -15,11 +16,13 @@ import com.ckkj.water.network.BaseBean;
|
|||||||
//import com.ckkj.water.plan.adapter.PlanDetailTimeAdapter;
|
//import com.ckkj.water.plan.adapter.PlanDetailTimeAdapter;
|
||||||
import com.ckkj.water.plan.adapter.PlanDetailDeviceAdapter;
|
import com.ckkj.water.plan.adapter.PlanDetailDeviceAdapter;
|
||||||
import com.ckkj.water.plan.adapter.PlanDetailTimeAdapter;
|
import com.ckkj.water.plan.adapter.PlanDetailTimeAdapter;
|
||||||
|
import com.ckkj.water.plan.adapter.PlanWeekDaysAdapter;
|
||||||
import com.ckkj.water.plan.entity.WaterPlanWeekEntity;
|
import com.ckkj.water.plan.entity.WaterPlanWeekEntity;
|
||||||
import com.ckkj.water.plan.mvp.WaterPlanContract;
|
import com.ckkj.water.plan.mvp.WaterPlanContract;
|
||||||
import com.ckkj.water.plan.mvp.WaterPlanImpl;
|
import com.ckkj.water.plan.mvp.WaterPlanImpl;
|
||||||
import com.ckkj.water.plan.mvp.WaterPlanPresenter;
|
import com.ckkj.water.plan.mvp.WaterPlanPresenter;
|
||||||
import com.ckkj.water.utils.show.ToastUtil;
|
import com.ckkj.water.utils.show.ToastUtil;
|
||||||
|
import com.ckkj.water.utils.time.ZYTimeUtils;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.gyf.immersionbar.ImmersionBar;
|
import com.gyf.immersionbar.ImmersionBar;
|
||||||
|
|
||||||
@@ -35,7 +38,7 @@ public class PlanDetailActivity extends BaseActivity<WaterPlanDetailLayoutBindin
|
|||||||
private WaterPlanWeekEntity mPlanEntity;
|
private WaterPlanWeekEntity mPlanEntity;
|
||||||
//查询到的排程详情
|
//查询到的排程详情
|
||||||
private WaterPlanWeekEntity mDetailEntity;
|
private WaterPlanWeekEntity mDetailEntity;
|
||||||
private PlanDetailTimeAdapter mAdapter;
|
private PlanWeekDaysAdapter mAdapter;
|
||||||
private PlanDetailDeviceAdapter deviceAdapter;
|
private PlanDetailDeviceAdapter deviceAdapter;
|
||||||
private List<WaterPlanWeekEntity.DetailsBean> mList = new ArrayList<>();
|
private List<WaterPlanWeekEntity.DetailsBean> mList = new ArrayList<>();
|
||||||
|
|
||||||
@@ -62,7 +65,7 @@ public class PlanDetailActivity extends BaseActivity<WaterPlanDetailLayoutBindin
|
|||||||
.init();
|
.init();
|
||||||
viewBinding.includedTitle.tvTitle.setText(R.string.plan_detail_title);
|
viewBinding.includedTitle.tvTitle.setText(R.string.plan_detail_title);
|
||||||
initListener();
|
initListener();
|
||||||
mAdapter = new PlanDetailTimeAdapter(R.layout.plan_detail_time_item,mList);
|
mAdapter = new PlanWeekDaysAdapter(R.layout.single_recycleview_item,mList);
|
||||||
viewBinding.rvPlanTime.setAdapter(mAdapter);
|
viewBinding.rvPlanTime.setAdapter(mAdapter);
|
||||||
List<WaterDeviceEntity> deviceList = new ArrayList<>();
|
List<WaterDeviceEntity> deviceList = new ArrayList<>();
|
||||||
deviceAdapter = new PlanDetailDeviceAdapter(R.layout.plan_detail_bind_device_item,deviceList);
|
deviceAdapter = new PlanDetailDeviceAdapter(R.layout.plan_detail_bind_device_item,deviceList);
|
||||||
@@ -80,7 +83,7 @@ public class PlanDetailActivity extends BaseActivity<WaterPlanDetailLayoutBindin
|
|||||||
// if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
// if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||||
// if (viewBinding.switchButton.isChecked()) {
|
// if (viewBinding.switchButton.isChecked()) {
|
||||||
// // 当前是开启状态,下一步将是关闭 -> 屏蔽动画(时长设为0)
|
// // 当前是开启状态,下一步将是关闭 -> 屏蔽动画(时长设为0)
|
||||||
// viewBinding.switchButton.setAnimationDuration(0);
|
// 0
|
||||||
// } else {
|
// } else {
|
||||||
// // 当前是关闭状态,下一步将是开启 -> 开启动画(恢复默认的 250ms 或你想要的时长)
|
// // 当前是关闭状态,下一步将是开启 -> 开启动画(恢复默认的 250ms 或你想要的时长)
|
||||||
// viewBinding.switchButton.setAnimationDuration(250);
|
// viewBinding.switchButton.setAnimationDuration(250);
|
||||||
@@ -125,31 +128,31 @@ public class PlanDetailActivity extends BaseActivity<WaterPlanDetailLayoutBindin
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case R.id.switch_button://切换状态
|
case R.id.switch_button://切换状态
|
||||||
// 先恢复 Switch 到原始状态,避免点击时立即改变
|
// 先恢复 Switch 到原始状态,避免点击时立即改变
|
||||||
viewBinding.switchButton.setChecked(mDetailEntity.getStatus().equals("1"));
|
viewBinding.switchButton.setChecked(mDetailEntity.getStatus().equals("1"));
|
||||||
if(mDetailEntity.getStatus().equals("1")){
|
if(mDetailEntity.getStatus().equals("1")){
|
||||||
showDialogtext(null, false, false, true,
|
showDialogtext(null, false, false, true,
|
||||||
getString(R.string.tip_text), getString(R.string.close_plan_dialog_tip),
|
getString(R.string.tip_text), getString(R.string.close_plan_dialog_tip),
|
||||||
getString(R.string.cancel_text), getString(R.string.confirm_text), new BaseFragment.OnDialogClick() {
|
getString(R.string.cancel_text), getString(R.string.confirm_text), new BaseFragment.OnDialogClick() {
|
||||||
@Override
|
@Override
|
||||||
public void onCancelClick() {
|
public void onCancelClick() {
|
||||||
// 取消操作,恢复 Switch 状态
|
// 取消操作,恢复 Switch 状态
|
||||||
viewBinding.switchButton.setChecked(true);
|
viewBinding.switchButton.setChecked(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConfirmClick() {
|
public void onConfirmClick() {
|
||||||
// 确认关闭任务,调用接口后再更新 Switch
|
// 确认关闭任务,调用接口后再更新 Switch
|
||||||
showLoadingDialog();
|
showLoadingDialog();
|
||||||
mPresenter.updatePlanStatus(mDetailEntity, "0");
|
mPresenter.updatePlanStatus(mDetailEntity, "0");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}else{
|
}else{
|
||||||
// 开启任务,调用接口后再更新 Switch
|
// 开启任务,调用接口后再更新 Switch
|
||||||
mPresenter.updatePlanStatus(mDetailEntity, "1");
|
mPresenter.updatePlanStatus(mDetailEntity, "1");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -173,7 +176,21 @@ public class PlanDetailActivity extends BaseActivity<WaterPlanDetailLayoutBindin
|
|||||||
List<WaterPlanWeekEntity.DetailsBean> list = new ArrayList<>();
|
List<WaterPlanWeekEntity.DetailsBean> list = new ArrayList<>();
|
||||||
for(WaterPlanWeekEntity.DetailsBean bean : entity.getDetails()){
|
for(WaterPlanWeekEntity.DetailsBean bean : entity.getDetails()){
|
||||||
if(bean.getStatus().equals("1")){
|
if(bean.getStatus().equals("1")){
|
||||||
list.add(bean);
|
// 检查该日期是否有有效的时间配置
|
||||||
|
boolean hasValidTime = false;
|
||||||
|
if(bean.getTimeData() != null){
|
||||||
|
for(WaterPlanWeekEntity.TimeDataBean timeBean : bean.getTimeData()){
|
||||||
|
if(!TextUtils.isEmpty(timeBean.getStartTime())
|
||||||
|
&& timeBean.getDurationMin() != 0){
|
||||||
|
hasValidTime = true;
|
||||||
|
bean.setWeekName(ZYTimeUtils.getWeekName(bean.getWeekday() - 1));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(hasValidTime){
|
||||||
|
list.add(bean);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//日期显示
|
//日期显示
|
||||||
|
|||||||
@@ -1,5 +1,10 @@
|
|||||||
package com.ckkj.water.plan.adapter;
|
package com.ckkj.water.plan.adapter;
|
||||||
|
|
||||||
|
import static android.view.View.INVISIBLE;
|
||||||
|
import static android.view.View.VISIBLE;
|
||||||
|
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.chad.library.adapter.base.BaseQuickAdapter;
|
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||||
@@ -10,15 +15,14 @@ import com.ckkj.water.utils.time.ZYTimeUtils;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class PlanDetailTimeAdapter extends BaseQuickAdapter<WaterPlanWeekEntity.DetailsBean, BaseViewHolder> {
|
public class PlanDetailTimeAdapter extends BaseQuickAdapter<WaterPlanWeekEntity.TimeDataBean, BaseViewHolder> {
|
||||||
|
|
||||||
public PlanDetailTimeAdapter(int layoutResId, @Nullable List<WaterPlanWeekEntity.DetailsBean> data) {
|
public PlanDetailTimeAdapter(int layoutResId, @Nullable List<WaterPlanWeekEntity.TimeDataBean> data) {
|
||||||
super(layoutResId, data);
|
super(layoutResId, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void convert(BaseViewHolder helper, WaterPlanWeekEntity.DetailsBean item) {
|
protected void convert(BaseViewHolder helper, WaterPlanWeekEntity.TimeDataBean item) {
|
||||||
helper.setText(R.id.tv_week, ZYTimeUtils.getWeekName(item.getWeekday() - 1));
|
|
||||||
helper.setText(R.id.tv_start_time,ZYTimeUtils.formatHHmm(item.getStartTime()));
|
helper.setText(R.id.tv_start_time,ZYTimeUtils.formatHHmm(item.getStartTime()));
|
||||||
helper.setText(R.id.tv_duration,item.getDurationMin() + "min");
|
helper.setText(R.id.tv_duration,item.getDurationMin() + "min");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package com.ckkj.water.plan.adapter;
|
||||||
|
|
||||||
|
import android.graphics.Rect;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import com.chad.library.adapter.base.BaseQuickAdapter;
|
||||||
|
import com.chad.library.adapter.base.BaseViewHolder;
|
||||||
|
import com.ckkj.water.R;
|
||||||
|
import com.ckkj.water.plan.entity.WaterPlanWeekEntity;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class PlanWeekDaysAdapter extends BaseQuickAdapter<WaterPlanWeekEntity.DetailsBean, BaseViewHolder> {
|
||||||
|
|
||||||
|
public PlanWeekDaysAdapter(int layoutResId, @Nullable List<WaterPlanWeekEntity.DetailsBean> data) {
|
||||||
|
super(layoutResId, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void convert(BaseViewHolder helper, WaterPlanWeekEntity.DetailsBean item) {
|
||||||
|
helper.setText(R.id.tv_week_name, item.getWeekName());
|
||||||
|
RecyclerView rvWeekDatas = helper.getView(R.id.rv_plan_detail_times);
|
||||||
|
PlanDetailTimeAdapter adapter = new PlanDetailTimeAdapter(R.layout.plan_detail_time_item, item.getTimeData());
|
||||||
|
rvWeekDatas.setAdapter(adapter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
|
||||||
|
super.onAttachedToRecyclerView(recyclerView);
|
||||||
|
// 添加透明色分割线,高度10px
|
||||||
|
recyclerView.addItemDecoration(new RecyclerView.ItemDecoration() {
|
||||||
|
@Override
|
||||||
|
public void getItemOffsets(Rect outRect, View view,
|
||||||
|
RecyclerView parent, RecyclerView.State state) {
|
||||||
|
int position = parent.getChildAdapterPosition(view);
|
||||||
|
if (position > 0) {
|
||||||
|
outRect.top = (int) (10 * view.getContext().getResources().getDisplayMetrics().density);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDraw(android.graphics.Canvas c, RecyclerView parent, RecyclerView.State state) {
|
||||||
|
// 不绘制任何内容,保持透明
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -72,5 +72,6 @@ public class WaterPlanWeekEntity implements Serializable {
|
|||||||
public static class TimeDataBean implements Serializable{
|
public static class TimeDataBean implements Serializable{
|
||||||
private String startTime = "";
|
private String startTime = "";
|
||||||
private int durationMin = 0;
|
private int durationMin = 0;
|
||||||
|
private String weekName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center_vertical">
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@@ -45,5 +46,4 @@
|
|||||||
android:textColor="@color/color_zhu"
|
android:textColor="@color/color_zhu"
|
||||||
android:textSize="14sp" />
|
android:textSize="14sp" />
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -10,41 +10,34 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:layout_marginBottom="@dimen/dp_15">
|
android:layout_marginBottom="@dimen/dp_10">
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tv_week"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:paddingHorizontal="@dimen/dp_12"
|
|
||||||
android:gravity="center"
|
|
||||||
android:text="周一"
|
|
||||||
android:textColor="@color/color_666666"
|
|
||||||
android:textSize="14sp" />
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tv_start_time"
|
android:id="@+id/tv_start_time"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
android:paddingHorizontal="@dimen/dp_12"
|
android:paddingHorizontal="@dimen/dp_12"
|
||||||
android:gravity="center"
|
android:gravity="left"
|
||||||
android:text="10:30"
|
android:text="10:30"
|
||||||
android:textColor="@color/color_666666"
|
android:textColor="@color/color_666666"
|
||||||
android:textSize="14sp" />
|
android:textSize="14sp" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tv_duration"
|
android:id="@+id/tv_duration"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
android:paddingHorizontal="@dimen/dp_12"
|
android:paddingHorizontal="@dimen/dp_12"
|
||||||
android:gravity="center"
|
android:gravity="left"
|
||||||
android:text="10min"
|
android:text="10min"
|
||||||
android:textColor="@color/color_666666"
|
android:textColor="@color/color_666666"
|
||||||
android:textSize="14sp" />
|
android:textSize="14sp" />
|
||||||
<View
|
<View
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="3"/>
|
android:layout_weight="1"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
25
app/src/main/res/layout/single_recycleview_item.xml
Normal file
25
app/src/main/res/layout/single_recycleview_item.xml
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tv_week_name"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="2"
|
||||||
|
android:textSize="14sp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:textColor="@color/color_222222"
|
||||||
|
android:text="周一"/>
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/rv_plan_detail_times"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="8"
|
||||||
|
tools:listitem="@layout/plan_detail_time_item"
|
||||||
|
tools:itemCount="2"
|
||||||
|
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"/>
|
||||||
|
</LinearLayout>
|
||||||
@@ -76,8 +76,8 @@
|
|||||||
android:id="@+id/rv_plan_time"
|
android:id="@+id/rv_plan_time"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
tools:listitem="@layout/plan_detail_time_item"
|
tools:listitem="@layout/single_recycleview_item"
|
||||||
tools:itemCount="5"
|
tools:itemCount="3"
|
||||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"/>
|
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
@@ -93,7 +93,7 @@
|
|||||||
<TextView
|
<TextView
|
||||||
android:layout_width="82dp"
|
android:layout_width="82dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/water_device_bind"
|
android:text="@string/water_bound_device"
|
||||||
android:textColor="@color/color_222222"
|
android:textColor="@color/color_222222"
|
||||||
android:textSize="16sp" />
|
android:textSize="16sp" />
|
||||||
|
|
||||||
@@ -102,7 +102,8 @@
|
|||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical"
|
||||||
|
android:paddingLeft="@dimen/dp_20">
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/rv_bind_devices"
|
android:id="@+id/rv_bind_devices"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
Reference in New Issue
Block a user