...
This commit is contained in:
@@ -105,6 +105,14 @@ public class ClientDashboardActivity extends AppCompatActivity {
|
||||
|
||||
rvFeatured.setAdapter(featuredAdapter);
|
||||
rvMainRestaurants.setAdapter(mainAdapter);
|
||||
|
||||
// Click listener for profile picture in the header
|
||||
findViewById(R.id.cardProfile).setOnClickListener(v -> {
|
||||
Intent intent = new Intent(this, ProfileDashboardActivity.class);
|
||||
intent.putExtra(MainActivity.EXTRA_EMAIL, email);
|
||||
intent.putExtra(MainActivity.EXTRA_DISPLAY_NAME, displayName);
|
||||
startActivity(intent);
|
||||
});
|
||||
}
|
||||
|
||||
private void setupBottomNavigation() {
|
||||
|
||||
@@ -101,14 +101,19 @@ public class NovaReservaActivity extends AppCompatActivity {
|
||||
|
||||
private void setupRestaurants() {
|
||||
java.util.List<com.example.pap_teste.models.Restaurant> filteredList = new java.util.ArrayList<>();
|
||||
com.google.firebase.database.DatabaseReference usersRef = com.google.firebase.database.FirebaseDatabase.getInstance().getReference("users");
|
||||
com.google.firebase.database.DatabaseReference usersRef = com.google.firebase.database.FirebaseDatabase
|
||||
.getInstance().getReference("users");
|
||||
|
||||
if (progressBar != null) progressBar.setVisibility(android.view.View.VISIBLE);
|
||||
if (progressBar != null)
|
||||
progressBar.setVisibility(android.view.View.VISIBLE);
|
||||
|
||||
usersRef.orderByChild("category").equalTo(selectedCategory).addListenerForSingleValueEvent(new com.google.firebase.database.ValueEventListener() {
|
||||
usersRef.orderByChild("category").equalTo(selectedCategory)
|
||||
.addListenerForSingleValueEvent(new com.google.firebase.database.ValueEventListener() {
|
||||
@Override
|
||||
public void onDataChange(@androidx.annotation.NonNull com.google.firebase.database.DataSnapshot snapshot) {
|
||||
if (progressBar != null) progressBar.setVisibility(android.view.View.GONE);
|
||||
public void onDataChange(
|
||||
@androidx.annotation.NonNull com.google.firebase.database.DataSnapshot snapshot) {
|
||||
if (progressBar != null)
|
||||
progressBar.setVisibility(android.view.View.GONE);
|
||||
filteredList.clear();
|
||||
for (com.google.firebase.database.DataSnapshot ds : snapshot.getChildren()) {
|
||||
String role = ds.child("role").getValue(String.class);
|
||||
@@ -116,18 +121,21 @@ public class NovaReservaActivity extends AppCompatActivity {
|
||||
|
||||
if ("ADMIN".equalsIgnoreCase(role) || "ESTABELECIMENTO".equalsIgnoreCase(accountType)) {
|
||||
String name = ds.child("establishmentName").getValue(String.class);
|
||||
if (name == null) name = ds.child("displayName").getValue(String.class);
|
||||
if (name == null)
|
||||
name = ds.child("displayName").getValue(String.class);
|
||||
String email = ds.child("email").getValue(String.class);
|
||||
String cat = ds.child("category").getValue(String.class);
|
||||
String logoUrl = ds.child("logoUrl").getValue(String.class);
|
||||
|
||||
if (name != null && email != null) {
|
||||
filteredList.add(new com.example.pap_teste.models.Restaurant(name, cat, email, false, logoUrl));
|
||||
filteredList.add(new com.example.pap_teste.models.Restaurant(name, cat, email,
|
||||
false, logoUrl));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rvRestaurants.setLayoutManager(new androidx.recyclerview.widget.LinearLayoutManager(NovaReservaActivity.this));
|
||||
rvRestaurants.setLayoutManager(
|
||||
new androidx.recyclerview.widget.LinearLayoutManager(NovaReservaActivity.this));
|
||||
rvRestaurants.setAdapter(new RestaurantAdapter(filteredList, restaurant -> {
|
||||
selectedRestaurant = restaurant;
|
||||
currentState = State.DETAILS;
|
||||
@@ -136,9 +144,12 @@ public class NovaReservaActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancelled(@androidx.annotation.NonNull com.google.firebase.database.DatabaseError error) {
|
||||
if (progressBar != null) progressBar.setVisibility(android.view.View.GONE);
|
||||
android.widget.Toast.makeText(NovaReservaActivity.this, "Erro ao carregar restaurantes.", android.widget.Toast.LENGTH_SHORT).show();
|
||||
public void onCancelled(
|
||||
@androidx.annotation.NonNull com.google.firebase.database.DatabaseError error) {
|
||||
if (progressBar != null)
|
||||
progressBar.setVisibility(android.view.View.GONE);
|
||||
android.widget.Toast.makeText(NovaReservaActivity.this, "Erro ao carregar restaurantes.",
|
||||
android.widget.Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -155,7 +166,8 @@ public class NovaReservaActivity extends AppCompatActivity {
|
||||
new android.app.DatePickerDialog(this, (view, year, month, dayOfMonth) -> {
|
||||
selectedDate = dayOfMonth + "/" + (month + 1) + "/" + year;
|
||||
btnDate.setText(selectedDate);
|
||||
}, cal.get(java.util.Calendar.YEAR), cal.get(java.util.Calendar.MONTH), cal.get(java.util.Calendar.DAY_OF_MONTH)).show();
|
||||
}, cal.get(java.util.Calendar.YEAR), cal.get(java.util.Calendar.MONTH),
|
||||
cal.get(java.util.Calendar.DAY_OF_MONTH)).show();
|
||||
});
|
||||
|
||||
btnTime.setOnClickListener(v -> {
|
||||
@@ -174,7 +186,8 @@ public class NovaReservaActivity extends AppCompatActivity {
|
||||
int val = 0;
|
||||
try {
|
||||
val = Integer.parseInt(etPartySize.getText().toString());
|
||||
} catch (Exception e) {}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
final int partySize = val;
|
||||
|
||||
if (selectedDate == null || selectedTime == null || partySize == 0) {
|
||||
@@ -185,11 +198,14 @@ public class NovaReservaActivity extends AppCompatActivity {
|
||||
|
||||
String restEmail = selectedRestaurant.getEmail();
|
||||
|
||||
if (progressBar != null) progressBar.setVisibility(android.view.View.VISIBLE);
|
||||
if (progressBar != null)
|
||||
progressBar.setVisibility(android.view.View.VISIBLE);
|
||||
android.widget.Button btnConfirmar = findViewById(R.id.btnConfirmarReserva);
|
||||
if (btnConfirmar != null) btnConfirmar.setEnabled(false);
|
||||
if (btnConfirmar != null)
|
||||
btnConfirmar.setEnabled(false);
|
||||
|
||||
com.google.firebase.database.DatabaseReference mesasRef = com.google.firebase.database.FirebaseDatabase.getInstance().getReference("Mesas");
|
||||
com.google.firebase.database.DatabaseReference mesasRef = com.google.firebase.database.FirebaseDatabase
|
||||
.getInstance().getReference("Mesas");
|
||||
|
||||
mesasRef.addListenerForSingleValueEvent(new com.google.firebase.database.ValueEventListener() {
|
||||
@Override
|
||||
@@ -219,17 +235,22 @@ public class NovaReservaActivity extends AppCompatActivity {
|
||||
|
||||
private void checkReservationsAndSave(int totalMesas, final int partySize) {
|
||||
String restEmail = selectedRestaurant.getEmail();
|
||||
com.google.firebase.database.DatabaseReference reservasRef = com.google.firebase.database.FirebaseDatabase.getInstance().getReference("reservas");
|
||||
com.google.firebase.database.DatabaseReference reservasRef = com.google.firebase.database.FirebaseDatabase
|
||||
.getInstance().getReference("reservas");
|
||||
|
||||
reservasRef.orderByChild("restauranteEmail").equalTo(restEmail).addListenerForSingleValueEvent(new com.google.firebase.database.ValueEventListener() {
|
||||
reservasRef.orderByChild("restauranteEmail").equalTo(restEmail)
|
||||
.addListenerForSingleValueEvent(new com.google.firebase.database.ValueEventListener() {
|
||||
@Override
|
||||
public void onDataChange(@androidx.annotation.NonNull com.google.firebase.database.DataSnapshot snapshot) {
|
||||
public void onDataChange(
|
||||
@androidx.annotation.NonNull com.google.firebase.database.DataSnapshot snapshot) {
|
||||
int ocupadas = 0;
|
||||
java.util.Map<String, Integer> ocupacaoPorHora = new java.util.HashMap<>();
|
||||
|
||||
for (com.google.firebase.database.DataSnapshot ds : snapshot.getChildren()) {
|
||||
com.example.pap_teste.models.Reserva r = ds.getValue(com.example.pap_teste.models.Reserva.class);
|
||||
if (r != null && selectedDate.equals(r.getData()) && !"Cancelada".equals(r.getEstado()) && !"Recusada".equals(r.getEstado())) {
|
||||
com.example.pap_teste.models.Reserva r = ds
|
||||
.getValue(com.example.pap_teste.models.Reserva.class);
|
||||
if (r != null && selectedDate.equals(r.getData()) && !"Cancelada".equals(r.getEstado())
|
||||
&& !"Recusada".equals(r.getEstado())) {
|
||||
int count = ocupacaoPorHora.getOrDefault(r.getHora(), 0) + 1;
|
||||
ocupacaoPorHora.put(r.getHora(), count);
|
||||
if (selectedTime.equals(r.getHora())) {
|
||||
@@ -240,7 +261,8 @@ public class NovaReservaActivity extends AppCompatActivity {
|
||||
|
||||
if (ocupadas >= totalMesas) {
|
||||
String sugestao = "";
|
||||
String[] horasComuns = {"12:00", "12:30", "13:00", "13:30", "14:00", "19:00", "19:30", "20:00", "20:30", "21:00", "21:30", "22:00"};
|
||||
String[] horasComuns = { "12:00", "12:30", "13:00", "13:30", "14:00", "19:00", "19:30",
|
||||
"20:00", "20:30", "21:00", "21:30", "22:00" };
|
||||
for (String h : horasComuns) {
|
||||
if (ocupacaoPorHora.getOrDefault(h, 0) < totalMesas && !h.equals(selectedTime)) {
|
||||
sugestao = h;
|
||||
@@ -253,14 +275,16 @@ public class NovaReservaActivity extends AppCompatActivity {
|
||||
} else {
|
||||
msg += " Tente para outro dia.";
|
||||
}
|
||||
android.widget.Toast.makeText(NovaReservaActivity.this, msg, android.widget.Toast.LENGTH_LONG).show();
|
||||
android.widget.Toast
|
||||
.makeText(NovaReservaActivity.this, msg, android.widget.Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
proceedWithReservation(partySize);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancelled(@androidx.annotation.NonNull com.google.firebase.database.DatabaseError error) {
|
||||
public void onCancelled(
|
||||
@androidx.annotation.NonNull com.google.firebase.database.DatabaseError error) {
|
||||
proceedWithReservation(partySize);
|
||||
}
|
||||
});
|
||||
@@ -286,17 +310,22 @@ public class NovaReservaActivity extends AppCompatActivity {
|
||||
|
||||
if (id != null) {
|
||||
ref.child(id).setValue(reserva).addOnCompleteListener(task -> {
|
||||
if (progressBar != null) progressBar.setVisibility(android.view.View.GONE);
|
||||
if (progressBar != null)
|
||||
progressBar.setVisibility(android.view.View.GONE);
|
||||
android.widget.Button btnConfirmar = findViewById(R.id.btnConfirmarReserva);
|
||||
if (btnConfirmar != null) btnConfirmar.setEnabled(true);
|
||||
if (btnConfirmar != null)
|
||||
btnConfirmar.setEnabled(true);
|
||||
|
||||
if (task.isSuccessful()) {
|
||||
android.widget.Toast
|
||||
.makeText(NovaReservaActivity.this, "Reserva solicitada com sucesso!", android.widget.Toast.LENGTH_SHORT)
|
||||
.makeText(NovaReservaActivity.this, "Reserva solicitada com sucesso!",
|
||||
android.widget.Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
finish();
|
||||
} else {
|
||||
android.widget.Toast.makeText(NovaReservaActivity.this, "Erro ao salvar reserva.", android.widget.Toast.LENGTH_SHORT)
|
||||
android.widget.Toast
|
||||
.makeText(NovaReservaActivity.this, "Erro ao salvar reserva.",
|
||||
android.widget.Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.google.firebase.storage.StorageReference;
|
||||
import java.util.UUID;
|
||||
import com.google.firebase.database.DatabaseReference;
|
||||
import com.google.firebase.database.FirebaseDatabase;
|
||||
import com.google.firebase.auth.FirebaseAuth;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -99,10 +100,13 @@ public class ProfileDashboardActivity extends AppCompatActivity {
|
||||
Button btnBack = findViewById(R.id.btnVoltar);
|
||||
Button btnFavs = findViewById(R.id.btnFavoritos);
|
||||
Button btnRes = findViewById(R.id.btnMinhasReservas);
|
||||
Button btnLogOut = findViewById(R.id.btnLogOut);
|
||||
|
||||
btnBack.setOnClickListener(v -> finish());
|
||||
btnSave.setOnClickListener(v -> saveProfile());
|
||||
|
||||
btnLogOut.setOnClickListener(v -> performLogOut());
|
||||
|
||||
btnFavs.setOnClickListener(v -> {
|
||||
startActivity(new Intent(this, FavoritosActivity.class));
|
||||
});
|
||||
@@ -112,6 +116,21 @@ public class ProfileDashboardActivity extends AppCompatActivity {
|
||||
});
|
||||
}
|
||||
|
||||
private void performLogOut() {
|
||||
try {
|
||||
FirebaseAuth.getInstance().signOut();
|
||||
Toast.makeText(this, "Sessão terminada com sucesso.", Toast.LENGTH_SHORT).show();
|
||||
|
||||
Intent intent = new Intent(this, MainActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(this, "Erro ao terminar sessão: " + e.getMessage(), Toast.LENGTH_LONG).show();
|
||||
android.util.Log.e("LogOut", "Error during sign out", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void showUrlInputDialog() {
|
||||
androidx.appcompat.app.AlertDialog.Builder builder = new androidx.appcompat.app.AlertDialog.Builder(this);
|
||||
builder.setTitle("Inserir URL da Imagem");
|
||||
|
||||
@@ -186,6 +186,20 @@
|
||||
app:cornerRadius="14dp"
|
||||
android:text="Histórico de Reservas"
|
||||
android:textAllCaps="false"
|
||||
android:textSize="16sp"
|
||||
android:layout_marginBottom="32dp" />
|
||||
|
||||
<!-- Botão de Log Out -->
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/btnLogOut"
|
||||
style="@style/Widget.Material3.Button.OutlinedButton"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="56dp"
|
||||
app:cornerRadius="14dp"
|
||||
app:strokeColor="#E53935"
|
||||
android:text="Terminar Sessão"
|
||||
android:textAllCaps="false"
|
||||
android:textColor="#E53935"
|
||||
android:textSize="16sp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
Reference in New Issue
Block a user