From 59ec619c8f3a34e90804067691854864d45d45e6 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Sat, 13 Feb 2021 21:55:12 +0200 Subject: [PATCH] make pattern editor survive reconfiguration --- .../mobileledger/ui/templates/TemplateDetailsViewModel.java | 6 ++++++ 1 file changed, 6 insertions(+) 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); } -- 2.39.5