antes do ollama

This commit is contained in:
2026-06-18 11:15:49 +01:00
parent 04ce7ece4f
commit 55560a1bfb
4 changed files with 21 additions and 13 deletions

View File

@@ -4,10 +4,10 @@
<selectionStates> <selectionStates>
<SelectionState runConfigName="app"> <SelectionState runConfigName="app">
<option name="selectionMode" value="DROPDOWN" /> <option name="selectionMode" value="DROPDOWN" />
<DropdownSelection timestamp="2026-06-03T14:39:06.554406Z"> <DropdownSelection timestamp="2026-06-18T10:01:02.387533Z">
<Target type="DEFAULT_BOOT"> <Target type="DEFAULT_BOOT">
<handle> <handle>
<DeviceId pluginId="LocalEmulator" identifier="path=/Users/230415/.android/avd/Pixel_9a.avd" /> <DeviceId pluginId="PhysicalDevice" identifier="serial=RZCX40Q6DDY" />
</handle> </handle>
</Target> </Target>
</DropdownSelection> </DropdownSelection>

View File

@@ -47,7 +47,7 @@ public class InvoiceScannerHelper {
} }
GenerativeModel gm = new GenerativeModel( GenerativeModel gm = new GenerativeModel(
"gemini-2.5-flash", "gemini-1.5-flash",
API_KEY API_KEY
); );
GenerativeModelFutures model = GenerativeModelFutures.from(gm); GenerativeModelFutures model = GenerativeModelFutures.from(gm);
@@ -65,13 +65,19 @@ public class InvoiceScannerHelper {
try { try {
String textResponse = result.getText(); String textResponse = result.getText();
if (textResponse != null) { if (textResponse != null) {
textResponse = textResponse.replace("```json", "").replace("```", "").trim(); int start = textResponse.indexOf("{");
JSONObject json = new JSONObject(textResponse); int end = textResponse.lastIndexOf("}");
if (start != -1 && end != -1 && end > start) {
String jsonContent = textResponse.substring(start, end + 1);
JSONObject json = new JSONObject(jsonContent);
double valor = json.optDouble("valor", 0.0); double valor = json.optDouble("valor", 0.0);
String descricao = json.optString("descricao", ""); String descricao = json.optString("descricao", "");
String categoria = json.optString("categoria", "Outros"); String categoria = json.optString("categoria", "Outros");
String data = json.optString("data", ""); String data = json.optString("data", "");
callback.onSuccess(valor, descricao, categoria, data); callback.onSuccess(valor, descricao, categoria, data);
} else {
callback.onError("Não foi possível extrair os dados formatados em JSON.");
}
} else { } else {
callback.onError("Resposta vazia da IA."); callback.onError("Resposta vazia da IA.");
} }

View File

@@ -7,7 +7,7 @@
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/adicionarCardView" android:id="@+id/adicionarCardView"
android:layout_width="364dp" android:layout_width="391dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginTop="544dp" android:layout_marginTop="544dp"
android:background="@drawable/cardview_background" android:background="@drawable/cardview_background"

View File

@@ -54,18 +54,19 @@
tools:text="Criptomoedas" /> tools:text="Criptomoedas" />
<!-- Quantity and Purchase Price --> <!-- Quantity and Purchase Price -->
<!-- Delete Button -->
<TextView <TextView
android:id="@+id/tvInfo" android:id="@+id/tvInfo"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="4dp" android:layout_marginTop="12dp"
android:textColor="#6b7280" android:textColor="#6b7280"
android:textSize="14sp" android:textSize="14sp"
app:layout_constraintStart_toStartOf="@id/tvNome" app:layout_constraintStart_toStartOf="@id/tvNome"
app:layout_constraintTop_toBottomOf="@id/tvTipo" app:layout_constraintTop_toBottomOf="@id/tvTipo"
tools:text="12 unidades x 16.10€" /> tools:text="12 unidades x 16.10€" />
<!-- Delete Button -->
<ImageView <ImageView
android:id="@+id/btnDelete" android:id="@+id/btnDelete"
android:layout_width="28dp" android:layout_width="28dp"
@@ -111,6 +112,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="2dp" android:layout_marginTop="2dp"
android:layout_marginEnd="8dp"
android:textColor="#16a34a" android:textColor="#16a34a"
android:textSize="14sp" android:textSize="14sp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"