]> git.ktnx.net Git - mobile-ledger.git/commitdiff
profile flag for enabling/disabling addition of new transactions
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 27 Jan 2019 18:11:36 +0000 (20:11 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 27 Jan 2019 18:11:36 +0000 (20:11 +0200)
app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java
app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfileDetailFragment.java
app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java
app/src/main/res/layout/profile_detail.xml
app/src/main/res/raw/sql_17.sql [new file with mode: 0644]
app/src/main/res/values-bg/strings.xml
app/src/main/res/values/strings.xml

index 6c7fb195719bb97ea7b5e6c2fc1dac03adb8ef34..bbd9a2be00ad982f8755984f7a44e8441b6b8611 100644 (file)
@@ -31,23 +31,27 @@ import java.util.UUID;
 public final class MobileLedgerProfile {
     private String uuid;
     private String name;
+    private boolean permitPosting;
     private String url;
     private boolean authEnabled;
     private String authUserName;
     private String authPassword;
-    public MobileLedgerProfile(String uuid, String name, String url, boolean authEnabled,
-                               String authUserName, String authPassword) {
+    public MobileLedgerProfile(String uuid, String name, boolean permitPosting, String url,
+                               boolean authEnabled, String authUserName, String authPassword) {
         this.uuid = uuid;
         this.name = name;
+        this.permitPosting = permitPosting;
         this.url = url;
         this.authEnabled = authEnabled;
         this.authUserName = authUserName;
         this.authPassword = authPassword;
     }
-    public MobileLedgerProfile(CharSequence name, CharSequence url, boolean authEnabled,
-                               CharSequence authUserName, CharSequence authPassword) {
+    public MobileLedgerProfile(CharSequence name, boolean permitPosting, CharSequence url,
+                               boolean authEnabled, CharSequence authUserName,
+                               CharSequence authPassword) {
         this.uuid = String.valueOf(UUID.randomUUID());
         this.name = String.valueOf(name);
+        this.permitPosting = permitPosting;
         this.url = String.valueOf(url);
         this.authEnabled = authEnabled;
         this.authUserName = String.valueOf(authUserName);
@@ -60,13 +64,14 @@ public final class MobileLedgerProfile {
         List<MobileLedgerProfile> list = new ArrayList<>();
         SQLiteDatabase db = MLDB.getReadableDatabase();
         try (Cursor cursor = db.rawQuery("SELECT uuid, name, url, use_authentication, auth_user, " +
-                                         "auth_password FROM profiles order by order_no", null))
+                                         "auth_password, permit_posting FROM profiles order by " +
+                                         "order_no", null))
         {
             while (cursor.moveToNext()) {
                 MobileLedgerProfile item =
                         new MobileLedgerProfile(cursor.getString(0), cursor.getString(1),
-                        cursor.getString(2), cursor.getInt(3) == 1, cursor.getString(4),
-                                cursor.getString(5));
+                                cursor.getInt(6) == 1, cursor.getString(2), cursor.getInt(3) == 1,
+                                cursor.getString(4), cursor.getString(5));
                 list.add(item);
                 if (item.getUuid().equals(currentProfileUUID)) result = item;
             }
@@ -91,6 +96,9 @@ public final class MobileLedgerProfile {
         }
     }
 
+    public boolean isPostingPermitted() {
+        return permitPosting;
+    }
     public String getUuid() {
         return uuid;
     }
@@ -140,9 +148,11 @@ public final class MobileLedgerProfile {
         SQLiteDatabase db = MLDB.getWritableDatabase();
         db.beginTransaction();
         try {
-            db.execSQL("REPLACE INTO profiles(uuid, name, url, use_authentication, auth_user, " +
-                       "auth_password) VALUES(?, ?, ?, ?, ?, ?)",
-                    new Object[]{uuid, name, url, authEnabled, authEnabled ? authUserName : null,
+            db.execSQL("REPLACE INTO profiles(uuid, name, permit_posting, url, " +
+                       "use_authentication, auth_user, " +
+                       "auth_password) VALUES(?, ?, ?, ?, ?, ?, ?)",
+                    new Object[]{uuid, name, permitPosting, url, authEnabled,
+                                 authEnabled ? authUserName : null,
                                  authEnabled ? authPassword : null
                     });
             db.setTransactionSuccessful();
index 7ef511d00656c2badc098dcedec3ba21a78b1a52..7cbfa0e7062c20abf3b7c2d6b75a6b128fccb7e7 100644 (file)
@@ -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;
@@ -140,8 +141,9 @@ 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();
@@ -165,6 +167,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);
@@ -185,6 +188,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);
@@ -194,6 +198,7 @@ public class ProfileDetailFragment extends Fragment {
         else {
             profileName.setText("");
             url.setText("");
+            postingPermitted.setChecked(true);
             useAuthentication.setChecked(false);
             authParams.setVisibility(View.GONE);
             userName.setText("");
index 76763d017677567af1a45a9e8ac5b444c6aa5f78..3d17facf58b3a48fecaabe70b16a7f4e51da916d 100644 (file)
@@ -217,7 +217,7 @@ public final class MLDB {
 
 class MobileLedgerDatabase extends SQLiteOpenHelper implements AutoCloseable {
     public static final String DB_NAME = "mobile-ledger.db";
-    public static final int LATEST_REVISION = 16;
+    public static final int LATEST_REVISION = 17;
 
     private final Application mContext;
 
index 43c74383dda7b7297ca50f235bddc7ce68b4a888..04e60dd08239b2cb1d9b755b4374889aa605af7a 100644 (file)
         android:layout_height="wrap_content"
         android:orientation="vertical">
 
+        <Switch
+            android:id="@+id/profile_permit_posting"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginBottom="16dp"
+            android:text="@string/posting_permitted" />
+
         <Switch
             android:id="@+id/enable_http_auth"
             android:layout_width="match_parent"
diff --git a/app/src/main/res/raw/sql_17.sql b/app/src/main/res/raw/sql_17.sql
new file mode 100644 (file)
index 0000000..f6f7eeb
--- /dev/null
@@ -0,0 +1,2 @@
+alter table profiles add permit_posting boolean default 0;
+update profiles set permit_posting = 1;
\ No newline at end of file
index 832d32f51f0639b8838ffa02b0f4ac188bb24941..db6924d560dea24a09b02c1a1bd918ea001f6693 100644 (file)
@@ -89,5 +89,6 @@
     <string name="err_profile_url_empty">Моля, въведете адрес, например https://server/location</string>
     <string name="err_profile_user_name_empty">Въвеждането на потребителско име е задължително когато се използва удостоверяване</string>
     <string name="err_profile_password_empty">Паролата е задължителна</string>
+    <string name="posting_permitted">Позволяване на добавянето на нови трансакции</string>
 
 </resources>
\ No newline at end of file
index d894ffaebdcfb11d17f8f422528ae8ed3b19f500..dc8003515555cefe8320b7e07f3d379cb98d306d 100644 (file)
         <item>November</item>
         <item>December</item>
     </string-array>
+    <string name="posting_permitted">Posting of new transactions enabled</string>
 </resources>