From fe2410f719402c84d21141e744f89ae66d89ff29 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Mon, 26 Dec 2022 21:49:55 +0100 Subject: [PATCH] Handling author field. --- .../android/adapters/ItemCardAdapter.kt | 2 +- .../android/adapters/ItemListAdapter.kt | 2 +- .../android/fragments/ArticleFragment.kt | 2 +- .../android/model/ParecelableItem.kt | 13 +++++++++---- androidApp/src/test/kotlin/TestUtils.kt | 7 +++++-- .../apps/readerforselfossv2/model/SelfossModel.kt | 15 +++++++++++---- .../apps/readerforselfossv2/utils/EntityUtils.kt | 6 ++++-- .../bou/amine/apps/readerforselfossv2/dao/1.sqm | 1 + .../amine/apps/readerforselfossv2/dao/Items.sq | 1 + 9 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 shared/src/commonMain/sqldelight/bou/amine/apps/readerforselfossv2/dao/1.sqm diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemCardAdapter.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemCardAdapter.kt index a5fd7d1..d9b5f55 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemCardAdapter.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemCardAdapter.kt @@ -62,7 +62,7 @@ class ItemCardAdapter( binding.title.setLinkTextColor(c.resources.getColor(R.color.colorAccent)) - binding.sourceTitleAndDate.text = itm.sourceAndDateText() + binding.sourceTitleAndDate.text = itm.sourceAuthorAndDate() if (!appSettingsService.isFullHeightCardsEnabled()) { binding.itemImage.maxHeight = imageMaxHeight diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemListAdapter.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemListAdapter.kt index 560a38a..bbd53c2 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemListAdapter.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/adapters/ItemListAdapter.kt @@ -51,7 +51,7 @@ class ItemListAdapter( binding.title.setLinkTextColor(c.resources.getColor(R.color.colorAccent)) - binding.sourceTitleAndDate.text = itm.sourceAndDateText() + binding.sourceTitleAndDate.text = itm.sourceAuthorAndDate() if (itm.getThumbnail(repository.baseUrl).isEmpty()) { diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt index 4e5af91..1dbb9a6 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt @@ -101,7 +101,7 @@ class ArticleFragment : Fragment(), DIAware { contentText = item.content contentTitle = item.title.getHtmlDecoded() contentImage = item.getThumbnail(repository.baseUrl) - contentSource = item.sourceAndDateText() + contentSource = item.sourceAuthorAndDate() allImages = item.getImages() fontSize = appSettingsService.getFontSize() 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 b42a196..9eaf41d 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 @@ -16,7 +16,8 @@ fun SelfossModel.Item.toParcelable() : ParecelableItem = this.icon, this.link, this.sourcetitle, - this.tags.joinToString(",") + this.tags.joinToString(","), + this.author ) fun ParecelableItem.toModel() : SelfossModel.Item = SelfossModel.Item( @@ -30,7 +31,8 @@ fun ParecelableItem.toModel() : SelfossModel.Item = this.icon, this.link, this.sourcetitle, - this.tags.split(",") + this.tags.split(","), + this.author ) data class ParecelableItem( val id: Int, @@ -43,7 +45,8 @@ data class ParecelableItem( val icon: String?, val link: String, val sourcetitle: String, - val tags: String + val tags: String, + val author: String ) : Parcelable { companion object { @@ -65,7 +68,8 @@ data class ParecelableItem( icon = source.readString(), link = source.readString().orEmpty(), sourcetitle = source.readString().orEmpty(), - tags = source.readString().orEmpty() + tags = source.readString().orEmpty(), + author = source.readString().orEmpty() ) override fun describeContents() = 0 @@ -82,5 +86,6 @@ data class ParecelableItem( dest.writeString(link) dest.writeString(sourcetitle) dest.writeString(tags) + dest.writeString(author) } } \ No newline at end of file diff --git a/androidApp/src/test/kotlin/TestUtils.kt b/androidApp/src/test/kotlin/TestUtils.kt index e568644..0578e26 100644 --- a/androidApp/src/test/kotlin/TestUtils.kt +++ b/androidApp/src/test/kotlin/TestUtils.kt @@ -17,7 +17,8 @@ fun generateTestDBItems(item: FakeItemParameters = FakeItemParameters()): List + val tags: List, + val author: String ) { // TODO: maybe find a better way to handle these kind of urls fun getLinkDecoded(): String { @@ -102,8 +102,14 @@ class SelfossModel { return stringUrl } - fun sourceAndDateText(): String = - this.sourcetitle.getHtmlDecoded() + DateUtils.parseRelativeDate(this.datetime) + fun sourceAuthorAndDate(): String { + var txt = this.sourcetitle.getHtmlDecoded() + if (this.author.isNotEmpty()) { + txt += " (by ${this.author}) " + } + txt += DateUtils.parseRelativeDate(this.datetime) + return txt + } fun toggleStar(): Item { this.starred = !this.starred @@ -111,6 +117,7 @@ class SelfossModel { } } + // TODO: this seems to be super slow. object TagsListSerializer : KSerializer> { override fun deserialize(decoder: Decoder): List { diff --git a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/utils/EntityUtils.kt b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/utils/EntityUtils.kt index e6e2a81..248e463 100644 --- a/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/utils/EntityUtils.kt +++ b/shared/src/commonMain/kotlin/bou/amine/apps/readerforselfossv2/utils/EntityUtils.kt @@ -51,7 +51,8 @@ fun ITEM.toView(): SelfossModel.Item = this.icon, this.link, this.sourcetitle, - this.tags.split(",") + this.tags.split(","), + this.author ) fun SelfossModel.Item.toEntity(): ITEM = @@ -66,5 +67,6 @@ fun SelfossModel.Item.toEntity(): ITEM = this.icon, this.link, this.sourcetitle.getHtmlDecoded(), - this.tags.joinToString(",") + this.tags.joinToString(","), + this.author ) \ No newline at end of file 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 new file mode 100644 index 0000000..6f9532c --- /dev/null +++ b/shared/src/commonMain/sqldelight/bou/amine/apps/readerforselfossv2/dao/1.sqm @@ -0,0 +1 @@ +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/Items.sq b/shared/src/commonMain/sqldelight/bou/amine/apps/readerforselfossv2/dao/Items.sq index 24fa055..f85ab2b 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,6 +10,7 @@ CREATE TABLE ITEM ( `link` TEXT NOT NULL, `sourcetitle` TEXT NOT NULL, `tags` TEXT NOT NULL, + `author` TEXT NOT NULL, PRIMARY KEY(`id`) );