Big code cleaning.
This commit is contained in:
@ -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
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
@ -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
|
@ -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")
|
||||
}
|
@ -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")
|
||||
}
|
Reference in New Issue
Block a user