Skip to content

Commit

Permalink
ReformulandoTabelasDeviceProjects
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielSirtoriCorrea committed Jul 18, 2020
1 parent 4c1e78f commit dee1ac6
Show file tree
Hide file tree
Showing 21 changed files with 155 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class AddDeviceFragment extends Fragment {
private Button btnAddDevice;
private EditText device;
private EditText desc;
private EditText actions;

private ServerConnection connection;

Expand All @@ -31,13 +32,14 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c

device = view.findViewById(R.id.txtAddDevice);
desc = view.findViewById(R.id.txtAddDeviceDescription);
actions = view.findViewById(R.id.txtAddDeviceActions);

btnAddDevice.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
connection = new ServerConnection();

connection.sendRequest(connection.prepareAddDevice("insertDevice", device.getText().toString(), desc.getText().toString(), "json"));
connection.sendRequest(connection.prepareAddDevice("insertDevice", device.getText().toString(), desc.getText().toString(), Integer.parseInt(actions.getText().toString())));

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 @@ -53,7 +53,7 @@ public void onClick(View view) {

ServerConnection connection = new ServerConnection();

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

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

Expand All @@ -67,6 +67,7 @@ public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
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());
intent.putExtra("Actions", arrayList.get(i).getInt(3));

assert getFragmentManager() != null;
getFragmentManager().beginTransaction().replace(R.id.frame, new ViewDevicesFragment()).commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class ViewDevicesFragment extends Fragment {
private Intent intent;
private EditText txtDevice;
private EditText txtDescription;
private EditText txtActions;

private Button btnEditSend;
private Button btnDeleteCancel;
Expand All @@ -42,6 +43,7 @@ public class ViewDevicesFragment extends Fragment {
private AlertDialog removeDialog;


@SuppressLint("SetTextI18n")
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
Expand All @@ -51,18 +53,20 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c

txtDevice = view.findViewById(R.id.txtViewDevice);
txtDescription = view.findViewById(R.id.txtViewDeviceDescription);
txtActions = view.findViewById(R.id.txtViewDeviceActions);

intent = getActivity().getIntent();

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

btnEditSend = view.findViewById(R.id.btnEditDevice);
btnDeleteCancel = view.findViewById(R.id.btnRemoveDevice);

removeAlert = new AlertDialog.Builder(view.getContext());
removeAlert.setMessage("Deseja remover a interação?");
removeAlert.setMessage("Deseja remover o device?");
removeAlert.setCancelable(false);

removeAlert.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
Expand Down Expand Up @@ -92,6 +96,7 @@ public void onClick(View view) {
if(btnEditSend.getText().equals("Editar")){
txtDevice.setEnabled(true);
txtDescription.setEnabled(true);
txtActions.setEnabled(true);

btnDeleteCancel.setText("Cancelar");
btnEditSend.setText("Salvar");
Expand All @@ -104,10 +109,11 @@ public void onClick(View view) {

}else{
connection.sendRequest(connection.prepareUpdateDevice("updateDevice", ID, txtDevice.getText().toString(), txtDescription.getText().toString(),
"json"));
Integer.parseInt(txtActions.getText().toString())));

txtDevice.setEnabled(false);
txtDescription.setEnabled(false);
txtActions.setEnabled(false);

btnDeleteCancel.setText("Excluir");
btnEditSend.setText("Editar");
Expand All @@ -121,6 +127,7 @@ public void onClick(View view) {
intent.putExtra("ID", ID);
intent.putExtra("Device", txtDevice.getText().toString());
intent.putExtra("Description", txtDescription.getText().toString());
intent.putExtra("Actions", Integer.parseInt(txtActions.getText().toString()));

if(connection.getMsgStatus()){
Toast.makeText(getContext(), "Salvo", Toast.LENGTH_SHORT).show();
Expand Down Expand Up @@ -152,6 +159,7 @@ public void onClick(View view) {

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

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

public class AddProjectFragment extends Fragment {
private Button btnAddProject;
private EditText type;
private EditText project;

private ServerConnection connection;
Expand All @@ -28,13 +29,14 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c

btnAddProject = view.findViewById(R.id.btnAddProject);
project = view.findViewById(R.id.txtAddNameProject);
type = view.findViewById(R.id.txtAddTypeProject);

btnAddProject.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
connection = new ServerConnection();

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

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 @@ -64,7 +64,7 @@ public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
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());
intent.putExtra("type", arrayList.get(i).get(2).toString());

assert getFragmentManager() != null;
getFragmentManager().beginTransaction().replace(R.id.frame, new ViewProjectsFragment()).commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class ViewProjectsFragment extends Fragment {
private Intent intent;
private EditText txtProject;
private EditText txtRepository;
private EditText txtType;

private Button btnEditSend;
private Button btnDeleteCancel;
Expand All @@ -48,7 +48,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
connection = new ServerConnection();

txtProject = view.findViewById(R.id.txtViewProject);
txtRepository = view.findViewById(R.id.txtViewRepository);
txtType = view.findViewById(R.id.txtViewProjectType);

btnEditSend = view.findViewById(R.id.btnEditProject);
btnDeleteCancel = view.findViewById(R.id.btnRemoveProject);
Expand All @@ -57,10 +57,10 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c

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

removeAlert = new AlertDialog.Builder(view.getContext());
removeAlert.setMessage("Deseja remover a interação?");
removeAlert.setMessage("Deseja remover o projeto?");
removeAlert.setCancelable(false);

removeAlert.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
Expand Down Expand Up @@ -89,7 +89,7 @@ public void onClick(DialogInterface dialogInterface, int i) {
public void onClick(View view) {
if(btnEditSend.getText().equals("Editar")){
txtProject.setEnabled(true);
txtRepository.setEnabled(true);
txtType.setEnabled(true);


btnDeleteCancel.setText("Cancelar");
Expand All @@ -102,10 +102,10 @@ public void onClick(View view) {
btnDeleteCancel.setCompoundDrawablesWithIntrinsicBounds(cancelIcon, null, null, null);

}else{
connection.sendRequest(connection.prepareUpdateProject("updateProject", ID, txtProject.getText().toString(), txtRepository.getText().toString()));
connection.sendRequest(connection.prepareUpdateProject("updateProject", ID, txtType.getText().toString(), txtProject.getText().toString()));

txtProject.setEnabled(false);
txtRepository.setEnabled(false);
txtType.setEnabled(false);

btnDeleteCancel.setText("Excluir");
btnEditSend.setText("Editar");
Expand All @@ -118,7 +118,7 @@ public void onClick(View view) {

intent.putExtra("ID", ID);
intent.putExtra("Project", txtProject.getText().toString());
intent.putExtra("Repository", txtRepository.getText().toString());
intent.putExtra("type", txtType.getText().toString());

if(connection.getMsgStatus()){
Toast.makeText(getContext(), "Salvo", Toast.LENGTH_SHORT).show();
Expand All @@ -138,7 +138,7 @@ public void onClick(View view) {

}else{
txtProject.setEnabled(false);
txtRepository.setEnabled(false);
txtType.setEnabled(false);

btnDeleteCancel.setText("Excluir");
btnEditSend.setText("Editar");
Expand All @@ -150,7 +150,7 @@ public void onClick(View view) {
btnDeleteCancel.setCompoundDrawablesWithIntrinsicBounds(removeIcon, null, null, null);

txtProject.setText(intent.getStringExtra("Project"));
txtRepository.setText(intent.getStringExtra("Repository"));
txtType.setText(intent.getStringExtra("type"));


}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ public View getView(int position, View convertView, ViewGroup parent) {
listID.setText(arrayLine.get(0).toString());
listField1.setText(arrayLine.get(1).toString());
listField2.setText(arrayLine.get(2).toString());
listField3.setText(arrayLine.get(3).toString());
break;
case "Projects":
arrayLine = list.get(position);

listID.setText(arrayLine.get(0).toString());
listField1.setText(arrayLine.get(1).toString());
listField2.setText(arrayLine.get(2).toString());
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ public JSONObject prepareAddInteraction(String request, String key1, String key2
return jsonRequest;
}

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

} catch (JSONException e) {
e.printStackTrace();
Expand All @@ -145,13 +145,13 @@ public JSONObject prepareAddHomework(String request, String type, String subject
return jsonRequest;
}

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

} catch (JSONException e) {
e.printStackTrace();
Expand Down Expand Up @@ -190,15 +190,15 @@ public JSONObject prepareUpdateInteraction(String request, int updateId, String
return jsonRequest;
}

public JSONObject prepareUpdateDevice(String request, int updateId, String device, String desc, String json){
public JSONObject prepareUpdateDevice(String request, int updateId, String device, String desc, int actions){
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);
this.jsonRequest.put("actions", actions);

} catch (JSONException e) {
e.printStackTrace();
Expand All @@ -224,14 +224,14 @@ public JSONObject prepareUpdateHomework(String request, int updateId, String typ
return jsonRequest;
}

public JSONObject prepareUpdateProject(String request, int updateId, String project, String desc){
public JSONObject prepareUpdateProject(String request, int updateId, String type, String project){
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("project", project);
this.jsonRequest.put("repository", desc);

} catch (JSONException e) {
e.printStackTrace();
Expand Down
27 changes: 27 additions & 0 deletions App/app/src/main/res/layout/fragment_adddevice.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,33 @@

</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/actions_"
android:textColor="#fff"
android:textSize="20sp"
android:layout_marginStart="10sp"
android:layout_marginTop="10dp"
android:fontFamily="sans-serif-black"/>

<EditText
android:layout_width="290dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginStart="5dp"
android:textColor="#fff"
android:fontFamily="sans-serif-black"
android:textSize="20sp"
android:id="@+id/txtAddDeviceActions"
/>

</LinearLayout>

<Button
android:layout_width="250dp"
Expand Down
28 changes: 28 additions & 0 deletions App/app/src/main/res/layout/fragment_addproject.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,34 @@
android:layout_margin="10dp"
/>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/tipo_"
android:textColor="#fff"
android:textSize="20sp"
android:layout_marginStart="10sp"
android:layout_marginTop="10dp"
android:fontFamily="sans-serif-black"/>

<EditText
android:layout_width="295dp"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_marginStart="5dp"
android:textColor="#fff"
android:fontFamily="sans-serif-black"
android:textSize="20sp"
android:id="@+id/txtAddTypeProject"
/>

</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
Loading

0 comments on commit dee1ac6

Please sign in to comment.