Handling author field.
This commit is contained in:
@ -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> {
|
||||
|
@ -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
|
||||
)
|
@ -0,0 +1 @@
|
||||
ALTER TABLE ITEM ADD COLUMN `author` TEXT NOT NULL;
|
@ -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`)
|
||||
);
|
||||
|
||||
|
Reference in New Issue
Block a user