]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java
Rename to MoLe
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / profiles / ProfileDetailFragment.java
index 004763a7ac87a45343018d67b095872aa612efc6..f26d26949200b7630908fb592bef870e3863ba55 100644 (file)
@@ -1,18 +1,18 @@
 /*
  * Copyright © 2019 Damyan Ivanov.
- * This file is part of Mobile-Ledger.
- * Mobile-Ledger is free software: you can distribute it and/or modify it
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
  * under the term of the GNU General Public License as published by
  * the Free Software Foundation, either version 3 of the License, or
  * (at your opinion), any later version.
  *
- * Mobile-Ledger is distributed in the hope that it will be useful,
+ * MoLe is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  * GNU General Public License terms for details.
  *
  * You should have received a copy of the GNU General Public License
- * along with Mobile-Ledger. If not, see <https://www.gnu.org/licenses/>.
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
  */
 
 package net.ktnx.mobileledger.ui.profiles;
@@ -61,6 +61,7 @@ public class ProfileDetailFragment extends Fragment {
      */
     private MobileLedgerProfile mProfile;
     private TextView url;
+    private Switch postingPermitted;
     private TextInputLayout urlLayout;
     private LinearLayout authParams;
     private Switch useAuthentication;
@@ -126,6 +127,7 @@ public class ProfileDetailFragment extends Fragment {
             if (mProfile != null) {
                 mProfile.setName(profileName.getText());
                 mProfile.setUrl(url.getText());
+                mProfile.setPostingPermitted(postingPermitted.isChecked());
                 mProfile.setAuthEnabled(useAuthentication.isChecked());
                 mProfile.setAuthUserName(userName.getText());
                 mProfile.setAuthPassword(password.getText());
@@ -140,11 +142,15 @@ public class ProfileDetailFragment extends Fragment {
                 }
             }
             else {
-                mProfile = new MobileLedgerProfile(profileName.getText(), url.getText(),
-                        useAuthentication.isChecked(), userName.getText(), password.getText());
+                mProfile = new MobileLedgerProfile(profileName.getText(), postingPermitted.isChecked(),
+                        url.getText(), useAuthentication.isChecked(), userName.getText(),
+                        password.getText());
                 mProfile.storeInDB();
                 Data.profiles.add(mProfile);
                 MobileLedgerProfile.storeProfilesOrder();
+
+                // first profile ever?
+                if (Data.profiles.getList().size() == 1) Data.profile.set(mProfile);
             }
 
             Activity activity = getActivity();
@@ -162,6 +168,7 @@ public class ProfileDetailFragment extends Fragment {
         profileNameLayout = rootView.findViewById(R.id.profile_name_layout);
         url = rootView.findViewById(R.id.url);
         urlLayout = rootView.findViewById(R.id.url_layout);
+        postingPermitted = rootView.findViewById(R.id.profile_permit_posting);
         authParams = rootView.findViewById(R.id.auth_params);
         useAuthentication = rootView.findViewById(R.id.enable_http_auth);
         userName = rootView.findViewById(R.id.auth_user_name);
@@ -182,6 +189,7 @@ public class ProfileDetailFragment extends Fragment {
 
         if (mProfile != null) {
             profileName.setText(mProfile.getName());
+            postingPermitted.setChecked(mProfile.isPostingPermitted());
             url.setText(mProfile.getUrl());
             useAuthentication.setChecked(mProfile.isAuthEnabled());
             authParams.setVisibility(mProfile.isAuthEnabled() ? View.VISIBLE : View.GONE);
@@ -191,6 +199,7 @@ public class ProfileDetailFragment extends Fragment {
         else {
             profileName.setText("");
             url.setText("");
+            postingPermitted.setChecked(true);
             useAuthentication.setChecked(false);
             authParams.setVisibility(View.GONE);
             userName.setText("");