- @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.getPosition() % 2 == 0) {
- holder.row.setBackgroundColor(Globals.tableRowEvenBG);
- }
- else {
- holder.row.setBackgroundColor(Globals.tableRowOddBG);
- }
-
- 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();
-
- accName.setText(acc.getAccountName());
- accAmount.setText(acc.toString());
-
-// Log.d("tmp", String.format("showing acc row %d: %s %1.2f", rowIndex,
-// acc.getAccountName(), acc.getAmount()));
-
- String boldAccountName = step.getBoldAccountName();
- if ((boldAccountName != null) && boldAccountName.equals(acc.getAccountName())) {
- accName.setTypeface(null, Typeface.BOLD);
- accAmount.setTypeface(null, Typeface.BOLD);
- accName.setTextColor(Globals.primaryDark);
- accAmount.setTextColor(Globals.primaryDark);
- }
- else {
- accName.setTypeface(null, Typeface.NORMAL);
- accAmount.setTypeface(null, Typeface.NORMAL);
- accName.setTextColor(Globals.defaultTextColor);
- accAmount.setTextColor(Globals.defaultTextColor);
- }
-
- break;
- case DONE:
- int accCount = step.getAccountCount();
- if (holder.tableAccounts.getChildCount() > accCount) {
- holder.tableAccounts.removeViews(accCount,
- holder.tableAccounts.getChildCount() - accCount);
- }
-
-// Log.d("transactions",
-// String.format("Position %d fill done", step.getPosition()));
- }
+ }
+ @NonNull
+ @Override
+ public TransactionRowHolderBase onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
+// debug("perf", "onCreateViewHolder called");
+ final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
+
+ switch (TransactionListItem.Type.valueOf(viewType)) {
+ case TRANSACTION:
+ return new TransactionRowHolder(
+ TransactionListRowBinding.inflate(inflater, parent, false));
+ case DELIMITER:
+ return new TransactionListDelimiterRowHolder(
+ TransactionDelimiterBinding.inflate(inflater, parent, false));
+ case HEADER:
+ return new TransactionListLastUpdateRowHolder(
+ LastUpdateLayoutBinding.inflate(inflater, parent, false));
+ default:
+ throw new IllegalStateException("Unexpected value: " + viewType);