From: Olaf Wintermann Date: Sun, 31 Aug 2025 10:58:07 +0000 (+0200) Subject: update unread counter in the sourcelist after a syncjob finishes X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=24e4e4f5e9b3c84d7c5a9a2400b8409d65e73aff;p=rssreader.git update unread counter in the sourcelist after a syncjob finishes --- diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/App.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/App.kt index 9a68cba..c1a3bac 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/App.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/App.kt @@ -16,6 +16,7 @@ class App : Application { val window = event.windowData as MainWindow SyncJob().sync() { window.sourceList.invalidateCache() + window.sourceList.reloadStatus() window.feedList.reloadCurrentFeed() } } diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedSourceList.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedSourceList.kt index cd6ce92..7c7f239 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedSourceList.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedSourceList.kt @@ -2,15 +2,18 @@ package de.unixwork.rssreader import de.unixwork.ui.Document import de.unixwork.ui.SubList +import de.unixwork.ui.kotlin.ToolkitDispatcher +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.IO +import kotlinx.coroutines.launch class FeedSourceList : Document() { val feeds = this.sourcelist("feeds") val groups: MutableList init { - val db = Database - - groups = db.getFeedTree(this) + groups = Database.getFeedTree(this) groups.forEach { val sublist = SubList() sublist.header = it.name @@ -35,4 +38,38 @@ class FeedSourceList : Document() { } } } + + fun reloadStatus() { + // Reload the current feed tree from the database + // and update the current items + // TODO: it would be simpler to replace the current tree + // however it is currently not possible to cleanup the sourcelist + + GlobalScope.launch(Dispatchers.IO) { + // get the current feed tree + val groupUpdate = Database.getFeedTree(this@FeedSourceList) + // create a map that contains all feed collections + val index = mutableMapOf() + groupUpdate.forEach { + it.feeds.forEach { feed -> + index[feed.id] = feed + } + } + + // Update feeds in the UI thread + GlobalScope.launch(ToolkitDispatcher) { + groups.forEach { group -> + group.feeds.forEach { feed -> + val updatedFeed = index[feed.id] + updatedFeed?.let { + println("Updating feed ${feed.name} : ${feed.unreadItemsCount} -> ${updatedFeed.unreadItemsCount}") + feed.unreadItemsCount = updatedFeed.unreadItemsCount + } + } + } + feeds.update() + } + + } + } } \ No newline at end of file