import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.util.TypedValue;
+import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import java.util.Date;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import static android.view.View.GONE;
import static net.ktnx.mobileledger.MobileLedgerDB.db;
return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics()));
}
+ Pattern higher_account = Pattern.compile("^[^:]+:");
+
+ private String strip_higher_accounts(String acc_name, int[] count) {
+ count[0] = 0;
+ while (true) {
+ Matcher m = higher_account.matcher(acc_name);
+ if (m.find()) {
+ count[0]++;
+ acc_name = m.replaceFirst("");
+ }
+ else break;
+ }
+
+ return acc_name;
+ }
+
@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()) {
TableLayout t = new TableLayout(this);
TableRow r = new TableRow(this);
r.setLayoutParams(new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
- r.setPadding(getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin), dp2px(4), getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin), dp2px(4));
+ r.setGravity(Gravity.CENTER_VERTICAL);
+ r.setPadding(getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin), dp2px(2), getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin), dp2px(4));
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);
+ int[] indent_level = new int[]{0};
+ String short_acc_name = strip_higher_accounts(acc_name, indent_level);
+ acc_tv.setPadding(indent_level[0] * getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin) / 2, 0, 0, 0);
+ acc_tv.setText(short_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.setGravity(Gravity.CENTER);
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})) {