public void new_transaction_save_clicked(View view) {
fab.setEnabled(false);
+ toggle_all_editing(false);
progress.setVisibility(View.VISIBLE);
saver = new SaveTransactionTask(this);
}
saver.execute(tr);
}
+
+ private void toggle_all_editing(boolean enabled) {
+ TableLayout table = findViewById(R.id.new_transaction_accounts_table);
+ for (int i = 0; i < table.getChildCount(); i++) {
+ TableRow row = (TableRow) table.getChildAt(i);
+ for (int j = 0; j < row.getChildCount(); j++) {
+ row.getChildAt(j).setEnabled(enabled);
+ }
+ }
+ }
+
private void hook_swipe_listener(final TableRow row) {
row.getChildAt(0).setOnTouchListener(new OnSwipeTouchListener(this) {
public void onSwipeLeft() {
return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics()));
}
- public void addTransactionAccountFromMenu(MenuItem item) {
+ private void do_add_account_row(boolean focus) {
final AutoCompleteTextView acc = new AutoCompleteTextView(this);
acc.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.WRAP_CONTENT, 9f));
acc.setHint(R.string.new_transaction_account_hint);
row.addView(amt);
table.addView(row);
- acc.requestFocus();
+ if (focus) acc.requestFocus();
hook_swipe_listener(row);
hook_autocompletion_adapter(row);
hook_text_change_listener(amt);
}
+ public void addTransactionAccountFromMenu(MenuItem item) {
+ do_add_account_row(true);
+ }
+
private void check_transaction_submittable() {
TableLayout table = findViewById(R.id.new_transaction_accounts_table);
int accounts = 0;
int accounts_with_values = 0;
- for( int i = 0; i < table.getChildCount(); i++ ) {
+ int empty_rows = 0;
+ for(int i = 0; i < table.getChildCount(); i++ ) {
TableRow row = (TableRow) table.getChildAt(i);
TextView acc_name_v = (TextView) row.getChildAt(0);
String amt = String.valueOf(amount_v.getText());
if (!amt.isEmpty()) accounts_with_values++;
- }
+ } else empty_rows++;
+ }
- if ((accounts >= 2) && (accounts_with_values >= (accounts - 1))) {
- show_fab();
- return;
- }
+ if (accounts_with_values == accounts && empty_rows == 0) {
+ do_add_account_row(false);
}
- hide_fab();
+ if ((accounts >= 2) && (accounts_with_values >= (accounts - 1))) {
+ show_fab();
+ } else hide_fab();
}
@Override
}
}, 1000);
reset_form();
+ toggle_all_editing(true);
}
private void reset_form() {