]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailModel.java
link show comments by default flag between the UI and the DB
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / profiles / ProfileDetailModel.java
index e64c4bc1dc13c8a19caee33efab7eef631aeaf7d..2a655dccd224b11d537ab24c9a4d89c0bded23b2 100644 (file)
@@ -35,6 +35,7 @@ public class ProfileDetailModel extends ViewModel {
     private final MutableLiveData<MobileLedgerProfile.FutureDates> futureDates =
             new MutableLiveData<>(MobileLedgerProfile.FutureDates.None);
     private final MutableLiveData<Boolean> showCommodityByDefault = new MutableLiveData<>(false);
+    private final MutableLiveData<Boolean> showCommentsByDefault = new MutableLiveData<>(true);
     private final MutableLiveData<Boolean> useAuthentication = new MutableLiveData<>(false);
     private final MutableLiveData<SendTransactionTask.API> apiVersion =
             new MutableLiveData<>(SendTransactionTask.API.auto);
@@ -69,6 +70,13 @@ public class ProfileDetailModel extends ViewModel {
     void observePostingPermitted(LifecycleOwner lfo, Observer<Boolean> o) {
         postingPermitted.observe(lfo, o);
     }
+    public void setShowCommentsByDefault(boolean newValue) {
+        if (newValue != showCommentsByDefault.getValue())
+            showCommentsByDefault.setValue(newValue);
+    }
+    void observeShowCommentsByDefault(LifecycleOwner lfo, Observer<Boolean> o) {
+        showCommentsByDefault.observe(lfo, o);
+    }
     MobileLedgerProfile.FutureDates getFutureDates() {
         return futureDates.getValue();
     }
@@ -189,6 +197,7 @@ public class ProfileDetailModel extends ViewModel {
         if (mProfile != null) {
             profileName.setValue(mProfile.getName());
             postingPermitted.setValue(mProfile.isPostingPermitted());
+            showCommentsByDefault.setValue(mProfile.getShowCommentsByDefault());
             showCommodityByDefault.setValue(mProfile.getShowCommodityByDefault());
             {
                 String comm = mProfile.getDefaultCommodity();
@@ -210,6 +219,7 @@ public class ProfileDetailModel extends ViewModel {
             profileName.setValue(null);
             url.setValue(HTTPS_URL_START);
             postingPermitted.setValue(true);
+            showCommentsByDefault.setValue(true);
             showCommodityByDefault.setValue(false);
             setFutureDates(MobileLedgerProfile.FutureDates.None);
             setApiVersion(SendTransactionTask.API.auto);
@@ -226,6 +236,7 @@ public class ProfileDetailModel extends ViewModel {
         mProfile.setName(profileName.getValue());
         mProfile.setUrl(url.getValue());
         mProfile.setPostingPermitted(postingPermitted.getValue());
+        mProfile.setShowCommentsByDefault(showCommentsByDefault.getValue());
         Currency c = defaultCommodity.getValue();
         mProfile.setDefaultCommodity((c == null) ? null : c.getName());
         mProfile.setShowCommodityByDefault(showCommodityByDefault.getValue());