| | |
| | | public void onItemClick(View view, int position) { |
| | | Context context = view.getContext(); |
| | | Intent intent = new Intent(context,MainActivity.class); |
| | | String ip = items.get(position).getIp(); |
| | | String clientId = items.get(position).getClientId(); |
| | | String agvNo = items.get(position).getAgvNo(); |
| | | AGVCar item = items.get(position); |
| | | // String ip = items.get(position).getIp(); |
| | | // String clientId = items.get(position).getClientId(); |
| | | // String agvNo = items.get(position).getAgvNo(); |
| | | |
| | | |
| | | intent.putExtra("ip", ip); |
| | | intent.putExtra("agvNo", agvNo); |
| | | intent.putExtra("clientId", clientId); |
| | | // intent.putExtra("ip", ip); |
| | | // intent.putExtra("agvNo", agvNo); |
| | | // intent.putExtra("clientId", clientId); |
| | | intent.putExtra("item", item); |
| | | startActivityForResult(intent,1); |
| | | } |
| | | }); |
| | |
| | | } |
| | | |
| | | @Subscribe(threadMode = ThreadMode.MAIN) |
| | | public void onDeviceConnected(AGVCar deviceAddress) { |
| | | Log.i("EventBus", "Received device connected: " + deviceAddress); |
| | | public void onDeviceConnected(AGVCar car) { |
| | | Log.i("EventBus", "Received device connected: " + car); |
| | | |
| | | |
| | | if (!items.isEmpty()) { |
| | | int sameIp = 0; |
| | | for (AGVCar item : items) { |
| | | if (item.getIp().equals(deviceAddress.getIp())) { |
| | | item.setAgvNo(deviceAddress.getAgvNo()); |
| | | item.setPort(deviceAddress.getPort()); |
| | | item.setClientId(deviceAddress.getClientId()); |
| | | item.setStatus(deviceAddress.getStatus()); |
| | | if (item.getIp().equals(car.getIp())) { |
| | | item.setAgvNo(car.getAgvNo().isEmpty() ? car.getAgvNo() : item.getAgvNo()); |
| | | item.setPort(car.getPort()); |
| | | item.setClientId(car.getClientId()); |
| | | item.setStatus(car.getStatus()); |
| | | item.setBattery(car.getBattery() != 0 ? car.getBattery() : item.getBattery()); |
| | | adapter.notifyItemChanged(items.indexOf(item)); |
| | | MainActivity.upClient(deviceAddress.getClientId()); |
| | | MainActivity.upClient(car); |
| | | sameIp++; |
| | | } |
| | | Log.i("Item",item.getIp()); |
| | | Log.i("Item",item.getClientId()); |
| | | } |
| | | if (sameIp == 0) { |
| | | items.add(new AGVCar(deviceAddress.getClientId() |
| | | ,deviceAddress.getIp() |
| | | ,deviceAddress.getPort() |
| | | ,deviceAddress.getAgvNo() |
| | | ,deviceAddress.getStatus())); |
| | | items.add(car); |
| | | } |
| | | } else { |
| | | items.add(new AGVCar(deviceAddress.getClientId() |
| | | ,deviceAddress.getIp() |
| | | ,deviceAddress.getPort() |
| | | ,deviceAddress.getAgvNo() |
| | | ,deviceAddress.getStatus())); |
| | | items.add(car); |
| | | } |
| | | adapter.notifyDataSetChanged(); |
| | | } |