- Log.d("visuals", "hiding progress");
-
- if (error == null) resetForm();
- else Snackbar.make(findViewById(R.id.new_transaction_accounts_table), error,
- BaseTransientBottomBar.LENGTH_LONG).show();
-
- toggleAllEditing(true);
- check_transaction_submittable();
- }
-
- private void resetForm() {
- tvDate.setText("");
- tvDescription.setText("");
-
- tvDescription.requestFocus();
-
- while (table.getChildCount() > 2) {
- table.removeViewAt(2);
- }
- for (int i = 0; i < 2; i++) {
- TableRow tr = (TableRow) table.getChildAt(i);
- if (tr == null) break;
-
- ((TextView) tr.getChildAt(0)).setText("");
- ((TextView) tr.getChildAt(1)).setText("");
- }
- }
- @Override
- public void descriptionSelected(String description) {
- Log.d("descr selected", description);
- if (!inputStateIsInitial()) return;
-
- MobileLedgerProfile currentProfile = Data.profile.get();
- String accFilter = currentProfile.getPreferredAccountsFilter();
-
- ArrayList<String> params = new ArrayList<>();
- StringBuilder sb = new StringBuilder(
- "select t.profile, t.id from transactions t where t.description=?");
- params.add(description);
-
- if (accFilter != null) {
- sb.append(" AND EXISTS (").append("SELECT 1 FROM transaction_accounts ta ")
- .append("WHERE ta.profile = t.profile").append(" AND ta.transaction_id = t.id")
- .append(" AND UPPER(ta.account_name) LIKE '%'||?||'%')");
- params.add(accFilter.toUpperCase());
- }
-
- sb.append(" ORDER BY date desc limit 1");
-
- final String sql = sb.toString();
- Log.d("descr", sql);
- Log.d("descr", params.toString());
-
- try (Cursor c = MLDB.getDatabase().rawQuery(sql, params.toArray(new String[]{}))) {
- if (!c.moveToNext()) return;
-
- String profileUUID = c.getString(0);
- int transactionId = c.getInt(1);
- LedgerTransaction tr;
- try (LockHolder lh = Data.profiles.lockForReading()) {
- MobileLedgerProfile profile = null;
- for (int i = 0; i < Data.profiles.size(); i++) {
- MobileLedgerProfile p = Data.profiles.get(i);
- if (p.getUuid().equals(profileUUID)) {
- profile = p;
- break;
- }
- }
- if (profile == null) throw new RuntimeException(String.format(
- "Unable to find profile %s, which is supposed to contain " +
- "transaction %d with description %s", profileUUID, transactionId,
- description));
-
- tr = profile.loadTransaction(transactionId);
- }
- int i = 0;
- table = findViewById(R.id.new_transaction_accounts_table);
- ArrayList<LedgerTransactionAccount> accounts = tr.getAccounts();
- TableRow firstNegative = null;
- int negativeCount = 0;
- for (i = 0; i < accounts.size(); i++) {
- LedgerTransactionAccount acc = accounts.get(i);
- TableRow row = (TableRow) table.getChildAt(i);
- if (row == null) row = doAddAccountRow(false);
-
- ((TextView) row.getChildAt(0)).setText(acc.getAccountName());
- ((TextView) row.getChildAt(1))
- .setText(String.format(Locale.US, "%1.2f", acc.getAmount()));