]> uap-core.de Git - rssreader.git/commitdiff
show number of unread items in the sourcelist
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 31 Aug 2025 10:37:48 +0000 (12:37 +0200)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sun, 31 Aug 2025 10:37:48 +0000 (12:37 +0200)
rss-application/src/main/kotlin/de/unixwork/rssreader/Database.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/FeedCollection.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/FeedList.kt
rss-application/src/main/kotlin/de/unixwork/rssreader/MainWindow.kt

index 171d6c721e4a9ca3fa868b50cc65176d54e0f25a..3bdfd9f05f3e94b8ad4f51f178a26f86e4ea9fab 100644 (file)
@@ -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)
                 }
 
index 49ec7be4ec6d56bec3833b3e1db2a0928e3bd737..5d8190b478736c0341d69a13cb6a9dcb110fccf6 100644 (file)
@@ -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<Item>()
     var itemsLoaded = false
index 77324bf5c0420fdfc60adc85191aba2db7d40950..4a5029ab1c9074af528bc8f6e453d724eafdc7bc 100644 (file)
@@ -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)
             }
index e619486c0b1d989ea889d7e273c5fabfb4da88a6..1eb007a59b769f845b5bec74be228b7a41cf04fb 100644 (file)
@@ -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) {