Skip to content

Commit

Permalink
DeletandoDadosDoDevicesStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielSirtoriCorrea committed Jul 17, 2020
1 parent a37da3a commit 4c1e78f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ public class ServerConnection extends AsyncTask<JSONObject, Integer, ArrayList<J
private ArrayList<JSONArray> list = null;
private JSONArray arrayResponse;
private char[] buffer;
private StringBuilder requestBuilder;
private String requestLine;
private boolean msgStatus = false;


Expand Down Expand Up @@ -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();
Expand Down
4 changes: 0 additions & 4 deletions Server/DevicesStatus.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,5 @@
"Friday": {
"action": 0,
"url": ".com"
},
"teste": {
"action": 0,
"url": ".com"
}
}
11 changes: 11 additions & 0 deletions Server/Server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down

0 comments on commit 4c1e78f

Please sign in to comment.