- @Override
- public void done() {
- fab.setEnabled(true);
-
- AnimatorSet set = (AnimatorSet) AnimatorInflater.loadAnimator(this, R.animator.new_trans_animation);
- set.setTarget(fab);
- set.start();
- final Handler at_fade_out = new Handler();
- at_fade_out.postDelayed(new Runnable() {
- @Override
- public void run() {
- fab.setImageResource(R.drawable.ic_thick_check_white);
-
- final Handler at_fade_in = new Handler();
- at_fade_in.postDelayed(new Runnable() {
- @Override
- public void run() {
- fab.setImageResource(R.drawable.ic_save_white_24dp);
+ public void addTransactionAccountFromMenu(MenuItem item) {
+ do_add_account_row(true);
+ }
+
+ public void resetTransactionFromMenu(MenuItem item) {
+ reset_form();
+ }
+
+ public void saveTransactionFromMenu(MenuItem item) {
+ save_transaction();
+ }
+
+ private boolean is_zero(float f) {
+ return (f < 0.005) && (f > -0.005);
+ }
+
+ // rules:
+ // 1) at least two account names
+ // 2) each amount must have account name
+ // 3) amounts must balance to 0, or
+ // 3a) there must be exactly one empty amount
+ // 4) empty accounts with empty amounts are ignored
+ // 5) a row with an empty account name or empty amount is guaranteed to exist
+ @SuppressLint("DefaultLocale")
+ private void check_transaction_submittable() {
+ TableLayout table = findViewById(R.id.new_transaction_accounts_table);
+ int accounts = 0;
+ int accounts_with_values = 0;
+ int amounts = 0;
+ int amounts_with_accounts = 0;
+ int empty_rows = 0;
+ TextView empty_amount = null;
+ boolean single_empty_amount = false;
+ boolean single_empty_amount_has_account = false;
+ float running_total = 0f;
+ boolean have_description =
+ !((TextView) findViewById(R.id.new_transaction_description)).getText().toString()
+ .isEmpty();
+
+ try {
+ for (int i = 0; i < table.getChildCount(); i++) {
+ TableRow row = (TableRow) table.getChildAt(i);
+
+ TextView acc_name_v = (TextView) row.getChildAt(0);
+ TextView amount_v = (TextView) row.getChildAt(1);
+ String amt = String.valueOf(amount_v.getText());
+ String acc_name = String.valueOf(acc_name_v.getText());
+ acc_name = acc_name.trim();
+
+ if (!acc_name.isEmpty()) {
+ accounts++;
+
+ if (!amt.isEmpty()) {
+ accounts_with_values++;