From 54c997e3b537d97a8dabf19ee605b58c644cc054 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Mon, 8 Feb 2021 05:43:36 +0000 Subject: [PATCH] stop propagating UI changes to the model during view binding prevents endless recursion --- .../ui/templates/TemplateDetailsAdapter.java | 384 ++++++++++-------- 1 file changed, 218 insertions(+), 166 deletions(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsAdapter.java b/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsAdapter.java index aee8511c..5c49a494 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsAdapter.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsAdapter.java @@ -274,8 +274,22 @@ class TemplateDetailsAdapter extends RecyclerView.Adapter selectHeaderDetailSource(v, HeaderDetail.DATE_YEAR)); + b.templateDetailsYearSource.setOnClickListener( + v -> selectHeaderDetailSource(v, HeaderDetail.DATE_YEAR)); + + if (header.hasLiteralDateMonth()) { + b.templateDetailsMonthSource.setText(R.string.template_details_source_literal); + final Integer dateMonth = header.getDateMonth(); + b.templateDetailsDateMonth.setText( + (dateMonth == null) ? null : String.valueOf(dateMonth)); + b.templateDetailsDateMonthLayout.setVisibility(View.VISIBLE); + } + else { + b.templateDetailsDateMonthLayout.setVisibility(View.GONE); + b.templateDetailsMonthSource.setText( + String.format(Locale.US, groupNoText, header.getDateMonthMatchGroup(), + getMatchGroupText(header.getDateMonthMatchGroup()))); + } + b.templateDetailsMonthSourceLabel.setOnClickListener( + v -> selectHeaderDetailSource(v, HeaderDetail.DATE_MONTH)); + b.templateDetailsMonthSource.setOnClickListener( + v -> selectHeaderDetailSource(v, HeaderDetail.DATE_MONTH)); + + if (header.hasLiteralDateDay()) { + b.templateDetailsDaySource.setText(R.string.template_details_source_literal); + final Integer dateDay = header.getDateDay(); + b.templateDetailsDateDay.setText( + (dateDay == null) ? null : String.valueOf(dateDay)); + b.templateDetailsDateDayLayout.setVisibility(View.VISIBLE); + } + else { + b.templateDetailsDateDayLayout.setVisibility(View.GONE); + b.templateDetailsDaySource.setText( + String.format(Locale.US, groupNoText, header.getDateDayMatchGroup(), + getMatchGroupText(header.getDateDayMatchGroup()))); + } + b.templateDetailsDaySourceLabel.setOnClickListener( + v -> selectHeaderDetailSource(v, HeaderDetail.DATE_DAY)); + b.templateDetailsDaySource.setOnClickListener( + v -> selectHeaderDetailSource(v, HeaderDetail.DATE_DAY)); + + if (header.hasLiteralTransactionDescription()) { + b.templateTransactionDescriptionSource.setText( + R.string.template_details_source_literal); + b.transactionDescription.setText(header.getTransactionDescription()); + b.transactionDescriptionLayout.setVisibility(View.VISIBLE); + } + else { + b.transactionDescriptionLayout.setVisibility(View.GONE); + b.templateTransactionDescriptionSource.setText( + String.format(Locale.US, groupNoText, + header.getTransactionDescriptionMatchGroup(), getMatchGroupText( + header.getTransactionDescriptionMatchGroup()))); - b.templateName.setText(header.getName()); - b.pattern.setText(header.getPattern()); - b.testText.setText(header.getTestText()); + } + b.templateTransactionDescriptionSourceLabel.setOnClickListener( + v -> selectHeaderDetailSource(v, HeaderDetail.DESCRIPTION)); + b.templateTransactionDescriptionSource.setOnClickListener( + v -> selectHeaderDetailSource(v, HeaderDetail.DESCRIPTION)); + + if (header.hasLiteralTransactionComment()) { + b.templateTransactionCommentSource.setText( + R.string.template_details_source_literal); + b.transactionComment.setText(header.getTransactionComment()); + b.transactionCommentLayout.setVisibility(View.VISIBLE); + } + else { + b.transactionCommentLayout.setVisibility(View.GONE); + b.templateTransactionCommentSource.setText(String.format(Locale.US, groupNoText, + header.getTransactionCommentMatchGroup(), + getMatchGroupText(header.getTransactionCommentMatchGroup()))); - if (header.hasLiteralDateYear()) { - b.templateDetailsYearSource.setText(R.string.template_details_source_literal); - final Integer dateYear = header.getDateYear(); - b.templateDetailsDateYear.setText( - (dateYear == null) ? null : String.valueOf(dateYear)); - b.templateDetailsDateYearLayout.setVisibility(View.VISIBLE); - } - else { - b.templateDetailsDateYearLayout.setVisibility(View.GONE); - b.templateDetailsYearSource.setText( - String.format(Locale.US, groupNoText, header.getDateYearMatchGroup(), - getMatchGroupText(header.getDateYearMatchGroup()))); - } - b.templateDetailsYearSourceLabel.setOnClickListener( - v -> selectHeaderDetailSource(v, HeaderDetail.DATE_YEAR)); - b.templateDetailsYearSource.setOnClickListener( - v -> selectHeaderDetailSource(v, HeaderDetail.DATE_YEAR)); - - if (header.hasLiteralDateMonth()) { - b.templateDetailsMonthSource.setText(R.string.template_details_source_literal); - final Integer dateMonth = header.getDateMonth(); - b.templateDetailsDateMonth.setText( - (dateMonth == null) ? null : String.valueOf(dateMonth)); - b.templateDetailsDateMonthLayout.setVisibility(View.VISIBLE); - } - else { - b.templateDetailsDateMonthLayout.setVisibility(View.GONE); - b.templateDetailsMonthSource.setText( - String.format(Locale.US, groupNoText, header.getDateMonthMatchGroup(), - getMatchGroupText(header.getDateMonthMatchGroup()))); - } - b.templateDetailsMonthSourceLabel.setOnClickListener( - v -> selectHeaderDetailSource(v, HeaderDetail.DATE_MONTH)); - b.templateDetailsMonthSource.setOnClickListener( - v -> selectHeaderDetailSource(v, HeaderDetail.DATE_MONTH)); - - if (header.hasLiteralDateDay()) { - b.templateDetailsDaySource.setText(R.string.template_details_source_literal); - final Integer dateDay = header.getDateDay(); - b.templateDetailsDateDay.setText( - (dateDay == null) ? null : String.valueOf(dateDay)); - b.templateDetailsDateDayLayout.setVisibility(View.VISIBLE); - } - else { - b.templateDetailsDateDayLayout.setVisibility(View.GONE); - b.templateDetailsDaySource.setText( - String.format(Locale.US, groupNoText, header.getDateDayMatchGroup(), - getMatchGroupText(header.getDateDayMatchGroup()))); - } - b.templateDetailsDaySourceLabel.setOnClickListener( - v -> selectHeaderDetailSource(v, HeaderDetail.DATE_DAY)); - b.templateDetailsDaySource.setOnClickListener( - v -> selectHeaderDetailSource(v, HeaderDetail.DATE_DAY)); - - if (header.hasLiteralTransactionDescription()) { - b.templateTransactionDescriptionSource.setText( - R.string.template_details_source_literal); - b.transactionDescription.setText(header.getTransactionDescription()); - b.transactionDescriptionLayout.setVisibility(View.VISIBLE); - } - else { - b.transactionDescriptionLayout.setVisibility(View.GONE); - b.templateTransactionDescriptionSource.setText(String.format(Locale.US, groupNoText, - header.getTransactionDescriptionMatchGroup(), - getMatchGroupText(header.getTransactionDescriptionMatchGroup()))); + } + b.templateTransactionCommentSourceLabel.setOnClickListener( + v -> selectHeaderDetailSource(v, HeaderDetail.COMMENT)); + b.templateTransactionCommentSource.setOnClickListener( + v -> selectHeaderDetailSource(v, HeaderDetail.COMMENT)); - } - b.templateTransactionDescriptionSourceLabel.setOnClickListener( - v -> selectHeaderDetailSource(v, HeaderDetail.DESCRIPTION)); - b.templateTransactionDescriptionSource.setOnClickListener( - v -> selectHeaderDetailSource(v, HeaderDetail.DESCRIPTION)); - - if (header.hasLiteralTransactionComment()) { - b.templateTransactionCommentSource.setText( - R.string.template_details_source_literal); - b.transactionComment.setText(header.getTransactionComment()); - b.transactionCommentLayout.setVisibility(View.VISIBLE); - } - else { - b.transactionCommentLayout.setVisibility(View.GONE); - b.templateTransactionCommentSource.setText(String.format(Locale.US, groupNoText, - header.getTransactionCommentMatchGroup(), - getMatchGroupText(header.getTransactionCommentMatchGroup()))); + b.templateDetailsHeadScanQrButton.setOnClickListener(this::scanTestQR); + checkPatternError(header); + } + finally { + enableUpdatePropagation(); } - b.templateTransactionCommentSourceLabel.setOnClickListener( - v -> selectHeaderDetailSource(v, HeaderDetail.COMMENT)); - b.templateTransactionCommentSource.setOnClickListener( - v -> selectHeaderDetailSource(v, HeaderDetail.COMMENT)); - - b.templateDetailsHeadScanQrButton.setOnClickListener(this::scanTestQR); - - checkPatternError(header); } private void checkPatternError(TemplateDetailsItem.Header item) { if (item.getPatternError() != null) { @@ -560,7 +593,7 @@ class TemplateDetailsAdapter extends RecyclerView.Adapter selectAccountRowDetailSource(v, AccDetail.ACCOUNT)); + b.templateDetailsAccountNameSource.setOnClickListener( + v -> selectAccountRowDetailSource(v, AccDetail.ACCOUNT)); + b.templateAccountCommentSourceLabel.setOnClickListener( + v -> selectAccountRowDetailSource(v, AccDetail.COMMENT)); + b.templateDetailsAccountCommentSource.setOnClickListener( + v -> selectAccountRowDetailSource(v, AccDetail.COMMENT)); + b.templateAccountAmountSourceLabel.setOnClickListener( + v -> selectAccountRowDetailSource(v, AccDetail.AMOUNT)); + b.templateDetailsAccountAmountSource.setOnClickListener( + v -> selectAccountRowDetailSource(v, AccDetail.AMOUNT)); } - else { - b.templateDetailsAccountAmountSource.setText( - String.format(Locale.US, groupNoText, accRow.getAmountMatchGroup(), - getMatchGroupText(accRow.getAmountMatchGroup()))); - b.templateDetailsAccountAmountLayout.setVisibility(View.GONE); - b.negateAmountSwitch.setVisibility(View.VISIBLE); - b.negateAmountSwitch.setChecked(accRow.isNegateAmount()); - b.templateDetailsNegateAmountText.setText( - accRow.isNegateAmount() ? R.string.template_account_change_amount_sign - : R.string.template_account_keep_amount_sign); - b.templateDetailsNegateAmountLabel.setVisibility(View.VISIBLE); - b.templateDetailsNegateAmountText.setVisibility(View.VISIBLE); + finally { + enableUpdatePropagation(); } - - b.templateAccountNameSourceLabel.setOnClickListener( - v -> selectAccountRowDetailSource(v, AccDetail.ACCOUNT)); - b.templateDetailsAccountNameSource.setOnClickListener( - v -> selectAccountRowDetailSource(v, AccDetail.ACCOUNT)); - b.templateAccountCommentSourceLabel.setOnClickListener( - v -> selectAccountRowDetailSource(v, AccDetail.COMMENT)); - b.templateDetailsAccountCommentSource.setOnClickListener( - v -> selectAccountRowDetailSource(v, AccDetail.COMMENT)); - b.templateAccountAmountSourceLabel.setOnClickListener( - v -> selectAccountRowDetailSource(v, AccDetail.AMOUNT)); - b.templateDetailsAccountAmountSource.setOnClickListener( - v -> selectAccountRowDetailSource(v, AccDetail.AMOUNT)); } private @NotNull TemplateDetailsItem.AccountRow getItem() { return differ.getCurrentList() -- 2.39.5