From 2c0103e9c08cd9d86180321960bf422f0255a6ac Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Sun, 10 Nov 2019 13:22:17 +0200 Subject: [PATCH] NewTransItemHolder: prevent sync loops via model data observers when the data in the model is changed (e.g. in a reset operation) the new data needs to be sent to the UI without this causing data sync back to the model --- .../ui/activity/NewTransactionItemHolder.java | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java index 031453c3..3198cc16 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java @@ -121,15 +121,33 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder dateObserver = date -> { if (syncingData) return; - tvDate.setText(item.getFormattedDate()); + syncingData = true; + try { + tvDate.setText(item.getFormattedDate()); + } + finally { + syncingData = false; + } }; descriptionObserver = description -> { if (syncingData) return; - tvDescription.setText(description); + syncingData = true; + try { + tvDescription.setText(description); + } + finally { + syncingData = false; + } }; hintObserver = hint -> { if (syncingData) return; - tvAmount.setHint(hint); + syncingData = true; + try { + tvAmount.setHint(hint); + } + finally { + syncingData = false; + } }; focusedAccountObserver = index -> { if ((index != null) && index.equals(getAdapterPosition())) { -- 2.39.2