| | |
| | | package com.doumee.keyCabinet.ui.keyCabinet; |
| | | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.annotation.Nullable; |
| | | import androidx.lifecycle.Observer; |
| | | |
| | | import android.os.Build; |
| | | import android.os.Bundle; |
| | | import android.os.Handler; |
| | | import android.os.Message; |
| | | import android.text.SpannableString; |
| | | import android.text.Spanned; |
| | | import android.text.TextUtils; |
| | |
| | | import android.widget.TextView; |
| | | import android.widget.Toast; |
| | | |
| | | import com.doumee.keyCabinet.MApplication; |
| | | import com.doumee.keyCabinet.R; |
| | | import com.doumee.keyCabinet.base.MyBaseActivity; |
| | | import com.doumee.keyCabinet.bean.ManageKeyCabinetBean; |
| | |
| | | import com.doumee.keyCabinet.event.KeyResultEvent; |
| | | import com.doumee.keyCabinet.event.ManageOpenGridResultEvent; |
| | | import com.doumee.keyCabinet.event.OpenAllGridEvent; |
| | | import com.doumee.keyCabinet.event.OpenErrEvent; |
| | | import com.doumee.keyCabinet.event.OpenGridEvent; |
| | | import com.doumee.keyCabinet.event.OpenGridListEvent; |
| | | import com.doumee.keyCabinet.event.OpenGridOneResultEvent; |
| | |
| | | import com.doumee.lib_coremodel.util.RecyclerHelp; |
| | | import com.doumee.lib_coremodel.util.StringUtil; |
| | | import com.example.datalibrary.db.DBManager; |
| | | import com.innohi.YNHAPI; |
| | | |
| | | import org.greenrobot.eventbus.EventBus; |
| | | import org.greenrobot.eventbus.Subscribe; |
| | |
| | | } |
| | | }); |
| | | getVM().getCabinetDetail(); |
| | | getDB().tvTitle.setOnLongClickListener(new View.OnLongClickListener() { |
| | | @Override |
| | | public boolean onLongClick(View v) { |
| | | //可以下拉 |
| | | YNHAPI mAPI = YNHAPI.getInstance(); |
| | | mAPI.setNavigationBarVisibility(YNHAPI.NavigationBarVisibility.VISIBLE); |
| | | return true; |
| | | } |
| | | }); |
| | | } |
| | | |
| | | private void updateBtnStatus(){ |
| | |
| | | } |
| | | } |
| | | |
| | | private String sygKey; |
| | | @Subscribe |
| | | public void OpenGridOneResultEvent(OpenGridOneResultEvent e){ |
| | | if(!isFinishing()){ |
| | | if(e.getIsOpen()==0){ |
| | | if(e.getKey().equals(sygKey)){ |
| | | return; |
| | | //开门成功,移除开门 |
| | | if(handler.hasMessages(1)){ |
| | | handler.removeMessages(1); |
| | | } |
| | | sygKey = e.getKey(); |
| | | if(e.getIsOpen()==0){ |
| | | //开门失败,重新开门 |
| | | EventBus.getDefault().post(new OpenGridEvent(Integer.parseInt(e.getKey().substring(2,4), 16)+"", |
| | | Integer.parseInt(e.getKey().substring(0,2), 16)+"")); |
| | |
| | | } |
| | | } |
| | | |
| | | private Long keyTime; |
| | | private HashMap<String,String> closeMap = new HashMap<>(); |
| | | /** |
| | | * 关门 |
| | | * @param e |
| | |
| | | @Subscribe(threadMode= ThreadMode.MAIN) |
| | | public void CloseGridOneResultEvent(CloseGridOneResultEvent e){ |
| | | if(!isFinishing()){ |
| | | //获取卡号 |
| | | EventBus.getDefault().post(new GetKeyStatusEvent()); |
| | | if(isShowTip){ |
| | | isShowTip = false; |
| | | getDB().clTip.setVisibility(View.GONE); |
| | | } |
| | | //关门成功,移除开门 |
| | | if(handler.hasMessages(1)){ |
| | | handler.removeMessages(1); |
| | | } |
| | | //发送查询钥匙号 |
| | | EventBus.getDefault().post(new GetKeyStatusEvent()); |
| | | keyTime = new Date().getTime()+500; |
| | | if(handler.hasMessages(0)){ |
| | | handler.removeMessages(0); |
| | | } |
| | | handler.sendEmptyMessageDelayed(0,1200); |
| | | closeMap.put(e.getKey(),""); |
| | | /*111 |
| | | //校验卡号 |
| | | CabinetGridDo gridDo = DaoManager.getCabinetGridDao().getGridByKey(e.getKey()); |
| | | if(gridDo!=null){ |
| | |
| | | } |
| | | } |
| | | } |
| | | EventBus.getDefault().post(new HttpEvent(StringUtil.DateToStrSS(new Date())+"门关闭成功==>目标:"+gridDo.getKeyCode()+",当前:"+gridDo.getCurKeyCode())); |
| | | EventBus.getDefault().post(new HttpEvent(StringUtil.DateToStrSS(new Date())+"门关闭成功***************************>目标:"+gridDo.getKeyCode()+",当前:"+gridDo.getCurKeyCode())); |
| | | getVM().closeGrid(gridDo); |
| | | }*/ |
| | | } |
| | | } |
| | | |
| | | @Subscribe(threadMode= ThreadMode.MAIN) |
| | | public void OpenErrEvent(OpenErrEvent e){ |
| | | //开门失败 |
| | | if(!isFinishing()){ |
| | | //开门 |
| | | if(handler.hasMessages(1)){ |
| | | handler.removeMessages(1); |
| | | } |
| | | EventBus.getDefault().post(new OpenGridEvent(e.getKey())); |
| | | Message msg = Message.obtain(); |
| | | msg.what=1; |
| | | msg.obj = e.getKey(); |
| | | handler.sendMessageDelayed(msg,1000); |
| | | } |
| | | } |
| | | |
| | | @Subscribe |
| | | public void KeyResultEvent(KeyResultEvent e){ |
| | | if(!isFinishing()){ |
| | | //校验时间 |
| | | if(keyTime==null){ |
| | | return; |
| | | } |
| | | if(keyTime!=null&&keyTime>System.currentTimeMillis()){ |
| | | //校验返回时间<命令时间 |
| | | return; |
| | | } |
| | | if(handler.hasMessages(0)){ |
| | | handler.removeMessages(0); |
| | | } |
| | | HashMap<String,String> copyMap = new HashMap<>(); |
| | | copyMap.putAll(closeMap); |
| | | closeMap.clear(); |
| | | //校验卡号不对的,直接弹出 |
| | | List<CabinetGridDo> gridDos = DaoManager.getCabinetGridDao().loadAll(); |
| | | List<String> keys = new ArrayList<>(); |
| | | StringBuilder sb = new StringBuilder(); |
| | | for(CabinetGridDo gridDo:gridDos){ |
| | | boolean isFail = false; |
| | | if(TextUtils.isEmpty(gridDo.getGridKey())){ |
| | | if(!TextUtils.isEmpty(gridDo.getCurKeyCode())&&gridDo.getIsOpen()==0){ |
| | | //未绑定的存放了钥匙 |
| | |
| | | sb.append("、"); |
| | | } |
| | | sb.append(gridDo.getCabinetName()); |
| | | isFail = true; |
| | | } |
| | | }else { |
| | | if(!TextUtils.isEmpty(gridDo.getCurKeyCode())){ |
| | |
| | | sb.append("、"); |
| | | } |
| | | sb.append(gridDo.getCabinetName()); |
| | | isFail = true; |
| | | } |
| | | } |
| | | } |
| | | if(!isFail){ |
| | | if(copyMap.containsKey(gridDo.getGridKey())){ |
| | | //关门成功 |
| | | EventBus.getDefault().post(new HttpEvent(StringUtil.DateToStrSS(new Date())+"门关闭成功***************************>目标:"+gridDo.getKeyCode()+",当前:"+gridDo.getCurKeyCode())); |
| | | getVM().closeGrid(gridDo); |
| | | } |
| | | } |
| | | } |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | protected void onDestroy() { |
| | | super.onDestroy(); |
| | | handler.removeCallbacksAndMessages(null); |
| | | handler = null; |
| | | } |
| | | |
| | | private Handler handler = new Handler(){ |
| | | @Override |
| | | public void handleMessage(@NonNull Message msg) { |
| | | switch (msg.what){ |
| | | case 0: |
| | | //重新发送钥匙查询 |
| | | //发送查询钥匙号 |
| | | EventBus.getDefault().post(new GetKeyStatusEvent()); |
| | | handler.sendEmptyMessageDelayed(0,1200); |
| | | break; |
| | | case 1: |
| | | EventBus.getDefault().post(new OpenGridEvent((String) msg.obj)); |
| | | handler.sendEmptyMessageDelayed(1,1000); |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | }; |
| | | } |