From: Damyan Ivanov Date: Sat, 13 Feb 2021 19:55:12 +0000 (+0200) Subject: make pattern editor survive reconfiguration X-Git-Tag: v0.17.0~127 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=59ec619c8f3a34e90804067691854864d45d45e6;p=mobile-ledger.git make pattern editor survive reconfiguration --- diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsViewModel.java b/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsViewModel.java index f5dacdc1..608bb634 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsViewModel.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsViewModel.java @@ -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> 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); }