From: Damyan Ivanov Date: Sun, 17 Feb 2019 20:05:51 +0000 (+0200) Subject: add color setting to profile data X-Git-Tag: v0.7~75 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=ffc5af343abba93ec94157aee7b46bc480d49bc4;p=mobile-ledger.git add color setting to profile data --- diff --git a/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java b/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java index bb3f20a4..3489c28a 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java @@ -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 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()); + } } diff --git a/app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java b/app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java index 442f610b..328d8c97 100644 --- a/app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java +++ b/app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java @@ -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 index 00000000..bea40aa9 --- /dev/null +++ b/app/src/main/res/raw/sql_18.sql @@ -0,0 +1,2 @@ +alter table profiles add theme integer default -1; +update profiles set theme = -1; \ No newline at end of file