From 1a9c2a62458a86ff1a08a65a05ca93b55827053b Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Sun, 31 Aug 2025 12:37:48 +0200 Subject: [PATCH] show number of unread items in the sourcelist --- .../src/main/kotlin/de/unixwork/rssreader/Database.kt | 7 ++++++- .../main/kotlin/de/unixwork/rssreader/FeedCollection.kt | 1 + .../src/main/kotlin/de/unixwork/rssreader/FeedList.kt | 1 + .../src/main/kotlin/de/unixwork/rssreader/MainWindow.kt | 5 ++++- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt index 171d6c7..3bdfd9f 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt @@ -107,9 +107,12 @@ object Database { f.feedcollection_id, f.name as feed_name, f.update_interval, - f.auto_mark_read + f.auto_mark_read, + c.unread_count from groups g left join feedcollections f on g.group_id = f.group_id + left join (select feedcollection_id, count(*) as unread_count from items I inner join feeds F on I.feed_id = F.feed_id + where I.is_read = false group by feedcollection_id) C on f.feedcollection_id = C.feedcollection_id order by g.pos, f.pos """.trimIndent()) @@ -121,6 +124,7 @@ object Database { val feedName = rs.getString("feed_name") val updateInterval = rs.getLong("update_interval") val autoMarkRead = rs.getBoolean("auto_mark_read") + val unreadCount = rs.getInt("unread_count") if(currentGroup == null || currentGroup.id != groupId) { currentGroup = FeedGroup(context, groupId, groupName) @@ -131,6 +135,7 @@ object Database { val feed = FeedCollection(feedId, feedName) feed.updateInterval = updateInterval feed.autoMarkRead = autoMarkRead + feed.unreadItemsCount = unreadCount currentGroup.feeds.add(feed) } diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedCollection.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedCollection.kt index 49ec7be..5d8190b 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedCollection.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedCollection.kt @@ -7,6 +7,7 @@ class FeedCollection(id: Int, name: String) { val name = name var updateInterval: Long = 0 var autoMarkRead = false + var unreadItemsCount = 0 var items = mutableListOf() var itemsLoaded = false diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedList.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedList.kt index 77324bf..4a5029a 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedList.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/FeedList.kt @@ -90,6 +90,7 @@ class FeedList : Document() { // Update read status if(!item.isRead) { item.isRead = true + currentFeed?.unreadItemsCount-- GlobalScope.launch(Dispatchers.IO) { Database.updateReadState(item, true) } diff --git a/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt b/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt index e619486..1eb007a 100644 --- a/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt +++ b/rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt @@ -45,6 +45,9 @@ class MainWindow { { elm: FeedCollection -> val item = SubListItem() item.label = elm.name + if(elm.unreadItemsCount > 0) { + item.badge = elm.unreadItemsCount.toString() + } item } hbox(margin = 4, spacing = 4) { @@ -75,6 +78,7 @@ class MainWindow { } feedList.items.selected?.let { feedList.selectItem(it) + sourceList.feeds.update() } }, getstyle = { elm, col, style -> @@ -82,7 +86,6 @@ class MainWindow { // only highlight unread items if the feed(collection) is configured // to have individual read states if(feedList.currentFeed?.autoMarkRead == false) { - println("yes") // col == -1: style for the entire row // highlight unread items if(col == -1 && !elm.isRead) { -- 2.47.3