correçao de pequenos erros e bugs , mudei opção de navegação e alterações no login
This commit is contained in:
@@ -83,10 +83,7 @@ public class CriarContaActivity extends AppCompatActivity {
|
||||
finish();
|
||||
}
|
||||
} else {
|
||||
String errorMessage = "Erro ao criar conta!";
|
||||
if (task.getException() != null && task.getException().getMessage() != null) {
|
||||
errorMessage = "Erro: " + task.getException().getMessage();
|
||||
}
|
||||
String errorMessage = com.example.vdcscore.utils.FirebaseErrorUtils.getErrorMessagePt(task.getException());
|
||||
Toast.makeText(CriarContaActivity.this, errorMessage, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
|
||||
@@ -124,10 +124,7 @@ public class LoginActivity extends AppCompatActivity {
|
||||
finish();
|
||||
|
||||
} else {
|
||||
String errorMessage = "Erro ao fazer login!";
|
||||
if (task.getException() != null && task.getException().getMessage() != null) {
|
||||
errorMessage = "Erro: " + task.getException().getMessage();
|
||||
}
|
||||
String errorMessage = com.example.vdcscore.utils.FirebaseErrorUtils.getErrorMessagePt(task.getException());
|
||||
Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -59,10 +59,7 @@ public class RecuperarPasswordActivity extends AppCompatActivity {
|
||||
Toast.LENGTH_LONG).show();
|
||||
voltarLogin();
|
||||
} else {
|
||||
String errorMessage = "Erro ao enviar email de recuperação!";
|
||||
if (task.getException() != null && task.getException().getMessage() != null) {
|
||||
errorMessage = "Erro: " + task.getException().getMessage();
|
||||
}
|
||||
String errorMessage = com.example.vdcscore.utils.FirebaseErrorUtils.getErrorMessagePt(task.getException());
|
||||
Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -134,21 +134,12 @@ public class ContaActivity extends AppCompatActivity {
|
||||
if (result.getResultCode() == RESULT_OK && result.getData() != null) {
|
||||
selectedImageUri = result.getData().getData();
|
||||
if (selectedImageUri != null) {
|
||||
try {
|
||||
InputStream inputStream = getContentResolver().openInputStream(selectedImageUri);
|
||||
if (inputStream != null) {
|
||||
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
|
||||
inputStream.close();
|
||||
if (bitmap != null) {
|
||||
imageProfile.setImageBitmap(bitmap);
|
||||
// Não fazemos upload até clicar em Gravar
|
||||
} else {
|
||||
Toast.makeText(this, "Erro ao carregar imagem", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(this, "Erro ao carregar imagem: " + e.getMessage(), Toast.LENGTH_SHORT)
|
||||
.show();
|
||||
if (imageProfile != null) {
|
||||
imageProfile.setImageTintList(null);
|
||||
Glide.with(this)
|
||||
.load(selectedImageUri)
|
||||
.circleCrop()
|
||||
.into(imageProfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -195,6 +186,7 @@ public class ContaActivity extends AppCompatActivity {
|
||||
|
||||
private void loadProfileImage(String imageUrl) {
|
||||
if (imageUrl == null || imageProfile == null) return;
|
||||
imageProfile.setImageTintList(null);
|
||||
Glide.with(this)
|
||||
.load(imageUrl)
|
||||
.placeholder(R.mipmap.ic_launcher_round)
|
||||
@@ -227,7 +219,7 @@ public class ContaActivity extends AppCompatActivity {
|
||||
btnSaveAll.setOnClickListener(v -> saveAllChanges());
|
||||
}
|
||||
if (btnChangeEmail != null) {
|
||||
btnChangeEmail.setOnClickListener(v -> sendEmailVerificationForEmailChange());
|
||||
btnChangeEmail.setOnClickListener(v -> showChangeEmailDialog());
|
||||
}
|
||||
if (btnChangePassword != null) {
|
||||
btnChangePassword.setOnClickListener(v -> sendPasswordResetEmail());
|
||||
@@ -295,9 +287,8 @@ public class ContaActivity extends AppCompatActivity {
|
||||
if (task.isSuccessful()) {
|
||||
Toast.makeText(this, "Alterações guardadas com sucesso!", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
Toast.makeText(this, "Erro ao guardar alterações: " +
|
||||
(task.getException() != null ? task.getException().getMessage() : "Erro desconhecido"),
|
||||
Toast.LENGTH_SHORT).show();
|
||||
String error = com.example.vdcscore.utils.FirebaseErrorUtils.getErrorMessagePt(task.getException());
|
||||
Toast.makeText(this, "Erro ao guardar alterações: " + error, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -394,51 +385,86 @@ public class ContaActivity extends AppCompatActivity {
|
||||
"Email de alteração de password enviado! Verifique a sua caixa de entrada.",
|
||||
Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
String errorMessage = "Erro ao enviar email!";
|
||||
if (task.getException() != null && task.getException().getMessage() != null) {
|
||||
errorMessage = "Erro: " + task.getException().getMessage();
|
||||
}
|
||||
String errorMessage = com.example.vdcscore.utils.FirebaseErrorUtils.getErrorMessagePt(task.getException());
|
||||
Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void sendEmailVerificationForEmailChange() {
|
||||
private void showChangeEmailDialog() {
|
||||
FirebaseUser user = mAuth.getCurrentUser();
|
||||
if (user == null || user.getEmail() == null) {
|
||||
if (user == null) {
|
||||
Toast.makeText(this, "Utilizador não autenticado", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
progressDialog.show();
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle("Alterar Email");
|
||||
|
||||
// Enviar email de verificação para alterar email
|
||||
user.sendEmailVerification()
|
||||
final TextInputEditText input = new TextInputEditText(this);
|
||||
input.setInputType(android.text.InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
|
||||
input.setHint("Novo email");
|
||||
if (user.getEmail() != null) {
|
||||
input.setText(user.getEmail());
|
||||
}
|
||||
|
||||
android.widget.FrameLayout container = new android.widget.FrameLayout(this);
|
||||
android.widget.FrameLayout.LayoutParams params = new android.widget.FrameLayout.LayoutParams(
|
||||
android.view.ViewGroup.LayoutParams.MATCH_PARENT,
|
||||
android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
|
||||
int marginPx = (int) (20 * getResources().getDisplayMetrics().density);
|
||||
params.leftMargin = marginPx;
|
||||
params.rightMargin = marginPx;
|
||||
params.topMargin = marginPx;
|
||||
params.bottomMargin = marginPx;
|
||||
input.setLayoutParams(params);
|
||||
container.addView(input);
|
||||
builder.setView(container);
|
||||
|
||||
builder.setPositiveButton("Alterar", (dialog, which) -> {
|
||||
String newEmail = input.getText().toString().trim();
|
||||
if (newEmail.isEmpty()) {
|
||||
Toast.makeText(this, "O email não pode estar vazio", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
if (!android.util.Patterns.EMAIL_ADDRESS.matcher(newEmail).matches()) {
|
||||
Toast.makeText(this, "Email inválido", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
if (newEmail.equalsIgnoreCase(user.getEmail())) {
|
||||
Toast.makeText(this, "O novo email é igual ao atual", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
performEmailChange(newEmail);
|
||||
});
|
||||
builder.setNegativeButton("Cancelar", (dialog, which) -> dialog.cancel());
|
||||
builder.show();
|
||||
}
|
||||
|
||||
private void performEmailChange(String newEmail) {
|
||||
FirebaseUser user = mAuth.getCurrentUser();
|
||||
if (user == null) return;
|
||||
|
||||
progressDialog.show();
|
||||
user.verifyBeforeUpdateEmail(newEmail)
|
||||
.addOnCompleteListener(task -> {
|
||||
progressDialog.dismiss();
|
||||
if (task.isSuccessful()) {
|
||||
Toast.makeText(this,
|
||||
"Email de verificação enviado! Verifique a sua caixa de entrada para alterar o email.",
|
||||
"Email de verificação enviado para o novo endereço! Por favor verifique.",
|
||||
Toast.LENGTH_LONG).show();
|
||||
if (textEmail != null) {
|
||||
textEmail.setText(newEmail);
|
||||
}
|
||||
} else {
|
||||
// Se não conseguir enviar email de verificação, enviar email de reset de
|
||||
// password
|
||||
// que pode ser usado para alterar o email através do Firebase Console
|
||||
mAuth.sendPasswordResetEmail(user.getEmail())
|
||||
.addOnCompleteListener(resetTask -> {
|
||||
if (resetTask.isSuccessful()) {
|
||||
Toast.makeText(this,
|
||||
"Email enviado! Verifique a sua caixa de entrada para instruções de alteração.",
|
||||
Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
String errorMessage = "Erro ao enviar email!";
|
||||
if (resetTask.getException() != null
|
||||
&& resetTask.getException().getMessage() != null) {
|
||||
errorMessage = "Erro: " + resetTask.getException().getMessage();
|
||||
}
|
||||
Toast.makeText(this, errorMessage, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
if (task.getException() instanceof com.google.firebase.auth.FirebaseAuthRecentLoginRequiredException) {
|
||||
Toast.makeText(this,
|
||||
"Por segurança, precisa de terminar sessão e voltar a entrar antes de mudar o email.",
|
||||
Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
String error = com.example.vdcscore.utils.FirebaseErrorUtils.getErrorMessagePt(task.getException());
|
||||
Toast.makeText(this, "Erro ao alterar email: " + error, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -22,12 +22,27 @@
|
||||
android:id="@+id/logoImage"
|
||||
android:layout_width="64dp"
|
||||
android:layout_height="64dp"
|
||||
android:layout_marginTop="50dp"
|
||||
android:layout_marginTop="40dp"
|
||||
android:background="@drawable/brand_icon_bg"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<!-- App Name Title -->
|
||||
<TextView
|
||||
android:id="@+id/textAppName"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:text="VdcScore"
|
||||
android:textColor="@color/text_1"
|
||||
android:fontFamily="@font/font_bebas_neue"
|
||||
android:textSize="26sp"
|
||||
android:letterSpacing="0.06"
|
||||
app:layout_constraintTop_toBottomOf="@+id/logoImage"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<!-- Login Form Container -->
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -94,7 +94,8 @@
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:background="@drawable/bg_circle_light_gray"
|
||||
android:src="@android:drawable/ic_media_previous"
|
||||
android:foreground="?attr/selectableItemBackgroundBorderless"
|
||||
android:src="@drawable/ic_arrow_back"
|
||||
android:contentDescription="Anterior"
|
||||
app:tint="@color/text_2" />
|
||||
|
||||
@@ -115,7 +116,8 @@
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:background="@drawable/bg_circle_light_gray"
|
||||
android:src="@android:drawable/ic_media_next"
|
||||
android:foreground="?attr/selectableItemBackgroundBorderless"
|
||||
android:src="@drawable/ic_arrow_forward"
|
||||
android:contentDescription="Próxima"
|
||||
app:tint="@color/text_2" />
|
||||
</LinearLayout>
|
||||
|
||||
@@ -94,7 +94,8 @@
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:background="@drawable/bg_circle_light_gray"
|
||||
android:src="@android:drawable/ic_media_previous"
|
||||
android:foreground="?attr/selectableItemBackgroundBorderless"
|
||||
android:src="@drawable/ic_arrow_back"
|
||||
android:contentDescription="Anterior"
|
||||
app:tint="@color/text_2" />
|
||||
|
||||
@@ -115,7 +116,8 @@
|
||||
android:layout_width="36dp"
|
||||
android:layout_height="36dp"
|
||||
android:background="@drawable/bg_circle_light_gray"
|
||||
android:src="@android:drawable/ic_media_next"
|
||||
android:foreground="?attr/selectableItemBackgroundBorderless"
|
||||
android:src="@drawable/ic_arrow_forward"
|
||||
android:contentDescription="Próxima"
|
||||
app:tint="@color/text_2" />
|
||||
</LinearLayout>
|
||||
|
||||
@@ -122,7 +122,7 @@
|
||||
android:fontFamily="@font/font_ibm_plex_sans"
|
||||
android:text="Anterior"
|
||||
android:textColor="@color/brand"
|
||||
app:icon="@android:drawable/ic_media_previous"
|
||||
app:icon="@drawable/ic_arrow_back"
|
||||
app:iconTint="@color/brand" />
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
@@ -134,7 +134,7 @@
|
||||
android:fontFamily="@font/font_ibm_plex_sans"
|
||||
android:text="Próxima"
|
||||
android:textColor="@color/brand"
|
||||
app:icon="@android:drawable/ic_media_next"
|
||||
app:icon="@drawable/ic_arrow_forward"
|
||||
app:iconTint="@color/brand"
|
||||
app:iconGravity="end" />
|
||||
|
||||
|
||||
Reference in New Issue
Block a user