]> git.ktnx.net Git - mobile-ledger.git/commitdiff
make pattern editor survive reconfiguration
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 13 Feb 2021 19:55:12 +0000 (21:55 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 18 Feb 2021 07:19:43 +0000 (07:19 +0000)
app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsViewModel.java

index f5dacdc1de2f57cff00b74a5db84429b44810c20..608bb6344cade07fab781509a1cdc37de1ade915 100644 (file)
@@ -44,6 +44,7 @@ public class TemplateDetailsViewModel extends ViewModel {
             new MutableLiveData<>(Collections.emptyList());
     private Long mPatternId;
     private String mDefaultPatternName;
+    private boolean itemsLoaded = false;
 
     public String getDefaultPatternName() {
         return mDefaultPatternName;
@@ -86,6 +87,9 @@ public class TemplateDetailsViewModel extends ViewModel {
             items.setValue(newList);
     }
     public LiveData<List<TemplateDetailsItem>> getItems(Long patternId) {
+        if (itemsLoaded && Objects.equals(patternId, this.mPatternId))
+            return items;
+
         if (patternId != null && patternId <= 0)
             throw new IllegalArgumentException("Pattern ID " + patternId + " is invalid");
 
@@ -93,6 +97,7 @@ public class TemplateDetailsViewModel extends ViewModel {
 
         if (mPatternId == null) {
             resetItems();
+            itemsLoaded = true;
             return items;
         }
 
@@ -114,6 +119,7 @@ public class TemplateDetailsViewModel extends ViewModel {
                     Logger.debug("patterns-db", "Loaded pattern item " + i);
                 }
                 items.postValue(l);
+                itemsLoaded = true;
 
                 dbList.removeObserver(this);
             }