From 4c1e78f8d422cc69a6e3fc9e6e7bec1f3814ca8c Mon Sep 17 00:00:00 2001 From: Gazebo Date: Thu, 16 Jul 2020 22:28:33 -0300 Subject: [PATCH] DeletandoDadosDoDevicesStatus --- .../DevicesFragments/ViewDevicesFragment.java | 2 +- .../sextafeiramobile/ServerConnection.java | 16 ++++++++++++++-- Server/DevicesStatus.json | 4 ---- Server/Server.py | 11 +++++++++++ 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/Fragments/DevicesFragments/ViewDevicesFragment.java b/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/Fragments/DevicesFragments/ViewDevicesFragment.java index 55aa23f..9c13e3b 100644 --- a/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/Fragments/DevicesFragments/ViewDevicesFragment.java +++ b/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/Fragments/DevicesFragments/ViewDevicesFragment.java @@ -75,7 +75,7 @@ public void onClick(DialogInterface dialogInterface, int i) { removeAlert.setPositiveButton("Excluir", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { - connection.sendRequest(connection.prepareDelete("deleteDevice", ID)); + connection.sendRequest(connection.prepareDelete("deleteDevice", ID, txtDevice.getText().toString())); if(connection.getMsgStatus()) { Toast.makeText(getContext(), "ExcluĂ­do", Toast.LENGTH_SHORT).show(); diff --git a/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/ServerConnection.java b/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/ServerConnection.java index acbaaa1..5a4acd4 100644 --- a/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/ServerConnection.java +++ b/App/app/src/main/java/com/gazeboindustries/sextafeiramobile/ServerConnection.java @@ -28,8 +28,6 @@ public class ServerConnection extends AsyncTask list = null; private JSONArray arrayResponse; private char[] buffer; - private StringBuilder requestBuilder; - private String requestLine; private boolean msgStatus = false; @@ -254,6 +252,20 @@ public JSONObject prepareDelete(String request, int deleteId){ return jsonRequest; } + public JSONObject prepareDelete(String request, int deleteId, String name){ + try { + this.jsonRequest = new JSONObject(); + this.jsonRequest.put("header", "gazeboindustries09082004"); + this.jsonRequest.put("request", request); + this.jsonRequest.put("deleteId", deleteId); + this.jsonRequest.put("deleteName", name); + + } catch (JSONException e) { + e.printStackTrace(); + } + return jsonRequest; + } + public JSONObject prepareSetDevice(String request, String device, int action){ try { this.jsonRequest = new JSONObject(); diff --git a/Server/DevicesStatus.json b/Server/DevicesStatus.json index efcaccf..e0b616e 100644 --- a/Server/DevicesStatus.json +++ b/Server/DevicesStatus.json @@ -6,9 +6,5 @@ "Friday": { "action": 0, "url": ".com" - }, - "teste": { - "action": 0, - "url": ".com" } } \ No newline at end of file diff --git a/Server/Server.py b/Server/Server.py index 0e26577..8f51fe7 100644 --- a/Server/Server.py +++ b/Server/Server.py @@ -163,6 +163,17 @@ def handle(self): elif clientRequest['request'] == 'deleteDevice': dataBaseConnection.deleteDevice(clientRequest['deleteId']) + readFile = open('E:/Sexta-Feira-Mark_6/Server/DevicesStatus.json', 'r') + + newJson = json.load(readFile) + + print(newJson) + + del newJson[clientRequest['deleteName']] + + writeFile = open('E:/Sexta-Feira-Mark_6/Server/DevicesStatus.json', 'w') + json.dump(newJson, writeFile, indent=4) + self.request.send(json.dumps({'requestStatus': True}).encode()) elif clientRequest['request'] == 'deleteHomeWork':