corrigir os novos erros amnhã e adicionar qual tipo de sexo a pessoa é no register
This commit is contained in:
@@ -158,28 +158,31 @@ public class FotoActivity extends AppCompatActivity {
|
||||
});
|
||||
}
|
||||
|
||||
// Função que "lê" a resposta da IA e guarda os números
|
||||
// Função que "lê" a resposta da IA e guarda os números E A DICA
|
||||
private void extrairEGuardarDados(String texto) {
|
||||
try {
|
||||
// Apanhar o Nome do prato (tudo o que está a seguir a "Prato: " até à próxima linha)
|
||||
int indexNomeStart = texto.indexOf("Prato: ") + 7;
|
||||
int indexNomeEnd = texto.indexOf("\n", indexNomeStart);
|
||||
String nomePrato = texto.substring(indexNomeStart, indexNomeEnd).trim();
|
||||
|
||||
// Apanhar os números
|
||||
int calorias = extrairNumero(texto, "Calorias: ", " kcal");
|
||||
int proteina = extrairNumero(texto, "Macros: ", "g Proteína");
|
||||
int hidratos = extrairNumero(texto, "Proteína, ", "g Hidratos");
|
||||
int gordura = extrairNumero(texto, "Hidratos, ", "g Gordura");
|
||||
|
||||
// Abrir a memória
|
||||
// EXTRAIR A DICA DA IA
|
||||
String dicaIA = "Continua a registar refeições para ver dicas.";
|
||||
if (texto.contains("Dica: ")) {
|
||||
int indexDica = texto.indexOf("Dica: ") + 6;
|
||||
dicaIA = texto.substring(indexDica).trim();
|
||||
}
|
||||
|
||||
SharedPreferences prefs = getSharedPreferences("DadosSaude", MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
|
||||
// Guardar nome do último prato
|
||||
editor.putString("ultimo_prato", nomePrato);
|
||||
editor.putString("ultima_dica_ia", dicaIA); // Guarda a dica
|
||||
|
||||
// Somar aos valores do dia
|
||||
editor.putInt("cal_hoje", prefs.getInt("cal_hoje", 0) + calorias);
|
||||
editor.putInt("prot_hoje", prefs.getInt("prot_hoje", 0) + proteina);
|
||||
editor.putInt("hidr_hoje", prefs.getInt("hidr_hoje", 0) + hidratos);
|
||||
@@ -191,17 +194,15 @@ public class FotoActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
// Ferramenta que corta a fatia certa de texto para tirar os números
|
||||
private int extrairNumero(String texto, String inicio, String fim) {
|
||||
try {
|
||||
int start = texto.indexOf(inicio) + inicio.length();
|
||||
int end = texto.indexOf(fim, start);
|
||||
String valorString = texto.substring(start, end).trim();
|
||||
// Limpa tudo o que não for número (caso a IA escreva mal)
|
||||
valorString = valorString.replaceAll("[^0-9]", "");
|
||||
return Integer.parseInt(valorString);
|
||||
} catch (Exception e) {
|
||||
return 0; // Se não encontrar, assume 0
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user