+ enum LoaderStep {HEAD, ACCOUNTS, DONE}
+ private static class TransactionLoader
+ extends AsyncTask<TransactionLoaderParams, TransactionLoaderStep, Void> {
+ @Override
+ protected Void doInBackground(TransactionLoaderParams... p) {
+ LedgerTransaction tr = p[0].transaction;
+ boolean odd = p[0].odd;
+
+ SQLiteDatabase db = MLDB.getDatabase();
+ tr.loadData(db);
+
+ publishProgress(new TransactionLoaderStep(p[0].holder, p[0].position, tr, odd));
+
+ int rowIndex = 0;
+ for (LedgerTransactionAccount acc : tr.getAccounts()) {
+// debug(c.getAccountName(), acc.getAmount()));
+ publishProgress(new TransactionLoaderStep(p[0].holder, acc, rowIndex++,
+ p[0].boldAccountName));
+ }
+
+ publishProgress(new TransactionLoaderStep(p[0].holder, p[0].position, rowIndex));
+
+ return null;
+ }
+ @Override
+ protected void onProgressUpdate(TransactionLoaderStep... values) {
+ super.onProgressUpdate(values);
+ TransactionLoaderStep step = values[0];
+ TransactionRowHolder holder = step.getHolder();
+
+ switch (step.getStep()) {
+ case HEAD:
+ holder.tvDescription.setText(step.getTransaction().getDescription());
+
+ if (step.isOdd()) holder.row.setBackgroundColor(Colors.tableRowDarkBG);
+ else holder.row.setBackgroundColor(Colors.tableRowLightBG);
+
+ break;
+ case ACCOUNTS:
+ int rowIndex = step.getAccountPosition();
+ Context ctx = holder.row.getContext();
+ LinearLayout row = (LinearLayout) holder.tableAccounts.getChildAt(rowIndex);
+ TextView accName, accAmount;
+ if (row == null) {
+ row = new LinearLayout(ctx);
+ row.setLayoutParams(new LinearLayout.LayoutParams(
+ LinearLayout.LayoutParams.MATCH_PARENT,
+ LinearLayout.LayoutParams.WRAP_CONTENT));
+ row.setGravity(Gravity.CENTER_VERTICAL);
+ row.setOrientation(LinearLayout.HORIZONTAL);
+ row.setPaddingRelative(dp2px(ctx, 8), 0, 0, 0);
+ accName = new AppCompatTextView(ctx);
+ accName.setLayoutParams(new LinearLayout.LayoutParams(0,
+ LinearLayout.LayoutParams.WRAP_CONTENT, 5f));
+ accName.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_START);
+ row.addView(accName);
+ accAmount = new AppCompatTextView(ctx);
+ LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(
+ LinearLayout.LayoutParams.WRAP_CONTENT,
+ LinearLayout.LayoutParams.WRAP_CONTENT);
+ llp.setMarginEnd(0);
+ accAmount.setLayoutParams(llp);
+ accAmount.setTextAlignment(View.TEXT_ALIGNMENT_VIEW_END);
+ accAmount.setMinWidth(dp2px(ctx, 60));
+ row.addView(accAmount);
+ holder.tableAccounts.addView(row);
+ }
+ else {
+ accName = (TextView) row.getChildAt(0);
+ accAmount = (TextView) row.getChildAt(1);
+ }
+ LedgerTransactionAccount acc = step.getAccount();
+
+
+// debug("tmp", String.format("showing acc row %d: %s %1.2f", rowIndex,
+// acc.getAccountName(), acc.getAmount()));
+
+ String boldAccountName = step.getBoldAccountName();
+ if ((boldAccountName != null) &&
+ acc.getAccountName().startsWith(boldAccountName))
+ {
+ accName.setTextColor(Colors.accent);
+ accAmount.setTextColor(Colors.accent);
+
+ SpannableString ss = new SpannableString(acc.getAccountName());
+ ss.setSpan(new StyleSpan(Typeface.BOLD), 0, boldAccountName.length(),
+ Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ accName.setText(ss);
+ }
+ else {
+ accName.setTextColor(Colors.defaultTextColor);
+ accAmount.setTextColor(Colors.defaultTextColor);
+ accName.setText(acc.getAccountName());
+ }
+ accAmount.setText(acc.toString());
+
+ break;
+ case DONE:
+ int accCount = step.getAccountCount();
+ if (holder.tableAccounts.getChildCount() > accCount) {
+ holder.tableAccounts.removeViews(accCount,
+ holder.tableAccounts.getChildCount() - accCount);
+ }
+
+// debug("transactions",
+// String.format("Position %d fill done", step.getPosition()));
+ }
+ }