|
@@ -11,11 +11,16 @@ import androidx.annotation.Nullable;
|
|
|
import androidx.fragment.app.Fragment;
|
|
|
|
|
|
import com.blankj.utilcode.util.LogUtils;
|
|
|
+import com.example.chemical.R;
|
|
|
import com.example.chemical.databinding.FragmentLockerBinding;
|
|
|
import com.example.chemical.ui.plan.FragmentCallBack;
|
|
|
+import com.example.chemical.ui.plan.room.RoomTool;
|
|
|
import com.example.chemical.ui.plan.room.bean.locker.HxpCabinetDoorVo;
|
|
|
import com.example.chemical.ui.plan.room.bean.locker.HxpCabinetVo;
|
|
|
import com.example.chemical.ui.plan.room.bean.locker.CabinetLayerSelect;
|
|
|
+import com.example.chemical.ui.plan.room.dao.HxpCabinetDAO;
|
|
|
+import com.example.chemical.ui.plan.room.dao.HxpDoorDAO;
|
|
|
+import com.example.chemical.ui.plan.room.dao.HxpLayerDAO;
|
|
|
|
|
|
import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
@@ -23,16 +28,23 @@ import java.util.List;
|
|
|
public class LockerFragment extends Fragment {
|
|
|
private FragmentLockerBinding binding;
|
|
|
|
|
|
- // 柜子信息
|
|
|
- private HxpCabinetVo hxpCabinetVo;
|
|
|
// 上柜门柜层
|
|
|
private List<DrawerUiBean> drawerUiUpList = new LinkedList<>();
|
|
|
// 下柜门柜层
|
|
|
private List<DrawerUiBean> drawerUiDownList = new LinkedList<>();
|
|
|
private FragmentCallBack fragmentCallBack;
|
|
|
|
|
|
- public LockerFragment(HxpCabinetVo hxpCabinetVo, FragmentCallBack fragmentCallBack) {
|
|
|
- this.hxpCabinetVo = hxpCabinetVo;
|
|
|
+ private List<HxpCabinetDoorVo> doorVoList;
|
|
|
+
|
|
|
+ // 柜子
|
|
|
+ private long cabinetId;
|
|
|
+ private HxpCabinetDAO hxpCabinetDAO;
|
|
|
+ private HxpDoorDAO hxpDoorDAO;
|
|
|
+ private HxpLayerDAO hxpLayerDAO;
|
|
|
+ private HxpCabinetVo hxpCabinetVo;
|
|
|
+
|
|
|
+ public LockerFragment(long cabinetId, FragmentCallBack fragmentCallBack) {
|
|
|
+ this.cabinetId = cabinetId;
|
|
|
this.fragmentCallBack = fragmentCallBack;
|
|
|
}
|
|
|
|
|
@@ -44,12 +56,22 @@ public class LockerFragment extends Fragment {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
|
|
- super.onViewCreated(view, savedInstanceState);
|
|
|
- if (savedInstanceState != null) {
|
|
|
- drawerUiUpList.clear();
|
|
|
- drawerUiDownList.clear();
|
|
|
- }
|
|
|
+ public void onResume() {
|
|
|
+ super.onResume();
|
|
|
+ updateUi();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onPause() {
|
|
|
+ super.onPause();
|
|
|
+ updateUi();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void updateUi() {
|
|
|
+ drawerUiUpList.clear();
|
|
|
+ drawerUiDownList.clear();
|
|
|
+ binding.lockerUpDrawerRG.clearCheck();
|
|
|
+ binding.lockerDownDrawerRG.clearCheck();
|
|
|
// 上柜view控制
|
|
|
drawerUiUpList.add(new DrawerUiBean(binding.lockerUpDrawer1RB, binding.lockerUpDrawer1TV, false));
|
|
|
drawerUiUpList.add(new DrawerUiBean(binding.lockerUpDrawer2RB, binding.lockerUpDrawer2TV, false));
|
|
@@ -66,84 +88,121 @@ public class LockerFragment extends Fragment {
|
|
|
drawerUiDownList.add(new DrawerUiBean(binding.lockerDownDrawer3RB, binding.lockerDownDrawer3TV, false));
|
|
|
drawerUiDownList.add(new DrawerUiBean(binding.lockerDownDrawer4RB, binding.lockerDownDrawer4TV, false));
|
|
|
|
|
|
+ hxpCabinetDAO = RoomTool.getInstance().hxpCabinetDAO();
|
|
|
+ hxpDoorDAO = RoomTool.getInstance().hxpDoorDAO();
|
|
|
+ hxpLayerDAO = RoomTool.getInstance().hxpLayerDAO();
|
|
|
+ hxpCabinetVo = hxpCabinetDAO.getById(cabinetId);
|
|
|
+ // 所有柜门
|
|
|
+ doorVoList = hxpDoorDAO.getByCabinetId(cabinetId);
|
|
|
for (int i = 0; i < drawerUiUpList.size(); i++) {
|
|
|
drawerUiUpList.get(i).getRadioButton().setOnClickListener(onClickDoorUpListener);
|
|
|
}
|
|
|
for (int i = 0; i < drawerUiDownList.size(); i++) {
|
|
|
drawerUiDownList.get(i).getRadioButton().setOnClickListener(onClickDoorDownListener);
|
|
|
}
|
|
|
- // 所有柜门
|
|
|
- List<HxpCabinetDoorVo> doorVoList = hxpCabinetVo.getCabinetDoorVoList();
|
|
|
-
|
|
|
- // 柜子名称
|
|
|
- String cabinetName = hxpCabinetVo.getCabinetName();
|
|
|
- binding.lockerNameTV.setText(TextUtils.isEmpty(cabinetName) ? "" : cabinetName);
|
|
|
-
|
|
|
- // 一个柜门
|
|
|
- if (doorVoList.size() == 1) {
|
|
|
- HxpCabinetDoorVo hxpCabinetDoorVo = doorVoList.get(0);
|
|
|
- // 柜门名称
|
|
|
- String doorName = hxpCabinetDoorVo.getDoorName();
|
|
|
- binding.upDoorNameTV.setText(TextUtils.isEmpty(doorName) ? "" : doorName);
|
|
|
- // 层数
|
|
|
- int doorLayers = hxpCabinetDoorVo.getDoorLayers();
|
|
|
- for (int i = 0; i < 8; i++) {
|
|
|
- DrawerUiBean drawerUiBean = drawerUiUpList.get(i);
|
|
|
- drawerUiBean.setVisible(i < doorLayers);
|
|
|
- }
|
|
|
+ if (null != doorVoList) {
|
|
|
+ // 柜子名称
|
|
|
+ String cabinetName = hxpCabinetVo.getCabinetName();
|
|
|
+ binding.lockerNameTV.setText(TextUtils.isEmpty(cabinetName) ? "" : cabinetName);
|
|
|
+ // 选中的柜层信息
|
|
|
+ CabinetLayerSelect cabinetLayerSelect = hxpLayerDAO.getCabinetChanged(cabinetId);
|
|
|
+ // 一个柜门
|
|
|
+ if (doorVoList.size() == 1) {
|
|
|
+ HxpCabinetDoorVo hxpCabinetDoorVo = doorVoList.get(0);
|
|
|
+ binding.cabinetRL.setBackgroundResource(R.mipmap.locker_one);
|
|
|
+ // 柜门名称
|
|
|
+ String doorName = hxpCabinetDoorVo.getDoorName();
|
|
|
+ binding.upDoorNameTV.setText(TextUtils.isEmpty(doorName) ? "" : doorName);
|
|
|
+ // 选中的柜层
|
|
|
+ int layer = -1;
|
|
|
+ if (null != cabinetLayerSelect) {
|
|
|
+ if (hxpCabinetDoorVo.getDoorId() == cabinetLayerSelect.getDoorId()) {
|
|
|
+ layer = cabinetLayerSelect.getLayer();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 层数
|
|
|
+ int doorLayers = hxpCabinetDoorVo.getDoorLayers();
|
|
|
+ for (int i = 0; i < 8; i++) {
|
|
|
+ DrawerUiBean drawerUiBean = drawerUiUpList.get(i);
|
|
|
+ drawerUiBean.setVisible(i < doorLayers);
|
|
|
+ }
|
|
|
|
|
|
- for (int i = 0; i < drawerUiUpList.size(); i++) {
|
|
|
- DrawerUiBean drawerUiBean = drawerUiUpList.get(i);
|
|
|
- if (drawerUiBean.isVisible()) {
|
|
|
- drawerUiBean.getRadioButton().setVisibility(View.VISIBLE);
|
|
|
- drawerUiBean.getTextView().setVisibility(View.VISIBLE);
|
|
|
+ for (int i = 0; i < drawerUiUpList.size(); i++) {
|
|
|
+ DrawerUiBean drawerUiBean = drawerUiUpList.get(i);
|
|
|
+ if (drawerUiBean.isVisible()) {
|
|
|
+ drawerUiBean.getRadioButton().setVisibility(View.VISIBLE);
|
|
|
+ drawerUiBean.getTextView().setVisibility(View.VISIBLE);
|
|
|
+ if (layer > 0 && (i + 1) == layer) {
|
|
|
+ drawerUiBean.getRadioButton().setChecked(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- // 两个柜门
|
|
|
- else if (doorVoList.size() > 1) {
|
|
|
- // 上柜门
|
|
|
- HxpCabinetDoorVo hxpCabinetDoorUpVo = doorVoList.get(0);
|
|
|
- String doorName = hxpCabinetDoorUpVo.getDoorName();
|
|
|
- binding.upDoorNameTV.setText(TextUtils.isEmpty(doorName) ? "" : doorName);
|
|
|
- // 层数
|
|
|
- int doorUpLayers = hxpCabinetDoorUpVo.getDoorLayers();
|
|
|
- for (int i = 0; i < 4; i++) {
|
|
|
- DrawerUiBean drawerUiBean = drawerUiUpList.get(i);
|
|
|
- drawerUiBean.setVisible(i < doorUpLayers);
|
|
|
- }
|
|
|
+ // 两个柜门
|
|
|
+ else if (doorVoList.size() > 1) {
|
|
|
+ // 上柜门
|
|
|
+ HxpCabinetDoorVo hxpCabinetDoorUpVo = doorVoList.get(0);
|
|
|
+ binding.cabinetRL.setBackgroundResource(R.mipmap.locker);
|
|
|
+ String doorName = hxpCabinetDoorUpVo.getDoorName();
|
|
|
+ binding.upDoorNameTV.setText(TextUtils.isEmpty(doorName) ? "" : doorName);
|
|
|
+ int layerUp = -1;
|
|
|
+ if (null != cabinetLayerSelect) {
|
|
|
+ if (hxpCabinetDoorUpVo.getDoorId() == cabinetLayerSelect.getDoorId()) {
|
|
|
+ layerUp = cabinetLayerSelect.getLayer();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 层数
|
|
|
+ int doorUpLayers = hxpCabinetDoorUpVo.getDoorLayers();
|
|
|
+ for (int i = 0; i < 4; i++) {
|
|
|
+ DrawerUiBean drawerUiBean = drawerUiUpList.get(i);
|
|
|
+ drawerUiBean.setVisible(i < doorUpLayers);
|
|
|
+ }
|
|
|
|
|
|
- for (int i = 0; i < drawerUiUpList.size(); i++) {
|
|
|
- DrawerUiBean drawerUiBean = drawerUiUpList.get(i);
|
|
|
- if (drawerUiBean.isVisible()) {
|
|
|
- drawerUiBean.getRadioButton().setVisibility(View.VISIBLE);
|
|
|
- drawerUiBean.getTextView().setVisibility(View.VISIBLE);
|
|
|
+ for (int i = 0; i < drawerUiUpList.size(); i++) {
|
|
|
+ DrawerUiBean drawerUiBean = drawerUiUpList.get(i);
|
|
|
+ if (drawerUiBean.isVisible()) {
|
|
|
+ drawerUiBean.getRadioButton().setVisibility(View.VISIBLE);
|
|
|
+ drawerUiBean.getTextView().setVisibility(View.VISIBLE);
|
|
|
+ if (layerUp > 0 && (i + 1) == layerUp) {
|
|
|
+ drawerUiBean.getRadioButton().setChecked(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- binding.lockerDownDrawerLL.setVisibility(View.VISIBLE);
|
|
|
- binding.lockerDownDrawerRG.setVisibility(View.VISIBLE);
|
|
|
-
|
|
|
- // 下柜门
|
|
|
- HxpCabinetDoorVo hxpCabinetDoorDownVo = doorVoList.get(1);
|
|
|
- String doorDownName = hxpCabinetDoorDownVo.getDoorName();
|
|
|
- binding.downDoorNameTV.setText(TextUtils.isEmpty(doorDownName) ? "" : doorDownName);
|
|
|
- // 层数
|
|
|
- int doorDownLayers = hxpCabinetDoorDownVo.getDoorLayers();
|
|
|
- for (int i = 0; i < 4; i++) {
|
|
|
- DrawerUiBean drawerUiBean = drawerUiDownList.get(i);
|
|
|
- drawerUiBean.setVisible(i < doorDownLayers);
|
|
|
- }
|
|
|
+ binding.lockerDownDrawerLL.setVisibility(View.VISIBLE);
|
|
|
+ binding.lockerDownDrawerRG.setVisibility(View.VISIBLE);
|
|
|
+
|
|
|
+ // 下柜门
|
|
|
+ HxpCabinetDoorVo hxpCabinetDoorDownVo = doorVoList.get(1);
|
|
|
+ String doorDownName = hxpCabinetDoorDownVo.getDoorName();
|
|
|
+ binding.downDoorNameTV.setText(TextUtils.isEmpty(doorDownName) ? "" : doorDownName);
|
|
|
+ int layerDown = -1;
|
|
|
+ if (null != cabinetLayerSelect) {
|
|
|
+ if (hxpCabinetDoorDownVo.getDoorId() == cabinetLayerSelect.getDoorId()) {
|
|
|
+ layerDown = cabinetLayerSelect.getLayer();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 层数
|
|
|
+ int doorDownLayers = hxpCabinetDoorDownVo.getDoorLayers();
|
|
|
+ for (int i = 0; i < 4; i++) {
|
|
|
+ DrawerUiBean drawerUiBean = drawerUiDownList.get(i);
|
|
|
+ drawerUiBean.setVisible(i < doorDownLayers);
|
|
|
+ }
|
|
|
|
|
|
- for (int i = 0; i < drawerUiDownList.size(); i++) {
|
|
|
- DrawerUiBean drawerUiBean = drawerUiDownList.get(i);
|
|
|
- if (drawerUiBean.isVisible()) {
|
|
|
- drawerUiBean.getRadioButton().setVisibility(View.VISIBLE);
|
|
|
- drawerUiBean.getTextView().setVisibility(View.VISIBLE);
|
|
|
+ for (int i = 0; i < drawerUiDownList.size(); i++) {
|
|
|
+ DrawerUiBean drawerUiBean = drawerUiDownList.get(i);
|
|
|
+ if (drawerUiBean.isVisible()) {
|
|
|
+ drawerUiBean.getRadioButton().setVisibility(View.VISIBLE);
|
|
|
+ drawerUiBean.getTextView().setVisibility(View.VISIBLE);
|
|
|
+ if (layerDown > 0 && (i + 1) == layerDown) {
|
|
|
+ drawerUiBean.getRadioButton().setChecked(true);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private final View.OnClickListener onClickDoorUpListener = new View.OnClickListener() {
|
|
@@ -167,8 +226,7 @@ public class LockerFragment extends Fragment {
|
|
|
} else if (binding.lockerUpDrawer8RB.getId() == v.getId()) {
|
|
|
layer = 8;
|
|
|
}
|
|
|
- LogUtils.d("上柜", layer + "层");
|
|
|
- fragmentCallBack.onSelected(new CabinetLayerSelect(hxpCabinetVo.getCabinetId(), hxpCabinetVo.getCabinetDoorVoList().get(0).getDoorId(), layer));
|
|
|
+ fragmentCallBack.onSelected(new CabinetLayerSelect(hxpCabinetVo.getCabinetId(), doorVoList.get(0).getDoorId(), layer));
|
|
|
}
|
|
|
};
|
|
|
private final View.OnClickListener onClickDoorDownListener = new View.OnClickListener() {
|
|
@@ -185,8 +243,13 @@ public class LockerFragment extends Fragment {
|
|
|
layer = 4;
|
|
|
}
|
|
|
LogUtils.d("下柜", layer + "层");
|
|
|
- fragmentCallBack.onSelected(new CabinetLayerSelect(hxpCabinetVo.getCabinetId(), hxpCabinetVo.getCabinetDoorVoList().get(1).getDoorId(), layer));
|
|
|
+ fragmentCallBack.onSelected(new CabinetLayerSelect(hxpCabinetVo.getCabinetId(), doorVoList.get(1).getDoorId(), layer));
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+ @Override
|
|
|
+ public void onDestroyView() {
|
|
|
+ super.onDestroyView();
|
|
|
+ binding = null;
|
|
|
+ }
|
|
|
}
|