]> git.ktnx.net Git - mobile-ledger.git/commitdiff
Default template name given at save time
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 15 Apr 2021 05:59:03 +0000 (05:59 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 15 Apr 2021 05:59:03 +0000 (05:59 +0000)
gets in the way when put in the details

app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsFragment.java
app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsViewModel.java

index ac72d890e54811c8e81de420dffafec4ff986804..03dd0ddf5a040eb342e975a0c13629e020586890 100644 (file)
@@ -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);
index 988d1bb86e8f07c4176938514c7219be46369612..8d0e29e64792eee5548e1072883e3b26dbe7cae1 100644 (file)
@@ -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();