From: Damyan Ivanov Date: Thu, 15 Apr 2021 05:59:03 +0000 (+0000) Subject: Default template name given at save time X-Git-Tag: v0.18.0~88 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=7d66376e2470788c6b1ad5df18603c814aa389ea;p=mobile-ledger.git Default template name given at save time gets in the way when put in the details --- diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsFragment.java index ac72d890..03dd0ddf 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsFragment.java @@ -105,7 +105,7 @@ public class TemplateDetailsFragment extends Fragment { final ViewModelStoreOwner viewModelStoreOwner = controller.getViewModelStoreOwner(R.id.template_list_navigation); mViewModel = new ViewModelProvider(viewModelStoreOwner).get(TemplateDetailsViewModel.class); - mViewModel.setDefaultPatternName(getString(R.string.unnamed_template)); + mViewModel.setDefaultTemplateName(getString(R.string.unnamed_template)); Logger.debug("flow", "PatternDetailsFragment.onCreateView(): model=" + mViewModel); b = TemplateDetailsFragmentBinding.inflate(inflater); 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 988d1bb8..8d0e29e6 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 @@ -33,6 +33,7 @@ import net.ktnx.mobileledger.db.TemplateHeader; import net.ktnx.mobileledger.db.TemplateWithAccounts; import net.ktnx.mobileledger.model.TemplateDetailsItem; import net.ktnx.mobileledger.utils.Logger; +import net.ktnx.mobileledger.utils.Misc; import java.util.ArrayList; import java.util.Collections; @@ -46,13 +47,13 @@ public class TemplateDetailsViewModel extends ViewModel { new MutableLiveData<>(Collections.emptyList()); private final AtomicInteger syntheticItemId = new AtomicInteger(0); private Long mPatternId; - private String mDefaultPatternName; + private String mDefaultTemplateName; private boolean itemsLoaded = false; - public String getDefaultPatternName() { - return mDefaultPatternName; + public String getDefaultTemplateName() { + return mDefaultTemplateName; } - public void setDefaultPatternName(String name) { - mDefaultPatternName = name; + public void setDefaultTemplateName(String name) { + mDefaultTemplateName = name; } public void resetItems() { @@ -85,7 +86,6 @@ public class TemplateDetailsViewModel extends ViewModel { if (srcList.size() < 1) { final TemplateDetailsItem.Header header = TemplateDetailsItem.createHeader(); - header.setName(mDefaultPatternName); header.setId(0); newList.add(header); changes = true; @@ -211,6 +211,9 @@ public class TemplateDetailsViewModel extends ViewModel { TemplateDetailsItem.Header modelHeader = list.get(0) .asHeaderItem(); + modelHeader.setName(Misc.trim(modelHeader.getName())); + if (modelHeader.getName().isEmpty()) + modelHeader.setName(getDefaultTemplateName()); TemplateHeaderDAO headerDAO = DB.get() .getTemplateDAO(); TemplateHeader dbHeader = modelHeader.toDBO();