Fixed bug with article loading

Signed-off-by: Balazs Toldi <balazs@toldi.eu>
This commit is contained in:
Balazs Toldi 2021-10-24 16:06:15 +02:00
parent 103a253ac0
commit d295eae730
Signed by: Bazsalanszky
GPG key ID: 933820884952BE27
3 changed files with 13 additions and 2 deletions

View file

@ -118,6 +118,9 @@ class MainActivity : ComponentActivity() {
}
}
}
LaunchedEffect(true) {
viewModel.initArticles()
}
}
}
}

View file

@ -94,8 +94,10 @@ class FeedRepository(private val feedsAndArticleDAO: FeedsAndArticlesDAO) {
val article: Node = items.item(i)
val a = withContext(Dispatchers.IO) { Article.createFromNode(article, feed = feed) }
val a1 = withContext(IO) { a.url?.let { feedsAndArticleDAO.getArticleByURL(it) } }
if (a != a1)
if (a != a1) {
feedsAndArticleDAO.insertArticle(feed, a)
_articleState.value = getAllArticles()
}
}
feed.faviconURL = withContext(Dispatchers.IO) {

View file

@ -25,8 +25,8 @@ class FeedViewModel(application: Application) : AndroidViewModel(application) {
feedRepo = FeedRepository(feedsAndArticleDAO = feedsAndArticlesDao)
articles = feedRepo.articleState
viewModelScope.launch(IO) {
//feedRepo.initArticles()
feedRepo.updateFeeds()
}
feeds = feedRepo.getFeedList()
isRefereshing = feedRepo.isRefeshing
@ -62,5 +62,11 @@ class FeedViewModel(application: Application) : AndroidViewModel(application) {
}
}
fun initArticles() {
viewModelScope.launch(IO) {
feedRepo.initArticles()
}
}
}