Skip to content

Commit

Permalink
DeletandoDados/ArrumandoDatas
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielSirtoriCorrea committed Jul 13, 2020
1 parent 0ae8c36 commit 3772942
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.gazeboindustries.sextafeiramobile.Fragments.DevicesFragments;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
Expand Down Expand Up @@ -36,11 +38,17 @@ public class ViewDevicesFragment extends Fragment {

private ServerConnection connection;

private AlertDialog.Builder removeAlert;
private AlertDialog removeDialog;


@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_viewdevice, container, false);

connection = new ServerConnection();

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

Expand All @@ -53,6 +61,29 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
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.setCancelable(false);

removeAlert.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(getContext(), "Cancelado", Toast.LENGTH_SHORT).show();
}
});

removeAlert.setPositiveButton("Excluir", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
connection.sendRequest(connection.prepareDelete("deleteDevice", ID));

if(connection.getMsgStatus()) {
Toast.makeText(getContext(), "Excluído", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getContext(), "Erro ao remover device", Toast.LENGTH_SHORT).show();
}
}
});

btnEditSend.setOnClickListener(new View.OnClickListener() {
@SuppressLint("SetTextI18n")
Expand All @@ -72,7 +103,6 @@ public void onClick(View view) {
btnDeleteCancel.setCompoundDrawablesWithIntrinsicBounds(cancelIcon, null, null, null);

}else{
connection = new ServerConnection();

connection.sendRequest(connection.prepareUpdateDevice("updateDevice", ID, txtDevice.getText().toString(), txtDescription.getText().toString(),
"json"));
Expand All @@ -89,18 +119,14 @@ public void onClick(View view) {
btnDeleteCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(btnDeleteCancel.getText().equals("Remover")){

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

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

if(btnDeleteCancel.getText().equals("Excluir")){
removeDialog = removeAlert.create();
removeDialog.show();
}else{
txtDevice.setEnabled(false);
txtDescription.setEnabled(false);

btnDeleteCancel.setText("Remover");
btnDeleteCancel.setText("Excluir");
btnEditSend.setText("Editar");

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

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

removeAlert.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(getContext(), "Cancelado", Toast.LENGTH_SHORT).show();
}
});

removeAlert.setPositiveButton("Remover", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(getContext(), "Removido", Toast.LENGTH_SHORT).show();

}
});
connection = new ServerConnection();

keyWord1 = view.findViewById(R.id.txtViewInteractionKeyword1);
keyWord2 = view.findViewById(R.id.txtViewInteractionKeyword2);
Expand All @@ -95,6 +78,30 @@ public void onClick(DialogInterface dialogInterface, int i) {
response3.setText(intent.getStringExtra("Response3"));
command.setText(intent.getStringExtra("Command"));

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

removeAlert.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(getContext(), "Cancelado", Toast.LENGTH_SHORT).show();
}
});

removeAlert.setPositiveButton("Excluir", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
connection.sendRequest(connection.prepareDelete("deleteInteraction", ID));

if(connection.getMsgStatus()) {
Toast.makeText(getContext(), "Excluído", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getContext(), "Erro ao remover Interação", Toast.LENGTH_SHORT).show();
}
}
});

btnEditSend.setOnClickListener(new View.OnClickListener() {
@SuppressLint("SetTextI18n")
@Override
Expand All @@ -118,7 +125,6 @@ public void onClick(View view) {
btnDeleteCancel.setCompoundDrawablesWithIntrinsicBounds(cancelIcon, null, null, null);

}else{
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(),
Expand All @@ -137,13 +143,10 @@ public void onClick(View view) {
@SuppressLint("SetTextI18n")
@Override
public void onClick(View view) {
if(btnDeleteCancel.getText().equals("Remover")){
if(btnDeleteCancel.getText().equals("Excluir")){
removeDialog = removeAlert.create();
removeDialog.show();

//connection = new ServerConnection();


}else{
keyWord1.setEnabled(false);
keyWord2.setEnabled(false);
Expand All @@ -153,7 +156,7 @@ public void onClick(View view) {
response3.setEnabled(false);
command.setEnabled(false);

btnDeleteCancel.setText("Remover");
btnDeleteCancel.setText("Excluir");
btnEditSend.setText("Editar");

editIcon = getResources().getDrawable(R.drawable.ic_edit_black_24dp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class AddHomeWorkFragment extends Fragment {
private Button btnAddHomeWork;
Expand All @@ -28,11 +29,14 @@ public class AddHomeWorkFragment extends Fragment {

private ServerConnection connection;
private SimpleDateFormat sdf;
private SimpleDateFormat dateOutput;
private Date dateFormated;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
sdf = new SimpleDateFormat("dd/MM/yyyy");
dateOutput = new SimpleDateFormat("yyyy-MM-dd");

View view = inflater.inflate(R.layout.fragment_addhomework, container, false);

Expand All @@ -50,10 +54,10 @@ public void onClick(View view) {
connection = new ServerConnection();

try {
sdf.parse(delivery.getText().toString());
dateFormated = sdf.parse(delivery.getText().toString());

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

if(connection.getMsgStatus()){
Toast.makeText(view.getContext(), "Tarefa enviada", Toast.LENGTH_SHORT).show();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.gazeboindustries.sextafeiramobile.Fragments.SkillsFragments.HomeworkFragments;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
Expand Down Expand Up @@ -40,16 +42,24 @@ public class ViewHomeWorkFragment extends Fragment {
private Drawable removeIcon;

private SimpleDateFormat sdf;
private SimpleDateFormat dateOutput;
private Date dateFormated;

private ServerConnection connection;
private int ID;

private AlertDialog.Builder removeAlert;
private AlertDialog removeDialog;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_viewhomework, container, false);

connection = new ServerConnection();

sdf = new SimpleDateFormat("dd/MM/yyyy");
dateOutput = new SimpleDateFormat("yyyy-MM-dd");


txtType = view.findViewById(R.id.txtViewHomeWorkType);
Expand All @@ -70,6 +80,30 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
txtDelivery.setText(intent.getStringExtra("Delivery"));
txtDescription.setText(intent.getStringExtra("Description"));

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

removeAlert.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(getContext(), "Cancelado", Toast.LENGTH_SHORT).show();
}
});

removeAlert.setPositiveButton("Excluir", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
connection.sendRequest(connection.prepareDelete("deleteHomeWork", ID));

if(connection.getMsgStatus()) {
Toast.makeText(getContext(), "Excluído", Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getContext(), "Erro ao remover tarefa", Toast.LENGTH_SHORT).show();
}
}
});

btnEditSend.setOnClickListener(new View.OnClickListener() {
@SuppressLint("SetTextI18n")
@Override
Expand All @@ -92,15 +126,31 @@ public void onClick(View view) {

}else{
try {
sdf.parse(txtDelivery.getText().toString());
dateFormated = sdf.parse(txtDelivery.getText().toString());

connection.sendRequest(connection.prepareUpdateHomework("updateHomeWork", ID, txtType.getText().toString(), txtSubject.getText().toString(),
txtHomeWork.getText().toString(), dateOutput.format(dateFormated), txtDescription.getText().toString()));


txtType.setEnabled(false);
txtSubject.setEnabled(false);
txtHomeWork.setEnabled(false);
txtDelivery.setEnabled(false);
txtDescription.setEnabled(false);

btnDeleteCancel.setText("Excluir");
btnEditSend.setText("Editar");

} catch (ParseException e) {
editIcon = getResources().getDrawable(R.drawable.ic_edit_black_24dp);
removeIcon = getResources().getDrawable(R.drawable.ic_delete_black_24dp);

btnEditSend.setCompoundDrawablesWithIntrinsicBounds(editIcon, null, null, null);
btnDeleteCancel.setCompoundDrawablesWithIntrinsicBounds(removeIcon, null, null, null);

} catch (ParseException e ) {
Toast.makeText(view.getContext(), "Insira um formato válido", Toast.LENGTH_SHORT).show();
}
connection = new ServerConnection();

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();
Expand All @@ -114,25 +164,11 @@ public void onClick(View view) {
btnDeleteCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(btnDeleteCancel.getText().equals("Remover")){
//show dialog
System.out.println("Remove");
if(btnDeleteCancel.getText().equals("Excluir")){
removeDialog = removeAlert.create();
removeDialog.show();

}else{
txtType.setEnabled(false);
txtSubject.setEnabled(false);
txtHomeWork.setEnabled(false);
txtDelivery.setEnabled(false);
txtDescription.setEnabled(false);

btnDeleteCancel.setText("Remover");
btnEditSend.setText("Editar");

editIcon = getResources().getDrawable(R.drawable.ic_edit_black_24dp);
removeIcon = getResources().getDrawable(R.drawable.ic_delete_black_24dp);

btnEditSend.setCompoundDrawablesWithIntrinsicBounds(editIcon, null, null, null);
btnDeleteCancel.setCompoundDrawablesWithIntrinsicBounds(removeIcon, null, null, null);

txtType.setText(intent.getStringExtra("Type"));
txtSubject.setText(intent.getStringExtra("Subject"));
Expand Down
Loading

0 comments on commit 3772942

Please sign in to comment.