depois do ollama
This commit is contained in:
@@ -112,13 +112,7 @@ public class DefinicoesActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
TextView tvDocuments = findViewById(R.id.tvDocuments);
|
||||
if (tvDocuments != null) {
|
||||
tvDocuments.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(DefinicoesActivity.this, DocumentosActivity.class);
|
||||
startActivity(intent);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
TextView tvTerms = findViewById(R.id.tvTerms);
|
||||
if (tvTerms != null) {
|
||||
|
||||
@@ -175,49 +175,26 @@ public class TelaInicialActivity extends AppCompatActivity {
|
||||
}
|
||||
transFragment.showNovaTransacaoDialog(valor, descricao, categoria, data);
|
||||
|
||||
// Save document to Firebase
|
||||
uploadDocumentoToFirebase(imageUri, descricao, data);
|
||||
deleteLocalInvoiceFile(imageUri);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String error) {
|
||||
runOnUiThread(() -> CustomToast.error(TelaInicialActivity.this, error));
|
||||
runOnUiThread(() -> {
|
||||
CustomToast.error(TelaInicialActivity.this, error);
|
||||
deleteLocalInvoiceFile(imageUri);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void uploadDocumentoToFirebase(android.net.Uri imageUri, String descricao, String data) {
|
||||
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
|
||||
if (user == null) {
|
||||
CustomToast.error(this, "Utilizador não autenticado.");
|
||||
return;
|
||||
private void deleteLocalInvoiceFile(android.net.Uri uri) {
|
||||
try {
|
||||
getContentResolver().delete(uri, null, null);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
CustomToast.info(this, "A guardar documento na Cloud...");
|
||||
|
||||
String fileName = "invoice_" + System.currentTimeMillis() + ".jpg";
|
||||
com.google.firebase.storage.StorageReference storageRef = com.google.firebase.storage.FirebaseStorage.getInstance().getReference()
|
||||
.child("users/" + user.getUid() + "/documentos/" + fileName);
|
||||
|
||||
storageRef.putFile(imageUri).addOnSuccessListener(taskSnapshot -> {
|
||||
storageRef.getDownloadUrl().addOnSuccessListener(uri -> {
|
||||
String downloadUrl = uri.toString();
|
||||
DatabaseReference dbRef = FirebaseDatabase.getInstance().getReference("users")
|
||||
.child(user.getUid()).child("documentos").push();
|
||||
|
||||
com.example.lifegrid.models.Documento doc = new com.example.lifegrid.models.Documento(descricao, data, downloadUrl);
|
||||
dbRef.setValue(doc).addOnCompleteListener(task -> {
|
||||
if (task.isSuccessful()) {
|
||||
CustomToast.success(TelaInicialActivity.this, "Documento guardado com sucesso!");
|
||||
} else {
|
||||
CustomToast.error(TelaInicialActivity.this, "Erro ao guardar dados na Cloud.");
|
||||
}
|
||||
});
|
||||
});
|
||||
}).addOnFailureListener(e -> {
|
||||
CustomToast.error(this, "Erro ao enviar imagem para a Cloud.");
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -196,21 +196,6 @@
|
||||
android:padding="16dp"
|
||||
android:layout_marginBottom="32dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvDocuments"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Meus Documentos (Faturas)"
|
||||
android:textColor="@color/preto"
|
||||
android:textSize="16sp"
|
||||
android:textStyle="bold"
|
||||
android:paddingVertical="8dp" />
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="#E0E0E0"
|
||||
android:layout_marginVertical="4dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvTerms"
|
||||
|
||||
Reference in New Issue
Block a user