From d6d95564b016c281bfa2e8c2454db8d71083e858 Mon Sep 17 00:00:00 2001
From: JLChen <551775569@qq.com>
Date: 星期二, 26 十一月 2019 17:48:09 +0800
Subject: [PATCH] 2019-11-26 1.控制命令改为广播模式。

---
 app/src/main/java/com/hdl/sdk/hdl_sdk/activity/MainActivity.java |   79 ++++++++++++++++++++++++++++++++++++++-
 1 files changed, 77 insertions(+), 2 deletions(-)

diff --git a/app/src/main/java/com/hdl/sdk/hdl_sdk/activity/MainActivity.java b/app/src/main/java/com/hdl/sdk/hdl_sdk/activity/MainActivity.java
index 6c3e53b..5b09f1c 100644
--- a/app/src/main/java/com/hdl/sdk/hdl_sdk/activity/MainActivity.java
+++ b/app/src/main/java/com/hdl/sdk/hdl_sdk/activity/MainActivity.java
@@ -19,11 +19,14 @@
 import com.hdl.sdk.hdl_core.HDLDeviceManger.Bean.AppliancesInfo;
 import com.hdl.sdk.hdl_core.HDLDeviceManger.Bean.DevicesData;
 import com.hdl.sdk.hdl_core.HDLDeviceManger.Core.HDLCommand;
+import com.hdl.sdk.hdl_core.HDLDeviceManger.Core.HDLDeviceManager;
+import com.hdl.sdk.hdl_core.HDLDeviceManger.Core.HandleSearch;
 import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.BgmInfoEvent;
 import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.DevicesInfoEvent;
 import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.ThirdPartyBgmInfoEvent;
 import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.WarningInfoEvent;
 import com.hdl.sdk.hdl_sdk.R;
+import com.hdl.sdk.hdl_sdk.utlis.HDLLog;
 
 import org.greenrobot.eventbus.EventBus;
 import org.greenrobot.eventbus.Subscribe;
@@ -37,7 +40,7 @@
 public class MainActivity extends AppCompatActivity {
 
     private Button btn, btn2;
-    private Button btn_get_all,btn_on_all, btn_off_all;
+    private Button btn_get_all,btn_on_all, btn_off_all,btn_getlocal,btn_getlocal_add;
     private TextView tv;
     private EditText editText;
     private List<DevicesData> devicesDatas;
@@ -72,7 +75,10 @@
         btn_get_all = findViewById(R.id.btn_get_all);
         btn_on_all = findViewById(R.id.btn_on_all);
         btn_off_all = findViewById(R.id.btn_off_all);
-        
+        btn_getlocal = findViewById(R.id.btn_getlocal);
+
+        btn_getlocal_add = findViewById(R.id.btn_getlocal_add);
+
         tv = findViewById(R.id.tv);
         editText = findViewById(R.id.edt);
         editText.setText("172.168.188.100");
@@ -142,8 +148,77 @@
                 sendAll(false);
             }
         });
+
+
+        btn_getlocal.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+
+                clearListView();
+                getLocalDevicesDataList();
+            }
+        });
+
+
+
+
+        btn_getlocal_add.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                startActivity(AddDevicesManuallyActivity.class);
+
+            }
+        });
     }
 
+    public void startActivity(Class<?> clazz) {
+        Intent intent = new Intent(this, clazz);
+        startActivity(intent);
+    }
+    /**
+     * 璇诲彇鍜屽姞杞芥湰鍦版暟鎹�
+     */
+    private void getLocalDevicesDataList() {
+        devicesDatas = HDLDeviceManager.getLocalDevicesDataList();
+        if (devicesDatas.size() > 0) {
+            updateDeviceListView();
+            HandleSearch.refreshAllDevicesStateAndRemarks();//濡傛灉鏈湴鏈夋暟鎹紝鍙互璋冪敤璇ユ柟娉曪紝閬嶅巻鍙戦�佹寚浠わ紝鍒锋柊鎵�鏈夎澶囩殑澶囨敞鍜岀姸鎬�
+        } else {
+            showToast("鏈湴鏁版嵁涓虹┖");
+        }
+    }
+
+    /**
+     * 鍒锋柊璁惧鍒楄〃鏁版嵁
+     */
+    private void updateDeviceListView() {
+        int countAll = 0;
+        for (DevicesData devicesData : devicesDatas) {
+            countAll += devicesData.getAppliancesInfoList().size();
+        }
+        tv.setText("鎬诲叡妯″潡鏁帮細" + devicesDatas.size() + " 鎬诲叡鍥炶矾鏁帮細" + countAll);
+        HDLLog.I("鑾峰彇鏁版嵁鎴愬姛锛氭�诲叡妯″潡鏁帮細" + devicesDatas.size() + " 鎬诲叡鍥炶矾鏁帮細" + countAll);
+
+        for (int i = 0; i < devicesDatas.size(); i++) {
+            if (TextUtils.isEmpty(devicesDatas.get(i).getRemark())) {
+                listString.add("鏆傛棤澶囨敞");
+            } else {
+                listString.add(devicesDatas.get(i).getRemark());
+            }
+        }
+        adapter.notifyDataSetChanged();
+    }
+
+
+    /**
+     * 娓呯┖鏁版嵁骞跺埛鏂板垪琛�
+     */
+    private void clearListView() {
+        if (devicesDatas != null) devicesDatas.clear();
+        if (listString != null) listString.clear();
+
+        adapter.notifyDataSetChanged();
+    }
 
     @Override
     protected void onDestroy() {

--
Gitblit v1.8.0