+ @SuppressLint("DefaultLocale")
+ private void update_account_table() {
+ LinearLayout root = findViewById(R.id.account_root);
+ root.removeAllViewsInLayout();
+
+ try (Cursor cursor = db.rawQuery("SELECT name FROM accounts ORDER BY name;", null)) {
+ boolean even = false;
+ while (cursor.moveToNext()) {
+ String acc_name = cursor.getString(0);
+
+ TableLayout t = new TableLayout(this);
+ TableRow r = new TableRow(this);
+ r.setLayoutParams(new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+ if (even)
+ r.setBackgroundColor(getResources().getColor(R.color.table_row_even_bg, getTheme()));
+ even = !even;
+
+ TextView acc_tv = new TextView(this, null, R.style.account_summary_account_name);
+ acc_tv.setLayoutParams(new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 9f));
+ acc_tv.setText(acc_name);
+ r.addView(acc_tv);
+
+ TextView amt_tv = new TextView(this, null, R.style.account_summary_amounts);
+ amt_tv.setLayoutParams(new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f));
+ amt_tv.setTextAlignment(EditText.TEXT_ALIGNMENT_VIEW_END);
+ amt_tv.setMinWidth(dp2px(40f));
+ StringBuilder amt_text = new StringBuilder();
+ try (Cursor cAmounts = db.rawQuery("SELECT currency, value FROM account_values WHERE account = ?", new String[]{acc_name})) {
+ while (cAmounts.moveToNext()) {
+ String curr = cAmounts.getString(0);
+ Float amt = cAmounts.getFloat(1);
+ if (amt_text.length() != 0) amt_text.append('\n');
+ amt_text.append(String.format("%s %1.2f", curr, amt));
+ }
+ }
+ amt_tv.setText(amt_text.toString());
+
+ r.addView(amt_tv);
+
+ t.addView(r);
+
+ root.addView(t);
+ }
+ }