|  |  |  | 
|---|
|  |  |  | import com.doumee.keyCabinet.dao.CabinetGridDo; | 
|---|
|  |  |  | import com.doumee.keyCabinet.dao.DaoManager; | 
|---|
|  |  |  | import com.doumee.keyCabinet.databinding.ManageCabinetActivityBinding; | 
|---|
|  |  |  | import com.doumee.keyCabinet.event.CloseGridOneResultEvent; | 
|---|
|  |  |  | import com.doumee.keyCabinet.event.HttpEvent; | 
|---|
|  |  |  | import com.doumee.keyCabinet.event.ManageOpenGridResultEvent; | 
|---|
|  |  |  | import com.doumee.keyCabinet.event.OpenAllGridEvent; | 
|---|
|  |  |  | import com.doumee.keyCabinet.event.OpenGridEvent; | 
|---|
|  |  |  | import com.doumee.keyCabinet.event.OpenGridListEvent; | 
|---|
|  |  |  | import com.doumee.keyCabinet.event.TimeClockEvent; | 
|---|
|  |  |  | import com.doumee.keyCabinet.ui.keyCabinet.adapter.ManageCabinetRcvAdapter; | 
|---|
|  |  |  | 
|---|
|  |  |  | @AndroidEntryPoint | 
|---|
|  |  |  | public class ManageCabinetActivity extends MyBaseActivity<ManageCabinetVM, ManageCabinetActivityBinding> { | 
|---|
|  |  |  | private ManageCabinetRcvAdapter adapter; | 
|---|
|  |  |  | //1待全开,2待批量开 | 
|---|
|  |  |  | private int status; | 
|---|
|  |  |  | private boolean isCanCZ = false; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //是否可批量操作 | 
|---|
|  |  |  | private boolean isCanPL = false; | 
|---|
|  |  |  | //可标记:全借出、全故障 | 
|---|
|  |  |  | private boolean isCanBJ = false; | 
|---|
|  |  |  | private int keyStatus = -1; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public int getLayoutId() { | 
|---|
|  |  |  | 
|---|
|  |  |  | adapter = new ManageCabinetRcvAdapter(this, R.layout.manage_cabinet_rcv_item, new ManageCabinetRcvAdapter.OnItemClick() { | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void onItemClick(ManageKeyCabinetBean item) { | 
|---|
|  |  |  | List<ManageKeyCabinetBean> datas = adapter.getListData(); | 
|---|
|  |  |  | isCanCZ = false; | 
|---|
|  |  |  | for(ManageKeyCabinetBean d:datas){ | 
|---|
|  |  |  | if(d.getIsSelected().get()){ | 
|---|
|  |  |  | isCanCZ = true; | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(isCanCZ){ | 
|---|
|  |  |  | getDB().tvPlOpen.setBackgroundResource(R.drawable.shape_mb_bt_ok); | 
|---|
|  |  |  | getDB().tvBj.setBackgroundResource(R.drawable.shape_mb_bt_ok); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | getDB().tvPlOpen.setBackgroundResource(R.drawable.shape_mb_bt_faile); | 
|---|
|  |  |  | getDB().tvBj.setBackgroundResource(R.drawable.shape_mb_bt_faile); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | updateBtnStatus(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | RecyclerHelp.bindVG(this,getDB().rcvKm,3,30); | 
|---|
|  |  |  | 
|---|
|  |  |  | getVM().getDatasLD().observe(this, new Observer<List<ManageKeyCabinetBean>>() { | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void onChanged(List<ManageKeyCabinetBean> gridInfoBeans) { | 
|---|
|  |  |  | if(getDB().clCz.getVisibility()==View.VISIBLE){ | 
|---|
|  |  |  | getDB().clCz.setVisibility(View.GONE); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(gridInfoBeans.size()>0){ | 
|---|
|  |  |  | adapter.refreshData(gridInfoBeans); | 
|---|
|  |  |  | getVM().emptyVisibility.set(View.GONE); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }); | 
|---|
|  |  |  | getVM().getCabinetDetail(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void updateBtnStatus(){ | 
|---|
|  |  |  | List<ManageKeyCabinetBean> datas = adapter.getListData(); | 
|---|
|  |  |  | isCanPL = false; | 
|---|
|  |  |  | isCanBJ = false; | 
|---|
|  |  |  | keyStatus = -1; | 
|---|
|  |  |  | for(ManageKeyCabinetBean d:datas){ | 
|---|
|  |  |  | if(d.getIsSelected().get()){ | 
|---|
|  |  |  | isCanPL = true; | 
|---|
|  |  |  | if(keyStatus==-1){ | 
|---|
|  |  |  | keyStatus = getGridStatus(d); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | if(keyStatus!=getGridStatus(d)){ | 
|---|
|  |  |  | //不同 | 
|---|
|  |  |  | keyStatus = -2; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(isCanPL){ | 
|---|
|  |  |  | getDB().tvPlOpen.setBackgroundResource(R.drawable.shape_mb_bt_ok); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | getDB().tvPlOpen.setBackgroundResource(R.drawable.shape_mb_bt_faile); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(keyStatus==2||keyStatus==4){ | 
|---|
|  |  |  | isCanBJ = true; | 
|---|
|  |  |  | getDB().tvBj.setBackgroundResource(R.drawable.shape_mb_bt_ok); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | getDB().tvBj.setBackgroundResource(R.drawable.shape_mb_bt_faile); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private int getGridStatus(ManageKeyCabinetBean grid){ | 
|---|
|  |  |  | if(grid.getWorkingStatus()==1){ | 
|---|
|  |  |  | return 4; | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | return grid.getKeyStatus(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void updateDao(List<ManageKeyCabinetBean> beans){ | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private List<Integer> bjIds = new ArrayList<>(); | 
|---|
|  |  |  | private boolean isGz = true; | 
|---|
|  |  |  | private boolean isAllOpen = false; | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | protected void doRegister(int type, ActionEventData data) { | 
|---|
|  |  |  | 
|---|
|  |  |  | case 2: | 
|---|
|  |  |  | { | 
|---|
|  |  |  | //全开 | 
|---|
|  |  |  | status = 1; | 
|---|
|  |  |  | //批量开门,校验是否可打开 | 
|---|
|  |  |  | List<Integer> ids = new ArrayList<>(); | 
|---|
|  |  |  | List<ManageKeyCabinetBean> datas = adapter.getListData(); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 3: { | 
|---|
|  |  |  | if(!isCanCZ){ | 
|---|
|  |  |  | if(!isCanPL){ | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | //批量开门,校验是否可打开 | 
|---|
|  |  |  | 
|---|
|  |  |  | }break; | 
|---|
|  |  |  | case 4: { | 
|---|
|  |  |  | //标记 | 
|---|
|  |  |  | if(!isCanCZ){ | 
|---|
|  |  |  | if(!isCanPL){ | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | bjIds.clear(); | 
|---|
|  |  |  | isGz = true; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<ManageKeyCabinetBean> datas = adapter.getListData(); | 
|---|
|  |  |  | for (ManageKeyCabinetBean bean : datas) { | 
|---|
|  |  |  | if (bean.getIsSelected().get()) { | 
|---|
|  |  |  | bjIds.add(bean.getId()); | 
|---|
|  |  |  | if(bean.getWorkingStatus()==0){ | 
|---|
|  |  |  | isGz = false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (bjIds.size() == 0) { | 
|---|
|  |  |  | Toast.makeText(mContext, "请选择柜格", Toast.LENGTH_SHORT).show(); | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(isGz){ | 
|---|
|  |  |  | if(keyStatus==4){ | 
|---|
|  |  |  | //全为故障 | 
|---|
|  |  |  | getDB().tvBjgz.setText("标记为正常"); | 
|---|
|  |  |  | getDB().tvBjgz.setTextColor(0xff279BAA); | 
|---|
|  |  |  | getDB().tvBjgz.setBackgroundResource(R.drawable.shape_mb_cz_2_bg); | 
|---|
|  |  |  | getDB().tvBy.setVisibility(View.GONE); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | //标记故障 | 
|---|
|  |  |  | getDB().tvBjgz.setText("标记为故障"); | 
|---|
|  |  |  | getDB().tvBjgz.setTextColor(0xffFF3600); | 
|---|
|  |  |  | getDB().tvBjgz.setBackgroundResource(R.drawable.shape_mb_cz_1_bg); | 
|---|
|  |  |  | getDB().tvBy.setVisibility(View.VISIBLE); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | getDB().clCz.setVisibility(View.VISIBLE); | 
|---|
|  |  |  | }break; | 
|---|
|  |  |  | 
|---|
|  |  |  | getVM().markRepair(bjIds); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 7: | 
|---|
|  |  |  | if(isGz) { | 
|---|
|  |  |  | if(keyStatus==4) { | 
|---|
|  |  |  | //正常 | 
|---|
|  |  |  | getVM().cancelFault(bjIds); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | case 9: { | 
|---|
|  |  |  | updateBtnStatus(); | 
|---|
|  |  |  | if(isShowOpenTip==true) { | 
|---|
|  |  |  | //清空开门提醒 | 
|---|
|  |  |  | isShowOpenTip = false; | 
|---|
|  |  |  | 
|---|
|  |  |  | getDB().clKmTip.setVisibility(View.GONE); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }break; | 
|---|
|  |  |  | case 11: | 
|---|
|  |  |  | updateBtnStatus(); | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | default: | 
|---|
|  |  |  | break; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | return styledText; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private void showKeyErrTip(CabinetGridDo gridDo){ | 
|---|
|  |  |  | getDB().imgClKm1.setImageResource(R.mipmap.ic_jjfail); | 
|---|
|  |  |  | getDB().tvClKm1.setText("识别失败"); | 
|---|
|  |  |  | getDB().tvClKm2.setText(getTipText2("钥匙柜",gridDo.getCabinetName(),"识别失败"), TextView.BufferType.SPANNABLE); | 
|---|
|  |  |  | getDB().tvClKmClose.setText("重新存放"); | 
|---|
|  |  |  | getDB().tvClKmClose.setTextColor(0xffffffff); | 
|---|
|  |  |  | getDB().tvClKmClose.setBackgroundResource(R.drawable.shape_mb_bt_ok); | 
|---|
|  |  |  | isShowOpenTip = false; | 
|---|
|  |  |  | getDB().clKmTip.setVisibility(View.VISIBLE); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public boolean onKeyDown(int keyCode, KeyEvent event) { | 
|---|
|  |  |  | if(keyCode == KeyEvent.KEYCODE_BACK){ | 
|---|
|  |  |  | 
|---|
|  |  |  | return super.onKeyDown(keyCode, event); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 开门返回 | 
|---|
|  |  |  | * @param e | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Subscribe(threadMode = ThreadMode.MAIN) | 
|---|
|  |  |  | public void ManageOpenGridResultEvent(ManageOpenGridResultEvent e){ | 
|---|
|  |  |  | if(!isFinishing()){ | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(waitOpenMap.size()==0){ | 
|---|
|  |  |  | if(getDB().clKmTip.getVisibility()==View.VISIBLE){ | 
|---|
|  |  |  | //已弹出就不提示了 | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | EventBus.getDefault().post(new HttpEvent("全部打开了:"+waitOpenMap.size())); | 
|---|
|  |  |  | //打开成功 | 
|---|
|  |  |  | if(isAllOpen){ | 
|---|
|  |  |  | 
|---|
|  |  |  | waitOpenMap.clear(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 关门 | 
|---|
|  |  |  | * @param e | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Subscribe(threadMode= ThreadMode.MAIN) | 
|---|
|  |  |  | public void CloseGridOneResultEvent(CloseGridOneResultEvent e){ | 
|---|
|  |  |  | if(!isFinishing()){ | 
|---|
|  |  |  | //校验卡号 | 
|---|
|  |  |  | CabinetGridDo gridDo = DaoManager.getCabinetGridDao().getGridByKey(e.getKey()); | 
|---|
|  |  |  | if(gridDo!=null){ | 
|---|
|  |  |  | //校验钥匙是否匹配 | 
|---|
|  |  |  | if(gridDo.getGridKey()==null){ | 
|---|
|  |  |  | if(!TextUtils.isEmpty(gridDo.getCurKeyCode())){ | 
|---|
|  |  |  | //未绑定的存放了钥匙 | 
|---|
|  |  |  | showKeyErrTip(gridDo); | 
|---|
|  |  |  | //开门 | 
|---|
|  |  |  | EventBus.getDefault().post(new OpenGridEvent(Integer.parseInt(e.getKey().substring(2,4), 16)+"", | 
|---|
|  |  |  | Integer.parseInt(e.getKey().substring(0,2), 16)+"")); | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | if(!TextUtils.isEmpty(gridDo.getCurKeyCode())){ | 
|---|
|  |  |  | if(!gridDo.getCurKeyCode().equals(gridDo.getKeyCode())){ | 
|---|
|  |  |  | //钥匙不匹配 | 
|---|
|  |  |  | showKeyErrTip(gridDo); | 
|---|
|  |  |  | //开门 | 
|---|
|  |  |  | EventBus.getDefault().post(new OpenGridEvent(Integer.parseInt(e.getKey().substring(2,4), 16)+"", | 
|---|
|  |  |  | Integer.parseInt(e.getKey().substring(0,2), 16)+"")); | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | getVM().closeGrid(gridDo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|