Skip to content

Commit

Permalink
Merge pull request #37 from GabrielSirtoriCorrea/AtualizandoDadosPeloApp
Browse files Browse the repository at this point in the history
AtualizandoDadosPeloApp
  • Loading branch information
GabrielSirtoriCorrea authored Jul 11, 2020
2 parents 12c9ed7 + 0ae8c36 commit 37c3925
Show file tree
Hide file tree
Showing 15 changed files with 168 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
public void onClick(View view) {
connection = new ServerConnection();

connection.sendRequest(connection.prepareDevice("insertDevice", device.getText().toString(), desc.getText().toString(), "json"));
connection.sendRequest(connection.prepareAddDevice("insertDevice", device.getText().toString(), desc.getText().toString(), "json"));

if(connection.getMsgStatus()){
Toast.makeText(view.getContext(), "Device adicionado", Toast.LENGTH_SHORT).show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public void onClick(View view) {
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
try {
intent = getActivity().getIntent();
intent.putExtra("ID", arrayList.get(i).getInt(0));
intent.putExtra("Device", arrayList.get(i).get(1).toString());
intent.putExtra("Description", arrayList.get(i).get(2).toString());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.gazeboindustries.sextafeiramobile.R;
import com.gazeboindustries.sextafeiramobile.ServerConnection;

public class ViewDevicesFragment extends Fragment {
private Intent intent;
Expand All @@ -30,6 +32,10 @@ public class ViewDevicesFragment extends Fragment {
private Drawable editIcon;
private Drawable removeIcon;

private int ID;

private ServerConnection connection;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
Expand All @@ -40,6 +46,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c

intent = getActivity().getIntent();

ID = intent.getIntExtra("ID", 0);
txtDevice.setText(intent.getStringExtra("Device"));
txtDescription.setText(intent.getStringExtra("Description"));

Expand All @@ -65,9 +72,16 @@ public void onClick(View view) {
btnDeleteCancel.setCompoundDrawablesWithIntrinsicBounds(cancelIcon, null, null, null);

}else{
//connection = new ServerConnection();
System.out.println("ENVIAR");
//connection.sendRequest(connection.prepareRequest());
connection = new ServerConnection();

connection.sendRequest(connection.prepareUpdateDevice("updateDevice", ID, txtDevice.getText().toString(), txtDescription.getText().toString(),
"json"));

if(connection.getMsgStatus()){
Toast.makeText(getContext(), "Salvo", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getContext(), "Erro ao salvar o device", Toast.LENGTH_SHORT).show();
}
}
}
});
Expand All @@ -76,8 +90,11 @@ public void onClick(View view) {
@Override
public void onClick(View view) {
if(btnDeleteCancel.getText().equals("Remover")){
//show dialog
System.out.println("Remove");

//Adicionar log de confirmação
connection = new ServerConnection();

connection.sendRequest(connection.prepareDelete("deleteDevice", ID));

}else{
txtDevice.setEnabled(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
public void onClick(View view) {
connection = new ServerConnection();

connection.sendRequest(connection.prepareInteraction("insertInteraction", key1.getText().toString(), key2.getText().toString(),
connection.sendRequest(connection.prepareAddInteraction("insertInteraction", key1.getText().toString(), key2.getText().toString(),
key3.getText().toString(), res1.getText().toString(), res2.getText().toString(), res3.getText().toString(),
command.getText().toString()));
if(connection.getMsgStatus()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
System.out.println(arrayList.toString());

intent = getActivity().getIntent();
intent.putExtra("ID", arrayList.get(i).getInt(0));
intent.putExtra("Keyword1", arrayList.get(i).getString(1));
intent.putExtra("Keyword2", arrayList.get(i).getString(2));
intent.putExtra("Keyword3", arrayList.get(i).getString(3));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

public class ViewInteractionFragment extends Fragment {
private Intent intent;
private int ID;
private EditText keyWord1;
private EditText keyWord2;
private EditText keyWord3;
Expand Down Expand Up @@ -85,6 +86,7 @@ public void onClick(DialogInterface dialogInterface, int i) {

intent = getActivity().getIntent();

ID = intent.getIntExtra("ID", 0);
keyWord1.setText(intent.getStringExtra("Keyword1"));
keyWord2.setText(intent.getStringExtra("Keyword2"));
keyWord3.setText(intent.getStringExtra("Keyword3"));
Expand Down Expand Up @@ -116,9 +118,17 @@ public void onClick(View view) {
btnDeleteCancel.setCompoundDrawablesWithIntrinsicBounds(cancelIcon, null, null, null);

}else{
//connection = new ServerConnection();
Toast.makeText(getContext(), "Salvo", Toast.LENGTH_SHORT).show();
//connection.sendRequest(connection.prepareRequest());
connection = new ServerConnection();

connection.sendRequest(connection.prepareUpdateInteraction("updateInteraction", ID, keyWord1.getText().toString(), keyWord2.getText().toString(),
keyWord3.getText().toString(), response1.getText().toString(), response2.getText().toString(), response3.getText().toString(),
command.getText().toString()));

if(connection.getMsgStatus()){
Toast.makeText(getContext(), "Salvo", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getContext(), "Erro ao salvar interação", Toast.LENGTH_SHORT).show();
}
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void onClick(View view) {
try {
sdf.parse(delivery.getText().toString());

connection.sendRequest(connection.prepareHomework("insertHomeWork", type.getText().toString(), subject.getText().toString(),
connection.sendRequest(connection.prepareAddHomework("insertHomeWork", type.getText().toString(), subject.getText().toString(),
homeWork.getText().toString(), delivery.getText().toString(), desc.getText().toString()));

if(connection.getMsgStatus()){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public void onClick(View view) {
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
try {
intent = getActivity().getIntent();
intent.putExtra("ID", arrayList.get(i).getInt(0));
intent.putExtra("Type", arrayList.get(i).get(1).toString());
intent.putExtra("Subject", arrayList.get(i).get(2).toString());
intent.putExtra("HomeWork", arrayList.get(i).get(3).toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import androidx.fragment.app.Fragment;

import com.gazeboindustries.sextafeiramobile.R;
import com.gazeboindustries.sextafeiramobile.ServerConnection;

import java.text.ParseException;
import java.text.SimpleDateFormat;
Expand All @@ -40,6 +41,9 @@ public class ViewHomeWorkFragment extends Fragment {

private SimpleDateFormat sdf;

private ServerConnection connection;
private int ID;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
Expand All @@ -59,7 +63,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
btnEditSend = view.findViewById(R.id.btnEditHomeWork);
btnDeleteCancel = view.findViewById(R.id.btnRemoveHomeWork);


ID = intent.getIntExtra("ID", 0);
txtType.setText(intent.getStringExtra("Type"));
txtSubject.setText(intent.getStringExtra("Subject"));
txtHomeWork.setText(intent.getStringExtra("HomeWork"));
Expand Down Expand Up @@ -93,9 +97,16 @@ public void onClick(View view) {
} catch (ParseException e) {
Toast.makeText(view.getContext(), "Insira um formato válido", Toast.LENGTH_SHORT).show();
}
connection = new ServerConnection();

//connection = new ServerConnection();
//connection.sendRequest(connection.prepareRequest());
connection.sendRequest(connection.prepareUpdateHomework("updateHomeWork", ID, txtType.getText().toString(), txtSubject.getText().toString(),
txtHomeWork.getText().toString(), txtDelivery.getText().toString(), txtDescription.getText().toString()));

if(connection.getMsgStatus()){
Toast.makeText(getContext(), "Salvo", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getContext(), "Erro ao salvar a tarefa", Toast.LENGTH_SHORT).show();
}
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
public void onClick(View view) {
connection = new ServerConnection();

connection.sendRequest(connection.prepareProject("insertProject", project.getText().toString(), "repository"));
connection.sendRequest(connection.prepareAddProject("insertProject", project.getText().toString(), "repository"));

if(connection.getMsgStatus()){
Toast.makeText(view.getContext(), "Projeto adicionado", Toast.LENGTH_SHORT).show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public void onClick(View view) {
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
try {
intent = getActivity().getIntent();
intent.putExtra("ID", arrayList.get(i).getInt(0));
intent.putExtra("Project", arrayList.get(i).get(1).toString());
intent.putExtra("Repository", arrayList.get(i).get(2).toString());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.gazeboindustries.sextafeiramobile.R;
import com.gazeboindustries.sextafeiramobile.ServerConnection;

public class ViewProjectsFragment extends Fragment {
private Intent intent;
Expand All @@ -30,6 +32,9 @@ public class ViewProjectsFragment extends Fragment {
private Drawable editIcon;
private Drawable removeIcon;

private ServerConnection connection;
private int ID;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
Expand All @@ -43,6 +48,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c

intent = getActivity().getIntent();

ID = intent.getIntExtra("ID", 0);
txtProject.setText(intent.getStringExtra("Project"));
txtRepository.setText(intent.getStringExtra("Repository"));

Expand All @@ -65,9 +71,15 @@ public void onClick(View view) {
btnDeleteCancel.setCompoundDrawablesWithIntrinsicBounds(cancelIcon, null, null, null);

}else{
//connection = new ServerConnection();
System.out.println("ENVIAR");
//connection.sendRequest(connection.prepareRequest());
connection = new ServerConnection();

connection.sendRequest(connection.prepareUpdateProject("updateProject", ID, txtProject.getText().toString(), txtRepository.getText().toString()));

if(connection.getMsgStatus()){
Toast.makeText(getContext(), "Salvo", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getContext(), "Erro ao salvar o projeto", Toast.LENGTH_SHORT).show();
}
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public ArrayList<JSONArray> sendRequest(JSONObject request){

}

public JSONObject prepareInteraction(String request, String key1, String key2, String key3, String res1, String res2, String res3, String command){
public JSONObject prepareAddInteraction(String request, String key1, String key2, String key3, String res1, String res2, String res3, String command){
try {
this.jsonRequest = new JSONObject();
this.jsonRequest.put("header", "gazeboindustries09082004");
Expand All @@ -104,7 +104,7 @@ public JSONObject prepareInteraction(String request, String key1, String key2, S
return jsonRequest;
}

public JSONObject prepareDevice(String request, String device, String desc, String json){
public JSONObject prepareAddDevice(String request, String device, String desc, String json){
try {
this.jsonRequest = new JSONObject();
this.jsonRequest.put("header", "gazeboindustries09082004");
Expand All @@ -119,7 +119,7 @@ public JSONObject prepareDevice(String request, String device, String desc, Stri
return jsonRequest;
}

public JSONObject prepareHomework(String request, String type, String subject, String homework, String delivery, String desc){
public JSONObject prepareAddHomework(String request, String type, String subject, String homework, String delivery, String desc){
try {
this.jsonRequest = new JSONObject();
this.jsonRequest.put("header", "gazeboindustries09082004");
Expand All @@ -136,7 +136,7 @@ public JSONObject prepareHomework(String request, String type, String subject, S
return jsonRequest;
}

public JSONObject prepareProject(String request, String project, String desc){
public JSONObject prepareAddProject(String request, String project, String desc){
try {
this.jsonRequest = new JSONObject();
this.jsonRequest.put("header", "gazeboindustries09082004");
Expand All @@ -161,4 +161,85 @@ public JSONObject prepareRequest(String request){
return jsonRequest;
}

public JSONObject prepareUpdateInteraction(String request, int updateId, String key1, String key2, String key3, String res1, String res2, String res3, String command){
try {
this.jsonRequest = new JSONObject();
this.jsonRequest.put("header", "gazeboindustries09082004");
this.jsonRequest.put("request", request);
this.jsonRequest.put("updateId", updateId);
this.jsonRequest.put("keyWord1", key1);
this.jsonRequest.put("keyWord2", key2);
this.jsonRequest.put("keyWord3", key3);
this.jsonRequest.put("response1", res1);
this.jsonRequest.put("response2", res2);
this.jsonRequest.put("response3", res3);
this.jsonRequest.put("command", command);

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

public JSONObject prepareUpdateDevice(String request, int updateId, String device, String desc, String json){
try {
this.jsonRequest = new JSONObject();
this.jsonRequest.put("header", "gazeboindustries09082004");
this.jsonRequest.put("request", request);
this.jsonRequest.put("updateId", updateId);
this.jsonRequest.put("device", device);
this.jsonRequest.put("description", desc);
this.jsonRequest.put("json", json);

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

public JSONObject prepareUpdateHomework(String request, int updateId, String type, String subject, String homework, String delivery, String desc){
try {
this.jsonRequest = new JSONObject();
this.jsonRequest.put("header", "gazeboindustries09082004");
this.jsonRequest.put("request", request);
this.jsonRequest.put("updateId", updateId);
this.jsonRequest.put("type", type);
this.jsonRequest.put("subject", subject);
this.jsonRequest.put("homeWork", homework);
this.jsonRequest.put("delivery", delivery);
this.jsonRequest.put("description", desc);

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

public JSONObject prepareUpdateProject(String request, int updateId, String project, String desc){
try {
this.jsonRequest = new JSONObject();
this.jsonRequest.put("header", "gazeboindustries09082004");
this.jsonRequest.put("request", request);
this.jsonRequest.put("updateId", updateId);
this.jsonRequest.put("project", project);
this.jsonRequest.put("repository", desc);

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

public JSONObject prepareDelete(String request, int deleteId){
try {
this.jsonRequest = new JSONObject();
this.jsonRequest.put("header", "gazeboindustries09082004");
this.jsonRequest.put("request", request);
this.jsonRequest.put("deleteId", deleteId);

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

0 comments on commit 37c3925

Please sign in to comment.