Fixed bug with article loading
Signed-off-by: Balazs Toldi <balazs@toldi.eu>
This commit is contained in:
parent
103a253ac0
commit
d295eae730
3 changed files with 13 additions and 2 deletions
|
@ -118,6 +118,9 @@ class MainActivity : ComponentActivity() {
|
|||
}
|
||||
}
|
||||
}
|
||||
LaunchedEffect(true) {
|
||||
viewModel.initArticles()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue