ecra principal

This commit is contained in:
2026-01-29 10:40:21 +00:00
parent 906849e4b7
commit 1c68112436
11 changed files with 234 additions and 19 deletions

View File

@@ -41,6 +41,7 @@ dependencies {
implementation(platform(libs.firebase.bom)) implementation(platform(libs.firebase.bom))
implementation("com.google.firebase:firebase-firestore") implementation("com.google.firebase:firebase-firestore")
implementation("com.google.firebase:firebase-auth") implementation("com.google.firebase:firebase-auth")
implementation(libs.firebase.database)
testImplementation(libs.junit) testImplementation(libs.junit)
androidTestImplementation(libs.ext.junit) androidTestImplementation(libs.ext.junit)
androidTestImplementation(libs.espresso.core) androidTestImplementation(libs.espresso.core)

View File

@@ -13,6 +13,9 @@
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.Pap_teste"> android:theme="@style/Theme.Pap_teste">
<activity
android:name=".AddStaffActivity"
android:exported="false" />
<activity <activity
android:name=".DetalhesReservasActivity" android:name=".DetalhesReservasActivity"
android:exported="false" android:exported="false"

View File

@@ -0,0 +1,60 @@
package com.example.pap_teste;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
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 com.example.pap_teste.models.Staff;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
public class AddStaffActivity extends AppCompatActivity {
private Button addButton;
private EditText nameEditText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_add_staff);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
addButton = findViewById(R.id.addButton);
nameEditText = findViewById(R.id.nammeEditText);
addButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String name = nameEditText.getText().toString();
//String zona = zonaSpinner.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);
databaseReference.child(uuid).setValue(staff);
//mensagem de sucesso
finish();
}
else{
//colocar mensagem de error tem que estar tudo preenchido
}
}
});
}
}

View File

@@ -1,6 +1,12 @@
package com.example.pap_teste; package com.example.pap_teste;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.QueryDocumentSnapshot;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
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.EditText;
@@ -23,9 +29,15 @@ public class GestaoStaffActivity extends AppCompatActivity {
private final List<StaffAssignment> staffAssignments = new ArrayList<>(); private final List<StaffAssignment> staffAssignments = new ArrayList<>();
private ArrayAdapter<String> staffAdapter; private ArrayAdapter<String> staffAdapter;
private ListView listStaffMesas; private ListView listStaffMesas;
private EditText inputNomeStaff;
private Spinner spinnerNomeStaff;
private Spinner spinnerMesaStaff; private Spinner spinnerMesaStaff;
private TextView txtMensagemStaff; private TextView txtMensagemStaff;
private FirebaseFirestore firestore;
private List<String> staffNames = new ArrayList<>();
private ArrayAdapter<String> staffNameAdapter;
private FloatingActionButton floatingActionButton;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@@ -38,6 +50,8 @@ public class GestaoStaffActivity extends AppCompatActivity {
return insets; return insets;
}); });
firestore = FirebaseFirestore.getInstance();
Button back = findViewById(R.id.btnVoltar); Button back = findViewById(R.id.btnVoltar);
if (back != null) { if (back != null) {
back.setOnClickListener(v -> finish()); back.setOnClickListener(v -> finish());
@@ -51,9 +65,10 @@ public class GestaoStaffActivity extends AppCompatActivity {
private void bindViews() { private void bindViews() {
listStaffMesas = findViewById(R.id.listStaffMesas); listStaffMesas = findViewById(R.id.listStaffMesas);
inputNomeStaff = findViewById(R.id.inputNomeStaff); spinnerNomeStaff = findViewById(R.id.spinnerNomeStaff);
spinnerMesaStaff = findViewById(R.id.spinnerMesaStaff); spinnerMesaStaff = findViewById(R.id.spinnerMesaStaff);
txtMensagemStaff = findViewById(R.id.txtMensagemStaff); txtMensagemStaff = findViewById(R.id.txtMensagemStaff);
floatingActionButton = findViewById(R.id.floatingActionButton);
} }
/** /**
@@ -63,8 +78,14 @@ public class GestaoStaffActivity extends AppCompatActivity {
private void setupMesaSpinner() { private void setupMesaSpinner() {
ArrayAdapter<String> mesaAdapter = new ArrayAdapter<>( ArrayAdapter<String> mesaAdapter = new ArrayAdapter<>(
this, this,
android.R.layout.simple_spinner_dropdown_item android.R.layout.simple_spinner_dropdown_item);
);
staffNameAdapter = new ArrayAdapter<>(
this,
android.R.layout.simple_spinner_dropdown_item,
staffNames);
spinnerNomeStaff.setAdapter(staffNameAdapter);
loadStaffMembers();
for (int i = 1; i <= 20; i++) { for (int i = 1; i <= 20; i++) {
mesaAdapter.add(String.format("Mesa %02d", i)); mesaAdapter.add(String.format("Mesa %02d", i));
@@ -80,7 +101,7 @@ public class GestaoStaffActivity extends AppCompatActivity {
listStaffMesas.setOnItemClickListener((parent, view, position, id) -> { listStaffMesas.setOnItemClickListener((parent, view, position, id) -> {
StaffAssignment item = staffAssignments.get(position); StaffAssignment item = staffAssignments.get(position);
inputNomeStaff.setText(item.nome); // inputNomeStaff.setText(item.nome); // Removed
int index = Math.max(0, Math.min(spinnerMesaStaff.getCount() - 1, item.mesaNumero - 1)); int index = Math.max(0, Math.min(spinnerMesaStaff.getCount() - 1, item.mesaNumero - 1));
spinnerMesaStaff.setSelection(index); spinnerMesaStaff.setSelection(index);
txtMensagemStaff.setText(String.format("A editar: %s (Mesa %02d)", item.nome, item.mesaNumero)); txtMensagemStaff.setText(String.format("A editar: %s (Mesa %02d)", item.nome, item.mesaNumero));
@@ -92,12 +113,24 @@ public class GestaoStaffActivity extends AppCompatActivity {
if (btnAtribuir != null) { if (btnAtribuir != null) {
btnAtribuir.setOnClickListener(v -> guardarAtribuicao()); btnAtribuir.setOnClickListener(v -> guardarAtribuicao());
} }
floatingActionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(GestaoStaffActivity.this, AddStaffActivity.class);
startActivity(intent);
}
});
} }
private void guardarAtribuicao() { private void guardarAtribuicao() {
String nome = inputNomeStaff != null ? inputNomeStaff.getText().toString().trim() : ""; String nome = "";
if (spinnerNomeStaff.getSelectedItem() != null) {
nome = spinnerNomeStaff.getSelectedItem().toString();
}
if (nome.isEmpty()) { if (nome.isEmpty()) {
Toast.makeText(this, "Indique o nome do funcionário.", Toast.LENGTH_SHORT).show(); Toast.makeText(this, "Selecione um funcionário.", Toast.LENGTH_SHORT).show();
return; return;
} }
@@ -130,7 +163,8 @@ public class GestaoStaffActivity extends AppCompatActivity {
} }
private void refreshList() { private void refreshList() {
if (staffAdapter == null) return; if (staffAdapter == null)
return;
staffAdapter.clear(); staffAdapter.clear();
for (StaffAssignment item : staffAssignments) { for (StaffAssignment item : staffAssignments) {
@@ -140,6 +174,28 @@ public class GestaoStaffActivity extends AppCompatActivity {
staffAdapter.notifyDataSetChanged(); 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();
});
}
private static class StaffAssignment { private static class StaffAssignment {
String nome; String nome;
int mesaNumero; int mesaNumero;
@@ -150,8 +206,3 @@ public class GestaoStaffActivity extends AppCompatActivity {
} }
} }
} }

View File

@@ -18,6 +18,7 @@ import androidx.core.view.WindowInsetsCompat;
import com.google.firebase.FirebaseApp; import com.google.firebase.FirebaseApp;
import com.google.firebase.auth.FirebaseAuth; import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.firestore.FirebaseFirestore; import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.firestore.SetOptions; import com.google.firebase.firestore.SetOptions;
@@ -480,4 +481,14 @@ public class MainActivity extends AppCompatActivity {
} }
return true; return true;
} }
// @Override
// protected void onStart() {
// super.onStart();
// FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
// if (firebaseUser != null) {
// startActivity(new Intent(this, MainActivity.class));
// finish();
// }
// }
} }

View File

@@ -0,0 +1,4 @@
package com.example.pap_teste.models;
public class Client {
}

View File

@@ -0,0 +1,4 @@
package com.example.pap_teste.models;
public class Mesa {
}

View File

@@ -0,0 +1,40 @@
package com.example.pap_teste.models;
public class Staff {
private String name;
private String zona;
private String id;
public Staff(String name, String zona, String id) {
this.name = name;
this.zona = zona;
this.id = id;
}
public Staff() {
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getZona() {
return zona;
}
public void setZona(String zona) {
this.zona = zona;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".AddStaffActivity">
<EditText
android:id="@+id/nammeEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:text="Name"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/addButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -67,15 +67,13 @@
android:textSize="16sp" android:textSize="16sp"
android:textStyle="bold" /> android:textStyle="bold" />
<EditText <Spinner
android:id="@+id/inputNomeStaff" android:id="@+id/spinnerNomeStaff"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="48dp" android:layout_height="48dp"
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:background="@drawable/input_bg" android:background="@drawable/input_bg"
android:hint="Nome do funcionário" android:padding="0dp" />
android:inputType="textPersonName"
android:padding="12dp" />
<Spinner <Spinner
android:id="@+id/spinnerMesaStaff" android:id="@+id/spinnerMesaStaff"
@@ -130,7 +128,21 @@
app:layout_constraintTop_toBottomOf="@id/txtListaStaffTitulo" app:layout_constraintTop_toBottomOf="@id/txtListaStaffTitulo"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" /> app:layout_constraintEnd_toEndOf="parent" >
</ListView>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/floatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="32dp"
android:layout_marginBottom="32dp"
android:clickable="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:srcCompat="@tools:sample/avatars" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -10,6 +10,7 @@ activity = "1.11.0"
constraintlayout = "2.2.1" constraintlayout = "2.2.1"
firebaseBom = "33.7.0" firebaseBom = "33.7.0"
googleServices = "4.4.2" googleServices = "4.4.2"
firebaseDatabase = "22.0.1"
[libraries] [libraries]
junit = { group = "junit", name = "junit", version.ref = "junit" } junit = { group = "junit", name = "junit", version.ref = "junit" }
@@ -21,6 +22,7 @@ material = { group = "com.google.android.material", name = "material", version.r
activity = { group = "androidx.activity", name = "activity", version.ref = "activity" } activity = { group = "androidx.activity", name = "activity", version.ref = "activity" }
constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" } constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
firebase-bom = { group = "com.google.firebase", name = "firebase-bom", version.ref = "firebaseBom" } firebase-bom = { group = "com.google.firebase", name = "firebase-bom", version.ref = "firebaseBom" }
firebase-database = { group = "com.google.firebase", name = "firebase-database", version.ref = "firebaseDatabase" }
[plugins] [plugins]
android-application = { id = "com.android.application", version.ref = "agp" } android-application = { id = "com.android.application", version.ref = "agp" }