ia
This commit is contained in:
@@ -59,6 +59,9 @@ public class TelaInicialActivity extends AppCompatActivity {
|
||||
|
||||
private String[] meses = {"Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro"};
|
||||
|
||||
private androidx.activity.result.ActivityResultLauncher<android.net.Uri> takePictureLauncher;
|
||||
private android.net.Uri currentPhotoUri;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@@ -70,7 +73,18 @@ public class TelaInicialActivity extends AppCompatActivity {
|
||||
return insets;
|
||||
});
|
||||
|
||||
|
||||
takePictureLauncher = registerForActivityResult(
|
||||
new androidx.activity.result.contract.ActivityResultContracts.TakePicture(),
|
||||
success -> {
|
||||
if (success) {
|
||||
processInvoiceImage(currentPhotoUri);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
com.google.android.material.floatingactionbutton.FloatingActionButton fabScanInvoice = findViewById(R.id.fabScanInvoice);
|
||||
fabScanInvoice.setOnClickListener(v -> startInvoiceScan());
|
||||
|
||||
ivHeaderProfilePicture = findViewById(R.id.ivHeaderProfilePicture);
|
||||
tvHeaderUsername = findViewById(R.id.tvHeaderUsername);
|
||||
|
||||
@@ -141,6 +155,55 @@ public class TelaInicialActivity extends AppCompatActivity {
|
||||
startActivity(intent);
|
||||
});
|
||||
}
|
||||
|
||||
public void startInvoiceScan() {
|
||||
java.io.File photoFile = new java.io.File(getFilesDir(), "invoice_" + System.currentTimeMillis() + ".jpg");
|
||||
currentPhotoUri = androidx.core.content.FileProvider.getUriForFile(this, getPackageName() + ".fileprovider", photoFile);
|
||||
takePictureLauncher.launch(currentPhotoUri);
|
||||
}
|
||||
|
||||
private void processInvoiceImage(android.net.Uri imageUri) {
|
||||
Toast.makeText(this, "A processar fatura com IA...", Toast.LENGTH_LONG).show();
|
||||
InvoiceScannerHelper.scanInvoice(this, imageUri, new InvoiceScannerHelper.ScanCallback() {
|
||||
@Override
|
||||
public void onSuccess(double valor, String descricao, String categoria, String data) {
|
||||
runOnUiThread(() -> {
|
||||
Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.fragmentContainerView);
|
||||
TransacoesFragment transFragment;
|
||||
if (currentFragment instanceof TransacoesFragment) {
|
||||
transFragment = (TransacoesFragment) currentFragment;
|
||||
} else {
|
||||
updateNavSelection(findViewById(R.id.carteiraImageView));
|
||||
transFragment = new TransacoesFragment();
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.replace(R.id.fragmentContainerView, transFragment)
|
||||
.commit();
|
||||
getSupportFragmentManager().executePendingTransactions();
|
||||
}
|
||||
transFragment.showNovaTransacaoDialog(valor, descricao, categoria, data);
|
||||
|
||||
// Save document to shared preferences or database
|
||||
saveDocument(imageUri.toString(), descricao, data);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(String error) {
|
||||
runOnUiThread(() -> Toast.makeText(TelaInicialActivity.this, error, Toast.LENGTH_LONG).show());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void saveDocument(String uriString, String descricao, String data) {
|
||||
SharedPreferences prefs = getSharedPreferences("LifeGridDocs", Context.MODE_PRIVATE);
|
||||
int count = prefs.getInt("doc_count", 0);
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putString("doc_uri_" + count, uriString);
|
||||
editor.putString("doc_desc_" + count, descricao);
|
||||
editor.putString("doc_data_" + count, data);
|
||||
editor.putInt("doc_count", count + 1);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
|
||||
Reference in New Issue
Block a user