ecra principal
This commit is contained in:
3
.idea/deploymentTargetSelector.xml
generated
3
.idea/deploymentTargetSelector.xml
generated
@@ -5,6 +5,9 @@
|
|||||||
<SelectionState runConfigName="app">
|
<SelectionState runConfigName="app">
|
||||||
<option name="selectionMode" value="DROPDOWN" />
|
<option name="selectionMode" value="DROPDOWN" />
|
||||||
</SelectionState>
|
</SelectionState>
|
||||||
|
<SelectionState runConfigName="Pap_teste">
|
||||||
|
<option name="selectionMode" value="DROPDOWN" />
|
||||||
|
</SelectionState>
|
||||||
</selectionStates>
|
</selectionStates>
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -4,6 +4,13 @@ import android.os.Bundle;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
import android.widget.Spinner;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
|
import android.widget.Toast;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.text.InputType;
|
||||||
|
|
||||||
import androidx.activity.EdgeToEdge;
|
import androidx.activity.EdgeToEdge;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
@@ -19,7 +26,13 @@ public class AddStaffActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
private Button addButton;
|
private Button addButton;
|
||||||
private EditText nameEditText;
|
private EditText nameEditText;
|
||||||
|
private Spinner zonaSpinner;
|
||||||
|
private Button btnAddZone;
|
||||||
|
private Spinner mesaSpinner;
|
||||||
|
private ArrayList<String> zones;
|
||||||
|
private ArrayList<String> mesas;
|
||||||
|
private ArrayAdapter<String> adapter;
|
||||||
|
private ArrayAdapter<String> mesaAdapter;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -34,25 +47,82 @@ public class AddStaffActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
addButton = findViewById(R.id.addButton);
|
addButton = findViewById(R.id.addButton);
|
||||||
nameEditText = findViewById(R.id.nammeEditText);
|
nameEditText = findViewById(R.id.nammeEditText);
|
||||||
|
zonaSpinner = findViewById(R.id.zonaSpinner);
|
||||||
|
btnAddZone = findViewById(R.id.btnAddZone);
|
||||||
|
mesaSpinner = findViewById(R.id.mesaSpinner);
|
||||||
|
|
||||||
|
zones = new ArrayList<>();
|
||||||
|
zones.add("Sala");
|
||||||
|
zones.add("Esplanada");
|
||||||
|
zones.add("Balcão");
|
||||||
|
|
||||||
|
adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, zones);
|
||||||
|
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||||
|
zonaSpinner.setAdapter(adapter);
|
||||||
|
|
||||||
|
mesas = new ArrayList<>();
|
||||||
|
for (int i = 1; i <= 10; i++) {
|
||||||
|
mesas.add("Mesa " + i);
|
||||||
|
}
|
||||||
|
mesaAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, mesas);
|
||||||
|
mesaAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||||
|
mesaSpinner.setAdapter(mesaAdapter);
|
||||||
|
|
||||||
|
btnAddZone.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(AddStaffActivity.this);
|
||||||
|
builder.setTitle("Adicionar Zona");
|
||||||
|
|
||||||
|
final EditText input = new EditText(AddStaffActivity.this);
|
||||||
|
input.setInputType(InputType.TYPE_CLASS_TEXT);
|
||||||
|
builder.setView(input);
|
||||||
|
|
||||||
|
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
String newZone = input.getText().toString();
|
||||||
|
if (!newZone.isEmpty()) {
|
||||||
|
zones.add(newZone);
|
||||||
|
adapter.notifyDataSetChanged();
|
||||||
|
zonaSpinner.setSelection(zones.size() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
dialog.cancel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
addButton.setOnClickListener(new View.OnClickListener() {
|
addButton.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
String name = nameEditText.getText().toString();
|
String name = nameEditText.getText().toString();
|
||||||
//String zona = zonaSpinner.getSelectedItem().toString();
|
String zona = "";
|
||||||
|
if (zonaSpinner.getSelectedItem() != null) {
|
||||||
|
zona = zonaSpinner.getSelectedItem().toString();
|
||||||
|
}
|
||||||
|
String mesa = "";
|
||||||
|
if (mesaSpinner.getSelectedItem() != null) {
|
||||||
|
mesa = mesaSpinner.getSelectedItem().toString();
|
||||||
|
}
|
||||||
|
|
||||||
if (!name.isEmpty()) {
|
if (!name.isEmpty()) {
|
||||||
DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("Staff");
|
DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("Staff");
|
||||||
String uuid = java.util.UUID.randomUUID().toString();
|
String uuid = java.util.UUID.randomUUID().toString();
|
||||||
Staff staff = new Staff(name, "Zona 1",uuid);
|
Staff staff = new Staff(name, zona, mesa, uuid);
|
||||||
databaseReference.child(uuid).setValue(staff);
|
databaseReference.child(uuid).setValue(staff);
|
||||||
|
|
||||||
//mensagem de sucesso
|
Toast.makeText(AddStaffActivity.this, "Staff adicionado com sucesso!", Toast.LENGTH_SHORT).show();
|
||||||
finish();
|
finish();
|
||||||
}
|
} else {
|
||||||
else{
|
Toast.makeText(AddStaffActivity.this, "Erro: Preencha todos os campos", Toast.LENGTH_SHORT).show();
|
||||||
//colocar mensagem de error tem que estar tudo preenchido
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -15,18 +15,28 @@ import androidx.core.graphics.Insets;
|
|||||||
import androidx.core.view.ViewCompat;
|
import androidx.core.view.ViewCompat;
|
||||||
import androidx.core.view.WindowInsetsCompat;
|
import androidx.core.view.WindowInsetsCompat;
|
||||||
|
|
||||||
|
import com.example.pap_teste.models.Mesa;
|
||||||
|
import com.google.firebase.database.DataSnapshot;
|
||||||
|
import com.google.firebase.database.DatabaseError;
|
||||||
|
import com.google.firebase.database.DatabaseReference;
|
||||||
|
import com.google.firebase.database.FirebaseDatabase;
|
||||||
|
import com.google.firebase.database.ValueEventListener;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
public class GerirMesasActivity extends AppCompatActivity {
|
public class GerirMesasActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private final List<MesaItem> mesas = new ArrayList<>();
|
private final List<Mesa> mesas = new ArrayList<>();
|
||||||
private ArrayAdapter<String> adapter;
|
private ArrayAdapter<String> adapter;
|
||||||
private ListView listMesas;
|
private ListView listMesas;
|
||||||
private EditText inputNumero;
|
private EditText inputNumero;
|
||||||
private EditText inputCapacidade;
|
private EditText inputCapacidade;
|
||||||
private Spinner spinnerEstado;
|
private Spinner spinnerEstado;
|
||||||
private TextView txtMensagem;
|
private TextView txtMensagem;
|
||||||
|
private DatabaseReference mDatabase;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -40,7 +50,9 @@ public class GerirMesasActivity extends AppCompatActivity {
|
|||||||
});
|
});
|
||||||
|
|
||||||
bindViews();
|
bindViews();
|
||||||
seedMesasDemo();
|
|
||||||
|
mDatabase = FirebaseDatabase.getInstance().getReference("Mesas");
|
||||||
|
|
||||||
setupList();
|
setupList();
|
||||||
setupFormActions();
|
setupFormActions();
|
||||||
}
|
}
|
||||||
@@ -60,29 +72,44 @@ public class GerirMesasActivity extends AppCompatActivity {
|
|||||||
ArrayAdapter<String> estadoAdapter = new ArrayAdapter<>(
|
ArrayAdapter<String> estadoAdapter = new ArrayAdapter<>(
|
||||||
this,
|
this,
|
||||||
android.R.layout.simple_spinner_dropdown_item,
|
android.R.layout.simple_spinner_dropdown_item,
|
||||||
new String[]{"Livre", "Ocupada", "Reservada"}
|
new String[] { "Livre", "Ocupada", "Reservada" });
|
||||||
);
|
|
||||||
spinnerEstado.setAdapter(estadoAdapter);
|
spinnerEstado.setAdapter(estadoAdapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void seedMesasDemo() {
|
|
||||||
mesas.add(new MesaItem(1, 4, "Livre"));
|
|
||||||
mesas.add(new MesaItem(2, 2, "Reservada"));
|
|
||||||
mesas.add(new MesaItem(3, 6, "Ocupada"));
|
|
||||||
mesas.add(new MesaItem(4, 4, "Livre"));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setupList() {
|
private void setupList() {
|
||||||
adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_activated_1);
|
adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_activated_1);
|
||||||
listMesas.setAdapter(adapter);
|
listMesas.setAdapter(adapter);
|
||||||
refreshList();
|
|
||||||
|
mDatabase.addValueEventListener(new ValueEventListener() {
|
||||||
|
@Override
|
||||||
|
public void onDataChange(@NonNull DataSnapshot snapshot) {
|
||||||
|
mesas.clear();
|
||||||
|
adapter.clear();
|
||||||
|
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
|
||||||
|
Mesa mesa = postSnapshot.getValue(Mesa.class);
|
||||||
|
if (mesa != null) {
|
||||||
|
mesas.add(mesa);
|
||||||
|
String resumo = String.format("Mesa %02d • %d lugares • %s", mesa.getNumero(),
|
||||||
|
mesa.getCapacidade(), mesa.getEstado());
|
||||||
|
adapter.add(resumo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
adapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCancelled(@NonNull DatabaseError error) {
|
||||||
|
Toast.makeText(GerirMesasActivity.this, "Erro ao carregar mesas: " + error.getMessage(),
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
listMesas.setOnItemClickListener((parent, view, position, id) -> {
|
listMesas.setOnItemClickListener((parent, view, position, id) -> {
|
||||||
MesaItem item = mesas.get(position);
|
Mesa item = mesas.get(position);
|
||||||
inputNumero.setText(String.valueOf(item.numero));
|
inputNumero.setText(String.valueOf(item.getNumero()));
|
||||||
inputCapacidade.setText(String.valueOf(item.capacidade));
|
inputCapacidade.setText(String.valueOf(item.getCapacidade()));
|
||||||
spinnerEstado.setSelection(getEstadoIndex(item.estado));
|
spinnerEstado.setSelection(getEstadoIndex(item.getEstado()));
|
||||||
txtMensagem.setText(String.format("Editar mesa %d", item.numero));
|
txtMensagem.setText(String.format("Editar mesa %d", item.getNumero()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,56 +150,36 @@ public class GerirMesasActivity extends AppCompatActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MesaItem existente = findMesa(numero);
|
Mesa existente = findMesa(numero);
|
||||||
|
String mesaId;
|
||||||
|
|
||||||
if (existente == null) {
|
if (existente == null) {
|
||||||
mesas.add(new MesaItem(numero, capacidade, estado));
|
mesaId = mDatabase.push().getKey();
|
||||||
txtMensagem.setText(String.format("Mesa %d adicionada/atualizada.", numero));
|
Mesa novaMesa = new Mesa(mesaId, numero, capacidade, estado);
|
||||||
|
if (mesaId != null) {
|
||||||
|
mDatabase.child(mesaId).setValue(novaMesa);
|
||||||
|
}
|
||||||
|
txtMensagem.setText(String.format("Mesa %d adicionada.", numero));
|
||||||
} else {
|
} else {
|
||||||
existente.capacidade = capacidade;
|
mesaId = existente.getId();
|
||||||
existente.estado = estado;
|
existente.setCapacidade(capacidade);
|
||||||
|
existente.setEstado(estado);
|
||||||
|
mDatabase.child(mesaId).setValue(existente);
|
||||||
txtMensagem.setText(String.format("Mesa %d atualizada.", numero));
|
txtMensagem.setText(String.format("Mesa %d atualizada.", numero));
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshList();
|
// Clearing inputs
|
||||||
|
inputNumero.setText("");
|
||||||
|
inputCapacidade.setText("");
|
||||||
}
|
}
|
||||||
|
|
||||||
private MesaItem findMesa(int numero) {
|
private Mesa findMesa(int numero) {
|
||||||
for (MesaItem item : mesas) {
|
for (Mesa item : mesas) {
|
||||||
if (item.numero == numero) {
|
if (item.getNumero() == numero) {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshList() {
|
|
||||||
adapter.clear();
|
|
||||||
for (MesaItem item : mesas) {
|
|
||||||
String resumo = String.format("Mesa %02d • %d lugares • %s", item.numero, item.capacidade, item.estado);
|
|
||||||
adapter.add(resumo);
|
|
||||||
}
|
|
||||||
adapter.notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class MesaItem {
|
|
||||||
int numero;
|
|
||||||
int capacidade;
|
|
||||||
String estado;
|
|
||||||
|
|
||||||
MesaItem(int numero, int capacidade, String estado) {
|
|
||||||
this.numero = numero;
|
|
||||||
this.capacidade = capacidade;
|
|
||||||
this.estado = estado;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,21 @@
|
|||||||
package com.example.pap_teste;
|
package com.example.pap_teste;
|
||||||
|
|
||||||
|
import com.example.pap_teste.models.Mesa;
|
||||||
|
import com.example.pap_teste.models.Staff;
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||||
import com.google.firebase.firestore.FirebaseFirestore;
|
import com.google.firebase.database.DataSnapshot;
|
||||||
import com.google.firebase.firestore.QueryDocumentSnapshot;
|
import com.google.firebase.database.DatabaseError;
|
||||||
|
import com.google.firebase.database.DatabaseReference;
|
||||||
|
import com.google.firebase.database.FirebaseDatabase;
|
||||||
|
import com.google.firebase.database.ValueEventListener;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@@ -26,16 +32,21 @@ import java.util.List;
|
|||||||
|
|
||||||
public class GestaoStaffActivity extends AppCompatActivity {
|
public class GestaoStaffActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private final List<StaffAssignment> staffAssignments = new ArrayList<>();
|
private final List<Staff> staffList = new ArrayList<>();
|
||||||
private ArrayAdapter<String> staffAdapter;
|
private ArrayAdapter<String> staffAdapter;
|
||||||
private ListView listStaffMesas;
|
private ListView listStaffMesas;
|
||||||
|
|
||||||
private Spinner spinnerNomeStaff;
|
private Spinner spinnerNomeStaff;
|
||||||
private Spinner spinnerMesaStaff;
|
private Spinner spinnerMesaStaff;
|
||||||
private TextView txtMensagemStaff;
|
private TextView txtMensagemStaff;
|
||||||
private FirebaseFirestore firestore;
|
|
||||||
|
private DatabaseReference staffRef;
|
||||||
|
private DatabaseReference mesasRef;
|
||||||
|
|
||||||
private List<String> staffNames = new ArrayList<>();
|
private List<String> staffNames = new ArrayList<>();
|
||||||
|
private List<Mesa> mesasDisponiveis = new ArrayList<>();
|
||||||
private ArrayAdapter<String> staffNameAdapter;
|
private ArrayAdapter<String> staffNameAdapter;
|
||||||
|
private ArrayAdapter<String> mesaSpinnerAdapter;
|
||||||
|
|
||||||
private FloatingActionButton floatingActionButton;
|
private FloatingActionButton floatingActionButton;
|
||||||
|
|
||||||
@@ -50,7 +61,8 @@ public class GestaoStaffActivity extends AppCompatActivity {
|
|||||||
return insets;
|
return insets;
|
||||||
});
|
});
|
||||||
|
|
||||||
firestore = FirebaseFirestore.getInstance();
|
staffRef = FirebaseDatabase.getInstance().getReference("Staff");
|
||||||
|
mesasRef = FirebaseDatabase.getInstance().getReference("Mesas");
|
||||||
|
|
||||||
Button back = findViewById(R.id.btnVoltar);
|
Button back = findViewById(R.id.btnVoltar);
|
||||||
if (back != null) {
|
if (back != null) {
|
||||||
@@ -76,7 +88,7 @@ public class GestaoStaffActivity extends AppCompatActivity {
|
|||||||
* Mais tarde isto pode ser ligado às mesas reais configuradas em "Gerir Mesas".
|
* Mais tarde isto pode ser ligado às mesas reais configuradas em "Gerir Mesas".
|
||||||
*/
|
*/
|
||||||
private void setupMesaSpinner() {
|
private void setupMesaSpinner() {
|
||||||
ArrayAdapter<String> mesaAdapter = new ArrayAdapter<>(
|
mesaSpinnerAdapter = new ArrayAdapter<>(
|
||||||
this,
|
this,
|
||||||
android.R.layout.simple_spinner_dropdown_item);
|
android.R.layout.simple_spinner_dropdown_item);
|
||||||
|
|
||||||
@@ -85,26 +97,60 @@ public class GestaoStaffActivity extends AppCompatActivity {
|
|||||||
android.R.layout.simple_spinner_dropdown_item,
|
android.R.layout.simple_spinner_dropdown_item,
|
||||||
staffNames);
|
staffNames);
|
||||||
spinnerNomeStaff.setAdapter(staffNameAdapter);
|
spinnerNomeStaff.setAdapter(staffNameAdapter);
|
||||||
|
|
||||||
loadStaffMembers();
|
loadStaffMembers();
|
||||||
|
loadMesas();
|
||||||
|
|
||||||
for (int i = 1; i <= 20; i++) {
|
spinnerMesaStaff.setAdapter(mesaSpinnerAdapter);
|
||||||
mesaAdapter.add(String.format("Mesa %02d", i));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
spinnerMesaStaff.setAdapter(mesaAdapter);
|
private void loadMesas() {
|
||||||
|
mesasRef.addValueEventListener(new ValueEventListener() {
|
||||||
|
@Override
|
||||||
|
public void onDataChange(@NonNull DataSnapshot snapshot) {
|
||||||
|
mesasDisponiveis.clear();
|
||||||
|
mesaSpinnerAdapter.clear();
|
||||||
|
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
|
||||||
|
Mesa mesa = postSnapshot.getValue(Mesa.class);
|
||||||
|
if (mesa != null) {
|
||||||
|
mesasDisponiveis.add(mesa);
|
||||||
|
mesaSpinnerAdapter.add("Mesa " + mesa.getNumero());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mesaSpinnerAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCancelled(@NonNull DatabaseError error) {
|
||||||
|
Toast.makeText(GestaoStaffActivity.this, "Erro ao carregar mesas.", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupList() {
|
private void setupList() {
|
||||||
staffAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_activated_1);
|
staffAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_activated_1);
|
||||||
listStaffMesas.setAdapter(staffAdapter);
|
listStaffMesas.setAdapter(staffAdapter);
|
||||||
refreshList();
|
|
||||||
|
|
||||||
listStaffMesas.setOnItemClickListener((parent, view, position, id) -> {
|
listStaffMesas.setOnItemClickListener((parent, view, position, id) -> {
|
||||||
StaffAssignment item = staffAssignments.get(position);
|
Staff item = staffList.get(position);
|
||||||
// inputNomeStaff.setText(item.nome); // Removed
|
// Select staff in spinner
|
||||||
int index = Math.max(0, Math.min(spinnerMesaStaff.getCount() - 1, item.mesaNumero - 1));
|
int staffIndex = staffNames.indexOf(item.getName());
|
||||||
spinnerMesaStaff.setSelection(index);
|
if (staffIndex >= 0) {
|
||||||
txtMensagemStaff.setText(String.format("A editar: %s (Mesa %02d)", item.nome, item.mesaNumero));
|
spinnerNomeStaff.setSelection(staffIndex);
|
||||||
|
}
|
||||||
|
// Select mesa in spinner
|
||||||
|
// Simple string matching for now since Mesa is stored as String in Staff
|
||||||
|
String assignedMesa = item.getMesa();
|
||||||
|
if (assignedMesa != null) {
|
||||||
|
for (int i = 0; i < mesaSpinnerAdapter.getCount(); i++) {
|
||||||
|
if (mesaSpinnerAdapter.getItem(i).equals(assignedMesa)) {
|
||||||
|
spinnerMesaStaff.setSelection(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
txtMensagemStaff.setText(String.format("A editar: %s", item.getName()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,70 +185,64 @@ public class GestaoStaffActivity extends AppCompatActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mesaNumero = spinnerMesaStaff.getSelectedItemPosition() + 1;
|
String mesaSelecionada = spinnerMesaStaff.getSelectedItem().toString();
|
||||||
|
|
||||||
StaffAssignment existente = findByNome(nome);
|
Staff staffToUpdate = findByNome(nome);
|
||||||
if (existente == null) {
|
if (staffToUpdate != null) {
|
||||||
staffAssignments.add(new StaffAssignment(nome, mesaNumero));
|
staffToUpdate.setMesa(mesaSelecionada);
|
||||||
txtMensagemStaff.setText(String.format("%s atribuído à mesa %02d.", nome, mesaNumero));
|
|
||||||
|
final String finalNome = nome;
|
||||||
|
final String finalMesa = mesaSelecionada;
|
||||||
|
|
||||||
|
staffRef.child(staffToUpdate.getId()).setValue(staffToUpdate)
|
||||||
|
.addOnSuccessListener(aVoid -> {
|
||||||
|
txtMensagemStaff.setText(String.format("%s atribuído à %s.", finalNome, finalMesa));
|
||||||
|
})
|
||||||
|
.addOnFailureListener(e -> {
|
||||||
|
Toast.makeText(this, "Erro ao atualizar: " + e.getMessage(), Toast.LENGTH_SHORT).show();
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
existente.mesaNumero = mesaNumero;
|
Toast.makeText(this, "Erro: Staff não encontrado.", Toast.LENGTH_SHORT).show();
|
||||||
txtMensagemStaff.setText(String.format("Mesa de %s atualizada para %02d.", nome, mesaNumero));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private StaffAssignment findByNome(String nome) {
|
private Staff findByNome(String nome) {
|
||||||
for (StaffAssignment item : staffAssignments) {
|
for (Staff item : staffList) {
|
||||||
if (item.nome.equalsIgnoreCase(nome)) {
|
if (item.getName().equalsIgnoreCase(nome)) {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refreshList() {
|
|
||||||
if (staffAdapter == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
staffAdapter.clear();
|
|
||||||
for (StaffAssignment item : staffAssignments) {
|
|
||||||
String resumo = String.format("%s • Mesa %02d", item.nome, item.mesaNumero);
|
|
||||||
staffAdapter.add(resumo);
|
|
||||||
}
|
|
||||||
staffAdapter.notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadStaffMembers() {
|
private void loadStaffMembers() {
|
||||||
firestore.collection("users")
|
staffRef.addValueEventListener(new ValueEventListener() {
|
||||||
.whereEqualTo("role", "STAFF")
|
@Override
|
||||||
.get()
|
public void onDataChange(@NonNull DataSnapshot snapshot) {
|
||||||
.addOnSuccessListener(queryDocumentSnapshots -> {
|
staffList.clear();
|
||||||
staffNames.clear();
|
staffNames.clear();
|
||||||
for (QueryDocumentSnapshot document : queryDocumentSnapshots) {
|
staffAdapter.clear();
|
||||||
String name = document.getString("displayName");
|
|
||||||
if (name != null && !name.isEmpty()) {
|
|
||||||
staffNames.add(name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (staffNames.isEmpty()) {
|
|
||||||
staffNames.add("Nenhum staff encontrado");
|
|
||||||
}
|
|
||||||
staffNameAdapter.notifyDataSetChanged();
|
|
||||||
})
|
|
||||||
.addOnFailureListener(e -> {
|
|
||||||
Toast.makeText(this, "Erro ao carregar staff: " + e.getMessage(), Toast.LENGTH_SHORT).show();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class StaffAssignment {
|
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
|
||||||
String nome;
|
Staff staff = postSnapshot.getValue(Staff.class);
|
||||||
int mesaNumero;
|
if (staff != null) {
|
||||||
|
staffList.add(staff);
|
||||||
|
staffNames.add(staff.getName());
|
||||||
|
|
||||||
StaffAssignment(String nome, int mesaNumero) {
|
String mesaInfo = staff.getMesa() != null ? staff.getMesa() : "Sem Mesa";
|
||||||
this.nome = nome;
|
String resumo = String.format("%s • %s • %s", staff.getName(), staff.getZona(), mesaInfo);
|
||||||
this.mesaNumero = mesaNumero;
|
staffAdapter.add(resumo);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
staffNameAdapter.notifyDataSetChanged();
|
||||||
|
staffAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCancelled(@NonNull DatabaseError error) {
|
||||||
|
Toast.makeText(GestaoStaffActivity.this, "Erro ao carregar staff.", Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -81,7 +81,6 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
setupTypeToggle();
|
setupTypeToggle();
|
||||||
setupActionToggle();
|
setupActionToggle();
|
||||||
setupPrimaryAction();
|
setupPrimaryAction();
|
||||||
enforceFirstAccountCreation();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindViews() {
|
private void bindViews() {
|
||||||
@@ -176,13 +175,6 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
String establishmentEmail = inputEstablishmentEmail.getText().toString().trim();
|
String establishmentEmail = inputEstablishmentEmail.getText().toString().trim();
|
||||||
String establishmentPhone = inputEstablishmentPhone.getText().toString().trim();
|
String establishmentPhone = inputEstablishmentPhone.getText().toString().trim();
|
||||||
|
|
||||||
if (selectedAccountAction == AccountAction.ENTRAR && !hasCreatedAccount) {
|
|
||||||
Toast.makeText(this, "Crie uma conta para começar a usar a app.", Toast.LENGTH_SHORT).show();
|
|
||||||
selectedAccountAction = AccountAction.CRIAR;
|
|
||||||
updateActionButtons();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TextUtils.isEmpty(email) || TextUtils.isEmpty(password)) {
|
if (TextUtils.isEmpty(email) || TextUtils.isEmpty(password)) {
|
||||||
Toast.makeText(this, "Preencha email e palavra-passe.", Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, "Preencha email e palavra-passe.", Toast.LENGTH_SHORT).show();
|
||||||
return;
|
return;
|
||||||
@@ -330,13 +322,10 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
establishmentPhone,
|
establishmentPhone,
|
||||||
uid,
|
uid,
|
||||||
() -> {
|
() -> {
|
||||||
Intent createdScreen = new Intent(this, AccountCreatedActivity.class);
|
Toast.makeText(this, "Conta criada com sucesso! Carregue em Entrar.", Toast.LENGTH_LONG)
|
||||||
createdScreen.putExtra(EXTRA_ACTION_MODE, selectedAccountAction.name());
|
.show();
|
||||||
createdScreen.putExtra(EXTRA_DISPLAY_NAME, finalDisplayName);
|
selectedAccountAction = AccountAction.ENTRAR;
|
||||||
createdScreen.putExtra(EXTRA_EMAIL, email);
|
updateActionButtons();
|
||||||
createdScreen.putExtra(EXTRA_ACCOUNT_TYPE, selectedAccountType.name());
|
|
||||||
createdScreen.putExtra(EXTRA_ROLE, resolvedRole);
|
|
||||||
startActivity(createdScreen);
|
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.addOnFailureListener(e -> {
|
.addOnFailureListener(e -> {
|
||||||
@@ -388,6 +377,14 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
})
|
})
|
||||||
.addOnFailureListener(e -> {
|
.addOnFailureListener(e -> {
|
||||||
android.util.Log.e("LoginError", "Firestore check failed", e);
|
android.util.Log.e("LoginError", "Firestore check failed", e);
|
||||||
|
if (e instanceof com.google.firebase.firestore.FirebaseFirestoreException) {
|
||||||
|
com.google.firebase.firestore.FirebaseFirestoreException fe = (com.google.firebase.firestore.FirebaseFirestoreException) e;
|
||||||
|
if (fe.getCode() == com.google.firebase.firestore.FirebaseFirestoreException.Code.UNAVAILABLE ||
|
||||||
|
fe.getCode() == com.google.firebase.firestore.FirebaseFirestoreException.Code.FAILED_PRECONDITION) {
|
||||||
|
Toast.makeText(this, "Sem internet. A entrar em modo offline...", Toast.LENGTH_LONG).show();
|
||||||
|
// Não fazemos return, deixamos cair no navigateToDashboard abaixo
|
||||||
|
}
|
||||||
|
}
|
||||||
Toast.makeText(this, "Falha ao validar perfil na cloud. A entrar em modo básico.",
|
Toast.makeText(this, "Falha ao validar perfil na cloud. A entrar em modo básico.",
|
||||||
Toast.LENGTH_SHORT)
|
Toast.LENGTH_SHORT)
|
||||||
.show();
|
.show();
|
||||||
@@ -482,13 +479,13 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
// @Override
|
||||||
// protected void onStart() {
|
// protected void onStart() {
|
||||||
// super.onStart();
|
// super.onStart();
|
||||||
// FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
|
// FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
|
||||||
// if (firebaseUser != null) {
|
// if (firebaseUser != null) {
|
||||||
// startActivity(new Intent(this, MainActivity.class));
|
// startActivity(new Intent(this, MainActivity.class));
|
||||||
// finish();
|
// finish();
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,56 @@
|
|||||||
package com.example.pap_teste.models;
|
package com.example.pap_teste.models;
|
||||||
|
|
||||||
public class Mesa {
|
public class Mesa {
|
||||||
|
private String id;
|
||||||
|
private int numero;
|
||||||
|
private int capacidade;
|
||||||
|
private String estado;
|
||||||
|
|
||||||
|
public Mesa() {
|
||||||
|
// Default constructor required for calls to DataSnapshot.getValue(Mesa.class)
|
||||||
|
}
|
||||||
|
|
||||||
|
public Mesa(String id, int numero, int capacidade, String estado) {
|
||||||
|
this.id = id;
|
||||||
|
this.numero = numero;
|
||||||
|
this.capacidade = capacidade;
|
||||||
|
this.estado = estado;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNumero() {
|
||||||
|
return numero;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNumero(int numero) {
|
||||||
|
this.numero = numero;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCapacidade() {
|
||||||
|
return capacidade;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCapacidade(int capacidade) {
|
||||||
|
this.capacidade = capacidade;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEstado() {
|
||||||
|
return estado;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEstado(String estado) {
|
||||||
|
this.estado = estado;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Mesa " + numero;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,14 +3,17 @@ package com.example.pap_teste.models;
|
|||||||
public class Staff {
|
public class Staff {
|
||||||
private String name;
|
private String name;
|
||||||
private String zona;
|
private String zona;
|
||||||
|
private String mesa;
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
public Staff(String name, String zona, String id) {
|
public Staff(String name, String zona, String mesa, String id) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.zona = zona;
|
this.zona = zona;
|
||||||
|
this.mesa = mesa;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Staff() {
|
public Staff() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,6 +33,14 @@ public class Staff {
|
|||||||
this.zona = zona;
|
this.zona = zona;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getMesa() {
|
||||||
|
return mesa;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMesa(String mesa) {
|
||||||
|
this.mesa = mesa;
|
||||||
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,14 +9,60 @@
|
|||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/nammeEditText"
|
android:id="@+id/nammeEditText"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginTop="32dp"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
android:ems="10"
|
android:ems="10"
|
||||||
|
android:hint="Name"
|
||||||
android:inputType="text"
|
android:inputType="text"
|
||||||
android:text="Name"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/zoneLayout"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
app:layout_constraintEnd_toEndOf="@+id/nammeEditText"
|
||||||
|
app:layout_constraintStart_toStartOf="@+id/nammeEditText"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/nammeEditText">
|
||||||
|
|
||||||
|
<Spinner
|
||||||
|
android:id="@+id/zonaSpinner"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:minHeight="48dp" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/btnAddZone"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="+" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/mesaLayout"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
app:layout_constraintEnd_toEndOf="@+id/zoneLayout"
|
||||||
|
app:layout_constraintStart_toStartOf="@+id/zoneLayout"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/zoneLayout">
|
||||||
|
|
||||||
|
<Spinner
|
||||||
|
android:id="@+id/mesaSpinner"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:minHeight="48dp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
android:id="@+id/addButton"
|
android:id="@+id/addButton"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|||||||
Reference in New Issue
Block a user