Handling author field.

This commit is contained in:
aminecmi 2022-12-26 21:49:55 +01:00
parent a5e86bfb77
commit fe2410f719
9 changed files with 34 additions and 15 deletions

View File

@ -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

View File

@ -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()) {

View File

@ -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()

View File

@ -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)
}
}

View File

@ -17,7 +17,8 @@ fun generateTestDBItems(item: FakeItemParameters = FakeItemParameters()): List<I
icon = item.icon,
link = item.link,
sourcetitle = item.sourcetitle,
tags = item.tags
tags = item.tags,
author = item.author
)
)
}
@ -35,7 +36,8 @@ fun generateTestApiItem(item: FakeItemParameters = FakeItemParameters()): List<S
icon = item.icon,
link = item.link,
sourcetitle = item.sourcetitle,
tags = item.tags.split(',')
tags = item.tags.split(','),
author = item.author
)
)
}
@ -54,4 +56,5 @@ class FakeItemParameters {
"https://ilblogdellasci.wordpress.com/2022/09/09/etica-della-ricerca-sotto-i-riflettori/"
var sourcetitle = "La Chimica e la Società"
var tags = "Chimica, Testing"
var author = "Someone important"
}

View File

@ -57,7 +57,6 @@ class SelfossModel {
val error: String,
val icon: String?
)
@Serializable
data class Item(
val id: Int,
@ -73,7 +72,8 @@ class SelfossModel {
val link: String,
val sourcetitle: String,
@Serializable(with = TagsListSerializer::class)
val tags: List<String>
val tags: List<String>,
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<List<String>> {
override fun deserialize(decoder: Decoder): List<String> {

View File

@ -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
)

View File

@ -0,0 +1 @@
ALTER TABLE ITEM ADD COLUMN `author` TEXT NOT NULL;

View File

@ -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`)
);