Changed how the articles are downloaded
Signed-off-by: Toldi Balázs Ádám <balazs@toldi.eu>
This commit is contained in:
parent
b41ee6e5f0
commit
c46e795ac6
2 changed files with 4 additions and 9 deletions
|
@ -1,6 +1,8 @@
|
||||||
package eu.toldi.balazs.anotherfeedreader.entities
|
package eu.toldi.balazs.anotherfeedreader.entities
|
||||||
|
|
||||||
import kotlinx.coroutines.Dispatchers.IO
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
|
import kotlinx.coroutines.GlobalScope
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.runBlocking
|
import kotlinx.coroutines.runBlocking
|
||||||
import org.jsoup.Jsoup
|
import org.jsoup.Jsoup
|
||||||
import org.w3c.dom.Element
|
import org.w3c.dom.Element
|
||||||
|
@ -91,7 +93,7 @@ class Article(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (imageURL == null && url != null) {
|
if (imageURL == null && url != null) {
|
||||||
runBlocking(IO) {
|
runBlocking (IO) {
|
||||||
val con = Jsoup.connect(url)
|
val con = Jsoup.connect(url)
|
||||||
val doc = con.userAgent("Mozilla").get()
|
val doc = con.userAgent("Mozilla").get()
|
||||||
|
|
||||||
|
|
|
@ -37,11 +37,6 @@ open class Feed
|
||||||
* A hírcsatornához tartozó cikkek listája
|
* A hírcsatornához tartozó cikkek listája
|
||||||
*/
|
*/
|
||||||
open var articleList: List<Article> = emptyList()
|
open var articleList: List<Article> = emptyList()
|
||||||
private val _isRefreshing = MutableStateFlow(false)
|
|
||||||
|
|
||||||
val isRefreshing: StateFlow<Boolean>
|
|
||||||
get() = _isRefreshing.asStateFlow()
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A hírcsatornán található cikkek számának lekérése
|
* A hírcsatornán található cikkek számának lekérése
|
||||||
|
@ -65,7 +60,6 @@ open class Feed
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
open suspend fun updateFeed() {
|
open suspend fun updateFeed() {
|
||||||
_isRefreshing.emit(true)
|
|
||||||
val factory: DocumentBuilderFactory = DocumentBuilderFactory.newInstance()
|
val factory: DocumentBuilderFactory = DocumentBuilderFactory.newInstance()
|
||||||
val builder: DocumentBuilder = factory.newDocumentBuilder()
|
val builder: DocumentBuilder = factory.newDocumentBuilder()
|
||||||
var doc: Document = withContext(Dispatchers.IO) {
|
var doc: Document = withContext(Dispatchers.IO) {
|
||||||
|
@ -82,7 +76,7 @@ open class Feed
|
||||||
|
|
||||||
for (i in 0 until items.length) {
|
for (i in 0 until items.length) {
|
||||||
val article: Node = items.item(i)
|
val article: Node = items.item(i)
|
||||||
val a = Article.createFromNode(article, this@Feed)
|
val a = withContext(Dispatchers.IO) {Article.createFromNode(article, this@Feed)}
|
||||||
addArticle(a)
|
addArticle(a)
|
||||||
}
|
}
|
||||||
articleList.sortedByDescending { it.pubDate }
|
articleList.sortedByDescending { it.pubDate }
|
||||||
|
@ -92,7 +86,6 @@ open class Feed
|
||||||
extractor.fromPage("https://" + link.host)[0].url
|
extractor.fromPage("https://" + link.host)[0].url
|
||||||
}
|
}
|
||||||
Log.e(null, faviconURL.toString())
|
Log.e(null, faviconURL.toString())
|
||||||
_isRefreshing.emit(false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue