Big code cleaning.
Some checks reported errors
continuous-integration/drone/push Build was killed
continuous-integration/drone/pr Build was killed

This commit is contained in:
aminecmi
2022-08-23 22:03:33 +02:00
parent 216c639a23
commit 437aa0abec
17 changed files with 171 additions and 160 deletions

View File

@ -1,6 +1,5 @@
package bou.amine.apps.readerforselfossv2.utils
import android.annotation.SuppressLint
import android.text.format.DateUtils
import java.time.Instant
import java.time.LocalDateTime

View File

@ -1,8 +1,51 @@
package bou.amine.apps.readerforselfossv2.utils
import android.net.Uri
import android.text.Html
import bou.amine.apps.readerforselfossv2.model.SelfossModel
import org.jsoup.Jsoup
import java.util.*
import kotlin.collections.ArrayList
actual fun String.getHtmlDecoded(): String {
return Html.fromHtml(this).toString()
}
actual fun SelfossModel.Item.getIcon(baseUrl: String): String {
return constructUrl(baseUrl, "favicons", icon)
}
actual fun SelfossModel.Item.getThumbnail(baseUrl: String): String {
return constructUrl(baseUrl, "thumbnails", thumbnail)
}
actual fun SelfossModel.Item.getImages(): ArrayList<String> {
val allImages = ArrayList<String>()
for ( image in Jsoup.parse(content).getElementsByTag("img")) {
val url = image.attr("src")
if (url.lowercase(Locale.US).contains(".jpg") ||
url.lowercase(Locale.US).contains(".jpeg") ||
url.lowercase(Locale.US).contains(".png") ||
url.lowercase(Locale.US).contains(".webp"))
{
allImages.add(url)
}
}
return allImages
}
actual fun SelfossModel.Source.getIcon(baseUrl: String): String {
return constructUrl(baseUrl, "favicons", icon)
}
actual fun constructUrl(baseUrl: String, path: String, file: String?): String {
return if (file == null || file == "null" || file.isEmpty()) {
""
} else {
val baseUriBuilder = Uri.parse(baseUrl).buildUpon()
baseUriBuilder.appendPath(path).appendPath(file)
baseUriBuilder.toString()
}
}

View File

@ -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("&amp;url=")) {
link.substringAfter("&amp;url=")
} else {
this.link.replace("&amp;", "&")
}
} else {
this.link.replace("&amp;", "&")
}
// 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
}
}
}

View File

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

View File

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

View File

@ -1,5 +1,27 @@
package bou.amine.apps.readerforselfossv2.utils
import bou.amine.apps.readerforselfossv2.model.SelfossModel
actual fun String.getHtmlDecoded(): String {
TODO("Not yet implemented")
}
actual fun SelfossModel.Item.getIcon(baseUrl: String): String {
TODO("Not yet implemented")
}
actual fun SelfossModel.Item.getThumbnail(baseUrl: String): String {
TODO("Not yet implemented")
}
actual fun SelfossModel.Item.getImages(): ArrayList<String> {
TODO("Not yet implemented")
}
actual fun SelfossModel.Source.getIcon(baseUrl: String): String {
TODO("Not yet implemented")
}
actual fun constructUrl(baseUrl: String, path: String, file: String?): String {
TODO("Not yet implemented")
}

View File

@ -1,5 +1,27 @@
package bou.amine.apps.readerforselfossv2.utils
import bou.amine.apps.readerforselfossv2.model.SelfossModel
actual fun String.getHtmlDecoded(): String {
TODO("Not yet implemented")
}
actual fun SelfossModel.Item.getIcon(baseUrl: String): String {
TODO("Not yet implemented")
}
actual fun SelfossModel.Item.getThumbnail(baseUrl: String): String {
TODO("Not yet implemented")
}
actual fun SelfossModel.Item.getImages(): ArrayList<String> {
TODO("Not yet implemented")
}
actual fun SelfossModel.Source.getIcon(baseUrl: String): String {
TODO("Not yet implemented")
}
actual fun constructUrl(baseUrl: String, path: String, file: String?): String {
TODO("Not yet implemented")
}