]> git.ktnx.net Git - mobile-ledger-staging.git/commitdiff
NewTransItemHolder: prevent sync loops via model data observers
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 10 Nov 2019 11:22:17 +0000 (13:22 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 10 Nov 2019 11:22:17 +0000 (13:22 +0200)
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

app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java

index 031453c3d1ed5fbae9382a90685515106695d141..3198cc1695597687063f781d53e16038c5f0ae74 100644 (file)
@@ -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())) {