...
This commit is contained in:
@@ -25,6 +25,7 @@ public class DetalhesReservasActivity extends AppCompatActivity {
|
||||
private TextView txtNotas;
|
||||
private TextView txtEstado;
|
||||
private TextView txtMensagem;
|
||||
private Button btnConfirmar, btnRecusar, btnApagar;
|
||||
private int selectedIndex = -1;
|
||||
|
||||
@Override
|
||||
@@ -51,6 +52,10 @@ public class DetalhesReservasActivity extends AppCompatActivity {
|
||||
txtEstado = findViewById(R.id.txtReservaEstado);
|
||||
txtMensagem = findViewById(R.id.txtMensagemReserva);
|
||||
|
||||
btnConfirmar = findViewById(R.id.btnConfirmarReserva);
|
||||
btnRecusar = findViewById(R.id.btnCancelarReserva);
|
||||
btnApagar = findViewById(R.id.btnApagarReserva);
|
||||
|
||||
Button back = findViewById(R.id.btnVoltar);
|
||||
if (back != null) {
|
||||
back.setOnClickListener(v -> finish());
|
||||
@@ -61,6 +66,7 @@ public class DetalhesReservasActivity extends AppCompatActivity {
|
||||
reservas.add(new ReservaItem("Ana Ribeiro", "Mesa 12", "20h00", 4, "Aniversário", "Confirmada"));
|
||||
reservas.add(new ReservaItem("Bruno Costa", "Mesa 03", "21h15", 2, "Preferência por janela", "Pendente"));
|
||||
reservas.add(new ReservaItem("Carla Silva", "Mesa 07", "19h30", 3, "Levar bolo para a mesa", "Pendente"));
|
||||
reservas.add(new ReservaItem("Duarte Neves", "Mesa 01", "22h00", 2, "", "Concluída"));
|
||||
}
|
||||
|
||||
private void setupList() {
|
||||
@@ -75,16 +81,59 @@ public class DetalhesReservasActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void setupActions() {
|
||||
Button btnConfirmar = findViewById(R.id.btnConfirmarReserva);
|
||||
Button btnCancelar = findViewById(R.id.btnCancelarReserva);
|
||||
|
||||
if (btnConfirmar != null) {
|
||||
btnConfirmar.setOnClickListener(v -> atualizarEstadoSelecionado("Confirmada"));
|
||||
btnConfirmar.setOnClickListener(v -> {
|
||||
ReservaItem item = reservas.get(selectedIndex);
|
||||
if ("Pendente".equals(item.estado)) {
|
||||
atualizarEstadoSelecionado("Confirmada");
|
||||
} else if ("Confirmada".equals(item.estado)) {
|
||||
atualizarEstadoSelecionado("Concluída");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (btnCancelar != null) {
|
||||
btnCancelar.setOnClickListener(v -> atualizarEstadoSelecionado("Cancelada"));
|
||||
if (btnRecusar != null) {
|
||||
btnRecusar.setOnClickListener(v -> showRecusarDialog());
|
||||
}
|
||||
|
||||
if (btnApagar != null) {
|
||||
btnApagar.setOnClickListener(v -> apagarReserva());
|
||||
}
|
||||
}
|
||||
|
||||
private void showRecusarDialog() {
|
||||
if (selectedIndex < 0)
|
||||
return;
|
||||
|
||||
String[] motivos = { "Sem espaço no restaurante", "Fora de horas", "Reserva duplicada", "Outro" };
|
||||
new androidx.appcompat.app.AlertDialog.Builder(this)
|
||||
.setTitle("Motivo da Recusa")
|
||||
.setItems(motivos, (dialog, which) -> {
|
||||
atualizarEstadoSelecionado("Recusada (" + motivos[which] + ")");
|
||||
})
|
||||
.setNegativeButton("Voltar", null)
|
||||
.show();
|
||||
}
|
||||
|
||||
private void apagarReserva() {
|
||||
if (selectedIndex < 0)
|
||||
return;
|
||||
|
||||
new androidx.appcompat.app.AlertDialog.Builder(this)
|
||||
.setTitle("Apagar Reserva")
|
||||
.setMessage("Tem a certeza que deseja apagar esta reserva?")
|
||||
.setPositiveButton("Apagar", (dialog, which) -> {
|
||||
reservas.remove(selectedIndex);
|
||||
selectedIndex = -1;
|
||||
txtInfo.setText("Selecione uma reserva");
|
||||
txtNotas.setText("");
|
||||
txtEstado.setText("Estado:");
|
||||
txtMensagem.setText("Reserva apagada com sucesso.");
|
||||
toggleButtons(null);
|
||||
refreshList();
|
||||
})
|
||||
.setNegativeButton("Voltar", null)
|
||||
.show();
|
||||
}
|
||||
|
||||
private void atualizarEstadoSelecionado(String novoEstado) {
|
||||
@@ -104,6 +153,41 @@ public class DetalhesReservasActivity extends AppCompatActivity {
|
||||
txtInfo.setText(String.format("%s • %s • %s • %dp", item.nomeCliente, item.mesa, item.hora, item.pessoas));
|
||||
txtNotas.setText(item.notas);
|
||||
txtEstado.setText(String.format("Estado: %s", item.estado));
|
||||
toggleButtons(item);
|
||||
}
|
||||
|
||||
private void toggleButtons(ReservaItem item) {
|
||||
if (item == null) {
|
||||
btnConfirmar.setVisibility(android.view.View.GONE);
|
||||
btnRecusar.setVisibility(android.view.View.GONE);
|
||||
btnApagar.setVisibility(android.view.View.GONE);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (item.estado) {
|
||||
case "Pendente":
|
||||
btnConfirmar.setText("Confirmar");
|
||||
btnConfirmar.setVisibility(android.view.View.VISIBLE);
|
||||
btnRecusar.setVisibility(android.view.View.VISIBLE);
|
||||
btnApagar.setVisibility(android.view.View.GONE);
|
||||
break;
|
||||
case "Confirmada":
|
||||
btnConfirmar.setText("Concluir");
|
||||
btnConfirmar.setVisibility(android.view.View.VISIBLE);
|
||||
btnRecusar.setVisibility(android.view.View.VISIBLE); // Still allow refusal
|
||||
btnApagar.setVisibility(android.view.View.GONE);
|
||||
break;
|
||||
case "Concluída":
|
||||
btnConfirmar.setVisibility(android.view.View.GONE);
|
||||
btnRecusar.setVisibility(android.view.View.GONE);
|
||||
btnApagar.setVisibility(android.view.View.VISIBLE);
|
||||
break;
|
||||
default: // Recusada or Cancelada
|
||||
btnConfirmar.setVisibility(android.view.View.GONE);
|
||||
btnRecusar.setVisibility(android.view.View.GONE);
|
||||
btnApagar.setVisibility(android.view.View.VISIBLE); // Allow deleting refused ones as well
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void refreshList() {
|
||||
@@ -133,13 +217,3 @@ public class DetalhesReservasActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user