esta guardar e nao esta a entar no perfil
This commit is contained in:
@@ -11,14 +11,33 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import com.google.ai.client.generativeai.type.BlockThreshold;
|
||||
import com.google.ai.client.generativeai.type.HarmCategory;
|
||||
import com.google.ai.client.generativeai.type.SafetySetting;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Collections;
|
||||
|
||||
public class Gemini {
|
||||
private final GenerativeModelFutures modelo;
|
||||
|
||||
public Gemini() {
|
||||
// 1. Configurar o modelo (usa a tua API Key do Google AI Studio)
|
||||
// 1. Configurar os SafetySettings para permitir termos médicos e partes do corpo
|
||||
List<SafetySetting> safetySettings = Arrays.asList(
|
||||
new SafetySetting(HarmCategory.HARASSMENT, BlockThreshold.NONE),
|
||||
new SafetySetting(HarmCategory.HATE_SPEECH, BlockThreshold.NONE),
|
||||
new SafetySetting(HarmCategory.SEXUALLY_EXPLICIT, BlockThreshold.NONE),
|
||||
new SafetySetting(HarmCategory.DANGEROUS_CONTENT, BlockThreshold.NONE)
|
||||
);
|
||||
|
||||
// 2. Configurar o modelo (usa a tua API Key do Google AI Studio)
|
||||
GenerativeModel generativeModel = new GenerativeModel(
|
||||
"gemini-2.5-flash",
|
||||
"AIzaSyBmLgn-SHaTDvAeDWsw2iTZRR9gahhOu7k");
|
||||
"AIzaSyBmLgn-SHaTDvAeDWsw2iTZRR9gahhOu7k",
|
||||
null, // generationConfig
|
||||
safetySettings
|
||||
);
|
||||
this.modelo = GenerativeModelFutures.from(generativeModel);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ public class ForgotPasswordActivity extends AppCompatActivity {
|
||||
setContentView(binding.getRoot());
|
||||
|
||||
binding.resetButton.setOnClickListener(v -> {
|
||||
String email = binding.emailEditText.getText().toString();
|
||||
String email = binding.emailEditText.getText().toString().trim();
|
||||
if (email.isEmpty()) {
|
||||
Toast.makeText(this, "Por favor insira o seu email.", Toast.LENGTH_SHORT).show();
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.example.cuida.ui.auth;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.example.cuida.databinding.ActivityResetPasswordBinding;
|
||||
import com.google.firebase.auth.FirebaseAuth;
|
||||
|
||||
public class ResetPasswordActivity extends AppCompatActivity {
|
||||
|
||||
private ActivityResetPasswordBinding binding;
|
||||
private String oobCode;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
binding = ActivityResetPasswordBinding.inflate(getLayoutInflater());
|
||||
setContentView(binding.getRoot());
|
||||
|
||||
// Use custom uri scheme or https scheme, extracting oobCode parameter
|
||||
Intent intent = getIntent();
|
||||
if (intent != null && intent.getData() != null) {
|
||||
Uri data = intent.getData();
|
||||
oobCode = data.getQueryParameter("oobCode");
|
||||
|
||||
if (oobCode == null || oobCode.isEmpty()) {
|
||||
Toast.makeText(this, "Link de redefinição inválido.", Toast.LENGTH_LONG).show();
|
||||
finish();
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(this, "Nenhum código de redefinição encontrado.", Toast.LENGTH_LONG).show();
|
||||
finish();
|
||||
}
|
||||
|
||||
binding.saveNewPasswordButton.setOnClickListener(v -> saveNewPassword());
|
||||
}
|
||||
|
||||
private void saveNewPassword() {
|
||||
String newPassword = binding.newPasswordEditText.getText().toString();
|
||||
String confirmPassword = binding.confirmNewPasswordEditText.getText().toString();
|
||||
|
||||
if (newPassword.isEmpty() || confirmPassword.isEmpty()) {
|
||||
Toast.makeText(this, "Preencha ambas as palavras-passe.", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!newPassword.equals(confirmPassword)) {
|
||||
Toast.makeText(this, "As palavras-passe não coincidem.", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (newPassword.length() < 6) {
|
||||
Toast.makeText(this, "A palavra-passe deve ter pelo menos 6 caracteres.", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
binding.saveNewPasswordButton.setEnabled(false);
|
||||
binding.saveNewPasswordButton.setText("A guardar...");
|
||||
|
||||
FirebaseAuth.getInstance().confirmPasswordReset(oobCode, newPassword)
|
||||
.addOnCompleteListener(task -> {
|
||||
if (task.isSuccessful()) {
|
||||
Toast.makeText(this, "Palavra-passe atualizada com sucesso!", Toast.LENGTH_LONG).show();
|
||||
// Go back to login screen
|
||||
Intent intent = new Intent(ResetPasswordActivity.this, LoginActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(intent);
|
||||
finish();
|
||||
} else {
|
||||
binding.saveNewPasswordButton.setEnabled(true);
|
||||
binding.saveNewPasswordButton.setText("Guardar Palavra-passe");
|
||||
|
||||
String errorMsg = task.getException() != null ? task.getException().getMessage() : "Erro desconhecido";
|
||||
Toast.makeText(this, "Erro: " + errorMsg, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ public class HomeFragment extends Fragment {
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
binding = FragmentHomeBinding.inflate(inflater, container, false);
|
||||
|
||||
// --- Greeting ---
|
||||
// --- Greeting & Profile Picture ---
|
||||
com.google.firebase.auth.FirebaseAuth auth = com.google.firebase.auth.FirebaseAuth.getInstance();
|
||||
if (auth.getCurrentUser() != null) {
|
||||
String userId = auth.getCurrentUser().getUid();
|
||||
@@ -42,6 +42,16 @@ public class HomeFragment extends Fragment {
|
||||
} else {
|
||||
binding.textGreeting.setText("Olá, Utilizador!");
|
||||
}
|
||||
|
||||
// Load Profile Picture
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.addOnFailureListener(e -> {
|
||||
|
||||
@@ -59,9 +59,9 @@ public class Sns24Fragment extends Fragment {
|
||||
com.example.cuida.services.Gemini gemini = new com.example.cuida.services.Gemini();
|
||||
String prompt = "Atua como um assistente de triagem médica. " +
|
||||
"Analisa os seguintes sintomas de um paciente e dá uma resposta MUITO CURTA e direta (máximo 2 a 3 frases). " +
|
||||
"Regra de Ouro: Se o paciente mencionar a palavra 'dor', deves avaliar a situação com muito cuidado, inclinando-te para a classificar como severa. " +
|
||||
"Se os sintomas indicarem uma situação grave, emergência ou necessidade de observação urgente de acordo com as tuas instruções, a tua resposta DEVE conter obrigatoriamente a palavra [GRAVE]. " +
|
||||
"Recomenda sempre qual o próximo passo (ex: urgências, SNS 24, consulta). " +
|
||||
"Tem bom senso e calma na avaliação: não assumas automaticamente que os sintomas são severos sem analisar todo o contexto. Evita ser alarmista desnecessariamente. " +
|
||||
"Apenas se os sintomas indicarem uma situação de verdadeira emergência ou necessidade indiscutível de observação médica urgente, a tua resposta DEVE conter obrigatoriamente a palavra [GRAVE]. " +
|
||||
"Recomenda sempre qual o próximo passo adequado (ex: repouso, farmácia, médico, SNS 24, ou urgências). " +
|
||||
"Sintomas: " + symptoms;
|
||||
|
||||
gemini.fazerPergunta(prompt, new com.example.cuida.services.Gemini.GeminiCallback() {
|
||||
|
||||
Reference in New Issue
Block a user