+ 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 = App.getDatabase();
+ tr.loadData(db);
+
+ publishProgress(new TransactionLoaderStep(p[0].holder, p[0].position, tr, odd));
+
+ int rowIndex = 0;
+ // FIXME ConcurrentModificationException in ArrayList$ltr.next (ArrayList.java:831)
+ 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());
+ String trComment = Misc.emptyIsNull(step.getTransaction()
+ .getComment());
+ if (trComment == null)
+ holder.tvComment.setVisibility(View.GONE);
+ else {
+ holder.tvComment.setText(trComment);
+ holder.tvComment.setVisibility(View.VISIBLE);
+ }
+
+// 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);
+ if (row == null) {
+ LayoutInflater inflater = ((Activity) ctx).getLayoutInflater();
+ row = (LinearLayout) inflater.inflate(
+ R.layout.transaction_list_row_accounts_table_row, null);
+ // if the rootView above is given (and the line below is spared)
+ // the accounts remain with their default text (set in the layout resource)
+ holder.tableAccounts.addView(row);
+ }
+ TextView dummyText = row.findViewById(R.id.dummy_text);
+ TextView accName = row.findViewById(R.id.transaction_list_acc_row_acc_name);
+ TextView accComment =
+ row.findViewById(R.id.transaction_list_acc_row_acc_comment);
+ TextView accAmount = row.findViewById(R.id.transaction_list_acc_row_acc_amount);
+ 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.secondary);
+ accAmount.setTextColor(Colors.secondary);
+
+ SpannableString ss = new SpannableString(acc.getAccountName());
+ ss.setSpan(new StyleSpan(Typeface.BOLD), 0, boldAccountName.length(),
+ Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ accName.setText(ss);
+ }
+ else {
+ @ColorInt int textColor = dummyText.getTextColors()
+ .getDefaultColor();
+ accName.setTextColor(textColor);
+ accAmount.setTextColor(textColor);
+ accName.setText(acc.getAccountName());
+ }
+
+ String comment = acc.getComment();
+ if (comment != null && !comment.isEmpty()) {
+ accComment.setText(comment);
+ accComment.setVisibility(View.VISIBLE);
+ }
+ else {
+ accComment.setVisibility(View.GONE);
+ }
+ 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()));
+ }
+ }