ecra principal
This commit is contained in:
3
.idea/deploymentTargetSelector.xml
generated
3
.idea/deploymentTargetSelector.xml
generated
@@ -5,6 +5,9 @@
|
||||
<SelectionState runConfigName="app">
|
||||
<option name="selectionMode" value="DROPDOWN" />
|
||||
</SelectionState>
|
||||
<SelectionState runConfigName="Pap_teste">
|
||||
<option name="selectionMode" value="DROPDOWN" />
|
||||
</SelectionState>
|
||||
</selectionStates>
|
||||
</component>
|
||||
</project>
|
||||
@@ -4,6 +4,13 @@ import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
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.appcompat.app.AppCompatActivity;
|
||||
@@ -19,7 +26,13 @@ public class AddStaffActivity extends AppCompatActivity {
|
||||
|
||||
private Button addButton;
|
||||
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
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -34,25 +47,82 @@ public class AddStaffActivity extends AppCompatActivity {
|
||||
|
||||
addButton = findViewById(R.id.addButton);
|
||||
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() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
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()) {
|
||||
DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("Staff");
|
||||
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);
|
||||
|
||||
//mensagem de sucesso
|
||||
Toast.makeText(AddStaffActivity.this, "Staff adicionado com sucesso!", Toast.LENGTH_SHORT).show();
|
||||
finish();
|
||||
}
|
||||
else{
|
||||
//colocar mensagem de error tem que estar tudo preenchido
|
||||
} else {
|
||||
Toast.makeText(AddStaffActivity.this, "Erro: Preencha todos os campos", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -15,18 +15,28 @@ import androidx.core.graphics.Insets;
|
||||
import androidx.core.view.ViewCompat;
|
||||
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.List;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public class GerirMesasActivity extends AppCompatActivity {
|
||||
|
||||
private final List<MesaItem> mesas = new ArrayList<>();
|
||||
private final List<Mesa> mesas = new ArrayList<>();
|
||||
private ArrayAdapter<String> adapter;
|
||||
private ListView listMesas;
|
||||
private EditText inputNumero;
|
||||
private EditText inputCapacidade;
|
||||
private Spinner spinnerEstado;
|
||||
private TextView txtMensagem;
|
||||
private DatabaseReference mDatabase;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -40,7 +50,9 @@ public class GerirMesasActivity extends AppCompatActivity {
|
||||
});
|
||||
|
||||
bindViews();
|
||||
seedMesasDemo();
|
||||
|
||||
mDatabase = FirebaseDatabase.getInstance().getReference("Mesas");
|
||||
|
||||
setupList();
|
||||
setupFormActions();
|
||||
}
|
||||
@@ -60,29 +72,44 @@ public class GerirMesasActivity extends AppCompatActivity {
|
||||
ArrayAdapter<String> estadoAdapter = new ArrayAdapter<>(
|
||||
this,
|
||||
android.R.layout.simple_spinner_dropdown_item,
|
||||
new String[]{"Livre", "Ocupada", "Reservada"}
|
||||
);
|
||||
new String[] { "Livre", "Ocupada", "Reservada" });
|
||||
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() {
|
||||
adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_activated_1);
|
||||
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) -> {
|
||||
MesaItem item = mesas.get(position);
|
||||
inputNumero.setText(String.valueOf(item.numero));
|
||||
inputCapacidade.setText(String.valueOf(item.capacidade));
|
||||
spinnerEstado.setSelection(getEstadoIndex(item.estado));
|
||||
txtMensagem.setText(String.format("Editar mesa %d", item.numero));
|
||||
Mesa item = mesas.get(position);
|
||||
inputNumero.setText(String.valueOf(item.getNumero()));
|
||||
inputCapacidade.setText(String.valueOf(item.getCapacidade()));
|
||||
spinnerEstado.setSelection(getEstadoIndex(item.getEstado()));
|
||||
txtMensagem.setText(String.format("Editar mesa %d", item.getNumero()));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -123,56 +150,36 @@ public class GerirMesasActivity extends AppCompatActivity {
|
||||
return;
|
||||
}
|
||||
|
||||
MesaItem existente = findMesa(numero);
|
||||
Mesa existente = findMesa(numero);
|
||||
String mesaId;
|
||||
|
||||
if (existente == null) {
|
||||
mesas.add(new MesaItem(numero, capacidade, estado));
|
||||
txtMensagem.setText(String.format("Mesa %d adicionada/atualizada.", numero));
|
||||
mesaId = mDatabase.push().getKey();
|
||||
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 {
|
||||
existente.capacidade = capacidade;
|
||||
existente.estado = estado;
|
||||
mesaId = existente.getId();
|
||||
existente.setCapacidade(capacidade);
|
||||
existente.setEstado(estado);
|
||||
mDatabase.child(mesaId).setValue(existente);
|
||||
txtMensagem.setText(String.format("Mesa %d atualizada.", numero));
|
||||
}
|
||||
|
||||
refreshList();
|
||||
// Clearing inputs
|
||||
inputNumero.setText("");
|
||||
inputCapacidade.setText("");
|
||||
}
|
||||
|
||||
private MesaItem findMesa(int numero) {
|
||||
for (MesaItem item : mesas) {
|
||||
if (item.numero == numero) {
|
||||
private Mesa findMesa(int numero) {
|
||||
for (Mesa item : mesas) {
|
||||
if (item.getNumero() == numero) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
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;
|
||||
|
||||
import com.example.pap_teste.models.Mesa;
|
||||
import com.example.pap_teste.models.Staff;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.google.firebase.firestore.FirebaseFirestore;
|
||||
import com.google.firebase.firestore.QueryDocumentSnapshot;
|
||||
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 androidx.annotation.NonNull;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
||||
import android.widget.ListView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
@@ -26,16 +32,21 @@ import java.util.List;
|
||||
|
||||
public class GestaoStaffActivity extends AppCompatActivity {
|
||||
|
||||
private final List<StaffAssignment> staffAssignments = new ArrayList<>();
|
||||
private final List<Staff> staffList = new ArrayList<>();
|
||||
private ArrayAdapter<String> staffAdapter;
|
||||
private ListView listStaffMesas;
|
||||
|
||||
private Spinner spinnerNomeStaff;
|
||||
private Spinner spinnerMesaStaff;
|
||||
private TextView txtMensagemStaff;
|
||||
private FirebaseFirestore firestore;
|
||||
|
||||
private DatabaseReference staffRef;
|
||||
private DatabaseReference mesasRef;
|
||||
|
||||
private List<String> staffNames = new ArrayList<>();
|
||||
private List<Mesa> mesasDisponiveis = new ArrayList<>();
|
||||
private ArrayAdapter<String> staffNameAdapter;
|
||||
private ArrayAdapter<String> mesaSpinnerAdapter;
|
||||
|
||||
private FloatingActionButton floatingActionButton;
|
||||
|
||||
@@ -50,7 +61,8 @@ public class GestaoStaffActivity extends AppCompatActivity {
|
||||
return insets;
|
||||
});
|
||||
|
||||
firestore = FirebaseFirestore.getInstance();
|
||||
staffRef = FirebaseDatabase.getInstance().getReference("Staff");
|
||||
mesasRef = FirebaseDatabase.getInstance().getReference("Mesas");
|
||||
|
||||
Button back = findViewById(R.id.btnVoltar);
|
||||
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".
|
||||
*/
|
||||
private void setupMesaSpinner() {
|
||||
ArrayAdapter<String> mesaAdapter = new ArrayAdapter<>(
|
||||
mesaSpinnerAdapter = new ArrayAdapter<>(
|
||||
this,
|
||||
android.R.layout.simple_spinner_dropdown_item);
|
||||
|
||||
@@ -85,26 +97,60 @@ public class GestaoStaffActivity extends AppCompatActivity {
|
||||
android.R.layout.simple_spinner_dropdown_item,
|
||||
staffNames);
|
||||
spinnerNomeStaff.setAdapter(staffNameAdapter);
|
||||
|
||||
loadStaffMembers();
|
||||
loadMesas();
|
||||
|
||||
for (int i = 1; i <= 20; i++) {
|
||||
mesaAdapter.add(String.format("Mesa %02d", i));
|
||||
}
|
||||
spinnerMesaStaff.setAdapter(mesaSpinnerAdapter);
|
||||
}
|
||||
|
||||
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() {
|
||||
staffAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_activated_1);
|
||||
listStaffMesas.setAdapter(staffAdapter);
|
||||
refreshList();
|
||||
|
||||
listStaffMesas.setOnItemClickListener((parent, view, position, id) -> {
|
||||
StaffAssignment item = staffAssignments.get(position);
|
||||
// inputNomeStaff.setText(item.nome); // Removed
|
||||
int index = Math.max(0, Math.min(spinnerMesaStaff.getCount() - 1, item.mesaNumero - 1));
|
||||
spinnerMesaStaff.setSelection(index);
|
||||
txtMensagemStaff.setText(String.format("A editar: %s (Mesa %02d)", item.nome, item.mesaNumero));
|
||||
Staff item = staffList.get(position);
|
||||
// Select staff in spinner
|
||||
int staffIndex = staffNames.indexOf(item.getName());
|
||||
if (staffIndex >= 0) {
|
||||
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;
|
||||
}
|
||||
|
||||
int mesaNumero = spinnerMesaStaff.getSelectedItemPosition() + 1;
|
||||
String mesaSelecionada = spinnerMesaStaff.getSelectedItem().toString();
|
||||
|
||||
StaffAssignment existente = findByNome(nome);
|
||||
if (existente == null) {
|
||||
staffAssignments.add(new StaffAssignment(nome, mesaNumero));
|
||||
txtMensagemStaff.setText(String.format("%s atribuído à mesa %02d.", nome, mesaNumero));
|
||||
Staff staffToUpdate = findByNome(nome);
|
||||
if (staffToUpdate != null) {
|
||||
staffToUpdate.setMesa(mesaSelecionada);
|
||||
|
||||
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 {
|
||||
existente.mesaNumero = mesaNumero;
|
||||
txtMensagemStaff.setText(String.format("Mesa de %s atualizada para %02d.", nome, mesaNumero));
|
||||
Toast.makeText(this, "Erro: Staff não encontrado.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
refreshList();
|
||||
}
|
||||
|
||||
private StaffAssignment findByNome(String nome) {
|
||||
for (StaffAssignment item : staffAssignments) {
|
||||
if (item.nome.equalsIgnoreCase(nome)) {
|
||||
private Staff findByNome(String nome) {
|
||||
for (Staff item : staffList) {
|
||||
if (item.getName().equalsIgnoreCase(nome)) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
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() {
|
||||
firestore.collection("users")
|
||||
.whereEqualTo("role", "STAFF")
|
||||
.get()
|
||||
.addOnSuccessListener(queryDocumentSnapshots -> {
|
||||
staffNames.clear();
|
||||
for (QueryDocumentSnapshot document : queryDocumentSnapshots) {
|
||||
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();
|
||||
});
|
||||
}
|
||||
staffRef.addValueEventListener(new ValueEventListener() {
|
||||
@Override
|
||||
public void onDataChange(@NonNull DataSnapshot snapshot) {
|
||||
staffList.clear();
|
||||
staffNames.clear();
|
||||
staffAdapter.clear();
|
||||
|
||||
private static class StaffAssignment {
|
||||
String nome;
|
||||
int mesaNumero;
|
||||
for (DataSnapshot postSnapshot : snapshot.getChildren()) {
|
||||
Staff staff = postSnapshot.getValue(Staff.class);
|
||||
if (staff != null) {
|
||||
staffList.add(staff);
|
||||
staffNames.add(staff.getName());
|
||||
|
||||
StaffAssignment(String nome, int mesaNumero) {
|
||||
this.nome = nome;
|
||||
this.mesaNumero = mesaNumero;
|
||||
}
|
||||
String mesaInfo = staff.getMesa() != null ? staff.getMesa() : "Sem Mesa";
|
||||
String resumo = String.format("%s • %s • %s", staff.getName(), staff.getZona(), mesaInfo);
|
||||
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();
|
||||
setupActionToggle();
|
||||
setupPrimaryAction();
|
||||
enforceFirstAccountCreation();
|
||||
}
|
||||
|
||||
private void bindViews() {
|
||||
@@ -176,13 +175,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
String establishmentEmail = inputEstablishmentEmail.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)) {
|
||||
Toast.makeText(this, "Preencha email e palavra-passe.", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
@@ -330,13 +322,10 @@ public class MainActivity extends AppCompatActivity {
|
||||
establishmentPhone,
|
||||
uid,
|
||||
() -> {
|
||||
Intent createdScreen = new Intent(this, AccountCreatedActivity.class);
|
||||
createdScreen.putExtra(EXTRA_ACTION_MODE, selectedAccountAction.name());
|
||||
createdScreen.putExtra(EXTRA_DISPLAY_NAME, finalDisplayName);
|
||||
createdScreen.putExtra(EXTRA_EMAIL, email);
|
||||
createdScreen.putExtra(EXTRA_ACCOUNT_TYPE, selectedAccountType.name());
|
||||
createdScreen.putExtra(EXTRA_ROLE, resolvedRole);
|
||||
startActivity(createdScreen);
|
||||
Toast.makeText(this, "Conta criada com sucesso! Carregue em Entrar.", Toast.LENGTH_LONG)
|
||||
.show();
|
||||
selectedAccountAction = AccountAction.ENTRAR;
|
||||
updateActionButtons();
|
||||
});
|
||||
})
|
||||
.addOnFailureListener(e -> {
|
||||
@@ -388,6 +377,14 @@ public class MainActivity extends AppCompatActivity {
|
||||
})
|
||||
.addOnFailureListener(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.LENGTH_SHORT)
|
||||
.show();
|
||||
@@ -482,13 +479,13 @@ public class MainActivity extends AppCompatActivity {
|
||||
return true;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// protected void onStart() {
|
||||
// super.onStart();
|
||||
// FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
|
||||
// if (firebaseUser != null) {
|
||||
// startActivity(new Intent(this, MainActivity.class));
|
||||
// finish();
|
||||
// }
|
||||
// }
|
||||
// @Override
|
||||
// protected void onStart() {
|
||||
// super.onStart();
|
||||
// FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
|
||||
// if (firebaseUser != null) {
|
||||
// startActivity(new Intent(this, MainActivity.class));
|
||||
// finish();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
@@ -1,4 +1,56 @@
|
||||
package com.example.pap_teste.models;
|
||||
|
||||
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 {
|
||||
private String name;
|
||||
private String zona;
|
||||
private String mesa;
|
||||
|
||||
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.zona = zona;
|
||||
this.mesa = mesa;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Staff() {
|
||||
}
|
||||
|
||||
@@ -30,6 +33,14 @@ public class Staff {
|
||||
this.zona = zona;
|
||||
}
|
||||
|
||||
public String getMesa() {
|
||||
return mesa;
|
||||
}
|
||||
|
||||
public void setMesa(String mesa) {
|
||||
this.mesa = mesa;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -9,14 +9,60 @@
|
||||
|
||||
<EditText
|
||||
android:id="@+id/nammeEditText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="32dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:ems="10"
|
||||
android:hint="Name"
|
||||
android:inputType="text"
|
||||
android:text="Name"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="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
|
||||
android:id="@+id/addButton"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
Reference in New Issue
Block a user