]> git.ktnx.net Git - mobile-ledger.git/commitdiff
add color setting to profile data
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 17 Feb 2019 20:05:51 +0000 (22:05 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 17 Feb 2019 20:05:51 +0000 (22:05 +0200)
app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java
app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java
app/src/main/res/raw/sql_18.sql [new file with mode: 0644]

index bb3f20a47df588610c24dc535971da63a83e51f2..3489c28a0385bd729bafcf134f6709e70009e7f5 100644 (file)
@@ -36,8 +36,15 @@ public final class MobileLedgerProfile {
     private boolean authEnabled;
     private String authUserName;
     private String authPassword;
+    private int themeId;
     public MobileLedgerProfile(String uuid, String name, boolean permitPosting, String url,
                                boolean authEnabled, String authUserName, String authPassword) {
+        this(uuid, name, permitPosting, url, authEnabled, authUserName, authPassword, -1);
+
+    }
+    public MobileLedgerProfile(String uuid, String name, boolean permitPosting, String url,
+                               boolean authEnabled, String authUserName, String authPassword,
+                               int themeId) {
         this.uuid = uuid;
         this.name = name;
         this.permitPosting = permitPosting;
@@ -45,10 +52,11 @@ public final class MobileLedgerProfile {
         this.authEnabled = authEnabled;
         this.authUserName = authUserName;
         this.authPassword = authPassword;
+        this.themeId = themeId;
     }
     public MobileLedgerProfile(CharSequence name, boolean permitPosting, CharSequence url,
                                boolean authEnabled, CharSequence authUserName,
-                               CharSequence authPassword) {
+                               CharSequence authPassword, int themeId) {
         this.uuid = String.valueOf(UUID.randomUUID());
         this.name = String.valueOf(name);
         this.permitPosting = permitPosting;
@@ -56,22 +64,23 @@ public final class MobileLedgerProfile {
         this.authEnabled = authEnabled;
         this.authUserName = String.valueOf(authUserName);
         this.authPassword = String.valueOf(authPassword);
+        this.themeId = themeId;
     }
-    // loads all profiles into Data.profiles
+        // loads all profiles into Data.profiles
     // returns the profile with the given UUID
     public static MobileLedgerProfile loadAllFromDB(String currentProfileUUID) {
         MobileLedgerProfile result = null;
         List<MobileLedgerProfile> list = new ArrayList<>();
         SQLiteDatabase db = MLDB.getReadableDatabase();
         try (Cursor cursor = db.rawQuery("SELECT uuid, name, url, use_authentication, auth_user, " +
-                                         "auth_password, permit_posting FROM profiles order by " +
-                                         "order_no", null))
+                                         "auth_password, permit_posting, theme FROM profiles " +
+                                         "order by order_no", null))
         {
             while (cursor.moveToNext()) {
                 MobileLedgerProfile item =
                         new MobileLedgerProfile(cursor.getString(0), cursor.getString(1),
                                 cursor.getInt(6) == 1, cursor.getString(2), cursor.getInt(3) == 1,
-                                cursor.getString(4), cursor.getString(5));
+                                cursor.getString(4), cursor.getString(5), cursor.getInt(7));
                 list.add(item);
                 if (item.getUuid().equals(currentProfileUUID)) result = item;
             }
@@ -150,12 +159,16 @@ public final class MobileLedgerProfile {
         SQLiteDatabase db = MLDB.getWritableDatabase();
         db.beginTransaction();
         try {
+//            Log.d("profiles", String.format("Storing profile in DB: uuid=%s, name=%s, " +
+//                                            "url=%s, permit_posting=%s, authEnabled=%s, " +
+//                                            "themeId=%d", uuid, name, url,
+//                    permitPosting ? "TRUE" : "FALSE", authEnabled ? "TRUE" : "FALSE", themeId));
             db.execSQL("REPLACE INTO profiles(uuid, name, permit_posting, url, " +
                        "use_authentication, auth_user, " +
-                       "auth_password) VALUES(?, ?, ?, ?, ?, ?, ?)",
+                       "auth_password, theme) VALUES(?, ?, ?, ?, ?, ?, ?, ?)",
                     new Object[]{uuid, name, permitPosting, url, authEnabled,
                                  authEnabled ? authUserName : null,
-                                 authEnabled ? authPassword : null
+                                 authEnabled ? authPassword : null, themeId
                     });
             db.setTransactionSuccessful();
         }
@@ -283,4 +296,15 @@ public final class MobileLedgerProfile {
 
         return tr;
     }
+    public int getThemeId() {
+//        Log.d("profile", String.format("Profile.getThemeId() returning %d", themeId));
+        return this.themeId;
+    }
+    public void setThemeId(int themeId) {
+//        Log.d("profile", String.format("Profile.setThemeId(%d) called", themeId));
+        this.themeId = themeId;
+    }
+    public void setThemeId(Object o) {
+        setThemeId(Integer.valueOf(String.valueOf(o)).intValue());
+    }
 }
index 442f610b469dc016dddf5e64b68c7a4e34059de1..328d8c978aa04cac0d29c12143cd74e6e71f523f 100644 (file)
@@ -222,7 +222,7 @@ public final class MLDB {
 
 class MobileLedgerDatabase extends SQLiteOpenHelper implements AutoCloseable {
     public static final String DB_NAME = "MoLe.db";
-    public static final int LATEST_REVISION = 17;
+    public static final int LATEST_REVISION = 18;
 
     private final Application mContext;
 
diff --git a/app/src/main/res/raw/sql_18.sql b/app/src/main/res/raw/sql_18.sql
new file mode 100644 (file)
index 0000000..bea40aa
--- /dev/null
@@ -0,0 +1,2 @@
+alter table profiles add theme integer default -1;
+update profiles set theme = -1;
\ No newline at end of file