146 lines
4.7 KiB
Java
146 lines
4.7 KiB
Java
package com.example.pap_teste;
|
|
|
|
import android.os.Bundle;
|
|
import android.widget.ArrayAdapter;
|
|
import android.widget.Button;
|
|
import android.widget.ListView;
|
|
import android.widget.TextView;
|
|
import android.widget.Toast;
|
|
|
|
import androidx.activity.EdgeToEdge;
|
|
import androidx.appcompat.app.AppCompatActivity;
|
|
import androidx.core.graphics.Insets;
|
|
import androidx.core.view.ViewCompat;
|
|
import androidx.core.view.WindowInsetsCompat;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class DetalhesReservasActivity extends AppCompatActivity {
|
|
|
|
private final List<ReservaItem> reservas = new ArrayList<>();
|
|
private ArrayAdapter<String> adapter;
|
|
private ListView listReservas;
|
|
private TextView txtInfo;
|
|
private TextView txtNotas;
|
|
private TextView txtEstado;
|
|
private TextView txtMensagem;
|
|
private int selectedIndex = -1;
|
|
|
|
@Override
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
EdgeToEdge.enable(this);
|
|
setContentView(R.layout.activity_detalhes_reservas);
|
|
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.detalhesReservasRoot), (v, insets) -> {
|
|
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
|
|
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
|
return insets;
|
|
});
|
|
|
|
bindViews();
|
|
seedReservasDemo();
|
|
setupList();
|
|
setupActions();
|
|
}
|
|
|
|
private void bindViews() {
|
|
listReservas = findViewById(R.id.listReservas);
|
|
txtInfo = findViewById(R.id.txtReservaInfo);
|
|
txtNotas = findViewById(R.id.txtReservaNotas);
|
|
txtEstado = findViewById(R.id.txtReservaEstado);
|
|
txtMensagem = findViewById(R.id.txtMensagemReserva);
|
|
|
|
Button back = findViewById(R.id.btnVoltar);
|
|
if (back != null) {
|
|
back.setOnClickListener(v -> finish());
|
|
}
|
|
}
|
|
|
|
private void seedReservasDemo() {
|
|
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"));
|
|
}
|
|
|
|
private void setupList() {
|
|
adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_activated_1);
|
|
listReservas.setAdapter(adapter);
|
|
refreshList();
|
|
|
|
listReservas.setOnItemClickListener((parent, view, position, id) -> {
|
|
selectedIndex = position;
|
|
mostrarDetalhe(reservas.get(position));
|
|
});
|
|
}
|
|
|
|
private void setupActions() {
|
|
Button btnConfirmar = findViewById(R.id.btnConfirmarReserva);
|
|
Button btnCancelar = findViewById(R.id.btnCancelarReserva);
|
|
|
|
if (btnConfirmar != null) {
|
|
btnConfirmar.setOnClickListener(v -> atualizarEstadoSelecionado("Confirmada"));
|
|
}
|
|
|
|
if (btnCancelar != null) {
|
|
btnCancelar.setOnClickListener(v -> atualizarEstadoSelecionado("Cancelada"));
|
|
}
|
|
}
|
|
|
|
private void atualizarEstadoSelecionado(String novoEstado) {
|
|
if (selectedIndex < 0 || selectedIndex >= reservas.size()) {
|
|
Toast.makeText(this, "Selecione uma reserva para atualizar.", Toast.LENGTH_SHORT).show();
|
|
return;
|
|
}
|
|
|
|
ReservaItem item = reservas.get(selectedIndex);
|
|
item.estado = novoEstado;
|
|
txtMensagem.setText(String.format("Reserva de %s marcada como %s.", item.nomeCliente, novoEstado));
|
|
mostrarDetalhe(item);
|
|
refreshList();
|
|
}
|
|
|
|
private void mostrarDetalhe(ReservaItem item) {
|
|
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));
|
|
}
|
|
|
|
private void refreshList() {
|
|
adapter.clear();
|
|
for (ReservaItem item : reservas) {
|
|
String resumo = String.format("%s - %s (%s) • %s", item.hora, item.mesa, item.estado, item.nomeCliente);
|
|
adapter.add(resumo);
|
|
}
|
|
adapter.notifyDataSetChanged();
|
|
}
|
|
|
|
private static class ReservaItem {
|
|
String nomeCliente;
|
|
String mesa;
|
|
String hora;
|
|
int pessoas;
|
|
String notas;
|
|
String estado;
|
|
|
|
ReservaItem(String nomeCliente, String mesa, String hora, int pessoas, String notas, String estado) {
|
|
this.nomeCliente = nomeCliente;
|
|
this.mesa = mesa;
|
|
this.hora = hora;
|
|
this.pessoas = pessoas;
|
|
this.notas = notas;
|
|
this.estado = estado;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|