Skip to content

Commit

Permalink
Merge pull request #33 from GabrielSirtoriCorrea/CriandoMetodoPrepare…
Browse files Browse the repository at this point in the history
…RequestApp

MetodoCriado
  • Loading branch information
GabrielSirtoriCorrea authored Jul 7, 2020
2 parents 72b4003 + 9f27842 commit c9284cb
Show file tree
Hide file tree
Showing 10 changed files with 300 additions and 303 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,9 @@ public void onClick(View view) {

listDevices = view.findViewById(R.id.listDevices);

ServerConnection connection = new ServerConnection("getDevicesJsons");
ServerConnection connection = new ServerConnection();

try {
sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}

arrayList = connection.getListResponse();
arrayList = connection.sendRequest(connection.prepareRequest("getDevicesJsons"));

arrayAdapter = new ListItemRow(view.getContext(), arrayList, "Devices");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,9 @@ public void onClick(View view) {

listInteractions = view.findViewById(R.id.listInteractions);

ServerConnection connection = new ServerConnection("getInteractions");
ServerConnection connection = new ServerConnection();

try {
sleep(4500);
} catch (InterruptedException e) {
e.printStackTrace();
}

arrayList = connection.getListResponse();
arrayList = connection.sendRequest(connection.prepareRequest("getInteractions"));

arrayAdapter = new ListItemRow(view.getContext(), arrayList, "Interactions");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,6 @@ public class ViewInteractionFragment extends Fragment {
private EditText response3;
private EditText command;

private String KeyWord1Text;
private String KeyWord2Text;
private String KeyWord3Text;
private String Response1Text;
private String Response2Text;
private String Response3Text;
private String CommandText;


@Nullable
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,11 @@ public void onClick(View view) {

listHomeWorks = view.findViewById(R.id.listHomeWorks);

ServerConnection connection = new ServerConnection("getHomeWorks");
ServerConnection connection = new ServerConnection();

try {
sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
arrayList = connection.sendRequest(connection.prepareRequest("getHomeWorks"));

arrayList = connection.getListResponse();

arrayAdapter = new ListItemRow(view.getContext(), arrayList, "HomeWorks");
arrayAdapter = new ListItemRow(view.getContext(), arrayList, "HomeWork");

listHomeWorks.setAdapter(arrayAdapter);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class ViewHomeWorkFragment extends Fragment {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_viewinteractions, container, false);
View view = inflater.inflate(R.layout.fragment_viewhomework, container, false);

txtType = view.findViewById(R.id.txtViewHomeWorkType);
txtSubject = view.findViewById(R.id.txtViewHomeWorkSubject);
Expand All @@ -34,11 +34,11 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c

intent = getActivity().getIntent();

txtType.setText(intent.getSerializableExtra("Type").toString());
txtSubject.setText(intent.getSerializableExtra("Subject").toString());
txtHomeWork.setText(intent.getSerializableExtra("HomeWork").toString());
txtDelivery.setText(intent.getSerializableExtra("Delivery").toString());
txtDescription.setText(intent.getSerializableExtra("Description").toString());
txtType.setText(intent.getStringExtra("Type"));
txtSubject.setText(intent.getStringExtra("Subject"));
txtHomeWork.setText(intent.getStringExtra("HomeWork"));
txtDelivery.setText(intent.getStringExtra("Delivery"));
txtDescription.setText(intent.getStringExtra("Description"));

return view;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,9 @@ public void onClick(View view) {

listProjects = view.findViewById(R.id.listProjects);

ServerConnection connection = new ServerConnection("getProjects");
ServerConnection connection = new ServerConnection();

try {
sleep(4500);
} catch (InterruptedException e) {
e.printStackTrace();
}

arrayList = connection.getListResponse();
arrayList = connection.sendRequest(connection.prepareRequest("getProjects"));

arrayAdapter = new ListItemRow(view.getContext(), arrayList, "Projects");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
listID.setText(arrayLine.get(0).toString());
listField1.setText(arrayLine.get(2).toString());
listField2.setText(arrayLine.get(3).toString());
listField3.setText(arrayLine.get(4).toString());
break;
case "Interactions":
arrayLine = list.get(position);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.ArrayList;

public class ServerConnection extends AsyncTask<String, Integer, String> {
import static java.lang.Thread.sleep;

public class ServerConnection extends AsyncTask<JSONObject, Integer, ArrayList<JSONArray>> {
private String IP = "192.168.0.5";
private int port = 5000;
private Socket socket;
Expand All @@ -27,22 +28,26 @@ public class ServerConnection extends AsyncTask<String, Integer, String> {
private JSONArray arrayResponse;
private char[] buffer = new char[9000];

public ServerConnection(String request){
execute(request);
public ArrayList<JSONArray> sendRequest(JSONObject request){
try {
execute(request);
sleep(4500);
} catch (InterruptedException e) {
e.printStackTrace();
}

return this.list;

}

@Override
protected String doInBackground(String... params) {
protected ArrayList<JSONArray> doInBackground(JSONObject... params) {
try {
this.socket = new Socket(IP, port);
this.out = new PrintWriter(this.socket.getOutputStream(), true);
this.in = new BufferedReader(new InputStreamReader(this.socket.getInputStream()));

this.jsonRequest = new JSONObject();
this.jsonRequest.put("header", "gazeboindustries09082004");
this.jsonRequest.put("request", params[0]);

this.out.println(this.jsonRequest);
this.out.println(params[0]);

this.in.read(this.buffer);

Expand Down Expand Up @@ -70,7 +75,16 @@ protected String doInBackground(String... params) {
return null;
}

public ArrayList<JSONArray> getListResponse(){
return this.list;
public JSONObject prepareRequest(String request){
try {
this.jsonRequest = new JSONObject();
this.jsonRequest.put("header", "gazeboindustries09082004");
this.jsonRequest.put("request", request);

} catch (JSONException e) {
e.printStackTrace();
}
return jsonRequest;
}

}
Loading

0 comments on commit c9284cb

Please sign in to comment.