tou a editar o perfil e deixar a pp mais bonita
This commit is contained in:
@@ -10,9 +10,9 @@
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
android:icon="@drawable/ic_logo"
|
||||
android:icon="@drawable/ic_launcher_final"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@drawable/ic_logo"
|
||||
android:roundIcon="@drawable/ic_launcher_final"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.Cuida"
|
||||
tools:targetApi="31">
|
||||
|
||||
@@ -13,6 +13,7 @@ public class User {
|
||||
public String password;
|
||||
public int age;
|
||||
public String utenteNumber;
|
||||
public String profilePictureUri;
|
||||
|
||||
public User(String name, String email, String password, int age, String utenteNumber) {
|
||||
this.name = name;
|
||||
|
||||
@@ -59,15 +59,47 @@ public class ProfileFragment extends Fragment {
|
||||
binding.profileEmail.setText(currentUser.email);
|
||||
binding.profileAge.setText(String.valueOf(currentUser.age));
|
||||
binding.profileUtente.setText(currentUser.utenteNumber != null ? currentUser.utenteNumber : "N/A");
|
||||
if (currentUser.profilePictureUri != null) {
|
||||
android.widget.ImageView profileImage = binding.getRoot().findViewById(R.id.profile_image);
|
||||
if (profileImage != null) {
|
||||
try {
|
||||
profileImage.setImageURI(android.net.Uri.parse(currentUser.profilePictureUri));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private android.net.Uri tempProfileUri;
|
||||
private android.widget.ImageView dialogImageView;
|
||||
|
||||
private final androidx.activity.result.ActivityResultLauncher<String> pickMedia = registerForActivityResult(
|
||||
new androidx.activity.result.contract.ActivityResultContracts.GetContent(), uri -> {
|
||||
if (uri != null) {
|
||||
tempProfileUri = uri;
|
||||
try {
|
||||
requireContext().getContentResolver().takePersistableUriPermission(uri,
|
||||
Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (dialogImageView != null) {
|
||||
dialogImageView.setImageURI(uri);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
private void showEditDialog() {
|
||||
if (currentUser == null)
|
||||
return;
|
||||
|
||||
// Reset temp uri
|
||||
tempProfileUri = null;
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||
|
||||
// Inflate custom layout
|
||||
@@ -81,8 +113,10 @@ public class ProfileFragment extends Fragment {
|
||||
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);
|
||||
EditText editPassword = dialogView.findViewById(R.id.edit_password);
|
||||
dialogImageView = dialogView.findViewById(R.id.edit_profile_image);
|
||||
View btnChangePassword = dialogView.findViewById(R.id.button_change_password);
|
||||
View btnSave = dialogView.findViewById(R.id.button_save);
|
||||
View btnCancel = dialogView.findViewById(R.id.button_cancel);
|
||||
|
||||
@@ -91,17 +125,24 @@ public class ProfileFragment extends Fragment {
|
||||
editAge.setText(String.valueOf(currentUser.age));
|
||||
editUtente.setText(currentUser.utenteNumber);
|
||||
editEmail.setText(currentUser.email);
|
||||
editPassword.setText(currentUser.password);
|
||||
|
||||
if (currentUser.profilePictureUri != null) {
|
||||
dialogImageView.setImageURI(android.net.Uri.parse(currentUser.profilePictureUri));
|
||||
}
|
||||
|
||||
dialogImageView.setOnClickListener(v -> pickMedia.launch("image/*"));
|
||||
|
||||
btnChangePassword.setOnClickListener(v -> {
|
||||
showChangePasswordDialog();
|
||||
});
|
||||
|
||||
btnSave.setOnClickListener(v -> {
|
||||
String newName = editName.getText().toString();
|
||||
String ageStr = editAge.getText().toString();
|
||||
String newUtente = editUtente.getText().toString();
|
||||
String newEmail = editEmail.getText().toString();
|
||||
String newPassword = editPassword.getText().toString();
|
||||
|
||||
if (newName.isEmpty() || ageStr.isEmpty() || newUtente.isEmpty() || newEmail.isEmpty()
|
||||
|| newPassword.isEmpty()) {
|
||||
if (newName.isEmpty() || ageStr.isEmpty() || newUtente.isEmpty() || newEmail.isEmpty()) {
|
||||
Toast.makeText(getContext(), "Preencha todos os campos", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
@@ -113,7 +154,10 @@ public class ProfileFragment extends Fragment {
|
||||
currentUser.age = newAge;
|
||||
currentUser.utenteNumber = newUtente;
|
||||
currentUser.email = newEmail;
|
||||
currentUser.password = newPassword;
|
||||
// Password not updated here
|
||||
if (tempProfileUri != null) {
|
||||
currentUser.profilePictureUri = tempProfileUri.toString();
|
||||
}
|
||||
|
||||
AppDatabase.databaseWriteExecutor.execute(() -> {
|
||||
userDao.insert(currentUser);
|
||||
@@ -128,17 +172,52 @@ public class ProfileFragment extends Fragment {
|
||||
}
|
||||
|
||||
// UI update
|
||||
binding.profileName.setText(newName);
|
||||
binding.profileEmail.setText(newEmail);
|
||||
binding.profileAge.setText(String.valueOf(newAge));
|
||||
binding.profileUtente.setText(newUtente);
|
||||
loadUserData(); // Reload to show new image and data
|
||||
|
||||
Toast.makeText(getContext(), "Dados atualizados com sucesso!", Toast.LENGTH_SHORT).show();
|
||||
dialog.dismiss();
|
||||
dialogImageView = null; // Clear reference
|
||||
});
|
||||
|
||||
btnCancel.setOnClickListener(v -> {
|
||||
dialog.dismiss();
|
||||
dialogImageView = null;
|
||||
});
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
private void showChangePasswordDialog() {
|
||||
if (currentUser == null)
|
||||
return;
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
|
||||
LayoutInflater inflater = requireActivity().getLayoutInflater();
|
||||
View dialogView = inflater.inflate(R.layout.dialog_change_password, null);
|
||||
builder.setView(dialogView);
|
||||
AlertDialog dialog = builder.create();
|
||||
|
||||
EditText editNewPassword = dialogView.findViewById(R.id.new_password);
|
||||
View btnSave = dialogView.findViewById(R.id.button_save_password);
|
||||
View btnCancel = dialogView.findViewById(R.id.button_cancel_password);
|
||||
|
||||
btnSave.setOnClickListener(v -> {
|
||||
String newPass = editNewPassword.getText().toString();
|
||||
if (newPass.isEmpty()) {
|
||||
Toast.makeText(getContext(), "Insira a nova palavra-passe", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
currentUser.password = newPass;
|
||||
AppDatabase.databaseWriteExecutor.execute(() -> {
|
||||
userDao.insert(currentUser);
|
||||
});
|
||||
|
||||
Toast.makeText(getContext(), "Palavra-passe alterada!", Toast.LENGTH_SHORT).show();
|
||||
dialog.dismiss();
|
||||
});
|
||||
|
||||
btnCancel.setOnClickListener(v -> dialog.dismiss());
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1017 KiB After Width: | Height: | Size: 82 KiB |
@@ -8,8 +8,8 @@
|
||||
android:background="@color/background_color">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="160dp"
|
||||
android:layout_height="160dp"
|
||||
android:layout_width="187dp"
|
||||
android:layout_height="177dp"
|
||||
android:layout_marginBottom="24dp"
|
||||
android:scaleType="centerCrop"
|
||||
android:src="@drawable/ic_logo" />
|
||||
|
||||
@@ -14,8 +14,8 @@
|
||||
android:padding="24dp">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="139dp"
|
||||
android:layout_height="129dp"
|
||||
android:layout_width="161dp"
|
||||
android:layout_height="160dp"
|
||||
android:layout_marginBottom="32dp"
|
||||
android:contentDescription="@string/app_name"
|
||||
android:src="@drawable/ic_logo" />
|
||||
@@ -54,6 +54,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/email_hint"
|
||||
android:autofillHints="emailAddress"
|
||||
android:inputType="textEmailAddress" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
@@ -68,6 +69,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/password_hint"
|
||||
android:autofillHints="password"
|
||||
android:inputType="textPassword" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
android:padding="24dp">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="120dp"
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="200dp"
|
||||
android:layout_marginBottom="24dp"
|
||||
android:src="@drawable/ic_logo"
|
||||
android:contentDescription="@string/app_name" />
|
||||
android:contentDescription="@string/app_name"
|
||||
android:src="@drawable/ic_logo" />
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
android:layout_width="match_parent"
|
||||
@@ -105,6 +105,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/email_hint"
|
||||
android:autofillHints="emailAddress"
|
||||
android:inputType="textEmailAddress" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
@@ -119,6 +120,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="@string/password_hint"
|
||||
android:autofillHints="password"
|
||||
android:inputType="textPassword" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
|
||||
@@ -9,6 +9,16 @@
|
||||
android:orientation="vertical"
|
||||
android:padding="24dp">
|
||||
|
||||
<ImageView
|
||||
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="16dp"
|
||||
android:clickable="true"
|
||||
android:focusable="true"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
@@ -60,7 +70,7 @@
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp">
|
||||
android:layout_marginBottom="24dp">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/edit_email"
|
||||
@@ -70,18 +80,14 @@
|
||||
android:inputType="textEmailAddress" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
||||
<com.google.android.material.textfield.TextInputLayout
|
||||
android:layout_width="match_parent"
|
||||
<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_marginBottom="24dp">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
android:id="@+id/edit_password"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="Nova Palavra-Passe"
|
||||
android:inputType="textPassword" />
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:text="Alterar Palavra-passe"
|
||||
android:layout_marginBottom="24dp"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -9,9 +9,10 @@
|
||||
android:background="@color/background_color">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/profile_image"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
android:src="@drawable/ic_logo"
|
||||
android:src="@drawable/ic_placeholder"
|
||||
android:layout_marginBottom="24dp"/>
|
||||
|
||||
<com.google.android.material.card.MaterialCardView
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
<string name="forgot_password">Esqueci-me da Palavra-passe</string>
|
||||
<string name="email_hint">Email</string>
|
||||
<string name="password_hint">Palavra-passe</string>
|
||||
<string name="name_hint">Nome</string>
|
||||
<string name="name_hint">Nome Completo</string>
|
||||
<string name="age_hint">Idade</string>
|
||||
<string name="login_button">Entrar</string>
|
||||
<string name="register_button">Registar</string>
|
||||
|
||||
Reference in New Issue
Block a user