ia
This commit is contained in:
@@ -74,6 +74,15 @@ public class TransacoesFragment extends Fragment {
|
||||
Button novaTransacaoButton = root.findViewById(R.id.novaTransacaoButton);
|
||||
novaTransacaoButton.setOnClickListener(v -> showNovaTransacaoDialog());
|
||||
|
||||
Button escanearTransacaoButton = root.findViewById(R.id.escanearTransacaoButton);
|
||||
if (escanearTransacaoButton != null) {
|
||||
escanearTransacaoButton.setOnClickListener(v -> {
|
||||
if (getActivity() instanceof com.example.lifegrid.TelaInicialActivity) {
|
||||
((com.example.lifegrid.TelaInicialActivity) getActivity()).startInvoiceScan();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
rvTransacoes = root.findViewById(R.id.rvTransacoes);
|
||||
tvEmptyState = root.findViewById(R.id.textView13);
|
||||
|
||||
@@ -136,11 +145,15 @@ public class TransacoesFragment extends Fragment {
|
||||
});
|
||||
}
|
||||
|
||||
public void showNovaTransacaoDialog() {
|
||||
showNovaTransacaoDialog(0.0, "", "", "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Cria e monta manualmente uma janela Modal (Pop-up) a fim do utilizador preencher
|
||||
* os detalhes referentes a uma recém aquisição de receita ou encargo para alimentar a base de dados.
|
||||
*/
|
||||
private void showNovaTransacaoDialog() {
|
||||
public void showNovaTransacaoDialog(double defaultValor, String defaultDescricao, String defaultCategoria, String defaultData) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(requireContext());
|
||||
View dialogView = getLayoutInflater().inflate(R.layout.dialog_nova_transacao, null);
|
||||
builder.setView(dialogView);
|
||||
@@ -154,6 +167,9 @@ public class TransacoesFragment extends Fragment {
|
||||
btnFechar.setOnClickListener(v -> dialog.dismiss());
|
||||
|
||||
EditText etData = dialogView.findViewById(R.id.etData);
|
||||
if (!defaultData.isEmpty()) {
|
||||
etData.setText(defaultData);
|
||||
}
|
||||
etData.setOnClickListener(v -> {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
int year = calendar.get(Calendar.YEAR);
|
||||
@@ -170,7 +186,13 @@ public class TransacoesFragment extends Fragment {
|
||||
|
||||
Button btnAdicionarTransacao = dialogView.findViewById(R.id.btnAdicionarTransacao);
|
||||
EditText etValor = dialogView.findViewById(R.id.etValor);
|
||||
if (defaultValor > 0) {
|
||||
etValor.setText(String.valueOf(defaultValor));
|
||||
}
|
||||
EditText etDescricao = dialogView.findViewById(R.id.etDescricao);
|
||||
if (!defaultDescricao.isEmpty()) {
|
||||
etDescricao.setText(defaultDescricao);
|
||||
}
|
||||
Spinner spinnerCategoria = dialogView.findViewById(R.id.spinnerCategoria);
|
||||
Spinner spinnerTipo = dialogView.findViewById(R.id.spinnerTipo);
|
||||
|
||||
@@ -182,12 +204,26 @@ public class TransacoesFragment extends Fragment {
|
||||
arrayResId, android.R.layout.simple_spinner_item);
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
spinnerCategoria.setAdapter(adapter);
|
||||
|
||||
if (!defaultCategoria.isEmpty()) {
|
||||
for (int i = 0; i < adapter.getCount(); i++) {
|
||||
if (adapter.getItem(i).toString().equalsIgnoreCase(defaultCategoria)) {
|
||||
spinnerCategoria.setSelection(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
}
|
||||
});
|
||||
|
||||
// Se vier da IA (geralmente despesa)
|
||||
if (!defaultDescricao.isEmpty()) {
|
||||
spinnerTipo.setSelection(1); // Despesa default para faturas
|
||||
}
|
||||
|
||||
btnAdicionarTransacao.setOnClickListener(v -> {
|
||||
String valor = etValor.getText().toString().trim();
|
||||
|
||||
Reference in New Issue
Block a user