X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2FNewTransactionActivity.java;h=f41063d96034d9f754bf7dee3c090182c8d2c6b7;hp=53cbc905d62cad18d25aa3abc7e4c2a3958a2882;hb=5e7a0e2a76b8d627801a5fbdf05c2dc7c6168b9f;hpb=a62fd00f3bc04e39a97817e8eca0421dc962e4fd diff --git a/app/src/main/java/net/ktnx/mobileledger/NewTransactionActivity.java b/app/src/main/java/net/ktnx/mobileledger/NewTransactionActivity.java index 53cbc905..f41063d9 100644 --- a/app/src/main/java/net/ktnx/mobileledger/NewTransactionActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/NewTransactionActivity.java @@ -179,6 +179,11 @@ public class NewTransactionActivity extends AppCompatActivity implements TaskCal prev_amt.setImeOptions(EditorInfo.IME_ACTION_NEXT); } + if (row.hasFocus()) { + if (next_acc != null) next_acc.requestFocus(); + else prev_amt.requestFocus(); + } + table.removeView(row); check_transaction_submittable(); // Toast.makeText(NewTransactionActivity.this, "LEFT", Toast.LENGTH_LONG).show(); @@ -343,6 +348,11 @@ public class NewTransactionActivity extends AppCompatActivity implements TaskCal 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 @@ -360,6 +370,7 @@ public class NewTransactionActivity extends AppCompatActivity implements TaskCal 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() @@ -389,6 +400,7 @@ public class NewTransactionActivity extends AppCompatActivity implements TaskCal if (empty_amount == null) { empty_amount = amount_v; single_empty_amount = true; + single_empty_amount_has_account = !acc_name.isEmpty(); } else if (!acc_name.isEmpty()) single_empty_amount = false; } @@ -405,8 +417,16 @@ public class NewTransactionActivity extends AppCompatActivity implements TaskCal do_add_account_row(false); } + Log.d("submittable", String.format("accounts=%d, accounts_with_values=%s, " + + "amounts_with_accounts=%d, amounts=%d, running_total=%1.2f, " + + "single_empty_with_acc=%s", accounts, accounts_with_values, + amounts_with_accounts, amounts, running_total, + (single_empty_amount && single_empty_amount_has_account) ? "true" : "false")); + if (have_description && (accounts >= 2) && (accounts_with_values >= (accounts - 1)) && ( - amounts_with_accounts == amounts)) + amounts_with_accounts == amounts) && ( + single_empty_amount && single_empty_amount_has_account || is_zero( + running_total))) { if (mSave != null) mSave.setVisible(true); } @@ -416,6 +436,7 @@ public class NewTransactionActivity extends AppCompatActivity implements TaskCal empty_amount .setHint(String.format("%1.2f", (running_total > 0) ? -running_total : 0f)); } + } catch (NumberFormatException e) { if (mSave != null) mSave.setVisible(false);