Big code cleaning.
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
package bou.amine.apps.readerforselfossv2.model
|
||||
|
||||
import bou.amine.apps.readerforselfossv2.utils.DateUtils
|
||||
import bou.amine.apps.readerforselfossv2.utils.getHtmlDecoded
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
class SelfossModel {
|
||||
@ -67,5 +69,40 @@ class SelfossModel {
|
||||
val link: String,
|
||||
val sourcetitle: String,
|
||||
val tags: List<String>
|
||||
)
|
||||
) {
|
||||
// TODO: maybe find a better way to handle these kind of urls
|
||||
fun getLinkDecoded(): String {
|
||||
var stringUrl: String
|
||||
stringUrl =
|
||||
if (link.startsWith("http://news.google.com/news/") || link.startsWith("https://news.google.com/news/")) {
|
||||
if (link.contains("&url=")) {
|
||||
link.substringAfter("&url=")
|
||||
} else {
|
||||
this.link.replace("&", "&")
|
||||
}
|
||||
} else {
|
||||
this.link.replace("&", "&")
|
||||
}
|
||||
|
||||
// handle :443 => https
|
||||
if (stringUrl.contains(":443")) {
|
||||
stringUrl = stringUrl.replace(":443", "").replace("http://", "https://")
|
||||
}
|
||||
|
||||
// handle url not starting with http
|
||||
if (stringUrl.startsWith("//")) {
|
||||
stringUrl = "http:$stringUrl"
|
||||
}
|
||||
|
||||
return stringUrl
|
||||
}
|
||||
|
||||
fun sourceAndDateText(dateUtils: DateUtils): String =
|
||||
this.title.getHtmlDecoded() + dateUtils.parseRelativeDate(this.datetime)
|
||||
|
||||
fun toggleStar(): Item {
|
||||
this.starred = !this.starred
|
||||
return this
|
||||
}
|
||||
}
|
||||
}
|
@ -6,9 +6,6 @@ import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
||||
fun SelfossModel.Item.parseDate(dateUtils: DateUtils): Long =
|
||||
dateUtils.parseDate(this.datetime)
|
||||
|
||||
fun SelfossModel.Item.parseRelativeDate(dateUtils: DateUtils): String =
|
||||
dateUtils.parseRelativeDate(this.datetime)
|
||||
|
||||
expect class DateUtils(apiMajorVersion: Int) {
|
||||
fun parseDate(dateString: String): Long
|
||||
|
||||
|
@ -1,3 +1,15 @@
|
||||
package bou.amine.apps.readerforselfossv2.utils
|
||||
|
||||
expect fun String.getHtmlDecoded(): String
|
||||
import bou.amine.apps.readerforselfossv2.model.SelfossModel
|
||||
|
||||
expect fun String.getHtmlDecoded(): String
|
||||
|
||||
expect fun SelfossModel.Item.getIcon(baseUrl: String): String
|
||||
|
||||
expect fun SelfossModel.Item.getThumbnail(baseUrl: String): String
|
||||
|
||||
expect fun SelfossModel.Item.getImages(): ArrayList<String>
|
||||
|
||||
expect fun SelfossModel.Source.getIcon(baseUrl: String): String
|
||||
|
||||
expect fun constructUrl(baseUrl: String, path: String, file: String?): String
|
Reference in New Issue
Block a user