From 5227751dcad431848fe29276a0344fcd1309b227 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Wed, 28 Dec 2022 11:02:43 +0100 Subject: [PATCH 1/3] Make the author field nullable --- .../apps/readerforselfossv2/android/model/ParecelableItem.kt | 2 +- .../bou/amine/apps/readerforselfossv2/model/SelfossModel.kt | 4 ++-- .../sqldelight/bou/amine/apps/readerforselfossv2/dao/1.sqm | 2 +- .../sqldelight/bou/amine/apps/readerforselfossv2/dao/Items.sq | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/model/ParecelableItem.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/model/ParecelableItem.kt index 9eaf41d..7ae2939 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/model/ParecelableItem.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/model/ParecelableItem.kt @@ -46,7 +46,7 @@ data class ParecelableItem( val link: String, val sourcetitle: String, val tags: String, - val author: String + val author: String? ) : Parcelable { companion object { diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/model/SelfossModel.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/model/SelfossModel.kt index 7566f18..5d4d5c4 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/model/SelfossModel.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/model/SelfossModel.kt @@ -73,7 +73,7 @@ class SelfossModel { val sourcetitle: String, @Serializable(with = TagsListSerializer::class) val tags: List, - val author: String + val author: String? ) { // TODO: maybe find a better way to handle these kind of urls fun getLinkDecoded(): String { @@ -104,7 +104,7 @@ class SelfossModel { fun sourceAuthorAndDate(): String { var txt = this.sourcetitle.getHtmlDecoded() - if (this.author.isNotEmpty()) { + if (!this.author.isNullOrBlank()) { txt += " (by ${this.author}) " } txt += DateUtils.parseRelativeDate(this.datetime) diff --git a/shared/src/commonMain/sqldelight/bou/amine/apps/readerforselfossv2/dao/1.sqm b/shared/src/commonMain/sqldelight/bou/amine/apps/readerforselfossv2/dao/1.sqm index 6f9532c..1a71de6 100644 --- a/shared/src/commonMain/sqldelight/bou/amine/apps/readerforselfossv2/dao/1.sqm +++ b/shared/src/commonMain/sqldelight/bou/amine/apps/readerforselfossv2/dao/1.sqm @@ -1 +1 @@ -ALTER TABLE ITEM ADD COLUMN `author` TEXT NOT NULL; \ No newline at end of file +ALTER TABLE ITEM ADD COLUMN `author` TEXT; \ No newline at end of file diff --git a/shared/src/commonMain/sqldelight/bou/amine/apps/readerforselfossv2/dao/Items.sq b/shared/src/commonMain/sqldelight/bou/amine/apps/readerforselfossv2/dao/Items.sq index ed9fa8e..04a9c00 100644 --- a/shared/src/commonMain/sqldelight/bou/amine/apps/readerforselfossv2/dao/Items.sq +++ b/shared/src/commonMain/sqldelight/bou/amine/apps/readerforselfossv2/dao/Items.sq @@ -10,7 +10,7 @@ CREATE TABLE ITEM ( `link` TEXT NOT NULL, `sourcetitle` TEXT NOT NULL, `tags` TEXT NOT NULL, - `author` TEXT NOT NULL, + `author` TEXT, PRIMARY KEY(`id`) ); -- 2.34.1 From 3a654f6edea020619d63aad72582cf82b37d5547 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Wed, 28 Dec 2022 14:25:34 +0100 Subject: [PATCH 2/3] Migrate the database table --- .../sqldelight/bou/amine/apps/readerforselfossv2/dao/1.sqm | 2 +- .../sqldelight/bou/amine/apps/readerforselfossv2/dao/2.sqm | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 shared/src/commonMain/sqldelight/bou/amine/apps/readerforselfossv2/dao/2.sqm diff --git a/shared/src/commonMain/sqldelight/bou/amine/apps/readerforselfossv2/dao/1.sqm b/shared/src/commonMain/sqldelight/bou/amine/apps/readerforselfossv2/dao/1.sqm index 1a71de6..6f9532c 100644 --- a/shared/src/commonMain/sqldelight/bou/amine/apps/readerforselfossv2/dao/1.sqm +++ b/shared/src/commonMain/sqldelight/bou/amine/apps/readerforselfossv2/dao/1.sqm @@ -1 +1 @@ -ALTER TABLE ITEM ADD COLUMN `author` TEXT; \ No newline at end of file +ALTER TABLE ITEM ADD COLUMN `author` TEXT NOT NULL; \ No newline at end of file diff --git a/shared/src/commonMain/sqldelight/bou/amine/apps/readerforselfossv2/dao/2.sqm b/shared/src/commonMain/sqldelight/bou/amine/apps/readerforselfossv2/dao/2.sqm new file mode 100644 index 0000000..bc2dc04 --- /dev/null +++ b/shared/src/commonMain/sqldelight/bou/amine/apps/readerforselfossv2/dao/2.sqm @@ -0,0 +1,6 @@ +CREATE TABLE ITEM_BACKUP AS SELECT `id`, `datetime`, `title`, `content`, + `unread`, `starred`, `thumbnail`, `icon`, `link`, `sourcetitle`, + `tags` FROM ITEM; +ALTER TABLE ITEM_BACKUP ADD COLUMN `author` TEXT; +DROP TABLE ITEM; +ALTER TABLE ITEM_BACKUP RENAME TO ITEM; \ No newline at end of file -- 2.34.1 From e51915d1cd96f5bfbb64fb7560d0d13e26e0a350 Mon Sep 17 00:00:00 2001 From: davidoskky Date: Wed, 28 Dec 2022 14:25:56 +0100 Subject: [PATCH 3/3] Include author field when updating the database --- .../amine/apps/readerforselfossv2/repository/RepositoryImpl.kt | 1 + .../sqldelight/bou/amine/apps/readerforselfossv2/dao/Items.sq | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt index 3979733..26d1733 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/repository/RepositoryImpl.kt @@ -511,6 +511,7 @@ class Repository( item.link, item.sourcetitle, item.tags.joinToString(","), + item.author, item.id.toString() ) diff --git a/shared/src/commonMain/sqldelight/bou/amine/apps/readerforselfossv2/dao/Items.sq b/shared/src/commonMain/sqldelight/bou/amine/apps/readerforselfossv2/dao/Items.sq index 04a9c00..fd5f34e 100644 --- a/shared/src/commonMain/sqldelight/bou/amine/apps/readerforselfossv2/dao/Items.sq +++ b/shared/src/commonMain/sqldelight/bou/amine/apps/readerforselfossv2/dao/Items.sq @@ -31,4 +31,4 @@ deleteItemsWhereSource: DELETE FROM ITEM WHERE `sourcetitle` = ?; updateItem: -UPDATE ITEM SET `datetime` = ?, `title` = ?, `content` = ?, `unread` = ?, `starred` = ?, `thumbnail` = ?, `icon` = ?, `link` = ?, `sourcetitle` = ?, `tags` = ? WHERE `id` = ?; \ No newline at end of file +UPDATE ITEM SET `datetime` = ?, `title` = ?, `content` = ?, `unread` = ?, `starred` = ?, `thumbnail` = ?, `icon` = ?, `link` = ?, `sourcetitle` = ?, `tags` = ?, `author` = ? WHERE `id` = ?; \ No newline at end of file -- 2.34.1