tenho de ver se marca as coisas
This commit is contained in:
@@ -72,4 +72,9 @@ dependencies {
|
||||
implementation 'com.google.firebase:firebase-auth'
|
||||
implementation 'com.google.firebase:firebase-firestore'
|
||||
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'
|
||||
}
|
||||
|
||||
@@ -59,6 +59,18 @@ public class MainActivity extends AppCompatActivity {
|
||||
if (navHostFragment != null) {
|
||||
NavController navController = navHostFragment.getNavController();
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
import com.example.cuida.R;
|
||||
import com.example.cuida.databinding.FragmentHomeBinding;
|
||||
import com.example.cuida.ui.medication.MedicationViewModel;
|
||||
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.data.model.Appointment;
|
||||
import com.example.cuida.data.model.Medication;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import java.util.Collections;
|
||||
|
||||
public class HomeFragment extends Fragment {
|
||||
@@ -45,27 +46,42 @@ public class HomeFragment extends Fragment {
|
||||
|
||||
if (name != null && !name.isEmpty()) {
|
||||
String firstName = name.split(" ")[0];
|
||||
binding.textGreeting.setText("Olá, " + firstName + "!");
|
||||
binding.textGreeting.setText("Olá, " + firstName);
|
||||
} else {
|
||||
binding.textGreeting.setText("Olá, Utilizador!");
|
||||
binding.textGreeting.setText("Olá");
|
||||
}
|
||||
|
||||
String profilePictureUri = documentSnapshot.getString("profilePictureUri");
|
||||
if (profilePictureUri != null && !profilePictureUri.isEmpty()) {
|
||||
try {
|
||||
binding.imageProfileHome.setImageURI(android.net.Uri.parse(profilePictureUri));
|
||||
} catch (Exception e) {
|
||||
android.util.Log.e("HomeFragment", "Error loading profile pic view: " + e.getMessage());
|
||||
if (isAdded() && binding.imageProfileHome != null) {
|
||||
binding.imageProfileHome.setVisibility(View.VISIBLE);
|
||||
if (profilePictureUri != null && !profilePictureUri.isEmpty() && getContext() != null) {
|
||||
Glide.with(getContext())
|
||||
.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 -> {
|
||||
if (isAdded())
|
||||
binding.textGreeting.setText("Olá, Utilizador!");
|
||||
binding.textGreeting.setText("Olá");
|
||||
});
|
||||
} else {
|
||||
binding.textGreeting.setText("Olá, Utilizador!");
|
||||
binding.textGreeting.setText("Olá");
|
||||
}
|
||||
|
||||
// --- Setup Adapters ---
|
||||
|
||||
@@ -11,51 +11,63 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.activity.result.contract.ActivityResultContracts;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.example.cuida.R;
|
||||
import com.example.cuida.data.model.User;
|
||||
import com.example.cuida.databinding.FragmentProfileBinding;
|
||||
import com.example.cuida.data.model.User;
|
||||
import com.example.cuida.ui.auth.LoginActivity;
|
||||
import com.google.firebase.auth.FirebaseAuth;
|
||||
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 {
|
||||
|
||||
private FragmentProfileBinding binding;
|
||||
private User currentUser;
|
||||
private FirebaseFirestore db;
|
||||
private FirebaseAuth auth;
|
||||
private Uri tempProfileUri;
|
||||
private FirebaseFirestore db;
|
||||
private FirebaseStorage storage;
|
||||
private User currentUser;
|
||||
private String userId;
|
||||
|
||||
private ImageView dialogImageView;
|
||||
private Uri tempProfileUri;
|
||||
|
||||
private final androidx.activity.result.ActivityResultLauncher<String> pickMedia = registerForActivityResult(
|
||||
new androidx.activity.result.contract.ActivityResultContracts.GetContent(), uri -> {
|
||||
if (uri != null) {
|
||||
private final ActivityResultLauncher<String> pickMedia = registerForActivityResult(
|
||||
new ActivityResultContracts.GetContent(), uri -> {
|
||||
if (uri != null && dialogImageView != null) {
|
||||
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) {
|
||||
binding = FragmentProfileBinding.inflate(inflater, container, false);
|
||||
try {
|
||||
binding = FragmentProfileBinding.inflate(inflater, container, false);
|
||||
View root = binding.getRoot();
|
||||
|
||||
db = FirebaseFirestore.getInstance();
|
||||
auth = FirebaseAuth.getInstance();
|
||||
loadUserData();
|
||||
db = FirebaseFirestore.getInstance();
|
||||
storage = FirebaseStorage.getInstance();
|
||||
|
||||
if (auth.getCurrentUser() != null) {
|
||||
userId = auth.getCurrentUser().getUid();
|
||||
loadUserData();
|
||||
}
|
||||
|
||||
binding.buttonEditProfile.setOnClickListener(v -> showEditDialog());
|
||||
|
||||
binding.buttonLogout.setOnClickListener(v -> {
|
||||
auth.signOut();
|
||||
if (getContext() != null) {
|
||||
@@ -65,170 +77,192 @@ public class ProfileFragment extends Fragment {
|
||||
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() {
|
||||
if (auth.getCurrentUser() == null) return;
|
||||
String userId = auth.getCurrentUser().getUid();
|
||||
|
||||
if (currentUser == null) {
|
||||
currentUser = new User();
|
||||
currentUser.id = userId;
|
||||
currentUser.email = auth.getCurrentUser().getEmail();
|
||||
currentUser.name = auth.getCurrentUser().getDisplayName();
|
||||
}
|
||||
|
||||
db.collection("utilizadores").document(userId)
|
||||
.addSnapshotListener((doc, error) -> {
|
||||
if (error != null) {
|
||||
Log.e("ProfileFragment", "Listen failed.", error);
|
||||
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());
|
||||
}
|
||||
if (userId == null || !isAdded()) return;
|
||||
|
||||
// Primeiro tenta na coleção geral 'utilizadores'
|
||||
db.collection("utilizadores").document(userId).addSnapshotListener((doc, error) -> {
|
||||
try {
|
||||
if (doc != null && doc.exists()) {
|
||||
updateUIFromDocument(doc);
|
||||
}
|
||||
|
||||
// Independentemente de encontrar em 'utilizadores', tenta TAMBÉM em 'Pacientes' para completar dados
|
||||
db.collection("Pacientes").document(userId).get().addOnSuccessListener(docP -> {
|
||||
if (docP.exists()) {
|
||||
updateUIFromDocument(docP);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
Log.e("ProfileFragment", "Erro no carregamento", e);
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
Log.e("ProfileFragment", "Image load error: " + e.getMessage());
|
||||
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() {
|
||||
if (currentUser == null) {
|
||||
Toast.makeText(getContext(), "Dados não carregados.", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
if (!isAdded()) return;
|
||||
if (currentUser == null) currentUser = new User();
|
||||
|
||||
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);
|
||||
builder.setView(dialogView);
|
||||
AlertDialog dialog = builder.create();
|
||||
if (dialog.getWindow() != null) dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
|
||||
|
||||
EditText editName = dialogView.findViewById(R.id.edit_name);
|
||||
EditText editAge = dialogView.findViewById(R.id.edit_age);
|
||||
EditText editUtente = dialogView.findViewById(R.id.edit_utente);
|
||||
EditText editEmail = dialogView.findViewById(R.id.edit_email);
|
||||
dialogImageView = dialogView.findViewById(R.id.edit_profile_image);
|
||||
|
||||
if (editName == null || dialogImageView == null) return;
|
||||
|
||||
editName.setText(currentUser.name);
|
||||
editAge.setText(String.valueOf(currentUser.age));
|
||||
editUtente.setText(currentUser.utenteNumber);
|
||||
editEmail.setText(currentUser.email);
|
||||
|
||||
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;
|
||||
try { currentUser.age = Integer.parseInt(ageStr); } catch (Exception ignored) {}
|
||||
currentUser.utenteNumber = newUtente;
|
||||
|
||||
if (tempProfileUri != null) currentUser.profilePictureUri = tempProfileUri.toString();
|
||||
|
||||
db.collection("utilizadores").document(currentUser.id).set(currentUser)
|
||||
.addOnSuccessListener(aVoid -> {
|
||||
Toast.makeText(getContext(), "Perfil atualizado!", Toast.LENGTH_SHORT).show();
|
||||
loadUserData();
|
||||
dialog.dismiss();
|
||||
})
|
||||
.addOnFailureListener(e -> Toast.makeText(getContext(), "Erro ao guardar.", Toast.LENGTH_SHORT).show());
|
||||
});
|
||||
|
||||
dialog.show();
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(getContext(), "Erro ao abrir edição.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void showChangePasswordDialog() {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||
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);
|
||||
view.findViewById(R.id.button_save_password).setOnClickListener(v -> {
|
||||
String newPass = editNewPassword.getText().toString();
|
||||
if (newPass.length() < 6) {
|
||||
Toast.makeText(getContext(), "Mínimo 6 caracteres.", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
// Preenchimento Seguro
|
||||
if (editName != null) editName.setText(currentUser.name);
|
||||
if (editAge != null) editAge.setText(String.valueOf(currentUser.age));
|
||||
if (editUtente != null) editUtente.setText(currentUser.utenteNumber);
|
||||
if (editEmail != null) editEmail.setText(currentUser.email);
|
||||
if (dialogImageView != null && currentUser.profilePictureUri != null) {
|
||||
loadSafeImage(dialogImageView, currentUser.profilePictureUri);
|
||||
}
|
||||
if (auth.getCurrentUser() != null) {
|
||||
auth.getCurrentUser().updatePassword(newPass).addOnCompleteListener(task -> {
|
||||
if (task.isSuccessful()) {
|
||||
Toast.makeText(getContext(), "Sucesso!", Toast.LENGTH_SHORT).show();
|
||||
dialog.dismiss();
|
||||
|
||||
// Listeners
|
||||
View btnPhoto = dialogView.findViewById(R.id.button_change_photo);
|
||||
if (btnPhoto != null) btnPhoto.setOnClickListener(v -> pickMedia.launch("image/*"));
|
||||
if (dialogImageView != null) dialogImageView.setOnClickListener(v -> pickMedia.launch("image/*"));
|
||||
|
||||
View btnPass = dialogView.findViewById(R.id.button_change_password);
|
||||
if (btnPass != null) btnPass.setOnClickListener(v -> showChangePasswordDialog());
|
||||
|
||||
View btnCancel = dialogView.findViewById(R.id.button_cancel);
|
||||
if (btnCancel != null) btnCancel.setOnClickListener(v -> dialog.dismiss());
|
||||
|
||||
View btnSave = dialogView.findViewById(R.id.button_save);
|
||||
if (btnSave != null) {
|
||||
btnSave.setOnClickListener(v -> {
|
||||
btnSave.setEnabled(false);
|
||||
if (tempProfileUri != null) {
|
||||
uploadPhotoAndSave(editName.getText().toString(), editAge.getText().toString(), editUtente.getText().toString(), editEmail.getText().toString(), dialog);
|
||||
} else {
|
||||
Toast.makeText(getContext(), "Erro: " + task.getException().getMessage(), Toast.LENGTH_LONG).show();
|
||||
saveDataToFirestore(editName.getText().toString(), editAge.getText().toString(), editUtente.getText().toString(), editEmail.getText().toString(), currentUser.profilePictureUri, dialog);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
view.findViewById(R.id.button_cancel_password).setOnClickListener(v -> dialog.dismiss());
|
||||
dialog.show();
|
||||
dialog.show();
|
||||
} catch (Throwable t) {
|
||||
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() {
|
||||
Toast.makeText(getContext(), "Funcionalidade de Password em breve.", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
binding = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,128 +1,194 @@
|
||||
<?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"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_height="wrap_content"
|
||||
app:cardCornerRadius="28dp"
|
||||
app:cardElevation="0dp"
|
||||
android:layout_margin="12dp">
|
||||
|
||||
<LinearLayout
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
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
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Editar Dados"
|
||||
android:textSize="20sp"
|
||||
android:textStyle="bold"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginBottom="24dp"/>
|
||||
|
||||
<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_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="Nome"
|
||||
android:inputType="textPersonName" />
|
||||
</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"/>
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="end">
|
||||
android:orientation="vertical"
|
||||
android:padding="24dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Editar Perfil"
|
||||
android:textSize="22sp"
|
||||
android:textStyle="bold"
|
||||
android:textColor="?attr/colorPrimary"
|
||||
android:layout_gravity="center_horizontal"
|
||||
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
|
||||
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
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
|
||||
android:id="@+id/edit_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textPersonName" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
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_cancel"
|
||||
android:id="@+id/button_change_password"
|
||||
style="@style/Widget.MaterialComponents.Button.TextButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Cancelar"
|
||||
android:layout_marginEnd="8dp"/>
|
||||
android:text="Alterar Palavra-passe"
|
||||
android:textAllCaps="false"
|
||||
android:textColor="?attr/colorPrimary"
|
||||
android:layout_marginBottom="24dp"/>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/button_save"
|
||||
android:layout_width="wrap_content"
|
||||
<!-- Action Buttons -->
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Salvar" />
|
||||
android:orientation="horizontal">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/button_cancel"
|
||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="56dp"
|
||||
android:layout_weight="1"
|
||||
android:text="Cancelar"
|
||||
android:textAllCaps="false"
|
||||
android:layout_marginEnd="8dp"
|
||||
app:cornerRadius="16dp"
|
||||
app:strokeColor="?attr/colorPrimary"
|
||||
android:textColor="?attr/colorPrimary"/>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/button_save"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="56dp"
|
||||
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>
|
||||
</ScrollView>
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
</com.google.android.material.card.MaterialCardView>
|
||||
|
||||
@@ -6,51 +6,51 @@
|
||||
android:background="@color/background_color">
|
||||
|
||||
<!-- Header / Top Bar area -->
|
||||
<View
|
||||
<LinearLayout
|
||||
android:id="@+id/header_bg"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="160dp"
|
||||
android:background="@color/primary_color"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<com.google.android.material.imageview.ShapeableImageView
|
||||
android:id="@+id/image_profile_home"
|
||||
android:layout_width="64dp"
|
||||
android:layout_height="64dp"
|
||||
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
|
||||
android:id="@+id/text_greeting"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="24dp"
|
||||
android:text="Olá, utilizador!"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="26sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintBottom_toBottomOf="@id/image_profile_home"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/image_profile_home"
|
||||
app:layout_constraintTop_toTopOf="@id/image_profile_home" />
|
||||
android:orientation="horizontal"
|
||||
android:paddingTop="56dp"
|
||||
android:paddingBottom="40dp"
|
||||
android:paddingHorizontal="28dp"
|
||||
android:background="@drawable/bg_gradient_header"
|
||||
android:elevation="12dp"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/text_greeting"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="Olá"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="38sp"
|
||||
android:fontFamily="sans-serif-black"
|
||||
android:gravity="center_vertical" />
|
||||
|
||||
<com.google.android.material.imageview.ShapeableImageView
|
||||
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
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_marginTop="24dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:fillViewport="true"
|
||||
android:clipToPadding="false"
|
||||
android:paddingBottom="40dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/image_profile_home">
|
||||
app:layout_constraintTop_toBottomOf="@id/header_bg">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="24dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:gravity="center"
|
||||
android:background="@color/background_color">
|
||||
|
||||
<com.google.android.material.imageview.ShapeableImageView
|
||||
@@ -116,7 +116,6 @@
|
||||
android:backgroundTint="@color/secondary_color"/>
|
||||
|
||||
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/button_logout"
|
||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
||||
|
||||
@@ -37,4 +37,13 @@
|
||||
<style name="ShapeAppearanceOverlay.App.CornerSize50Percent" parent="">
|
||||
<item name="cornerSize">50%</item>
|
||||
</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>
|
||||
|
||||
Reference in New Issue
Block a user