This commit is contained in:
2026-03-10 16:30:08 +00:00
parent d5c457c9a6
commit 7ad72ad334
29 changed files with 1353 additions and 562 deletions

View File

@@ -11,70 +11,89 @@ import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.recyclerview.widget.RecyclerView;
import com.example.pap_teste.models.FoodCategory;
import java.util.ArrayList;
import java.util.List;
public class ClientDashboardActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_client_dashboard);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.clientRoot), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
private String email, displayName, role;
private TextView txtGreeting;
private androidx.activity.result.ActivityResultLauncher<Intent> profileLauncher;
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);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_client_dashboard);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.clientRoot), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});
String actionMode = getIntent().getStringExtra(MainActivity.EXTRA_ACTION_MODE);
String displayName = getIntent().getStringExtra(MainActivity.EXTRA_DISPLAY_NAME);
String role = getIntent().getStringExtra(MainActivity.EXTRA_ROLE);
txtGreeting = findViewById(R.id.txtClientGreeting);
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.");
email = getIntent().getStringExtra(MainActivity.EXTRA_EMAIL);
displayName = getIntent().getStringExtra(MainActivity.EXTRA_DISPLAY_NAME);
role = getIntent().getStringExtra(MainActivity.EXTRA_ROLE);
txtReservationStatus.setText("Próxima reserva");
txtReservationSubtitle.setText("Mesa para 2 • Amanhã às 20h • Sabor & Arte");
profileLauncher = registerForActivityResult(
new androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult(),
result -> {
if (result.getResultCode() == RESULT_OK) {
android.widget.Toast.makeText(this,
"Perfil atualizado. Reinicie para ver mudanças.",
android.widget.Toast.LENGTH_SHORT).show();
}
});
Button btnNewReservation = findViewById(R.id.btnNovaReserva);
Button btnExplore = findViewById(R.id.btnExplorar);
Button btnFavorites = findViewById(R.id.btnFavoritos);
Button btnCheckIn = findViewById(R.id.btnCheckIn);
Button btnShare = findViewById(R.id.btnPartilhar);
btnNewReservation.setOnClickListener(v ->
startActivity(new Intent(this, NovaReservaActivity.class))
);
btnExplore.setOnClickListener(v ->
startActivity(new Intent(this, ExplorarRestaurantesActivity.class))
);
btnFavorites.setOnClickListener(v ->
startActivity(new Intent(this, FavoritosActivity.class))
);
btnCheckIn.setOnClickListener(v ->
startActivity(new Intent(this, CheckInAntecipadoActivity.class))
);
btnShare.setOnClickListener(v ->
startActivity(new Intent(this, PartilharReservaActivity.class))
);
if (btnBack != null) {
btnBack.setOnClickListener(v -> finish());
updateGreeting();
setupCategories();
setupActions();
}
}
}
private void updateGreeting() {
txtGreeting.setText(String.format("Olá, %s", displayName != null ? displayName : "convidado"));
}
private void setupCategories() {
RecyclerView rv = findViewById(R.id.rvCategories);
List<FoodCategory> cats = new ArrayList<>();
cats.add(new FoodCategory("Carnes", R.drawable.cat_carnes));
cats.add(new FoodCategory("Massas", R.drawable.cat_massas));
cats.add(new FoodCategory("Sushi", R.drawable.cat_sushi));
cats.add(new FoodCategory("Pizzas", R.drawable.ic_launcher_background));
cats.add(new FoodCategory("Sobremesas", R.drawable.ic_launcher_background));
FoodCategoryAdapter adapter = new FoodCategoryAdapter(cats);
rv.setAdapter(adapter);
}
private void setupActions() {
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);
profileLauncher.launch(intent);
});
findViewById(R.id.btnVoltar).setOnClickListener(v -> finish());
findViewById(R.id.btnCheckIn).setOnClickListener(v -> {
Intent intent = new Intent(this, CheckInAntecipadoActivity.class);
intent.putExtra("restaurant_email", "sabor_arte@restaurante.com");
startActivity(intent);
});
findViewById(R.id.btnPartilhar).setOnClickListener(
v -> startActivity(new Intent(this, PartilharReservaActivity.class)));
findViewById(R.id.btnNovaReserva)
.setOnClickListener(v -> startActivity(new Intent(this, NovaReservaActivity.class)));
findViewById(R.id.btnExplorar).setOnClickListener(
v -> startActivity(new Intent(this, ExplorarRestaurantesActivity.class)));
}
}