ecra principal
This commit is contained in:
@@ -8,6 +8,8 @@ import androidx.core.graphics.Insets;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
|
||||
import android.widget.Button;
|
||||
|
||||
public class BloqueioHorarioActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
@@ -20,7 +22,15 @@ public class BloqueioHorarioActivity extends AppCompatActivity {
|
||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||
return insets;
|
||||
});
|
||||
|
||||
Button back = findViewById(R.id.btnVoltar);
|
||||
if (back != null) {
|
||||
back.setOnClickListener(v -> finish());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ import androidx.core.graphics.Insets;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
|
||||
import android.widget.Button;
|
||||
|
||||
public class CheckInAntecipadoActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
@@ -20,7 +22,15 @@ public class CheckInAntecipadoActivity extends AppCompatActivity {
|
||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||
return insets;
|
||||
});
|
||||
|
||||
Button back = findViewById(R.id.btnVoltar);
|
||||
if (back != null) {
|
||||
back.setOnClickListener(v -> finish());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -26,14 +26,18 @@ public class ClientDashboardActivity extends AppCompatActivity {
|
||||
|
||||
TextView txtGreeting = findViewById(R.id.txtClientGreeting);
|
||||
TextView txtStatus = findViewById(R.id.txtClientStatus);
|
||||
TextView txtRole = findViewById(R.id.txtClientRole);
|
||||
TextView txtReservationStatus = findViewById(R.id.txtReservationStatus);
|
||||
TextView txtReservationSubtitle = findViewById(R.id.txtReservationSubtitle);
|
||||
Button btnBack = findViewById(R.id.btnVoltar);
|
||||
|
||||
String actionMode = getIntent().getStringExtra(MainActivity.EXTRA_ACTION_MODE);
|
||||
String displayName = getIntent().getStringExtra(MainActivity.EXTRA_DISPLAY_NAME);
|
||||
String role = getIntent().getStringExtra(MainActivity.EXTRA_ROLE);
|
||||
|
||||
boolean isNewAccount = "CRIAR".equalsIgnoreCase(actionMode);
|
||||
txtGreeting.setText(String.format("Olá, %s", displayName != null ? displayName : "convidado"));
|
||||
txtRole.setText(String.format("Função: %s", role != null ? role : "CLIENTE"));
|
||||
txtStatus.setText(isNewAccount
|
||||
? "Conta criada com sucesso! Configure as suas preferências para começarmos."
|
||||
: "Bom tê-lo de volta! Já deixámos tudo pronto para a sua próxima reserva.");
|
||||
@@ -67,6 +71,10 @@ public class ClientDashboardActivity extends AppCompatActivity {
|
||||
btnShare.setOnClickListener(v ->
|
||||
startActivity(new Intent(this, PartilharReservaActivity.class))
|
||||
);
|
||||
|
||||
if (btnBack != null) {
|
||||
btnBack.setOnClickListener(v -> finish());
|
||||
}
|
||||
}
|
||||
|
||||
// Mantemos este método caso seja útil no futuro para feedback rápido.
|
||||
|
||||
@@ -26,12 +26,15 @@ public class EstablishmentDashboardActivity extends AppCompatActivity {
|
||||
|
||||
TextView txtTitle = findViewById(R.id.txtEstabTitle);
|
||||
TextView txtSubtitle = findViewById(R.id.txtEstabSubtitle);
|
||||
TextView txtRole = findViewById(R.id.txtEstabRole);
|
||||
|
||||
String actionMode = getIntent().getStringExtra(MainActivity.EXTRA_ACTION_MODE);
|
||||
String displayName = getIntent().getStringExtra(MainActivity.EXTRA_DISPLAY_NAME);
|
||||
String role = getIntent().getStringExtra(MainActivity.EXTRA_ROLE);
|
||||
|
||||
boolean isNewAccount = "CRIAR".equalsIgnoreCase(actionMode);
|
||||
txtTitle.setText(displayName != null ? displayName : "Estabelecimento");
|
||||
txtRole.setText(String.format("Função: %s", role != null ? role : "ADMIN"));
|
||||
txtSubtitle.setText(isNewAccount
|
||||
? "Perfil criado. Configure horários, mesas e abra reservas."
|
||||
: "Dashboard operacional. Acompanhe as reservas em tempo real.");
|
||||
@@ -40,6 +43,9 @@ public class EstablishmentDashboardActivity extends AppCompatActivity {
|
||||
Button btnBlockTime = findViewById(R.id.btnCriarBloqueio);
|
||||
Button btnStaff = findViewById(R.id.btnGestaoStaff);
|
||||
Button btnReports = findViewById(R.id.btnVerRelatorios);
|
||||
Button btnGerirMesas = findViewById(R.id.btnGerirMesas);
|
||||
Button btnDetalhesReservas = findViewById(R.id.btnDetalhesReservas);
|
||||
Button btnBack = findViewById(R.id.btnVoltar);
|
||||
|
||||
btnOpenWalkIns.setOnClickListener(v ->
|
||||
startActivity(new Intent(this, ListaEsperaActivity.class))
|
||||
@@ -56,6 +62,18 @@ public class EstablishmentDashboardActivity extends AppCompatActivity {
|
||||
btnReports.setOnClickListener(v ->
|
||||
startActivity(new Intent(this, RelatoriosActivity.class))
|
||||
);
|
||||
|
||||
btnGerirMesas.setOnClickListener(v ->
|
||||
startActivity(new Intent(this, GerirMesasActivity.class))
|
||||
);
|
||||
|
||||
btnDetalhesReservas.setOnClickListener(v ->
|
||||
startActivity(new Intent(this, DetalhesReservasActivity.class))
|
||||
);
|
||||
|
||||
if (btnBack != null) {
|
||||
btnBack.setOnClickListener(v -> finish());
|
||||
}
|
||||
}
|
||||
|
||||
// Mantemos este método caso seja útil no futuro para feedback rápido.
|
||||
|
||||
@@ -8,6 +8,8 @@ import androidx.core.graphics.Insets;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
|
||||
import android.widget.Button;
|
||||
|
||||
public class ExplorarRestaurantesActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
@@ -20,7 +22,15 @@ public class ExplorarRestaurantesActivity extends AppCompatActivity {
|
||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||
return insets;
|
||||
});
|
||||
|
||||
Button back = findViewById(R.id.btnVoltar);
|
||||
if (back != null) {
|
||||
back.setOnClickListener(v -> finish());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ import androidx.core.graphics.Insets;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
|
||||
import android.widget.Button;
|
||||
|
||||
public class FavoritosActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
@@ -20,7 +22,15 @@ public class FavoritosActivity extends AppCompatActivity {
|
||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||
return insets;
|
||||
});
|
||||
|
||||
Button back = findViewById(R.id.btnVoltar);
|
||||
if (back != null) {
|
||||
back.setOnClickListener(v -> finish());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ import androidx.core.graphics.Insets;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
|
||||
import android.widget.Button;
|
||||
|
||||
public class GestaoStaffActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
@@ -20,7 +22,15 @@ public class GestaoStaffActivity extends AppCompatActivity {
|
||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||
return insets;
|
||||
});
|
||||
|
||||
Button back = findViewById(R.id.btnVoltar);
|
||||
if (back != null) {
|
||||
back.setOnClickListener(v -> finish());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ import androidx.core.graphics.Insets;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
|
||||
import android.widget.Button;
|
||||
|
||||
public class ListaEsperaActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
@@ -20,7 +22,15 @@ public class ListaEsperaActivity extends AppCompatActivity {
|
||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||
return insets;
|
||||
});
|
||||
|
||||
Button back = findViewById(R.id.btnVoltar);
|
||||
if (back != null) {
|
||||
back.setOnClickListener(v -> finish());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.example.pap_teste;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
@@ -15,14 +16,26 @@ import androidx.core.graphics.Insets;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
|
||||
import com.google.firebase.FirebaseApp;
|
||||
import com.google.firebase.auth.FirebaseAuth;
|
||||
import com.google.firebase.firestore.FirebaseFirestore;
|
||||
import com.google.firebase.firestore.SetOptions;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
public static final String EXTRA_ACTION_MODE = "extra_action_mode";
|
||||
public static final String EXTRA_DISPLAY_NAME = "extra_display_name";
|
||||
public static final String EXTRA_EMAIL = "extra_email";
|
||||
public static final String EXTRA_ACCOUNT_TYPE = "extra_account_type";
|
||||
public static final String EXTRA_ROLE = "extra_role";
|
||||
private static final String PREFS_NAME = "pap_prefs";
|
||||
private static final String KEY_HAS_CREATED_ACCOUNT = "has_created_account";
|
||||
|
||||
private enum AccountType {CLIENTE, ESTABELECIMENTO}
|
||||
private enum AccountAction {ENTRAR, CRIAR}
|
||||
public enum AccountType {CLIENTE, ESTABELECIMENTO}
|
||||
public enum AccountAction {ENTRAR, CRIAR}
|
||||
|
||||
private AccountType selectedAccountType = AccountType.CLIENTE;
|
||||
private AccountAction selectedAccountAction = AccountAction.ENTRAR;
|
||||
@@ -35,6 +48,13 @@ public class MainActivity extends AppCompatActivity {
|
||||
private EditText inputName;
|
||||
private EditText inputEmail;
|
||||
private EditText inputPassword;
|
||||
private EditText inputOwnerPhone;
|
||||
private EditText inputEstablishmentName;
|
||||
private EditText inputEstablishmentEmail;
|
||||
private EditText inputEstablishmentPhone;
|
||||
private boolean hasCreatedAccount;
|
||||
private FirebaseAuth firebaseAuth;
|
||||
private FirebaseFirestore firestore;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -47,10 +67,15 @@ public class MainActivity extends AppCompatActivity {
|
||||
return insets;
|
||||
});
|
||||
|
||||
FirebaseApp.initializeApp(this);
|
||||
firebaseAuth = FirebaseAuth.getInstance();
|
||||
firestore = FirebaseFirestore.getInstance();
|
||||
|
||||
bindViews();
|
||||
setupTypeToggle();
|
||||
setupActionToggle();
|
||||
setupPrimaryAction();
|
||||
enforceFirstAccountCreation();
|
||||
}
|
||||
|
||||
private void bindViews() {
|
||||
@@ -62,6 +87,10 @@ public class MainActivity extends AppCompatActivity {
|
||||
inputName = findViewById(R.id.inputName);
|
||||
inputEmail = findViewById(R.id.inputEmail);
|
||||
inputPassword = findViewById(R.id.inputPassword);
|
||||
inputOwnerPhone = findViewById(R.id.inputOwnerPhone);
|
||||
inputEstablishmentName = findViewById(R.id.inputEstablishmentName);
|
||||
inputEstablishmentEmail = findViewById(R.id.inputEstablishmentEmail);
|
||||
inputEstablishmentPhone = findViewById(R.id.inputEstablishmentPhone);
|
||||
}
|
||||
|
||||
private void setupTypeToggle() {
|
||||
@@ -96,6 +125,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
private void updateTypeButtons() {
|
||||
setSelectedState(btnCliente, selectedAccountType == AccountType.CLIENTE);
|
||||
setSelectedState(btnEstabelecimento, selectedAccountType == AccountType.ESTABELECIMENTO);
|
||||
updateInputVisibility();
|
||||
}
|
||||
|
||||
private void updateActionButtons() {
|
||||
@@ -105,44 +135,93 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void setSelectedState(Button button, boolean isSelected) {
|
||||
int selectedTextColor = Color.WHITE;
|
||||
int defaultTextColor = Color.parseColor("#231F1F");
|
||||
button.setBackgroundResource(isSelected ? R.drawable.tab_selected : R.drawable.tab_unselected);
|
||||
button.setTextColor(isSelected ? Color.WHITE : Color.parseColor("#00001A"));
|
||||
button.setTextColor(isSelected ? selectedTextColor : defaultTextColor);
|
||||
}
|
||||
|
||||
private void updatePrimaryActionState() {
|
||||
boolean creatingAccount = selectedAccountAction == AccountAction.CRIAR;
|
||||
btnPrimaryAction.setText(creatingAccount ? "Criar Conta" : "Entrar");
|
||||
updateInputVisibility();
|
||||
}
|
||||
|
||||
private void updateInputVisibility() {
|
||||
boolean creatingAccount = selectedAccountAction == AccountAction.CRIAR;
|
||||
boolean isEstablishment = selectedAccountType == AccountType.ESTABELECIMENTO;
|
||||
|
||||
inputName.setHint(isEstablishment ? "Nome do proprietário" : "O seu nome");
|
||||
inputEmail.setHint(isEstablishment ? "Email do proprietário" : "Email");
|
||||
|
||||
inputName.setVisibility(creatingAccount ? View.VISIBLE : View.GONE);
|
||||
inputOwnerPhone.setVisibility(creatingAccount && isEstablishment ? View.VISIBLE : View.GONE);
|
||||
inputEstablishmentName.setVisibility(creatingAccount && isEstablishment ? View.VISIBLE : View.GONE);
|
||||
inputEstablishmentEmail.setVisibility(creatingAccount && isEstablishment ? View.VISIBLE : View.GONE);
|
||||
inputEstablishmentPhone.setVisibility(creatingAccount && isEstablishment ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
private void handlePrimaryAction() {
|
||||
String email = inputEmail.getText().toString().trim();
|
||||
String password = inputPassword.getText().toString().trim();
|
||||
String providedName = inputName.getText().toString().trim();
|
||||
String ownerPhone = inputOwnerPhone.getText().toString().trim();
|
||||
String establishmentName = inputEstablishmentName.getText().toString().trim();
|
||||
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;
|
||||
}
|
||||
|
||||
if (selectedAccountAction == AccountAction.CRIAR && TextUtils.isEmpty(providedName)) {
|
||||
Toast.makeText(this, "Indique o seu nome para criar conta.", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
boolean creatingAccount = selectedAccountAction == AccountAction.CRIAR;
|
||||
|
||||
if (creatingAccount) {
|
||||
if (selectedAccountType == AccountType.CLIENTE && TextUtils.isEmpty(providedName)) {
|
||||
Toast.makeText(this, "Indique o seu nome para criar conta.", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (selectedAccountType == AccountType.ESTABELECIMENTO) {
|
||||
boolean missingOwner = TextUtils.isEmpty(providedName) || TextUtils.isEmpty(ownerPhone);
|
||||
boolean missingEstablishment = TextUtils.isEmpty(establishmentName)
|
||||
|| TextUtils.isEmpty(establishmentEmail)
|
||||
|| TextUtils.isEmpty(establishmentPhone);
|
||||
|
||||
if (missingOwner || missingEstablishment) {
|
||||
Toast.makeText(this, "Preencha os dados do proprietário e do estabelecimento.", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String fallbackName = !TextUtils.isEmpty(providedName) ? providedName : deriveNameFromEmail(email);
|
||||
Intent nextScreen;
|
||||
String resolvedRole = getRoleForSelectedType();
|
||||
|
||||
if (selectedAccountType == AccountType.CLIENTE) {
|
||||
nextScreen = new Intent(this, ClientDashboardActivity.class);
|
||||
} else {
|
||||
nextScreen = new Intent(this, EstablishmentDashboardActivity.class);
|
||||
if (creatingAccount) {
|
||||
createAccountInFirebase(
|
||||
email,
|
||||
password,
|
||||
providedName,
|
||||
ownerPhone,
|
||||
establishmentName,
|
||||
establishmentEmail,
|
||||
establishmentPhone,
|
||||
fallbackName,
|
||||
resolvedRole
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
nextScreen.putExtra(EXTRA_ACTION_MODE, selectedAccountAction.name());
|
||||
nextScreen.putExtra(EXTRA_DISPLAY_NAME, fallbackName);
|
||||
nextScreen.putExtra(EXTRA_EMAIL, email);
|
||||
startActivity(nextScreen);
|
||||
signInExistingAccount(email, password, fallbackName, resolvedRole);
|
||||
}
|
||||
|
||||
private String deriveNameFromEmail(String email) {
|
||||
@@ -157,4 +236,206 @@ public class MainActivity extends AppCompatActivity {
|
||||
String rest = candidate.length() > 1 ? candidate.substring(1) : "";
|
||||
return firstLetter + rest;
|
||||
}
|
||||
|
||||
private void enforceFirstAccountCreation() {
|
||||
SharedPreferences prefs = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
|
||||
hasCreatedAccount = prefs.getBoolean(KEY_HAS_CREATED_ACCOUNT, false);
|
||||
|
||||
if (!hasCreatedAccount) {
|
||||
selectedAccountAction = AccountAction.CRIAR;
|
||||
Toast.makeText(this, "Crie uma conta para começar a usar a app.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
updateActionButtons();
|
||||
}
|
||||
|
||||
private void markAccountCreated() {
|
||||
hasCreatedAccount = true;
|
||||
SharedPreferences prefs = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
|
||||
prefs.edit().putBoolean(KEY_HAS_CREATED_ACCOUNT, true).apply();
|
||||
}
|
||||
|
||||
private String getRoleForSelectedType() {
|
||||
return selectedAccountType == AccountType.ESTABELECIMENTO ? "ADMIN" : "CLIENTE";
|
||||
}
|
||||
|
||||
private String buildDocumentId(String email) {
|
||||
return email.replace(".", "_").replace("@", "_at_");
|
||||
}
|
||||
|
||||
private boolean ensureFirebaseReady() {
|
||||
boolean ready = firebaseAuth != null && firestore != null;
|
||||
if (!ready) {
|
||||
Toast.makeText(this, "Ligue-se ao Firebase para continuar.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
return ready;
|
||||
}
|
||||
|
||||
private void signInExistingAccount(String email, String password, String fallbackName, String resolvedRole) {
|
||||
if (!ensureFirebaseReady()) {
|
||||
return;
|
||||
}
|
||||
|
||||
firebaseAuth.signInWithEmailAndPassword(email, password)
|
||||
.addOnSuccessListener(authResult ->
|
||||
fetchAccountAndNavigate(email, fallbackName, resolvedRole)
|
||||
)
|
||||
.addOnFailureListener(e ->
|
||||
Toast.makeText(this, "Não foi possível iniciar sessão: " + e.getMessage(), Toast.LENGTH_SHORT).show()
|
||||
);
|
||||
}
|
||||
|
||||
private void createAccountInFirebase(
|
||||
String email,
|
||||
String password,
|
||||
String providedName,
|
||||
String ownerPhone,
|
||||
String establishmentName,
|
||||
String establishmentEmail,
|
||||
String establishmentPhone,
|
||||
String fallbackName,
|
||||
String resolvedRole
|
||||
) {
|
||||
if (!ensureFirebaseReady()) {
|
||||
return;
|
||||
}
|
||||
|
||||
firebaseAuth.createUserWithEmailAndPassword(email, password)
|
||||
.addOnSuccessListener(result -> {
|
||||
if (!hasCreatedAccount) {
|
||||
markAccountCreated();
|
||||
}
|
||||
String finalDisplayName = selectedAccountType == AccountType.ESTABELECIMENTO && !TextUtils.isEmpty(establishmentName)
|
||||
? establishmentName
|
||||
: fallbackName;
|
||||
String uid = result.getUser() != null ? result.getUser().getUid() : null;
|
||||
|
||||
persistAccountInFirebase(
|
||||
email,
|
||||
providedName,
|
||||
resolvedRole,
|
||||
ownerPhone,
|
||||
establishmentName,
|
||||
establishmentEmail,
|
||||
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);
|
||||
}
|
||||
);
|
||||
})
|
||||
.addOnFailureListener(e ->
|
||||
Toast.makeText(this, "Falha ao criar conta: " + e.getMessage(), Toast.LENGTH_SHORT).show()
|
||||
);
|
||||
}
|
||||
|
||||
private void fetchAccountAndNavigate(String email, String fallbackName, String resolvedRole) {
|
||||
if (firestore == null) {
|
||||
Toast.makeText(this, "Firebase indisponível.", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
String documentId = buildDocumentId(email);
|
||||
firestore.collection("users")
|
||||
.document(documentId)
|
||||
.get()
|
||||
.addOnSuccessListener(snapshot -> {
|
||||
if (snapshot == null || !snapshot.exists()) {
|
||||
Toast.makeText(this, "Conta não encontrada no Firebase.", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
String accountTypeInFirebase = snapshot.getString("accountType");
|
||||
if (accountTypeInFirebase != null
|
||||
&& !accountTypeInFirebase.equalsIgnoreCase(selectedAccountType.name())) {
|
||||
Toast.makeText(this, "Tipo de conta não corresponde ao registo no Firebase.", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
String displayNameFromDb = snapshot.getString("displayName");
|
||||
String establishmentName = snapshot.getString("establishmentName");
|
||||
String ownerName = snapshot.getString("ownerName");
|
||||
String roleFromDb = snapshot.getString("role");
|
||||
|
||||
String finalDisplayName = !TextUtils.isEmpty(establishmentName)
|
||||
? establishmentName
|
||||
: !TextUtils.isEmpty(displayNameFromDb) ? displayNameFromDb
|
||||
: !TextUtils.isEmpty(ownerName) ? ownerName
|
||||
: fallbackName;
|
||||
|
||||
String finalRole = !TextUtils.isEmpty(roleFromDb) ? roleFromDb : resolvedRole;
|
||||
|
||||
Intent nextScreen = selectedAccountType == AccountType.CLIENTE
|
||||
? new Intent(this, ClientDashboardActivity.class)
|
||||
: new Intent(this, EstablishmentDashboardActivity.class);
|
||||
|
||||
nextScreen.putExtra(EXTRA_ACTION_MODE, selectedAccountAction.name());
|
||||
nextScreen.putExtra(EXTRA_DISPLAY_NAME, finalDisplayName);
|
||||
nextScreen.putExtra(EXTRA_EMAIL, email);
|
||||
nextScreen.putExtra(EXTRA_ACCOUNT_TYPE, selectedAccountType.name());
|
||||
nextScreen.putExtra(EXTRA_ROLE, finalRole);
|
||||
startActivity(nextScreen);
|
||||
})
|
||||
.addOnFailureListener(e ->
|
||||
Toast.makeText(this, "Erro ao verificar conta no Firebase.", Toast.LENGTH_SHORT).show()
|
||||
);
|
||||
}
|
||||
|
||||
private void persistAccountInFirebase(
|
||||
String ownerEmail,
|
||||
String ownerName,
|
||||
String role,
|
||||
String ownerPhone,
|
||||
String establishmentName,
|
||||
String establishmentEmail,
|
||||
String establishmentPhone,
|
||||
String uid,
|
||||
Runnable onSuccess
|
||||
) {
|
||||
if (firestore == null) {
|
||||
Toast.makeText(this, "Firebase indisponível.", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
String documentId = buildDocumentId(ownerEmail);
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
if (!TextUtils.isEmpty(uid)) {
|
||||
payload.put("uid", uid);
|
||||
}
|
||||
payload.put("email", ownerEmail);
|
||||
payload.put("displayName", ownerName);
|
||||
payload.put("role", role);
|
||||
payload.put("accountType", selectedAccountType.name());
|
||||
payload.put("createdAt", System.currentTimeMillis());
|
||||
|
||||
if (selectedAccountType == AccountType.ESTABELECIMENTO) {
|
||||
payload.put("ownerName", ownerName);
|
||||
payload.put("ownerEmail", ownerEmail);
|
||||
payload.put("ownerPhone", ownerPhone);
|
||||
payload.put("establishmentName", establishmentName);
|
||||
payload.put("establishmentEmail", establishmentEmail);
|
||||
payload.put("establishmentPhone", establishmentPhone);
|
||||
}
|
||||
|
||||
firestore.collection("users")
|
||||
.document(documentId)
|
||||
.set(payload, SetOptions.merge())
|
||||
.addOnSuccessListener(unused ->
|
||||
{
|
||||
Toast.makeText(this, "Conta guardada na cloud.", Toast.LENGTH_SHORT).show();
|
||||
if (onSuccess != null) {
|
||||
onSuccess.run();
|
||||
}
|
||||
}
|
||||
)
|
||||
.addOnFailureListener(e ->
|
||||
Toast.makeText(this, "Não foi possível guardar na cloud.", Toast.LENGTH_SHORT).show()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,8 @@ import androidx.core.graphics.Insets;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
|
||||
import android.widget.Button;
|
||||
|
||||
public class NovaReservaActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
@@ -20,7 +22,15 @@ public class NovaReservaActivity extends AppCompatActivity {
|
||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||
return insets;
|
||||
});
|
||||
|
||||
Button back = findViewById(R.id.btnVoltar);
|
||||
if (back != null) {
|
||||
back.setOnClickListener(v -> finish());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ import androidx.core.graphics.Insets;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
|
||||
import android.widget.Button;
|
||||
|
||||
public class PartilharReservaActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
@@ -20,7 +22,10 @@ public class PartilharReservaActivity extends AppCompatActivity {
|
||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||
return insets;
|
||||
});
|
||||
|
||||
Button back = findViewById(R.id.btnVoltar);
|
||||
if (back != null) {
|
||||
back.setOnClickListener(v -> finish());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@ import androidx.core.graphics.Insets;
|
||||
import androidx.core.view.ViewCompat;
|
||||
import androidx.core.view.WindowInsetsCompat;
|
||||
|
||||
import android.widget.Button;
|
||||
|
||||
public class RelatoriosActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
@@ -20,7 +22,10 @@ public class RelatoriosActivity extends AppCompatActivity {
|
||||
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
|
||||
return insets;
|
||||
});
|
||||
|
||||
Button back = findViewById(R.id.btnVoltar);
|
||||
if (back != null) {
|
||||
back.setOnClickListener(v -> finish());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user