From 8ce9ce72d3e32427d01ebe4bf8bef6aa863979ca Mon Sep 17 00:00:00 2001
From: whycq <913841844@qq.com>
Date: 星期五, 17 一月 2025 15:48:36 +0800
Subject: [PATCH] #
---
app/src/main/java/com/example/agvcontroller/StartActivity.java | 41 ++++++++++++++++++++++++++++++++++++++---
1 files changed, 38 insertions(+), 3 deletions(-)
diff --git a/app/src/main/java/com/example/agvcontroller/StartActivity.java b/app/src/main/java/com/example/agvcontroller/StartActivity.java
index adb74d2..e6592be 100644
--- a/app/src/main/java/com/example/agvcontroller/StartActivity.java
+++ b/app/src/main/java/com/example/agvcontroller/StartActivity.java
@@ -2,6 +2,7 @@
import android.content.Context;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
@@ -25,11 +26,13 @@
private List<Item> items;
private ItemAdapter adapter;
SocketManager socketManager;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_start);
+
recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
@@ -47,7 +50,14 @@
public void onItemClick(View view, int position) {
Context context = view.getContext();
Intent intent = new Intent(context,MainActivity.class);
- intent.putExtra("message", items.get(position).getIp());
+ 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);
startActivityForResult(intent,1);
}
});
@@ -58,11 +68,36 @@
@Subscribe(threadMode = ThreadMode.MAIN)
public void onDeviceConnected(Item deviceAddress) {
Log.i("EventBus", "Received device connected: " + deviceAddress);
- items.add(new Item("1",deviceAddress.getIp(),"3"));
- if (items.size() > 0) {
+
+
+ if (!items.isEmpty()) {
+ int sameIp = 0;
for (Item item : items) {
+ if (item.getIp().equals(deviceAddress.getIp())) {
+ item.setAgvNo(deviceAddress.getAgvNo());
+ item.setPort(deviceAddress.getPort());
+ item.setClientId(deviceAddress.getClientId());
+ item.setStatus(deviceAddress.getStatus());
+ adapter.notifyItemChanged(items.indexOf(item));
+ MainActivity.upClient(deviceAddress.getClientId());
+ sameIp++;
+ }
Log.i("Item",item.getIp());
+ Log.i("Item",item.getClientId());
}
+ if (sameIp == 0) {
+ items.add(new Item(deviceAddress.getClientId()
+ ,deviceAddress.getIp()
+ ,deviceAddress.getPort()
+ ,deviceAddress.getAgvNo()
+ ,deviceAddress.getStatus()));
+ }
+ } else {
+ items.add(new Item(deviceAddress.getClientId()
+ ,deviceAddress.getIp()
+ ,deviceAddress.getPort()
+ ,deviceAddress.getAgvNo()
+ ,deviceAddress.getStatus()));
}
adapter.notifyDataSetChanged();
}
--
Gitblit v1.9.1