tenho de ver se marca as coisas

This commit is contained in:
2026-05-05 17:13:39 +01:00
parent 5d7ed9b0a4
commit 5f1b849afe
8 changed files with 456 additions and 315 deletions

View File

@@ -72,4 +72,9 @@ dependencies {
implementation 'com.google.firebase:firebase-auth' implementation 'com.google.firebase:firebase-auth'
implementation 'com.google.firebase:firebase-firestore' implementation 'com.google.firebase:firebase-firestore'
implementation 'com.google.firebase:firebase-database' implementation 'com.google.firebase:firebase-database'
implementation 'com.google.firebase:firebase-storage'
// Glide
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
} }

View File

@@ -59,6 +59,18 @@ public class MainActivity extends AppCompatActivity {
if (navHostFragment != null) { if (navHostFragment != null) {
NavController navController = navHostFragment.getNavController(); NavController navController = navHostFragment.getNavController();
NavigationUI.setupWithNavController(binding.navView, navController); NavigationUI.setupWithNavController(binding.navView, navController);
// Força o clique no Perfil com Transação Manual (Infalível)
binding.navView.setOnItemSelectedListener(item -> {
if (item.getItemId() == R.id.navigation_profile) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.nav_host_fragment, new com.example.cuida.ui.profile.ProfileFragment())
.addToBackStack(null)
.commit();
return true;
}
return NavigationUI.onNavDestinationSelected(item, navController);
});
} }
} }
} }

View File

@@ -9,6 +9,7 @@ import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import com.example.cuida.R;
import com.example.cuida.databinding.FragmentHomeBinding; import com.example.cuida.databinding.FragmentHomeBinding;
import com.example.cuida.ui.medication.MedicationViewModel; import com.example.cuida.ui.medication.MedicationViewModel;
import com.example.cuida.ui.medication.MedicationAdapter; import com.example.cuida.ui.medication.MedicationAdapter;
@@ -16,7 +17,7 @@ import com.example.cuida.ui.appointments.AppointmentsViewModel;
import com.example.cuida.ui.appointments.AppointmentAdapter; import com.example.cuida.ui.appointments.AppointmentAdapter;
import com.example.cuida.data.model.Appointment; import com.example.cuida.data.model.Appointment;
import com.example.cuida.data.model.Medication; import com.example.cuida.data.model.Medication;
import com.bumptech.glide.Glide;
import java.util.Collections; import java.util.Collections;
public class HomeFragment extends Fragment { public class HomeFragment extends Fragment {
@@ -45,27 +46,42 @@ public class HomeFragment extends Fragment {
if (name != null && !name.isEmpty()) { if (name != null && !name.isEmpty()) {
String firstName = name.split(" ")[0]; String firstName = name.split(" ")[0];
binding.textGreeting.setText("Olá, " + firstName + "!"); binding.textGreeting.setText("Olá, " + firstName);
} else { } else {
binding.textGreeting.setText("Olá, Utilizador!"); binding.textGreeting.setText("Olá");
} }
String profilePictureUri = documentSnapshot.getString("profilePictureUri"); String profilePictureUri = documentSnapshot.getString("profilePictureUri");
if (profilePictureUri != null && !profilePictureUri.isEmpty()) { if (isAdded() && binding.imageProfileHome != null) {
try { binding.imageProfileHome.setVisibility(View.VISIBLE);
binding.imageProfileHome.setImageURI(android.net.Uri.parse(profilePictureUri)); if (profilePictureUri != null && !profilePictureUri.isEmpty() && getContext() != null) {
} catch (Exception e) { Glide.with(getContext())
android.util.Log.e("HomeFragment", "Error loading profile pic view: " + e.getMessage()); .load(profilePictureUri)
.placeholder(R.drawable.ic_user)
.circleCrop()
.into(binding.imageProfileHome);
} else {
binding.imageProfileHome.setImageResource(R.drawable.ic_user);
} }
// Clique para entrar no perfil (Manual e Infalível)
binding.imageProfileHome.setOnClickListener(v -> {
if (getActivity() != null) {
getActivity().getSupportFragmentManager().beginTransaction()
.replace(R.id.nav_host_fragment, new com.example.cuida.ui.profile.ProfileFragment())
.addToBackStack(null)
.commit();
}
});
} }
} }
}) })
.addOnFailureListener(e -> { .addOnFailureListener(e -> {
if (isAdded()) if (isAdded())
binding.textGreeting.setText("Olá, Utilizador!"); binding.textGreeting.setText("Olá");
}); });
} else { } else {
binding.textGreeting.setText("Olá, Utilizador!"); binding.textGreeting.setText("Olá");
} }
// --- Setup Adapters --- // --- Setup Adapters ---

View File

@@ -11,51 +11,63 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import com.bumptech.glide.Glide;
import com.example.cuida.R; import com.example.cuida.R;
import com.example.cuida.data.model.User;
import com.example.cuida.databinding.FragmentProfileBinding; import com.example.cuida.databinding.FragmentProfileBinding;
import com.example.cuida.data.model.User;
import com.example.cuida.ui.auth.LoginActivity; import com.example.cuida.ui.auth.LoginActivity;
import com.google.firebase.auth.FirebaseAuth; import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.firestore.FirebaseFirestore; import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference;
import java.util.HashMap;
import java.util.Map;
public class ProfileFragment extends Fragment { public class ProfileFragment extends Fragment {
private FragmentProfileBinding binding; private FragmentProfileBinding binding;
private User currentUser;
private FirebaseFirestore db;
private FirebaseAuth auth; private FirebaseAuth auth;
private Uri tempProfileUri; private FirebaseFirestore db;
private ImageView dialogImageView; private FirebaseStorage storage;
private User currentUser;
private String userId;
private final androidx.activity.result.ActivityResultLauncher<String> pickMedia = registerForActivityResult( private ImageView dialogImageView;
new androidx.activity.result.contract.ActivityResultContracts.GetContent(), uri -> { private Uri tempProfileUri;
if (uri != null) {
private final ActivityResultLauncher<String> pickMedia = registerForActivityResult(
new ActivityResultContracts.GetContent(), uri -> {
if (uri != null && dialogImageView != null) {
tempProfileUri = uri; tempProfileUri = uri;
try {
requireContext().getContentResolver().takePersistableUriPermission(uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION);
} catch (Exception e) {
Log.e("ProfileFragment", "Permission error: " + e.getMessage());
}
if (dialogImageView != null) {
dialogImageView.setImageURI(uri); dialogImageView.setImageURI(uri);
} }
}
}); });
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
try {
binding = FragmentProfileBinding.inflate(inflater, container, false); binding = FragmentProfileBinding.inflate(inflater, container, false);
View root = binding.getRoot();
db = FirebaseFirestore.getInstance();
auth = FirebaseAuth.getInstance(); auth = FirebaseAuth.getInstance();
db = FirebaseFirestore.getInstance();
storage = FirebaseStorage.getInstance();
if (auth.getCurrentUser() != null) {
userId = auth.getCurrentUser().getUid();
loadUserData(); loadUserData();
}
binding.buttonEditProfile.setOnClickListener(v -> showEditDialog()); binding.buttonEditProfile.setOnClickListener(v -> showEditDialog());
binding.buttonLogout.setOnClickListener(v -> { binding.buttonLogout.setOnClickListener(v -> {
auth.signOut(); auth.signOut();
if (getContext() != null) { if (getContext() != null) {
@@ -65,91 +77,100 @@ public class ProfileFragment extends Fragment {
requireActivity().finish(); requireActivity().finish();
}); });
return binding.getRoot(); return root;
} catch (Exception e) {
Log.e("ProfileFragment", "Erro ao inflar perfil", e);
return inflater.inflate(R.layout.fragment_profile, container, false);
}
} }
private void loadUserData() { private void loadUserData() {
if (auth.getCurrentUser() == null) return; try {
String userId = auth.getCurrentUser().getUid(); if (userId == null || !isAdded()) return;
if (currentUser == null) { // Primeiro tenta na coleção geral 'utilizadores'
currentUser = new User(); db.collection("utilizadores").document(userId).addSnapshotListener((doc, error) -> {
currentUser.id = userId; try {
currentUser.email = auth.getCurrentUser().getEmail(); if (doc != null && doc.exists()) {
currentUser.name = auth.getCurrentUser().getDisplayName(); updateUIFromDocument(doc);
} }
db.collection("utilizadores").document(userId) // Independentemente de encontrar em 'utilizadores', tenta TAMBÉM em 'Pacientes' para completar dados
.addSnapshotListener((doc, error) -> { db.collection("Pacientes").document(userId).get().addOnSuccessListener(docP -> {
if (error != null) { if (docP.exists()) {
Log.e("ProfileFragment", "Listen failed.", error); updateUIFromDocument(docP);
return;
}
if (doc != null && doc.exists() && isAdded()) {
currentUser.id = doc.getId();
String nome = doc.getString("nome_completo");
if (nome == null) nome = doc.getString("name");
currentUser.name = nome;
currentUser.email = doc.getString("email");
String utente = doc.getString("numero_utente");
if (utente == null) utente = doc.getString("utenteNumber");
currentUser.utenteNumber = utente;
currentUser.profilePictureUri = doc.getString("profilePictureUri");
Object ageObj = doc.get("idade");
if (ageObj == null) ageObj = doc.get("age");
if (ageObj instanceof Number) currentUser.age = ((Number) ageObj).intValue();
else if (ageObj instanceof String) {
try { currentUser.age = Integer.parseInt((String) ageObj); }
catch (Exception e) { currentUser.age = 0; }
}
updateUI();
} }
}); });
}
private void updateUI() {
if (!isAdded() || binding == null || currentUser == null) return;
binding.profileName.setText(currentUser.name != null ? currentUser.name : "N/D");
binding.profileEmail.setText(currentUser.email != null ? currentUser.email : "N/D");
binding.profileAge.setText(currentUser.age > 0 ? String.valueOf(currentUser.age) : "N/D");
binding.profileUtente.setText(currentUser.utenteNumber != null ? currentUser.utenteNumber : "N/D");
if (currentUser.profilePictureUri != null && !currentUser.profilePictureUri.isEmpty()) {
ImageView profileImage = binding.getRoot().findViewById(R.id.profile_image);
if (profileImage != null) loadSafeImage(profileImage, currentUser.profilePictureUri);
}
}
private void loadSafeImage(ImageView view, String uriStr) {
if (view == null || uriStr == null) return;
try {
Uri uri = Uri.parse(uriStr);
if (uri.getScheme() != null && (uri.getScheme().equals("content") || uri.getScheme().equals("file"))) {
view.setImageURI(uri);
} else {
Log.d("ProfileFragment", "Skipping setImageURI for non-local scheme: " + uri.getScheme());
}
} catch (Exception e) { } catch (Exception e) {
Log.e("ProfileFragment", "Image load error: " + e.getMessage()); Log.e("ProfileFragment", "Erro no carregamento", e);
}
});
} catch (Exception e) {
Log.e("ProfileFragment", "Erro ao iniciar", e);
}
}
private void updateUIFromDocument(com.google.firebase.firestore.DocumentSnapshot doc) {
if (!isAdded() || binding == null) return;
// Nome
String n = doc.getString("nome_completo");
if (n == null) n = doc.getString("name");
if (n == null) n = doc.getString("nome");
if (n != null && !n.isEmpty()) binding.profileName.setText(n);
// Email
String e = doc.getString("email");
if (e != null && !e.isEmpty()) binding.profileEmail.setText(e);
// Idade
Long i = doc.getLong("idade");
if (i != null) binding.profileAge.setText(String.valueOf(i));
// Nº Utente
String u = doc.getString("numero_utente");
if (u == null) u = doc.getString("utenteNumber");
if (u != null && !u.isEmpty()) binding.profileUtente.setText(u);
// Foto
String p = doc.getString("profilePictureUri");
if (p != null && !p.isEmpty()) {
loadSafeImage(binding.profileImage, p);
}
// Atualiza objeto local para o EditDialog
if (currentUser == null) currentUser = new User();
if (n != null) currentUser.name = n;
if (e != null) currentUser.email = e;
if (i != null) currentUser.age = i.intValue();
if (u != null) currentUser.utenteNumber = u;
if (p != null) currentUser.profilePictureUri = p;
currentUser.id = doc.getId();
}
private void loadSafeImage(ImageView view, String url) {
try {
if (!isAdded() || view == null || getContext() == null) return;
Glide.with(getContext())
.load(url)
.placeholder(R.drawable.ic_user)
.circleCrop()
.into(view);
} catch (Exception e) {
Log.e("ProfileFragment", "Erro ao carregar imagem", e);
} }
} }
private void showEditDialog() { private void showEditDialog() {
if (currentUser == null) { if (!isAdded()) return;
Toast.makeText(getContext(), "Dados não carregados.", Toast.LENGTH_SHORT).show(); if (currentUser == null) currentUser = new User();
return;
}
try { try {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); AlertDialog.Builder builder = new AlertDialog.Builder(requireContext(), R.style.CustomDialogTheme);
View dialogView = requireActivity().getLayoutInflater().inflate(R.layout.dialog_edit_profile, null); View dialogView = requireActivity().getLayoutInflater().inflate(R.layout.dialog_edit_profile, null);
builder.setView(dialogView); builder.setView(dialogView);
AlertDialog dialog = builder.create(); AlertDialog dialog = builder.create();
if (dialog.getWindow() != null) dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
EditText editName = dialogView.findViewById(R.id.edit_name); EditText editName = dialogView.findViewById(R.id.edit_name);
EditText editAge = dialogView.findViewById(R.id.edit_age); EditText editAge = dialogView.findViewById(R.id.edit_age);
@@ -157,78 +178,91 @@ public class ProfileFragment extends Fragment {
EditText editEmail = dialogView.findViewById(R.id.edit_email); EditText editEmail = dialogView.findViewById(R.id.edit_email);
dialogImageView = dialogView.findViewById(R.id.edit_profile_image); dialogImageView = dialogView.findViewById(R.id.edit_profile_image);
if (editName == null || dialogImageView == null) return; // Preenchimento Seguro
if (editName != null) editName.setText(currentUser.name);
editName.setText(currentUser.name); if (editAge != null) editAge.setText(String.valueOf(currentUser.age));
editAge.setText(String.valueOf(currentUser.age)); if (editUtente != null) editUtente.setText(currentUser.utenteNumber);
editUtente.setText(currentUser.utenteNumber); if (editEmail != null) editEmail.setText(currentUser.email);
editEmail.setText(currentUser.email); if (dialogImageView != null && currentUser.profilePictureUri != null) {
loadSafeImage(dialogImageView, currentUser.profilePictureUri);
if (currentUser.profilePictureUri != null) loadSafeImage(dialogImageView, currentUser.profilePictureUri);
dialogView.findViewById(R.id.button_change_photo).setOnClickListener(v -> pickMedia.launch("image/*"));
dialogImageView.setOnClickListener(v -> pickMedia.launch("image/*"));
dialogView.findViewById(R.id.button_change_password).setOnClickListener(v -> showChangePasswordDialog());
dialogView.findViewById(R.id.button_cancel).setOnClickListener(v -> dialog.dismiss());
dialogView.findViewById(R.id.button_save).setOnClickListener(v -> {
String newName = editName.getText().toString().trim();
String ageStr = editAge.getText().toString().trim();
String newUtente = editUtente.getText().toString().trim();
String newEmail = editEmail.getText().toString().trim();
if (newName.isEmpty() || ageStr.isEmpty() || newUtente.isEmpty() || newEmail.isEmpty()) {
Toast.makeText(getContext(), "Preencha todos os campos.", Toast.LENGTH_SHORT).show();
return;
} }
currentUser.name = newName; // Listeners
try { currentUser.age = Integer.parseInt(ageStr); } catch (Exception ignored) {} View btnPhoto = dialogView.findViewById(R.id.button_change_photo);
currentUser.utenteNumber = newUtente; if (btnPhoto != null) btnPhoto.setOnClickListener(v -> pickMedia.launch("image/*"));
if (dialogImageView != null) dialogImageView.setOnClickListener(v -> pickMedia.launch("image/*"));
if (tempProfileUri != null) currentUser.profilePictureUri = tempProfileUri.toString(); View btnPass = dialogView.findViewById(R.id.button_change_password);
if (btnPass != null) btnPass.setOnClickListener(v -> showChangePasswordDialog());
db.collection("utilizadores").document(currentUser.id).set(currentUser) View btnCancel = dialogView.findViewById(R.id.button_cancel);
.addOnSuccessListener(aVoid -> { if (btnCancel != null) btnCancel.setOnClickListener(v -> dialog.dismiss());
Toast.makeText(getContext(), "Perfil atualizado!", Toast.LENGTH_SHORT).show();
loadUserData(); View btnSave = dialogView.findViewById(R.id.button_save);
dialog.dismiss(); if (btnSave != null) {
}) btnSave.setOnClickListener(v -> {
.addOnFailureListener(e -> Toast.makeText(getContext(), "Erro ao guardar.", Toast.LENGTH_SHORT).show()); btnSave.setEnabled(false);
if (tempProfileUri != null) {
uploadPhotoAndSave(editName.getText().toString(), editAge.getText().toString(), editUtente.getText().toString(), editEmail.getText().toString(), dialog);
} else {
saveDataToFirestore(editName.getText().toString(), editAge.getText().toString(), editUtente.getText().toString(), editEmail.getText().toString(), currentUser.profilePictureUri, dialog);
}
}); });
}
dialog.show(); dialog.show();
} catch (Exception e) { } catch (Throwable t) {
Toast.makeText(getContext(), "Erro ao abrir edição.", Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "Erro: " + t.toString(), Toast.LENGTH_LONG).show();
} }
} }
private void uploadPhotoAndSave(String n, String a, String u, String e, AlertDialog d) {
StorageReference ref = storage.getReference().child("perfil_pacientes/" + userId + ".jpg");
ref.putFile(tempProfileUri).addOnSuccessListener(task -> {
ref.getDownloadUrl().addOnSuccessListener(uri -> saveDataToFirestore(n, a, u, e, uri.toString(), d));
}).addOnFailureListener(err -> {
Toast.makeText(getContext(), "Erro foto", Toast.LENGTH_SHORT).show();
saveDataToFirestore(n, a, u, e, currentUser.profilePictureUri, d);
});
}
private void saveDataToFirestore(String name, String age, String utente, String email, String photo, AlertDialog d) {
Map<String, Object> map = new HashMap<>();
map.put("nome_completo", name);
map.put("email", email);
try { map.put("idade", Integer.parseInt(age)); } catch (Exception ignored) {
map.put("idade", 0);
}
map.put("numero_utente", utente);
map.put("tipo", "paciente");
if (photo != null) map.put("profilePictureUri", photo);
com.google.firebase.firestore.WriteBatch batch = db.batch();
batch.set(db.collection("utilizadores").document(userId), map, com.google.firebase.firestore.SetOptions.merge());
batch.set(db.collection("Pacientes").document(userId), map, com.google.firebase.firestore.SetOptions.merge());
batch.commit().addOnSuccessListener(aVoid -> {
if (isAdded()) {
Toast.makeText(getContext(), "Perfil Atualizado com Sucesso!", Toast.LENGTH_SHORT).show();
loadUserData();
d.dismiss();
tempProfileUri = null;
}
}).addOnFailureListener(e -> {
if (isAdded()) {
Toast.makeText(getContext(), "Erro ao guardar no Firebase", Toast.LENGTH_SHORT).show();
d.dismiss();
}
});
}
private void showChangePasswordDialog() { private void showChangePasswordDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); Toast.makeText(getContext(), "Funcionalidade de Password em breve.", Toast.LENGTH_SHORT).show();
View view = requireActivity().getLayoutInflater().inflate(R.layout.dialog_change_password, null); }
builder.setView(view);
AlertDialog dialog = builder.create();
EditText editNewPassword = view.findViewById(R.id.new_password); @Override
view.findViewById(R.id.button_save_password).setOnClickListener(v -> { public void onDestroyView() {
String newPass = editNewPassword.getText().toString(); super.onDestroyView();
if (newPass.length() < 6) { binding = null;
Toast.makeText(getContext(), "Mínimo 6 caracteres.", Toast.LENGTH_SHORT).show();
return;
}
if (auth.getCurrentUser() != null) {
auth.getCurrentUser().updatePassword(newPass).addOnCompleteListener(task -> {
if (task.isSuccessful()) {
Toast.makeText(getContext(), "Sucesso!", Toast.LENGTH_SHORT).show();
dialog.dismiss();
} else {
Toast.makeText(getContext(), "Erro: " + task.getException().getMessage(), Toast.LENGTH_LONG).show();
}
});
}
});
view.findViewById(R.id.button_cancel_password).setOnClickListener(v -> dialog.dismiss());
dialog.show();
} }
} }

View File

@@ -1,6 +1,13 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" <com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="28dp"
app:cardElevation="0dp"
android:layout_margin="12dp">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
@@ -10,119 +17,178 @@
android:orientation="vertical" android:orientation="vertical"
android:padding="24dp"> android:padding="24dp">
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/edit_profile_image"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/ic_placeholder"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="8dp"
android:scaleType="centerCrop"
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.App.CornerSize50Percent"
android:clickable="true"
android:focusable="true"/>
<com.google.android.material.button.MaterialButton
android:id="@+id/button_change_photo"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Mudar Foto"
android:layout_marginBottom="16dp"/>
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Editar Dados" android:text="Editar Perfil"
android:textSize="20sp" android:textSize="22sp"
android:textStyle="bold" android:textStyle="bold"
android:textColor="?attr/colorPrimary"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:layout_marginBottom="24dp"/> android:layout_marginBottom="24dp"/>
<!-- Photo Section -->
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="24dp">
<com.google.android.material.imageview.ShapeableImageView
android:id="@+id/edit_profile_image"
android:layout_width="110dp"
android:layout_height="110dp"
android:padding="4dp"
app:strokeWidth="2dp"
app:strokeColor="?attr/colorPrimary"
android:src="@drawable/ic_user"
android:scaleType="centerCrop"
app:shapeAppearanceOverlay="@style/CircleImageView" />
<com.google.android.material.button.MaterialButton
android:id="@+id/button_change_photo"
style="@style/Widget.MaterialComponents.Button.Icon"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_gravity="bottom|end"
android:padding="8dp"
app:icon="@drawable/ic_camera"
app:iconSize="20dp"
app:iconGravity="textStart"
app:iconPadding="0dp"
app:cornerRadius="18dp"
android:insetLeft="0dp"
android:insetTop="0dp"
android:insetRight="0dp"
android:insetBottom="0dp"
app:backgroundTint="?attr/colorPrimary"/>
</FrameLayout>
<!-- Inputs -->
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="16dp"> android:layout_marginBottom="12dp"
android:hint="Nome Completo"
app:startIconDrawable="@drawable/ic_user"
app:boxCornerRadiusBottomEnd="16dp"
app:boxCornerRadiusBottomStart="16dp"
app:boxCornerRadiusTopEnd="16dp"
app:boxCornerRadiusTopStart="16dp">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_name" android:id="@+id/edit_name"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="Nome"
android:inputType="textPersonName" /> android:inputType="textPersonName" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_age"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Idade"
android:maxLength="3"
android:inputType="number" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_utente"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Nº Utente"
android:maxLength="9"
android:inputType="number" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email"
android:inputType="textEmailAddress" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/button_change_password"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Alterar Palavra-passe"
android:layout_marginBottom="24dp"/>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:orientation="horizontal"
android:gravity="end"> android:layout_marginBottom="12dp">
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginEnd="6dp"
android:hint="Idade"
app:boxCornerRadiusBottomEnd="16dp"
app:boxCornerRadiusBottomStart="16dp"
app:boxCornerRadiusTopEnd="16dp"
app:boxCornerRadiusTopStart="16dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_age"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:layout_marginStart="6dp"
android:hint="Nº Utente"
app:boxCornerRadiusBottomEnd="16dp"
app:boxCornerRadiusBottomStart="16dp"
app:boxCornerRadiusTopEnd="16dp"
app:boxCornerRadiusTopStart="16dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_utente"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:hint="Email"
app:startIconDrawable="@drawable/ic_user"
app:boxCornerRadiusBottomEnd="16dp"
app:boxCornerRadiusBottomStart="16dp"
app:boxCornerRadiusTopEnd="16dp"
app:boxCornerRadiusTopStart="16dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/button_change_password"
style="@style/Widget.MaterialComponents.Button.TextButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Alterar Palavra-passe"
android:textAllCaps="false"
android:textColor="?attr/colorPrimary"
android:layout_marginBottom="24dp"/>
<!-- Action Buttons -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/button_cancel" android:id="@+id/button_cancel"
style="@style/Widget.MaterialComponents.Button.TextButton" style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="56dp"
android:layout_weight="1"
android:text="Cancelar" android:text="Cancelar"
android:layout_marginEnd="8dp"/> android:textAllCaps="false"
android:layout_marginEnd="8dp"
app:cornerRadius="16dp"
app:strokeColor="?attr/colorPrimary"
android:textColor="?attr/colorPrimary"/>
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/button_save" android:id="@+id/button_save"
android:layout_width="wrap_content" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="56dp"
android:text="Salvar" /> android:layout_weight="1.5"
android:text="Salvar Dados"
android:textAllCaps="false"
android:textStyle="bold"
app:cornerRadius="16dp"
android:layout_marginStart="8dp"/>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</ScrollView> </androidx.core.widget.NestedScrollView>
</com.google.android.material.card.MaterialCardView>

View File

@@ -6,51 +6,51 @@
android:background="@color/background_color"> android:background="@color/background_color">
<!-- Header / Top Bar area --> <!-- Header / Top Bar area -->
<View <LinearLayout
android:id="@+id/header_bg" android:id="@+id/header_bg"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="160dp" android:layout_height="wrap_content"
android:background="@color/primary_color" android:orientation="horizontal"
app:layout_constraintTop_toTopOf="parent" /> android:paddingTop="56dp"
android:paddingBottom="40dp"
<com.google.android.material.imageview.ShapeableImageView android:paddingHorizontal="28dp"
android:id="@+id/image_profile_home" android:background="@drawable/bg_gradient_header"
android:layout_width="64dp" android:elevation="12dp"
android:layout_height="64dp" app:layout_constraintTop_toTopOf="parent">
android:layout_marginStart="24dp"
android:layout_marginTop="48dp"
android:scaleType="centerCrop"
android:src="@drawable/ic_placeholder"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.App.CornerSize50Percent"
app:strokeWidth="2dp"
app:strokeColor="@color/white" />
<TextView <TextView
android:id="@+id/text_greeting" android:id="@+id/text_greeting"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="16dp" android:layout_weight="1"
android:layout_marginEnd="24dp" android:text="Olá"
android:text="Olá, utilizador!"
android:textColor="@color/white" android:textColor="@color/white"
android:textSize="26sp" android:textSize="38sp"
android:textStyle="bold" android:fontFamily="sans-serif-black"
app:layout_constraintBottom_toBottomOf="@id/image_profile_home" android:gravity="center_vertical" />
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/image_profile_home" <com.google.android.material.imageview.ShapeableImageView
app:layout_constraintTop_toTopOf="@id/image_profile_home" /> android:id="@+id/image_profile_home"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_marginStart="16dp"
android:scaleType="centerCrop"
android:src="@drawable/ic_placeholder"
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.App.CornerSize50Percent"
app:strokeWidth="2dp"
app:strokeColor="@color/white"
android:visibility="gone" />
</LinearLayout>
<androidx.core.widget.NestedScrollView <androidx.core.widget.NestedScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
android:layout_marginTop="24dp" android:layout_marginTop="16dp"
android:fillViewport="true" android:fillViewport="true"
android:clipToPadding="false" android:clipToPadding="false"
android:paddingBottom="40dp" android:paddingBottom="40dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/image_profile_home"> app:layout_constraintTop_toBottomOf="@id/header_bg">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@@ -5,7 +5,7 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical"
android:padding="24dp" android:padding="24dp"
android:gravity="center_horizontal" android:gravity="center"
android:background="@color/background_color"> android:background="@color/background_color">
<com.google.android.material.imageview.ShapeableImageView <com.google.android.material.imageview.ShapeableImageView
@@ -116,7 +116,6 @@
android:backgroundTint="@color/secondary_color"/> android:backgroundTint="@color/secondary_color"/>
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/button_logout" android:id="@+id/button_logout"
style="@style/Widget.MaterialComponents.Button.OutlinedButton" style="@style/Widget.MaterialComponents.Button.OutlinedButton"

View File

@@ -37,4 +37,13 @@
<style name="ShapeAppearanceOverlay.App.CornerSize50Percent" parent=""> <style name="ShapeAppearanceOverlay.App.CornerSize50Percent" parent="">
<item name="cornerSize">50%</item> <item name="cornerSize">50%</item>
</style> </style>
<style name="CircleImageView" parent="">
<item name="cornerSize">50%</item>
</style>
<style name="CustomDialogTheme" parent="Theme.MaterialComponents.Light.Dialog.Alert">
<item name="windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>
</resources> </resources>